Skip to content
module

tgintegration.botcontroller

Entry point to tgintegration features.

Classes
  • BotController This class is the entry point for all interactions with either regular bots or userbots in TgIntegration. It expects a Pyrogram Client (typically a user client) that serves as the controlling account for a specific peer - which can be seen as the "bot under test" or "conversation partner". In addition, the controller holds a number of settings to control the timeouts for all these interactions.</>
class

tgintegration.botcontroller.BotController(client, peer, max_wait=20.0, wait_consecutive=2.0, raise_no_response=True, global_action_delay=0.8)

This class is the entry point for all interactions with either regular bots or userbots in TgIntegration. It expects a Pyrogram Client (typically a user client) that serves as the controlling account for a specific peer - which can be seen as the "bot under test" or "conversation partner". In addition, the controller holds a number of settings to control the timeouts for all these interactions.

Methods
  • add_handler_transient(handler) (NoneType) Registers a one-time/ad-hoc Pyrogram Handler that is only valid during the context manager body.</>
  • clear_chat() Deletes all messages in the conversation with the assigned peer.</>
  • initialize(start_client) Fetches and caches information about the given peer and optionally starts the assigned client. This method will automatically be called when coroutines of this class are invoked, but you can call it manually to override defaults (namely whether to start_client).</>
  • query_inline(query, latitude, longitude, limit) (InlineResultContainer) Requests inline results from the peer (which needs to be a bot).</>
  • send_command(command, args, peer, add_bot_name) (Message) Send a slash-command with corresponding parameters.</>
method

initialize(start_client=True)

Fetches and caches information about the given peer and optionally starts the assigned client. This method will automatically be called when coroutines of this class are invoked, but you can call it manually to override defaults (namely whether to start_client).

Parameters
  • start_client (bool, optional) Set to False if the client should not be started as part of initialization.

Note

It is unlikely that you will need to call this manually.

method

clear_chat()

Deletes all messages in the conversation with the assigned peer.

Warning

Be careful as this will completely drop your mutual message history.

method

add_handler_transient(handler)

Registers a one-time/ad-hoc Pyrogram Handler that is only valid during the context manager body.

Parameters
  • handler (Handler) A Pyrogram Handler (typically a MessageHandler).
Yields (NoneType)

None

Examples
async def some_callback(client, message):
    print(message)

async def main():
    async with controller.add_handler_transient(MessageHandler(some_callback, filters.text)):
        await controller.send_command("start")
        await asyncio.sleep(3)  # Wait 3 seconds for a reply
method

collect(filters=None, count=None, peer=None, max_wait=15, wait_consecutive=None, raise_=None) → abstractasynccontextmanager of Response

method

send_command(command, args=None, peer=None, add_bot_name=True) → Message

Send a slash-command with corresponding parameters.

method

query_inline(query, latitude=None, longitude=None, limit=200)

Requests inline results from the peer (which needs to be a bot).

Parameters
  • query (str) The query text.
  • latitude (float, optional) Latitude of a geo point.
  • longitude (float, optional) Longitude of a geo point.
  • limit (int, optional) When result pages get iterated automatically, specifies the maximum number of results to return from the bot.

A container for convenient access to the inline results.