tgintegration.botcontroller
Entry point to tgintegration features.
BotController— This class is the entry point for all interactions with either regular bots or userbots inTgIntegration. It expects a PyrogramClient(typically a user client) that serves as the controlling account for a specificpeer- 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.</>
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.
add_handler_transient(handler)(NoneType) — Registers a one-time/ad-hoc PyrogramHandlerthat is only valid during the context manager body.</>clear_chat()— Deletes all messages in the conversation with the assignedpeer.</>initialize(start_client)— Fetches and caches information about the givenpeerand optionally starts the assignedclient. This method will automatically be called when coroutines of this class are invoked, but you can call it manually to override defaults (namely whether tostart_client).</>query_inline(query,latitude,longitude,limit)(InlineResultContainer) — Requests inline results from thepeer(which needs to be a bot).</>send_command(command,args,peer,add_bot_name)(Message) — Send a slash-command with corresponding parameters.</>
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).
start_client(bool, optional) — Set toFalseif the client should not be started as part of initialization.
Note
It is unlikely that you will need to call this manually.
clear_chat()
Deletes all messages in the conversation with the assigned peer.
Warning
Be careful as this will completely drop your mutual message history.
add_handler_transient(handler)
Registers a one-time/ad-hoc Pyrogram Handler that is only valid during the context manager body.
handler(Handler) — A PyrogramHandler(typically aMessageHandler).
None
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
send_command(command, args=None, peer=None, add_bot_name=True) → Message
Send a slash-command with corresponding parameters.
query_inline(query, latitude=None, longitude=None, limit=200)
Requests inline results from the peer (which needs to be a bot).
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.