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": 9,
    "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": 15
}

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": 60,
  "audio_file_id": "string",
  "audio_file_size": 65,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 88,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 16,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 80,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 66,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 55,
  "from_username": "string",
  "link": "string",
  "location_latitude": 6,
  "location_longitude": 12,
  "media_group_id": "string",
  "message_id": 31,
  "photo_file_id": "string",
  "photo_file_size": 69,
  "photo_height": 85,
  "photo_width": 49,
  "text": "string",
  "video_duration": 9,
  "video_file_id": "string",
  "video_file_size": 5,
  "video_height": 29,
  "video_mime_type": "string",
  "video_width": 93
}

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": 62,
  "audio_file_id": "string",
  "audio_file_size": 12,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 47,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 41,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 98,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 35,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 20,
  "from_username": "string",
  "link": "string",
  "location_latitude": 30,
  "location_longitude": 60,
  "media_group_id": "string",
  "message_id": 25,
  "photo_file_id": "string",
  "photo_file_size": 34,
  "photo_height": 19,
  "photo_width": 32,
  "text": "string",
  "video_duration": 2,
  "video_file_id": "string",
  "video_file_size": 16,
  "video_height": 89,
  "video_mime_type": "string",
  "video_width": 90
}

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": 36,
  "audio_file_id": "string",
  "audio_file_size": 5,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 87,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 47,
  "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": 66,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 45,
  "from_username": "string",
  "link": "string",
  "location_latitude": 73,
  "location_longitude": 12,
  "media_group_id": "string",
  "message_id": 85,
  "photo_file_id": "string",
  "photo_file_size": 93,
  "photo_height": 46,
  "photo_width": 65,
  "text": "string",
  "video_duration": 30,
  "video_file_id": "string",
  "video_file_size": 42,
  "video_height": 93,
  "video_mime_type": "string",
  "video_width": 54
}

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": 55,
  "audio_file_id": "string",
  "audio_file_size": 9,
  "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": 49,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 3,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 16,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 75,
  "from_username": "string",
  "link": "string",
  "location_latitude": 88,
  "location_longitude": 63,
  "media_group_id": "string",
  "message_id": 41,
  "photo_file_id": "string",
  "photo_file_size": 34,
  "photo_height": 90,
  "photo_width": 83,
  "text": "string",
  "video_duration": 20,
  "video_file_id": "string",
  "video_file_size": 93,
  "video_height": 18,
  "video_mime_type": "string",
  "video_width": 87
}

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": 83,
  "audio_file_id": "string",
  "audio_file_size": 79,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 33,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 14,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 20,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 92,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 20,
  "from_username": "string",
  "link": "string",
  "location_latitude": 90,
  "location_longitude": 4,
  "media_group_id": "string",
  "message_id": 31,
  "photo_file_id": "string",
  "photo_file_size": 99,
  "photo_height": 43,
  "photo_width": 58,
  "text": "string",
  "video_duration": 9,
  "video_file_id": "string",
  "video_file_size": 35,
  "video_height": 11,
  "video_mime_type": "string",
  "video_width": 52
}

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": 15,
  "audio_file_id": "string",
  "audio_file_size": 66,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 91,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 65,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 85,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 54,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 21,
  "from_username": "string",
  "link": "string",
  "location_latitude": 95,
  "location_longitude": 33,
  "media_group_id": "string",
  "message_id": 41,
  "photo_file_id": "string",
  "photo_file_size": 29,
  "photo_height": 75,
  "photo_width": 67,
  "text": "string",
  "video_duration": 56,
  "video_file_id": "string",
  "video_file_size": 78,
  "video_height": 89,
  "video_mime_type": "string",
  "video_width": 73
}

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": 52,
  "audio_file_id": "string",
  "audio_file_size": 80,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 82,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 61,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 48,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 66,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 2,
  "from_username": "string",
  "link": "string",
  "location_latitude": 17,
  "location_longitude": 31,
  "media_group_id": "string",
  "message_id": 37,
  "photo_file_id": "string",
  "photo_file_size": 72,
  "photo_height": 43,
  "photo_width": 63,
  "text": "string",
  "video_duration": 46,
  "video_file_id": "string",
  "video_file_size": 56,
  "video_height": 6,
  "video_mime_type": "string",
  "video_width": 63
}

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": 76,
  "audio_file_id": "string",
  "audio_file_size": 80,
  "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": 60,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 9,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 59,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 31,
  "from_username": "string",
  "link": "string",
  "location_latitude": 49,
  "location_longitude": 80,
  "media_group_id": "string",
  "message_id": 7,
  "photo_file_id": "string",
  "photo_file_size": 27,
  "photo_height": 42,
  "photo_width": 3,
  "text": "string",
  "video_duration": 80,
  "video_file_id": "string",
  "video_file_size": 16,
  "video_height": 73,
  "video_mime_type": "string",
  "video_width": 56
}

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": 18,
  "audio_file_id": "string",
  "audio_file_size": 62,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 53,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 93,
  "contact_vcard": "string",
  "creation_date": "date",
  "document_file_id": "string",
  "document_file_name": "string",
  "document_file_size": 55,
  "document_mime_type": "string",
  "edit_date": "date",
  "forward_date": "date",
  "forward_from_message_id": 97,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 58,
  "from_username": "string",
  "link": "string",
  "location_latitude": 18,
  "location_longitude": 49,
  "media_group_id": "string",
  "message_id": 65,
  "photo_file_id": "string",
  "photo_file_size": 6,
  "photo_height": 54,
  "photo_width": 43,
  "text": "string",
  "video_duration": 17,
  "video_file_id": "string",
  "video_file_size": 24,
  "video_height": 4,
  "video_mime_type": "string",
  "video_width": 96
}

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": 1,
  "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": 38,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 6,
  "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": 56,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 36,
  "from_username": "string",
  "link": "string",
  "location_latitude": 24,
  "location_longitude": 84,
  "media_group_id": "string",
  "message_id": 81,
  "photo_file_id": "string",
  "photo_file_size": 60,
  "photo_height": 69,
  "photo_width": 3,
  "text": "string",
  "video_duration": 77,
  "video_file_id": "string",
  "video_file_size": 78,
  "video_height": 88,
  "video_mime_type": "string",
  "video_width": 8
}

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": 44,
  "audio_file_id": "string",
  "audio_file_size": 47,
  "audio_mime_type": "string",
  "audio_performer": "string",
  "audio_title": "string",
  "caption": "string",
  "chat_firstname": "string",
  "chat_id": 82,
  "chat_lastname": "string",
  "chat_username": "string",
  "contact_first_name": "string",
  "contact_last_name": "string",
  "contact_phone_number": "string",
  "contact_user_id": 68,
  "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": 27,
  "from_firstname": "string",
  "from_lastname": "string",
  "from_user_id": 7,
  "from_username": "string",
  "link": "string",
  "location_latitude": 5,
  "location_longitude": 36,
  "media_group_id": "string",
  "message_id": 52,
  "photo_file_id": "string",
  "photo_file_size": 72,
  "photo_height": 96,
  "photo_width": 6,
  "text": "string",
  "video_duration": 66,
  "video_file_id": "string",
  "video_file_size": 89,
  "video_height": 68,
  "video_mime_type": "string",
  "video_width": 73
}

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.