telegram#

Description#

Plugin to programmatically send Telegram messages through a Telegram bot. In order to send messages to contacts, groups or channels you’ll first need to register a bot. To do so:

  1. Open a Telegram conversation with the @BotFather.

  2. Send /start followed by /newbot. Choose a display name and a username for your bot.

  3. Copy the provided API token in the configuration of this plugin.

  4. Open a conversation with your newly created bot.

Configuration#

telegram:
  # [Required]
  # API token as returned by the `@BotFather
  # <https://telegram.me/BotFather>`_
  api_token:   # type=str

  # [Optional]
  # Optional list of chat_id/user_id which are
  # authorized to send messages to the bot. If nothing is specified
  # then no restrictions are applied.
  # authorized_chat_ids:   # type=Optional[List[Union[str, int]]]

  # [Optional]
  # How often the `RunnablePlugin.loop <https://docs.platypush.tech/platypush/plugins/.html#platypush.plugins.RunnablePlugin.loop>`_ function should be
  # executed (default: 15 seconds). *NOTE*: For back-compatibility
  # reasons, the `poll_seconds` argument is also supported, but it's
  # deprecated.
  # poll_interval: 15  # type=Optional[float]

  # [Optional]
  # How long we should wait for any running
  # threads/processes to stop before exiting (default: 5 seconds).
  # stop_timeout: 5  # type=Optional[float]

  # [Optional]
  # If set to True then the plugin will not monitor
  # for new events. This is useful if you want to run a plugin in
  # stateless mode and only leverage its actions, without triggering any
  # events. Defaults to False.
  # disable_monitor: False  # type=bool

Dependencies#

pip

pip install python-telegram-bot

Triggered events#

Actions#

Module reference#

class platypush.plugins.telegram.TelegramPlugin(api_token: str, authorized_chat_ids: List[str | int] | None = None, **kwargs)[source]#

Bases: ChatPlugin, RunnablePlugin

Plugin to programmatically send Telegram messages through a Telegram bot. In order to send messages to contacts, groups or channels you’ll first need to register a bot. To do so:

  1. Open a Telegram conversation with the @BotFather.

  2. Send /start followed by /newbot. Choose a display name and a username for your bot.

  3. Copy the provided API token in the configuration of this plugin.

  4. Open a conversation with your newly created bot.

__init__(api_token: str, authorized_chat_ids: List[str | int] | None = None, **kwargs)[source]#
Parameters:
  • api_token

    API token as returned by the @BotFather

  • authorized_chat_ids – Optional list of chat_id/user_id which are authorized to send messages to the bot. If nothing is specified then no restrictions are applied.

delete_chat_photo(chat_id: str | int, timeout: float | None = 20)[source]#

Delete the photo of a channel/group.

Parameters:
  • chat_id – Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • timeout – Request timeout (default: 20 seconds)

get_chat(chat_id: int | str, timeout: float | None = 20) dict[source]#

Get the info about a Telegram chat.

Parameters:
  • chat_id – Chat ID.

  • timeout – Upload timeout (default: 20 seconds).

get_chat_administrators(chat_id: int | str, timeout: float | None = 20) List[dict][source]#

Get the list of the administrators of a chat.

Parameters:
  • chat_id – Chat ID.

  • timeout – Upload timeout (default: 20 seconds).

Returns:

[
  {
    "first_name": "string",
    "is_bot": false,
    "language_code": "string",
    "last_name": "string",
    "link": "string",
    "user_id": 32,
    "username": "string"
  }
]

get_chat_members_count(chat_id: int | str, timeout: float | None = 20) int[source]#

Get the number of users in a chat.

Parameters:
  • chat_id – Chat ID.

  • timeout – Upload timeout (default: 20 seconds).

get_chat_user(chat_id: int | str, user_id: int, timeout: float | None = 20) dict[source]#

Get the info about a user connected to a chat.

Parameters:
  • chat_id – Chat ID.

  • user_id – User ID.

  • timeout – Upload timeout (default: 20 seconds).

get_file(file_id: str, timeout: float | None = None) dict[source]#

Get the info and URL of an uploaded file by file_id.

Parameters:
  • file_id – File ID.

  • timeout – Upload timeout (default: 20 seconds).

Returns:

{
  "file_id": "string",
  "file_path": "string",
  "file_size": 42
}

kick_chat_member(chat_id: str | int, user_id: int, until_date: datetime | None = None, timeout: float | None = 20)[source]#

