telegram_platform#

class besser.bot.platforms.telegram.telegram_platform.TelegramPlatform(bot)[source]#

Bases: Platform

The Telegram Platform allows a bot to interact via Telegram.

It includes a message handler to handle all text inputs except commands (i.e. messages starting with ‘/’), voice, file and image handlers and a reset handler, triggered by the /reset command, to reset the bot session.

Parameters:

bot (Bot) – the bot the platform belongs to

_bot#

The bot the platform belongs to

Type:

Bot

_telegram_app#

The Telegram Application

Type:

Application

_event_loop#

The event loop that runs the asynchronous tasks of the Telegram Application

Type:

asyncio.AbstractEventLoop

_abc_impl = <_abc._abc_data object>#
_send(session_id, payload)[source]#

Send a payload message to a specific user.

Parameters:
  • session_id (str) – the user to send the response to

  • payload (Payload) – the payload message to send to the user

add_handler(handler)[source]#

Add a custom Telegram handler for the bot.

Parameters:

handler (telegram.ext.BaseHandler) – the handler to add

initialize()[source]#

Initialize the platform. This function is called right before starting the platform.

reply(session, message)[source]#

Send a bot reply, i.e. a text message, to a specific user.

Parameters:
  • session (Session) – the user session

  • message (str) – the message to send to the user

reply_file(session, file, message=None)[source]#

Send a file reply to a specific user

Parameters:
  • session (Session) – the user session

  • file (File) – the file to send

  • message (str, optional) – message to be attached to file, 1024 char limit

reply_image(session, file, message=None)[source]#

Send an image reply to a specific user

Parameters:
  • session (Session) – the user session

  • file (File) – the file to send (the image)

  • message (str, optional) – message to be attached to file, 1024 char limit

reply_location(session, latitude, longitude)[source]#

Send a location reply to a specific user.

Parameters:
  • session (Session) – the user session

  • latitude (str) – the latitude of the location

  • longitude (str) – the longitude of the location

start()[source]#

Start the platform.

stop()[source]#

Terminate the platform execution.

property telegram_app#

The Telegram app.

Type:

telegram.ext._application.Application

besser.bot.platforms.telegram.telegram_platform._wait_future(future)[source]#

Wait for a future (an asynchronous coroutine) to be finished.

Parameters:

future (Future) – the Future to wait for