Messenger#

The Messenger module provides the TelegramMessenger class. The former inherits from the TeleBot class from the pytelegrambotapi library. Using it, you can put Telegram update handlers inside your script and condition your transitions accordingly.

class TelegramMessenger(token, **kwargs)[source]#

Bases: TeleBot

This class inherits from Telebot and implements framework-specific functionality like sending generic responses.

Parameters:
  • token (str) – A Telegram API bot token.

  • kwargs – Arbitrary parameters that match the signature of the Telebot class. For reference see: link .

send_response(chat_id, response)[source]#

Cast response to TelegramMessage and send it. Message fields are sent in separate messages in the following order:

  1. Attachments

  2. Location

  3. Text with keyboard

Parameters:
  • chat_id (Union[str, int]) – Telegram chat ID.

  • response (Union[str, dict, Message]) – Response data. String, dictionary or Response. will be cast to TelegramMessage.

Return type:

None

class UpdateType(value)[source]#

Bases: Enum

Represents a type of the telegram update (which field contains an update in telebot.types.Update). See link.

ALL = 'ALL'#
MESSAGE = 'message'#
EDITED_MESSAGE = 'edited_message'#
CHANNEL_POST = 'channel_post'#
EDITED_CHANNEL_POST = 'edited_channel_post'#
INLINE_QUERY = 'inline_query'#
CHOSEN_INLINE_RESULT = 'chosen_inline_result'#
CALLBACK_QUERY = 'callback_query'#
SHIPPING_QUERY = 'shipping_query'#
PRE_CHECKOUT_QUERY = 'pre_checkout_query'#
POLL = 'poll'#
POLL_ANSWER = 'poll_answer'#
MY_CHAT_MEMBER = 'my_chat_member'#
CHAT_MEMBER = 'chat_member'#
CHAT_JOIN_REQUEST = 'chat_join_request'#
telegram_condition(messenger=<telebot.TeleBot object>, update_type=UpdateType.MESSAGE, commands=None, regexp=None, func=None, content_types=None, chat_types=None, **kwargs)[source]#

A condition triggered by updates that match the given parameters.

Parameters:
  • messenger (TeleBot) – Messenger to test filters on. Used only for Telebot.custom_filters. Defaults to _default_messenger.

  • update_type (UpdateType) – If set to any UpdateType other than UpdateType.ALL it will check that an update is of the same type. Defaults to UpdateType.Message.

  • commands (Optional[List[str]]) – Telegram command trigger. See link.

  • regexp (Optional[str]) – Regex trigger. See link.

  • func (Optional[Callable]) – Callable trigger. See link.

  • content_types (Optional[List[str]]) – Content type trigger. See link.

  • chat_types (Optional[List[str]]) – Chat type trigger. See link.