Kick a user from a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • user_id – Unique user ID.

  • until_date – End date for the ban.

  • timeout – Request timeout (default: 20 seconds)

leave_chat(chat_id: str | int, timeout: float | None = 20)[source]#

Leave a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • timeout – Request timeout (default: 20 seconds)

main()[source]#

Implementation of the main loop of the plugin.

pin_chat_message(chat_id: str | int, message_id: int, disable_notification: bool | None = None, timeout: float | None = 20)[source]#

Pin a message in a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • message_id – Message ID.

  • disable_notification – If True then no notification will be sent to the users.

  • timeout – Request timeout (default: 20 seconds)

promote_chat_member(chat_id: str | int, user_id: int, can_change_info: bool | None = None, can_post_messages: bool | None = None, can_edit_messages: bool | None = None, can_delete_messages: bool | None = None, can_invite_users: bool | None = None, can_restrict_members: bool | None = None, can_promote_members: bool | None = None, can_pin_messages: bool | None = None, timeout: float | None = 20)[source]#

Promote or demote a member.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • user_id – Unique user ID.

  • can_change_info – Pass True if the user can change channel info.

  • can_post_messages – Pass True if the user can post messages.

  • can_edit_messages – Pass True if the user can edit messages.

  • can_delete_messages – Pass True if the user can delete messages.

  • can_invite_users – Pass True if the user can invite other users to the channel/group.

  • can_restrict_members – Pass True if the user can restrict the permissions of other users.

  • can_promote_members – Pass True if the user can promote mebmers.

  • can_pin_messages – Pass True if the user can pin messages.

  • timeout – Request timeout (default: 20 seconds)

send_animation(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, duration: int | None = None, caption: str | None = None, width: int | None = None, height: int | None = None, parse_mode: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send an animation (GIF or H.264/MPEG-4 AVC video without sound) to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • duration – Duration in seconds.

  • caption – Optional caption for the picture.

  • width – Video width.

  • height – Video height.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 76,
  "audio_file_id": "string",
  "audio_file_size": 91,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 54,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 99,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 11,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 88,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 80,
  "from_username": "string",
  "link": "string",
  "location_latitude": 14,
  "location_longitude": 36,
  "media_group_id": "string",
  "message_id": 44,
  "photo_file_id": "string",
  "photo_file_size": 38,
  "photo_height": 2,
  "photo_width": 58,
  "text": "string",
  "video_duration": 35,
  "video_file_id": "string",
  "video_file_size": 34,
  "video_height": 77,
  "video_mime_type": "string",
  "video_width": 88
}

send_audio(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, caption: str | None = None, performer: str | None = None, title: str | None = None, duration: float | None = None, parse_mode: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send audio to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • caption – Optional caption for the picture.

  • performer – Optional audio performer.

  • title – Optional audio title.

  • duration – Duration of the audio in seconds.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 12,
  "audio_file_id": "string",
  "audio_file_size": 25,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 36,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 66,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 83,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 33,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 92,
  "from_username": "string",
  "link": "string",
  "location_latitude": 22,
  "location_longitude": 19,
  "media_group_id": "string",
  "message_id": 4,
  "photo_file_id": "string",
  "photo_file_size": 93,
  "photo_height": 95,
  "photo_width": 85,
  "text": "string",
  "video_duration": 21,
  "video_file_id": "string",
  "video_file_size": 77,
  "video_height": 22,
  "video_mime_type": "string",
  "video_width": 13
}

send_contact(chat_id: str | int, phone_number: str, first_name: str, last_name: str | None = None, vcard: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send a contact to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • phone_number – Phone number.

  • first_name – First name.

  • last_name – Last name.

  • vcard – Additional contact info in vCard format (0-2048 bytes).

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 35,
  "audio_file_id": "string",
  "audio_file_size": 37,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 2,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 88,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 89,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 23,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 99,
  "from_username": "string",
  "link": "string",
  "location_latitude": 27,
  "location_longitude": 59,
  "media_group_id": "string",
  "message_id": 71,
  "photo_file_id": "string",
  "photo_file_size": 78,
  "photo_height": 97,
  "photo_width": 35,
  "text": "string",
  "video_duration": 9,
  "video_file_id": "string",
  "video_file_size": 25,
  "video_height": 81,
  "video_mime_type": "string",
  "video_width": 64
}

