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:
Open a Telegram conversation with the @BotFather.
Send
/start
followed by/newbot
. Choose a display name and a username for your bot.Copy the provided API token in the configuration of this plugin.
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:
Open a Telegram conversation with the @BotFather.
Send
/start
followed by/newbot
. Choose a display name and a username for your bot.Copy the provided API token in the configuration of this plugin.
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": true, "language_code": "string", "last_name": "string", "link": "string", "user_id": 52, "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": 91 }
- 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)
- 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
orpath
.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
orpath
.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
orpath
.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": 46, "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": 86, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 19, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 46, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 27, "from_firstname": "string", "from_lastname": "string", "from_user_id": 40, "from_username": "string", "link": "string", "location_latitude": 93, "location_longitude": 80, "media_group_id": "string", "message_id": 33, "photo_file_id": "string", "photo_file_size": 80, "photo_height": 9, "photo_width": 19, "text": "string", "video_duration": 48, "video_file_id": "string", "video_file_size": 31, "video_height": 69, "video_mime_type": "string", "video_width": 22 }
- 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
orpath
.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
orpath
.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
orpath
.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": 73, "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": 73, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 82, "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": 13, "from_firstname": "string", "from_lastname": "string", "from_user_id": 84, "from_username": "string", "link": "string", "location_latitude": 27, "location_longitude": 15, "media_group_id": "string", "message_id": 23, "photo_file_id": "string", "photo_file_size": 2, "photo_height": 95, "photo_width": 74, "text": "string", "video_duration": 40, "video_file_id": "string", "video_file_size": 62, "video_height": 76, "video_mime_type": "string", "video_width": 22 }
- 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": 52, "audio_file_id": "string", "audio_file_size": 27, "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": 89, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 54, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 99, "from_firstname": "string", "from_lastname": "string", "from_user_id": 35, "from_username": "string", "link": "string", "location_latitude": 27, "location_longitude": 55, "media_group_id": "string", "message_id": 15, "photo_file_id": "string", "photo_file_size": 32, "photo_height": 62, "photo_width": 39, "text": "string", "video_duration": 93, "video_file_id": "string", "video_file_size": 45, "video_height": 27, "video_mime_type": "string", "video_width": 58 }
- 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
orpath
.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
orpath
.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
orpath
.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": 67, "audio_file_id": "string", "audio_file_size": 18, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 61, "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": 45, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 58, "from_firstname": "string", "from_lastname": "string", "from_user_id": 44, "from_username": "string", "link": "string", "location_latitude": 28, "location_longitude": 44, "media_group_id": "string", "message_id": 61, "photo_file_id": "string", "photo_file_size": 48, "photo_height": 53, "photo_width": 93, "text": "string", "video_duration": 77, "video_file_id": "string", "video_file_size": 69, "video_height": 29, "video_mime_type": "string", "video_width": 23 }
- 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": 2, "audio_file_id": "string", "audio_file_size": 57, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 85, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 13, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 39, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 58, "from_firstname": "string", "from_lastname": "string", "from_user_id": 53, "from_username": "string", "link": "string", "location_latitude": 27, "location_longitude": 70, "media_group_id": "string", "message_id": 2, "photo_file_id": "string", "photo_file_size": 82, "photo_height": 54, "photo_width": 54, "text": "string", "video_duration": 37, "video_file_id": "string", "video_file_size": 18, "video_height": 91, "video_mime_type": "string", "video_width": 29 }
- 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": 47, "audio_file_id": "string", "audio_file_size": 56, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 40, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 63, "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": 65, "from_firstname": "string", "from_lastname": "string", "from_user_id": 78, "from_username": "string", "link": "string", "location_latitude": 1, "location_longitude": 74, "media_group_id": "string", "message_id": 16, "photo_file_id": "string", "photo_file_size": 65, "photo_height": 39, "photo_width": 41, "text": "string", "video_duration": 47, "video_file_id": "string", "video_file_size": 83, "video_height": 67, "video_mime_type": "string", "video_width": 56 }
- 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
orpath
.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
orpath
.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
orpath
.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": 60, "audio_file_id": "string", "audio_file_size": 48, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 81, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 58, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 8, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 47, "from_firstname": "string", "from_lastname": "string", "from_user_id": 81, "from_username": "string", "link": "string", "location_latitude": 6, "location_longitude": 20, "media_group_id": "string", "message_id": 80, "photo_file_id": "string", "photo_file_size": 71, "photo_height": 68, "photo_width": 5, "text": "string", "video_duration": 27, "video_file_id": "string", "video_file_size": 97, "video_height": 10, "video_mime_type": "string", "video_width": 56 }
- 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": 7, "audio_file_id": "string", "audio_file_size": 39, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 92, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 63, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 82, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 25, "from_firstname": "string", "from_lastname": "string", "from_user_id": 18, "from_username": "string", "link": "string", "location_latitude": 57, "location_longitude": 67, "media_group_id": "string", "message_id": 2, "photo_file_id": "string", "photo_file_size": 44, "photo_height": 96, "photo_width": 41, "text": "string", "video_duration": 82, "video_file_id": "string", "video_file_size": 6, "video_height": 37, "video_mime_type": "string", "video_width": 86 }
- 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
orpath
.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
orpath
.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
orpath
.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": 79, "audio_file_id": "string", "audio_file_size": 28, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 75, "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": 57, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 44, "from_firstname": "string", "from_lastname": "string", "from_user_id": 80, "from_username": "string", "link": "string", "location_latitude": 59, "location_longitude": 47, "media_group_id": "string", "message_id": 3, "photo_file_id": "string", "photo_file_size": 85, "photo_height": 94, "photo_width": 57, "text": "string", "video_duration": 55, "video_file_id": "string", "video_file_size": 14, "video_height": 33, "video_mime_type": "string", "video_width": 20 }
- 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
orpath
.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
orpath
.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
orpath
.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": 64, "audio_file_id": "string", "audio_file_size": 11, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 40, "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": 76, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 81, "from_firstname": "string", "from_lastname": "string", "from_user_id": 20, "from_username": "string", "link": "string", "location_latitude": 50, "location_longitude": 48, "media_group_id": "string", "message_id": 31, "photo_file_id": "string", "photo_file_size": 97, "photo_height": 46, "photo_width": 2, "text": "string", "video_duration": 50, "video_file_id": "string", "video_file_size": 38, "video_height": 26, "video_mime_type": "string", "video_width": 42 }
- 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
orpath
.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
orpath
.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
orpath
.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": 45, "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": 73, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 72, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 23, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 85, "from_firstname": "string", "from_lastname": "string", "from_user_id": 40, "from_username": "string", "link": "string", "location_latitude": 9, "location_longitude": 4, "media_group_id": "string", "message_id": 2, "photo_file_id": "string", "photo_file_size": 14, "photo_height": 5, "photo_width": 46, "text": "string", "video_duration": 64, "video_file_id": "string", "video_file_size": 31, "video_height": 83, "video_mime_type": "string", "video_width": 84 }
- 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)
- 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)