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": 2, "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": 59 }
- 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": 6, "audio_file_id": "string", "audio_file_size": 95, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 76, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 94, "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": 74, "from_firstname": "string", "from_lastname": "string", "from_user_id": 27, "from_username": "string", "link": "string", "location_latitude": 23, "location_longitude": 12, "media_group_id": "string", "message_id": 14, "photo_file_id": "string", "photo_file_size": 41, "photo_height": 85, "photo_width": 58, "text": "string", "video_duration": 80, "video_file_id": "string", "video_file_size": 90, "video_height": 55, "video_mime_type": "string", "video_width": 97 }
- 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": 58, "audio_file_id": "string", "audio_file_size": 89, "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": 41, "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": 71, "from_firstname": "string", "from_lastname": "string", "from_user_id": 2, "from_username": "string", "link": "string", "location_latitude": 40, "location_longitude": 45, "media_group_id": "string", "message_id": 43, "photo_file_id": "string", "photo_file_size": 64, "photo_height": 18, "photo_width": 93, "text": "string", "video_duration": 1, "video_file_id": "string", "video_file_size": 87, "video_height": 56, "video_mime_type": "string", "video_width": 26 }
- 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": 60, "audio_file_id": "string", "audio_file_size": 31, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 23, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 76, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 92, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 21, "from_firstname": "string", "from_lastname": "string", "from_user_id": 99, "from_username": "string", "link": "string", "location_latitude": 49, "location_longitude": 76, "media_group_id": "string", "message_id": 89, "photo_file_id": "string", "photo_file_size": 96, "photo_height": 36, "photo_width": 5, "text": "string", "video_duration": 37, "video_file_id": "string", "video_file_size": 74, "video_height": 4, "video_mime_type": "string", "video_width": 59 }
- 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": 42, "audio_file_id": "string", "audio_file_size": 8, "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": 63, "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": 13, "from_firstname": "string", "from_lastname": "string", "from_user_id": 75, "from_username": "string", "link": "string", "location_latitude": 90, "location_longitude": 30, "media_group_id": "string", "message_id": 48, "photo_file_id": "string", "photo_file_size": 74, "photo_height": 45, "photo_width": 61, "text": "string", "video_duration": 97, "video_file_id": "string", "video_file_size": 1, "video_height": 42, "video_mime_type": "string", "video_width": 36 }
- 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": 49, "audio_file_id": "string", "audio_file_size": 90, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 69, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 46, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 2, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 2, "from_firstname": "string", "from_lastname": "string", "from_user_id": 10, "from_username": "string", "link": "string", "location_latitude": 7, "location_longitude": 5, "media_group_id": "string", "message_id": 8, "photo_file_id": "string", "photo_file_size": 25, "photo_height": 52, "photo_width": 44, "text": "string", "video_duration": 93, "video_file_id": "string", "video_file_size": 4, "video_height": 76, "video_mime_type": "string", "video_width": 75 }
- 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": 9, "audio_file_id": "string", "audio_file_size": 90, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 79, "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": 7, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 69, "from_firstname": "string", "from_lastname": "string", "from_user_id": 69, "from_username": "string", "link": "string", "location_latitude": 67, "location_longitude": 77, "media_group_id": "string", "message_id": 11, "photo_file_id": "string", "photo_file_size": 55, "photo_height": 54, "photo_width": 58, "text": "string", "video_duration": 5, "video_file_id": "string", "video_file_size": 62, "video_height": 49, "video_mime_type": "string", "video_width": 69 }
- 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": 31, "audio_file_id": "string", "audio_file_size": 85, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 84, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 7, "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": 12, "from_firstname": "string", "from_lastname": "string", "from_user_id": 34, "from_username": "string", "link": "string", "location_latitude": 72, "location_longitude": 9, "media_group_id": "string", "message_id": 25, "photo_file_id": "string", "photo_file_size": 63, "photo_height": 3, "photo_width": 71, "text": "string", "video_duration": 89, "video_file_id": "string", "video_file_size": 98, "video_height": 4, "video_mime_type": "string", "video_width": 66 }
- 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": 17, "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": 73, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 71, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 38, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 87, "from_firstname": "string", "from_lastname": "string", "from_user_id": 40, "from_username": "string", "link": "string", "location_latitude": 90, "location_longitude": 63, "media_group_id": "string", "message_id": 23, "photo_file_id": "string", "photo_file_size": 76, "photo_height": 44, "photo_width": 36, "text": "string", "video_duration": 2, "video_file_id": "string", "video_file_size": 77, "video_height": 56, "video_mime_type": "string", "video_width": 36 }
- 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": 65, "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": 86, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 34, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 79, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 92, "from_firstname": "string", "from_lastname": "string", "from_user_id": 37, "from_username": "string", "link": "string", "location_latitude": 71, "location_longitude": 95, "media_group_id": "string", "message_id": 65, "photo_file_id": "string", "photo_file_size": 39, "photo_height": 82, "photo_width": 29, "text": "string", "video_duration": 31, "video_file_id": "string", "video_file_size": 61, "video_height": 56, "video_mime_type": "string", "video_width": 83 }
- 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": 28, "audio_file_id": "string", "audio_file_size": 35, "audio_mime_type": "string", "audio_performer": "string", "audio_title": "string", "caption": "string", "chat_firstname": "string", "chat_id": 67, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 30, "contact_vcard": "string", "creation_date": "date", "document_file_id": "string", "document_file_name": "string", "document_file_size": 52, "document_mime_type": "string", "edit_date": "date", "forward_date": "date", "forward_from_message_id": 78, "from_firstname": "string", "from_lastname": "string", "from_user_id": 13, "from_username": "string", "link": "string", "location_latitude": 83, "location_longitude": 58, "media_group_id": "string", "message_id": 97, "photo_file_id": "string", "photo_file_size": 86, "photo_height": 18, "photo_width": 39, "text": "string", "video_duration": 15, "video_file_id": "string", "video_file_size": 7, "video_height": 1, "video_mime_type": "string", "video_width": 38 }
- 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": 6, "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": 83, "chat_lastname": "string", "chat_username": "string", "contact_first_name": "string", "contact_last_name": "string", "contact_phone_number": "string", "contact_user_id": 52, "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": 59, "from_firstname": "string", "from_lastname": "string", "from_user_id": 39, "from_username": "string", "link": "string", "location_latitude": 3, "location_longitude": 76, "media_group_id": "string", "message_id": 24, "photo_file_id": "string", "photo_file_size": 58, "photo_height": 75, "photo_width": 1, "text": "string", "video_duration": 42, "video_file_id": "string", "video_file_size": 26, "video_height": 31, "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.
- 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.