@@ -20,6 +20,22 @@ def to_json(self):
2020 raise NotImplementedError
2121
2222
23+ class Dictionaryable :
24+ """
25+ Subclasses of this class are guaranteed to be able to be converted to dictionary.
26+ All subclasses of this class must override to_dic.
27+ """
28+
29+ def to_dic (self ):
30+ """
31+ Returns a JSON string representation of this class.
32+
33+ This function must be overridden by subclasses.
34+ :return: a JSON formatted string.
35+ """
36+ raise NotImplementedError
37+
38+
2339class JsonDeserializable :
2440 """
2541 Subclasses of this class are guaranteed to be able to be created from a json-style dict or json formatted string.
@@ -564,14 +580,14 @@ def to_json(self):
564580 return json .dumps (json_dict )
565581
566582
567- class KeyboardButton (JsonSerializable ):
583+ class KeyboardButton (Dictionaryable , JsonSerializable ):
568584 def __init__ (self , text , request_contact = None , request_location = None ):
569585 self .text = text
570586 self .request_contact = request_contact
571587 self .request_location = request_location
572588
573589 def to_json (self ):
574- return json .dumps (self .to_dic ())
590+ return json .dumps (self .to_dic ())
575591
576592 def to_dic (self ):
577593 json_dic = {'text' : self .text }
@@ -582,8 +598,7 @@ def to_dic(self):
582598 return json_dic
583599
584600
585-
586- class InlineKeyboardMarkup (JsonSerializable ):
601+ class InlineKeyboardMarkup (Dictionaryable , JsonSerializable ):
587602 def __init__ (self , row_width = 3 ):
588603 self .row_width = row_width
589604
@@ -630,7 +645,6 @@ def to_json(self):
630645 return json .dumps (json_dict )
631646
632647
633-
634648class InlineKeyboardButton (JsonSerializable ):
635649 def __init__ (self , text , url = None , callback_data = None , switch_inline_query = None ):
636650 self .text = text
@@ -651,6 +665,7 @@ def to_dic(self):
651665 json_dic ['switch_inline_quer' ] = self .switch_inline_quer
652666 return json_dic
653667
668+
654669class CallbackQuery (JsonDeserializable ):
655670 @classmethod
656671 def de_json (cls , json_type ):
@@ -701,6 +716,60 @@ def __init__(self, id, from_user, query, offset):
701716 self .offset = offset
702717
703718
719+ class InputTextMessageContent (Dictionaryable ):
720+ def __init__ (self , message_text , parse_mode = None , disable_web_page_preview = None ):
721+ self .message_text = message_text
722+ self .parse_mode = parse_mode
723+ self .disable_web_page_preview = disable_web_page_preview
724+
725+ def to_dic (self ):
726+ json_dic = {'message_text' : self .message_text }
727+ if self .parse_mode :
728+ json_dic ['parse_mode' ] = self .parse_mode
729+ if self .disable_web_page_preview :
730+ json_dic ['disable_web_page_preview' ] = self .disable_web_page_preview
731+ return json_dic
732+
733+
734+ class InputLocationMessageContent (Dictionaryable ):
735+ def __init__ (self , latitude , longitude ):
736+ self .latitude = latitude
737+ self .longitude = longitude
738+
739+ def to_dic (self ):
740+ json_dic = {'latitude' : self .latitudet , 'longitude' : self .longitude }
741+ return json_dic
742+
743+
744+ class InputVenueMessageContent (Dictionaryable ):
745+ def __init__ (self , latitude , longitude , title , address , foursquare_id = None ):
746+ self .latitude = latitude
747+ self .longitude = longitude
748+ self .title = title
749+ self .address = address
750+ self .foursquare_id = foursquare_id
751+
752+ def to_dic (self ):
753+ json_dic = {'latitude' : self .latitude , 'longitude' : self .longitude , 'title' : self .title ,
754+ 'address' : self .address }
755+ if self .foursquare_id :
756+ json_dic ['foursquare_id' ] = self .foursquare_id
757+ return json_dic
758+
759+
760+ class InputContactMessageContent (Dictionaryable ):
761+ def __init__ (self , phone_number , first_name , last_name = None ):
762+ self .phone_number = phone_number
763+ self .first_name = first_name
764+ self .last_name = last_name
765+
766+ def to_dic (self ):
767+ json_dic = {'phone_numbe' : self .phone_number , 'first_name' : self .first_name }
768+ if self .last_name :
769+ json_dic ['last_name' ] = self .last_name
770+ return json_dic
771+
772+
704773class ChosenInlineResult (JsonDeserializable ):
705774 @classmethod
706775 def de_json (cls , json_type ):
@@ -719,9 +788,6 @@ def __init__(self, result_id, from_user, query):
719788 :param query: String The query that was used to obtain the result.
720789 :return: ChosenInlineResult Object.
721790 """
722- self .result_id = result_id
723- self .from_user = from_user
724- self .query = query
725791
726792
727793class InlineQueryResultArticle (JsonSerializable ):
@@ -975,4 +1041,3 @@ def to_json(self):
9751041 if self .description :
9761042 json_dict ['description' ] = self .description
9771043 return json .dumps (json_dict )
978-
0 commit comments