send_document(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, filename: str | None = None, caption: str | None = None, parse_mode: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send a document to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • filename – Name of the file as it will be shown in Telegram.

  • caption – Optional caption for the picture.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 16,
  "audio_file_id": "string",
  "audio_file_size": 20,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 6,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 26,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 43,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 26,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 43,
  "from_username": "string",
  "link": "string",
  "location_latitude": 23,
  "location_longitude": 72,
  "media_group_id": "string",
  "message_id": 24,
  "photo_file_id": "string",
  "photo_file_size": 83,
  "photo_height": 54,
  "photo_width": 69,
  "text": "string",
  "video_duration": 5,
  "video_file_id": "string",
  "video_file_size": 87,
  "video_height": 76,
  "video_mime_type": "string",
  "video_width": 70
}

send_location(chat_id: str | int, latitude: float, longitude: float, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send a location to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • latitude – Latitude

  • longitude – Longitude

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 15,
  "audio_file_id": "string",
  "audio_file_size": 7,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 86,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 26,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 25,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 26,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 60,
  "from_username": "string",
  "link": "string",
  "location_latitude": 45,
  "location_longitude": 79,
  "media_group_id": "string",
  "message_id": 99,
  "photo_file_id": "string",
  "photo_file_size": 19,
  "photo_height": 43,
  "photo_width": 69,
  "text": "string",
  "video_duration": 9,
  "video_file_id": "string",
  "video_file_size": 39,
  "video_height": 22,
  "video_mime_type": "string",
  "video_width": 68
}

send_message(chat_id: str | int, text: str, *_, parse_mode: str | None = None, disable_web_page_preview: bool = False, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20, **__) dict[source]#

Send a message to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • text – Text to be sent.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_web_page_preview – If True then web previews for URLs will be disabled.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Request timeout (default: 20 seconds).

Returns:

{
  "audio_duration": 31,
  "audio_file_id": "string",
  "audio_file_size": 78,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 68,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 10,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 4,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 81,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 59,
  "from_username": "string",
  "link": "string",
  "location_latitude": 25,
  "location_longitude": 64,
  "media_group_id": "string",
  "message_id": 17,
  "photo_file_id": "string",
  "photo_file_size": 16,
  "photo_height": 59,
  "photo_width": 62,
  "text": "string",
  "video_duration": 84,
  "video_file_id": "string",
  "video_file_size": 1,
  "video_height": 97,
  "video_mime_type": "string",
  "video_width": 7
}

send_photo(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, caption: str | None = None, parse_mode: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send a picture to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • caption – Optional caption for the picture.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 35,
  "audio_file_id": "string",
  "audio_file_size": 6,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 58,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 44,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 61,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 49,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 24,
  "from_username": "string",
  "link": "string",
  "location_latitude": 49,
  "location_longitude": 47,
  "media_group_id": "string",
  "message_id": 17,
  "photo_file_id": "string",
  "photo_file_size": 34,
  "photo_height": 81,
  "photo_width": 44,
  "text": "string",
  "video_duration": 53,
  "video_file_id": "string",
  "video_file_size": 86,
  "video_height": 31,
  "video_mime_type": "string",
  "video_width": 87
}

send_venue(chat_id: str | int, latitude: float, longitude: float, title: str, address: str, foursquare_id: str | None = None, foursquare_type: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send the address of a venue to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • latitude – Latitude

  • longitude – Longitude

  • title – Venue name.

  • address – Venue address.

  • foursquare_id – Foursquare ID.

  • foursquare_type – Foursquare type.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 15,
  "audio_file_id": "string",
  "audio_file_size": 10,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 43,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 20,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 24,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 48,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 69,
  "from_username": "string",
  "link": "string",
  "location_latitude": 62,
  "location_longitude": 91,
  "media_group_id": "string",
  "message_id": 61,
  "photo_file_id": "string",
  "photo_file_size": 10,
  "photo_height": 64,
  "photo_width": 8,
  "text": "string",
  "video_duration": 9,
  "video_file_id": "string",
  "video_file_size": 10,
  "video_height": 65,
  "video_mime_type": "string",
  "video_width": 35
}

send_video(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, duration: int | None = None, caption: str | None = None, width: int | None = None, height: int | None = None, parse_mode: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send a video to a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • duration – Duration in seconds.

  • caption – Optional caption for the picture.

  • width – Video width.

  • height – Video height.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 95,
  "audio_file_id": "string",
  "audio_file_size": 77,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 97,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 64,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 16,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 45,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 66,
  "from_username": "string",
  "link": "string",
  "location_latitude": 33,
  "location_longitude": 42,
  "media_group_id": "string",
  "message_id": 29,
  "photo_file_id": "string",
  "photo_file_size": 17,
  "photo_height": 84,
  "photo_width": 65,
  "text": "string",
  "video_duration": 40,
  "video_file_id": "string",
  "video_file_size": 64,
  "video_height": 58,
  "video_mime_type": "string",
  "video_width": 13
}

send_video_note(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, duration: int | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send a video note to a chat. As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • duration – Duration in seconds.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 83,
  "audio_file_id": "string",
  "audio_file_size": 74,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 11,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 8,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 42,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 51,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 76,
  "from_username": "string",
  "link": "string",
  "location_latitude": 90,
  "location_longitude": 45,
  "media_group_id": "string",
  "message_id": 58,
  "photo_file_id": "string",
  "photo_file_size": 76,
  "photo_height": 31,
  "photo_width": 84,
  "text": "string",
  "video_duration": 49,
  "video_file_id": "string",
  "video_file_size": 5,
  "video_height": 21,
  "video_mime_type": "string",
  "video_width": 97
}

send_voice(chat_id: str | int, file_id: int | None = None, url: str | None = None, path: str | None = None, caption: str | None = None, duration: float | None = None, parse_mode: str | None = None, disable_notification: bool = False, reply_to_message_id: int | None = None, timeout: float | None = 20) dict[source]#

Send audio to a chat as a voice file. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document).

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • file_id – Set it if the file already exists on Telegram servers and has a file_id. Note that you’ll have to specify either file_id, url or path.

  • url – Set it if you want to send a file from a remote URL. Note that you’ll have to specify either file_id, url or path.

  • path – Set it if you want to send a file from the local filesystem. Note that you’ll have to specify either file_id, url or path.

  • caption – Optional caption for the picture.

  • duration – Duration of the voice in seconds.

  • parse_mode – Set to ‘Markdown’ or ‘HTML’ to send either Markdown or HTML content.

  • disable_notification – If True then no notification will be sent to the users.

  • reply_to_message_id – If set then the message will be sent as a response to the specified message.

  • timeout – Upload timeout (default: 20 seconds)

Returns:

{
  "audio_duration": 3,
  "audio_file_id": "string",
  "audio_file_size": 96,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 77,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 32,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 74,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 48,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 66,
  "from_username": "string",
  "link": "string",
  "location_latitude": 97,
  "location_longitude": 53,
  "media_group_id": "string",
  "message_id": 61,
  "photo_file_id": "string",
  "photo_file_size": 50,
  "photo_height": 35,
  "photo_width": 12,
  "text": "string",
  "video_duration": 18,
  "video_file_id": "string",
  "video_file_size": 31,
  "video_height": 80,
  "video_mime_type": "string",
  "video_width": 11
}

set_chat_description(chat_id: str | int, description: str, timeout: float | None = 20)[source]#

Set the description of a channel/group.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • description – New chat description.

  • timeout – Request timeout (default: 20 seconds)

set_chat_photo(chat_id: str | int, path: str, timeout: float | None = 20)[source]#

Set the photo of a channel/group.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • path – Path of the new image.

  • timeout – Request timeout (default: 20 seconds)

set_chat_title(chat_id: str | int, title: str, timeout: float | None = 20)[source]#

Set the title of a channel/group.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • title – New chat title.

  • timeout – Request timeout (default: 20 seconds)

start()#

Start the plugin.

stop()[source]#

Stop the plugin.

unban_chat_member(chat_id: str | int, user_id: int, timeout: float | None = 20)[source]#

Lift the ban from a chat member.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • user_id – Unique user ID.

  • timeout – Request timeout (default: 20 seconds)

unpin_chat_message(chat_id: str | int, timeout: float | None = 20)[source]#

Unpin the message of a chat.

Parameters:
  • chat_id

    Chat ID. Can be either a numerical ID or a unique identifier in the format @channelname. In order to get your own Telegram chat_id open a conversation with @IDBot and type /start followed by /getid. Similar procedures also exist to get a group or channel chat_id - just Google for “Telegram get channel/group chat_id”.

  • timeout – Request timeout (default: 20 seconds)

wait_stop(timeout=None)#

Wait until a stop event is received.