2015-06-26 09:55:13 +03:00
# -*- coding: utf-8 -*-
2016-01-05 04:57:25 +03:00
2022-08-01 10:40:43 +03:00
from io import IOBase
2020-08-02 18:20:33 +03:00
import logging
2022-08-01 10:40:43 +03:00
import os
from pathlib import Path
2021-06-21 20:59:39 +03:00
from typing import Dict , List , Optional , Union
2021-06-27 17:28:11 +03:00
from abc import ABC
2020-08-02 18:20:33 +03:00
2016-09-12 11:38:54 +03:00
try :
import ujson as json
except ImportError :
import json
2016-05-19 11:18:00 +03:00
from telebot import util
2015-07-01 23:34:40 +03:00
2020-08-04 12:29:56 +03:00
DISABLE_KEYLEN_ERROR = False
2020-08-02 18:20:33 +03:00
logger = logging . getLogger ( ' TeleBot ' )
2016-05-20 09:39:34 +03:00
2020-08-04 12:29:56 +03:00
2018-08-14 12:23:15 +03:00
class JsonSerializable ( object ) :
2015-07-01 19:17:33 +03:00
"""
Subclasses of this class are guaranteed to be able to be converted to JSON format .
All subclasses of this class must override to_json .
2022-07-24 21:14:09 +03:00
2015-07-01 19:17:33 +03:00
"""
2015-10-12 05:36:58 +03:00
2015-07-01 19:17:33 +03:00
def to_json ( self ) :
"""
Returns a JSON string representation of this class .
2022-07-26 14:16:35 +03:00
: meta private :
2015-07-01 19:17:33 +03:00
This function must be overridden by subclasses .
: return : a JSON formatted string .
"""
raise NotImplementedError
2015-06-26 10:15:30 +03:00
2015-07-01 23:34:40 +03:00
2018-08-14 12:23:15 +03:00
class Dictionaryable ( object ) :
2016-04-14 10:50:55 +03:00
"""
Subclasses of this class are guaranteed to be able to be converted to dictionary .
2020-05-09 00:51:18 +03:00
All subclasses of this class must override to_dict .
2022-07-24 21:14:09 +03:00
2016-04-14 10:50:55 +03:00
"""
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
2016-04-14 10:50:55 +03:00
"""
2020-04-25 22:22:08 +03:00
Returns a DICT with class field values
2016-04-14 10:50:55 +03:00
2022-07-26 14:16:35 +03:00
: meta private :
2016-04-14 10:50:55 +03:00
This function must be overridden by subclasses .
2020-04-25 22:22:08 +03:00
: return : a DICT
2016-04-14 10:50:55 +03:00
"""
raise NotImplementedError
2018-08-14 12:23:15 +03:00
class JsonDeserializable ( object ) :
2015-07-01 23:16:13 +03:00
"""
Subclasses of this class are guaranteed to be able to be created from a json - style dict or json formatted string .
All subclasses of this class must override de_json .
"""
2015-10-12 05:36:58 +03:00
2015-07-01 23:16:13 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2015-07-01 23:16:13 +03:00
"""
Returns an instance of this class from the given json dict or string .
2022-07-26 14:16:35 +03:00
: meta private :
2015-07-01 23:16:13 +03:00
This function must be overridden by subclasses .
: return : an instance of this class created from the given json dict or string .
"""
raise NotImplementedError
@staticmethod
2021-07-08 09:35:48 +03:00
def check_json ( json_type , dict_copy = True ) :
2015-07-01 23:16:13 +03:00
"""
Checks whether json_type is a dict or a string . If it is already a dict , it is returned as - is .
If it is not , it is converted to a dict by means of json . loads ( json_type )
2022-07-26 14:16:35 +03:00
: meta private :
2022-03-19 11:49:36 +03:00
2021-07-08 09:35:48 +03:00
: param json_type : input json or parsed dict
: param dict_copy : if dict is passed and it is changed outside - should be True !
: return : Dictionary parsed from json or original dict
2015-07-01 23:16:13 +03:00
"""
2020-07-31 23:28:56 +03:00
if util . is_dict ( json_type ) :
2021-08-18 18:47:38 +03:00
return json_type . copy ( ) if dict_copy else json_type
2020-07-31 23:28:56 +03:00
elif util . is_string ( json_type ) :
2015-07-01 23:16:13 +03:00
return json . loads ( json_type )
else :
raise ValueError ( " json_type should be a json dict or string. " )
2015-09-01 22:55:02 +03:00
def __str__ ( self ) :
2021-07-19 20:01:37 +03:00
d = {
x : y . __dict__ if hasattr ( y , ' __dict__ ' ) else y
for x , y in self . __dict__ . items ( )
}
2020-08-24 16:02:35 +03:00
return str ( d )
2015-09-01 22:55:02 +03:00
2015-10-12 05:36:58 +03:00
2015-09-05 12:58:53 +03:00
class Update ( JsonDeserializable ) :
2022-07-24 21:14:09 +03:00
"""
2022-07-26 14:16:35 +03:00
This object represents an incoming update . At most one of the optional parameters can be present in any given update .
2022-07-24 21:14:09 +03:00
2022-07-26 14:16:35 +03:00
Telegram Documentation : https : / / core . telegram . org / bots / api #update
2022-07-24 21:14:09 +03:00
2022-07-26 14:16:35 +03:00
: param update_id : 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 . If there are no new updates
for at least a week , then identifier of the next update will be chosen randomly instead of sequentially .
: type update_id : : obj : ` int `
2022-07-24 21:14:09 +03:00
2022-07-26 14:16:35 +03:00
: param message : Optional . New incoming message of any kind - text , photo , sticker , etc .
2022-07-24 21:14:09 +03:00
: type message : : class : ` telebot . types . Message `
2022-07-26 14:16:35 +03:00
: param edited_message : Optional . New version of a message that is known to the bot and was edited
2022-07-24 21:14:09 +03:00
: type edited_message : : class : ` telebot . types . Message `
2022-07-26 14:16:35 +03:00
: param channel_post : Optional . New incoming channel post of any kind - text , photo , sticker , etc .
2022-07-24 21:14:09 +03:00
: type channel_post : : class : ` telebot . types . Message `
2022-07-26 14:16:35 +03:00
: param edited_channel_post : Optional . New version of a channel post that is known to the bot and was edited
2022-07-24 21:14:09 +03:00
: type edited_channel_post : : class : ` telebot . types . Message `
2022-07-26 14:16:35 +03:00
: param inline_query : Optional . New incoming inline query
2022-07-24 21:14:09 +03:00
: type inline_query : : class : ` telebot . types . InlineQuery `
2022-07-26 14:16:35 +03:00
: param chosen_inline_result : Optional . The result of an inline query that was chosen by a user and sent to their chat
partner . Please see our documentation on the feedback collecting for details on how to enable these updates for your
bot .
2022-07-24 21:14:09 +03:00
: type chosen_inline_result : : class : ` telebot . types . ChosenInlineResult `
2022-07-26 14:16:35 +03:00
: param callback_query : Optional . New incoming callback query
2022-07-24 21:14:09 +03:00
: type callback_query : : class : ` telebot . types . CallbackQuery `
2022-07-26 14:16:35 +03:00
: param shipping_query : Optional . New incoming shipping query . Only for invoices with flexible price
2022-07-24 21:14:09 +03:00
: type shipping_query : : class : ` telebot . types . ShippingQuery `
2022-07-26 14:16:35 +03:00
: param pre_checkout_query : Optional . New incoming pre - checkout query . Contains full information about
checkout
2022-07-24 21:14:09 +03:00
: type pre_checkout_query : : class : ` telebot . types . PreCheckoutQuery `
2022-07-26 14:16:35 +03:00
: param poll : Optional . New poll state . Bots receive only updates about stopped polls and polls , which are sent by the
bot
2022-07-24 21:14:09 +03:00
: type poll : : class : ` telebot . types . Poll `
2022-07-26 14:16:35 +03:00
: param poll_answer : Optional . A user changed their answer in a non - anonymous poll . Bots receive new votes only in
polls that were sent by the bot itself .
2022-07-24 21:14:09 +03:00
: type poll_answer : : class : ` telebot . types . PollAnswer `
2022-07-26 14:16:35 +03:00
: param my_chat_member : Optional . The bot ' s chat member status was updated in a chat. For private chats, this update
is received only when the bot is blocked or unblocked by the user .
: type my_chat_member : : class : ` telebot . types . ChatMemberUpdated `
2022-07-24 21:14:09 +03:00
2022-07-26 14:16:35 +03:00
: param chat_member : Optional . A chat member ' s status was updated in a chat. The bot must be an administrator in the
chat and must explicitly specify “ chat_member ” in the list of allowed_updates to receive these updates .
: type chat_member : : class : ` telebot . types . ChatMemberUpdated `
2022-07-24 21:14:09 +03:00
2022-07-26 14:16:35 +03:00
: param chat_join_request : Optional . A request to join the chat has been sent . The bot must have the
can_invite_users administrator right in the chat to receive these updates .
2022-07-24 21:14:09 +03:00
: type chat_join_request : : class : ` telebot . types . ChatJoinRequest `
2022-07-26 14:16:35 +03:00
: return : Instance of the class
2022-07-24 21:14:09 +03:00
: rtype : : class : ` telebot . types . Update `
2022-07-26 14:16:35 +03:00
2022-07-24 21:14:09 +03:00
"""
2015-09-05 12:58:53 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
update_id = obj [ ' update_id ' ]
message = Message . de_json ( obj . get ( ' message ' ) )
edited_message = Message . de_json ( obj . get ( ' edited_message ' ) )
channel_post = Message . de_json ( obj . get ( ' channel_post ' ) )
edited_channel_post = Message . de_json ( obj . get ( ' edited_channel_post ' ) )
inline_query = InlineQuery . de_json ( obj . get ( ' inline_query ' ) )
chosen_inline_result = ChosenInlineResult . de_json ( obj . get ( ' chosen_inline_result ' ) )
callback_query = CallbackQuery . de_json ( obj . get ( ' callback_query ' ) )
shipping_query = ShippingQuery . de_json ( obj . get ( ' shipping_query ' ) )
pre_checkout_query = PreCheckoutQuery . de_json ( obj . get ( ' pre_checkout_query ' ) )
poll = Poll . de_json ( obj . get ( ' poll ' ) )
poll_answer = PollAnswer . de_json ( obj . get ( ' poll_answer ' ) )
my_chat_member = ChatMemberUpdated . de_json ( obj . get ( ' my_chat_member ' ) )
chat_member = ChatMemberUpdated . de_json ( obj . get ( ' chat_member ' ) )
2021-11-05 21:22:03 +03:00
chat_join_request = ChatJoinRequest . de_json ( obj . get ( ' chat_join_request ' ) )
2021-07-08 09:35:48 +03:00
return cls ( update_id , message , edited_message , channel_post , edited_channel_post , inline_query ,
chosen_inline_result , callback_query , shipping_query , pre_checkout_query , poll , poll_answer ,
2021-11-06 10:15:28 +03:00
my_chat_member , chat_member , chat_join_request )
2016-01-04 17:29:04 +03:00
2016-12-03 08:28:22 +03:00
def __init__ ( self , update_id , message , edited_message , channel_post , edited_channel_post , inline_query ,
2021-06-19 21:13:53 +03:00
chosen_inline_result , callback_query , shipping_query , pre_checkout_query , poll , poll_answer ,
2021-11-06 10:15:28 +03:00
my_chat_member , chat_member , chat_join_request ) :
2015-09-05 12:58:53 +03:00
self . update_id = update_id
self . message = message
2016-05-22 13:35:21 +03:00
self . edited_message = edited_message
2016-12-03 08:28:22 +03:00
self . channel_post = channel_post
self . edited_channel_post = edited_channel_post
2016-01-04 17:29:04 +03:00
self . inline_query = inline_query
self . chosen_inline_result = chosen_inline_result
2016-04-16 09:18:19 +03:00
self . callback_query = callback_query
2017-05-21 16:52:56 +03:00
self . shipping_query = shipping_query
self . pre_checkout_query = pre_checkout_query
2020-03-09 13:25:54 +03:00
self . poll = poll
2020-05-12 08:42:17 +03:00
self . poll_answer = poll_answer
2021-06-19 21:13:53 +03:00
self . my_chat_member = my_chat_member
self . chat_member = chat_member
2021-11-06 10:15:28 +03:00
self . chat_join_request = chat_join_request
2021-06-19 21:13:53 +03:00
class ChatMemberUpdated ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents changes in the status of a chat member .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmemberupdated
: param chat : Chat the user belongs to
: type chat : : class : ` telebot . types . Chat `
: param from_user : Performer of the action , which resulted in the change
: type from_user : : class : ` telebot . types . User `
: param date : Date the change was done in Unix time
: type date : : obj : ` int `
: param old_chat_member : Previous information about the chat member
: type old_chat_member : : class : ` telebot . types . ChatMember `
: param new_chat_member : New information about the chat member
: type new_chat_member : : class : ` telebot . types . ChatMember `
: param invite_link : Optional . Chat invite link , which was used by the user to join the chat ; for joining by invite
link events only .
: type invite_link : : class : ` telebot . types . ChatInviteLink `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberUpdated `
"""
2021-06-19 21:13:53 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
obj [ ' chat ' ] = Chat . de_json ( obj [ ' chat ' ] )
obj [ ' from_user ' ] = User . de_json ( obj . pop ( ' from ' ) )
obj [ ' old_chat_member ' ] = ChatMember . de_json ( obj [ ' old_chat_member ' ] )
obj [ ' new_chat_member ' ] = ChatMember . de_json ( obj [ ' new_chat_member ' ] )
obj [ ' invite_link ' ] = ChatInviteLink . de_json ( obj . get ( ' invite_link ' ) )
return cls ( * * obj )
def __init__ ( self , chat , from_user , date , old_chat_member , new_chat_member , invite_link = None , * * kwargs ) :
self . chat : Chat = chat
self . from_user : User = from_user
self . date : int = date
self . old_chat_member : ChatMember = old_chat_member
self . new_chat_member : ChatMember = new_chat_member
2021-06-21 20:59:39 +03:00
self . invite_link : Optional [ ChatInviteLink ] = invite_link
2021-06-30 15:16:38 +03:00
@property
def difference ( self ) - > Dict [ str , List ] :
"""
Get the difference between ` old_chat_member ` and ` new_chat_member `
as a dict in the following format { ' parameter ' : [ old_value , new_value ] }
2022-07-26 14:16:35 +03:00
E . g { ' status ' : [ ' member ' , ' kicked ' ] , ' until_date ' : [ None , 1625055092 ] }
: return : Dict of differences
: rtype : Dict [ str , List ]
2021-06-30 15:16:38 +03:00
"""
old : Dict = self . old_chat_member . __dict__
new : Dict = self . new_chat_member . __dict__
dif = { }
for key in new :
2021-07-01 19:54:39 +03:00
if key == ' user ' : continue
2021-06-30 15:16:38 +03:00
if new [ key ] != old [ key ] :
dif [ key ] = [ old [ key ] , new [ key ] ]
return dif
2022-07-26 14:16:35 +03:00
2015-07-01 23:16:13 +03:00
2021-11-05 21:22:03 +03:00
class ChatJoinRequest ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
Represents a join request sent to a chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatjoinrequest
: param chat : Chat to which the request was sent
: type chat : : class : ` telebot . types . Chat `
: param from : User that sent the join request
: type from_user : : class : ` telebot . types . User `
: param date : Date the request was sent in Unix time
: type date : : obj : ` int `
: param bio : Optional . Bio of the user .
: type bio : : obj : ` str `
: param invite_link : Optional . Chat invite link that was used by the user to send the join request
: type invite_link : : class : ` telebot . types . ChatInviteLink `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatJoinRequest `
"""
2021-11-05 21:22:03 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
obj [ ' chat ' ] = Chat . de_json ( obj [ ' chat ' ] )
2021-11-06 10:15:28 +03:00
obj [ ' from_user ' ] = User . de_json ( obj [ ' from ' ] )
2021-11-08 18:51:42 +03:00
obj [ ' invite_link ' ] = ChatInviteLink . de_json ( obj . get ( ' invite_link ' ) )
2021-11-05 21:22:03 +03:00
return cls ( * * obj )
def __init__ ( self , chat , from_user , date , bio = None , invite_link = None , * * kwargs ) :
2021-11-08 18:51:42 +03:00
self . chat = chat
self . from_user = from_user
self . date = date
self . bio = bio
self . invite_link = invite_link
2015-10-12 05:36:58 +03:00
2016-10-20 10:52:38 +03:00
class WebhookInfo ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
Describes the current status of a webhook .
Telegram Documentation : https : / / core . telegram . org / bots / api #webhookinfo
: param url : Webhook URL , may be empty if webhook is not set up
: type url : : obj : ` str `
: param has_custom_certificate : True , if a custom certificate was provided for webhook certificate checks
: type has_custom_certificate : : obj : ` bool `
: param pending_update_count : Number of updates awaiting delivery
: type pending_update_count : : obj : ` int `
: param ip_address : Optional . Currently used webhook IP address
: type ip_address : : obj : ` str `
: param last_error_date : Optional . Unix time for the most recent error that happened when trying to deliver an
update via webhook
: type last_error_date : : obj : ` int `
: param last_error_message : Optional . Error message in human - readable format for the most recent error that
happened when trying to deliver an update via webhook
: type last_error_message : : obj : ` str `
: param last_synchronization_error_date : Optional . Unix time of the most recent error that happened when trying
to synchronize available updates with Telegram datacenters
: type last_synchronization_error_date : : obj : ` int `
: param max_connections : Optional . The maximum allowed number of simultaneous HTTPS connections to the webhook
for update delivery
: type max_connections : : obj : ` int `
: param allowed_updates : Optional . A list of update types the bot is subscribed to . Defaults to all update types
except chat_member
: type allowed_updates : : obj : ` list ` of : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . WebhookInfo `
"""
2016-10-20 10:52:38 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-19 21:13:53 +03:00
return cls ( * * obj )
def __init__ ( self , url , has_custom_certificate , pending_update_count , ip_address = None ,
2022-04-17 14:39:09 +03:00
last_error_date = None , last_error_message = None , last_synchronization_error_date = None ,
max_connections = None , allowed_updates = None , * * kwargs ) :
2016-10-20 10:52:38 +03:00
self . url = url
self . has_custom_certificate = has_custom_certificate
self . pending_update_count = pending_update_count
2020-12-29 19:24:41 +03:00
self . ip_address = ip_address
2016-10-20 10:52:38 +03:00
self . last_error_date = last_error_date
self . last_error_message = last_error_message
2022-04-17 14:39:09 +03:00
self . last_synchronization_error_date = last_synchronization_error_date
2016-12-12 19:29:57 +03:00
self . max_connections = max_connections
self . allowed_updates = allowed_updates
2016-10-20 10:52:38 +03:00
2020-05-12 03:09:34 +03:00
class User ( JsonDeserializable , Dictionaryable , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a Telegram user or bot .
Telegram Documentation : https : / / core . telegram . org / bots / api #user
: param id : Unique identifier for this user or bot . This number may have more than 32 significant bits and some
programming languages may have difficulty / silent defects in interpreting it . But it has at most 52 significant
bits , so a 64 - bit integer or double - precision float type are safe for storing this identifier .
: type id : : obj : ` int `
: param is_bot : True , if this user is a bot
: type is_bot : : obj : ` bool `
: param first_name : User ' s or bot ' s first name
: type first_name : : obj : ` str `
: param last_name : Optional . User ' s or bot ' s last name
: type last_name : : obj : ` str `
: param username : Optional . User ' s or bot ' s username
: type username : : obj : ` str `
: param language_code : Optional . IETF language tag of the user ' s language
: type language_code : : obj : ` str `
: param is_premium : Optional . : obj : ` bool ` , if this user is a Telegram Premium user
: type is_premium : : obj : ` bool `
: param added_to_attachment_menu : Optional . : obj : ` bool ` , if this user added the bot to the attachment menu
: type added_to_attachment_menu : : obj : ` bool `
: param can_join_groups : Optional . True , if the bot can be invited to groups . Returned only in getMe .
: type can_join_groups : : obj : ` bool `
: param can_read_all_group_messages : Optional . True , if privacy mode is disabled for the bot . Returned only in
getMe .
: type can_read_all_group_messages : : obj : ` bool `
: param supports_inline_queries : Optional . True , if the bot supports inline queries . Returned only in getMe .
: type supports_inline_queries : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . User `
"""
2015-06-26 10:15:30 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , id , is_bot , first_name , last_name = None , username = None , language_code = None ,
2022-06-21 13:21:35 +03:00
can_join_groups = None , can_read_all_group_messages = None , supports_inline_queries = None ,
is_premium = None , added_to_attachment_menu = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . id : int = id
self . is_bot : bool = is_bot
self . first_name : str = first_name
self . username : str = username
self . last_name : str = last_name
self . language_code : str = language_code
self . can_join_groups : bool = can_join_groups
self . can_read_all_group_messages : bool = can_read_all_group_messages
self . supports_inline_queries : bool = supports_inline_queries
2022-06-21 13:21:35 +03:00
self . is_premium : bool = is_premium
self . added_to_attachment_menu : bool = added_to_attachment_menu
2015-06-26 09:55:13 +03:00
2021-04-01 22:56:08 +03:00
@property
def full_name ( self ) :
2022-07-26 14:16:35 +03:00
"""
: return : User ' s full name
"""
2021-04-01 22:56:08 +03:00
full_name = self . first_name
if self . last_name :
2021-04-02 00:52:12 +03:00
full_name + = ' {0} ' . format ( self . last_name )
2021-04-01 22:56:08 +03:00
return full_name
2020-05-12 03:09:34 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
return { ' id ' : self . id ,
' is_bot ' : self . is_bot ,
' first_name ' : self . first_name ,
' last_name ' : self . last_name ,
' username ' : self . username ,
2020-06-22 14:18:13 +03:00
' language_code ' : self . language_code ,
' can_join_groups ' : self . can_join_groups ,
' can_read_all_group_messages ' : self . can_read_all_group_messages ,
2022-07-26 14:16:35 +03:00
' supports_inline_queries ' : self . supports_inline_queries ,
' is_premium ' : self . is_premium ,
' added_to_attachment_menu ' : self . added_to_attachment_menu }
2020-05-12 03:09:34 +03:00
2015-06-26 09:55:13 +03:00
2015-07-01 23:16:13 +03:00
class GroupChat ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
: meta private :
"""
2015-06-26 13:02:30 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2015-06-26 13:02:30 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , id , title , * * kwargs ) :
self . id : int = id
self . title : str = title
2015-06-26 09:55:13 +03:00
2015-10-12 05:36:58 +03:00
class Chat ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #chat
: param id : Unique identifier for this chat . This number may have more than 32 significant bits and some programming
languages may have difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed
64 - bit integer or double - precision float type are safe for storing this identifier .
: type id : : obj : ` int `
: param type : Type of chat , can be either “ private ” , “ group ” , “ supergroup ” or “ channel ”
: type type : : obj : ` str `
: param title : Optional . Title , for supergroups , channels and group chats
: type title : : obj : ` str `
: param username : Optional . Username , for private chats , supergroups and channels if available
: type username : : obj : ` str `
: param first_name : Optional . First name of the other party in a private chat
: type first_name : : obj : ` str `
: param last_name : Optional . Last name of the other party in a private chat
: type last_name : : obj : ` str `
2022-11-05 22:14:37 +03:00
: param is_forum : Optional . True , if the supergroup chat is a forum ( has topics enabled )
: type is_forum : : obj : ` bool `
2022-07-26 14:16:35 +03:00
: param photo : Optional . Chat photo . Returned only in getChat .
: type photo : : class : ` telebot . types . ChatPhoto `
2022-11-06 16:38:01 +03:00
: param active_usernames : Optional . If non - empty , the list of all active chat usernames ; for private chats , supergroups and channels .
Returned only in getChat .
: type active_usernames : : obj : ` list ` of : obj : ` str `
: param emoji_status_custom_emoji_id : Optional . Custom emoji identifier of emoji status of the other party in a private chat .
Returned only in getChat .
: type emoji_status_custom_emoji_id : : obj : ` str `
2022-07-26 14:16:35 +03:00
: param bio : Optional . Bio of the other party in a private chat . Returned only in getChat .
: type bio : : obj : ` str `
: param has_private_forwards : Optional . : obj : ` bool ` , if privacy settings of the other party in the private chat
allows to use tg : / / user ? id = < user_id > links only in chats with the user . Returned only in getChat .
: type has_private_forwards : : obj : ` bool `
2022-08-12 20:10:08 +03:00
: param has_restricted_voice_and_video_messages : Optional . True , if the privacy settings of the other party restrict sending voice and video note messages
in the private chat . Returned only in getChat .
: type : obj : ` bool `
2022-07-26 14:16:35 +03:00
: param join_to_send_messages : Optional . : obj : ` bool ` , if users need to join the supergroup before they can send
messages . Returned only in getChat .
: type join_to_send_messages : : obj : ` bool `
: param join_by_request : Optional . : obj : ` bool ` , if all users directly joining the supergroup need to be approved
by supergroup administrators . Returned only in getChat .
: type join_by_request : : obj : ` bool `
: param description : Optional . Description , for groups , supergroups and channel chats . Returned only in getChat .
: type description : : obj : ` str `
: param invite_link : Optional . Primary invite link , for groups , supergroups and channel chats . Returned only in
getChat .
: type invite_link : : obj : ` str `
: param pinned_message : Optional . The most recent pinned message ( by sending date ) . Returned only in getChat .
: type pinned_message : : class : ` telebot . types . Message `
: param permissions : Optional . Default chat member permissions , for groups and supergroups . Returned only in
getChat .
: type permissions : : class : ` telebot . types . ChatPermissions `
: param slow_mode_delay : Optional . For supergroups , the minimum allowed delay between consecutive messages sent
by each unpriviledged user ; in seconds . Returned only in getChat .
: type slow_mode_delay : : obj : ` int `
: param message_auto_delete_time : Optional . The time after which all messages sent to the chat will be
automatically deleted ; in seconds . Returned only in getChat .
: type message_auto_delete_time : : obj : ` int `
: param has_protected_content : Optional . : obj : ` bool ` , if messages from the chat can ' t be forwarded to other
chats . Returned only in getChat .
: type has_protected_content : : obj : ` bool `
: param sticker_set_name : Optional . For supergroups , name of group sticker set . Returned only in getChat .
: type sticker_set_name : : obj : ` str `
: param can_set_sticker_set : Optional . : obj : ` bool ` , if the bot can change the group sticker set . Returned only in
getChat .
: type can_set_sticker_set : : obj : ` bool `
: param linked_chat_id : Optional . Unique identifier for the linked chat , i . e . the discussion group identifier for
a channel and vice versa ; for supergroups and channel chats . This identifier may be greater than 32 bits and some
programming languages may have difficulty / silent defects in interpreting it . But it is smaller than 52 bits , so a
signed 64 bit integer or double - precision float type are safe for storing this identifier . Returned only in getChat .
: type linked_chat_id : : obj : ` int `
: param location : Optional . For supergroups , the location to which the supergroup is connected . Returned only in
getChat .
: type location : : class : ` telebot . types . ChatLocation `
: return : Instance of the class
: rtype : : class : ` telebot . types . Chat `
"""
2015-10-12 05:36:58 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2015-10-12 05:36:58 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
if ' photo ' in obj :
obj [ ' photo ' ] = ChatPhoto . de_json ( obj [ ' photo ' ] )
if ' pinned_message ' in obj :
obj [ ' pinned_message ' ] = Message . de_json ( obj [ ' pinned_message ' ] )
if ' permissions ' in obj :
obj [ ' permissions ' ] = ChatPermissions . de_json ( obj [ ' permissions ' ] )
if ' location ' in obj :
obj [ ' location ' ] = ChatLocation . de_json ( obj [ ' location ' ] )
return cls ( * * obj )
2020-05-11 22:26:03 +03:00
def __init__ ( self , id , type , title = None , username = None , first_name = None ,
2021-12-07 20:17:51 +03:00
last_name = None , photo = None , bio = None , has_private_forwards = None ,
description = None , invite_link = None , pinned_message = None ,
permissions = None , slow_mode_delay = None ,
message_auto_delete_time = None , has_protected_content = None , sticker_set_name = None ,
2022-06-21 13:21:35 +03:00
can_set_sticker_set = None , linked_chat_id = None , location = None ,
2022-11-05 22:14:37 +03:00
join_to_send_messages = None , join_by_request = None , has_restricted_voice_and_video_messages = None ,
2022-11-06 16:38:01 +03:00
is_forum = None , active_usernames = None , emoji_status_custom_emoji_id = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . id : int = id
self . type : str = type
self . title : str = title
self . username : str = username
self . first_name : str = first_name
self . last_name : str = last_name
2022-11-05 22:14:37 +03:00
self . is_forum : bool = is_forum
2021-06-17 21:28:53 +03:00
self . photo : ChatPhoto = photo
self . bio : str = bio
2022-06-21 13:21:35 +03:00
self . join_to_send_messages : bool = join_to_send_messages
self . join_by_request : bool = join_by_request
2021-12-07 20:17:51 +03:00
self . has_private_forwards : bool = has_private_forwards
2022-08-12 20:10:08 +03:00
self . has_restricted_voice_and_video_messages : bool = has_restricted_voice_and_video_messages
2021-06-17 21:28:53 +03:00
self . description : str = description
self . invite_link : str = invite_link
self . pinned_message : Message = pinned_message
self . permissions : ChatPermissions = permissions
self . slow_mode_delay : int = slow_mode_delay
2021-08-18 21:57:56 +03:00
self . message_auto_delete_time : int = message_auto_delete_time
2021-12-07 20:17:51 +03:00
self . has_protected_content : bool = has_protected_content
2021-06-17 21:28:53 +03:00
self . sticker_set_name : str = sticker_set_name
self . can_set_sticker_set : bool = can_set_sticker_set
self . linked_chat_id : int = linked_chat_id
self . location : ChatLocation = location
2022-11-06 16:38:01 +03:00
self . active_usernames : List [ str ] = active_usernames
self . emoji_status_custom_emoji_id : str = emoji_status_custom_emoji_id
2015-10-12 05:36:58 +03:00
2021-01-12 10:47:53 +03:00
class MessageID ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a unique message identifier .
Telegram Documentation : https : / / core . telegram . org / bots / api #messageid
: param message_id : Unique message identifier
: type message_id : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . MessageId `
"""
2021-01-12 10:47:53 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
return cls ( * * obj )
2021-01-12 10:47:53 +03:00
2021-07-08 09:35:48 +03:00
def __init__ ( self , message_id , * * kwargs ) :
2021-01-12 10:47:53 +03:00
self . message_id = message_id
2022-07-26 14:27:15 +03:00
class WebAppData ( JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Describes data sent from a Web App to the bot .
Telegram Documentation : https : / / core . telegram . org / bots / api #webappdata
: param data : The data . Be aware that a bad client can send arbitrary data in this field .
: type data : : obj : ` str `
: param button_text : Text of the web_app keyboard button from which the Web App was opened . Be aware that a bad client
can send arbitrary data in this field .
: type button_text : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . WebAppData `
"""
2022-04-17 14:39:09 +03:00
def __init__ ( self , data , button_text ) :
self . data = data
self . button_text = button_text
def to_dict ( self ) :
return { ' data ' : self . data , ' button_text ' : self . button_text }
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
return cls ( * * obj )
2015-07-01 23:16:13 +03:00
class Message ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a message .
Telegram Documentation : https : / / core . telegram . org / bots / api #message
: param message_id : Unique message identifier inside this chat
: type message_id : : obj : ` int `
2022-11-05 22:23:00 +03:00
: param message_thread_id : Optional . Unique identifier of a message thread to which the message belongs ; for supergroups only
: type message_thread_id : : obj : ` int `
2022-07-26 14:16:35 +03:00
: param from_user : Optional . Sender of the message ; empty for messages sent to channels . For backward compatibility , the
field contains a fake sender user in non - channel chats , if the message was sent on behalf of a chat .
: type from_user : : class : ` telebot . types . User `
: param sender_chat : Optional . Sender of the message , sent on behalf of a chat . For example , the channel itself for
channel posts , the supergroup itself for messages from anonymous group administrators , the linked channel for
messages automatically forwarded to the discussion group . For backward compatibility , the field from contains a
fake sender user in non - channel chats , if the message was sent on behalf of a chat .
: type sender_chat : : class : ` telebot . types . Chat `
: param date : Date the message was sent in Unix time
: type date : : obj : ` int `
: param chat : Conversation the message belongs to
: type chat : : class : ` telebot . types . Chat `
: param forward_from : Optional . For forwarded messages , sender of the original message
: type forward_from : : class : ` telebot . types . User `
: param forward_from_chat : Optional . For messages forwarded from channels or from anonymous administrators ,
information about the original sender chat
: type forward_from_chat : : class : ` telebot . types . Chat `
: param forward_from_message_id : Optional . For messages forwarded from channels , identifier of the original
message in the channel
: type forward_from_message_id : : obj : ` int `
: param forward_signature : Optional . For forwarded messages that were originally sent in channels or by an
anonymous chat administrator , signature of the message sender if present
: type forward_signature : : obj : ` str `
: param forward_sender_name : Optional . Sender ' s name for messages forwarded from users who disallow adding a link
to their account in forwarded messages
: type forward_sender_name : : obj : ` str `
: param forward_date : Optional . For forwarded messages , date the original message was sent in Unix time
: type forward_date : : obj : ` int `
2022-11-05 22:23:00 +03:00
: param is_topic_message : Optional . True , if the message is sent to a forum topic
: type is_topic_message : : obj : ` bool `
2022-07-26 14:16:35 +03:00
: param is_automatic_forward : Optional . : obj : ` bool ` , if the message is a channel post that was automatically
forwarded to the connected discussion group
: type is_automatic_forward : : obj : ` bool `
: param reply_to_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 .
: type reply_to_message : : class : ` telebot . types . Message `
: param via_bot : Optional . Bot through which the message was sent
: type via_bot : : class : ` telebot . types . User `
: param edit_date : Optional . Date the message was last edited in Unix time
: type edit_date : : obj : ` int `
: param has_protected_content : Optional . : obj : ` bool ` , if the message can ' t be forwarded
: type has_protected_content : : obj : ` bool `
: param media_group_id : Optional . The unique identifier of a media message group this message belongs to
: type media_group_id : : obj : ` str `
: param author_signature : Optional . Signature of the post author for messages in channels , or the custom title of an
anonymous group administrator
: type author_signature : : obj : ` str `
: param text : Optional . For text messages , the actual UTF - 8 text of the message
: type text : : obj : ` str `
: param entities : Optional . For text messages , special entities like usernames , URLs , bot commands , etc . that
appear in the text
: type entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param animation : Optional . Message is an animation , information about the animation . For backward
compatibility , when this field is set , the document field will also be set
: type animation : : class : ` telebot . types . Animation `
: param audio : Optional . Message is an audio file , information about the file
: type audio : : class : ` telebot . types . Audio `
: param document : Optional . Message is a general file , information about the file
: type document : : class : ` telebot . types . Document `
: param photo : Optional . Message is a photo , available sizes of the photo
: type photo : : obj : ` list ` of : class : ` telebot . types . PhotoSize `
: param sticker : Optional . Message is a sticker , information about the sticker
: type sticker : : class : ` telebot . types . Sticker `
: param video : Optional . Message is a video , information about the video
: type video : : class : ` telebot . types . Video `
: param video_note : Optional . Message is a video note , information about the video message
: type video_note : : class : ` telebot . types . VideoNote `
: param voice : Optional . Message is a voice message , information about the file
: type voice : : class : ` telebot . types . Voice `
: param caption : Optional . Caption for the animation , audio , document , photo , video or voice
: type caption : : obj : ` str `
: param caption_entities : Optional . For messages with a caption , special entities like usernames , URLs , bot
commands , etc . that appear in the caption
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param contact : Optional . Message is a shared contact , information about the contact
: type contact : : class : ` telebot . types . Contact `
: param dice : Optional . Message is a dice with random value
: type dice : : class : ` telebot . types . Dice `
: param game : Optional . Message is a game , information about the game . More about games »
: type game : : class : ` telebot . types . Game `
: param poll : Optional . Message is a native poll , information about the poll
: type poll : : class : ` telebot . types . Poll `
: param venue : Optional . Message is a venue , information about the venue . For backward compatibility , when this
field is set , the location field will also be set
: type venue : : class : ` telebot . types . Venue `
: param location : Optional . Message is a shared location , information about the location
: type location : : class : ` telebot . types . Location `
: param new_chat_members : Optional . New members that were added to the group or supergroup and information about
them ( the bot itself may be one of these members )
: type new_chat_members : : obj : ` list ` of : class : ` telebot . types . User `
: param left_chat_member : Optional . A member was removed from the group , information about them ( this member may be
the bot itself )
: type left_chat_member : : class : ` telebot . types . User `
: param new_chat_title : Optional . A chat title was changed to this value
: type new_chat_title : : obj : ` str `
: param new_chat_photo : Optional . A chat photo was change to this value
: type new_chat_photo : : obj : ` list ` of : class : ` telebot . types . PhotoSize `
: param delete_chat_photo : Optional . Service message : the chat photo was deleted
: type delete_chat_photo : : obj : ` bool `
: param group_chat_created : Optional . Service message : the group has been created
: type group_chat_created : : obj : ` bool `
: param supergroup_chat_created : Optional . Service message : the supergroup has been created . This field can ' t be
received in a message coming through updates , because bot can ' t be a member of a supergroup when it is created. It can
only be found in reply_to_message if someone replies to a very first message in a directly created supergroup .
: type supergroup_chat_created : : obj : ` bool `
: param channel_chat_created : Optional . Service message : the channel has been created . This field can ' t be
received in a message coming through updates , because bot can ' t be a member of a channel when it is created. It can only
be found in reply_to_message if someone replies to a very first message in a channel .
: type channel_chat_created : : obj : ` bool `
: param message_auto_delete_timer_changed : Optional . Service message : auto - delete timer settings changed in
the chat
: type message_auto_delete_timer_changed : : class : ` telebot . types . MessageAutoDeleteTimerChanged `
: param migrate_to_chat_id : Optional . The group has been migrated to a supergroup with the specified identifier .
This number may have more than 32 significant bits and some programming languages may have difficulty / silent
defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or double - precision
float type are safe for storing this identifier .
: type migrate_to_chat_id : : obj : ` int `
: param migrate_from_chat_id : Optional . The supergroup has been migrated from a group with the specified
identifier . This number may have more than 32 significant bits and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this identifier .
: type migrate_from_chat_id : : obj : ` int `
: param pinned_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 .
: type pinned_message : : class : ` telebot . types . Message `
: param invoice : Optional . Message is an invoice for a payment , information about the invoice . More about payments »
: type invoice : : class : ` telebot . types . Invoice `
: param successful_payment : Optional . Message is a service message about a successful payment , information about
the payment . More about payments »
: type successful_payment : : class : ` telebot . types . SuccessfulPayment `
: param connected_website : Optional . The domain name of the website on which the user has logged in . More about
Telegram Login »
: type connected_website : : obj : ` str `
: param passport_data : Optional . Telegram Passport data
: type passport_data : : class : ` telebot . types . PassportData `
: param proximity_alert_triggered : Optional . Service message . A user in the chat triggered another user ' s
proximity alert while sharing Live Location .
: type proximity_alert_triggered : : class : ` telebot . types . ProximityAlertTriggered `
2022-11-06 00:04:33 +03:00
: param forum_topic_created : Optional . Service message : forum topic created
: type forum_topic_created : : class : ` telebot . types . ForumTopicCreated `
: param forum_topic_closed : Optional . Service message : forum topic closed
: type forum_topic_closed : : class : ` telebot . types . ForumTopicClosed `
: param forum_topic_reopened : Optional . Service message : forum topic reopened
: type forum_topic_reopened : : class : ` telebot . types . ForumTopicReopened `
2022-07-26 14:16:35 +03:00
: param video_chat_scheduled : Optional . Service message : video chat scheduled
: type video_chat_scheduled : : class : ` telebot . types . VideoChatScheduled `
: param video_chat_started : Optional . Service message : video chat started
: type video_chat_started : : class : ` telebot . types . VideoChatStarted `
: param video_chat_ended : Optional . Service message : video chat ended
: type video_chat_ended : : class : ` telebot . types . VideoChatEnded `
: param video_chat_participants_invited : Optional . Service message : new participants invited to a video chat
: type video_chat_participants_invited : : class : ` telebot . types . VideoChatParticipantsInvited `
: param web_app_data : Optional . Service message : data sent by a Web App
: type web_app_data : : class : ` telebot . types . WebAppData `
: param reply_markup : Optional . Inline keyboard attached to the message . login_url buttons are represented as
ordinary url buttons .
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: return : Instance of the class
: rtype : : class : ` telebot . types . Message `
"""
2015-06-26 13:02:30 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2015-06-26 13:02:30 +03:00
message_id = obj [ ' message_id ' ]
2020-04-11 16:54:25 +03:00
from_user = User . de_json ( obj . get ( ' from ' ) )
2015-06-26 13:02:30 +03:00
date = obj [ ' date ' ]
2016-04-14 05:57:18 +03:00
chat = Chat . de_json ( obj [ ' chat ' ] )
2015-06-28 12:19:15 +03:00
content_type = None
2015-06-26 16:56:49 +03:00
opts = { }
2021-08-18 18:47:38 +03:00
if ' sender_chat ' in obj :
opts [ ' sender_chat ' ] = Chat . de_json ( obj [ ' sender_chat ' ] )
2015-07-17 09:40:49 +03:00
if ' forward_from ' in obj :
opts [ ' forward_from ' ] = User . de_json ( obj [ ' forward_from ' ] )
2016-05-07 20:24:16 +03:00
if ' forward_from_chat ' in obj :
opts [ ' forward_from_chat ' ] = Chat . de_json ( obj [ ' forward_from_chat ' ] )
2016-11-21 09:10:51 +03:00
if ' forward_from_message_id ' in obj :
opts [ ' forward_from_message_id ' ] = obj . get ( ' forward_from_message_id ' )
2017-08-23 10:30:32 +03:00
if ' forward_signature ' in obj :
opts [ ' forward_signature ' ] = obj . get ( ' forward_signature ' )
2020-08-25 18:18:51 +03:00
if ' forward_sender_name ' in obj :
opts [ ' forward_sender_name ' ] = obj . get ( ' forward_sender_name ' )
2015-07-17 09:40:49 +03:00
if ' forward_date ' in obj :
2016-11-21 09:10:51 +03:00
opts [ ' forward_date ' ] = obj . get ( ' forward_date ' )
2021-12-07 20:17:51 +03:00
if ' is_automatic_forward ' in obj :
opts [ ' is_automatic_forward ' ] = obj . get ( ' is_automatic_forward ' )
2022-11-18 22:12:03 +03:00
if ' is_topic_message ' in obj :
opts [ ' is_topic_message ' ] = obj . get ( ' is_topic_message ' )
2022-11-18 22:21:06 +03:00
if ' message_thread_id ' in obj :
opts [ ' message_thread_id ' ] = obj . get ( ' message_thread_id ' )
2015-07-17 09:40:49 +03:00
if ' reply_to_message ' in obj :
opts [ ' reply_to_message ' ] = Message . de_json ( obj [ ' reply_to_message ' ] )
2021-06-17 21:28:53 +03:00
if ' via_bot ' in obj :
opts [ ' via_bot ' ] = User . de_json ( obj [ ' via_bot ' ] )
2016-05-22 13:32:53 +03:00
if ' edit_date ' in obj :
2016-05-22 13:55:54 +03:00
opts [ ' edit_date ' ] = obj . get ( ' edit_date ' )
2021-12-07 20:17:51 +03:00
if ' has_protected_content ' in obj :
opts [ ' has_protected_content ' ] = obj . get ( ' has_protected_content ' )
2018-01-24 14:05:38 +03:00
if ' media_group_id ' in obj :
opts [ ' media_group_id ' ] = obj . get ( ' media_group_id ' )
2017-08-23 10:30:32 +03:00
if ' author_signature ' in obj :
opts [ ' author_signature ' ] = obj . get ( ' author_signature ' )
2015-06-26 13:02:30 +03:00
if ' text ' in obj :
2015-06-26 16:56:49 +03:00
opts [ ' text ' ] = obj [ ' text ' ]
2015-06-28 12:19:15 +03:00
content_type = ' text '
2016-04-14 05:57:18 +03:00
if ' entities ' in obj :
opts [ ' entities ' ] = Message . parse_entities ( obj [ ' entities ' ] )
2017-10-22 19:50:51 +03:00
if ' caption_entities ' in obj :
opts [ ' caption_entities ' ] = Message . parse_entities ( obj [ ' caption_entities ' ] )
2015-06-28 12:19:15 +03:00
if ' audio ' in obj :
2015-07-01 23:34:40 +03:00
opts [ ' audio ' ] = Audio . de_json ( obj [ ' audio ' ] )
2015-06-28 12:19:15 +03:00
content_type = ' audio '
if ' document ' in obj :
2015-07-01 23:34:40 +03:00
opts [ ' document ' ] = Document . de_json ( obj [ ' document ' ] )
2015-06-28 12:19:15 +03:00
content_type = ' document '
2020-11-03 17:46:19 +03:00
if ' animation ' in obj :
2021-06-19 18:59:55 +03:00
# Document content type accompanies "animation",
# so "animation" should be checked below "document" to override it
2020-11-03 17:46:19 +03:00
opts [ ' animation ' ] = Animation . de_json ( obj [ ' animation ' ] )
content_type = ' animation '
2016-10-08 15:06:08 +03:00
if ' game ' in obj :
2016-10-29 23:23:39 +03:00
opts [ ' game ' ] = Game . de_json ( obj [ ' game ' ] )
2016-10-08 15:06:08 +03:00
content_type = ' game '
2015-06-28 12:19:15 +03:00
if ' photo ' in obj :
opts [ ' photo ' ] = Message . parse_photo ( obj [ ' photo ' ] )
content_type = ' photo '
if ' sticker ' in obj :
2015-07-01 23:34:40 +03:00
opts [ ' sticker ' ] = Sticker . de_json ( obj [ ' sticker ' ] )
2015-06-28 12:19:15 +03:00
content_type = ' sticker '
if ' video ' in obj :
2015-07-01 23:34:40 +03:00
opts [ ' video ' ] = Video . de_json ( obj [ ' video ' ] )
2015-06-28 12:19:15 +03:00
content_type = ' video '
2017-05-19 17:19:15 +03:00
if ' video_note ' in obj :
opts [ ' video_note ' ] = VideoNote . de_json ( obj [ ' video_note ' ] )
content_type = ' video_note '
2016-04-14 05:57:18 +03:00
if ' voice ' in obj :
opts [ ' voice ' ] = Audio . de_json ( obj [ ' voice ' ] )
content_type = ' voice '
if ' caption ' in obj :
opts [ ' caption ' ] = obj [ ' caption ' ]
2015-07-02 06:19:38 +03:00
if ' contact ' in obj :
opts [ ' contact ' ] = Contact . de_json ( json . dumps ( obj [ ' contact ' ] ) )
content_type = ' contact '
2016-04-14 06:02:19 +03:00
if ' location ' in obj :
opts [ ' location ' ] = Location . de_json ( obj [ ' location ' ] )
content_type = ' location '
if ' venue ' in obj :
opts [ ' venue ' ] = Venue . de_json ( obj [ ' venue ' ] )
content_type = ' venue '
2020-04-15 08:10:05 +03:00
if ' dice ' in obj :
opts [ ' dice ' ] = Dice . de_json ( obj [ ' dice ' ] )
content_type = ' dice '
2017-05-21 14:27:31 +03:00
if ' new_chat_members ' in obj :
2020-04-11 16:54:25 +03:00
new_chat_members = [ ]
for member in obj [ ' new_chat_members ' ] :
new_chat_members . append ( User . de_json ( member ) )
opts [ ' new_chat_members ' ] = new_chat_members
2017-05-21 14:27:31 +03:00
content_type = ' new_chat_members '
2016-04-14 06:15:58 +03:00
if ' left_chat_member ' in obj :
opts [ ' left_chat_member ' ] = User . de_json ( obj [ ' left_chat_member ' ] )
2016-04-24 18:53:13 +03:00
content_type = ' left_chat_member '
2015-07-03 04:41:11 +03:00
if ' new_chat_title ' in obj :
opts [ ' new_chat_title ' ] = obj [ ' new_chat_title ' ]
2017-11-30 18:34:07 +03:00
content_type = ' new_chat_title '
2015-07-03 04:41:11 +03:00
if ' new_chat_photo ' in obj :
2016-04-14 06:15:58 +03:00
opts [ ' new_chat_photo ' ] = Message . parse_photo ( obj [ ' new_chat_photo ' ] )
2017-11-30 18:34:07 +03:00
content_type = ' new_chat_photo '
2015-07-03 04:43:26 +03:00
if ' delete_chat_photo ' in obj :
opts [ ' delete_chat_photo ' ] = obj [ ' delete_chat_photo ' ]
2017-11-30 18:34:07 +03:00
content_type = ' delete_chat_photo '
2015-07-03 04:43:26 +03:00
if ' group_chat_created ' in obj :
opts [ ' group_chat_created ' ] = obj [ ' group_chat_created ' ]
2017-11-29 08:48:34 +03:00
content_type = ' group_chat_created '
2016-04-14 06:15:58 +03:00
if ' supergroup_chat_created ' in obj :
opts [ ' supergroup_chat_created ' ] = obj [ ' supergroup_chat_created ' ]
2017-11-29 08:48:34 +03:00
content_type = ' supergroup_chat_created '
2016-04-14 06:15:58 +03:00
if ' channel_chat_created ' in obj :
opts [ ' channel_chat_created ' ] = obj [ ' channel_chat_created ' ]
2017-11-29 08:48:34 +03:00
content_type = ' channel_chat_created '
2016-04-14 06:15:58 +03:00
if ' migrate_to_chat_id ' in obj :
opts [ ' migrate_to_chat_id ' ] = obj [ ' migrate_to_chat_id ' ]
2017-11-30 18:34:07 +03:00
content_type = ' migrate_to_chat_id '
2016-04-14 06:15:58 +03:00
if ' migrate_from_chat_id ' in obj :
opts [ ' migrate_from_chat_id ' ] = obj [ ' migrate_from_chat_id ' ]
2017-11-30 18:34:07 +03:00
content_type = ' migrate_from_chat_id '
2016-04-14 06:15:58 +03:00
if ' pinned_message ' in obj :
opts [ ' pinned_message ' ] = Message . de_json ( obj [ ' pinned_message ' ] )
2017-11-29 08:48:34 +03:00
content_type = ' pinned_message '
2017-05-21 16:52:56 +03:00
if ' invoice ' in obj :
opts [ ' invoice ' ] = Invoice . de_json ( obj [ ' invoice ' ] )
content_type = ' invoice '
if ' successful_payment ' in obj :
opts [ ' successful_payment ' ] = SuccessfulPayment . de_json ( obj [ ' successful_payment ' ] )
content_type = ' successful_payment '
2018-02-14 23:27:55 +03:00
if ' connected_website ' in obj :
opts [ ' connected_website ' ] = obj [ ' connected_website ' ]
content_type = ' connected_website '
2019-06-06 21:47:08 +03:00
if ' poll ' in obj :
opts [ ' poll ' ] = Poll . de_json ( obj [ ' poll ' ] )
content_type = ' poll '
2019-08-27 11:55:14 +03:00
if ' passport_data ' in obj :
opts [ ' passport_data ' ] = obj [ ' passport_data ' ]
content_type = ' passport_data '
2021-06-21 18:39:13 +03:00
if ' proximity_alert_triggered ' in obj :
opts [ ' proximity_alert_triggered ' ] = ProximityAlertTriggered . de_json ( obj [
' proximity_alert_triggered ' ] )
content_type = ' proximity_alert_triggered '
2022-04-17 14:39:09 +03:00
if ' video_chat_scheduled ' in obj :
2022-04-23 15:03:54 +03:00
opts [ ' video_chat_scheduled ' ] = VideoChatScheduled . de_json ( obj [ ' video_chat_scheduled ' ] )
opts [ ' voice_chat_scheduled ' ] = opts [ ' video_chat_scheduled ' ] # deprecated, for backward compatibility
2022-04-17 14:39:09 +03:00
content_type = ' video_chat_scheduled '
if ' video_chat_started ' in obj :
2022-04-23 15:03:54 +03:00
opts [ ' video_chat_started ' ] = VideoChatStarted . de_json ( obj [ ' video_chat_started ' ] )
opts [ ' voice_chat_started ' ] = opts [ ' video_chat_started ' ] # deprecated, for backward compatibility
2022-04-17 14:39:09 +03:00
content_type = ' video_chat_started '
if ' video_chat_ended ' in obj :
2022-04-23 15:03:54 +03:00
opts [ ' video_chat_ended ' ] = VideoChatEnded . de_json ( obj [ ' video_chat_ended ' ] )
opts [ ' voice_chat_ended ' ] = opts [ ' video_chat_ended ' ] # deprecated, for backward compatibility
2022-04-17 14:39:09 +03:00
content_type = ' video_chat_ended '
if ' video_chat_participants_invited ' in obj :
2022-04-23 15:03:54 +03:00
opts [ ' video_chat_participants_invited ' ] = VideoChatParticipantsInvited . de_json ( obj [ ' video_chat_participants_invited ' ] )
opts [ ' voice_chat_participants_invited ' ] = opts [ ' video_chat_participants_invited ' ] # deprecated, for backward compatibility
2022-04-17 14:39:09 +03:00
content_type = ' video_chat_participants_invited '
if ' web_app_data ' in obj :
opts [ ' web_app_data ' ] = WebAppData . de_json ( obj [ ' web_app_data ' ] )
content_type = ' web_app_data '
2021-06-21 18:39:13 +03:00
if ' message_auto_delete_timer_changed ' in obj :
2021-08-18 23:27:28 +03:00
opts [ ' message_auto_delete_timer_changed ' ] = MessageAutoDeleteTimerChanged . de_json ( obj [ ' message_auto_delete_timer_changed ' ] )
2021-06-21 18:39:13 +03:00
content_type = ' message_auto_delete_timer_changed '
2020-08-31 15:00:56 +03:00
if ' reply_markup ' in obj :
opts [ ' reply_markup ' ] = InlineKeyboardMarkup . de_json ( obj [ ' reply_markup ' ] )
2022-11-06 00:04:33 +03:00
if ' forum_topic_created ' in obj :
opts [ ' forum_topic_created ' ] = ForumTopicCreated . de_json ( obj [ ' forum_topic_created ' ] )
content_type = ' forum_topic_created '
if ' forum_topic_closed ' in obj :
opts [ ' forum_topic_closed ' ] = ForumTopicClosed . de_json ( obj [ ' forum_topic_closed ' ] )
content_type = ' forum_topic_closed '
if ' forum_topic_reopened ' in obj :
opts [ ' forum_topic_reopened ' ] = ForumTopicReopened . de_json ( obj [ ' forum_topic_reopened ' ] )
content_type = ' forum_topic_reopened '
2018-03-21 10:45:34 +03:00
return cls ( message_id , from_user , date , chat , content_type , opts , json_string )
2015-06-26 13:02:30 +03:00
@classmethod
def parse_chat ( cls , chat ) :
2022-07-26 14:16:35 +03:00
"""
Parses chat .
"""
2015-06-28 12:19:15 +03:00
if ' first_name ' not in chat :
2015-07-01 23:34:40 +03:00
return GroupChat . de_json ( chat )
2015-06-26 13:02:30 +03:00
else :
2015-07-01 23:34:40 +03:00
return User . de_json ( chat )
2015-06-26 13:02:30 +03:00
2015-06-28 12:19:15 +03:00
@classmethod
def parse_photo ( cls , photo_size_array ) :
2022-07-26 14:16:35 +03:00
"""
Parses photo array .
"""
2015-06-28 12:19:15 +03:00
ret = [ ]
for ps in photo_size_array :
2015-07-01 23:34:40 +03:00
ret . append ( PhotoSize . de_json ( ps ) )
2015-06-28 12:19:15 +03:00
return ret
2016-04-14 05:57:18 +03:00
@classmethod
def parse_entities ( cls , message_entity_array ) :
2022-07-26 14:16:35 +03:00
"""
Parses message entity array .
"""
2016-04-14 05:57:18 +03:00
ret = [ ]
for me in message_entity_array :
ret . append ( MessageEntity . de_json ( me ) )
return ret
2018-03-21 10:44:37 +03:00
def __init__ ( self , message_id , from_user , date , chat , content_type , options , json_string ) :
2021-06-17 21:28:53 +03:00
self . content_type : str = content_type
self . id : int = message_id # Lets fix the telegram usability ####up with ID in Message :)
self . message_id : int = message_id
self . from_user : User = from_user
self . date : int = date
self . chat : Chat = chat
2021-08-18 18:47:38 +03:00
self . sender_chat : Optional [ Chat ] = None
2021-06-21 20:59:39 +03:00
self . forward_from : Optional [ User ] = None
self . forward_from_chat : Optional [ Chat ] = None
self . forward_from_message_id : Optional [ int ] = None
self . forward_signature : Optional [ str ] = None
self . forward_sender_name : Optional [ str ] = None
self . forward_date : Optional [ int ] = None
2021-12-07 20:17:51 +03:00
self . is_automatic_forward : Optional [ bool ] = None
2021-06-21 20:59:39 +03:00
self . reply_to_message : Optional [ Message ] = None
self . via_bot : Optional [ User ] = None
self . edit_date : Optional [ int ] = None
2021-12-07 20:17:51 +03:00
self . has_protected_content : Optional [ bool ] = None
2021-06-21 20:59:39 +03:00
self . media_group_id : Optional [ str ] = None
self . author_signature : Optional [ str ] = None
self . text : Optional [ str ] = None
self . entities : Optional [ List [ MessageEntity ] ] = None
self . caption_entities : Optional [ List [ MessageEntity ] ] = None
self . audio : Optional [ Audio ] = None
self . document : Optional [ Document ] = None
self . photo : Optional [ List [ PhotoSize ] ] = None
self . sticker : Optional [ Sticker ] = None
self . video : Optional [ Video ] = None
self . video_note : Optional [ VideoNote ] = None
self . voice : Optional [ Voice ] = None
self . caption : Optional [ str ] = None
self . contact : Optional [ Contact ] = None
self . location : Optional [ Location ] = None
self . venue : Optional [ Venue ] = None
self . animation : Optional [ Animation ] = None
self . dice : Optional [ Dice ] = None
self . new_chat_member : Optional [ User ] = None # Deprecated since Bot API 3.0. Not processed anymore
self . new_chat_members : Optional [ List [ User ] ] = None
self . left_chat_member : Optional [ User ] = None
self . new_chat_title : Optional [ str ] = None
self . new_chat_photo : Optional [ List [ PhotoSize ] ] = None
self . delete_chat_photo : Optional [ bool ] = None
self . group_chat_created : Optional [ bool ] = None
self . supergroup_chat_created : Optional [ bool ] = None
self . channel_chat_created : Optional [ bool ] = None
self . migrate_to_chat_id : Optional [ int ] = None
self . migrate_from_chat_id : Optional [ int ] = None
self . pinned_message : Optional [ Message ] = None
self . invoice : Optional [ Invoice ] = None
self . successful_payment : Optional [ SuccessfulPayment ] = None
self . connected_website : Optional [ str ] = None
self . reply_markup : Optional [ InlineKeyboardMarkup ] = None
2022-11-05 22:23:00 +03:00
self . message_thread_id : Optional [ int ] = None
self . is_topic_message : Optional [ bool ] = None
2022-11-06 00:04:33 +03:00
self . forum_topic_created : Optional [ ForumTopicCreated ] = None
self . forum_topic_closed : Optional [ ForumTopicClosed ] = None
self . forum_topic_reopened : Optional [ ForumTopicReopened ] = None
2015-06-26 13:02:30 +03:00
for key in options :
setattr ( self , key , options [ key ] )
2018-03-21 10:44:37 +03:00
self . json = json_string
2015-06-26 09:55:13 +03:00
2018-05-14 13:29:34 +03:00
def __html_text ( self , text , entities ) :
2018-04-04 10:47:37 +03:00
"""
Author : @sviat9440
2020-04-11 16:54:25 +03:00
Updaters : @badiboy
2018-04-04 10:47:37 +03:00
Message : " *Test* parse _formatting_, [url](https://example.com), [text_mention](tg://user?id=123456) and mention @username "
2022-07-26 14:16:35 +03:00
. . code - block : : python3
: caption : Example :
2018-04-04 10:47:37 +03:00
message . html_text
>> " <b>Test</b> parse <i>formatting</i>, <a href= \" https://example.com \" >url</a>, <a href= \" tg://user?id=123456 \" >text_mention</a> and mention @username "
2021-06-19 18:59:55 +03:00
Custom subs :
2018-04-04 10:47:37 +03:00
You can customize the substitutes . By default , there is no substitute for the entities : hashtag , bot_command , email . You can add or modify substitute an existing entity .
2022-07-26 14:16:35 +03:00
. . code - block : : python3
: caption : Example :
2018-04-04 10:47:37 +03:00
message . custom_subs = { " bold " : " <strong class= \" example \" > {text} </strong> " , " italic " : " <i class= \" example \" > {text} </i> " , " mention " : " <a href= {url} > {text} </a> " }
message . html_text
>> " <strong class= \" example \" >Test</strong> parse <i class= \" example \" >formatting</i>, <a href= \" https://example.com \" >url</a> and <a href= \" tg://user?id=123456 \" >text_mention</a> and mention <a href= \" https://t.me/username \" >@username</a> "
"""
2018-05-14 13:29:34 +03:00
if not entities :
return text
2020-04-11 16:54:25 +03:00
2018-04-04 10:47:37 +03:00
_subs = {
2021-06-19 18:59:55 +03:00
" bold " : " <b> {text} </b> " ,
" italic " : " <i> {text} </i> " ,
" pre " : " <pre> {text} </pre> " ,
" code " : " <code> {text} </code> " ,
# "url": "<a href=\"{url}\">{text}</a>", # @badiboy plain URLs have no text and do not need tags
2020-07-17 13:43:45 +03:00
" text_link " : " <a href= \" {url} \" > {text} </a> " ,
" strikethrough " : " <s> {text} </s> " ,
2022-01-02 13:12:15 +03:00
" underline " : " <u> {text} </u> " ,
" spoiler " : " <span class= \" tg-spoiler \" > {text} </span> " ,
2021-06-19 18:59:55 +03:00
}
2020-07-17 13:43:45 +03:00
2018-04-04 10:47:37 +03:00
if hasattr ( self , " custom_subs " ) :
2020-04-25 22:22:08 +03:00
for key , value in self . custom_subs . items ( ) :
_subs [ key ] = value
2018-05-14 13:29:34 +03:00
utf16_text = text . encode ( " utf-16-le " )
2018-04-04 10:47:37 +03:00
html_text = " "
2018-08-17 13:01:03 +03:00
2020-04-25 22:22:08 +03:00
def func ( upd_text , subst_type = None , url = None , user = None ) :
upd_text = upd_text . decode ( " utf-16-le " )
if subst_type == " text_mention " :
2020-10-14 12:06:49 +03:00
subst_type = " text_link "
2018-04-04 10:47:37 +03:00
url = " tg://user?id= {0} " . format ( user . id )
2020-04-25 22:22:08 +03:00
elif subst_type == " mention " :
url = " https://t.me/ {0} " . format ( upd_text [ 1 : ] )
upd_text = upd_text . replace ( " & " , " & " ) . replace ( " < " , " < " ) . replace ( " > " , " > " )
if not subst_type or not _subs . get ( subst_type ) :
return upd_text
subs = _subs . get ( subst_type )
return subs . format ( text = upd_text , url = url )
2018-04-04 10:47:37 +03:00
offset = 0
2018-05-14 13:29:34 +03:00
for entity in entities :
2018-04-04 10:47:37 +03:00
if entity . offset > offset :
2018-04-15 19:19:29 +03:00
html_text + = func ( utf16_text [ offset * 2 : entity . offset * 2 ] )
2018-04-04 10:47:37 +03:00
offset = entity . offset
2020-04-11 16:54:25 +03:00
html_text + = func ( utf16_text [ offset * 2 : ( offset + entity . length ) * 2 ] , entity . type , entity . url , entity . user )
offset + = entity . length
elif entity . offset == offset :
html_text + = func ( utf16_text [ offset * 2 : ( offset + entity . length ) * 2 ] , entity . type , entity . url , entity . user )
offset + = entity . length
else :
2022-08-16 19:39:20 +03:00
# Here we are processing nested entities.
# We shouldn't update offset, because they are the same as entity before.
# And, here we are replacing previous string with a new html-rendered text(previous string is already html-rendered,
# And we don't change it).
entity_string = utf16_text [ entity . offset * 2 : ( entity . offset + entity . length ) * 2 ]
formatted_string = func ( entity_string , entity . type , entity . url , entity . user )
entity_string_decoded = entity_string . decode ( " utf-16-le " )
last_occurence = html_text . rfind ( entity_string_decoded )
string_length = len ( entity_string_decoded )
2022-11-22 17:36:15 +03:00
#html_text = html_text.replace(html_text[last_occurence:last_occurence+string_length], formatted_string)
html_text = html_text [ : last_occurence ] + formatted_string + html_text [ last_occurence + string_length : ]
2018-04-15 19:19:29 +03:00
if offset * 2 < len ( utf16_text ) :
html_text + = func ( utf16_text [ offset * 2 : ] )
2022-08-16 19:39:20 +03:00
2018-04-04 10:47:37 +03:00
return html_text
2018-05-14 13:29:34 +03:00
@property
def html_text ( self ) :
2022-07-26 14:16:35 +03:00
"""
Returns html - rendered text .
"""
2018-05-14 13:29:34 +03:00
return self . __html_text ( self . text , self . entities )
@property
def html_caption ( self ) :
2022-07-26 14:16:35 +03:00
"""
Returns html - rendered caption .
"""
2018-05-14 13:29:34 +03:00
return self . __html_text ( self . caption , self . caption_entities )
2015-06-26 09:55:13 +03:00
2018-08-17 13:01:03 +03:00
2021-01-12 10:47:53 +03:00
class MessageEntity ( Dictionaryable , JsonSerializable , JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents one special entity in a text message . For example , hashtags , usernames , URLs , etc .
Telegram Documentation : https : / / core . telegram . org / bots / api #messageentity
: param type : Type of the entity . Currently , can be “ mention ” ( @username ) , “ hashtag ” ( #hashtag), “cashtag”
( $ USD ) , “ bot_command ” ( / start @jobs_bot ) , “ url ” ( https : / / telegram . org ) , “ email ”
( do - not - reply @telegram.org ) , “ phone_number ” ( + 1 - 212 - 555 - 0123 ) , “ bold ” ( bold text ) , “ italic ” ( italic text ) ,
“ underline ” ( underlined text ) , “ strikethrough ” ( strikethrough text ) , “ spoiler ” ( spoiler message ) , “ code ”
( monowidth string ) , “ pre ” ( monowidth block ) , “ text_link ” ( for clickable text URLs ) , “ text_mention ” ( for users
2022-08-12 20:10:08 +03:00
without usernames ) , “ custom_emoji ” ( for inline custom emoji stickers )
2022-07-26 14:16:35 +03:00
: type type : : obj : ` str `
: param offset : Offset in UTF - 16 code units to the start of the entity
: type offset : : obj : ` int `
: param length : Length of the entity in UTF - 16 code units
: type length : : obj : ` int `
: param url : Optional . For “ text_link ” only , URL that will be opened after user taps on the text
: type url : : obj : ` str `
: param user : Optional . For “ text_mention ” only , the mentioned user
: type user : : class : ` telebot . types . User `
: param language : Optional . For “ pre ” only , the programming language of the entity text
: type language : : obj : ` str `
2022-08-12 20:10:08 +03:00
: param custom_emoji_id : Optional . For “ custom_emoji ” only , unique identifier of the custom emoji .
2022-08-13 11:22:25 +03:00
Use get_custom_emoji_stickers to get full information about the sticker .
2022-08-12 20:10:08 +03:00
: type custom_emoji_id : : obj : ` str `
2022-07-26 14:16:35 +03:00
: return : Instance of the class
: rtype : : class : ` telebot . types . MessageEntity `
"""
2021-06-17 21:28:53 +03:00
@staticmethod
2021-06-19 18:59:55 +03:00
def to_list_of_dicts ( entity_list ) - > Union [ List [ Dict ] , None ] :
2022-07-26 14:16:35 +03:00
"""
Converts a list of MessageEntity objects to a list of dictionaries .
"""
2021-06-17 21:28:53 +03:00
res = [ ]
for e in entity_list :
res . append ( MessageEntity . to_dict ( e ) )
return res or None
2021-06-19 18:59:55 +03:00
2016-04-14 05:51:05 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2016-04-14 05:51:05 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
if ' user ' in obj :
obj [ ' user ' ] = User . de_json ( obj [ ' user ' ] )
return cls ( * * obj )
2022-08-12 20:10:08 +03:00
def __init__ ( self , type , offset , length , url = None , user = None , language = None , custom_emoji_id = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . type : str = type
self . offset : int = offset
self . length : int = length
self . url : str = url
self . user : User = user
self . language : str = language
2022-08-12 20:10:08 +03:00
self . custom_emoji_id : str = custom_emoji_id
2016-04-14 05:51:05 +03:00
2021-01-12 10:47:53 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
return { " type " : self . type ,
" offset " : self . offset ,
" length " : self . length ,
" url " : self . url ,
" user " : self . user ,
2022-08-12 20:10:08 +03:00
" language " : self . language ,
" custom_emoji_id " : self . custom_emoji_id }
2021-01-12 10:47:53 +03:00
2016-04-14 05:51:05 +03:00
2020-04-15 08:10:05 +03:00
class Dice ( JsonSerializable , Dictionaryable , JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents an animated emoji that displays a random value .
Telegram Documentation : https : / / core . telegram . org / bots / api #dice
: param emoji : Emoji on which the dice throw animation is based
: type emoji : : obj : ` str `
: param value : Value of the dice , 1 - 6 for “ 🎲 ” , “ 🎯 ” and “ 🎳 ” base emoji , 1 - 5 for “ 🏀 ” and “ ⚽ ” base emoji , 1 - 64 for “ 🎰 ” base emoji
: type value : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Dice `
"""
2020-04-15 08:10:05 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2020-05-08 21:06:39 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , value , emoji , * * kwargs ) :
self . value : int = value
self . emoji : str = emoji
2020-05-08 21:06:39 +03:00
2020-04-15 08:10:05 +03:00
def to_json ( self ) :
2020-05-09 00:51:18 +03:00
return json . dumps ( self . to_dict ( ) )
2020-05-08 21:06:39 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
2020-04-27 08:30:05 +03:00
return { ' value ' : self . value ,
' emoji ' : self . emoji }
2020-04-15 08:10:05 +03:00
2015-07-01 23:16:13 +03:00
class PhotoSize ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents one size of a photo or a file / sticker thumbnail .
Telegram Documentation : https : / / core . telegram . org / bots / api #photosize
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param width : Photo width
: type width : : obj : ` int `
: param height : Photo height
: type height : : obj : ` int `
: param file_size : Optional . File size in bytes
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . PhotoSize `
"""
2015-06-28 12:19:15 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , width , height , file_size = None , * * kwargs ) :
2021-06-22 16:55:14 +03:00
self . file_id : str = file_id
2021-06-17 21:28:53 +03:00
self . file_unique_id : str = file_unique_id
self . width : int = width
2021-06-22 16:55:14 +03:00
self . height : int = height
self . file_size : int = file_size
2015-06-26 09:55:13 +03:00
2015-07-01 23:16:13 +03:00
class Audio ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents an audio file to be treated as music by the Telegram clients .
Telegram Documentation : https : / / core . telegram . org / bots / api #audio
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param duration : Duration of the audio in seconds as defined by sender
: type duration : : obj : ` int `
: param performer : Optional . Performer of the audio as defined by sender or by audio tags
: type performer : : obj : ` str `
: param title : Optional . Title of the audio as defined by sender or by audio tags
: type title : : obj : ` str `
: param file_name : Optional . Original filename as defined by sender
: type file_name : : obj : ` str `
: param mime_type : Optional . MIME type of the file as defined by sender
: type mime_type : : obj : ` str `
: param file_size : Optional . File size in bytes . It can be bigger than 2 ^ 31 and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this value .
: type file_size : : obj : ` int `
: param thumb : Optional . Thumbnail of the album cover to which the music file belongs
: type thumb : : class : ` telebot . types . PhotoSize `
: return : Instance of the class
: rtype : : class : ` telebot . types . Audio `
"""
2015-08-19 13:08:01 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2015-08-19 13:08:01 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
obj [ ' thumb ' ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
2021-06-18 23:35:49 +03:00
else :
obj [ ' thumb ' ] = None
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , duration , performer = None , title = None , file_name = None , mime_type = None ,
file_size = None , thumb = None , * * kwargs ) :
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . duration : int = duration
self . performer : str = performer
self . title : str = title
self . file_name : str = file_name
self . mime_type : str = mime_type
self . file_size : int = file_size
self . thumb : PhotoSize = thumb
2015-08-19 13:08:01 +03:00
class Voice ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a voice note .
Telegram Documentation : https : / / core . telegram . org / bots / api #voice
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param duration : Duration of the audio in seconds as defined by sender
: type duration : : obj : ` int `
: param mime_type : Optional . MIME type of the file as defined by sender
: type mime_type : : obj : ` str `
: param file_size : Optional . File size in bytes . It can be bigger than 2 ^ 31 and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this value .
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Voice `
"""
2015-06-28 12:19:15 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-19 18:59:55 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , duration , mime_type = None , file_size = None , * * kwargs ) :
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . duration : int = duration
self . mime_type : str = mime_type
self . file_size : int = file_size
2015-06-26 09:55:13 +03:00
2015-07-01 23:16:13 +03:00
class Document ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a general file ( as opposed to photos , voice messages and audio files ) .
Telegram Documentation : https : / / core . telegram . org / bots / api #document
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param thumb : Optional . Document thumbnail as defined by sender
: type thumb : : class : ` telebot . types . PhotoSize `
: param file_name : Optional . Original filename as defined by sender
: type file_name : : obj : ` str `
: param mime_type : Optional . MIME type of the file as defined by sender
: type mime_type : : obj : ` str `
: param file_size : Optional . File size in bytes . It can be bigger than 2 ^ 31 and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this value .
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Document `
"""
2015-06-28 12:19:15 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2015-07-01 23:16:13 +03:00
obj = cls . check_json ( json_string )
2015-10-15 17:53:59 +03:00
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
2021-06-17 21:28:53 +03:00
obj [ ' thumb ' ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
2021-06-18 23:35:49 +03:00
else :
obj [ ' thumb ' ] = None
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , thumb = None , file_name = None , mime_type = None , file_size = None , * * kwargs ) :
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . thumb : PhotoSize = thumb
self . file_name : str = file_name
self . mime_type : str = mime_type
self . file_size : int = file_size
2015-06-26 09:55:13 +03:00
2015-07-01 23:16:13 +03:00
class Video ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a video file .
Telegram Documentation : https : / / core . telegram . org / bots / api #video
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param width : Video width as defined by sender
: type width : : obj : ` int `
: param height : Video height as defined by sender
: type height : : obj : ` int `
: param duration : Duration of the video in seconds as defined by sender
: type duration : : obj : ` int `
: param thumb : Optional . Video thumbnail
: type thumb : : class : ` telebot . types . PhotoSize `
: param file_name : Optional . Original filename as defined by sender
: type file_name : : obj : ` str `
: param mime_type : Optional . MIME type of the file as defined by sender
: type mime_type : : obj : ` str `
: param file_size : Optional . File size in bytes . It can be bigger than 2 ^ 31 and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this value .
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Video `
"""
2015-06-28 12:19:15 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2015-07-01 23:16:13 +03:00
obj = cls . check_json ( json_string )
2021-06-19 18:59:55 +03:00
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
2021-06-17 21:28:53 +03:00
obj [ ' thumb ' ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , width , height , duration , thumb = None , file_name = None , mime_type = None , file_size = None , * * kwargs ) :
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . width : int = width
self . height : int = height
self . duration : int = duration
self . thumb : PhotoSize = thumb
self . file_name : str = file_name
self . mime_type : str = mime_type
self . file_size : int = file_size
2015-06-26 09:55:13 +03:00
2017-05-19 17:19:15 +03:00
class VideoNote ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a video message ( available in Telegram apps as of v .4 .0 ) .
2021-06-17 21:28:53 +03:00
2022-07-26 14:16:35 +03:00
Telegram Documentation : https : / / core . telegram . org / bots / api #videonote
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param length : Video width and height ( diameter of the video message ) as defined by sender
: type length : : obj : ` int `
: param duration : Duration of the video in seconds as defined by sender
: type duration : : obj : ` int `
: param thumb : Optional . Video thumbnail
: type thumb : : class : ` telebot . types . PhotoSize `
: param file_size : Optional . File size in bytes
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . VideoNote `
"""
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
obj [ ' thumb ' ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , length , duration , thumb = None , file_size = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . length : int = length
self . duration : int = duration
self . thumb : PhotoSize = thumb
self . file_size : int = file_size
2017-05-19 17:19:15 +03:00
2015-07-02 15:12:10 +03:00
class Contact ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a phone contact .
Telegram Documentation : https : / / core . telegram . org / bots / api #contact
: param phone_number : Contact ' s phone number
: type phone_number : : obj : ` str `
: param first_name : Contact ' s first name
: type first_name : : obj : ` str `
: param last_name : Optional . Contact ' s last name
: type last_name : : obj : ` str `
: param user_id : Optional . Contact ' s user identifier in Telegram. This number may have more than 32 significant bits
and some programming languages may have difficulty / silent defects in interpreting it . But it has at most 52
significant bits , so a 64 - bit integer or double - precision float type are safe for storing this identifier .
: type user_id : : obj : ` int `
: param vcard : Optional . Additional data about the contact in the form of a vCard
: type vcard : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . Contact `
"""
2015-07-02 06:19:38 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , phone_number , first_name , last_name = None , user_id = None , vcard = None , * * kwargs ) :
self . phone_number : str = phone_number
self . first_name : str = first_name
self . last_name : str = last_name
self . user_id : int = user_id
self . vcard : str = vcard
2015-06-26 09:55:13 +03:00
2021-06-17 21:28:53 +03:00
class Location ( JsonDeserializable , JsonSerializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a point on the map .
Telegram Documentation : https : / / core . telegram . org / bots / api #location
: param longitude : Longitude as defined by sender
: type longitude : : obj : ` float `
: param latitude : Latitude as defined by sender
: type latitude : : obj : ` float `
: param horizontal_accuracy : Optional . The radius of uncertainty for the location , measured in meters ; 0 - 1500
: type horizontal_accuracy : : obj : ` float ` number
: param live_period : Optional . Time relative to the message sending date , during which the location can be updated ;
in seconds . For active live locations only .
: type live_period : : obj : ` int `
: param heading : Optional . The direction in which user is moving , in degrees ; 1 - 360. For active live locations only .
: type heading : : obj : ` int `
: param proximity_alert_radius : Optional . The maximum distance for proximity alerts about approaching another
chat member , in meters . For sent live locations only .
: type proximity_alert_radius : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Location `
"""
2015-06-28 12:19:15 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2021-06-19 18:59:55 +03:00
def __init__ ( self , longitude , latitude , horizontal_accuracy = None ,
live_period = None , heading = None , proximity_alert_radius = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . longitude : float = longitude
self . latitude : float = latitude
self . horizontal_accuracy : float = horizontal_accuracy
self . live_period : int = live_period
self . heading : int = heading
self . proximity_alert_radius : int = proximity_alert_radius
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
return {
" longitude " : self . longitude ,
" latitude " : self . latitude ,
" horizontal_accuracy " : self . horizontal_accuracy ,
" live_period " : self . live_period ,
" heading " : self . heading ,
" proximity_alert_radius " : self . proximity_alert_radius ,
}
2015-06-26 09:55:13 +03:00
2016-04-14 06:00:33 +03:00
class Venue ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a venue .
Telegram Documentation : https : / / core . telegram . org / bots / api #venue
: param location : Venue location . Can ' t be a live location
: type location : : class : ` telebot . types . Location `
: param title : Name of the venue
: type title : : obj : ` str `
: param address : Address of the venue
: type address : : obj : ` str `
: param foursquare_id : Optional . Foursquare identifier of the venue
: type foursquare_id : : obj : ` str `
: param foursquare_type : Optional . Foursquare type of the venue . ( For example , “ arts_entertainment / default ” ,
“ arts_entertainment / aquarium ” or “ food / icecream ” . )
: type foursquare_type : : obj : ` str `
: param google_place_id : Optional . Google Places identifier of the venue
: type google_place_id : : obj : ` str `
: param google_place_type : Optional . Google Places type of the venue . ( See supported types . )
: type google_place_type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . Venue `
"""
2016-04-14 06:00:33 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2020-04-11 17:06:14 +03:00
obj = cls . check_json ( json_string )
2021-06-19 21:13:53 +03:00
obj [ ' location ' ] = Location . de_json ( obj [ ' location ' ] )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , location , title , address , foursquare_id = None , foursquare_type = None ,
google_place_id = None , google_place_type = None , * * kwargs ) :
self . location : Location = location
self . title : str = title
self . address : str = address
self . foursquare_id : str = foursquare_id
self . foursquare_type : str = foursquare_type
self . google_place_id : str = google_place_id
self . google_place_type : str = google_place_type
2016-04-14 06:00:33 +03:00
2015-07-01 23:16:13 +03:00
class UserProfilePhotos ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represent a user ' s profile pictures.
Telegram Documentation : https : / / core . telegram . org / bots / api #userprofilephotos
: param total_count : Total number of profile pictures the target user has
: type total_count : : obj : ` int `
: param photos : Requested profile pictures ( in up to 4 sizes each )
: type photos : : obj : ` list ` of : obj : ` list ` of : class : ` telebot . types . PhotoSize `
: return : Instance of the class
: rtype : : class : ` telebot . types . UserProfilePhotos `
"""
2015-06-30 17:40:44 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2015-07-01 23:16:13 +03:00
obj = cls . check_json ( json_string )
2021-06-19 18:59:55 +03:00
if ' photos ' in obj :
photos = [ [ PhotoSize . de_json ( y ) for y in x ] for x in obj [ ' photos ' ] ]
obj [ ' photos ' ] = photos
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2015-06-30 17:40:44 +03:00
2021-06-19 18:59:55 +03:00
def __init__ ( self , total_count , photos = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . total_count : int = total_count
self . photos : List [ PhotoSize ] = photos
2015-06-26 09:55:13 +03:00
2015-09-18 21:31:29 +03:00
2015-10-12 05:36:58 +03:00
class File ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a file ready to be downloaded . The file can be downloaded via the link https : / / api . telegram . org / file / bot < token > / < file_path > . 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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #file
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param file_size : Optional . File size in bytes . It can be bigger than 2 ^ 31 and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this value .
: type file_size : : obj : ` int `
: param file_path : Optional . File path . Use https : / / api . telegram . org / file / bot < token > / < file_path > to get the
file .
: type file_path : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . File `
"""
2015-09-18 21:31:29 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2015-09-18 21:31:29 +03:00
2022-05-08 23:34:56 +03:00
def __init__ ( self , file_id , file_unique_id , file_size = None , file_path = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . file_size : int = file_size
self . file_path : str = file_path
2015-09-18 21:31:29 +03:00
2015-06-26 09:55:13 +03:00
2015-07-01 23:16:13 +03:00
class ForceReply ( JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
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.
Telegram Documentation : https : / / core . telegram . org / bots / api #forcereply
: param force_reply : Shows reply interface to the user , as if they manually selected the bot ' s message and tapped
' Reply '
: type force_reply : : obj : ` bool `
: param input_field_placeholder : Optional . The placeholder to be shown in the input field when the reply is active ;
1 - 64 characters
: type input_field_placeholder : : obj : ` str `
: param selective : 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 .
: type selective : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . ForceReply `
"""
2021-06-28 10:31:06 +03:00
def __init__ ( self , selective : Optional [ bool ] = None , input_field_placeholder : Optional [ str ] = None ) :
2021-06-17 21:28:53 +03:00
self . selective : bool = selective
2021-06-28 10:31:06 +03:00
self . input_field_placeholder : str = input_field_placeholder
2015-07-01 19:17:33 +03:00
def to_json ( self ) :
json_dict = { ' force_reply ' : True }
2021-06-28 10:31:06 +03:00
if self . selective is not None :
2021-09-30 11:56:36 +03:00
json_dict [ ' selective ' ] = self . selective
2021-06-26 14:36:14 +03:00
if self . input_field_placeholder :
json_dict [ ' input_field_placeholder ' ] = self . input_field_placeholder
2015-07-01 19:17:33 +03:00
return json . dumps ( json_dict )
2016-11-16 14:18:39 +03:00
class ReplyKeyboardRemove ( JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
Upon receiving a message with this object , Telegram clients will remove 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 ) .
Telegram Documentation : https : / / core . telegram . org / bots / api #replykeyboardremove
: param remove_keyboard : Requests clients to remove the custom keyboard ( user will not be able to summon this
keyboard ; if you want to hide the keyboard from sight but keep it accessible , use one_time_keyboard in
ReplyKeyboardMarkup )
Note that this parameter is set to True by default by the library . You cannot modify it .
: type remove_keyboard : : obj : ` bool `
: param selective : Optional . Use this parameter if you want to remove the keyboard for 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 user votes in a poll , bot returns confirmation
message in reply to the vote and removes the keyboard for that user , while still showing the keyboard with poll options
to users who haven ' t voted yet.
: type selective : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . ReplyKeyboardRemove `
"""
2015-07-01 19:17:33 +03:00
def __init__ ( self , selective = None ) :
2021-06-17 21:28:53 +03:00
self . selective : bool = selective
2015-07-01 19:17:33 +03:00
def to_json ( self ) :
2016-11-21 08:57:38 +03:00
json_dict = { ' remove_keyboard ' : True }
2015-07-01 19:17:33 +03:00
if self . selective :
2021-09-30 11:56:36 +03:00
json_dict [ ' selective ' ] = self . selective
2015-07-01 19:17:33 +03:00
return json . dumps ( json_dict )
2022-07-26 14:27:15 +03:00
class WebAppInfo ( JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Describes a Web App .
Telegram Documentation : https : / / core . telegram . org / bots / api #webappinfo
: param url : An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps
: type url : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . WebAppInfo `
"""
2022-04-17 14:39:09 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
return cls ( * * obj )
def __init__ ( self , url , * * kwargs ) :
self . url : str = url
def to_dict ( self ) :
return { ' url ' : self . url }
2015-07-01 23:16:13 +03:00
class ReplyKeyboardMarkup ( JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a custom keyboard with reply options ( see Introduction to bots for details and examples ) .
. . code - block : : python3
: caption : Example on creating ReplyKeyboardMarkup object
from telebot . types import ReplyKeyboardMarkup , KeyboardButton
markup = ReplyKeyboardMarkup ( resize_keyboard = True )
markup . add ( KeyboardButton ( ' Text ' ) )
# or:
markup . add ( ' Text ' )
# display this markup:
bot . send_message ( chat_id , ' Text ' , reply_markup = markup )
Telegram Documentation : https : / / core . telegram . org / bots / api #replykeyboardmarkup
: param keyboard : : obj : ` list ` of button rows , each represented by an : obj : ` list ` of
: class : ` telebot . types . KeyboardButton ` objects
: type keyboard : : obj : ` list ` of : obj : ` list ` of : class : ` telebot . types . KeyboardButton `
: param resize_keyboard : 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.
: type resize_keyboard : : obj : ` bool `
: param one_time_keyboard : Optional . Requests clients to hide the keyboard as soon as it ' s been used. The keyboard
will still be available , but clients will automatically display the usual letter - keyboard in the chat - the user can
press a special button in the input field to see the custom keyboard again . Defaults to false .
: type one_time_keyboard : : obj : ` bool `
: param input_field_placeholder : Optional . The placeholder to be shown in the input field when the keyboard is
active ; 1 - 64 characters
: type input_field_placeholder : : obj : ` str `
: param selective : Optional . Use this parameter if you want to show the keyboard to 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 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.
: type selective : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . ReplyKeyboardMarkup `
"""
2020-08-02 18:58:22 +03:00
max_row_keys = 12
2021-06-28 10:31:06 +03:00
def __init__ ( self , resize_keyboard : Optional [ bool ] = None , one_time_keyboard : Optional [ bool ] = None ,
selective : Optional [ bool ] = None , row_width : int = 3 , input_field_placeholder : Optional [ str ] = None ) :
2020-08-02 18:58:22 +03:00
if row_width > self . max_row_keys :
# Todo: Will be replaced with Exception in future releases
2020-08-04 12:29:56 +03:00
if not DISABLE_KEYLEN_ERROR :
logger . error ( ' Telegram does not support reply keyboard row width over %d . ' % self . max_row_keys )
2020-08-02 18:58:22 +03:00
row_width = self . max_row_keys
2020-07-31 23:28:56 +03:00
2021-06-17 21:28:53 +03:00
self . resize_keyboard : bool = resize_keyboard
self . one_time_keyboard : bool = one_time_keyboard
self . selective : bool = selective
self . row_width : int = row_width
2021-06-28 10:31:06 +03:00
self . input_field_placeholder : str = input_field_placeholder
2021-06-17 21:28:53 +03:00
self . keyboard : List [ List [ KeyboardButton ] ] = [ ]
2015-06-30 03:00:47 +03:00
2020-07-31 23:28:56 +03:00
def add ( self , * args , row_width = None ) :
2015-06-30 03:00:47 +03:00
"""
This function adds strings to the keyboard , while not exceeding row_width .
E . g . ReplyKeyboardMarkup #add("A", "B", "C") yields the json result {keyboard: [["A"], ["B"], ["C"]]}
when row_width is set to 1.
When row_width is set to 2 , the following is the result of this function : { keyboard : [ [ " A " , " B " ] , [ " C " ] ] }
See https : / / core . telegram . org / bots / api #replykeyboardmarkup
2022-03-19 11:49:36 +03:00
2016-04-14 07:01:17 +03:00
: param args : KeyboardButton to append to the keyboard
2022-07-26 14:16:35 +03:00
: type args : : obj : ` str ` or : class : ` telebot . types . KeyboardButton `
2020-07-31 23:28:56 +03:00
: param row_width : width of row
2022-07-26 14:16:35 +03:00
: type row_width : : obj : ` int `
2020-07-31 23:28:56 +03:00
: return : self , to allow function chaining .
2022-07-26 14:16:35 +03:00
: rtype : : class : ` telebot . types . ReplyKeyboardMarkup `
2015-06-30 03:00:47 +03:00
"""
2020-08-02 18:58:22 +03:00
if row_width is None :
row_width = self . row_width
2021-06-19 18:59:55 +03:00
2020-08-02 18:58:22 +03:00
if row_width > self . max_row_keys :
# Todo: Will be replaced with Exception in future releases
2020-08-04 12:29:56 +03:00
if not DISABLE_KEYLEN_ERROR :
logger . error ( ' Telegram does not support reply keyboard row width over %d . ' % self . max_row_keys )
2020-08-02 18:58:22 +03:00
row_width = self . max_row_keys
2020-07-31 23:28:56 +03:00
for row in util . chunks ( args , row_width ) :
button_array = [ ]
for button in row :
if util . is_string ( button ) :
button_array . append ( { ' text ' : button } )
elif util . is_bytes ( button ) :
button_array . append ( { ' text ' : button . decode ( ' utf-8 ' ) } )
else :
button_array . append ( button . to_dict ( ) )
self . keyboard . append ( button_array )
return self
2015-06-30 03:00:47 +03:00
def row ( self , * args ) :
"""
2016-04-14 07:01:17 +03:00
Adds a list of KeyboardButton to the keyboard . This function does not consider row_width .
2015-06-30 03:00:47 +03:00
ReplyKeyboardMarkup #row("A")#row("B", "C")#to_json() outputs '{keyboard: [["A"], ["B", "C"]]}'
See https : / / core . telegram . org / bots / api #replykeyboardmarkup
2022-03-19 11:49:36 +03:00
2015-06-30 03:00:47 +03:00
: param args : strings
2022-07-26 14:16:35 +03:00
: type args : : obj : ` str `
2015-06-30 03:00:47 +03:00
: return : self , to allow function chaining .
2022-07-26 14:16:35 +03:00
: rtype : : class : ` telebot . types . ReplyKeyboardMarkup `
2015-06-30 03:00:47 +03:00
"""
2021-06-26 14:36:14 +03:00
2020-08-04 21:45:33 +03:00
return self . add ( * args , row_width = self . max_row_keys )
2015-06-30 03:00:47 +03:00
def to_json ( self ) :
2015-06-30 06:54:04 +03:00
json_dict = { ' keyboard ' : self . keyboard }
2021-06-28 10:31:06 +03:00
if self . one_time_keyboard is not None :
2021-09-30 11:56:36 +03:00
json_dict [ ' one_time_keyboard ' ] = self . one_time_keyboard
2021-06-28 10:31:06 +03:00
if self . resize_keyboard is not None :
2021-09-30 11:56:36 +03:00
json_dict [ ' resize_keyboard ' ] = self . resize_keyboard
2021-06-28 10:31:06 +03:00
if self . selective is not None :
2021-09-30 11:56:36 +03:00
json_dict [ ' selective ' ] = self . selective
2021-06-26 14:36:14 +03:00
if self . input_field_placeholder :
json_dict [ ' input_field_placeholder ' ] = self . input_field_placeholder
2015-06-30 03:00:47 +03:00
return json . dumps ( json_dict )
2016-01-04 17:24:18 +03:00
2021-08-18 18:47:38 +03:00
class KeyboardButtonPollType ( Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents type of a poll , which is allowed to be created and sent when the corresponding button is pressed .
Telegram Documentation : https : / / core . telegram . org / bots / api #keyboardbuttonpolltype
: param type : Optional . If quiz is passed , the user will be allowed to create only polls in the quiz mode . If regular is
passed , only regular polls will be allowed . Otherwise , the user will be allowed to create a poll of any type .
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . KeyboardButtonPollType `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , type = ' ' ) :
self . type : str = type
def to_dict ( self ) :
return { ' type ' : self . type }
2016-04-14 10:50:55 +03:00
class KeyboardButton ( Dictionaryable , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
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 web_app , request_contact , request_location , and request_poll are mutually exclusive .
Telegram Documentation : https : / / core . telegram . org / bots / api #keyboardbutton
: param text : Text of the button . If none of the optional fields are used , it will be sent as a message when the button is
pressed
: type text : : obj : ` str `
: param request_contact : Optional . If True , the user ' s phone number will be sent as a contact when the button is
pressed . Available in private chats only .
: type request_contact : : obj : ` bool `
: param request_location : Optional . If True , the user ' s current location will be sent when the button is pressed.
Available in private chats only .
: type request_location : : obj : ` bool `
: param request_poll : Optional . If specified , the user will be asked to create a poll and send it to the bot when the
button is pressed . Available in private chats only .
: type request_poll : : class : ` telebot . types . KeyboardButtonPollType `
: param web_app : Optional . If specified , the described Web App will be launched when the button is pressed . The Web App
will be able to send a “ web_app_data ” service message . Available in private chats only .
: type web_app : : class : ` telebot . types . WebAppInfo `
: return : Instance of the class
: rtype : : class : ` telebot . types . KeyboardButton `
"""
2021-06-28 10:31:06 +03:00
def __init__ ( self , text : str , request_contact : Optional [ bool ] = None ,
2022-04-17 14:39:09 +03:00
request_location : Optional [ bool ] = None , request_poll : Optional [ KeyboardButtonPollType ] = None ,
web_app : WebAppInfo = None ) :
2021-06-17 21:28:53 +03:00
self . text : str = text
self . request_contact : bool = request_contact
self . request_location : bool = request_location
self . request_poll : KeyboardButtonPollType = request_poll
2022-04-17 14:39:09 +03:00
self . web_app : WebAppInfo = web_app
2016-04-14 07:01:17 +03:00
def to_json ( self ) :
2020-05-08 21:06:39 +03:00
return json . dumps ( self . to_dict ( ) )
2016-04-14 08:35:18 +03:00
2020-05-08 21:06:39 +03:00
def to_dict ( self ) :
json_dict = { ' text ' : self . text }
2021-06-28 10:31:06 +03:00
if self . request_contact is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' request_contact ' ] = self . request_contact
2021-06-28 10:31:06 +03:00
if self . request_location is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' request_location ' ] = self . request_location
2021-06-28 10:31:06 +03:00
if self . request_poll is not None :
2020-05-06 11:23:39 +03:00
json_dict [ ' request_poll ' ] = self . request_poll . to_dict ( )
2022-04-17 14:39:09 +03:00
if self . web_app is not None :
json_dict [ ' web_app ' ] = self . web_app . to_dict ( )
2020-05-08 21:06:39 +03:00
return json_dict
2016-04-14 07:01:17 +03:00
2020-09-02 04:25:23 +03:00
class InlineKeyboardMarkup ( Dictionaryable , JsonSerializable , JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents an inline keyboard that appears right next to the message it belongs to .
. . note : :
It is recommended to use : meth : ` telebot . util . quick_markup ` instead .
. . code - block : : python3
: caption : Example of a custom keyboard with buttons .
from telebot . util import quick_markup
markup = quick_markup (
{ ' text ' : ' Press me ' , ' callback_data ' : ' press ' } ,
{ ' text ' : ' Press me too ' , ' callback_data ' : ' press_too ' }
)
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinekeyboardmarkup
: param inline_keyboard : : obj : ` list ` of button rows , each represented by an : obj : ` list ` of
: class : ` telebot . types . InlineKeyboardButton ` objects
: type inline_keyboard : : obj : ` list ` of : obj : ` list ` of : class : ` telebot . types . InlineKeyboardButton `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineKeyboardMarkup `
"""
2020-08-04 18:28:35 +03:00
max_row_keys = 8
2020-09-01 13:13:22 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2020-09-02 04:25:23 +03:00
keyboard = [ [ InlineKeyboardButton . de_json ( button ) for button in row ] for row in obj [ ' inline_keyboard ' ] ]
2021-08-18 18:47:38 +03:00
return cls ( keyboard = keyboard )
2020-08-02 18:58:22 +03:00
2021-06-19 18:59:55 +03:00
def __init__ ( self , keyboard = None , row_width = 3 ) :
2020-08-02 18:58:22 +03:00
if row_width > self . max_row_keys :
# Todo: Will be replaced with Exception in future releases
logger . error ( ' Telegram does not support inline keyboard row width over %d . ' % self . max_row_keys )
row_width = self . max_row_keys
2020-08-02 18:20:33 +03:00
2021-06-17 21:28:53 +03:00
self . row_width : int = row_width
self . keyboard : List [ List [ InlineKeyboardButton ] ] = keyboard or [ ]
2016-04-14 07:01:17 +03:00
2020-07-31 23:28:56 +03:00
def add ( self , * args , row_width = None ) :
2016-04-14 07:01:17 +03:00
"""
2020-05-09 20:06:33 +03:00
This method adds buttons to the keyboard without exceeding row_width .
2020-09-22 01:34:49 +03:00
E . g . InlineKeyboardMarkup . add ( " A " , " B " , " C " ) yields the json result :
2022-03-07 12:24:28 +03:00
{ keyboard : [ [ " A " ] , [ " B " ] , [ " C " ] ] }
2016-04-14 07:01:17 +03:00
when row_width is set to 1.
2020-05-09 20:06:33 +03:00
When row_width is set to 2 , the result :
2022-03-07 12:24:28 +03:00
{ keyboard : [ [ " A " , " B " ] , [ " C " ] ] }
2020-05-09 20:06:33 +03:00
See https : / / core . telegram . org / bots / api #inlinekeyboardmarkup
2020-07-31 23:28:56 +03:00
2020-05-09 20:06:33 +03:00
: param args : Array of InlineKeyboardButton to append to the keyboard
2022-07-26 14:16:35 +03:00
: type args : : obj : ` list ` of : class : ` telebot . types . InlineKeyboardButton `
2020-07-31 23:28:56 +03:00
: param row_width : width of row
2022-07-26 14:16:35 +03:00
: type row_width : : obj : ` int `
2020-07-31 23:28:56 +03:00
: return : self , to allow function chaining .
2022-07-26 14:16:35 +03:00
: rtype : : class : ` telebot . types . InlineKeyboardMarkup `
2016-04-14 07:01:17 +03:00
"""
2020-08-02 18:58:22 +03:00
if row_width is None :
row_width = self . row_width
2020-07-31 23:28:56 +03:00
2020-08-02 18:58:22 +03:00
if row_width > self . max_row_keys :
# Todo: Will be replaced with Exception in future releases
logger . error ( ' Telegram does not support inline keyboard row width over %d . ' % self . max_row_keys )
row_width = self . max_row_keys
2020-07-31 23:28:56 +03:00
for row in util . chunks ( args , row_width ) :
2020-09-02 04:25:23 +03:00
button_array = [ button for button in row ]
2020-07-31 23:28:56 +03:00
self . keyboard . append ( button_array )
return self
2016-04-14 07:01:17 +03:00
def row ( self , * args ) :
"""
2020-05-09 20:06:33 +03:00
Adds a list of InlineKeyboardButton to the keyboard .
2022-03-07 12:24:28 +03:00
This method does not consider row_width .
2020-05-09 20:06:33 +03:00
InlineKeyboardMarkup . row ( " A " ) . row ( " B " , " C " ) . to_json ( ) outputs :
2022-03-07 12:24:28 +03:00
' { keyboard: [[ " A " ], [ " B " , " C " ]]} '
2016-04-14 07:01:17 +03:00
See https : / / core . telegram . org / bots / api #inlinekeyboardmarkup
2020-07-31 23:28:56 +03:00
2020-05-09 20:06:33 +03:00
: param args : Array of InlineKeyboardButton to append to the keyboard
2022-07-26 14:16:35 +03:00
: type args : : obj : ` list ` of : class : ` telebot . types . InlineKeyboardButton `
2016-04-14 07:01:17 +03:00
: return : self , to allow function chaining .
2022-07-26 14:16:35 +03:00
: rtype : : class : ` telebot . types . InlineKeyboardMarkup `
2016-04-14 07:01:17 +03:00
"""
2020-07-31 23:28:56 +03:00
2020-08-04 21:45:33 +03:00
return self . add ( * args , row_width = self . max_row_keys )
2016-04-14 07:01:17 +03:00
def to_json ( self ) :
2020-05-09 20:06:33 +03:00
return json . dumps ( self . to_dict ( ) )
2016-04-14 07:01:17 +03:00
2020-05-08 21:06:39 +03:00
def to_dict ( self ) :
2020-09-02 04:25:23 +03:00
json_dict = dict ( )
2020-09-02 13:09:14 +03:00
json_dict [ ' inline_keyboard ' ] = [ [ button . to_dict ( ) for button in row ] for row in self . keyboard ]
2016-04-14 12:09:12 +03:00
return json_dict
2016-04-14 07:01:17 +03:00
2021-06-17 21:28:53 +03:00
class InlineKeyboardButton ( Dictionaryable , JsonSerializable , JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents one button of an inline keyboard . You must use exactly one of the optional fields .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinekeyboardbutton
: param text : Label text on the button
: type text : : obj : ` str `
: param url : Optional . HTTP or tg : / / URL to be opened when the button is pressed . Links tg : / / user ? id = < user_id > can be
used to mention a user by their ID without using a username , if this is allowed by their privacy settings .
: type url : : obj : ` str `
: param callback_data : Optional . Data to be sent in a callback query to the bot when button is pressed , 1 - 64 bytes
: type callback_data : : obj : ` str `
: param web_app : Optional . Description of the Web App that will be launched when the user presses the button . The Web
App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery . Available only
in private chats between a user and the bot .
: type web_app : : class : ` telebot . types . WebAppInfo `
: param login_url : Optional . An HTTPS URL used to automatically authorize the user . Can be used as a replacement for
the Telegram Login Widget .
: type login_url : : class : ` telebot . types . LoginUrl `
: param switch_inline_query : 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. May 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 .
: type switch_inline_query : : obj : ` str `
: param switch_inline_query_current_chat : Optional . If set , pressing the button will insert the bot ' s username
and the specified inline query in the current chat ' s input field. May be empty, in which case only the bot ' s username
will be inserted . This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting
something from multiple options .
: type switch_inline_query_current_chat : : obj : ` str `
: param callback_game : Optional . Description of the game that will be launched when the user presses the
button . NOTE : This type of button must always be the first button in the first row .
: type callback_game : : class : ` telebot . types . CallbackGame `
: param pay : Optional . Specify True , to send a Pay button . NOTE : This type of button must always be the first button in
the first row and can only be used in invoice messages .
: type pay : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineKeyboardButton `
"""
2020-09-01 13:03:21 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2020-09-01 13:03:21 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
if ' login_url ' in obj :
obj [ ' login_url ' ] = LoginUrl . de_json ( obj . get ( ' login_url ' ) )
2022-04-17 14:39:09 +03:00
if ' web_app ' in obj :
obj [ ' web_app ' ] = WebAppInfo . de_json ( obj . get ( ' web_app ' ) )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2019-06-15 22:59:41 +03:00
2022-04-17 14:39:09 +03:00
def __init__ ( self , text , url = None , callback_data = None , web_app = None , switch_inline_query = None ,
2021-06-17 21:28:53 +03:00
switch_inline_query_current_chat = None , callback_game = None , pay = None , login_url = None , * * kwargs ) :
self . text : str = text
self . url : str = url
self . callback_data : str = callback_data
2022-04-17 14:39:09 +03:00
self . web_app : WebAppInfo = web_app
2021-06-17 21:28:53 +03:00
self . switch_inline_query : str = switch_inline_query
self . switch_inline_query_current_chat : str = switch_inline_query_current_chat
self . callback_game = callback_game # Not Implemented
self . pay : bool = pay
self . login_url : LoginUrl = login_url
2016-04-14 07:01:17 +03:00
def to_json ( self ) :
2020-05-08 21:06:39 +03:00
return json . dumps ( self . to_dict ( ) )
2016-04-14 08:35:18 +03:00
2020-05-08 21:06:39 +03:00
def to_dict ( self ) :
json_dict = { ' text ' : self . text }
2016-04-14 07:01:17 +03:00
if self . url :
2020-05-08 21:06:39 +03:00
json_dict [ ' url ' ] = self . url
2016-04-14 07:01:17 +03:00
if self . callback_data :
2020-05-08 21:06:39 +03:00
json_dict [ ' callback_data ' ] = self . callback_data
2022-04-17 14:39:09 +03:00
if self . web_app :
2022-04-22 21:06:11 +03:00
json_dict [ ' web_app ' ] = self . web_app . to_dict ( )
2016-04-17 18:21:11 +03:00
if self . switch_inline_query is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' switch_inline_query ' ] = self . switch_inline_query
2016-10-08 17:04:44 +03:00
if self . switch_inline_query_current_chat is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' switch_inline_query_current_chat ' ] = self . switch_inline_query_current_chat
2016-10-08 17:04:44 +03:00
if self . callback_game is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' callback_game ' ] = self . callback_game
2017-05-25 06:48:16 +03:00
if self . pay is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' pay ' ] = self . pay
2019-06-15 22:59:41 +03:00
if self . login_url is not None :
2020-05-08 21:06:39 +03:00
json_dict [ ' login_url ' ] = self . login_url . to_dict ( )
return json_dict
2016-04-14 07:01:17 +03:00
2016-04-14 10:50:55 +03:00
2021-06-17 21:28:53 +03:00
class LoginUrl ( Dictionaryable , JsonSerializable , JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a parameter of the inline keyboard button used to automatically authorize a user . Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram . All the user needs to do is tap / click a button and confirm that they want to log in :
Telegram Documentation : https : / / core . telegram . org / bots / api #loginurl
: param url : An HTTPS URL to be opened with user authorization data added to the query string when the button is pressed .
If the user refuses to provide authorization data , the original URL without information about the user will be
opened . The data added is the same as described in Receiving authorization data . NOTE : You must always check the hash
of the received data to verify the authentication and the integrity of the data as described in Checking
authorization .
: type url : : obj : ` str `
: param forward_text : Optional . New text of the button in forwarded messages .
: type forward_text : : obj : ` str `
: param bot_username : Optional . Username of a bot , which will be used for user authorization . See Setting up a bot for
more details . If not specified , the current bot ' s username will be assumed. The url ' s domain must be the same as the
domain linked with the bot . See Linking your domain to the bot for more details .
: type bot_username : : obj : ` str `
: param request_write_access : Optional . Pass True to request the permission for your bot to send messages to the
user .
: type request_write_access : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . LoginUrl `
"""
2016-04-14 07:01:17 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2016-04-14 07:01:17 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , url , forward_text = None , bot_username = None , request_write_access = None , * * kwargs ) :
self . url : str = url
self . forward_text : str = forward_text
self . bot_username : str = bot_username
self . request_write_access : bool = request_write_access
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
json_dict = { ' url ' : self . url }
if self . forward_text :
json_dict [ ' forward_text ' ] = self . forward_text
if self . bot_username :
json_dict [ ' bot_username ' ] = self . bot_username
if self . request_write_access is not None :
json_dict [ ' request_write_access ' ] = self . request_write_access
return json_dict
2016-04-14 07:01:17 +03:00
2021-06-17 21:28:53 +03:00
class CallbackQuery ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
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 present . If the button was attached to a message sent via the bot ( in inline mode ) , the field inline_message_id will be present . Exactly one of the fields data or game_short_name will be present .
Telegram Documentation : https : / / core . telegram . org / bots / api #callbackquery
: param id : Unique identifier for this query
: type id : : obj : ` str `
: param from_user : Sender
: type from_user : : class : ` telebot . types . User `
: param 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
: type message : : class : ` telebot . types . Message `
: param inline_message_id : Optional . Identifier of the message sent via the bot in inline mode , that originated the
query .
: type inline_message_id : : obj : ` str `
: param chat_instance : Global identifier , uniquely corresponding to the chat to which the message with the callback
button was sent . Useful for high scores in games .
: type chat_instance : : obj : ` str `
: param data : Optional . Data associated with the callback button . Be aware that the message originated the query can
contain no callback buttons with this data .
: type data : : obj : ` str `
: param game_short_name : Optional . Short name of a Game to be returned , serves as the unique identifier for the game
: type game_short_name : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . CallbackQuery `
"""
2021-06-17 21:28:53 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
2021-07-13 20:11:47 +03:00
if not " data " in obj :
# "data" field is Optional in the API, but historically is mandatory in the class constructor
obj [ ' data ' ] = None
2021-06-17 21:28:53 +03:00
obj [ ' from_user ' ] = User . de_json ( obj . pop ( ' from ' ) )
if ' message ' in obj :
obj [ ' message ' ] = Message . de_json ( obj . get ( ' message ' ) )
2022-07-04 22:36:42 +03:00
obj [ ' json_string ' ] = json_string
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2022-07-04 22:36:42 +03:00
def __init__ ( self , id , from_user , data , chat_instance , json_string , message = None , inline_message_id = None , game_short_name = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . id : int = id
self . from_user : User = from_user
self . message : Message = message
self . inline_message_id : str = inline_message_id
self . chat_instance : str = chat_instance
self . data : str = data
self . game_short_name : str = game_short_name
2022-07-04 22:36:42 +03:00
self . json = json_string
2021-06-17 21:28:53 +03:00
2017-06-30 19:47:09 +03:00
class ChatPhoto ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a chat photo .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatphoto
: param small_file_id : File identifier of small ( 160 x160 ) chat photo . This file_id can be used only for photo
download and only for as long as the photo is not changed .
: type small_file_id : : obj : ` str `
: param small_file_unique_id : Unique file identifier of small ( 160 x160 ) chat photo , which is supposed to be the same
over time and for different bots . Can ' t be used to download or reuse the file.
: type small_file_unique_id : : obj : ` str `
: param big_file_id : File identifier of big ( 640 x640 ) chat photo . This file_id can be used only for photo download and
only for as long as the photo is not changed .
: type big_file_id : : obj : ` str `
: param big_file_unique_id : Unique file identifier of big ( 640 x640 ) chat photo , which is supposed to be the same over
time and for different bots . Can ' t be used to download or reuse the file.
: type big_file_unique_id : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatPhoto `
"""
2017-06-30 19:47:09 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2017-06-30 19:47:09 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , small_file_id , small_file_unique_id , big_file_id , big_file_unique_id , * * kwargs ) :
self . small_file_id : str = small_file_id
self . small_file_unique_id : str = small_file_unique_id
self . big_file_id : str = big_file_id
self . big_file_unique_id : str = big_file_unique_id
2017-06-30 19:47:09 +03:00
2016-06-07 14:00:44 +03:00
class ChatMember ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains information about one member of a chat .
Currently , the following 6 types of chat members are supported :
* : class : ` telebot . types . ChatMemberOwner `
* : class : ` telebot . types . ChatMemberAdministrator `
* : class : ` telebot . types . ChatMemberMember `
* : class : ` telebot . types . ChatMemberRestricted `
* : class : ` telebot . types . ChatMemberLeft `
* : class : ` telebot . types . ChatMemberBanned `
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmember
"""
2016-06-07 14:00:44 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2020-04-11 17:06:14 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' user ' ] = User . de_json ( obj [ ' user ' ] )
2022-07-03 23:33:55 +03:00
member_type = obj [ ' status ' ]
2022-07-04 22:41:01 +03:00
# Ordered according to estimated appearance frequency.
if member_type == " member " :
2022-07-03 23:33:55 +03:00
return ChatMemberMember ( * * obj )
elif member_type == " left " :
return ChatMemberLeft ( * * obj )
elif member_type == " kicked " :
return ChatMemberBanned ( * * obj )
2022-07-04 22:41:01 +03:00
elif member_type == " restricted " :
return ChatMemberRestricted ( * * obj )
elif member_type == " administrator " :
return ChatMemberAdministrator ( * * obj )
elif member_type == " creator " :
return ChatMemberOwner ( * * obj )
2022-07-03 23:33:55 +03:00
else :
2022-07-04 22:41:01 +03:00
# Should not be here. For "if something happen" compatibility
2022-07-03 23:33:55 +03:00
return cls ( * * obj )
2021-06-17 21:28:53 +03:00
def __init__ ( self , user , status , custom_title = None , is_anonymous = None , can_be_edited = None ,
2020-05-11 22:26:03 +03:00
can_post_messages = None , can_edit_messages = None , can_delete_messages = None ,
can_restrict_members = None , can_promote_members = None , can_change_info = None ,
can_invite_users = None , can_pin_messages = None , is_member = None ,
can_send_messages = None , can_send_media_messages = None , can_send_polls = None ,
2021-06-23 23:52:24 +03:00
can_send_other_messages = None , can_add_web_page_previews = None ,
2022-04-17 14:39:09 +03:00
can_manage_chat = None , can_manage_video_chats = None ,
2022-11-06 14:00:20 +03:00
until_date = None , can_manage_topics = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . user : User = user
self . status : str = status
self . custom_title : str = custom_title
self . is_anonymous : bool = is_anonymous
self . can_be_edited : bool = can_be_edited
self . can_post_messages : bool = can_post_messages
self . can_edit_messages : bool = can_edit_messages
self . can_delete_messages : bool = can_delete_messages
self . can_restrict_members : bool = can_restrict_members
self . can_promote_members : bool = can_promote_members
self . can_change_info : bool = can_change_info
self . can_invite_users : bool = can_invite_users
self . can_pin_messages : bool = can_pin_messages
self . is_member : bool = is_member
self . can_send_messages : bool = can_send_messages
self . can_send_media_messages : bool = can_send_media_messages
self . can_send_polls : bool = can_send_polls
self . can_send_other_messages : bool = can_send_other_messages
self . can_add_web_page_previews : bool = can_add_web_page_previews
2021-06-23 23:52:24 +03:00
self . can_manage_chat : bool = can_manage_chat
2022-04-17 14:39:09 +03:00
self . can_manage_video_chats : bool = can_manage_video_chats
2022-04-23 15:03:54 +03:00
self . can_manage_voice_chats : bool = self . can_manage_video_chats # deprecated, for backward compatibility
2021-06-17 21:28:53 +03:00
self . until_date : int = until_date
2022-11-06 14:00:20 +03:00
self . can_manage_topics : bool = can_manage_topics
2016-06-07 14:00:44 +03:00
2017-08-06 09:25:25 +03:00
2021-08-18 23:27:28 +03:00
class ChatMemberOwner ( ChatMember ) :
2022-07-26 14:16:35 +03:00
"""
Represents a chat member that owns the chat and has all administrator privileges .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmemberowner
: param status : The member ' s status in the chat, always “creator”
: type status : : obj : ` str `
: param user : Information about the user
: type user : : class : ` telebot . types . User `
: param is_anonymous : True , if the user ' s presence in the chat is hidden
: type is_anonymous : : obj : ` bool `
: param custom_title : Optional . Custom title for this user
: type custom_title : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberOwner `
"""
2021-08-18 23:27:28 +03:00
pass
2022-07-03 23:33:55 +03:00
2021-08-18 23:27:28 +03:00
class ChatMemberAdministrator ( ChatMember ) :
2022-07-26 14:16:35 +03:00
"""
Represents a chat member that has some additional privileges .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmemberadministrator
: param status : The member ' s status in the chat, always “administrator”
: type status : : obj : ` str `
: param user : Information about the user
: type user : : class : ` telebot . types . User `
: param can_be_edited : True , if the bot is allowed to edit administrator privileges of that user
: type can_be_edited : : obj : ` bool `
: param is_anonymous : True , if the user ' s presence in the chat is hidden
: type is_anonymous : : obj : ` bool `
: param can_manage_chat : True , if the administrator can access the chat event log , chat statistics , message
statistics in channels , see channel members , see anonymous administrators in supergroups and ignore slow mode .
Implied by any other administrator privilege
: type can_manage_chat : : obj : ` bool `
: param can_delete_messages : True , if the administrator can delete messages of other users
: type can_delete_messages : : obj : ` bool `
: param can_manage_video_chats : True , if the administrator can manage video chats
: type can_manage_video_chats : : obj : ` bool `
: param can_restrict_members : True , if the administrator can restrict , ban or unban chat members
: type can_restrict_members : : obj : ` bool `
: param can_promote_members : True , if the administrator can add new administrators with a subset of their own
privileges or demote administrators that he has promoted , directly or indirectly ( promoted by administrators that
were appointed by the user )
: type can_promote_members : : obj : ` bool `
: param can_change_info : True , if the user is allowed to change the chat title , photo and other settings
: type can_change_info : : obj : ` bool `
: param can_invite_users : True , if the user is allowed to invite new users to the chat
: type can_invite_users : : obj : ` bool `
: param can_post_messages : Optional . True , if the administrator can post in the channel ; channels only
: type can_post_messages : : obj : ` bool `
: param can_edit_messages : Optional . True , if the administrator can edit messages of other users and can pin
messages ; channels only
: type can_edit_messages : : obj : ` bool `
: param can_pin_messages : Optional . True , if the user is allowed to pin messages ; groups and supergroups only
: type can_pin_messages : : obj : ` bool `
2022-11-06 14:00:20 +03:00
: param can_manage_topics : Optional . True , if the user is allowed to create , rename , close , and reopen forum topics ;
supergroups only
: type can_manage_topics : : obj : ` bool `
2022-07-26 14:16:35 +03:00
: param custom_title : Optional . Custom title for this user
: type custom_title : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberAdministrator `
"""
2021-08-18 23:27:28 +03:00
pass
class ChatMemberMember ( ChatMember ) :
2022-07-26 14:16:35 +03:00
"""
Represents a chat member that has no additional privileges or restrictions .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmembermember
: param status : The member ' s status in the chat, always “member”
: type status : : obj : ` str `
: param user : Information about the user
: type user : : class : ` telebot . types . User `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberMember `
"""
2021-08-18 23:27:28 +03:00
pass
class ChatMemberRestricted ( ChatMember ) :
2022-07-26 14:16:35 +03:00
"""
Represents a chat member that is under certain restrictions in the chat . Supergroups only .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmemberrestricted
: param status : The member ' s status in the chat, always “restricted”
: type status : : obj : ` str `
: param user : Information about the user
: type user : : class : ` telebot . types . User `
: param is_member : True , if the user is a member of the chat at the moment of the request
: type is_member : : obj : ` bool `
: param can_change_info : True , if the user is allowed to change the chat title , photo and other settings
: type can_change_info : : obj : ` bool `
: param can_invite_users : True , if the user is allowed to invite new users to the chat
: type can_invite_users : : obj : ` bool `
: param can_pin_messages : True , if the user is allowed to pin messages
: type can_pin_messages : : obj : ` bool `
2022-11-06 14:00:20 +03:00
: param can_manage_topics : True , if the user is allowed to create forum topics
: type can_manage_topics : : obj : ` bool `
2022-07-26 14:16:35 +03:00
: param can_send_messages : True , if the user is allowed to send text messages , contacts , locations and venues
: type can_send_messages : : obj : ` bool `
: param can_send_media_messages : True , if the user is allowed to send audios , documents , photos , videos , video
notes and voice notes
: type can_send_media_messages : : obj : ` bool `
: param can_send_polls : True , if the user is allowed to send polls
: type can_send_polls : : obj : ` bool `
: param can_send_other_messages : True , if the user is allowed to send animations , games , stickers and use inline
bots
: type can_send_other_messages : : obj : ` bool `
: param can_add_web_page_previews : True , if the user is allowed to add web page previews to their messages
: type can_add_web_page_previews : : obj : ` bool `
: param until_date : Date when restrictions will be lifted for this user ; unix time . If 0 , then the user is restricted
forever
: type until_date : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberRestricted `
"""
2021-08-18 23:27:28 +03:00
pass
class ChatMemberLeft ( ChatMember ) :
2022-07-26 14:16:35 +03:00
"""
Represents a chat member that isn ' t currently a member of the chat, but may join it themselves.
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmemberleft
: param status : The member ' s status in the chat, always “left”
: type status : : obj : ` str `
: param user : Information about the user
: type user : : class : ` telebot . types . User `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberLeft `
"""
2021-08-18 23:27:28 +03:00
pass
class ChatMemberBanned ( ChatMember ) :
2022-07-26 14:16:35 +03:00
"""
Represents a chat member that was banned in the chat and can ' t return to the chat or view chat messages.
Telegram Documentation : https : / / core . telegram . org / bots / api #chatmemberbanned
: param status : The member ' s status in the chat, always “kicked”
: type status : : obj : ` str `
: param user : Information about the user
: type user : : class : ` telebot . types . User `
: param until_date : Date when restrictions will be lifted for this user ; unix time . If 0 , then the user is banned
forever
: type until_date : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatMemberBanned `
"""
2021-08-18 23:27:28 +03:00
pass
2020-05-11 16:38:09 +03:00
class ChatPermissions ( JsonDeserializable , JsonSerializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Describes actions that a non - administrator user is allowed to take in a chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatpermissions
: param can_send_messages : Optional . True , if the user is allowed to send text messages , contacts , locations and
venues
: type can_send_messages : : obj : ` bool `
: param can_send_media_messages : Optional . True , if the user is allowed to send audios , documents , photos , videos ,
video notes and voice notes , implies can_send_messages
: type can_send_media_messages : : obj : ` bool `
: param can_send_polls : Optional . True , if the user is allowed to send polls , implies can_send_messages
: type can_send_polls : : obj : ` bool `
: param can_send_other_messages : Optional . True , if the user is allowed to send animations , games , stickers and use
inline bots , implies can_send_media_messages
: type can_send_other_messages : : obj : ` bool `
: param can_add_web_page_previews : Optional . True , if the user is allowed to add web page previews to their
messages , implies can_send_media_messages
: type can_add_web_page_previews : : obj : ` bool `
: param can_change_info : Optional . True , if the user is allowed to change the chat title , photo and other settings .
Ignored in public supergroups
: type can_change_info : : obj : ` bool `
: param can_invite_users : Optional . True , if the user is allowed to invite new users to the chat
: type can_invite_users : : obj : ` bool `
: param can_pin_messages : Optional . True , if the user is allowed to pin messages . Ignored in public supergroups
: type can_pin_messages : : obj : ` bool `
2022-11-06 14:00:20 +03:00
: param can_manage_topics : Optional . True , if the user is allowed to create forum topics . If omitted defaults to the
value of can_pin_messages
: type can_manage_topics : : obj : ` bool `
2022-07-26 14:16:35 +03:00
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatPermissions `
"""
2020-05-11 16:38:09 +03:00
@classmethod
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return json_string
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , can_send_messages = None , can_send_media_messages = None ,
can_send_polls = None , can_send_other_messages = None ,
can_add_web_page_previews = None , can_change_info = None ,
2022-11-06 14:00:20 +03:00
can_invite_users = None , can_pin_messages = None ,
can_manage_topics = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . can_send_messages : bool = can_send_messages
self . can_send_media_messages : bool = can_send_media_messages
self . can_send_polls : bool = can_send_polls
self . can_send_other_messages : bool = can_send_other_messages
self . can_add_web_page_previews : bool = can_add_web_page_previews
self . can_change_info : bool = can_change_info
self . can_invite_users : bool = can_invite_users
self . can_pin_messages : bool = can_pin_messages
2022-11-06 14:00:20 +03:00
self . can_manage_topics : bool = can_manage_topics
2020-05-11 16:38:09 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
json_dict = dict ( )
if self . can_send_messages is not None :
json_dict [ ' can_send_messages ' ] = self . can_send_messages
if self . can_send_media_messages is not None :
json_dict [ ' can_send_media_messages ' ] = self . can_send_media_messages
if self . can_send_polls is not None :
json_dict [ ' can_send_polls ' ] = self . can_send_polls
if self . can_send_other_messages is not None :
json_dict [ ' can_send_other_messages ' ] = self . can_send_other_messages
if self . can_add_web_page_previews is not None :
json_dict [ ' can_add_web_page_previews ' ] = self . can_add_web_page_previews
if self . can_change_info is not None :
json_dict [ ' can_change_info ' ] = self . can_change_info
if self . can_invite_users is not None :
json_dict [ ' can_invite_users ' ] = self . can_invite_users
if self . can_pin_messages is not None :
json_dict [ ' can_pin_messages ' ] = self . can_pin_messages
2022-11-06 14:00:20 +03:00
if self . can_manage_topics is not None :
json_dict [ ' can_manage_topics ' ] = self . can_manage_topics
2020-05-11 16:38:09 +03:00
return json_dict
2022-07-26 14:27:15 +03:00
class BotCommand ( JsonSerializable , JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a bot command .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommand
: param command : Text of the command ; 1 - 32 characters . Can contain only lowercase English letters , digits and
underscores .
: type command : : obj : ` str `
: param description : Description of the command ; 1 - 256 characters .
: type description : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommand `
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-21 18:39:13 +03:00
return cls ( * * obj )
2020-05-08 21:06:39 +03:00
def __init__ ( self , command , description ) :
2021-06-17 21:28:53 +03:00
self . command : str = command
self . description : str = description
2020-05-08 21:06:39 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
2020-05-09 00:51:18 +03:00
return { ' command ' : self . command , ' description ' : self . description }
2020-05-08 21:06:39 +03:00
2021-06-26 14:36:14 +03:00
# BotCommandScopes
2021-06-27 17:28:11 +03:00
class BotCommandScope ( ABC , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents the scope to which bot commands are applied . Currently , the following 7 scopes are supported :
* : class : ` BotCommandScopeDefault `
* : class : ` BotCommandScopeAllPrivateChats `
* : class : ` BotCommandScopeAllGroupChats `
* : class : ` BotCommandScopeAllChatAdministrators `
* : class : ` BotCommandScopeChat `
* : class : ` BotCommandScopeChatAdministrators `
* : class : ` BotCommandScopeChatMember `
Determining list of commands
The following algorithm is used to determine the list of commands for a particular user viewing the bot menu . The first list of commands which is set is returned :
Commands in the chat with the bot :
* : class : ` BotCommandScopeChat ` + language_code
* : class : ` BotCommandScopeChat `
* : class : ` BotCommandScopeAllPrivateChats ` + language_code
* : class : ` BotCommandScopeAllPrivateChats `
* : class : ` BotCommandScopeDefault ` + language_code
* : class : ` BotCommandScopeDefault `
Commands in group and supergroup chats :
* : class : ` BotCommandScopeChatMember ` + language_code
* : class : ` BotCommandScopeChatMember `
* : class : ` BotCommandScopeChatAdministrators ` + language_code ( administrators only )
* : class : ` BotCommandScopeChatAdministrators ` ( administrators only )
* : class : ` BotCommandScopeChat ` + language_code
* : class : ` BotCommandScopeChat `
* : class : ` BotCommandScopeAllChatAdministrators ` + language_code ( administrators only )
* : class : ` BotCommandScopeAllChatAdministrators ` ( administrators only )
* : class : ` BotCommandScopeAllGroupChats ` + language_code
* : class : ` BotCommandScopeAllGroupChats `
* : class : ` BotCommandScopeDefault ` + language_code
* : class : ` BotCommandScopeDefault `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScope `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self , type = ' default ' , chat_id = None , user_id = None ) :
self . type : str = type
self . chat_id : Optional [ Union [ int , str ] ] = chat_id
self . user_id : Optional [ Union [ int , str ] ] = user_id
def to_json ( self ) :
json_dict = { ' type ' : self . type }
if self . chat_id :
json_dict [ ' chat_id ' ] = self . chat_id
if self . user_id :
json_dict [ ' user_id ' ] = self . user_id
return json . dumps ( json_dict )
class BotCommandScopeDefault ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the default scope of bot commands . Default commands are used if no commands with a narrower scope are specified for the user .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopedefault
: param type : Scope type , must be default
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeDefault `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self ) :
2021-06-27 17:28:11 +03:00
"""
Represents the default scope of bot commands .
Default commands are used if no commands with a narrower scope are specified for the user .
"""
2021-06-26 14:36:14 +03:00
super ( BotCommandScopeDefault , self ) . __init__ ( type = ' default ' )
class BotCommandScopeAllPrivateChats ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the scope of bot commands , covering all private chats .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopeallprivatechats
: param type : Scope type , must be all_private_chats
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeAllPrivateChats `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self ) :
2021-06-27 17:28:11 +03:00
"""
Represents the scope of bot commands , covering all private chats .
"""
2021-06-26 14:36:14 +03:00
super ( BotCommandScopeAllPrivateChats , self ) . __init__ ( type = ' all_private_chats ' )
class BotCommandScopeAllGroupChats ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the scope of bot commands , covering all group and supergroup chats .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopeallgroupchats
: param type : Scope type , must be all_group_chats
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeAllGroupChats `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self ) :
2021-06-27 17:28:11 +03:00
"""
Represents the scope of bot commands , covering all group and supergroup chats .
"""
2021-06-26 14:36:14 +03:00
super ( BotCommandScopeAllGroupChats , self ) . __init__ ( type = ' all_group_chats ' )
class BotCommandScopeAllChatAdministrators ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the scope of bot commands , covering all group and supergroup chat administrators .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopeallchatadministrators
: param type : Scope type , must be all_chat_administrators
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeAllChatAdministrators `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self ) :
2021-06-27 17:28:11 +03:00
"""
Represents the scope of bot commands , covering all group and supergroup chat administrators .
"""
2021-06-26 14:36:14 +03:00
super ( BotCommandScopeAllChatAdministrators , self ) . __init__ ( type = ' all_chat_administrators ' )
class BotCommandScopeChat ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the scope of bot commands , covering a specific chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopechat
: param type : Scope type , must be chat
: type type : : obj : ` str `
: param chat_id : Unique identifier for the target chat or username of the target supergroup ( in the format
@supergroupusername )
: type chat_id : : obj : ` int ` or : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeChat `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self , chat_id = None ) :
super ( BotCommandScopeChat , self ) . __init__ ( type = ' chat ' , chat_id = chat_id )
class BotCommandScopeChatAdministrators ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the scope of bot commands , covering all administrators of a specific group or supergroup chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopechatadministrators
: param type : Scope type , must be chat_administrators
: type type : : obj : ` str `
: param chat_id : Unique identifier for the target chat or username of the target supergroup ( in the format
@supergroupusername )
: type chat_id : : obj : ` int ` or : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeChatAdministrators `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self , chat_id = None ) :
super ( BotCommandScopeChatAdministrators , self ) . __init__ ( type = ' chat_administrators ' , chat_id = chat_id )
class BotCommandScopeChatMember ( BotCommandScope ) :
2022-07-26 14:16:35 +03:00
"""
Represents the scope of bot commands , covering a specific member of a group or supergroup chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #botcommandscopechatmember
: param type : Scope type , must be chat_member
: type type : : obj : ` str `
: param chat_id : Unique identifier for the target chat or username of the target supergroup ( in the format
@supergroupusername )
: type chat_id : : obj : ` int ` or : obj : ` str `
: param user_id : Unique identifier of the target user
: type user_id : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . BotCommandScopeChatMember `
"""
2021-06-26 14:36:14 +03:00
def __init__ ( self , chat_id = None , user_id = None ) :
2021-08-12 15:16:04 +03:00
super ( BotCommandScopeChatMember , self ) . __init__ ( type = ' chat_member ' , chat_id = chat_id , user_id = user_id )
2021-06-26 14:36:14 +03:00
2016-04-14 05:51:05 +03:00
# InlineQuery
2016-01-04 17:24:18 +03:00
class InlineQuery ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents an incoming inline query . When the user sends an empty query , your bot could return some default or trending results .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequery
: param id : Unique identifier for this query
: type id : : obj : ` str `
: param from_user : Sender
: type from_user : : class : ` telebot . types . User `
: param query : Text of the query ( up to 256 characters )
: type query : : obj : ` str `
: param offset : Offset of the results to be returned , can be controlled by the bot
: type offset : : obj : ` str `
: param chat_type : Optional . Type of the chat from which the inline query was sent . Can be either “ sender ” for a private
chat with the inline query sender , “ private ” , “ group ” , “ supergroup ” , or “ channel ” . The chat type should be always
known for requests sent from official clients and most third - party clients , unless the request was sent from a secret
chat
: type chat_type : : obj : ` str `
: param location : Optional . Sender location , only for bots that request user location
: type location : : class : ` telebot . types . Location `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQuery `
"""
2016-01-04 17:24:18 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2020-04-11 17:06:14 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' from_user ' ] = User . de_json ( obj . pop ( ' from ' ) )
if ' location ' in obj :
obj [ ' location ' ] = Location . de_json ( obj [ ' location ' ] )
return cls ( * * obj )
def __init__ ( self , id , from_user , query , offset , chat_type = None , location = None , * * kwargs ) :
self . id : int = id
self . from_user : User = from_user
self . query : str = query
self . offset : str = offset
self . chat_type : str = chat_type
self . location : Location = location
2016-01-04 17:53:08 +03:00
2016-04-14 10:50:55 +03:00
class InputTextMessageContent ( Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents the content of a text message to be sent as the result of an inline query .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputtextmessagecontent
: param message_text : Text of the message to be sent , 1 - 4096 characters
: type message_text : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the message text . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param entities : Optional . List of special entities that appear in message text , which can be specified instead of
parse_mode
: type entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param disable_web_page_preview : Optional . Disables link previews for links in the sent message
: type disable_web_page_preview : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputTextMessageContent `
"""
2021-06-17 21:28:53 +03:00
def __init__ ( self , message_text , parse_mode = None , entities = None , disable_web_page_preview = None ) :
self . message_text : str = message_text
self . parse_mode : str = parse_mode
self . entities : List [ MessageEntity ] = entities
self . disable_web_page_preview : bool = disable_web_page_preview
2016-04-14 10:50:55 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
2021-06-17 21:28:53 +03:00
json_dict = { ' message_text ' : self . message_text }
2016-04-14 10:50:55 +03:00
if self . parse_mode :
2021-06-17 21:28:53 +03:00
json_dict [ ' parse_mode ' ] = self . parse_mode
if self . entities :
json_dict [ ' entities ' ] = MessageEntity . to_list_of_dicts ( self . entities )
2021-06-21 20:59:39 +03:00
if self . disable_web_page_preview is not None :
2021-06-17 21:28:53 +03:00
json_dict [ ' disable_web_page_preview ' ] = self . disable_web_page_preview
return json_dict
2016-04-14 10:50:55 +03:00
class InputLocationMessageContent ( Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents the content of a location message to be sent as the result of an inline query .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputlocationmessagecontent
: param latitude : Latitude of the location in degrees
: type latitude : : obj : ` float `
: param longitude : Longitude of the location in degrees
: type longitude : : obj : ` float `
: param horizontal_accuracy : Optional . The radius of uncertainty for the location , measured in meters ; 0 - 1500
: type horizontal_accuracy : : obj : ` float ` number
: param live_period : Optional . Period in seconds for which the location can be updated , should be between 60 and
86400.
: type live_period : : obj : ` int `
: param heading : Optional . For live locations , a direction in which the user is moving , in degrees . Must be between 1
and 360 if specified .
: type heading : : obj : ` int `
: param proximity_alert_radius : Optional . For live locations , a maximum distance for proximity alerts about
approaching another chat member , in meters . Must be between 1 and 100000 if specified .
: type proximity_alert_radius : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputLocationMessageContent `
"""
2021-06-17 21:28:53 +03:00
def __init__ ( self , latitude , longitude , horizontal_accuracy = None , live_period = None , heading = None , proximity_alert_radius = None ) :
self . latitude : float = latitude
self . longitude : float = longitude
self . horizontal_accuracy : float = horizontal_accuracy
self . live_period : int = live_period
self . heading : int = heading
self . proximity_alert_radius : int = proximity_alert_radius
2016-04-14 10:50:55 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
2021-06-17 21:28:53 +03:00
json_dict = { ' latitude ' : self . latitude , ' longitude ' : self . longitude }
if self . horizontal_accuracy :
json_dict [ ' horizontal_accuracy ' ] = self . horizontal_accuracy
2017-10-22 19:50:51 +03:00
if self . live_period :
2021-06-17 21:28:53 +03:00
json_dict [ ' live_period ' ] = self . live_period
if self . heading :
json_dict [ ' heading ' ] = self . heading
if self . proximity_alert_radius :
json_dict [ ' proximity_alert_radius ' ] = self . proximity_alert_radius
return json_dict
2016-04-14 10:50:55 +03:00
class InputVenueMessageContent ( Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents the content of a venue message to be sent as the result of an inline query .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputvenuemessagecontent
: param latitude : Latitude of the venue in degrees
: type latitude : : obj : ` float `
: param longitude : Longitude of the venue in degrees
: type longitude : : obj : ` float `
: param title : Name of the venue
: type title : : obj : ` str `
: param address : Address of the venue
: type address : : obj : ` str `
: param foursquare_id : Optional . Foursquare identifier of the venue , if known
: type foursquare_id : : obj : ` str `
: param foursquare_type : Optional . Foursquare type of the venue , if known . ( For example ,
“ arts_entertainment / default ” , “ arts_entertainment / aquarium ” or “ food / icecream ” . )
: type foursquare_type : : obj : ` str `
: param google_place_id : Optional . Google Places identifier of the venue
: type google_place_id : : obj : ` str `
: param google_place_type : Optional . Google Places type of the venue . ( See supported types . )
: type google_place_type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputVenueMessageContent `
"""
2021-06-17 21:28:53 +03:00
def __init__ ( self , latitude , longitude , title , address , foursquare_id = None , foursquare_type = None ,
google_place_id = None , google_place_type = None ) :
self . latitude : float = latitude
self . longitude : float = longitude
self . title : str = title
self . address : str = address
self . foursquare_id : str = foursquare_id
self . foursquare_type : str = foursquare_type
self . google_place_id : str = google_place_id
self . google_place_type : str = google_place_type
2016-04-14 10:50:55 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
json_dict = {
' latitude ' : self . latitude ,
' longitude ' : self . longitude ,
' title ' : self . title ,
' address ' : self . address
}
2016-04-14 10:50:55 +03:00
if self . foursquare_id :
2020-05-09 00:51:18 +03:00
json_dict [ ' foursquare_id ' ] = self . foursquare_id
2020-08-25 18:18:51 +03:00
if self . foursquare_type :
json_dict [ ' foursquare_type ' ] = self . foursquare_type
2021-06-17 21:28:53 +03:00
if self . google_place_id :
json_dict [ ' google_place_id ' ] = self . google_place_id
if self . google_place_type :
json_dict [ ' google_place_type ' ] = self . google_place_type
2020-05-09 00:51:18 +03:00
return json_dict
2016-04-14 10:50:55 +03:00
class InputContactMessageContent ( Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents the content of a contact message to be sent as the result of an inline query .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputcontactmessagecontent
: param phone_number : Contact ' s phone number
: type phone_number : : obj : ` str `
: param first_name : Contact ' s first name
: type first_name : : obj : ` str `
: param last_name : Optional . Contact ' s last name
: type last_name : : obj : ` str `
: param vcard : Optional . Additional data about the contact in the form of a vCard , 0 - 2048 bytes
: type vcard : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputContactMessageContent `
"""
2020-08-25 18:18:51 +03:00
def __init__ ( self , phone_number , first_name , last_name = None , vcard = None ) :
2021-06-17 21:28:53 +03:00
self . phone_number : str = phone_number
self . first_name : str = first_name
self . last_name : str = last_name
self . vcard : str = vcard
2016-04-14 10:50:55 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
2021-06-19 18:59:55 +03:00
json_dict = { ' phone_number ' : self . phone_number , ' first_name ' : self . first_name }
2016-04-14 10:50:55 +03:00
if self . last_name :
2020-05-09 00:51:18 +03:00
json_dict [ ' last_name ' ] = self . last_name
2020-08-25 18:18:51 +03:00
if self . vcard :
json_dict [ ' vcard ' ] = self . vcard
2020-05-09 00:51:18 +03:00
return json_dict
2016-04-14 10:50:55 +03:00
2021-06-21 20:59:39 +03:00
class InputInvoiceMessageContent ( Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents the content of an invoice message to be sent as the result of an inline query .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputinvoicemessagecontent
: param title : Product name , 1 - 32 characters
: type title : : obj : ` str `
: param description : Product description , 1 - 255 characters
: type description : : obj : ` str `
: param payload : Bot - defined invoice payload , 1 - 128 bytes . This will not be displayed to the user , use for your
internal processes .
: type payload : : obj : ` str `
: param provider_token : Payment provider token , obtained via @BotFather
: type provider_token : : obj : ` str `
: param currency : Three - letter ISO 4217 currency code , see more on currencies
: type currency : : obj : ` str `
: param prices : Price breakdown , a JSON - serialized list of components ( e . g . product price , tax , discount , delivery
cost , delivery tax , bonus , etc . )
: type prices : : obj : ` list ` of : class : ` telebot . types . LabeledPrice `
: param max_tip_amount : Optional . The maximum accepted amount for tips in the smallest units of the currency
( integer , not float / double ) . For example , for a maximum tip of US $ 1.45 pass max_tip_amount = 145. See the exp
parameter in currencies . json , it shows the number of digits past the decimal point for each currency ( 2 for the
majority of currencies ) . Defaults to 0
: type max_tip_amount : : obj : ` int `
: param suggested_tip_amounts : Optional . A JSON - serialized array of suggested amounts of tip in the smallest units
of the currency ( integer , not float / double ) . At most 4 suggested tip amounts can be specified . The suggested tip
amounts must be positive , passed in a strictly increased order and must not exceed max_tip_amount .
: type suggested_tip_amounts : : obj : ` list ` of : obj : ` int `
: param provider_data : Optional . A JSON - serialized object for data about the invoice , which will be shared with the
payment provider . A detailed description of the required fields should be provided by the payment provider .
: type provider_data : : obj : ` str `
: param photo_url : Optional . URL of the product photo for the invoice . Can be a photo of the goods or a marketing image
for a service .
: type photo_url : : obj : ` str `
: param photo_size : Optional . Photo size in bytes
: type photo_size : : obj : ` int `
: param photo_width : Optional . Photo width
: type photo_width : : obj : ` int `
: param photo_height : Optional . Photo height
: type photo_height : : obj : ` int `
: param need_name : Optional . Pass True , if you require the user ' s full name to complete the order
: type need_name : : obj : ` bool `
: param need_phone_number : Optional . Pass True , if you require the user ' s phone number to complete the order
: type need_phone_number : : obj : ` bool `
: param need_email : Optional . Pass True , if you require the user ' s email address to complete the order
: type need_email : : obj : ` bool `
: param need_shipping_address : Optional . Pass True , if you require the user ' s shipping address to complete the
order
: type need_shipping_address : : obj : ` bool `
: param send_phone_number_to_provider : Optional . Pass True , if the user ' s phone number should be sent to provider
: type send_phone_number_to_provider : : obj : ` bool `
: param send_email_to_provider : Optional . Pass True , if the user ' s email address should be sent to provider
: type send_email_to_provider : : obj : ` bool `
: param is_flexible : Optional . Pass True , if the final price depends on the shipping method
: type is_flexible : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputInvoiceMessageContent `
"""
2021-06-21 20:59:39 +03:00
def __init__ ( self , title , description , payload , provider_token , currency , prices ,
max_tip_amount = None , suggested_tip_amounts = None , provider_data = None ,
photo_url = None , photo_size = None , photo_width = None , photo_height = None ,
need_name = None , need_phone_number = None , need_email = None , need_shipping_address = None ,
send_phone_number_to_provider = None , send_email_to_provider = None ,
is_flexible = None ) :
self . title : str = title
self . description : str = description
self . payload : str = payload
self . provider_token : str = provider_token
self . currency : str = currency
self . prices : List [ LabeledPrice ] = prices
self . max_tip_amount : Optional [ int ] = max_tip_amount
self . suggested_tip_amounts : Optional [ List [ int ] ] = suggested_tip_amounts
self . provider_data : Optional [ str ] = provider_data
self . photo_url : Optional [ str ] = photo_url
self . photo_size : Optional [ int ] = photo_size
self . photo_width : Optional [ int ] = photo_width
self . photo_height : Optional [ int ] = photo_height
self . need_name : Optional [ bool ] = need_name
self . need_phone_number : Optional [ bool ] = need_phone_number
self . need_email : Optional [ bool ] = need_email
self . need_shipping_address : Optional [ bool ] = need_shipping_address
self . send_phone_number_to_provider : Optional [ bool ] = send_phone_number_to_provider
self . send_email_to_provider : Optional [ bool ] = send_email_to_provider
self . is_flexible : Optional [ bool ] = is_flexible
def to_dict ( self ) :
json_dict = {
' title ' : self . title ,
' description ' : self . description ,
' payload ' : self . payload ,
' provider_token ' : self . provider_token ,
' currency ' : self . currency ,
' prices ' : [ LabeledPrice . to_dict ( lp ) for lp in self . prices ]
}
if self . max_tip_amount :
json_dict [ ' max_tip_amount ' ] = self . max_tip_amount
if self . suggested_tip_amounts :
json_dict [ ' suggested_tip_amounts ' ] = self . suggested_tip_amounts
if self . provider_data :
json_dict [ ' provider_data ' ] = self . provider_data
if self . photo_url :
json_dict [ ' photo_url ' ] = self . photo_url
if self . photo_size :
json_dict [ ' photo_size ' ] = self . photo_size
if self . photo_width :
json_dict [ ' photo_width ' ] = self . photo_width
if self . photo_height :
json_dict [ ' photo_height ' ] = self . photo_height
if self . need_name is not None :
json_dict [ ' need_name ' ] = self . need_name
if self . need_phone_number is not None :
json_dict [ ' need_phone_number ' ] = self . need_phone_number
if self . need_email is not None :
json_dict [ ' need_email ' ] = self . need_email
if self . need_shipping_address is not None :
json_dict [ ' need_shipping_address ' ] = self . need_shipping_address
if self . send_phone_number_to_provider is not None :
json_dict [ ' send_phone_number_to_provider ' ] = self . send_phone_number_to_provider
if self . send_email_to_provider is not None :
json_dict [ ' send_email_to_provider ' ] = self . send_email_to_provider
if self . is_flexible is not None :
json_dict [ ' is_flexible ' ] = self . is_flexible
2021-08-03 19:34:29 +03:00
return json_dict
2021-06-21 20:59:39 +03:00
2021-08-03 19:35:59 +03:00
2016-01-04 17:53:08 +03:00
class ChosenInlineResult ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
Represents a result of an inline query that was chosen by the user and sent to their chat partner .
Telegram Documentation : https : / / core . telegram . org / bots / api #choseninlineresult
: param result_id : The unique identifier for the result that was chosen
: type result_id : : obj : ` str `
: param from : The user that chose the result
: type from : : class : ` telebot . types . User `
: param location : Optional . Sender location , only for bots that require user location
: type location : : class : ` telebot . types . Location `
: param inline_message_id : 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 .
: type inline_message_id : : obj : ` str `
: param query : The query that was used to obtain the result
: type query : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChosenInlineResult `
"""
2016-01-04 17:53:08 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
2021-06-17 21:28:53 +03:00
if json_string is None : return None
2020-04-11 17:06:14 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' from_user ' ] = User . de_json ( obj . pop ( ' from ' ) )
if ' location ' in obj :
obj [ ' location ' ] = Location . de_json ( obj [ ' location ' ] )
return cls ( * * obj )
def __init__ ( self , result_id , from_user , query , location = None , inline_message_id = None , * * kwargs ) :
self . result_id : str = result_id
self . from_user : User = from_user
self . location : Location = location
self . inline_message_id : str = inline_message_id
self . query : str = query
2016-01-05 04:57:25 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultBase ( ABC , Dictionaryable , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents one result of an inline query . Telegram clients currently support results of the following 20 types :
* : class : ` InlineQueryResultCachedAudio `
* : class : ` InlineQueryResultCachedDocument `
* : class : ` InlineQueryResultCachedGif `
* : class : ` InlineQueryResultCachedMpeg4Gif `
* : class : ` InlineQueryResultCachedPhoto `
* : class : ` InlineQueryResultCachedSticker `
* : class : ` InlineQueryResultCachedVideo `
* : class : ` InlineQueryResultCachedVoice `
* : class : ` InlineQueryResultArticle `
* : class : ` InlineQueryResultAudio `
* : class : ` InlineQueryResultContact `
* : class : ` InlineQueryResultGame `
* : class : ` InlineQueryResultDocument `
* : class : ` InlineQueryResultGif `
* : class : ` InlineQueryResultLocation `
* : class : ` InlineQueryResultMpeg4Gif `
* : class : ` InlineQueryResultPhoto `
* : class : ` InlineQueryResultVenue `
* : class : ` InlineQueryResultVideo `
* : class : ` InlineQueryResultVoice `
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresult
"""
2021-08-18 18:47:38 +03:00
# noinspection PyShadowingBuiltins
def __init__ ( self , type , id , title = None , caption = None , input_message_content = None ,
reply_markup = None , caption_entities = None , parse_mode = None ) :
self . type = type
self . id = id
self . title = title
self . caption = caption
self . input_message_content = input_message_content
self . reply_markup = reply_markup
self . caption_entities = caption_entities
self . parse_mode = parse_mode
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
json_dict = {
' type ' : self . type ,
' id ' : self . id
}
if self . title :
json_dict [ ' title ' ] = self . title
if self . caption :
json_dict [ ' caption ' ] = self . caption
if self . input_message_content :
json_dict [ ' input_message_content ' ] = self . input_message_content . to_dict ( )
if self . reply_markup :
json_dict [ ' reply_markup ' ] = self . reply_markup . to_dict ( )
if self . caption_entities :
json_dict [ ' caption_entities ' ] = MessageEntity . to_list_of_dicts ( self . caption_entities )
if self . parse_mode :
json_dict [ ' parse_mode ' ] = self . parse_mode
return json_dict
2022-07-26 14:27:15 +03:00
class SentWebAppMessage ( JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Describes an inline message sent by a Web App on behalf of a user .
Telegram Documentation : https : / / core . telegram . org / bots / api #sentwebappmessage
: param inline_message_id : Optional . Identifier of the sent inline message . Available only if there is an inline
keyboard attached to the message .
: type inline_message_id : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . SentWebAppMessage `
"""
2022-04-17 14:39:09 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
return cls ( * * obj )
2022-04-23 15:03:54 +03:00
def __init__ ( self , inline_message_id = None ) :
2022-04-17 14:39:09 +03:00
self . inline_message_id = inline_message_id
def to_dict ( self ) :
2022-04-23 15:03:54 +03:00
json_dict = { }
if self . inline_message_id :
json_dict [ ' inline_message_id ' ] = self . inline_message_id
return json_dict
2022-04-17 14:39:09 +03:00
2022-07-26 14:16:35 +03:00
class InlineQueryResultArticle ( InlineQueryResultBase ) :
"""
Represents a link to an article or web page .
2022-04-17 14:39:09 +03:00
2022-07-26 14:16:35 +03:00
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultarticle
2022-04-17 14:39:09 +03:00
2022-07-26 14:16:35 +03:00
: param type : Type of the result , must be article
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 Bytes
: type id : : obj : ` str `
: param title : Title of the result
: type title : : obj : ` str `
: param input_message_content : Content of the message to be sent
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param url : Optional . URL of the result
: type url : : obj : ` str `
: param hide_url : Optional . Pass True , if you don ' t want the URL to be shown in the message
: type hide_url : : obj : ` bool `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param thumb_url : Optional . Url of the thumbnail for the result
: type thumb_url : : obj : ` str `
: param thumb_width : Optional . Thumbnail width
: type thumb_width : : obj : ` int `
: param thumb_height : Optional . Thumbnail height
: type thumb_height : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultArticle `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , title , input_message_content , reply_markup = None ,
url = None , hide_url = None , description = None , thumb_url = None , thumb_width = None , thumb_height = None ) :
super ( ) . __init__ ( ' article ' , id , title = title , input_message_content = input_message_content , reply_markup = reply_markup )
2016-01-05 04:57:25 +03:00
self . url = url
self . hide_url = hide_url
self . description = description
self . thumb_url = thumb_url
self . thumb_width = thumb_width
self . thumb_height = thumb_height
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
2016-01-05 04:57:25 +03:00
if self . url :
json_dict [ ' url ' ] = self . url
if self . hide_url :
json_dict [ ' hide_url ' ] = self . hide_url
if self . description :
json_dict [ ' description ' ] = self . description
if self . thumb_url :
json_dict [ ' thumb_url ' ] = self . thumb_url
if self . thumb_width :
json_dict [ ' thumb_width ' ] = self . thumb_width
if self . thumb_height :
json_dict [ ' thumb_height ' ] = self . thumb_height
2021-08-18 18:47:38 +03:00
return json_dict
2016-01-05 05:24:21 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultPhoto ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
Represents a link to a photo . By default , this photo will be sent by the user with optional caption . Alternatively , you can use input_message_content to send a message with the specified content instead of the photo .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultphoto
: param type : Type of the result , must be photo
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param photo_url : A valid URL of the photo . Photo must be in JPEG format . Photo size must not exceed 5 MB
: type photo_url : : obj : ` str `
: param thumb_url : URL of the thumbnail for the photo
: type thumb_url : : obj : ` str `
: param photo_width : Optional . Width of the photo
: type photo_width : : obj : ` int `
: param photo_height : Optional . Height of the photo
: type photo_height : : obj : ` int `
: param title : Optional . Title for the result
: type title : : obj : ` str `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param caption : Optional . Caption of the photo to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the photo caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the photo
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultPhoto `
"""
2016-01-06 10:53:35 +03:00
def __init__ ( self , id , photo_url , thumb_url , photo_width = None , photo_height = None , title = None ,
2021-08-18 18:47:38 +03:00
description = None , caption = None , caption_entities = None , parse_mode = None , reply_markup = None , input_message_content = None ) :
super ( ) . __init__ ( ' photo ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-01-05 05:24:21 +03:00
self . photo_url = photo_url
2021-08-18 18:47:38 +03:00
self . thumb_url = thumb_url
2016-01-05 05:24:21 +03:00
self . photo_width = photo_width
self . photo_height = photo_height
self . description = description
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' photo_url ' ] = self . photo_url
json_dict [ ' thumb_url ' ] = self . thumb_url
2016-01-05 05:24:21 +03:00
if self . photo_width :
json_dict [ ' photo_width ' ] = self . photo_width
if self . photo_height :
json_dict [ ' photo_height ' ] = self . photo_height
if self . description :
json_dict [ ' description ' ] = self . description
2021-08-18 18:47:38 +03:00
return json_dict
2016-01-05 05:24:21 +03:00
2016-01-05 05:41:32 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultGif ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 use input_message_content to send a message with the specified content instead of the animation .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultgif
: param type : Type of the result , must be gif
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param gif_url : A valid URL for the GIF file . File size must not exceed 1 MB
: type gif_url : : obj : ` str `
: param gif_width : Optional . Width of the GIF
: type gif_width : : obj : ` int `
: param gif_height : Optional . Height of the GIF
: type gif_height : : obj : ` int `
: param gif_duration : Optional . Duration of the GIF in seconds
: type gif_duration : : obj : ` int `
: param thumb_url : URL of the static ( JPEG or GIF ) or animated ( MPEG4 ) thumbnail for the result
: type thumb_url : : obj : ` str `
: param thumb_mime_type : Optional . MIME type of the thumbnail , must be one of “ image / jpeg ” , “ image / gif ” , or
“ video / mp4 ” . Defaults to “ image / jpeg ”
: type thumb_mime_type : : obj : ` str `
: param title : Optional . Title for the result
: type title : : obj : ` str `
: param caption : Optional . Caption of the GIF file to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the caption . See formatting options for more details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the GIF animation
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultGif `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , gif_url , thumb_url , gif_width = None , gif_height = None ,
title = None , caption = None , caption_entities = None ,
2021-08-18 19:32:43 +03:00
reply_markup = None , input_message_content = None , gif_duration = None , parse_mode = None ,
thumb_mime_type = None ) :
2021-08-18 18:47:38 +03:00
super ( ) . __init__ ( ' gif ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-01-05 05:41:32 +03:00
self . gif_url = gif_url
self . gif_width = gif_width
self . gif_height = gif_height
self . thumb_url = thumb_url
2017-05-25 08:27:13 +03:00
self . gif_duration = gif_duration
2021-08-18 19:32:43 +03:00
self . thumb_mime_type = thumb_mime_type
2016-01-05 05:41:32 +03:00
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' gif_url ' ] = self . gif_url
2016-01-05 05:41:32 +03:00
if self . gif_width :
json_dict [ ' gif_width ' ] = self . gif_width
2021-08-18 18:47:38 +03:00
if self . gif_height :
json_dict [ ' gif_height ' ] = self . gif_height
json_dict [ ' thumb_url ' ] = self . thumb_url
2017-05-25 08:27:13 +03:00
if self . gif_duration :
json_dict [ ' gif_duration ' ] = self . gif_duration
2021-08-18 19:32:43 +03:00
if self . thumb_mime_type :
json_dict [ ' thumb_mime_type ' ] = self . thumb_mime_type
2021-08-18 18:47:38 +03:00
return json_dict
2016-01-05 05:51:33 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultMpeg4Gif ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 use input_message_content to send a message with the specified content instead of the animation .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultmpeg4gif
: param type : Type of the result , must be mpeg4_gif
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param mpeg4_url : A valid URL for the MPEG4 file . File size must not exceed 1 MB
: type mpeg4_url : : obj : ` str `
: param mpeg4_width : Optional . Video width
: type mpeg4_width : : obj : ` int `
: param mpeg4_height : Optional . Video height
: type mpeg4_height : : obj : ` int `
: param mpeg4_duration : Optional . Video duration in seconds
: type mpeg4_duration : : obj : ` int `
: param thumb_url : URL of the static ( JPEG or GIF ) or animated ( MPEG4 ) thumbnail for the result
: type thumb_url : : obj : ` str `
: param thumb_mime_type : Optional . MIME type of the thumbnail , must be one of “ image / jpeg ” , “ image / gif ” , or
“ video / mp4 ” . Defaults to “ image / jpeg ”
: type thumb_mime_type : : obj : ` str `
: param title : Optional . Title for the result
: type title : : obj : ` str `
: param caption : Optional . Caption of the MPEG - 4 file to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the caption . See formatting options for more details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the video animation
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultMpeg4Gif `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , mpeg4_url , thumb_url , mpeg4_width = None , mpeg4_height = None ,
title = None , caption = None , caption_entities = None ,
2021-08-18 19:32:43 +03:00
parse_mode = None , reply_markup = None , input_message_content = None , mpeg4_duration = None ,
thumb_mime_type = None ) :
2021-08-18 18:47:38 +03:00
super ( ) . __init__ ( ' mpeg4_gif ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-01-05 05:51:33 +03:00
self . mpeg4_url = mpeg4_url
self . mpeg4_width = mpeg4_width
self . mpeg4_height = mpeg4_height
self . thumb_url = thumb_url
2017-05-25 08:27:13 +03:00
self . mpeg4_duration = mpeg4_duration
2021-08-18 19:32:43 +03:00
self . thumb_mime_type = thumb_mime_type
2016-01-05 05:51:33 +03:00
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' mpeg4_url ' ] = self . mpeg4_url
2016-01-05 05:51:33 +03:00
if self . mpeg4_width :
json_dict [ ' mpeg4_width ' ] = self . mpeg4_width
if self . mpeg4_height :
json_dict [ ' mpeg4_height ' ] = self . mpeg4_height
2021-08-18 18:47:38 +03:00
json_dict [ ' thumb_url ' ] = self . thumb_url
2017-05-25 08:27:13 +03:00
if self . mpeg4_duration :
json_dict [ ' mpeg4_duration ' ] = self . mpeg4_duration
2021-08-18 19:32:43 +03:00
if self . thumb_mime_type :
json_dict [ ' thumb_mime_type ' ] = self . thumb_mime_type
2021-08-18 18:47:38 +03:00
return json_dict
2016-01-05 06:03:05 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultVideo ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
Represents a link to a page containing an embedded video player or a video file . 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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultvideo
: param type : Type of the result , must be video
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param video_url : A valid URL for the embedded video player or video file
: type video_url : : obj : ` str `
: param mime_type : MIME type of the content of the video URL , “ text / html ” or “ video / mp4 ”
: type mime_type : : obj : ` str `
: param thumb_url : URL of the thumbnail ( JPEG only ) for the video
: type thumb_url : : obj : ` str `
: param title : Title for the result
: type title : : obj : ` str `
: param caption : Optional . Caption of the video to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the video caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param video_width : Optional . Video width
: type video_width : : obj : ` int `
: param video_height : Optional . Video height
: type video_height : : obj : ` int `
: param video_duration : Optional . Video duration in seconds
: type video_duration : : obj : ` int `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the video . This field is
required if InlineQueryResultVideo is used to send an HTML - page as a result ( e . g . , a YouTube video ) .
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultVideo `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , video_url , mime_type , thumb_url ,
title , caption = None , caption_entities = None , parse_mode = None ,
video_width = None , video_height = None , video_duration = None ,
2018-08-02 21:15:33 +03:00
description = None , reply_markup = None , input_message_content = None ) :
2021-08-18 18:47:38 +03:00
super ( ) . __init__ ( ' video ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-01-05 06:03:05 +03:00
self . video_url = video_url
self . mime_type = mime_type
2021-08-18 18:47:38 +03:00
self . thumb_url = thumb_url
2016-01-05 06:03:05 +03:00
self . video_width = video_width
self . video_height = video_height
self . video_duration = video_duration
self . description = description
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' video_url ' ] = self . video_url
json_dict [ ' mime_type ' ] = self . mime_type
json_dict [ ' thumb_url ' ] = self . thumb_url
2016-01-05 06:03:05 +03:00
if self . video_height :
json_dict [ ' video_height ' ] = self . video_height
if self . video_duration :
json_dict [ ' video_duration ' ] = self . video_duration
if self . description :
json_dict [ ' description ' ] = self . description
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultAudio ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultaudio
: param type : Type of the result , must be audio
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param audio_url : A valid URL for the audio file
: type audio_url : : obj : ` str `
: param title : Title
: type title : : obj : ` str `
: param caption : Optional . Caption , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the audio caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param performer : Optional . Performer
: type performer : : obj : ` str `
: param audio_duration : Optional . Audio duration in seconds
: type audio_duration : : obj : ` int `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the audio
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultAudio `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , audio_url , title ,
caption = None , caption_entities = None , parse_mode = None , performer = None ,
audio_duration = None , reply_markup = None , input_message_content = None ) :
super ( ) . __init__ ( ' audio ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-04-14 11:57:23 +03:00
self . audio_url = audio_url
self . performer = performer
self . audio_duration = audio_duration
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' audio_url ' ] = self . audio_url
2016-04-14 11:57:23 +03:00
if self . performer :
json_dict [ ' performer ' ] = self . performer
if self . audio_duration :
json_dict [ ' audio_duration ' ] = self . audio_duration
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultVoice ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultvoice
: param type : Type of the result , must be voice
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param voice_url : A valid URL for the voice recording
: type voice_url : : obj : ` str `
: param title : Recording title
: type title : : obj : ` str `
: param caption : Optional . Caption , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the voice message caption . See formatting options for
more details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param voice_duration : Optional . Recording duration in seconds
: type voice_duration : : obj : ` int `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the voice recording
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultVoice `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , voice_url , title , caption = None , caption_entities = None ,
parse_mode = None , voice_duration = None , reply_markup = None , input_message_content = None ) :
super ( ) . __init__ ( ' voice ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-04-14 11:57:23 +03:00
self . voice_url = voice_url
self . voice_duration = voice_duration
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' voice_url ' ] = self . voice_url
2016-04-14 11:57:23 +03:00
if self . voice_duration :
json_dict [ ' voice_duration ' ] = self . voice_duration
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultDocument ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultdocument
: param type : Type of the result , must be document
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param title : Title for the result
: type title : : obj : ` str `
: param caption : Optional . Caption of the document to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the document caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param document_url : A valid URL for the file
: type document_url : : obj : ` str `
: param mime_type : MIME type of the content of the file , either “ application / pdf ” or “ application / zip ”
: type mime_type : : obj : ` str `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the file
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: param thumb_url : Optional . URL of the thumbnail ( JPEG only ) for the file
: type thumb_url : : obj : ` str `
: param thumb_width : Optional . Thumbnail width
: type thumb_width : : obj : ` int `
: param thumb_height : Optional . Thumbnail height
: type thumb_height : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultDocument `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , title , document_url , mime_type , caption = None , caption_entities = None ,
parse_mode = None , description = None , reply_markup = None , input_message_content = None ,
thumb_url = None , thumb_width = None , thumb_height = None ) :
super ( ) . __init__ ( ' document ' , id , title = title , caption = caption ,
input_message_content = input_message_content , reply_markup = reply_markup ,
parse_mode = parse_mode , caption_entities = caption_entities )
2016-04-14 11:57:23 +03:00
self . document_url = document_url
self . mime_type = mime_type
self . description = description
self . thumb_url = thumb_url
self . thumb_width = thumb_width
self . thumb_height = thumb_height
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' document_url ' ] = self . document_url
json_dict [ ' mime_type ' ] = self . mime_type
2016-04-14 11:57:23 +03:00
if self . description :
json_dict [ ' description ' ] = self . description
if self . thumb_url :
json_dict [ ' thumb_url ' ] = self . thumb_url
if self . thumb_width :
json_dict [ ' thumb_width ' ] = self . thumb_width
if self . thumb_height :
json_dict [ ' thumb_height ' ] = self . thumb_height
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultLocation ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultlocation
: param type : Type of the result , must be location
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 Bytes
: type id : : obj : ` str `
: param latitude : Location latitude in degrees
: type latitude : : obj : ` float ` number
: param longitude : Location longitude in degrees
: type longitude : : obj : ` float ` number
: param title : Location title
: type title : : obj : ` str `
: param horizontal_accuracy : Optional . The radius of uncertainty for the location , measured in meters ; 0 - 1500
: type horizontal_accuracy : : obj : ` float ` number
: param live_period : Optional . Period in seconds for which the location can be updated , should be between 60 and
86400.
: type live_period : : obj : ` int `
: param heading : Optional . For live locations , a direction in which the user is moving , in degrees . Must be between 1
and 360 if specified .
: type heading : : obj : ` int `
: param proximity_alert_radius : Optional . For live locations , a maximum distance for proximity alerts about
approaching another chat member , in meters . Must be between 1 and 100000 if specified .
: type proximity_alert_radius : : obj : ` int `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the location
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: param thumb_url : Optional . Url of the thumbnail for the result
: type thumb_url : : obj : ` str `
: param thumb_width : Optional . Thumbnail width
: type thumb_width : : obj : ` int `
: param thumb_height : Optional . Thumbnail height
: type thumb_height : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultLocation `
"""
2021-06-21 18:39:13 +03:00
def __init__ ( self , id , title , latitude , longitude , horizontal_accuracy , live_period = None , reply_markup = None ,
2021-08-18 18:47:38 +03:00
input_message_content = None , thumb_url = None , thumb_width = None , thumb_height = None , heading = None , proximity_alert_radius = None ) :
super ( ) . __init__ ( ' location ' , id , title = title ,
input_message_content = input_message_content , reply_markup = reply_markup )
2016-04-14 11:57:23 +03:00
self . latitude = latitude
self . longitude = longitude
2021-06-21 18:39:13 +03:00
self . horizontal_accuracy = horizontal_accuracy
2017-10-22 19:50:51 +03:00
self . live_period = live_period
2021-08-18 18:47:38 +03:00
self . heading : int = heading
self . proximity_alert_radius : int = proximity_alert_radius
2016-04-14 11:57:23 +03:00
self . thumb_url = thumb_url
self . thumb_width = thumb_width
self . thumb_height = thumb_height
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' latitude ' ] = self . latitude
json_dict [ ' longitude ' ] = self . longitude
2021-06-21 18:39:13 +03:00
if self . horizontal_accuracy :
json_dict [ ' horizontal_accuracy ' ] = self . horizontal_accuracy
2017-10-22 19:50:51 +03:00
if self . live_period :
json_dict [ ' live_period ' ] = self . live_period
2021-08-18 18:47:38 +03:00
if self . heading :
json_dict [ ' heading ' ] = self . heading
if self . proximity_alert_radius :
json_dict [ ' proximity_alert_radius ' ] = self . proximity_alert_radius
2016-04-14 11:57:23 +03:00
if self . thumb_url :
json_dict [ ' thumb_url ' ] = self . thumb_url
if self . thumb_width :
json_dict [ ' thumb_width ' ] = self . thumb_width
if self . thumb_height :
json_dict [ ' thumb_height ' ] = self . thumb_height
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultVenue ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultvenue
: param type : Type of the result , must be venue
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 Bytes
: type id : : obj : ` str `
: param latitude : Latitude of the venue location in degrees
: type latitude : : obj : ` float `
: param longitude : Longitude of the venue location in degrees
: type longitude : : obj : ` float `
: param title : Title of the venue
: type title : : obj : ` str `
: param address : Address of the venue
: type address : : obj : ` str `
: param foursquare_id : Optional . Foursquare identifier of the venue if known
: type foursquare_id : : obj : ` str `
: param foursquare_type : Optional . Foursquare type of the venue , if known . ( For example ,
“ arts_entertainment / default ” , “ arts_entertainment / aquarium ” or “ food / icecream ” . )
: type foursquare_type : : obj : ` str `
: param google_place_id : Optional . Google Places identifier of the venue
: type google_place_id : : obj : ` str `
: param google_place_type : Optional . Google Places type of the venue . ( See supported types . )
: type google_place_type : : obj : ` str `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the venue
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: param thumb_url : Optional . Url of the thumbnail for the result
: type thumb_url : : obj : ` str `
: param thumb_width : Optional . Thumbnail width
: type thumb_width : : obj : ` int `
: param thumb_height : Optional . Thumbnail height
: type thumb_height : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultVenue `
"""
2020-08-25 18:18:51 +03:00
def __init__ ( self , id , title , latitude , longitude , address , foursquare_id = None , foursquare_type = None ,
2021-06-21 18:39:13 +03:00
reply_markup = None , input_message_content = None , thumb_url = None ,
thumb_width = None , thumb_height = None , google_place_id = None , google_place_type = None ) :
2021-08-18 18:47:38 +03:00
super ( ) . __init__ ( ' venue ' , id , title = title ,
input_message_content = input_message_content , reply_markup = reply_markup )
2016-04-14 11:57:23 +03:00
self . latitude = latitude
self . longitude = longitude
self . address = address
self . foursquare_id = foursquare_id
2020-08-25 18:18:51 +03:00
self . foursquare_type = foursquare_type
2021-08-18 18:47:38 +03:00
self . google_place_id = google_place_id
self . google_place_type = google_place_type
2016-04-14 11:57:23 +03:00
self . thumb_url = thumb_url
self . thumb_width = thumb_width
self . thumb_height = thumb_height
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' latitude ' ] = self . latitude
json_dict [ ' longitude ' ] = self . longitude
json_dict [ ' address ' ] = self . address
2016-04-14 11:57:23 +03:00
if self . foursquare_id :
json_dict [ ' foursquare_id ' ] = self . foursquare_id
2020-08-25 18:18:51 +03:00
if self . foursquare_type :
json_dict [ ' foursquare_type ' ] = self . foursquare_type
2021-08-18 18:47:38 +03:00
if self . google_place_id :
json_dict [ ' google_place_id ' ] = self . google_place_id
if self . google_place_type :
json_dict [ ' google_place_type ' ] = self . google_place_type
2016-04-14 11:57:23 +03:00
if self . thumb_url :
json_dict [ ' thumb_url ' ] = self . thumb_url
if self . thumb_width :
json_dict [ ' thumb_width ' ] = self . thumb_width
if self . thumb_height :
json_dict [ ' thumb_height ' ] = self . thumb_height
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultContact ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
Represents a contact with a phone number . By default , this contact will be sent by the user . Alternatively , you can use input_message_content to send a message with the specified content instead of the contact .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcontact
: param type : Type of the result , must be contact
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 Bytes
: type id : : obj : ` str `
: param phone_number : Contact ' s phone number
: type phone_number : : obj : ` str `
: param first_name : Contact ' s first name
: type first_name : : obj : ` str `
: param last_name : Optional . Contact ' s last name
: type last_name : : obj : ` str `
: param vcard : Optional . Additional data about the contact in the form of a vCard , 0 - 2048 bytes
: type vcard : : obj : ` str `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the contact
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: param thumb_url : Optional . Url of the thumbnail for the result
: type thumb_url : : obj : ` str `
: param thumb_width : Optional . Thumbnail width
: type thumb_width : : obj : ` int `
: param thumb_height : Optional . Thumbnail height
: type thumb_height : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultContact `
"""
2020-08-25 18:18:51 +03:00
def __init__ ( self , id , phone_number , first_name , last_name = None , vcard = None ,
reply_markup = None , input_message_content = None ,
thumb_url = None , thumb_width = None , thumb_height = None ) :
2021-08-18 18:47:38 +03:00
super ( ) . __init__ ( ' contact ' , id ,
input_message_content = input_message_content , reply_markup = reply_markup )
2016-04-14 11:57:23 +03:00
self . phone_number = phone_number
self . first_name = first_name
self . last_name = last_name
2020-08-25 18:18:51 +03:00
self . vcard = vcard
2016-04-14 11:57:23 +03:00
self . thumb_url = thumb_url
self . thumb_width = thumb_width
self . thumb_height = thumb_height
2021-08-18 18:47:38 +03:00
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' phone_number ' ] = self . phone_number
json_dict [ ' first_name ' ] = self . first_name
2016-04-14 11:57:23 +03:00
if self . last_name :
json_dict [ ' last_name ' ] = self . last_name
2020-08-25 18:18:51 +03:00
if self . vcard :
json_dict [ ' vcard ' ] = self . vcard
2016-04-14 11:57:23 +03:00
if self . thumb_url :
json_dict [ ' thumb_url ' ] = self . thumb_url
if self . thumb_width :
json_dict [ ' thumb_width ' ] = self . thumb_width
if self . thumb_height :
json_dict [ ' thumb_height ' ] = self . thumb_height
2021-08-18 18:47:38 +03:00
return json_dict
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultGame ( InlineQueryResultBase ) :
2022-07-26 14:16:35 +03:00
"""
Represents a Game .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultgame
: param type : Type of the result , must be game
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param game_short_name : Short name of the game
: type game_short_name : : obj : ` str `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultGame `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , game_short_name , reply_markup = None ) :
super ( ) . __init__ ( ' game ' , id , reply_markup = reply_markup )
self . game_short_name = game_short_name
def to_dict ( self ) :
json_dict = super ( ) . to_dict ( )
json_dict [ ' game_short_name ' ] = self . game_short_name
return json_dict
class InlineQueryResultCachedBase ( ABC , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
Base class of all InlineQueryResultCached * classes .
"""
2016-04-14 11:57:23 +03:00
def __init__ ( self ) :
self . type = None
self . id = None
self . title = None
self . description = None
self . caption = None
self . reply_markup = None
self . input_message_content = None
2018-09-15 21:25:06 +03:00
self . parse_mode = None
2021-08-18 18:47:38 +03:00
self . caption_entities = None
2016-04-14 11:57:23 +03:00
self . payload_dic = { }
def to_json ( self ) :
json_dict = self . payload_dic
json_dict [ ' type ' ] = self . type
json_dict [ ' id ' ] = self . id
if self . title :
json_dict [ ' title ' ] = self . title
if self . description :
json_dict [ ' description ' ] = self . description
if self . caption :
json_dict [ ' caption ' ] = self . caption
if self . reply_markup :
2020-05-09 00:51:18 +03:00
json_dict [ ' reply_markup ' ] = self . reply_markup . to_dict ( )
2016-04-14 11:57:23 +03:00
if self . input_message_content :
2020-05-09 00:51:18 +03:00
json_dict [ ' input_message_content ' ] = self . input_message_content . to_dict ( )
2018-09-15 21:25:06 +03:00
if self . parse_mode :
json_dict [ ' parse_mode ' ] = self . parse_mode
2021-08-18 18:47:38 +03:00
if self . caption_entities :
json_dict [ ' caption_entities ' ] = MessageEntity . to_list_of_dicts ( self . caption_entities )
2016-01-05 06:03:05 +03:00
return json . dumps ( json_dict )
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedPhoto ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
Represents a link to a photo stored on the Telegram servers . By default , this photo 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 photo .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedphoto
: param type : Type of the result , must be photo
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param photo_file_id : A valid file identifier of the photo
: type photo_file_id : : obj : ` str `
: param title : Optional . Title for the result
: type title : : obj : ` str `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param caption : Optional . Caption of the photo to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the photo caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the photo
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedPhoto `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , photo_file_id , title = None , description = None ,
caption = None , caption_entities = None , parse_mode = None ,
2018-08-02 21:15:33 +03:00
reply_markup = None , input_message_content = None ) :
2021-08-18 18:47:38 +03:00
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' photo '
self . id = id
self . photo_file_id = photo_file_id
self . title = title
self . description = description
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 11:57:23 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-14 11:57:23 +03:00
self . payload_dic [ ' photo_file_id ' ] = photo_file_id
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedGif ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedgif
: param type : Type of the result , must be gif
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param gif_file_id : A valid file identifier for the GIF file
: type gif_file_id : : obj : ` str `
: param title : Optional . Title for the result
: type title : : obj : ` str `
: param caption : Optional . Caption of the GIF file to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the caption . See formatting options for more details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the GIF animation
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedGif `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , gif_file_id , title = None , description = None ,
caption = None , caption_entities = None , parse_mode = None ,
reply_markup = None , input_message_content = None ) :
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' gif '
self . id = id
self . gif_file_id = gif_file_id
self . title = title
self . description = description
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 11:57:23 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-14 11:57:23 +03:00
self . payload_dic [ ' gif_file_id ' ] = gif_file_id
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedMpeg4Gif ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedmpeg4gif
: param type : Type of the result , must be mpeg4_gif
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param mpeg4_file_id : A valid file identifier for the MPEG4 file
: type mpeg4_file_id : : obj : ` str `
: param title : Optional . Title for the result
: type title : : obj : ` str `
: param caption : Optional . Caption of the MPEG - 4 file to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the caption . See formatting options for more details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the video animation
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedMpeg4Gif `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , mpeg4_file_id , title = None , description = None ,
caption = None , caption_entities = None , parse_mode = None ,
2018-08-02 21:15:33 +03:00
reply_markup = None , input_message_content = None ) :
2021-08-18 18:47:38 +03:00
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 12:09:12 +03:00
self . type = ' mpeg4_gif '
self . id = id
self . mpeg4_file_id = mpeg4_file_id
self . title = title
self . description = description
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 12:09:12 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-14 12:09:12 +03:00
self . payload_dic [ ' mpeg4_file_id ' ] = mpeg4_file_id
2016-04-25 18:54:30 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedSticker ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedsticker
: param type : Type of the result , must be sticker
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param sticker_file_id : A valid file identifier of the sticker
: type sticker_file_id : : obj : ` str `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the sticker
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedSticker `
"""
2016-04-14 11:57:23 +03:00
def __init__ ( self , id , sticker_file_id , reply_markup = None , input_message_content = None ) :
2021-08-18 18:47:38 +03:00
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' sticker '
self . id = id
self . sticker_file_id = sticker_file_id
self . reply_markup = reply_markup
self . input_message_content = input_message_content
self . payload_dic [ ' sticker_file_id ' ] = sticker_file_id
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedDocument ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcacheddocument
: param type : Type of the result , must be document
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param title : Title for the result
: type title : : obj : ` str `
: param document_file_id : A valid file identifier for the file
: type document_file_id : : obj : ` str `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param caption : Optional . Caption of the document to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the document caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the file
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedDocument `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , document_file_id , title , description = None ,
caption = None , caption_entities = None , parse_mode = None ,
reply_markup = None , input_message_content = None ) :
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' document '
self . id = id
self . document_file_id = document_file_id
self . title = title
self . description = description
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 11:57:23 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-14 11:57:23 +03:00
self . payload_dic [ ' document_file_id ' ] = document_file_id
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedVideo ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedvideo
: param type : Type of the result , must be video
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param video_file_id : A valid file identifier for the video file
: type video_file_id : : obj : ` str `
: param title : Title for the result
: type title : : obj : ` str `
: param description : Optional . Short description of the result
: type description : : obj : ` str `
: param caption : Optional . Caption of the video to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the video caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the video
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedVideo `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , video_file_id , title , description = None ,
caption = None , caption_entities = None , parse_mode = None ,
reply_markup = None ,
2016-04-14 11:57:23 +03:00
input_message_content = None ) :
2021-08-18 18:47:38 +03:00
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' video '
self . id = id
self . video_file_id = video_file_id
self . title = title
self . description = description
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 11:57:23 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-14 11:57:23 +03:00
self . payload_dic [ ' video_file_id ' ] = video_file_id
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedVoice ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedvoice
: param type : Type of the result , must be voice
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param voice_file_id : A valid file identifier for the voice message
: type voice_file_id : : obj : ` str `
: param title : Voice message title
: type title : : obj : ` str `
: param caption : Optional . Caption , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the voice message caption . See formatting options for
more details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the voice message
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedVoice `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , voice_file_id , title , caption = None , caption_entities = None ,
parse_mode = None , reply_markup = None , input_message_content = None ) :
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' voice '
self . id = id
self . voice_file_id = voice_file_id
self . title = title
2016-10-11 22:57:16 +03:00
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 11:57:23 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-30 19:24:54 +03:00
self . payload_dic [ ' voice_file_id ' ] = voice_file_id
2016-04-14 11:57:23 +03:00
2021-08-18 18:47:38 +03:00
class InlineQueryResultCachedAudio ( InlineQueryResultCachedBase ) :
2022-07-26 14:16:35 +03:00
"""
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 .
Telegram Documentation : https : / / core . telegram . org / bots / api #inlinequeryresultcachedaudio
: param type : Type of the result , must be audio
: type type : : obj : ` str `
: param id : Unique identifier for this result , 1 - 64 bytes
: type id : : obj : ` str `
: param audio_file_id : A valid file identifier for the audio file
: type audio_file_id : : obj : ` str `
: param caption : Optional . Caption , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the audio caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param reply_markup : Optional . Inline keyboard attached to the message
: type reply_markup : : class : ` telebot . types . InlineKeyboardMarkup `
: param input_message_content : Optional . Content of the message to be sent instead of the audio
: type input_message_content : : class : ` telebot . types . InputMessageContent `
: return : Instance of the class
: rtype : : class : ` telebot . types . InlineQueryResultCachedAudio `
"""
2021-08-18 18:47:38 +03:00
def __init__ ( self , id , audio_file_id , caption = None , caption_entities = None ,
parse_mode = None , reply_markup = None , input_message_content = None ) :
InlineQueryResultCachedBase . __init__ ( self )
2016-04-14 11:57:23 +03:00
self . type = ' audio '
self . id = id
self . audio_file_id = audio_file_id
2016-10-11 22:57:16 +03:00
self . caption = caption
2021-08-18 18:47:38 +03:00
self . caption_entities = caption_entities
2016-04-14 11:57:23 +03:00
self . reply_markup = reply_markup
self . input_message_content = input_message_content
2018-09-15 21:25:06 +03:00
self . parse_mode = parse_mode
2016-04-14 11:57:23 +03:00
self . payload_dic [ ' audio_file_id ' ] = audio_file_id
2016-10-08 14:50:29 +03:00
# Games
class Game ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a game . Use BotFather to create and edit games , their short names will act as unique identifiers .
Telegram Documentation : https : / / core . telegram . org / bots / api #game
: param title : Title of the game
: type title : : obj : ` str `
: param description : Description of the game
: type description : : obj : ` str `
: param photo : Photo that will be displayed in the game message in chats .
: type photo : : obj : ` list ` of : class : ` telebot . types . PhotoSize `
: param text : Optional . Brief description of the game or high scores included in the game message . Can be
automatically edited to include current high scores for the game when the bot calls setGameScore , or manually edited
using editMessageText . 0 - 4096 characters .
: type text : : obj : ` str `
: param text_entities : Optional . Special entities that appear in text , such as usernames , URLs , bot commands , etc .
: type text_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param animation : Optional . Animation that will be displayed in the game message in chats . Upload via BotFather
: type animation : : class : ` telebot . types . Animation `
: return : Instance of the class
: rtype : : class : ` telebot . types . Game `
"""
2016-10-08 14:50:29 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2016-10-08 14:50:29 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' photo ' ] = Game . parse_photo ( obj [ ' photo ' ] )
2016-10-08 14:50:29 +03:00
if ' text_entities ' in obj :
2021-06-17 21:28:53 +03:00
obj [ ' text_entities ' ] = Game . parse_entities ( obj [ ' text_entities ' ] )
if ' animation ' in obj :
obj [ ' animation ' ] = Animation . de_json ( obj [ ' animation ' ] )
return cls ( * * obj )
2016-10-08 14:50:29 +03:00
@classmethod
def parse_photo ( cls , photo_size_array ) :
2022-07-26 14:16:35 +03:00
"""
Parse the photo array into a list of PhotoSize objects
"""
2016-10-08 14:50:29 +03:00
ret = [ ]
for ps in photo_size_array :
ret . append ( PhotoSize . de_json ( ps ) )
return ret
@classmethod
def parse_entities ( cls , message_entity_array ) :
2022-07-26 14:16:35 +03:00
"""
Parse the message entity array into a list of MessageEntity objects
"""
2016-10-08 14:50:29 +03:00
ret = [ ]
for me in message_entity_array :
ret . append ( MessageEntity . de_json ( me ) )
return ret
2021-06-17 21:28:53 +03:00
def __init__ ( self , title , description , photo , text = None , text_entities = None , animation = None , * * kwargs ) :
self . title : str = title
self . description : str = description
self . photo : List [ PhotoSize ] = photo
self . text : str = text
self . text_entities : List [ MessageEntity ] = text_entities
self . animation : Animation = animation
2016-10-08 14:50:29 +03:00
class Animation ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents an animation file ( GIF or H .264 / MPEG - 4 AVC video without sound ) .
Telegram Documentation : https : / / core . telegram . org / bots / api #animation
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
: param width : Video width as defined by sender
: type width : : obj : ` int `
: param height : Video height as defined by sender
: type height : : obj : ` int `
: param duration : Duration of the video in seconds as defined by sender
: type duration : : obj : ` int `
: param thumb : Optional . Animation thumbnail as defined by sender
: type thumb : : class : ` telebot . types . PhotoSize `
: param file_name : Optional . Original animation filename as defined by sender
: type file_name : : obj : ` str `
: param mime_type : Optional . MIME type of the file as defined by sender
: type mime_type : : obj : ` str `
: param file_size : Optional . File size in bytes . It can be bigger than 2 ^ 31 and some programming languages may have
difficulty / silent defects in interpreting it . But it has at most 52 significant bits , so a signed 64 - bit integer or
double - precision float type are safe for storing this value .
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Animation `
"""
2016-10-08 14:50:29 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2016-10-08 14:50:29 +03:00
obj = cls . check_json ( json_string )
2021-06-19 18:59:55 +03:00
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
obj [ " thumb " ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
else :
obj [ ' thumb ' ] = None
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , file_id , file_unique_id , width = None , height = None , duration = None ,
thumb = None , file_name = None , mime_type = None , file_size = None , * * kwargs ) :
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
self . width : int = width
self . height : int = height
self . duration : int = duration
self . thumb : PhotoSize = thumb
self . file_name : str = file_name
self . mime_type : str = mime_type
self . file_size : int = file_size
2016-10-08 14:50:29 +03:00
class GameHighScore ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents one row of the high scores table for a game .
Telegram Documentation : https : / / core . telegram . org / bots / api #gamehighscore
: param position : Position in high score table for the game
: type position : : obj : ` int `
: param user : User
: type user : : class : ` telebot . types . User `
: param score : Score
: type score : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . GameHighScore `
"""
2016-10-08 14:50:29 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2016-10-08 14:50:29 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' user ' ] = User . de_json ( obj [ ' user ' ] )
return cls ( * * obj )
2016-10-08 14:50:29 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , position , user , score , * * kwargs ) :
self . position : int = position
self . user : User = user
self . score : int = score
2017-05-21 16:45:12 +03:00
# Payments
2022-07-26 14:27:15 +03:00
class LabeledPrice ( JsonSerializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a portion of the price for goods or services .
Telegram Documentation : https : / / core . telegram . org / bots / api #labeledprice
: param label : Portion label
: type label : : obj : ` str `
: param amount : Price of the product in the smallest units of the currency ( integer , not float / double ) . For example ,
for a price of US $ 1.45 pass amount = 145. See the exp parameter in currencies . json , it shows the number of digits past
the decimal point for each currency ( 2 for the majority of currencies ) .
: type amount : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . LabeledPrice `
"""
2017-05-21 16:45:12 +03:00
def __init__ ( self , label , amount ) :
2021-06-17 21:28:53 +03:00
self . label : str = label
self . amount : int = amount
2017-05-21 16:45:12 +03:00
2021-06-21 20:59:39 +03:00
def to_dict ( self ) :
return {
2020-05-09 00:51:18 +03:00
' label ' : self . label , ' amount ' : self . amount
2021-06-21 20:59:39 +03:00
}
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
2017-05-21 16:45:12 +03:00
class Invoice ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains basic information about an invoice .
Telegram Documentation : https : / / core . telegram . org / bots / api #invoice
: param title : Product name
: type title : : obj : ` str `
: param description : Product description
: type description : : obj : ` str `
: param start_parameter : Unique bot deep - linking parameter that can be used to generate this invoice
: type start_parameter : : obj : ` str `
: param currency : Three - letter ISO 4217 currency code
: type currency : : obj : ` str `
: param total_amount : Total price in the smallest units of the currency ( integer , not float / double ) . For example ,
for a price of US $ 1.45 pass amount = 145. See the exp parameter in currencies . json , it shows the number of digits past
the decimal point for each currency ( 2 for the majority of currencies ) .
: type total_amount : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Invoice `
"""
2017-05-21 16:45:12 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , title , description , start_parameter , currency , total_amount , * * kwargs ) :
self . title : str = title
self . description : str = description
self . start_parameter : str = start_parameter
self . currency : str = currency
self . total_amount : int = total_amount
2017-05-21 16:45:12 +03:00
class ShippingAddress ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a shipping address .
Telegram Documentation : https : / / core . telegram . org / bots / api #shippingaddress
: param country_code : Two - letter ISO 3166 - 1 alpha - 2 country code
: type country_code : : obj : ` str `
: param state : State , if applicable
: type state : : obj : ` str `
: param city : City
: type city : : obj : ` str `
: param street_line1 : First line for the address
: type street_line1 : : obj : ` str `
: param street_line2 : Second line for the address
: type street_line2 : : obj : ` str `
: param post_code : Address post code
: type post_code : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ShippingAddress `
"""
2017-05-21 16:45:12 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , country_code , state , city , street_line1 , street_line2 , post_code , * * kwargs ) :
self . country_code : str = country_code
self . state : str = state
self . city : str = city
self . street_line1 : str = street_line1
self . street_line2 : str = street_line2
self . post_code : str = post_code
2017-05-21 16:45:12 +03:00
class OrderInfo ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents information about an order .
Telegram Documentation : https : / / core . telegram . org / bots / api #orderinfo
: param name : Optional . User name
: type name : : obj : ` str `
: param phone_number : Optional . User ' s phone number
: type phone_number : : obj : ` str `
: param email : Optional . User email
: type email : : obj : ` str `
: param shipping_address : Optional . User shipping address
: type shipping_address : : class : ` telebot . types . ShippingAddress `
: return : Instance of the class
: rtype : : class : ` telebot . types . OrderInfo `
"""
2017-05-21 16:45:12 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2017-05-21 16:45:12 +03:00
obj = cls . check_json ( json_string )
2021-06-19 18:59:55 +03:00
obj [ ' shipping_address ' ] = ShippingAddress . de_json ( obj . get ( ' shipping_address ' ) )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2021-06-19 18:59:55 +03:00
def __init__ ( self , name = None , phone_number = None , email = None , shipping_address = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . name : str = name
self . phone_number : str = phone_number
self . email : str = email
self . shipping_address : ShippingAddress = shipping_address
2017-05-21 16:45:12 +03:00
class ShippingOption ( JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents one shipping option .
Telegram Documentation : https : / / core . telegram . org / bots / api #shippingoption
: param id : Shipping option identifier
: type id : : obj : ` str `
: param title : Option title
: type title : : obj : ` str `
: param prices : List of price portions
: type prices : : obj : ` list ` of : class : ` telebot . types . LabeledPrice `
: return : Instance of the class
: rtype : : class : ` telebot . types . ShippingOption `
"""
2017-05-21 16:45:12 +03:00
def __init__ ( self , id , title ) :
2021-06-17 21:28:53 +03:00
self . id : str = id
self . title : str = title
self . prices : List [ LabeledPrice ] = [ ]
2017-05-21 16:45:12 +03:00
def add_price ( self , * args ) :
"""
Add LabeledPrice to ShippingOption
2022-03-19 11:49:36 +03:00
2018-04-04 10:47:37 +03:00
: param args : LabeledPrices
2022-07-26 14:16:35 +03:00
: type args : : obj : ` LabeledPrice `
: return : None
2017-05-21 16:45:12 +03:00
"""
for price in args :
self . prices . append ( price )
2018-11-12 02:43:00 +03:00
return self
2017-05-21 16:45:12 +03:00
def to_json ( self ) :
price_list = [ ]
for p in self . prices :
2020-05-09 00:51:18 +03:00
price_list . append ( p . to_dict ( ) )
2017-11-13 05:25:39 +03:00
json_dict = json . dumps ( { ' id ' : self . id , ' title ' : self . title , ' prices ' : price_list } )
2017-05-21 16:45:12 +03:00
return json_dict
class SuccessfulPayment ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains basic information about a successful payment .
Telegram Documentation : https : / / core . telegram . org / bots / api #successfulpayment
: param currency : Three - letter ISO 4217 currency code
: type currency : : obj : ` str `
: param total_amount : Total price in the smallest units of the currency ( integer , not float / double ) . For example ,
for a price of US $ 1.45 pass amount = 145. See the exp parameter in currencies . json , it shows the number of digits past
the decimal point for each currency ( 2 for the majority of currencies ) .
: type total_amount : : obj : ` int `
: param invoice_payload : Bot specified invoice payload
: type invoice_payload : : obj : ` str `
: param shipping_option_id : Optional . Identifier of the shipping option chosen by the user
: type shipping_option_id : : obj : ` str `
: param order_info : Optional . Order information provided by the user
: type order_info : : class : ` telebot . types . OrderInfo `
: param telegram_payment_charge_id : Telegram payment identifier
: type telegram_payment_charge_id : : obj : ` str `
: param provider_payment_charge_id : Provider payment identifier
: type provider_payment_charge_id : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . SuccessfulPayment `
"""
2017-05-21 16:45:12 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2017-05-21 16:45:12 +03:00
obj = cls . check_json ( json_string )
2021-06-19 18:59:55 +03:00
obj [ ' order_info ' ] = OrderInfo . de_json ( obj . get ( ' order_info ' ) )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , currency , total_amount , invoice_payload , shipping_option_id = None , order_info = None ,
telegram_payment_charge_id = None , provider_payment_charge_id = None , * * kwargs ) :
self . currency : str = currency
self . total_amount : int = total_amount
self . invoice_payload : str = invoice_payload
self . shipping_option_id : str = shipping_option_id
self . order_info : OrderInfo = order_info
self . telegram_payment_charge_id : str = telegram_payment_charge_id
self . provider_payment_charge_id : str = provider_payment_charge_id
2017-05-21 16:45:12 +03:00
class ShippingQuery ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains information about an incoming shipping query .
Telegram Documentation : https : / / core . telegram . org / bots / api #shippingquery
: param id : Unique query identifier
: type id : : obj : ` str `
: param from : User who sent the query
: type from : : class : ` telebot . types . User `
: param invoice_payload : Bot specified invoice payload
: type invoice_payload : : obj : ` str `
: param shipping_address : User specified shipping address
: type shipping_address : : class : ` telebot . types . ShippingAddress `
: return : Instance of the class
: rtype : : class : ` telebot . types . ShippingQuery `
"""
2017-05-21 16:45:12 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2017-05-21 16:45:12 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' from_user ' ] = User . de_json ( obj . pop ( ' from ' ) )
obj [ ' shipping_address ' ] = ShippingAddress . de_json ( obj [ ' shipping_address ' ] )
return cls ( * * obj )
2017-05-21 16:45:12 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , id , from_user , invoice_payload , shipping_address , * * kwargs ) :
self . id : str = id
self . from_user : User = from_user
self . invoice_payload : str = invoice_payload
self . shipping_address : ShippingAddress = shipping_address
2017-05-21 16:45:12 +03:00
class PreCheckoutQuery ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains information about an incoming pre - checkout query .
Telegram Documentation : https : / / core . telegram . org / bots / api #precheckoutquery
: param id : Unique query identifier
: type id : : obj : ` str `
: param from : User who sent the query
: type from : : class : ` telebot . types . User `
: param currency : Three - letter ISO 4217 currency code
: type currency : : obj : ` str `
: param total_amount : Total price in the smallest units of the currency ( integer , not float / double ) . For example ,
for a price of US $ 1.45 pass amount = 145. See the exp parameter in currencies . json , it shows the number of digits past
the decimal point for each currency ( 2 for the majority of currencies ) .
: type total_amount : : obj : ` int `
: param invoice_payload : Bot specified invoice payload
: type invoice_payload : : obj : ` str `
: param shipping_option_id : Optional . Identifier of the shipping option chosen by the user
: type shipping_option_id : : obj : ` str `
: param order_info : Optional . Order information provided by the user
: type order_info : : class : ` telebot . types . OrderInfo `
: return : Instance of the class
: rtype : : class : ` telebot . types . PreCheckoutQuery `
"""
2017-05-21 16:45:12 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2017-05-21 16:45:12 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' from_user ' ] = User . de_json ( obj . pop ( ' from ' ) )
2021-06-19 18:59:55 +03:00
obj [ ' order_info ' ] = OrderInfo . de_json ( obj . get ( ' order_info ' ) )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , id , from_user , currency , total_amount , invoice_payload , shipping_option_id = None , order_info = None , * * kwargs ) :
self . id : str = id
self . from_user : User = from_user
self . currency : str = currency
self . total_amount : int = total_amount
self . invoice_payload : str = invoice_payload
self . shipping_option_id : str = shipping_option_id
self . order_info : OrderInfo = order_info
2017-08-06 07:00:26 +03:00
2017-08-06 09:25:25 +03:00
2017-08-06 07:00:26 +03:00
# Stickers
class StickerSet ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a sticker set .
Telegram Documentation : https : / / core . telegram . org / bots / api #stickerset
: param name : Sticker set name
: type name : : obj : ` str `
: param title : Sticker set title
: type title : : obj : ` str `
2022-08-12 20:10:08 +03:00
: param sticker_type : Type of stickers in the set , currently one of “ regular ” , “ mask ” , “ custom_emoji ”
: type sticker_type : : obj : ` str `
2022-07-26 14:16:35 +03:00
: param is_animated : True , if the sticker set contains animated stickers
: type is_animated : : obj : ` bool `
: param is_video : True , if the sticker set contains video stickers
: type is_video : : obj : ` bool `
2022-08-12 20:10:08 +03:00
: param contains_masks : True , if the sticker set contains masks . Deprecated since Bot API 6.2 ,
use sticker_type instead .
2022-07-26 14:16:35 +03:00
: type contains_masks : : obj : ` bool `
: param stickers : List of all set stickers
: type stickers : : obj : ` list ` of : class : ` telebot . types . Sticker `
: param thumb : Optional . Sticker set thumbnail in the . WEBP , . TGS , or . WEBM format
: type thumb : : class : ` telebot . types . PhotoSize `
: return : Instance of the class
: rtype : : class : ` telebot . types . StickerSet `
"""
2017-08-06 07:00:26 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2017-08-06 07:00:26 +03:00
obj = cls . check_json ( json_string )
2017-08-06 09:25:25 +03:00
stickers = [ ]
for s in obj [ ' stickers ' ] :
2017-08-06 07:00:26 +03:00
stickers . append ( Sticker . de_json ( s ) )
2021-06-17 21:28:53 +03:00
obj [ ' stickers ' ] = stickers
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
obj [ ' thumb ' ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
2021-06-18 23:35:49 +03:00
else :
obj [ ' thumb ' ] = None
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2017-08-06 07:00:26 +03:00
2022-08-13 11:22:25 +03:00
def __init__ ( self , name , title , sticker_type , is_animated , is_video , stickers , thumb = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . name : str = name
self . title : str = title
2022-08-12 20:10:08 +03:00
self . sticker_type : str = sticker_type
2021-06-17 21:28:53 +03:00
self . is_animated : bool = is_animated
2022-02-01 13:47:42 +03:00
self . is_video : bool = is_video
2021-06-17 21:28:53 +03:00
self . stickers : List [ Sticker ] = stickers
self . thumb : PhotoSize = thumb
2017-08-06 07:00:26 +03:00
2022-08-13 11:22:25 +03:00
@property
def contains_masks ( self ) :
"""
Deprecated since Bot API 6.2 , use sticker_type instead .
"""
logger . warning ( " contains_masks is deprecated, use sticker_type instead " )
return self . sticker_type == ' mask '
2017-08-06 07:00:26 +03:00
class Sticker ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a sticker .
Telegram Documentation : https : / / core . telegram . org / bots / api #sticker
: param file_id : Identifier for this file , which can be used to download or reuse the file
: type file_id : : obj : ` str `
: param file_unique_id : Unique identifier for this file , which is supposed to be the same over time and for different
bots . Can ' t be used to download or reuse the file.
: type file_unique_id : : obj : ` str `
2022-08-12 20:10:08 +03:00
: param type : Type of the sticker , currently one of “ regular ” , “ mask ” , “ custom_emoji ” . The type of the sticker is
independent from its format , which is determined by the fields is_animated and is_video .
: type type : : obj : ` str `
2022-07-26 14:16:35 +03:00
: param width : Sticker width
: type width : : obj : ` int `
: param height : Sticker height
: type height : : obj : ` int `
: param is_animated : True , if the sticker is animated
: type is_animated : : obj : ` bool `
: param is_video : True , if the sticker is a video sticker
: type is_video : : obj : ` bool `
: param thumb : Optional . Sticker thumbnail in the . WEBP or . JPG format
: type thumb : : class : ` telebot . types . PhotoSize `
: param emoji : Optional . Emoji associated with the sticker
: type emoji : : obj : ` str `
: param set_name : Optional . Name of the sticker set to which the sticker belongs
: type set_name : : obj : ` str `
: param premium_animation : Optional . Premium animation for the sticker , if the sticker is premium
: type premium_animation : : class : ` telebot . types . File `
: param mask_position : Optional . For mask stickers , the position where the mask should be placed
: type mask_position : : class : ` telebot . types . MaskPosition `
2022-08-12 20:10:08 +03:00
: param custom_emoji_id : Optional . For custom emoji stickers , unique identifier of the custom emoji
: type custom_emoji_id : : obj : ` str `
2022-07-26 14:16:35 +03:00
: param file_size : Optional . File size in bytes
: type file_size : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Sticker `
"""
2017-08-06 07:00:26 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2017-08-06 07:00:26 +03:00
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
if ' thumb ' in obj and ' file_id ' in obj [ ' thumb ' ] :
obj [ ' thumb ' ] = PhotoSize . de_json ( obj [ ' thumb ' ] )
2021-06-18 23:35:49 +03:00
else :
obj [ ' thumb ' ] = None
2021-06-17 21:28:53 +03:00
if ' mask_position ' in obj :
obj [ ' mask_position ' ] = MaskPosition . de_json ( obj [ ' mask_position ' ] )
2022-06-21 13:27:45 +03:00
if ' premium_animation ' in obj :
2022-06-21 13:21:35 +03:00
obj [ ' premium_animation ' ] = File . de_json ( obj [ ' premium_animation ' ] )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2022-08-12 20:10:08 +03:00
def __init__ ( self , file_id , file_unique_id , type , width , height , is_animated ,
2022-06-21 13:21:35 +03:00
is_video , thumb = None , emoji = None , set_name = None , mask_position = None , file_size = None ,
2022-08-12 20:10:08 +03:00
premium_animation = None , custom_emoji_id = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . file_id : str = file_id
self . file_unique_id : str = file_unique_id
2022-08-12 20:10:08 +03:00
self . type : str = type
2021-06-17 21:28:53 +03:00
self . width : int = width
self . height : int = height
self . is_animated : bool = is_animated
2022-02-01 13:47:42 +03:00
self . is_video : bool = is_video
2021-06-17 21:28:53 +03:00
self . thumb : PhotoSize = thumb
self . emoji : str = emoji
self . set_name : str = set_name
self . mask_position : MaskPosition = mask_position
self . file_size : int = file_size
2022-06-21 13:21:35 +03:00
self . premium_animation : File = premium_animation
2022-08-12 20:10:08 +03:00
self . custom_emoji_id : int = custom_emoji_id
2021-06-17 21:28:53 +03:00
2017-08-06 07:00:26 +03:00
2020-04-25 22:22:08 +03:00
class MaskPosition ( Dictionaryable , JsonDeserializable , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object describes the position on faces where a mask should be placed by default .
Telegram Documentation : https : / / core . telegram . org / bots / api #maskposition
: param point : The part of the face relative to which the mask should be placed . One of “ forehead ” , “ eyes ” , “ mouth ” , or
“ chin ” .
: type point : : obj : ` str `
: param x_shift : Shift by X - axis measured in widths of the mask scaled to the face size , from left to right . For example ,
choosing - 1.0 will place mask just to the left of the default mask position .
: type x_shift : : obj : ` float ` number
: param y_shift : Shift by Y - axis measured in heights of the mask scaled to the face size , from top to bottom . For
example , 1.0 will place the mask just below the default mask position .
: type y_shift : : obj : ` float ` number
: param scale : Mask scaling coefficient . For example , 2.0 means double size .
: type scale : : obj : ` float ` number
: return : Instance of the class
: rtype : : class : ` telebot . types . MaskPosition `
"""
2017-08-06 07:00:26 +03:00
@classmethod
def de_json ( cls , json_string ) :
2020-04-11 16:54:25 +03:00
if ( json_string is None ) : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
def __init__ ( self , point , x_shift , y_shift , scale , * * kwargs ) :
self . point : str = point
self . x_shift : float = x_shift
self . y_shift : float = y_shift
self . scale : float = scale
2017-08-06 09:25:25 +03:00
def to_json ( self ) :
2020-05-09 00:51:18 +03:00
return json . dumps ( self . to_dict ( ) )
2017-08-06 09:25:25 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
2017-08-06 09:25:25 +03:00
return { ' point ' : self . point , ' x_shift ' : self . x_shift , ' y_shift ' : self . y_shift , ' scale ' : self . scale }
2017-11-29 08:45:25 +03:00
# InputMedia
2020-04-25 22:22:08 +03:00
class InputMedia ( Dictionaryable , JsonSerializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents the content of a media message to be sent . It should be one of
* : class : ` InputMediaAnimation `
* : class : ` InputMediaDocument `
* : class : ` InputMediaAudio `
* : class : ` InputMediaPhoto `
* : class : ` InputMediaVideo `
"""
2021-06-22 16:55:14 +03:00
def __init__ ( self , type , media , caption = None , parse_mode = None , caption_entities = None ) :
2021-06-17 21:28:53 +03:00
self . type : str = type
self . media : str = media
2021-06-22 16:55:14 +03:00
self . caption : Optional [ str ] = caption
self . parse_mode : Optional [ str ] = parse_mode
self . caption_entities : Optional [ List [ MessageEntity ] ] = caption_entities
2017-11-29 08:45:25 +03:00
2018-08-10 16:47:59 +03:00
if util . is_string ( self . media ) :
self . _media_name = ' '
self . _media_dic = self . media
else :
self . _media_name = util . generate_random_token ( )
2018-08-14 17:29:35 +03:00
self . _media_dic = ' attach:// {0} ' . format ( self . _media_name )
2018-08-09 19:10:01 +03:00
2017-11-29 08:45:25 +03:00
def to_json ( self ) :
2020-05-09 00:51:18 +03:00
return json . dumps ( self . to_dict ( ) )
2017-11-29 08:45:25 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
json_dict = { ' type ' : self . type , ' media ' : self . _media_dic }
2017-11-29 08:45:25 +03:00
if self . caption :
2020-05-09 00:51:18 +03:00
json_dict [ ' caption ' ] = self . caption
2018-02-14 23:27:55 +03:00
if self . parse_mode :
2020-05-09 00:51:18 +03:00
json_dict [ ' parse_mode ' ] = self . parse_mode
2021-06-22 16:55:14 +03:00
if self . caption_entities :
2021-08-18 18:47:38 +03:00
json_dict [ ' caption_entities ' ] = MessageEntity . to_list_of_dicts ( self . caption_entities )
2020-05-09 00:51:18 +03:00
return json_dict
2017-11-29 08:45:25 +03:00
2020-07-21 01:20:01 +03:00
def convert_input_media ( self ) :
2022-07-26 14:16:35 +03:00
"""
: meta private :
"""
2018-08-09 19:10:01 +03:00
if util . is_string ( self . media ) :
return self . to_json ( ) , None
2018-08-10 16:47:59 +03:00
return self . to_json ( ) , { self . _media_name : self . media }
2018-08-09 19:10:01 +03:00
class InputMediaPhoto ( InputMedia ) :
2022-07-26 14:16:35 +03:00
"""
Represents a photo to be sent .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputmediaphoto
: param type : Type of the result , must be photo
: type type : : obj : ` str `
: param media : File to send . Pass a file_id to send a file that exists on the Telegram servers ( recommended ) , pass an
HTTP URL for Telegram to get a file from the Internet , or pass “ attach : / / < file_attach_name > ” to upload a new one using
multipart / form - data under < file_attach_name > name . More information on Sending Files »
: type media : : obj : ` str `
: param caption : Optional . Caption of the photo to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the photo caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputMediaPhoto `
"""
2018-08-09 19:10:01 +03:00
def __init__ ( self , media , caption = None , parse_mode = None ) :
2020-08-02 18:20:33 +03:00
if util . is_pil_image ( media ) :
media = util . pil_image_to_file ( media )
2018-08-10 16:47:59 +03:00
super ( InputMediaPhoto , self ) . __init__ ( type = " photo " , media = media , caption = caption , parse_mode = parse_mode )
2018-08-09 19:10:01 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
return super ( InputMediaPhoto , self ) . to_dict ( )
2018-08-09 19:10:01 +03:00
2017-11-29 08:45:25 +03:00
2018-08-09 19:10:01 +03:00
class InputMediaVideo ( InputMedia ) :
2022-07-26 14:16:35 +03:00
"""
Represents a video to be sent .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputmediavideo
: param type : Type of the result , must be video
: type type : : obj : ` str `
: param media : File to send . Pass a file_id to send a file that exists on the Telegram servers ( recommended ) , pass an
HTTP URL for Telegram to get a file from the Internet , or pass “ attach : / / < file_attach_name > ” to upload a new one using
multipart / form - data under < file_attach_name > name . More information on Sending Files »
: type media : : obj : ` str `
: param thumb : Optional . Thumbnail of the file sent ; can be ignored if thumbnail generation for the file is supported
server - side . The thumbnail should be in JPEG format and less than 200 kB in size . A thumbnail ' s width and height should
not exceed 320. Ignored if the file is not uploaded using multipart / form - data . Thumbnails can ' t be reused and can be
only uploaded as a new file , so you can pass “ attach : / / < file_attach_name > ” if the thumbnail was uploaded using
multipart / form - data under < file_attach_name > . More information on Sending Files »
: type thumb : InputFile or : obj : ` str `
: param caption : Optional . Caption of the video to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the video caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param width : Optional . Video width
: type width : : obj : ` int `
: param height : Optional . Video height
: type height : : obj : ` int `
: param duration : Optional . Video duration in seconds
: type duration : : obj : ` int `
: param supports_streaming : Optional . Pass True , if the uploaded video is suitable for streaming
: type supports_streaming : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputMediaVideo `
"""
2018-08-09 19:10:01 +03:00
def __init__ ( self , media , thumb = None , caption = None , parse_mode = None , width = None , height = None , duration = None ,
2018-02-14 23:27:55 +03:00
supports_streaming = None ) :
2018-08-10 16:47:59 +03:00
super ( InputMediaVideo , self ) . __init__ ( type = " video " , media = media , caption = caption , parse_mode = parse_mode )
2018-08-09 19:10:01 +03:00
self . thumb = thumb
2017-11-29 08:45:25 +03:00
self . width = width
self . height = height
self . duration = duration
2018-02-14 23:27:55 +03:00
self . supports_streaming = supports_streaming
2017-11-29 08:45:25 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
ret = super ( InputMediaVideo , self ) . to_dict ( )
2018-08-09 19:10:01 +03:00
if self . thumb :
ret [ ' thumb ' ] = self . thumb
2017-11-29 08:45:25 +03:00
if self . width :
ret [ ' width ' ] = self . width
if self . height :
ret [ ' height ' ] = self . height
if self . duration :
ret [ ' duration ' ] = self . duration
2018-02-14 23:27:55 +03:00
if self . supports_streaming :
ret [ ' supports_streaming ' ] = self . supports_streaming
2017-11-29 08:45:25 +03:00
return ret
2018-08-09 19:10:01 +03:00
class InputMediaAnimation ( InputMedia ) :
2022-07-26 14:16:35 +03:00
"""
Represents an animation file ( GIF or H .264 / MPEG - 4 AVC video without sound ) to be sent .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputmediaanimation
: param type : Type of the result , must be animation
: type type : : obj : ` str `
: param media : File to send . Pass a file_id to send a file that exists on the Telegram servers ( recommended ) , pass an
HTTP URL for Telegram to get a file from the Internet , or pass “ attach : / / < file_attach_name > ” to upload a new one using
multipart / form - data under < file_attach_name > name . More information on Sending Files »
: type media : : obj : ` str `
: param thumb : Optional . Thumbnail of the file sent ; can be ignored if thumbnail generation for the file is supported
server - side . The thumbnail should be in JPEG format and less than 200 kB in size . A thumbnail ' s width and height should
not exceed 320. Ignored if the file is not uploaded using multipart / form - data . Thumbnails can ' t be reused and can be
only uploaded as a new file , so you can pass “ attach : / / < file_attach_name > ” if the thumbnail was uploaded using
multipart / form - data under < file_attach_name > . More information on Sending Files »
: type thumb : InputFile or : obj : ` str `
: param caption : Optional . Caption of the animation to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the animation caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param width : Optional . Animation width
: type width : : obj : ` int `
: param height : Optional . Animation height
: type height : : obj : ` int `
: param duration : Optional . Animation duration in seconds
: type duration : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputMediaAnimation `
"""
2018-08-09 19:10:01 +03:00
def __init__ ( self , media , thumb = None , caption = None , parse_mode = None , width = None , height = None , duration = None ) :
2018-08-10 16:47:59 +03:00
super ( InputMediaAnimation , self ) . __init__ ( type = " animation " , media = media , caption = caption , parse_mode = parse_mode )
2018-08-09 19:10:01 +03:00
self . thumb = thumb
self . width = width
self . height = height
self . duration = duration
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
ret = super ( InputMediaAnimation , self ) . to_dict ( )
2018-08-09 19:10:01 +03:00
if self . thumb :
ret [ ' thumb ' ] = self . thumb
if self . width :
ret [ ' width ' ] = self . width
if self . height :
ret [ ' height ' ] = self . height
if self . duration :
ret [ ' duration ' ] = self . duration
return ret
class InputMediaAudio ( InputMedia ) :
2022-07-26 14:16:35 +03:00
"""
Represents an audio file to be treated as music to be sent .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputmediaaudio
: param type : Type of the result , must be audio
: type type : : obj : ` str `
: param media : File to send . Pass a file_id to send a file that exists on the Telegram servers ( recommended ) , pass an
HTTP URL for Telegram to get a file from the Internet , or pass “ attach : / / < file_attach_name > ” to upload a new one using
multipart / form - data under < file_attach_name > name . More information on Sending Files »
: type media : : obj : ` str `
: param thumb : Optional . Thumbnail of the file sent ; can be ignored if thumbnail generation for the file is supported
server - side . The thumbnail should be in JPEG format and less than 200 kB in size . A thumbnail ' s width and height should
not exceed 320. Ignored if the file is not uploaded using multipart / form - data . Thumbnails can ' t be reused and can be
only uploaded as a new file , so you can pass “ attach : / / < file_attach_name > ” if the thumbnail was uploaded using
multipart / form - data under < file_attach_name > . More information on Sending Files »
: type thumb : InputFile or : obj : ` str `
: param caption : Optional . Caption of the audio to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the audio caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param duration : Optional . Duration of the audio in seconds
: type duration : : obj : ` int `
: param performer : Optional . Performer of the audio
: type performer : : obj : ` str `
: param title : Optional . Title of the audio
: type title : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputMediaAudio `
"""
2018-08-09 19:10:01 +03:00
def __init__ ( self , media , thumb = None , caption = None , parse_mode = None , duration = None , performer = None , title = None ) :
2018-08-10 16:47:59 +03:00
super ( InputMediaAudio , self ) . __init__ ( type = " audio " , media = media , caption = caption , parse_mode = parse_mode )
2018-08-09 19:10:01 +03:00
self . thumb = thumb
self . duration = duration
self . performer = performer
self . title = title
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
ret = super ( InputMediaAudio , self ) . to_dict ( )
2018-08-09 19:10:01 +03:00
if self . thumb :
ret [ ' thumb ' ] = self . thumb
if self . duration :
ret [ ' duration ' ] = self . duration
if self . performer :
ret [ ' performer ' ] = self . performer
if self . title :
ret [ ' title ' ] = self . title
return ret
class InputMediaDocument ( InputMedia ) :
2022-07-26 14:16:35 +03:00
"""
Represents a general file to be sent .
Telegram Documentation : https : / / core . telegram . org / bots / api #inputmediadocument
: param type : Type of the result , must be document
: type type : : obj : ` str `
: param media : File to send . Pass a file_id to send a file that exists on the Telegram servers ( recommended ) , pass an
HTTP URL for Telegram to get a file from the Internet , or pass “ attach : / / < file_attach_name > ” to upload a new one using
multipart / form - data under < file_attach_name > name . More information on Sending Files »
: type media : : obj : ` str `
: param thumb : Optional . Thumbnail of the file sent ; can be ignored if thumbnail generation for the file is supported
server - side . The thumbnail should be in JPEG format and less than 200 kB in size . A thumbnail ' s width and height should
not exceed 320. Ignored if the file is not uploaded using multipart / form - data . Thumbnails can ' t be reused and can be
only uploaded as a new file , so you can pass “ attach : / / < file_attach_name > ” if the thumbnail was uploaded using
multipart / form - data under < file_attach_name > . More information on Sending Files »
: type thumb : InputFile or : obj : ` str `
: param caption : Optional . Caption of the document to be sent , 0 - 1024 characters after entities parsing
: type caption : : obj : ` str `
: param parse_mode : Optional . Mode for parsing entities in the document caption . See formatting options for more
details .
: type parse_mode : : obj : ` str `
: param caption_entities : Optional . List of special entities that appear in the caption , which can be specified
instead of parse_mode
: type caption_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param disable_content_type_detection : Optional . Disables automatic server - side content type detection for
files uploaded using multipart / form - data . Always True , if the document is sent as part of an album .
: type disable_content_type_detection : : obj : ` bool `
: return : Instance of the class
: rtype : : class : ` telebot . types . InputMediaDocument `
"""
2021-06-22 16:55:14 +03:00
def __init__ ( self , media , thumb = None , caption = None , parse_mode = None , disable_content_type_detection = None ) :
2018-08-10 16:47:59 +03:00
super ( InputMediaDocument , self ) . __init__ ( type = " document " , media = media , caption = caption , parse_mode = parse_mode )
2018-08-09 19:10:01 +03:00
self . thumb = thumb
2021-06-22 16:55:14 +03:00
self . disable_content_type_detection = disable_content_type_detection
2018-08-09 19:10:01 +03:00
2020-05-09 00:51:18 +03:00
def to_dict ( self ) :
ret = super ( InputMediaDocument , self ) . to_dict ( )
2018-08-09 19:10:01 +03:00
if self . thumb :
ret [ ' thumb ' ] = self . thumb
2021-06-22 16:55:14 +03:00
if self . disable_content_type_detection is not None :
ret [ ' disable_content_type_detection ' ] = self . disable_content_type_detection
2018-08-09 19:10:01 +03:00
return ret
2019-06-06 21:47:08 +03:00
2021-05-12 00:26:33 +03:00
class PollOption ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains information about one answer option in a poll .
Telegram Documentation : https : / / core . telegram . org / bots / api #polloption
: param text : Option text , 1 - 100 characters
: type text : : obj : ` str `
: param voter_count : Number of users that voted for this option
: type voter_count : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . PollOption `
"""
2019-06-06 21:47:08 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
if ( json_string is None ) : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-17 21:28:53 +03:00
return cls ( * * obj )
2019-06-06 21:47:08 +03:00
2021-06-17 21:28:53 +03:00
def __init__ ( self , text , voter_count = 0 , * * kwargs ) :
self . text : str = text
self . voter_count : int = voter_count
2021-05-12 00:26:33 +03:00
# Converted in _convert_poll_options
# def to_json(self):
# # send_poll Option is a simple string: https://core.telegram.org/bots/api#sendpoll
# return json.dumps(self.text)
2019-06-06 21:47:08 +03:00
class Poll ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object contains information about a poll .
Telegram Documentation : https : / / core . telegram . org / bots / api #poll
: param id : Unique poll identifier
: type id : : obj : ` str `
: param question : Poll question , 1 - 300 characters
: type question : : obj : ` str `
: param options : List of poll options
: type options : : obj : ` list ` of : class : ` telebot . types . PollOption `
: param total_voter_count : Total number of users that voted in the poll
: type total_voter_count : : obj : ` int `
: param is_closed : True , if the poll is closed
: type is_closed : : obj : ` bool `
: param is_anonymous : True , if the poll is anonymous
: type is_anonymous : : obj : ` bool `
: param type : Poll type , currently can be “ regular ” or “ quiz ”
: type type : : obj : ` str `
: param allows_multiple_answers : True , if the poll allows multiple answers
: type allows_multiple_answers : : obj : ` bool `
: param correct_option_id : Optional . 0 - based identifier of the correct answer option . Available only for polls in
the quiz mode , which are closed , or was sent ( not forwarded ) by the bot or to the private chat with the bot .
: type correct_option_id : : obj : ` int `
: param explanation : Optional . Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a
quiz - style poll , 0 - 200 characters
: type explanation : : obj : ` str `
: param explanation_entities : Optional . Special entities like usernames , URLs , bot commands , etc . that appear in
the explanation
: type explanation_entities : : obj : ` list ` of : class : ` telebot . types . MessageEntity `
: param open_period : Optional . Amount of time in seconds the poll will be active after creation
: type open_period : : obj : ` int `
: param close_date : Optional . Point in time ( Unix timestamp ) when the poll will be automatically closed
: type close_date : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . Poll `
"""
2019-06-06 21:47:08 +03:00
@classmethod
2020-04-11 17:06:14 +03:00
def de_json ( cls , json_string ) :
if ( json_string is None ) : return None
obj = cls . check_json ( json_string )
2021-06-18 23:35:49 +03:00
obj [ ' poll_id ' ] = obj . pop ( ' id ' )
2019-06-06 21:47:08 +03:00
options = [ ]
for opt in obj [ ' options ' ] :
options . append ( PollOption . de_json ( opt ) )
2021-06-17 21:28:53 +03:00
obj [ ' options ' ] = options or None
2020-04-25 22:22:08 +03:00
if ' explanation_entities ' in obj :
2021-06-17 21:28:53 +03:00
obj [ ' explanation_entities ' ] = Message . parse_entities ( obj [ ' explanation_entities ' ] )
return cls ( * * obj )
2020-04-25 22:22:08 +03:00
2022-05-15 00:59:35 +03:00
# noinspection PyShadowingBuiltins
2020-04-25 22:22:08 +03:00
def __init__ (
self ,
question , options ,
2022-05-15 00:59:35 +03:00
poll_id = None , total_voter_count = None , is_closed = None , is_anonymous = None , type = None ,
2020-04-25 22:22:08 +03:00
allows_multiple_answers = None , correct_option_id = None , explanation = None , explanation_entities = None ,
2022-05-15 00:59:35 +03:00
open_period = None , close_date = None , poll_type = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . id : str = poll_id
self . question : str = question
self . options : List [ PollOption ] = options
self . total_voter_count : int = total_voter_count
self . is_closed : bool = is_closed
self . is_anonymous : bool = is_anonymous
2022-05-15 00:59:35 +03:00
self . type : str = type
if poll_type is not None :
# Wrong param name backward compatibility
logger . warning ( " Poll: poll_type parameter is deprecated. Use type instead. " )
if type is None :
self . type : str = poll_type
2021-06-17 21:28:53 +03:00
self . allows_multiple_answers : bool = allows_multiple_answers
self . correct_option_id : int = correct_option_id
self . explanation : str = explanation
2022-05-15 00:59:35 +03:00
self . explanation_entities : List [ MessageEntity ] = explanation_entities
2021-06-17 21:28:53 +03:00
self . open_period : int = open_period
self . close_date : int = close_date
2019-06-06 21:47:08 +03:00
def add ( self , option ) :
2022-07-26 14:16:35 +03:00
"""
Add an option to the poll .
: param option : Option to add
: type option : : class : ` telebot . types . PollOption ` or : obj : ` str `
"""
2019-06-06 21:47:08 +03:00
if type ( option ) is PollOption :
self . options . append ( option )
else :
self . options . append ( PollOption ( option ) )
2020-05-12 03:09:34 +03:00
class PollAnswer ( JsonSerializable , JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents an answer of a user in a non - anonymous poll .
Telegram Documentation : https : / / core . telegram . org / bots / api #pollanswer
: param poll_id : Unique poll identifier
: type poll_id : : obj : ` str `
: param user : The user , who changed the answer to the poll
: type user : : class : ` telebot . types . User `
: param option_ids : 0 - based identifiers of answer options , chosen by the user . May be empty if the user retracted
their vote .
: type option_ids : : obj : ` list ` of : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . PollAnswer `
"""
2020-05-12 03:09:34 +03:00
@classmethod
def de_json ( cls , json_string ) :
if ( json_string is None ) : return None
obj = cls . check_json ( json_string )
2021-06-17 21:28:53 +03:00
obj [ ' user ' ] = User . de_json ( obj [ ' user ' ] )
return cls ( * * obj )
2020-05-12 03:09:34 +03:00
2021-06-19 21:13:53 +03:00
def __init__ ( self , poll_id , user , option_ids , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . poll_id : str = poll_id
self . user : User = user
2021-06-19 21:13:53 +03:00
self . option_ids : List [ int ] = option_ids
2020-05-12 03:09:34 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
return { ' poll_id ' : self . poll_id ,
' user ' : self . user . to_dict ( ) ,
2021-06-19 21:13:53 +03:00
' option_ids ' : self . option_ids }
2021-06-17 21:28:53 +03:00
class ChatLocation ( JsonSerializable , JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents a location to which a chat is connected .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatlocation
: param location : The location to which the supergroup is connected . Can ' t be a live location.
: type location : : class : ` telebot . types . Location `
: param address : Location address ; 1 - 64 characters , as defined by the chat owner
: type address : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatLocation `
"""
2021-06-17 21:28:53 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return json_string
obj = cls . check_json ( json_string )
obj [ ' location ' ] = Location . de_json ( obj [ ' location ' ] )
return cls ( * * obj )
2021-06-19 18:59:55 +03:00
def __init__ ( self , location , address , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . location : Location = location
self . address : str = address
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
return {
" location " : self . location . to_dict ( ) ,
" address " : self . address
}
class ChatInviteLink ( JsonSerializable , JsonDeserializable , Dictionaryable ) :
2022-07-26 14:16:35 +03:00
"""
Represents an invite link for a chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatinvitelink
: param invite_link : The invite link . If the link was created by another chat administrator , then the second part of
the link will be replaced with “ … ” .
: type invite_link : : obj : ` str `
: param creator : Creator of the link
: type creator : : class : ` telebot . types . User `
: param creates_join_request : True , if users joining the chat via the link need to be approved by chat administrators
: type creates_join_request : : obj : ` bool `
: param is_primary : True , if the link is primary
: type is_primary : : obj : ` bool `
: param is_revoked : True , if the link is revoked
: type is_revoked : : obj : ` bool `
: param name : Optional . Invite link name
: type name : : obj : ` str `
: param expire_date : Optional . Point in time ( Unix timestamp ) when the link will expire or has been expired
: type expire_date : : obj : ` int `
: param member_limit : Optional . The maximum number of users that can be members of the chat simultaneously after
joining the chat via this invite link ; 1 - 99999
: type member_limit : : obj : ` int `
: param pending_join_request_count : Optional . Number of pending join requests created using this link
: type pending_join_request_count : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatInviteLink `
"""
2021-06-17 21:28:53 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
obj [ ' creator ' ] = User . de_json ( obj [ ' creator ' ] )
return cls ( * * obj )
2021-11-05 21:22:03 +03:00
def __init__ ( self , invite_link , creator , creates_join_request , is_primary , is_revoked ,
name = None , expire_date = None , member_limit = None , pending_join_request_count = None , * * kwargs ) :
2021-06-17 21:28:53 +03:00
self . invite_link : str = invite_link
self . creator : User = creator
2021-11-05 21:22:03 +03:00
self . creates_join_request : bool = creates_join_request
2021-06-17 21:28:53 +03:00
self . is_primary : bool = is_primary
self . is_revoked : bool = is_revoked
2021-11-05 21:22:03 +03:00
self . name : str = name
2021-06-17 21:28:53 +03:00
self . expire_date : int = expire_date
self . member_limit : int = member_limit
2021-11-05 21:22:03 +03:00
self . pending_join_request_count : int = pending_join_request_count
2021-06-17 21:28:53 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
def to_dict ( self ) :
2021-08-18 23:27:28 +03:00
json_dict = {
2021-06-17 21:28:53 +03:00
" invite_link " : self . invite_link ,
" creator " : self . creator . to_dict ( ) ,
" is_primary " : self . is_primary ,
2021-11-05 21:22:03 +03:00
" is_revoked " : self . is_revoked ,
" creates_join_request " : self . creates_join_request
2021-06-21 18:39:13 +03:00
}
2021-08-18 23:27:28 +03:00
if self . expire_date :
json_dict [ " expire_date " ] = self . expire_date
if self . member_limit :
json_dict [ " member_limit " ] = self . member_limit
2021-11-05 21:22:03 +03:00
if self . pending_join_request_count :
json_dict [ " pending_join_request_count " ] = self . pending_join_request_count
if self . name :
json_dict [ " name " ] = self . name
2021-08-18 23:27:28 +03:00
return json_dict
2021-06-21 18:39:13 +03:00
class ProximityAlertTriggered ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents the content of a service message , sent whenever a user in the chat triggers a proximity alert set by another user .
Telegram Documentation : https : / / core . telegram . org / bots / api #proximityalerttriggered
: param traveler : User that triggered the alert
: type traveler : : class : ` telebot . types . User `
: param watcher : User that set the alert
: type watcher : : class : ` telebot . types . User `
: param distance : The distance between the users
: type distance : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . ProximityAlertTriggered `
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-06-21 18:39:13 +03:00
return cls ( * * obj )
def __init__ ( self , traveler , watcher , distance , * * kwargs ) :
self . traveler : User = traveler
self . watcher : User = watcher
self . distance : int = distance
2022-04-23 15:03:54 +03:00
class VideoChatStarted ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a service message about a video chat started in the chat . Currently holds no information .
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
return cls ( )
def __init__ ( self ) :
pass
2022-04-23 15:03:54 +03:00
class VoiceChatStarted ( VideoChatStarted ) :
2022-07-26 14:16:35 +03:00
"""
Deprecated , use : class : ` VideoChatStarted ` instead .
"""
2022-04-23 15:03:54 +03:00
def __init__ ( self ) :
logger . warning ( ' VoiceChatStarted is deprecated. Use VideoChatStarted instead. ' )
super ( ) . __init__ ( )
2021-08-18 23:27:28 +03:00
2022-04-23 15:03:54 +03:00
class VideoChatScheduled ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a service message about a video chat scheduled in the chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #videochatscheduled
: param start_date : Point in time ( Unix timestamp ) when the video chat is supposed to be started by a chat
administrator
: type start_date : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . VideoChatScheduled `
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-08-18 18:47:38 +03:00
return cls ( * * obj )
2021-06-21 18:39:13 +03:00
2021-08-18 18:47:38 +03:00
def __init__ ( self , start_date , * * kwargs ) :
2021-06-21 18:39:13 +03:00
self . start_date : int = start_date
2022-04-23 15:03:54 +03:00
class VoiceChatScheduled ( VideoChatScheduled ) :
2022-07-26 14:16:35 +03:00
"""
Deprecated , use : class : ` VideoChatScheduled ` instead .
"""
2022-04-23 15:03:54 +03:00
def __init__ ( self , * args , * * kwargs ) :
logger . warning ( ' VoiceChatScheduled is deprecated. Use VideoChatScheduled instead. ' )
super ( ) . __init__ ( * args , * * kwargs )
2021-06-21 18:39:13 +03:00
2022-04-23 15:03:54 +03:00
class VideoChatEnded ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a service message about a video chat ended in the chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #videochatended
: param duration : Video chat duration in seconds
: type duration : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . VideoChatEnded `
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-08-18 18:47:38 +03:00
return cls ( * * obj )
2021-06-21 18:39:13 +03:00
2021-08-18 18:47:38 +03:00
def __init__ ( self , duration , * * kwargs ) :
2021-06-21 18:39:13 +03:00
self . duration : int = duration
2022-04-23 15:03:54 +03:00
class VoiceChatEnded ( VideoChatEnded ) :
2022-07-26 14:16:35 +03:00
"""
Deprecated , use : class : ` VideoChatEnded ` instead .
"""
2022-04-23 15:03:54 +03:00
def __init__ ( self , * args , * * kwargs ) :
logger . warning ( ' VoiceChatEnded is deprecated. Use VideoChatEnded instead. ' )
super ( ) . __init__ ( * args , * * kwargs )
2021-06-21 18:39:13 +03:00
2022-04-23 15:03:54 +03:00
class VideoChatParticipantsInvited ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a service message about new members invited to a video chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #videochatparticipantsinvited
: param users : New members that were invited to the video chat
: type users : : obj : ` list ` of : class : ` telebot . types . User `
: return : Instance of the class
: rtype : : class : ` telebot . types . VideoChatParticipantsInvited `
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
if ' users ' in obj :
2021-08-18 18:47:38 +03:00
obj [ ' users ' ] = [ User . de_json ( u ) for u in obj [ ' users ' ] ]
return cls ( * * obj )
2021-06-21 18:39:13 +03:00
2021-08-18 18:47:38 +03:00
def __init__ ( self , users = None , * * kwargs ) :
2021-06-21 18:39:13 +03:00
self . users : List [ User ] = users
2022-04-23 15:03:54 +03:00
class VoiceChatParticipantsInvited ( VideoChatParticipantsInvited ) :
2022-07-26 14:16:35 +03:00
"""
Deprecated , use : class : ` VideoChatParticipantsInvited ` instead .
"""
2022-04-23 15:03:54 +03:00
def __init__ ( self , * args , * * kwargs ) :
logger . warning ( ' VoiceChatParticipantsInvited is deprecated. Use VideoChatParticipantsInvited instead. ' )
super ( ) . __init__ ( * args , * * kwargs )
2021-06-21 18:39:13 +03:00
class MessageAutoDeleteTimerChanged ( JsonDeserializable ) :
2022-07-26 14:16:35 +03:00
"""
This object represents a service message about a change in auto - delete timer settings .
Telegram Documentation : https : / / core . telegram . org / bots / api #messageautodeletetimerchanged
: param message_auto_delete_time : New auto - delete time for messages in the chat ; in seconds
: type message_auto_delete_time : : obj : ` int `
: return : Instance of the class
: rtype : : class : ` telebot . types . MessageAutoDeleteTimerChanged `
"""
2021-06-21 18:39:13 +03:00
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
2021-07-08 09:35:48 +03:00
obj = cls . check_json ( json_string , dict_copy = False )
2021-08-18 18:47:38 +03:00
return cls ( * * obj )
2021-06-21 18:39:13 +03:00
2021-08-18 18:47:38 +03:00
def __init__ ( self , message_auto_delete_time , * * kwargs ) :
2021-06-21 18:39:13 +03:00
self . message_auto_delete_time = message_auto_delete_time
2022-04-17 14:39:09 +03:00
2022-07-26 14:27:15 +03:00
class MenuButton ( JsonDeserializable , JsonSerializable , Dictionaryable ) :
2022-04-17 14:39:09 +03:00
"""
2022-07-26 14:16:35 +03:00
This object describes the bot ' s menu button in a private chat. It should be one of
* : class : ` MenuButtonCommands `
* : class : ` MenuButtonWebApp `
* : class : ` MenuButtonDefault `
If a menu button other than MenuButtonDefault is set for a private chat , then it is applied
in the chat . Otherwise the default menu button is applied . By default , the menu button opens the list of bot commands .
2022-04-17 14:39:09 +03:00
"""
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
map = {
' commands ' : MenuButtonCommands ,
' web_app ' : MenuButtonWebApp ,
' default ' : MenuButtonDefault
}
return map [ obj [ ' type ' ] ] ( * * obj )
def to_json ( self ) :
2022-07-26 14:27:15 +03:00
"""
: meta private :
"""
raise NotImplementedError
def to_dict ( self ) :
"""
: meta private :
"""
2022-04-17 14:39:09 +03:00
raise NotImplementedError
class MenuButtonCommands ( MenuButton ) :
2022-07-26 14:16:35 +03:00
"""
Represents a menu button , which opens the bot ' s list of commands.
Telegram Documentation : https : / / core . telegram . org / bots / api #menubuttoncommands
: param type : Type of the button , must be commands
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . MenuButtonCommands `
"""
2022-04-17 14:39:09 +03:00
def __init__ ( self , type ) :
self . type = type
def to_dict ( self ) :
return { ' type ' : self . type }
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
class MenuButtonWebApp ( MenuButton ) :
2022-07-26 14:16:35 +03:00
"""
Represents a menu button , which launches a Web App .
Telegram Documentation : https : / / core . telegram . org / bots / api #menubuttonwebapp
: param type : Type of the button , must be web_app
: type type : : obj : ` str `
: param text : Text on the button
: type text : : obj : ` str `
: param web_app : Description of the Web App that will be launched when the user presses the button . The Web App will be
able to send an arbitrary message on behalf of the user using the method answerWebAppQuery .
: type web_app : : class : ` telebot . types . WebAppInfo `
: return : Instance of the class
: rtype : : class : ` telebot . types . MenuButtonWebApp `
"""
2022-04-17 14:39:09 +03:00
def __init__ ( self , type , text , web_app ) :
self . type : str = type
self . text : str = text
self . web_app : WebAppInfo = web_app
def to_dict ( self ) :
return { ' type ' : self . type , ' text ' : self . text , ' web_app ' : self . web_app . to_dict ( ) }
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
class MenuButtonDefault ( MenuButton ) :
2022-07-26 14:16:35 +03:00
"""
Describes that no specific value for the menu button was set .
2022-04-17 14:39:09 +03:00
2022-07-26 14:16:35 +03:00
Telegram Documentation : https : / / core . telegram . org / bots / api #menubuttondefault
: param type : Type of the button , must be default
: type type : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . MenuButtonDefault `
"""
2022-04-17 14:39:09 +03:00
def __init__ ( self , type ) :
self . type : str = type
def to_dict ( self ) :
return { ' type ' : self . type }
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
2022-07-26 14:27:15 +03:00
class ChatAdministratorRights ( JsonDeserializable , JsonSerializable , Dictionaryable ) :
2022-04-17 14:39:09 +03:00
"""
2022-07-26 14:16:35 +03:00
Represents the rights of an administrator in a chat .
Telegram Documentation : https : / / core . telegram . org / bots / api #chatadministratorrights
: param is_anonymous : True , if the user ' s presence in the chat is hidden
: type is_anonymous : : obj : ` bool `
: param can_manage_chat : True , if the administrator can access the chat event log , chat statistics , message
statistics in channels , see channel members , see anonymous administrators in supergroups and ignore slow mode .
Implied by any other administrator privilege
: type can_manage_chat : : obj : ` bool `
: param can_delete_messages : True , if the administrator can delete messages of other users
: type can_delete_messages : : obj : ` bool `
: param can_manage_video_chats : True , if the administrator can manage video chats
: type can_manage_video_chats : : obj : ` bool `
: param can_restrict_members : True , if the administrator can restrict , ban or unban chat members
: type can_restrict_members : : obj : ` bool `
: param can_promote_members : True , if the administrator can add new administrators with a subset of their own
privileges or demote administrators that he has promoted , directly or indirectly ( promoted by administrators that
were appointed by the user )
: type can_promote_members : : obj : ` bool `
: param can_change_info : True , if the user is allowed to change the chat title , photo and other settings
: type can_change_info : : obj : ` bool `
: param can_invite_users : True , if the user is allowed to invite new users to the chat
: type can_invite_users : : obj : ` bool `
: param can_post_messages : Optional . True , if the administrator can post in the channel ; channels only
: type can_post_messages : : obj : ` bool `
: param can_edit_messages : Optional . True , if the administrator can edit messages of other users and can pin
messages ; channels only
: type can_edit_messages : : obj : ` bool `
: param can_pin_messages : Optional . True , if the user is allowed to pin messages ; groups and supergroups only
: type can_pin_messages : : obj : ` bool `
2022-11-06 14:00:20 +03:00
: param can_manage_topics : Optional . True , if the user is allowed to create , rename , close , and reopen forum topics ; supergroups only
: type can_manage_topics : : obj : ` bool `
2022-07-26 14:16:35 +03:00
: return : Instance of the class
: rtype : : class : ` telebot . types . ChatAdministratorRights `
2022-04-17 14:39:09 +03:00
"""
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
return cls ( * * obj )
def __init__ ( self , is_anonymous : bool , can_manage_chat : bool ,
can_delete_messages : bool , can_manage_video_chats : bool , can_restrict_members : bool ,
can_promote_members : bool , can_change_info : bool , can_invite_users : bool ,
can_post_messages : bool = None , can_edit_messages : bool = None ,
2022-11-06 14:00:20 +03:00
can_pin_messages : bool = None , can_manage_topics : bool = None ) - > None :
2022-04-17 14:39:09 +03:00
self . is_anonymous : bool = is_anonymous
self . can_manage_chat : bool = can_manage_chat
self . can_delete_messages : bool = can_delete_messages
self . can_manage_video_chats : bool = can_manage_video_chats
self . can_restrict_members : bool = can_restrict_members
self . can_promote_members : bool = can_promote_members
self . can_change_info : bool = can_change_info
self . can_invite_users : bool = can_invite_users
self . can_post_messages : bool = can_post_messages
self . can_edit_messages : bool = can_edit_messages
self . can_pin_messages : bool = can_pin_messages
2022-11-06 14:00:20 +03:00
self . can_manage_topics : bool = can_manage_topics
2022-04-17 14:39:09 +03:00
def to_dict ( self ) :
2022-04-23 15:03:54 +03:00
json_dict = {
2022-04-17 14:39:09 +03:00
' is_anonymous ' : self . is_anonymous ,
' can_manage_chat ' : self . can_manage_chat ,
' can_delete_messages ' : self . can_delete_messages ,
' can_manage_video_chats ' : self . can_manage_video_chats ,
' can_restrict_members ' : self . can_restrict_members ,
' can_promote_members ' : self . can_promote_members ,
' can_change_info ' : self . can_change_info ,
' can_invite_users ' : self . can_invite_users ,
}
2022-04-24 23:41:08 +03:00
if self . can_post_messages is not None :
2022-04-23 15:03:54 +03:00
json_dict [ ' can_post_messages ' ] = self . can_post_messages
2022-04-24 23:41:08 +03:00
if self . can_edit_messages is not None :
2022-04-23 15:03:54 +03:00
json_dict [ ' can_edit_messages ' ] = self . can_edit_messages
2022-04-24 23:41:08 +03:00
if self . can_pin_messages is not None :
2022-04-23 15:03:54 +03:00
json_dict [ ' can_pin_messages ' ] = self . can_pin_messages
2022-11-06 14:00:20 +03:00
if self . can_manage_topics is not None :
json_dict [ ' can_manage_topics ' ] = self . can_manage_topics
2022-04-23 15:03:54 +03:00
return json_dict
2022-04-17 14:39:09 +03:00
def to_json ( self ) :
return json . dumps ( self . to_dict ( ) )
2022-08-01 10:40:43 +03:00
class InputFile :
2022-08-12 12:33:24 +03:00
"""
A class to send files through Telegram Bot API .
You need to pass a file , which should be an instance of : class : ` io . IOBase ` or
: class : ` pathlib . Path ` , or : obj : ` str ` .
If you pass an : obj : ` str ` as a file , it will be opened and closed by the class .
: param file : A file to send .
: type file : : class : ` io . IOBase ` or : class : ` pathlib . Path ` or : obj : ` str `
. . code - block : : python3
: caption : Example on sending a file using this class
from telebot . types import InputFile
# Sending a file from disk
bot . send_document (
chat_id ,
InputFile ( ' /path/to/file/file.txt ' )
)
# Sending a file from an io.IOBase object
with open ( ' /path/to/file/file.txt ' , ' rb ' ) as f :
bot . send_document (
chat_id ,
InputFile ( f )
)
# Sending a file using pathlib.Path:
bot . send_document (
chat_id ,
InputFile ( pathlib . Path ( ' /path/to/file/file.txt ' ) )
)
"""
2022-08-01 10:40:43 +03:00
def __init__ ( self , file ) - > None :
self . _file , self . file_name = self . _resolve_file ( file )
def _resolve_file ( self , file ) :
if isinstance ( file , str ) :
_file = open ( file , ' rb ' )
2022-08-12 12:33:24 +03:00
return _file , os . path . basename ( _file . name )
2022-08-01 10:40:43 +03:00
elif isinstance ( file , IOBase ) :
return file , os . path . basename ( file . name )
elif isinstance ( file , Path ) :
_file = open ( file , ' rb ' )
2022-08-12 12:33:24 +03:00
return _file , os . path . basename ( _file . name )
2022-08-01 10:40:43 +03:00
else :
raise TypeError ( " File must be a string or a file-like object(pathlib.Path, io.IOBase). " )
@property
def file ( self ) :
2022-08-12 12:33:24 +03:00
"""
File object .
"""
2022-08-01 10:40:43 +03:00
return self . _file
2022-11-06 00:04:33 +03:00
class ForumTopicCreated ( JsonDeserializable ) :
"""
This object represents a service message about a new forum topic created in the chat .
2022-11-06 14:43:16 +03:00
Telegram documentation : https : / / core . telegram . org / bots / api #forumtopiccreated
2022-11-06 00:04:33 +03:00
: param name : Name of the topic
: type name : : obj : ` str `
: param icon_color : Color of the topic icon in RGB format
: type icon_color : : obj : ` int `
: param icon_custom_emoji_id : Optional . Unique identifier of the custom emoji shown as the topic icon
: type icon_custom_emoji_id : : obj : ` str `
: return : Instance of the class
: rtype : : class : ` telebot . types . ForumTopicCreated `
"""
2022-11-06 14:14:19 +03:00
@classmethod
def de_json ( cls , json_string ) :
2022-11-06 00:04:33 +03:00
if json_string is None : return None
2022-11-06 14:14:19 +03:00
obj = cls . check_json ( json_string )
return cls ( * * obj )
2022-11-06 00:04:33 +03:00
2022-11-06 13:49:13 +03:00
def __init__ ( self , name : str , icon_color : int , icon_custom_emoji_id : Optional [ str ] = None ) - > None :
2022-11-06 00:04:33 +03:00
self . name : str = name
self . icon_color : int = icon_color
self . icon_custom_emoji_id : Optional [ str ] = icon_custom_emoji_id
class ForumTopicClosed ( JsonDeserializable ) :
2022-11-06 14:43:16 +03:00
"""
This object represents a service message about a forum topic closed in the chat . Currently holds no information .
Telegram documentation : https : / / core . telegram . org / bots / api #forumtopicclosed
"""
2022-11-06 00:04:33 +03:00
# for future use
2022-11-06 14:14:19 +03:00
@classmethod
def de_json ( cls , json_string ) :
return cls ( )
2022-11-06 00:04:33 +03:00
def __init__ ( self ) - > None :
pass
class ForumTopicReopened ( JsonDeserializable ) :
2022-11-06 14:43:16 +03:00
"""
This object represents a service message about a forum topic reopened in the chat . Currently holds no information .
Telegram documentation : https : / / core . telegram . org / bots / api #forumtopicreopened
"""
2022-11-06 00:04:33 +03:00
# for future use
2022-11-06 14:14:19 +03:00
@classmethod
def de_json ( cls , json_string ) :
return cls ( )
2022-11-06 00:04:33 +03:00
def __init__ ( self ) - > None :
pass
2022-11-06 14:14:19 +03:00
class ForumTopic ( JsonDeserializable ) :
"""
This object represents a forum topic .
2022-11-06 14:43:16 +03:00
Telegram documentation : https : / / core . telegram . org / bots / api #forumtopic
2022-11-06 14:14:19 +03:00
: param message_thread_id : Unique identifier of the forum topic
: type message_thread_id : : obj : ` int `
: param name : Name of the topic
: type name : : obj : ` str `
: param icon_color : Color of the topic icon in RGB format
: type icon_color : : obj : ` int `
: param icon_custom_emoji_id : Optional . Unique identifier of the custom emoji shown as the topic icon
: type icon_custom_emoji_id : : obj : ` str `
2022-11-06 14:43:16 +03:00
: return : Instance of the class
: rtype : : class : ` telebot . types . ForumTopic `
2022-11-06 14:14:19 +03:00
"""
@classmethod
def de_json ( cls , json_string ) :
if json_string is None : return None
obj = cls . check_json ( json_string )
return cls ( * * obj )
def __init__ ( self , message_thread_id : int , name : str , icon_color : int , icon_custom_emoji_id : Optional [ str ] = None ) - > None :
self . message_thread_id : int = message_thread_id
self . name : str = name
self . icon_color : int = icon_color
self . icon_custom_emoji_id : Optional [ str ] = icon_custom_emoji_id
2022-11-06 00:04:33 +03:00