twx.botapi
— Unofficial Telegram Bot API Client¶
Telegram Bot API Types¶
User¶
ChatMember¶
Chat¶
-
class
twx.botapi.
Chat
[source]¶ This object represents a chat.
-
id
¶ int – Unique identifier for this chat, not exceeding 1e13 by absolute value
-
type
¶ str – Type of chat, can be either “private”, or “group”, or “channel”
-
title
¶ str – Optional. Title, for channels and group chats
-
username
¶ str – Optional. Username, for private chats and channels if available
-
first_name
¶ str – Optional. First name of the other party in a private chat
-
last_name
¶ str – Optional. Last name of the other party in a private chat
-
Message¶
-
class
twx.botapi.
Message
[source]¶ This object represents a message.
-
message_id
¶ int – Unique message identifier
-
from
¶ User – Optional. Sender, can be empty for messages sent to channels
-
date
¶ int – Date the message was sent in Unix time
-
chat
¶ Chat – Conversation the message belongs to
-
forward_from
¶ User – Optional. For forwarded messages, sender of the original message
-
forward_from_chat
¶ Chat – Optional. For messages forwarded from a channel, information about the original channel
-
forward_date
¶ int – Optional. For forwarded messages, date the original message was sent in Unix time
-
reply_to_message
¶ Message – Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
-
edit_date
¶ int – Optional. Date the message was last edited in Unix time
-
text
¶ str – Optional. For text messages, the actual UTF-8 text of the message
-
entities
¶ Sequence[MessageEntity] – *Optional.*For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
-
audio
¶ Audio – Optional. Message is an audio file, information about the file
-
document
¶ Document – Optional. Message is a general file, information about the file
-
photo
¶ Sequence[PhotoSize] – Optional. Message is a photo, available sizes of the photo
-
sticker
¶ Sticker – Optional. Message is a sticker, information about the sticker
-
video
¶ Video – Optional. Message is a video, information about the video
-
voice
¶ Voice – Optional. Message is a voice message, information about the file
str – Optional. Caption for the photo or video
-
contact
¶ Contact – Optional. Message is a shared contact, information about the contact
-
location
¶ Location – Optional. Message is a shared location, information about the location
-
venue
¶ Venue – Optional. Message is a venue, information about the venue
-
new_chat_member
¶ User – Optional. A new member was added to the group, information about them (this member may be bot itself)
-
left_chat_member
¶ User – Optional. A member was removed from the group, information about them (this member may be bot itself)
-
new_chat_title
¶ str – Optional. A group title was changed to this value
-
new_chat_photo
¶ Sequence[PhotoSize] – Optional. A group photo was change to this value
-
delete_chat_photo
¶ bool – Optional. Informs that the group photo was deleted
-
group_chat_created
¶ bool – Optional. Informs that the group has been created
-
supergroup_chat_created
¶ bool – Optional. Service message: the supergroup has been created
-
channel_chat_created
¶ bool – Optional. Service message: the channel has been created
-
migrate_to_chat_id
¶ int – Optional. The group has been migrated to a supergroup with the specified identifier, not exceeding 1e13 by absolute value
-
migrate_from_chat_id
¶ int – Optional. The supergroup has been migrated from a group with the specified identifier, not exceeding 1e13 by absolute value
-
pinned_message
¶ Message – Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
-
MessageEntity¶
-
class
twx.botapi.
MessageEntity
[source]¶ This object represents a chat.
-
type
¶ str – Type of the entity. One of mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)
-
offset
¶ int – Offset in UTF-16 code units to the start of the entity
-
length
¶ int – Length of the entity in UTF-16 code units
-
url
¶ str – Optional. For “text_link” only, url that will be opened after user taps on the text
-
user (User0
Optional. For “text_mention” only, the mentioned user
-
PhotoSize¶
Audio¶
-
class
twx.botapi.
Audio
[source]¶ This object represents a generic audio file (not voice note).
-
file_id
¶ str – Unique identifier for this file
-
duration
¶ int – Duration of the audio in seconds as defined by sender
-
performer
¶ str – Optional. Performer of the audio as defined by sender or by audio tags
-
title
¶ str – Optional. Title of the audio as defined by sender or by audio tags
-
mime_type
¶ str – Optional. MIME type of the file as defined by sender
-
file_size
¶ int – Optional. File size
-
Document¶
-
class
twx.botapi.
Document
[source]¶ This object represents a general file (as opposed to photos and audio files).
-
file_id
¶ str – Unique file identifier
-
thumb
¶ PhotoSize – Optional. Document thumbnail as defined by sender
-
file_name
¶ str – Optional. Original filename as defined by sender
-
mime_type
¶ str – Optional. MIME type of the file as defined by sender
-
file_size
¶ int – Optional. File size
-
Sticker¶
-
class
twx.botapi.
Sticker
[source]¶ This object represents a sticker.
-
file_id
¶ str – Unique identifier for this file
-
width
¶ int – Sticker width
-
height
¶ int – Sticker height
-
thumb
¶ PhotoSize – Optional. Sticker thumbnail in .webp or .jpg format
-
emoji
¶ str – Optional. Emoji associated with the sticker
-
file_size
¶ int – Optional. File size
-
Video¶
-
class
twx.botapi.
Video
[source]¶ This object represents a video file.
-
file_id
¶ str – Unique identifier for this file
-
width
¶ int – Video width as defined by sender
-
height
¶ int – Video height as defined by sender
-
duration
¶ int – Duration of the video in seconds as defined by sender
-
thumb
¶ PhotoSize – Optional. Video thumbnail
-
mime_type
¶ str – Optional. Mime type of a file as defined by sender
-
file_size
¶ int – Optional. File size
-
Voice¶
-
class
twx.botapi.
Voice
[source]¶ This object represents an voice node audio file.
-
file_id
¶ str – Unique identifier for this file
-
duration
¶ int – Duration of the audio in seconds as defined by sender
-
mime_type
¶ str – Optional. MIME type of the file as defined by sender
-
file_size
¶ int – Optional. File size
-
Contact¶
Location¶
Venue¶
Update¶
-
class
twx.botapi.
Update
[source]¶ This object represents an incoming update.
-
update_id
¶ int – The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
-
message
¶ Message – Optional. New incoming message of any kind — text, photo, sticker, etc.
-
edited_message
¶ Message – Optional. New version of a message that is known to the bot and was edited.
-
inline_query
¶ InlineQuery – Optional. New incoming inline query
-
chosen_inline_result
¶ ChosenInlineResult – Optional. The result of a inline query that was chosen by a user and sent to their chat partner
-
callback_query
¶ CallbackQuery – Optional. New incoming callback query
-
InputFile¶
-
class
twx.botapi.
InputFile
[source]¶ This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser.
-
form
¶ str – the form used to submit (e.g. ‘photo’)
-
file_info
¶ InputFileInfo – The file metadata required
Example: fp = open('foo.png', 'rb') file_info = InputFileInfo('foo.png', fp, 'image/png') InputFile('photo', file_info) bot.send_photo(chat_id=12345678, photo=InputFile)
Note
While creating the FileInput currently requires a reasonable amount of preparation just to send a file. This class will be extended in the future to make the process easier.
-
InputFileInfo¶
-
class
twx.botapi.
InputFileInfo
[source]¶ This object represents the contents of a file to be uploaded. Must be posted using multipart/form-data in the usual way that files are uploaded via the browser.
-
file_name
¶ str – The full file name
-
fp
¶ file object – File object obtained via open()
-
mime_type
¶ str – Optional. Mimetype to use when sending.
-
UserProfilePhotos¶
File¶
-
class
twx.botapi.
File
[source]¶ This object represents a file ready to be downloaded.
-
file_id
¶ str – Unique identifier for this file
-
file_size
¶ int – Optional. File size, if known
-
file_path
¶ str – Optional. File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file. It is guaranteed that the link will be valid for at least 1 hour.
-
ReplyKeyboardMarkup¶
-
class
twx.botapi.
ReplyKeyboardMarkup
[source]¶ This object represents a custom keyboard with reply options (see Introduction to bots for details and examples).
-
keyboard
¶ Sequence[Sequence[KeyboardButton or str]] – Array of button rows, each represented by an Array of KeyboardButton objects or strings
-
resize_keyboard
¶ bool – Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app’s standard keyboard.
-
one_time_keyboard
¶ bool – Optional. Requests clients to hide the keyboard as soon as it’s been used. Defaults to false.
-
selective
¶ bool – Optional. Use this parameter if you want to show the keyboard to specific users only. Targets:
- users that are @mentioned in the text of the Message object;
- if the bot’s message is a reply (has reply_to_message_id), sender of the original message.
Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.
Example: keyboard = [ ['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0'] ] reply_markup = ReplyKeyboardMarkup.create(keyboard) bot.send_message(12345678, 'testing reply_markup', reply_markup=reply_markup)
-
ReplyKeyboardHide¶
-
class
twx.botapi.
ReplyKeyboardHide
[source]¶ - Upon receiving a message with this object, Telegram clients will hide the current custom keyboard and
- display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard
is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the
user presses a button (see
ReplyKeyboardMarkup
).
-
hide_keyboard
¶ True
– Requests clients to hide the custom keyboard
-
selective
¶ bool – Optional. Use this parameter if you want to hide keyboard for specific users only. Targets:
- users that are @mentioned in the text of the Message object;
- if the bot’s message is a reply (has reply_to_message_id), sender of the original message.
Example: A user votes in a poll, bot returns confirmation message in reply to the vote and hides keyboard for that user, while still showing the keyboard with poll options to users who haven’t voted yet.
ForceReply¶
-
class
twx.botapi.
ForceReply
[source]¶ - Upon receiving a message with this object, Telegram clients will display a reply interface to the user
- (act as if the user has selected the bot‘s message and tapped ’Reply’). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
-
force_reply
¶ True
– Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply’
-
selective
¶ bool – Optional. Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot’s message is a reply (has reply_to_message_id), sender of the original message.
Example: A poll bot for groups runs in privacy mode (only receives commands, replies to its messages and mentions). There could be two ways to create a new poll:
- Explain the user how to send a command with parameters (e.g. /newpoll question answer1 answer2). May be appealing for hardcore users but lacks modern day polish.
- Guide the user through a step-by-step process. ‘Please send me your question’, ‘Cool, now let’s add the first answer option‘, ’Great. Keep adding answer options, then send /done when you‘re ready’.
The last option is definitely more attractive. And if you use ForceReply in your bot‘s questions, it will receive the user’s answers even if it only receives replies, commands and mentions — without any extra work for the user.
KeyboardButton¶
-
class
twx.botapi.
KeyboardButton
[source]¶ - This object represents one button of the reply keyboard. For simple text buttons String can be used instead
- of this object to specify text of the button. Optional fields are mutually exclusive.
-
text
¶ str – Unique identifier for this file
-
request_contact
¶ bool – Optional. If True, the user’s phone number will be sent as a contact when the button is pressed. Available in private chats only
-
request_location
¶ bool – Optional. If True, the user’s current location will be sent when the button is pressed. Available in private chats only
Inline Types¶
InlineQuery¶
-
class
twx.botapi.
InlineQuery
[source]¶ - This object represents an incoming inline query. When the user sends an empty query,
- your bot could return some default or trending results.
-
id
¶ str – Unique identifier for this query
-
sender
¶ User – Sender
-
location
¶ Location – Optional. Sender location, only for bots that request user location
-
query
¶ str – Text of the query
-
offset
¶ str – Offset of the results to be returned, can be controlled by the bot
ChosenInlineResult¶
-
class
twx.botapi.
ChosenInlineResult
[source]¶ - This object represents an incoming inline query. When the user sends an empty query,
- your bot could return some default or trending results.
-
result_id
¶ str – The unique identifier for the result that was chosen.
-
sender
¶ User – The user that chose the result.
-
location
¶ Location – Optional. Sender location, only for bots that require user location
-
inline_message_id
¶ str – Optional. Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.
-
query
¶ str – The query that was used to obtain the result.
CallbackQuery¶
-
class
twx.botapi.
CallbackQuery
[source]¶ - This object represents an incoming callback query from a callback button in an inline keyboard. If
- the button that originated the query was attached to a message sent by the bot, the field message will be presented. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be presented.
-
id
¶ str – Unique identifier for this query.
-
sender
¶ User – Sender.
-
message
¶ Message – Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
-
inline_message_id
¶ str – Optional. Identifier of the message sent via the bot in inline mode, that originated the query
-
data
¶ str – Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
InlineKeyboardMarkup¶
-
class
twx.botapi.
InlineKeyboardMarkup
(inline_keyboard)[source]¶ This object represents an inline keyboard that appears right next to the message it belongs to.
-
inline_keyboard
¶ Sequence[Sequence[InlineKeyboardButton]] – Array of button rows, each represented by an Array of InlineKeyboardButton objects
-
InlineKeyboardButton¶
-
class
twx.botapi.
InlineKeyboardButton
(text, url=None, callback_data=None, switch_inline_query=None)[source]¶ This object represents one button of an inline keyboard. You must use exactly one of the optional fields.
-
text
¶ str – Label text on the button
-
url
¶ str – Optional. HTTP url to be opened when button is pressed
-
callback_data
¶ str – Optional. Data to be sent in a callback query to the bot when button is pressed
-
switch_inline_query
¶ str – Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm… actions – in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
-
Inline Query Return Types¶
InlineQueryResultArticle¶
-
class
twx.botapi.
InlineQueryResultArticle
(id, title, input_message_content, reply_markup=None, url=None, hide_url=None, description=None, thumb_url=None, thumb_width=None, thumb_height=None)[source]¶ Represents a link to an article or web page.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
title
¶ str – Title of the result
-
input_message_content
¶ InputMessageContent – Content of the message to be sent
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
url
¶ str – Optional. URL of the result
-
hide_url
¶ bool – Optional. Pass True, if you don’t want the URL to be shown in the message
-
description
¶ str – Optional. Short description of the result
-
thumb_url
¶ str – Optional. Url of the thumbnail for the result
-
thumb_width
¶ int – Optional. Thumbnail width
-
thumb_height
¶ int – Optional. Thumbnail height
-
InlineQueryResultPhoto¶
-
class
twx.botapi.
InlineQueryResultPhoto
(id, photo_url, mime_type=None, photo_width=None, photo_height=None, thumb_url=None, title=None, description=None, caption=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can provide message_text to send it instead of photo.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
photo_url
¶ str – A valid URL of the photo. Photo size must not exceed 5MB
-
mime_type
¶ str – Optional. MIME type of the photo, defaults to image/jpeg
-
photo_width
¶ int – Optional. Width of the photo
-
photo_height
¶ int – Optional. Height of the photo
-
thumb_url
¶ str – Optional. URL of the thumbnail for the photo
-
title
¶ str – Optional. Title for the result
-
description
¶ str – Optional. Short description of the result
str – Optional. Caption of the photo to be sent, 0-200 characters
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
InlineQueryResultCachedPhoto¶
-
class
twx.botapi.
InlineQueryResultPhoto
(id, photo_url, mime_type=None, photo_width=None, photo_height=None, thumb_url=None, title=None, description=None, caption=None, input_message_content=None, reply_markup=None)[source] Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can provide message_text to send it instead of photo.
-
id
str – Unique identifier for this result, 1-64 bytes
-
photo_url
str – A valid URL of the photo. Photo size must not exceed 5MB
-
mime_type
str – Optional. MIME type of the photo, defaults to image/jpeg
-
photo_width
int – Optional. Width of the photo
-
photo_height
int – Optional. Height of the photo
-
thumb_url
str – Optional. URL of the thumbnail for the photo
-
title
str – Optional. Title for the result
-
description
str – Optional. Short description of the result
-
caption
str – Optional. Caption of the photo to be sent, 0-200 characters
-
reply_markup
InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
InputMessageContent – *Optional.*Content of the message to be sent instead of the photo
-
InlineQueryResultGif¶
-
class
twx.botapi.
InlineQueryResultGif
(id, gif_url, gif_width=None, gif_height=None, thumb_url=None, title=None, caption=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can provide message_text to send it instead of the animation.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
gif_url
¶ str – A valid URL for the GIF file. File size must not exceed 1MB
-
gif_width
¶ int – Optional. Width of the GIF
-
gif_height
¶ int – Optional. Height of the GIF
-
thumb_url
¶ str – Optional. URL of a static thumbnail for the result (jpeg or gif)
-
title
¶ str – Optional. Title for the result
str – Optional. Caption of the GIF file to be sent, 0-200 characters
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
InlineQueryResultCachedGif¶
-
class
twx.botapi.
InlineQueryResultCachedGif
(id, gif_file_id, title=None, caption=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
gif_file_id
¶ str – A valid file identifier for the GIF file
-
title
¶ str – Optional. Title for the result
str – Optional. Caption of the GIF file to be sent, 0-200 characters
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
InlineQueryResultMpeg4Gif¶
-
class
twx.botapi.
InlineQueryResultMpeg4Gif
(id, mpeg4_url, mpeg4_width=None, mpeg4_height=None, thumb_url=None, title=None, caption=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can provide message_text to send it instead of the animation.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
mpeg4_url
¶ str – A valid URL for the mp4 file. File size must not exceed 1MB
-
mpeg4_width
¶ int – Optional. Width of the mp4
-
mpeg4_height
¶ int – Optional. Height of the mp4
-
thumb_url
¶ str – Optional. URL of a static thumbnail for the result (jpeg or mpeg4)
-
title
¶ str – Optional. Title for the result
str – Optional. Caption of the mp4 file to be sent, 0-200 characters
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
InlineQueryResultCachedMpeg4Gif¶
-
class
twx.botapi.
InlineQueryResultCachedMpeg4Gif
(id, mpeg4_file_id, title=None, caption=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
mpeg4_file_id
¶ str – A valid file identifier for the MP4 file
-
title
¶ str – Optional. Title for the result
str – Optional. Caption of the mp4 file to be sent, 0-200 characters
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
InlineQueryResultVideo¶
-
class
twx.botapi.
InlineQueryResultVideo
(id, video_url, mime_type, title=None, video_width=None, video_height=None, video_duration=None, thumb_url=None, description=None, input_message_content=None, reply_markup=None)[source]¶ Represents link to a page containing an embedded video player or a video file.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
video_url
¶ str – A valid URL for the embedded video player or video file
-
mime_type
¶ str – Mime type of the content of video url, i.e. “text/html” or “video/mp4”
-
title
¶ str – Title for the result
-
video_width
¶ int – Optional. Video width
-
video_height
¶ int – Optional. Video height
-
video_duration
¶ int – Optional. Video duration in seconds
-
thumb_url
¶ str – Optional. URL of the thumbnail (jpeg only) for the video
-
description
¶ str – Optional. Short description of the result
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the video
-
InlineQueryResultCachedVideo¶
-
class
twx.botapi.
InlineQueryResultCachedVideo
(id, video_file_id, title, description=None, input_message_content=None, reply_markup=None)[source]¶ - Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent
- by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
video_file_id
¶ str – A valid file identifier for the video file
-
title
¶ str – Title for the result
-
description
¶ str – Optional. Short description of the result
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the video
InlineQueryResultAudio¶
-
class
twx.botapi.
InlineQueryResultAudio
(id, audio_url, title, performer=None, audio_duration=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
audio_url
¶ str – A valid URL for the audio file
-
title
¶ str – Title
-
performer
¶ str – Optional. Performer
-
audio_duration
¶ int – Optional. Audio duration in seconds
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the audio
-
InlineQueryResultCachedAudio¶
-
class
twx.botapi.
InlineQueryResultCachedAudio
(id, audio_file_id, title, input_message_content=None, reply_markup=None)[source]¶ Represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
audio_file_id
¶ str – A valid file identifier for the audio file
-
title
¶ str – Title
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the audio
-
InlineQueryResultVoice¶
-
class
twx.botapi.
InlineQueryResultVoice
(id, voice_url, title, voice_duration=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
voice_url
¶ str – A valid URL for the audio file
-
title
¶ str – Title
-
voice_duration
¶ int – Optional. Recording duration in seconds
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the voice recording
-
InlineQueryResultCachedVoice¶
-
class
twx.botapi.
InlineQueryResultCachedVoice
(id, voice_file_id, title, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
voice_file_id
¶ str – A valid URL for the audio file
-
title
¶ str – Title
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the voice recording
-
InlineQueryResultDocument¶
-
class
twx.botapi.
InlineQueryResultDocument
(id, document_url, title, mime_type, caption=None, description=None, input_message_content=None, reply_markup=None, thumb_url=None, thumb_width=None, thumb_height=None)[source]¶ Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
document_url
¶ str – A valid URL for the file
-
title
¶ str – Title
-
mime_type
¶ str – Mime type of the content of the file, either “application/pdf” or “application/zip”
str – Optional. Caption of the document to be sent, 0-200 characters
-
description
¶ str – Optional. Short description of the result
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the document
-
thumb_url
¶ str – Optional. URL of the thumbnail (jpeg only) for the file
-
thumb_width
¶ int – Optional. Thumbnail width
-
thumb_height
¶ int – Optional. Thumbnail height
-
InlineQueryResultCachedDocument¶
-
class
twx.botapi.
InlineQueryResultCachedDocument
(id, document_file_id, title, caption=None, description=None, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only pdf-files and zip archives can be sent using this method.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
document_file_id
¶ str – A valid file identifier for the file
-
title
¶ str – Title
str – Optional. Caption of the document to be sent, 0-200 characters
-
description
¶ str – Optional. Short description of the result
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the document
-
InlineQueryResultLocation¶
-
class
twx.botapi.
InlineQueryResultLocation
(id, latitude, longitude, title, input_message_content=None, reply_markup=None, thumb_url=None, thumb_width=None, thumb_height=None)[source]¶ Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
latitude
¶ str – Location latitude in degrees
-
longitude
¶ str – Location longitude in degrees
-
title
¶ str – Title
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the location
-
thumb_url
¶ str – Optional. URL of the thumbnail (jpeg only) for the file
-
thumb_width
¶ int – Optional. Thumbnail width
-
thumb_height
¶ int – Optional. Thumbnail height
-
InlineQueryResultVenue¶
-
class
twx.botapi.
InlineQueryResultVenue
(id, latitude, longitude, title, address, foursquare_id=None, input_message_content=None, reply_markup=None, thumb_url=None, thumb_width=None, thumb_height=None)[source]¶ Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
latitude
¶ str – Location latitude in degrees
-
longitude
¶ str – Location longitude in degrees
-
title
¶ str – Title
-
address
¶ str – Address of the venue
-
foursquare_id
¶ str – Optional. Foursquare identifier of the venue if known
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the venue
-
thumb_url
¶ str – Optional. URL of the thumbnail (jpeg only) for the file
-
thumb_width
¶ int – Optional. Thumbnail width
-
thumb_height
¶ int – Optional. Thumbnail height
-
InlineQueryResultContact¶
-
class
twx.botapi.
InlineQueryResultContact
(id, sticker_file_id, input_message_content=None, reply_markup=None)[source]¶ Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker.
-
id
¶ str – Unique identifier for this result, 1-64 bytes
-
sticker_file_id
¶ str – A valid file identifier of the sticker
-
reply_markup
¶ InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
¶ InputMessageContent – Optional. Content of the message to be sent instead of the document
-
InlineQueryResultContact¶
-
class
twx.botapi.
InlineQueryResultContact
(id, sticker_file_id, input_message_content=None, reply_markup=None)[source] Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker.
-
id
str – Unique identifier for this result, 1-64 bytes
-
sticker_file_id
str – A valid file identifier of the sticker
-
reply_markup
InlineKeyboardMarkup – Optional. Inline keyboard attached to the message
-
input_message_content
InputMessageContent – Optional. Content of the message to be sent instead of the document
-
InputTextMessageContent¶
-
class
twx.botapi.
InputTextMessageContent
(message_text, parse_mode=None, disable_web_page_preview=None)[source]¶ Represents the content of a text message to be sent as the result of an inline query.
-
message_text
¶ str – Text of the message to be sent, 1-4096 characters
-
parse_mode
¶ str – Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
-
disable_web_page_preview
¶ bool – Optional. Disables link previews for links in the sent message
-
InputLocationMessageContent¶
InputVenueMessageContent¶
-
class
twx.botapi.
InputVenueMessageContent
(latitude, longitude, title, address, foursquare_id=None)[source]¶ Represents the content of a location message to be sent as the result of an inline query.
-
latitude
¶ float – Latitude of the venue in degrees
-
longitude
¶ float – Longitude of the venue in degrees
-
title
¶ str – Name of the venue
-
address
¶ str – Address of the venue
-
foursquare_id
¶ str – Optional. Foursquare identifier of the venue, if known
-
InputContactMessageContent¶
-
class
twx.botapi.
InputContactMessageContent
(phone_number, first_name, last_name=None)[source]¶ Represents the content of a contact message to be sent as the result of an inline query.
-
phone_number
¶ str – Contact’s phone number
-
first_name
¶ str – Contact’s first name
-
last_name
¶ str – Optional. Contact’s last name
-
Additional Types¶
Error¶
-
class
twx.botapi.
Error
[source]¶ The error code and message returned when a request was successfuly but the method call was invalid
-
error_code
¶ int – An Integer ‘error_code’ field is also returned, but its contents are subject to change in the future.
-
description
¶ str – The description of the error as reported by Telegram
-
Request Objects¶
-
class
twx.botapi.
RequestMethod
[source]¶ Used to specify the HTTP request method.
-
GET
¶ ‘GET’
-
POST
¶ ‘POST’
Example: bot.get_me(request_method=RequestMethod.GET)
-
-
class
twx.botapi.
TelegramBotRPCRequest
(api_method, token, params=None, on_result=None, on_success=None, callback=None, on_error=None, files=None, request_method=<RequestMethod.POST: 'POST'>)[source]¶ Class that handles creating the actual RPC request, and sending callbacks based on response
Parameters: - api_method (str) – The API method to call. See https://core.telegram.org/bots/api#available-methods
- token (str) – The API token generated following the instructions at https://core.telegram.org/bots#botfather
- params (dict) – A dictionary mapping the api method parameters to their arguments
- on_result (callable) – a callback function that gets called before when te request finishes. The return value of this function gets passed to on_success. Useful if you wish to override the generated result type
- on_success (callable) – a callback function that gets called when the api call was successful, gets passed the return value from on_result
- on_error (callable) – called when an error occurs
- files (list of
InputFile
) – a list ofInputFile`s to be sent to the server
- request_method (RequestMethod) –
RequestMethod.POST
orRequestMethod.GET
Note
Typically you do not have to interact with this class directly. However, you may override any of these arguments by specifiying it in the the **kwargs of any api method.
Telegram Bot API Methods¶
get_me¶
-
twx.botapi.
get_me
(*, request_args=None, **kwargs)[source]¶ A simple method for testing your bot’s auth token. Requires no parameters. Returns basic information about the bot in form of a User object.
Parameters: **kwargs – Args that get passed down to TelegramBotRPCRequest
Returns: Returns basic information about the bot in form of a User object. Return type: User
send_message¶
-
twx.botapi.
send_message
(chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup, *, request_args=None, **kwargs)[source]¶ Use this method to send text messages.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- text (str) – Text of the message to be sent
- parse_mode – Send
"Markdown"
, if you want Telegram apps to show bold, italic and inline URLs in your bot’s message. - disable_web_page_preview (bool) – Disables link previews for links in this message
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (
ReplyKeyboardMarkup
orReplyKeyboardHide
orForceReply
) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
forward_message¶
-
twx.botapi.
forward_message
(chat_id, from_chat_id, message_id, *, request_args=None, **kwargs)[source]¶ Use this method to forward messages of any kind.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- from_chat_id (int) – Unique identifier for the chat where the original message was sent — User or GroupChat id
- message_id (int) – Unique message identifier
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_photo¶
-
twx.botapi.
send_photo
(chat_id, photo, caption=None, reply_to_message_id=None, reply_markup, *, request_args=None, **kwargs)[source]¶ Use this method to send photos.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- photo (InputFile or str) – Photo to send. You can either pass a file_id as String to resend a photo that is already on the Telegram servers, or upload a new photo using multipart/form-data.
- caption (str) – Photo caption (may also be used when resending photos by file_id).
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (
ReplyKeyboardMarkup
orReplyKeyboardHide
orForceReply
) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. - disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_audio¶
-
twx.botapi.
send_audio
(chat_id, audio, duration=None, performer=None, title=None, reply_to_message_id=None, reply_markup=None, *, request_args=None, **kwargs)[source]¶ Use this method to send audio files, if you want Telegram clients to display them in the music player.
Your audio must be in the .mp3 format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
For backward compatibility, when the fields title and performer are both empty and the mime-type of the file to be sent is not audio/mpeg, the file will be sent as a playable voice message. For this to work, the audio must be in an .ogg file encoded with OPUS. This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- audio (InputFile or str) – Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
- duration – Duration of the audio in seconds
- performer – Performer
- title – Track name
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard,
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
- duration – int
- performer – str
- title – str
Returns: On success, the sent Message is returned.
Return type:
send_document¶
-
twx.botapi.
send_document
(chat_id, document, reply_to_message_id=None, reply_markup=None, *, request_args=None, **kwargs)[source]¶ Use this method to send general files.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- document (InputFile or str) – File to send. You can either pass a file_id as String to resend a file that is already on the Telegram servers, or upload a new file using multipart/form-data.
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_sticker¶
-
twx.botapi.
send_sticker
(chat_id, sticker, reply_to_message_id=None, reply_markup=None, *, request_args=None, **kwargs)[source]¶ Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- sticker (InputFile or str) – Sticker to send. You can either pass a file_id as String to resend a sticker that is already on the Telegram servers, or upload a new sticker using multipart/form-data.
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_video¶
-
twx.botapi.
send_video
(chat_id, video, duration=None, caption=None, reply_to_message_id=None, reply_markup=None, *, request_args=None, **kwargs)[source]¶ Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- video (InputFile or str) – Video to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video using multipart/form-data.
- duration (int) – Duration of sent video in seconds
- caption (str) – Video caption (may also be used when resending videos by file_id)
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_voice¶
-
twx.botapi.
send_voice
(chat_id, voice, duration=None, reply_to_message_id=None, reply_markup=None, *, request_args=None, **kwargs)[source]¶ Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.
For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- voice (InputFile or str) – Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
- duration (int) – Duration of sent audio in seconds
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard,
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_location¶
-
twx.botapi.
send_location
(chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None, *, request_args=None, **kwargs)[source]¶ Use this method to send point on the map.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- latitude (float) – Latitude of location.
- longitude (float) – Longitude of location.
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
- disable_notification – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_venue¶
-
twx.botapi.
send_venue
(chat_id, latitude, longitude, title, address, foursquare_id=None, reply_to_message_id=None, reply_markup=None, disable_notification=False, **kwargs)[source]¶ Use this method to send information about a venue.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- latitude (float) – Latitude of location.
- longitude (float) – Longitude of location.
- title (str) – Name of the venue.
- address (str) – Address of the venue.
- foursquare_id (str) – Foursquare identifier of the venue.
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
- disable_notification (bool) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_contact¶
-
twx.botapi.
send_contact
(chat_id, phone_number, first_name, last_name=None, reply_to_message_id=None, reply_markup=None, disable_notification=False, **kwargs)[source]¶ Use this method to send phone contacts.
Parameters: - chat_id (int) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- phone_number (str) – Contact’s phone number.
- first_name (str) – Contact’s first name.
- last_name (str) – Contact’s last name.
- reply_to_message_id (int) – If the message is a reply, ID of the original message
- reply_markup (ReplyKeyboardMarkup or ReplyKeyboardHide or ForceReply) – Additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
- disable_notification (bool) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent Message is returned.
Return type:
send_chat_action¶
-
twx.botapi.
send_chat_action
(chat_id, action, *, request_args=None, **kwargs)[source]¶ - Use this method when you need to tell the user that something is happening on the bot’s side. The status is set
- for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.
We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
Parameters: - chat_id (int) – Unique identifier for the message recipient — User or GroupChat id
- action (ChatAction) – Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns True on success.
Return type:
kick_chat_member¶
-
twx.botapi.
kick_chat_member
(chat_id, user_id, **kwargs)[source]¶ Use this method to kick a user from a group or a supergroup. In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the group for this to work. Returns True on success.
Note: This will method only work if the ‘All Members Are Admins’ setting is off in the target group. Otherwise members may only be removed by the group’s creator or by the member that added them.
Parameters: - chat_id (int or str) – Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
- user_id (int) – Unique identifier of the target user
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns True on success.
Return type:
unban_chat_member¶
-
twx.botapi.
unban_chat_member
(chat_id, user_id, **kwargs)[source]¶ Use this method to unban a previously kicked user in a supergroup. The user will not return to the group automatically, but will be able to join via link, etc. The bot must be an administrator in the group for this to work
Parameters: - chat_id (int or str) – Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
- user_id (int) – Unique identifier of the target user
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns True on success.
Return type:
get_chat¶
-
twx.botapi.
get_chat
(chat_id, **kwargs)[source]¶ Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
Parameters: - chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns a Chat object on success.
Return type:
leave_chat¶
-
twx.botapi.
leave_chat
(chat_id, **kwargs)[source]¶ Use this method for your bot to leave a group, supergroup or channel.
Parameters: - chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns true on success.
Return type:
get_chat_administrators¶
-
twx.botapi.
get_chat_administrators
(chat_id, **kwargs)[source]¶ Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
Parameters: - chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: List of Chat Members on success.
Return type: list[ChatMember]
get_chat_member¶
-
twx.botapi.
get_chat_member
(chat_id, **kwargs)[source]¶ Use this method to get information about a member of a chat
Parameters: - chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
- user_id (int) – Unique identifier of the target user
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns ChatMember on success.
Return type:
get_chat_members_count¶
-
twx.botapi.
get_chat_members_count
(chat_id, **kwargs)[source]¶ Use this method to get the number of members in a chat.
Parameters: - chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns count on success.
Return type:
answer_callback_query¶
-
twx.botapi.
answer_callback_query
(callback_query_id, text=None, show_alert=None, **kwargs)[source]¶ Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
Parameters: - callback_query_id (str) – Unique identifier for the query to be answered
- text (str) – Text of the notification. If not specified, nothing will be shown to the user
- show_alert (bool) – If true, an alert will be shown by the client instead of a notificaiton at the top of the chat screen. Defaults to false.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns True on success.
Return type:
edit_message_text¶
-
twx.botapi.
edit_message_text
(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, disable_web_page_preview=None, reply_markup=None, **kwargs)[source]¶ Use this method to edit text messages sent by the bot or via the bot (for inline bots).
Parameters: - text (str) – New text of the message
- chat_id (str or int) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- message_id (int) – Required if inline_message_id is not specified. Unique identifier of the sent message
- inline_message_id (str) – Required if chat_id and message_id are not specified. Identifier of the inline message
- parse_mode (str) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
- disable_web_page_preview (bool) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
- reply_markup (InlineKeyboardMarkup) – A JSON-serialized object for an inline keyboard.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the edited Message is returned.
Return type:
edit_message_reply_markup¶
-
twx.botapi.
edit_message_reply_markup
(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, **kwargs)[source]¶ Use this method to edit text messages sent by the bot or via the bot (for inline bots).
Parameters: - chat_id (str or int) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
- message_id (int) – Required if inline_message_id is not specified. Unique identifier of the sent message
- inline_message_id (str) – Required if chat_id and message_id are not specified. Identifier of the inline message
- reply_markup (InlineKeyboardMarkup) – A JSON-serialized object for an inline keyboard.
- **kwargs –
Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the edited Message is returned.
Return type:
answer_inline_query¶
-
twx.botapi.
answer_inline_query
(inline_query_id, results, cache_time=None, is_personal=None, next_offset=None, switch_pm_text=None, switch_pm_parameter=None, **kwargs)[source]¶ Use this method to send answers to an inline query. On success, True is returned.
Parameters: - inline_query_id (str) – Unique identifier for the message recipient — String
- results (InlineQueryResult[]) – An array of results for the inline query — Array of InlineQueryResult
- cache_time (int) – The maximum amount of time the result of the inline query may be cached on the server
- is_personal (bool) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
- next_offset (str) – Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
- switch_pm_text (str) – If passed, clients will display a button with specified text that switches the user to a private that with the bot and sends the bot a start message with the parameter switch_pm_parameter
- switch_pm_parameter (str) – Parameter for the start message sent to the bot when user presses the switch button Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a ‘Connect your YouTube account’ button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot’s inline capabilities.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: On success, the sent True is returned.
Return type:
get_user_profile_photos¶
-
twx.botapi.
get_user_profile_photos
(user_id, offset=None, limit=None, *, request_args=None, **kwargs)[source]¶ Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.
Parameters: - user_id (int) – Unique identifier of the target user
- offset (int) – Sequential number of the first photo to be returned. By default, all photos are returned.
- limit (int) – Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100.
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns a UserProfilePhotos object.
Return type:
get_file¶
-
twx.botapi.
get_file
(file_id, **kwargs)[source]¶ Use this method to get basic info about a file and prepare it for downloading.
For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
Parameters: file_id (str) – File identifier to get info about Returns: Returns a File object. Return type: TelegramBotRPCRequest
download_file¶
-
twx.botapi.
download_file
(file_path, out_file, **kwargs)[source]¶ Use this method to download a file from the telegram servers.
It is guaranteed that the link will be valid for at least 1 hour.
Parameters: - file_path (str) – The remote file path received via
get_file()
- out_file (str or file-like object) – File to save to. Can be a file path (str) or a file-like object
- **kwargs – Args that get passed down to
TelegramDownloadRequest
Returns: Returns out_file on success or an Exception on error.
Return type: TelegramDownloadRequest
- file_path (str) – The remote file path received via
get_updates¶
-
twx.botapi.
get_updates
(offset=None, limit=None, timeout=None, *, request_args, **kwargs)[source]¶ Use this method to receive incoming updates using long polling.
Note
- This method will not work if an outgoing webhook is set up.
- In order to avoid getting duplicate updates, recalculate offset after each server response.
Parameters: - offset (int) – Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
- limit (int) – Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100
- timeout (int) – Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: An Array of Update objects is returned.
Return type:
set_webhook¶
-
twx.botapi.
set_webhook
(url=None, *, request_args=None, **kwargs)[source]¶ Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.
Please note that you will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
Ports currently supported for Webhooks: 443, 80, 88, 8443.
Parameters: - url (str) – HTTPS url to send updates to. Use an empty string to remove webhook integration
- certificate (InputFile) – Upload your public key certificate so that the root certificate in use can be checked. See telegram’s self-signed guide for details (https://core.telegram.org/bots/self-signed).
- **kwargs – Args that get passed down to
TelegramBotRPCRequest
Returns: Returns True on success.
Return type: