django-telegram-bot-api 0.1.2__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-telegram-bot-api
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A typed Telegram Bot API client for Django
5
5
  Author: reza
6
6
  Author-email: reza <rza.karampour@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "django-telegram-bot-api"
3
- version = "0.1.2"
3
+ version = "0.1.4"
4
4
  description = "A typed Telegram Bot API client for Django"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import logging
2
3
  import os
3
4
  from io import BufferedReader
4
5
  from typing import Any, Dict, List, cast
@@ -23,6 +24,7 @@ from django_telegram.telegram_models import (
23
24
  ChatMember,
24
25
  ChatMemberAdapter,
25
26
  ChatPermissions,
27
+ ChatShareThemeBackdrops,
26
28
  EphemeralMessageParameters,
27
29
  File,
28
30
  ForumTopic,
@@ -81,6 +83,26 @@ from django_telegram.telegram_models import (
81
83
 
82
84
  from .conf import conf
83
85
 
86
+ logger = logging.getLogger(__name__)
87
+
88
+
89
+ def _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters):
90
+ if chat_id is not None:
91
+ return
92
+
93
+ if ephemeral_message_parameters is None:
94
+ raise TypeError(
95
+ "chat_id is required unless ephemeral_message_parameters is given"
96
+ )
97
+
98
+ if ephemeral_message_parameters.callback_query_id is None:
99
+ raise TypeError(
100
+ "without chat_id, ephemeral_message_parameters must include callback_query_id"
101
+ )
102
+
103
+ if ephemeral_message_parameters.receiver_user_id is not None:
104
+ raise TypeError("without chat_id, receiver_user_id must not be set")
105
+
84
106
 
85
107
  class Telegram:
86
108
  """
@@ -112,7 +134,6 @@ class Telegram:
112
134
  def __new__(cls, *args, **kwargs):
113
135
  if cls._instance is None:
114
136
  cls._instance = super().__new__(cls)
115
-
116
137
  return cls._instance
117
138
 
118
139
  def _validate_config(self, token, webhook_url):
@@ -144,7 +165,7 @@ class Telegram:
144
165
  """
145
166
  Send HTTP request to Telegram Bot API.
146
167
  """
147
- url = self.BASE_URL.format(self.token, method_name)
168
+ url = f"{self.webhook}/bot{self.token}/{method_name}"
148
169
  params = self._clean_dict(params)
149
170
  data = self._clean_dict(data)
150
171
  response = None
@@ -262,15 +283,15 @@ class Telegram:
262
283
 
263
284
  def send_message(
264
285
  self,
265
- chat_id: int | str,
286
+ chat_id: int | str | None,
266
287
  text: str,
267
288
  business_connection_id: str | None = None,
268
289
  message_thread_id: int | None = None,
269
290
  direct_messages_topic_id: int | None = None,
270
291
  ephemeral_message_parameters: EphemeralMessageParameters | None = None,
271
- parse_mode: str | None = None,
292
+ parse_mode: str | None = "html",
272
293
  entities: List[MessageEntity] | None = None,
273
- link_preview_options: LinkPreviewOptions | None = None,
294
+ link_preview_options: LinkPreviewOptions | None = LinkPreviewOptions(),
274
295
  disable_notification: bool | None = None,
275
296
  protect_content: bool | None = None,
276
297
  allow_paid_broadcast: bool | None = None,
@@ -287,8 +308,10 @@ class Telegram:
287
308
  text: Text of the message to be sent, 1-4096 characters after entities parsing.
288
309
  parse_mode: Mode for parsing entities in the message text. ("html" or "MarkdownV2").
289
310
 
290
- See full parameters here: [sendMessage](https://core.telegram.org/bots/api#sendmessage)
311
+ See full parameters here: [sendMessage](https://core.telegram.org/bots/api#sendMessage)
291
312
  """
313
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
314
+
292
315
  payload = {
293
316
  "chat_id": chat_id,
294
317
  "text": text,
@@ -474,7 +497,7 @@ class Telegram:
474
497
 
475
498
  def send_photo(
476
499
  self,
477
- chat_id: int | str,
500
+ chat_id: int | str | None,
478
501
  photo: str | InputFile,
479
502
  business_connection_id: str | None = None,
480
503
  message_thread_id: int | None = None,
@@ -508,6 +531,8 @@ class Telegram:
508
531
 
509
532
  See full parameters here: [sendPhoto](https://core.telegram.org/bots/api#sendphoto)
510
533
  """
534
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
535
+
511
536
  payload = {
512
537
  "chat_id": chat_id,
513
538
  "business_connection_id": business_connection_id,
@@ -535,7 +560,7 @@ class Telegram:
535
560
 
536
561
  def send_live_photo(
537
562
  self,
538
- chat_id: int | str,
563
+ chat_id: int | str | None,
539
564
  live_photo: InputFile | str,
540
565
  photo: InputFile | str,
541
566
  business_connection_id: str | None = None,
@@ -574,6 +599,8 @@ class Telegram:
574
599
 
575
600
  See full parameters here: [sendLivePhoto](https://core.telegram.org/bots/api#sendlivephoto)
576
601
  """
602
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
603
+
577
604
  payload = {
578
605
  "business_connection_id": business_connection_id,
579
606
  "chat_id": chat_id,
@@ -602,7 +629,7 @@ class Telegram:
602
629
 
603
630
  def send_audio(
604
631
  self,
605
- chat_id: int | str,
632
+ chat_id: int | str | None,
606
633
  audio: str | InputFile,
607
634
  business_connection_id: str | None = None,
608
635
  message_thread_id: int | None = None,
@@ -636,6 +663,8 @@ class Telegram:
636
663
 
637
664
  See full parameters here: [sendAudio](https://core.telegram.org/bots/api#sendaudio)
638
665
  """
666
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
667
+
639
668
  payload = {
640
669
  "chat_id": chat_id,
641
670
  "business_connection_id": business_connection_id,
@@ -664,7 +693,7 @@ class Telegram:
664
693
 
665
694
  def send_document(
666
695
  self,
667
- chat_id: int | str,
696
+ chat_id: int | str | None,
668
697
  document: str | InputFile,
669
698
  business_connection_id: str | None = None,
670
699
  message_thread_id: int | None = None,
@@ -694,6 +723,8 @@ class Telegram:
694
723
 
695
724
  See full parameters here: [sendDocument](https://core.telegram.org/bots/api#senddocument)
696
725
  """
726
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
727
+
697
728
  payload = {
698
729
  "chat_id": chat_id,
699
730
  "business_connection_id": business_connection_id,
@@ -722,7 +753,7 @@ class Telegram:
722
753
 
723
754
  def send_video(
724
755
  self,
725
- chat_id: int | str,
756
+ chat_id: int | str | None,
726
757
  video: str | InputFile,
727
758
  business_connection_id: str | None = None,
728
759
  message_thread_id: int | None = None,
@@ -759,6 +790,8 @@ class Telegram:
759
790
 
760
791
  See full parameters here: [sendVideo](https://core.telegram.org/bots/api#sendvideo)
761
792
  """
793
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
794
+
762
795
  payload = {
763
796
  "chat_id": chat_id,
764
797
  "business_connection_id": business_connection_id,
@@ -793,7 +826,7 @@ class Telegram:
793
826
 
794
827
  def send_animation(
795
828
  self,
796
- chat_id: int | str,
829
+ chat_id: int | str | None,
797
830
  animation: str | InputFile,
798
831
  business_connection_id: str | None = None,
799
832
  message_thread_id: int | None = None,
@@ -827,6 +860,8 @@ class Telegram:
827
860
 
828
861
  See full parameters here: [sendAnimation](https://core.telegram.org/bots/api#sendanimation)
829
862
  """
863
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
864
+
830
865
  payload = {
831
866
  "chat_id": chat_id,
832
867
  "business_connection_id": business_connection_id,
@@ -859,7 +894,7 @@ class Telegram:
859
894
 
860
895
  def send_voice(
861
896
  self,
862
- chat_id: int | str,
897
+ chat_id: int | str | None,
863
898
  voice: str | InputFile,
864
899
  business_connection_id: str | None = None,
865
900
  message_thread_id: int | None = None,
@@ -888,6 +923,8 @@ class Telegram:
888
923
 
889
924
  See full parameters here: [sendVoice](https://core.telegram.org/bots/api#sendvoice)
890
925
  """
926
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
927
+
891
928
  payload = {
892
929
  "chat_id": chat_id,
893
930
  "business_connection_id": business_connection_id,
@@ -914,7 +951,7 @@ class Telegram:
914
951
 
915
952
  def send_video_note(
916
953
  self,
917
- chat_id: int | str,
954
+ chat_id: int | str | None,
918
955
  video_note: str | InputFile,
919
956
  business_connection_id: str | None = None,
920
957
  message_thread_id: int | None = None,
@@ -942,6 +979,8 @@ class Telegram:
942
979
 
943
980
  See full parameters here: [sendVideoNote](https://core.telegram.org/bots/api#sendvideonote)
944
981
  """
982
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
983
+
945
984
  payload = {
946
985
  "chat_id": chat_id,
947
986
  "business_connection_id": business_connection_id,
@@ -966,6 +1005,115 @@ class Telegram:
966
1005
  )
967
1006
  return Message.model_validate(response)
968
1007
 
1008
+ def send_widget(
1009
+ self,
1010
+ chat_id: int | str,
1011
+ html: str,
1012
+ width: int | None = None,
1013
+ height: int | None = None,
1014
+ public_data: str | None = None,
1015
+ chat_data: str | None | None = None,
1016
+ caption: str | None = None,
1017
+ is_shared: bool | None = None,
1018
+ parse_mode: str | None = None,
1019
+ message_thread_id: int | None = None,
1020
+ caption_entities: List[MessageEntity] | None = None,
1021
+ show_caption_above_media: bool | None = None,
1022
+ allow_queries: bool | None = None,
1023
+ disable_notification: bool | None = None,
1024
+ protect_content: bool | None = None,
1025
+ allow_paid_broadcast: bool | None = None,
1026
+ message_effect_id: str | None = None,
1027
+ reply_parameters: ReplyParameters | None = None,
1028
+ reply_markup: ReplyMarkup | None = None,
1029
+ ) -> Message:
1030
+ """
1031
+ send a message with an HTML widget.
1032
+ Currently, in the production environment, widgets can be sent only to private chats,
1033
+ and sent widgets automatically have protected content and therefore can't be forwarded.
1034
+ On success, the sent Message is returned.
1035
+
1036
+ Args:
1037
+ chat_id: Unique identifier for the target chat or username (e.g. @channelusername).
1038
+ html: HTML code of the widget, 1-32768 bytes. The code must not exceed 4096 bytes when compressed by zlib with the maximum compression level.
1039
+ width: Width of the widget in logical pixels; omit if the widget must occupy the whole width of the message bubble. The width is clamped by the app to the range from 200 to the maximum width of the message bubble.
1040
+ height: Height of the widget in logical pixels; omit if the height of the widget isn't fixed. The height is clamped by the app to the range 50-600.
1041
+
1042
+ See full parameters here: [sendVideoNote](https://core.telegram.org/bots/api#sendWidget)
1043
+ """
1044
+ payload = {
1045
+ "chat_id": chat_id,
1046
+ "html": html,
1047
+ "width": width,
1048
+ "height": height,
1049
+ "message_thread_id": message_thread_id,
1050
+ "public_data": public_data,
1051
+ "chat_data": chat_data,
1052
+ "caption": caption,
1053
+ "parse_mode": parse_mode,
1054
+ "caption_entities": caption_entities,
1055
+ "show_caption_above_media": show_caption_above_media,
1056
+ "allow_queries": allow_queries,
1057
+ "is_shared": is_shared,
1058
+ "disable_notification": disable_notification,
1059
+ "protect_content": protect_content,
1060
+ "allow_paid_broadcast": allow_paid_broadcast,
1061
+ "message_effect_id": message_effect_id,
1062
+ "reply_parameters": reply_parameters,
1063
+ "reply_markup": reply_markup,
1064
+ }
1065
+ response = self._make_request("sendWidget", method="POST", data=payload)
1066
+ return Message.model_validate(response)
1067
+
1068
+ def send_shared_widget(
1069
+ self,
1070
+ chat_id: int | str,
1071
+ widget_id: str,
1072
+ chat_data: str | None | None = None,
1073
+ caption: str | None = None,
1074
+ parse_mode: str | None = None,
1075
+ message_thread_id: int | None = None,
1076
+ caption_entities: List[MessageEntity] | None = None,
1077
+ show_caption_above_media: bool | None = None,
1078
+ disable_notification: bool | None = None,
1079
+ protect_content: bool | None = None,
1080
+ allow_paid_broadcast: bool | None = None,
1081
+ message_effect_id: str | None = None,
1082
+ reply_parameters: ReplyParameters | None = None,
1083
+ reply_markup: ReplyMarkup | None = None,
1084
+ ) -> Message:
1085
+ """
1086
+ send again a shared widget created by the bot.
1087
+ Currently, in the production environment, widgets can be sent only to private chats,
1088
+ and sent widgets automatically have protected content and therefore can't be forwarded.
1089
+ On success, the sent Message is returned.
1090
+
1091
+ Args:
1092
+ chat_id: Unique identifier for the target chat or username (e.g. @channelusername).
1093
+ widget_id: Unique identifier of the shared widget
1094
+ chat_data: Data of the widget, which is specific to the message, 0-1024 bytes
1095
+
1096
+ See full parameters here: [sendSharedWidget](https://core.telegram.org/bots/api#sendSharedWidget)
1097
+ """
1098
+ payload = {
1099
+ "chat_id": chat_id,
1100
+ "widget_id": widget_id,
1101
+ "chat_data": chat_data,
1102
+ "caption": caption,
1103
+ "parse_mode": parse_mode,
1104
+ "message_thread_id": message_thread_id,
1105
+ "caption_entities": caption_entities,
1106
+ "show_caption_above_media": show_caption_above_media,
1107
+ "disable_notification": disable_notification,
1108
+ "protect_content": protect_content,
1109
+ "allow_paid_broadcast": allow_paid_broadcast,
1110
+ "message_effect_id": message_effect_id,
1111
+ "reply_parameters": reply_parameters,
1112
+ "reply_markup": reply_markup,
1113
+ }
1114
+ response = self._make_request("sendSharedWidget", method="POST", data=payload)
1115
+ return Message.model_validate(response)
1116
+
969
1117
  def send_paid_media(
970
1118
  self,
971
1119
  chat_id: int | str,
@@ -1057,7 +1205,7 @@ class Telegram:
1057
1205
 
1058
1206
  def send_location(
1059
1207
  self,
1060
- chat_id: int | str,
1208
+ chat_id: int | str | None,
1061
1209
  latitude: float,
1062
1210
  longitude: float,
1063
1211
  business_connection_id: str | None = None,
@@ -1086,6 +1234,8 @@ class Telegram:
1086
1234
 
1087
1235
  See full parameters here: [sendLocation](https://core.telegram.org/bots/api#sendlocation)
1088
1236
  """
1237
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
1238
+
1089
1239
  payload = {
1090
1240
  "chat_id": chat_id,
1091
1241
  "business_connection_id": business_connection_id,
@@ -1111,7 +1261,7 @@ class Telegram:
1111
1261
 
1112
1262
  def send_venue(
1113
1263
  self,
1114
- chat_id: int | str,
1264
+ chat_id: int | str | None,
1115
1265
  latitude: float,
1116
1266
  longitude: float,
1117
1267
  title: str,
@@ -1144,6 +1294,8 @@ class Telegram:
1144
1294
 
1145
1295
  See full parameters here: [sendVenue](https://core.telegram.org/bots/api#sendvenue)
1146
1296
  """
1297
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
1298
+
1147
1299
  payload = {
1148
1300
  "chat_id": chat_id,
1149
1301
  "business_connection_id": business_connection_id,
@@ -1171,7 +1323,7 @@ class Telegram:
1171
1323
 
1172
1324
  def send_contact(
1173
1325
  self,
1174
- chat_id: int | str,
1326
+ chat_id: int | str | None,
1175
1327
  phone_number: str,
1176
1328
  first_name: str,
1177
1329
  business_connection_id: str | None = None,
@@ -1198,6 +1350,8 @@ class Telegram:
1198
1350
 
1199
1351
  See full parameters here: [sendContact](https://core.telegram.org/bots/api#sendcontact)
1200
1352
  """
1353
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
1354
+
1201
1355
  payload = {
1202
1356
  "chat_id": chat_id,
1203
1357
  "business_connection_id": business_connection_id,
@@ -1308,9 +1462,9 @@ class Telegram:
1308
1462
 
1309
1463
  def send_checklist(
1310
1464
  self,
1311
- business_connection_id: str,
1312
1465
  chat_id: int,
1313
1466
  checklist: InputChecklist,
1467
+ business_connection_id: str,
1314
1468
  disable_notification: bool | None = None,
1315
1469
  protect_content: bool | None = None,
1316
1470
  message_effect_id: str | None = None,
@@ -2242,6 +2396,20 @@ class Telegram:
2242
2396
  response = self._make_request("getChatMember", method="GET", params=payload)
2243
2397
  return ChatMemberAdapter.validate_python(response)
2244
2398
 
2399
+ def get_chat_share_theme_backdrops(self) -> ChatShareThemeBackdrops:
2400
+ """
2401
+ Use this method to get the list of backdrops,
2402
+ which can be used as the background of a theme of the screen for
2403
+ sharing a link to a user or a chat.
2404
+ Requires no parameters.
2405
+
2406
+ Args:
2407
+ user_id: Unique identifier for the target chat or @username of the supergroup/channel.
2408
+ limit: The maximum number of messages to return; 1-20.
2409
+ """
2410
+ response = self._make_request("getUserPersonalChatMessages", method="GET")
2411
+ return ChatShareThemeBackdrops.model_validate(response)
2412
+
2245
2413
  def get_user_personal_chat_messages(
2246
2414
  self, user_id: int, limit: int
2247
2415
  ) -> List[Message]:
@@ -2548,6 +2716,25 @@ class Telegram:
2548
2716
  )
2549
2717
  return bool(response)
2550
2718
 
2719
+ def answer_widget_query(
2720
+ self, widget_query_id: str, data: str | None = None
2721
+ ) -> bool:
2722
+ """
2723
+ Send an answer to a query from a widget.
2724
+ The query must be answered within 15 seconds.
2725
+ The answer is received only by the widget that sent the query and doesn't change data of the widget;
2726
+ use editMessageWidgetData or editSharedWidgetData to change it.
2727
+ On success, True is returned.
2728
+
2729
+ Args:
2730
+ widget_query_id: Unique identifier for the query to be answered.
2731
+ data: Data to be returned to the widget, 0-1024 bytes.
2732
+ """
2733
+ payload = {"widget_query_id": widget_query_id, "data": data}
2734
+
2735
+ response = self._make_request("answerWidgetQuery", method="POST", data=payload)
2736
+ return bool(response)
2737
+
2551
2738
  def answer_guest_query(
2552
2739
  self, guest_query_id: str, result: InlineQueryResult
2553
2740
  ) -> SentGuestMessage:
@@ -2981,7 +3168,13 @@ class Telegram:
2981
3168
  )
2982
3169
  return bool(response)
2983
3170
 
2984
- def verify_user(self, user_id: int, custom_description: str | None = None) -> bool:
3171
+ def verify_user(
3172
+ self,
3173
+ user_id: int,
3174
+ custom_description: str | None = None,
3175
+ custom_description_parse_mode: str | None = None,
3176
+ custom_description_entities: List[MessageEntity] | None = None,
3177
+ ) -> bool:
2985
3178
  """
2986
3179
  Verify a user on behalf of the organization represented by the bot.
2987
3180
 
@@ -2993,12 +3186,18 @@ class Telegram:
2993
3186
  payload = {
2994
3187
  "user_id": user_id,
2995
3188
  "custom_description": custom_description,
3189
+ "custom_description_parse_mode": custom_description_parse_mode,
3190
+ "custom_description_entities": custom_description_entities,
2996
3191
  }
2997
3192
  response = self._make_request("verifyUser", method="POST", data=payload)
2998
3193
  return bool(response)
2999
3194
 
3000
3195
  def verify_chat(
3001
- self, chat_id: int | str, custom_description: str | None = None
3196
+ self,
3197
+ chat_id: int | str,
3198
+ custom_description: str | None = None,
3199
+ custom_description_parse_mode: str | None = None,
3200
+ custom_description_entities: List[MessageEntity] | None = None,
3002
3201
  ) -> bool:
3003
3202
  """
3004
3203
  Verify a chat (e.g., channel) on behalf of the organization represented by the bot.
@@ -3012,6 +3211,8 @@ class Telegram:
3012
3211
  payload = {
3013
3212
  "chat_id": chat_id,
3014
3213
  "custom_description": custom_description,
3214
+ "custom_description_parse_mode": custom_description_parse_mode,
3215
+ "custom_description_entities": custom_description_entities,
3015
3216
  }
3016
3217
  response = self._make_request("verifyChat", method="POST", data=payload)
3017
3218
  return bool(response)
@@ -3088,8 +3289,8 @@ class Telegram:
3088
3289
 
3089
3290
  def set_business_account_name(
3090
3291
  self,
3091
- business_connection_id: str,
3092
3292
  first_name: str,
3293
+ business_connection_id: str,
3093
3294
  last_name: str | None = None,
3094
3295
  ) -> bool:
3095
3296
  """
@@ -3153,8 +3354,8 @@ class Telegram:
3153
3354
 
3154
3355
  def set_business_account_profile_photo(
3155
3356
  self,
3156
- business_connection_id: str,
3157
3357
  photo: InputProfilePhoto,
3358
+ business_connection_id: str,
3158
3359
  is_public: bool | None = None,
3159
3360
  ) -> bool:
3160
3361
  """
@@ -3204,9 +3405,9 @@ class Telegram:
3204
3405
 
3205
3406
  def set_business_account_gift_settings(
3206
3407
  self,
3207
- business_connection_id: str,
3208
3408
  show_gift_button: bool,
3209
3409
  accepted_gift_types: AcceptedGiftTypes,
3410
+ business_connection_id: str,
3210
3411
  ) -> bool:
3211
3412
  """
3212
3413
  Change the privacy settings for incoming gifts in a managed business account.
@@ -3373,6 +3574,17 @@ class Telegram:
3373
3574
  response = self._make_request("getChatGifts", method="GET", params=payload)
3374
3575
  return OwnedGiftAdapter.validate_python(response)
3375
3576
 
3577
+ def get_unique_gift(self, name: str | int) -> OwnedGift:
3578
+ """
3579
+ Use this method to get information about a unique gift by its name.
3580
+
3581
+ Args:
3582
+ name: Use this method to get information about a unique gift by its name.
3583
+ """
3584
+ payload = {"name": name}
3585
+ response = self._make_request("getUniqueGift", method="GET", params=payload)
3586
+ return OwnedGiftAdapter.validate_python(response)
3587
+
3376
3588
  def convert_gift_to_stars(
3377
3589
  self, business_connection_id: str, owned_gift_id: str
3378
3590
  ) -> bool:
@@ -3393,8 +3605,8 @@ class Telegram:
3393
3605
 
3394
3606
  def upgrade_gift(
3395
3607
  self,
3396
- business_connection_id: str,
3397
3608
  owned_gift_id: str,
3609
+ business_connection_id: str,
3398
3610
  keep_original_details: bool | None = None,
3399
3611
  star_count: int | None = None,
3400
3612
  ) -> bool:
@@ -3420,9 +3632,9 @@ class Telegram:
3420
3632
 
3421
3633
  def transfer_gift(
3422
3634
  self,
3423
- business_connection_id: str,
3424
3635
  owned_gift_id: str,
3425
3636
  new_owner_chat_id: int,
3637
+ business_connection_id: str,
3426
3638
  star_count: int | None = None,
3427
3639
  ) -> bool:
3428
3640
  """
@@ -3447,11 +3659,37 @@ class Telegram:
3447
3659
  response = self._make_request("transferGift", method="POST", data=payload)
3448
3660
  return bool(response)
3449
3661
 
3450
- def post_story(
3662
+ def delete_business_account_Gift(
3451
3663
  self,
3664
+ owned_gift_id: str,
3452
3665
  business_connection_id: str,
3666
+ star_count: int | None = None,
3667
+ ) -> bool:
3668
+ """
3669
+ Deletes a regular gift owned by a managed business account without receiving Telegram Stars for it.
3670
+ Requires the can_convert_gifts_to_stars business bot right.
3671
+ The gift can be deleted only if it isn't limited (the field total_count of the Gift is omitted)
3672
+ and wasn't refunded
3673
+
3674
+ Args:
3675
+ business_connection_id: Unique identifier of the business connection.
3676
+ owned_gift_id: Unique identifier of the regular gift that should be transferred.
3677
+ """
3678
+ payload = {
3679
+ "business_connection_id": business_connection_id,
3680
+ "owned_gift_id": owned_gift_id,
3681
+ "star_count": star_count,
3682
+ }
3683
+ response = self._make_request(
3684
+ "deleteBusinessAccountGift", method="POST", data=payload
3685
+ )
3686
+ return bool(response)
3687
+
3688
+ def post_story(
3689
+ self,
3453
3690
  content: InputStoryContent,
3454
3691
  active_period: int,
3692
+ business_connection_id: str,
3455
3693
  caption: str | None = None,
3456
3694
  parse_mode: str | None = "html",
3457
3695
  caption_entities: List[MessageEntity] | None = None,
@@ -3487,10 +3725,10 @@ class Telegram:
3487
3725
 
3488
3726
  def repost_story(
3489
3727
  self,
3490
- business_connection_id: str,
3491
3728
  from_chat_id: int,
3492
3729
  from_story_id: int,
3493
3730
  active_period: int,
3731
+ business_connection_id: str,
3494
3732
  post_to_chat_page: bool | None = None,
3495
3733
  protect_content: bool | None = None,
3496
3734
  ) -> Story:
@@ -3520,9 +3758,9 @@ class Telegram:
3520
3758
 
3521
3759
  def edit_story(
3522
3760
  self,
3523
- business_connection_id: str,
3524
3761
  story_id: int,
3525
3762
  content: InputStoryContent,
3763
+ business_connection_id: str,
3526
3764
  caption: str | None = None,
3527
3765
  parse_mode: str | None = "html",
3528
3766
  caption_entities: List[MessageEntity] | None = None,
@@ -3633,14 +3871,14 @@ class Telegram:
3633
3871
 
3634
3872
  def edit_message_text(
3635
3873
  self,
3636
- text: str | None = None,
3637
- business_connection_id: str | None = None,
3638
3874
  chat_id: int | str | None = None,
3639
3875
  message_id: int | None = None,
3876
+ text: str | None = None,
3640
3877
  inline_message_id: str | None = None,
3878
+ business_connection_id: str | None = None,
3641
3879
  parse_mode: str | None = "html",
3642
3880
  entities: List[MessageEntity] | None = None,
3643
- link_preview_options: LinkPreviewOptions | None = None,
3881
+ link_preview_options: LinkPreviewOptions | None = LinkPreviewOptions(),
3644
3882
  rich_message: InputRichMessage | None = None,
3645
3883
  reply_markup: InlineKeyboardMarkup | None = None,
3646
3884
  ) -> Message | bool:
@@ -3665,10 +3903,10 @@ class Telegram:
3665
3903
  )
3666
3904
 
3667
3905
  payload = {
3668
- "business_connection_id": business_connection_id,
3669
3906
  "chat_id": chat_id,
3670
3907
  "message_id": message_id,
3671
3908
  "inline_message_id": inline_message_id,
3909
+ "business_connection_id": business_connection_id,
3672
3910
  "text": text,
3673
3911
  "parse_mode": parse_mode,
3674
3912
  "entities": entities,
@@ -3684,10 +3922,10 @@ class Telegram:
3684
3922
 
3685
3923
  def edit_message_caption(
3686
3924
  self,
3687
- business_connection_id: str | None = None,
3688
3925
  chat_id: int | str | None = None,
3689
3926
  message_id: int | None = None,
3690
3927
  inline_message_id: str | None = None,
3928
+ business_connection_id: str | None = None,
3691
3929
  caption: str | None = None,
3692
3930
  parse_mode: str | None = "html",
3693
3931
  caption_entities: List[MessageEntity] | None = None,
@@ -3715,8 +3953,8 @@ class Telegram:
3715
3953
  )
3716
3954
 
3717
3955
  payload = {
3718
- "business_connection_id": business_connection_id,
3719
3956
  "chat_id": chat_id,
3957
+ "business_connection_id": business_connection_id,
3720
3958
  "message_id": message_id,
3721
3959
  "inline_message_id": inline_message_id,
3722
3960
  "caption": caption,
@@ -3734,9 +3972,9 @@ class Telegram:
3734
3972
  def edit_message_media(
3735
3973
  self,
3736
3974
  media: InputMedia,
3737
- business_connection_id: str | None = None,
3738
3975
  chat_id: int | str | None = None,
3739
3976
  message_id: int | None = None,
3977
+ business_connection_id: str | None = None,
3740
3978
  inline_message_id: str | None = None,
3741
3979
  reply_markup: InlineKeyboardMarkup | None = None,
3742
3980
  ) -> Message | bool:
@@ -3779,9 +4017,9 @@ class Telegram:
3779
4017
  self,
3780
4018
  latitude: float,
3781
4019
  longitude: float,
3782
- business_connection_id: str | None = None,
3783
4020
  chat_id: int | str | None = None,
3784
4021
  message_id: int | None = None,
4022
+ business_connection_id: str | None = None,
3785
4023
  inline_message_id: str | None = None,
3786
4024
  live_period: int | None = None,
3787
4025
  horizontal_accuracy: float | None = None,
@@ -3832,9 +4070,9 @@ class Telegram:
3832
4070
 
3833
4071
  def stop_message_live_location(
3834
4072
  self,
3835
- business_connection_id: str | None = None,
3836
4073
  chat_id: int | str | None = None,
3837
4074
  message_id: int | None = None,
4075
+ business_connection_id: str | None = None,
3838
4076
  inline_message_id: str | None = None,
3839
4077
  reply_markup: InlineKeyboardMarkup | None = None,
3840
4078
  ) -> Message | bool:
@@ -3870,9 +4108,9 @@ class Telegram:
3870
4108
 
3871
4109
  def edit_message_checklist(
3872
4110
  self,
3873
- business_connection_id: str,
3874
4111
  chat_id: int,
3875
4112
  message_id: int,
4113
+ business_connection_id: str,
3876
4114
  checklist: InputChecklist,
3877
4115
  reply_markup: InlineKeyboardMarkup | None = None,
3878
4116
  ) -> Message | bool:
@@ -3901,13 +4139,78 @@ class Telegram:
3901
4139
 
3902
4140
  return Message.model_validate(response)
3903
4141
 
4142
+ def edit_message_widgetData(
4143
+ self,
4144
+ chat_id: int | None = None,
4145
+ message_id: int | None = None,
4146
+ inline_message_id: str | None = None,
4147
+ public_data: str | None = None,
4148
+ chat_data: str | None = None,
4149
+ ) -> Message | bool:
4150
+ """
4151
+ Edit a checklist on behalf of a connected business account.
4152
+ Edit data of a widget in a message sent by the bot or via the bot (for inline bots).
4153
+ Public data of a shared widget can be changed at most once per second.
4154
+ On success, True is returned.
4155
+
4156
+ Args:
4157
+ chat_id: Chat ID or @username of the target chat/bot.
4158
+ public_data: New public data of the widget, 0-1024 bytes; pass an empty string to remove the public data. If omitted, then the public data isn't changed.
4159
+ chat_data: New data of the widget, which is specific to the message, 0-1024 bytes; pass an empty string to remove the data. If omitted, then the data isn't changed.
4160
+
4161
+ See full parameters here: [editMessageWidgetData](https://core.telegram.org/bots/api#editMessageWidgetData)
4162
+ """
4163
+ payload = {
4164
+ "chat_id": chat_id,
4165
+ "message_id": message_id,
4166
+ "inline_message_id": inline_message_id,
4167
+ "public_data": public_data,
4168
+ "chat_data": chat_data,
4169
+ }
4170
+ response = self._make_request(
4171
+ "editMessageWidgetData", method="POST", data=payload
4172
+ )
4173
+ if isinstance(response, bool):
4174
+ return bool(response)
4175
+
4176
+ return Message.model_validate(response)
4177
+
4178
+ def edit_shared_widget_data(
4179
+ self,
4180
+ widget_id: str,
4181
+ public_data: str,
4182
+ cache_time: str | None = None,
4183
+ ) -> Message | bool:
4184
+ """
4185
+ Use this method to edit public data of a shared widget created by the bot.
4186
+ A shared widget can be edited at most once per second.
4187
+ On success, True is returned.
4188
+
4189
+ Args:
4190
+ chat_id: Chat ID or @username of the target chat/bot.
4191
+ public_data: New public data of the widget, 0-1024 bytes; pass an empty string to remove the public data. If omitted, then the public data isn't changed.
4192
+ chat_data: New data of the widget, which is specific to the message, 0-1024 bytes; pass an empty string to remove the data. If omitted, then the data isn't changed.
4193
+ """
4194
+ payload = {
4195
+ "widget_id": widget_id,
4196
+ "public_data": public_data,
4197
+ "cache_time": cache_time,
4198
+ }
4199
+ response = self._make_request(
4200
+ "editSharedWidgetData", method="POST", data=payload
4201
+ )
4202
+ if isinstance(response, bool):
4203
+ return bool(response)
4204
+
4205
+ return Message.model_validate(response)
4206
+
3904
4207
  def edit_message_reply_markup(
3905
4208
  self,
3906
- business_connection_id: str | None = None,
3907
4209
  chat_id: int | str | None = None,
3908
4210
  message_id: int | None = None,
3909
4211
  inline_message_id: str | None = None,
3910
4212
  reply_markup: InlineKeyboardMarkup | None = None,
4213
+ business_connection_id: str | None = None,
3911
4214
  ) -> Message | bool:
3912
4215
  """
3913
4216
  Edit only the reply markup (inline keyboard) of a message.
@@ -3974,7 +4277,7 @@ class Telegram:
3974
4277
  parse_mode: str | None = "html",
3975
4278
  entities: List[MessageEntity] | None = None,
3976
4279
  rich_message: InputRichMessage | None = None,
3977
- link_preview_options: LinkPreviewOptions | None = None,
4280
+ link_preview_options: LinkPreviewOptions | None = LinkPreviewOptions(),
3978
4281
  reply_markup: InlineKeyboardMarkup | None = None,
3979
4282
  ) -> bool:
3980
4283
  """
@@ -4269,7 +4572,7 @@ class Telegram:
4269
4572
 
4270
4573
  def send_sticker(
4271
4574
  self,
4272
- chat_id: int | str,
4575
+ chat_id: int | str | None,
4273
4576
  sticker: InputFile | str,
4274
4577
  business_connection_id: str | None = None,
4275
4578
  message_thread_id: int | None = None,
@@ -4299,6 +4602,8 @@ class Telegram:
4299
4602
 
4300
4603
  - See full parameters here: [sendSticker](https://core.telegram.org/bots/api#sendsticker)
4301
4604
  """
4605
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
4606
+
4302
4607
  payload = {
4303
4608
  "chat_id": chat_id,
4304
4609
  "business_connection_id": business_connection_id,
@@ -4636,7 +4941,7 @@ class Telegram:
4636
4941
 
4637
4942
  def send_rich_message(
4638
4943
  self,
4639
- chat_id: int | str,
4944
+ chat_id: int | str | None,
4640
4945
  rich_message: InputRichMessage,
4641
4946
  message_thread_id: int | None = None,
4642
4947
  business_connection_id: str | None = None,
@@ -4660,6 +4965,8 @@ class Telegram:
4660
4965
 
4661
4966
  See full parameters here: [sendRichMessage](https://core.telegram.org/bots/api#sendrichmessage)
4662
4967
  """
4968
+ _validate_chat_id_or_ephemeral_reply(chat_id, ephemeral_message_parameters)
4969
+
4663
4970
  payload = {
4664
4971
  "chat_id": chat_id,
4665
4972
  "rich_message": rich_message,
@@ -37,6 +37,8 @@ class Update(_BaseModel):
37
37
  inline_query: InlineQuery | None = None
38
38
  chosen_inline_result: ChosenInlineResult | None = None
39
39
  callback_query: CallbackQuery | None = None
40
+ widget_query: WidgetQuery | None = None
41
+ shared_widget_query: SharedWidgetQuery | None = None
40
42
  shipping_query: ShippingQuery | None = None
41
43
  pre_checkout_query: PreCheckoutQuery | None = None
42
44
  purchased_paid_media: PaidMediaPurchased | None = None
@@ -75,7 +77,7 @@ class User(_BaseModel):
75
77
 
76
78
  class Chat(_BaseModel):
77
79
  id: int
78
- type: str
80
+ type: Literal["private", "group", "supergroup", "channel"]
79
81
  title: str | None = None
80
82
  username: str | None = None
81
83
  first_name: str | None = None
@@ -86,7 +88,7 @@ class Chat(_BaseModel):
86
88
 
87
89
  class ChatFullInfo(_BaseModel):
88
90
  id: int
89
- type: str
91
+ type: Literal["private", "group", "supergroup", "channel"]
90
92
  title: str | None = None
91
93
  username: str | None = None
92
94
  first_name: str | None = None
@@ -138,6 +140,8 @@ class ChatFullInfo(_BaseModel):
138
140
  paid_message_star_count: int | None = None
139
141
  guard_bot: User | None = None
140
142
  community: Community | None = None
143
+ ton_wallet_card: TonWalletCard | None = None
144
+ share_theme: ChatShareTheme | None = None
141
145
 
142
146
 
143
147
  class Message(_BaseModel):
@@ -193,6 +197,7 @@ class Message(_BaseModel):
193
197
  video: Video | None = None
194
198
  video_note: VideoNote | None = None
195
199
  voice: Voice | None = None
200
+ widget: Widget | None = None
196
201
  caption: str | None = None
197
202
  caption_entities: List[MessageEntity] | None = None
198
203
  show_caption_above_media: bool | None = None
@@ -250,6 +255,7 @@ class Message(_BaseModel):
250
255
  giveaway_completed: GiveawayCompleted | None = None
251
256
  managed_bot_created: ManagedBotCreated | None = None
252
257
  paid_message_price_changed: PaidMessagePriceChanged | None = None
258
+ paid_messages_waived: PaidMessagesWaived | None = None
253
259
  poll_option_added: PollOptionAdded | None = None
254
260
  poll_option_deleted: PollOptionDeleted | None = None
255
261
  suggested_post_approved: SuggestedPostApproved | None = None
@@ -257,6 +263,7 @@ class Message(_BaseModel):
257
263
  suggested_post_declined: SuggestedPostDeclined | None = None
258
264
  suggested_post_paid: SuggestedPostPaid | None = None
259
265
  suggested_post_refunded: SuggestedPostRefunded | None = None
266
+ ton_wallet_transfer: TonWalletTransfer | None = None
260
267
  video_chat_scheduled: VideoChatScheduled | None = None
261
268
  video_chat_started: VideoChatStarted | None = None
262
269
  video_chat_ended: VideoChatEnded | None = None
@@ -301,7 +308,30 @@ class InaccessibleMessage(_BaseModel):
301
308
 
302
309
 
303
310
  class MessageEntity(_BaseModel):
304
- type: str
311
+ type: Literal[
312
+ "mention",
313
+ "hashtag",
314
+ "cashtag",
315
+ "bot_command",
316
+ "url",
317
+ "email",
318
+ "phone_number",
319
+ "bank_card_number",
320
+ "ton_address",
321
+ "bold",
322
+ "italic",
323
+ "underline",
324
+ "strikethrough",
325
+ "spoiler",
326
+ "blockquote",
327
+ "expandable_blockquote",
328
+ "code",
329
+ "pre",
330
+ "text_link",
331
+ "text_mention",
332
+ "custom_emoji",
333
+ "date_time",
334
+ ]
305
335
  offset: int
306
336
  length: int
307
337
  url: str | None = None
@@ -314,6 +344,7 @@ class MessageEntity(_BaseModel):
314
344
  class TextQuote(_BaseModel):
315
345
  text: str
316
346
  entities: List[MessageEntity] | None = None
347
+ rich_texts: List[RichText] | None = None
317
348
  position: int
318
349
  is_manual: bool
319
350
 
@@ -334,6 +365,7 @@ class ExternalReplyInfo(_BaseModel):
334
365
  video: Video | None = None
335
366
  video_note: VideoNote | None = None
336
367
  voice: Voice | None = None
368
+ widget: Widget | None = None
337
369
  has_media_spoiler: bool | None = None
338
370
  checklist: Checklist | None = None
339
371
  contact: Contact | None = None
@@ -355,6 +387,7 @@ class ReplyParameters(_BaseModel):
355
387
  quote: str | None = None
356
388
  quote_parse_mode: str | None = None
357
389
  quote_entities: List[MessageEntity] | None = None
390
+ quote_rich_texts: List[RichText] | None = None
358
391
  quote_position: int | None = None
359
392
  checklist_task_id: int | None = None
360
393
  poll_option_id: str | None = None
@@ -370,10 +403,19 @@ class ReplyParameters(_BaseModel):
370
403
 
371
404
 
372
405
  class EphemeralMessageParameters(_BaseModel):
373
- receiver_user_id: int
406
+ receiver_user_id: int | None = None
374
407
  callback_query_id: str | None = None
375
408
  replace_callback_query_message: bool | None = None
376
409
 
410
+ @model_validator(mode="after")
411
+ def _check_target(self):
412
+ if self.receiver_user_id is None and self.callback_query_id is None:
413
+ raise ValueError(
414
+ "Either receiver_user_id or callback_query_id must be specified"
415
+ )
416
+
417
+ return self
418
+
377
419
 
378
420
  class MessageOriginUser(_BaseModel):
379
421
  type: Literal["user"] = "user"
@@ -509,7 +551,7 @@ class File(_BaseModel):
509
551
  class Sticker(_BaseModel):
510
552
  file_id: str
511
553
  file_unique_id: str
512
- type: str # regular | mask | custom_emoji
554
+ type: Literal["regular", "mask", "custom_emoji"]
513
555
  width: int
514
556
  height: int
515
557
  is_animated: bool
@@ -527,7 +569,7 @@ class Sticker(_BaseModel):
527
569
  class StickerSet(_BaseModel):
528
570
  name: str
529
571
  title: str
530
- sticker_type: str # "regular", "mask", "custom_emoji"
572
+ sticker_type: Literal["regular", "mask", "custom_emoji"]
531
573
  stickers: List[Sticker]
532
574
  thumbnail: PhotoSize | None = None
533
575
 
@@ -710,6 +752,12 @@ class RichTextBankCardNumber(_BaseModel):
710
752
  bank_card_number: str
711
753
 
712
754
 
755
+ class RichTextTonAddress(_BaseModel):
756
+ type: str = "ton_address"
757
+ text: RichText
758
+ bank_card_number: str
759
+
760
+
713
761
  class RichTextMention(_BaseModel):
714
762
  type: str = "mention"
715
763
  text: RichText
@@ -1090,6 +1138,15 @@ class Voice(_BaseModel):
1090
1138
  file_size: int | None = None
1091
1139
 
1092
1140
 
1141
+ class Widget(_BaseModel):
1142
+ id: str | None = None
1143
+ width: int | None = None
1144
+ hight: int | None = None
1145
+ html: str | None = None
1146
+ public_data: str | None = None
1147
+ chat_data: int | None = None
1148
+
1149
+
1093
1150
  class PaidMedia(_BaseModel):
1094
1151
  type: str
1095
1152
 
@@ -1185,7 +1242,7 @@ class Poll(_BaseModel):
1185
1242
  total_voter_count: int
1186
1243
  is_closed: bool
1187
1244
  is_anonymous: bool
1188
- type: str
1245
+ type: Literal["regular", "quiz"]
1189
1246
  allows_multiple_answers: bool
1190
1247
  members_only: bool
1191
1248
  country_codes: list[str] | None = None
@@ -1494,7 +1551,7 @@ class GiveawayCompleted(_BaseModel):
1494
1551
 
1495
1552
 
1496
1553
  class LinkPreviewOptions(_BaseModel):
1497
- is_disabled: bool | None = None
1554
+ is_disabled: bool | None = True
1498
1555
  url: str | None = None
1499
1556
  prefer_small_media: bool | None = None
1500
1557
  prefer_large_media: bool | None = None
@@ -1852,7 +1909,9 @@ class InlineQuery(_BaseModel):
1852
1909
  from_user: User = Field(..., alias="from")
1853
1910
  query: str
1854
1911
  offset: str
1855
- chat_type: str | None = None
1912
+ chat_type: Literal["sender", "private", "group", "supergroup", "channel"] | None = (
1913
+ None
1914
+ )
1856
1915
  location: Location | None = None
1857
1916
 
1858
1917
 
@@ -2200,6 +2259,54 @@ class CallbackQuery(_BaseModel):
2200
2259
  game_short_name: str | None = None
2201
2260
 
2202
2261
 
2262
+ class WidgetQueryTypeData(_BaseModel):
2263
+ type: str = "data"
2264
+ wallet_card: TonWalletCard | None
2265
+
2266
+
2267
+ class WidgetQueryTypeSignData(_BaseModel):
2268
+ type: str = "sign_data"
2269
+ wallet: WidgetQueryWallet
2270
+ sign_data: str
2271
+
2272
+
2273
+ class WidgetQueryTypeSentTransaction(_BaseModel):
2274
+ type: str = "sent_transaction"
2275
+ wallet: WidgetQueryWallet
2276
+ msg_hash: str
2277
+
2278
+
2279
+ class WidgetQueryWallet(_BaseModel):
2280
+ address: str
2281
+ amount: str
2282
+ public_key: str | None = None
2283
+ state_init: str | None = None
2284
+
2285
+
2286
+ class WidgetQuery(_BaseModel):
2287
+ id: str
2288
+ type: WidgetQueryType
2289
+ data: str
2290
+ chat_instance: str
2291
+ from_user: User = Field(..., alias="from")
2292
+ chat: Chat | None = None
2293
+ message_id: int | None = None
2294
+ inline_message_id: str | None = None
2295
+ chat_type: Literal["sender", "private", "group", "supergroup", "channel"] | None = (
2296
+ None
2297
+ )
2298
+
2299
+ widget_id: str | None = None
2300
+
2301
+
2302
+ class SharedWidgetQuery(_BaseModel):
2303
+ id: str
2304
+ from_user: User = Field(..., alias="from")
2305
+ type: WidgetQueryType
2306
+ data: str
2307
+ widget_id: str
2308
+
2309
+
2203
2310
  class ForceReply(_BaseModel):
2204
2311
  force_reply: bool
2205
2312
  input_field_placeholder: str | None = None
@@ -2240,7 +2347,7 @@ class UserRating(_BaseModel):
2240
2347
  next_level_rating: int | None = None
2241
2348
 
2242
2349
 
2243
- class StoryAreaPosition(_BaseModel):
2350
+ class AreaPosition(_BaseModel):
2244
2351
  x_percentage: float
2245
2352
  y_percentage: float
2246
2353
  width_percentage: float
@@ -2249,6 +2356,64 @@ class StoryAreaPosition(_BaseModel):
2249
2356
  corner_radius_percentage: float
2250
2357
 
2251
2358
 
2359
+ class TonNft(_BaseModel):
2360
+ address: str
2361
+ index: str
2362
+ name: str
2363
+ description: str
2364
+ collection_address: str
2365
+ attributes: List[TonNftAttribute] | None = None
2366
+ gift: UniqueGift | None = None
2367
+
2368
+
2369
+ class TonNftAttribute(_BaseModel):
2370
+ trait_type: str
2371
+ value: str
2372
+
2373
+
2374
+ class TonWalletCardSticker(_BaseModel):
2375
+ position: AreaPosition
2376
+ nft: TonNft
2377
+
2378
+
2379
+ class TonWalletCard(_BaseModel):
2380
+ address: str
2381
+ amount: str
2382
+ stickers: List[TonWalletCardSticker]
2383
+ background_nft_address: str | None = None
2384
+
2385
+
2386
+ class EmojiTypeEmoji(_BaseModel):
2387
+ type: str = "emoji"
2388
+ emoji: str
2389
+
2390
+
2391
+ class EmojiTypeCustomEmoji(_BaseModel):
2392
+ type: str = "custom_emoji"
2393
+ custom_emoji_id: str
2394
+
2395
+
2396
+ class ChatShareThemeEmoji(_BaseModel):
2397
+ type: str = "emoji"
2398
+ emojis: List[EmojiType]
2399
+ background_backdrop_id: int | None = None
2400
+
2401
+
2402
+ class ChatShareThemeUniqueGift(_BaseModel):
2403
+ type: str = "unique_gift"
2404
+ gift: UniqueGift
2405
+
2406
+
2407
+ class ChatShareThemeBackdrops(_BaseModel):
2408
+ id: int
2409
+ name: str
2410
+ colors: UniqueGiftBackdropColors
2411
+
2412
+
2413
+ class ChatShareThemeBackdrop(_BaseModel):
2414
+ backdrops: List[ChatShareThemeBackdrop]
2415
+
2416
+
2252
2417
  class LocationAddress(_BaseModel):
2253
2418
  country_code: str
2254
2419
  state: str | None = None
@@ -2307,7 +2472,7 @@ class StoryAreaTypeUniqueGift(_BaseModel):
2307
2472
 
2308
2473
 
2309
2474
  class StoryArea(_BaseModel):
2310
- position: StoryAreaPosition
2475
+ position: AreaPosition
2311
2476
  type: StoryAreaType
2312
2477
 
2313
2478
 
@@ -2366,7 +2531,9 @@ class UniqueGiftModel(_BaseModel):
2366
2531
  name: str
2367
2532
  sticker: Sticker
2368
2533
  rarity_per_mille: int
2369
- rarity: str # Currently, can be "uncommon", "rare", "epic", or "legendary".
2534
+ rarity: Literal[
2535
+ "uncommon", "rare", "epic", "legendary"
2536
+ ] # Currently, can be "uncommon", "rare", "epic", or "legendary".
2370
2537
 
2371
2538
 
2372
2539
  class UniqueGiftSymbol(_BaseModel):
@@ -2964,7 +3131,13 @@ class AffiliateInfo(_BaseModel):
2964
3131
 
2965
3132
  class TransactionPartnerUser(_BaseModel):
2966
3133
  type: Literal["user"] = "user"
2967
- transaction_type: str # "invoice_payment", "paid_media_payment", "gift_purchase", "premium_purchase", "business_account_transfer"
3134
+ transaction_type: Literal[
3135
+ "invoice_payment",
3136
+ "paid_media_payment",
3137
+ "gift_purchase",
3138
+ "premium_purchase",
3139
+ "business_account_transfer",
3140
+ ]
2968
3141
  user: User
2969
3142
  affiliate: AffiliateInfo | None = None
2970
3143
  invoice_payload: str | None = None
@@ -3030,7 +3203,7 @@ class SuggestedPostPrice(_BaseModel):
3030
3203
 
3031
3204
 
3032
3205
  class SuggestedPostInfo(_BaseModel):
3033
- state: str
3206
+ state: Literal["pending", "approved", "declined"]
3034
3207
  price: SuggestedPostPrice | None = None
3035
3208
  send_date: int | None = None
3036
3209
 
@@ -3068,6 +3241,17 @@ class SuggestedPostRefunded(_BaseModel):
3068
3241
  reason: str
3069
3242
 
3070
3243
 
3244
+ class PaidMessagesWaived(_BaseModel):
3245
+ pass
3246
+
3247
+
3248
+ class TonWalletTransfer(_BaseModel):
3249
+ transaction_id: str
3250
+ peer_address: str
3251
+ amount: str
3252
+ comment: str | None = None
3253
+
3254
+
3071
3255
  class PassportFile(_BaseModel):
3072
3256
  file_id: str
3073
3257
  file_unique_id: str
@@ -3168,6 +3352,29 @@ class InputInvoiceMessageContent(_BaseModel):
3168
3352
  return self
3169
3353
 
3170
3354
 
3355
+ class InputWidgetMessageContent(_BaseModel):
3356
+ html: str
3357
+ width: int | None = None
3358
+ height: int | None = None
3359
+ public_data: str | None = None
3360
+ chat_data: str | None = None
3361
+ caption: str | None = None
3362
+ parse_mode: str | None = None
3363
+ caption_entities: List[MessageEntity] | None = None
3364
+ show_caption_above_media: bool | None = None
3365
+ allow_queries: bool | None = None
3366
+ is_shared: bool | None = None
3367
+
3368
+
3369
+ class InputSharedWidgetMessageContent(_BaseModel):
3370
+ widget_id: str
3371
+ chat_data: str | None = None
3372
+ caption: str | None = None
3373
+ parse_mode: str | None = None
3374
+ caption_entities: List[MessageEntity] | None = None
3375
+ show_caption_above_media: bool | None = None
3376
+
3377
+
3171
3378
  # ─── Discriminated Unions ──────────────────────────────────────
3172
3379
  ChatMember = Annotated[
3173
3380
  ChatMemberOwner
@@ -3359,6 +3566,7 @@ RichText = (
3359
3566
  | RichTextEmailAddress
3360
3567
  | RichTextPhoneNumber
3361
3568
  | RichTextBankCardNumber
3569
+ | RichTextTonAddress
3362
3570
  | RichTextMention
3363
3571
  | RichTextHashtag
3364
3572
  | RichTextCashtag
@@ -3423,6 +3631,14 @@ InputRichBlock = (
3423
3631
  | InputRichBlockVoiceNote
3424
3632
  | InputRichBlockThinking
3425
3633
  )
3634
+
3635
+ WidgetQueryType = (
3636
+ WidgetQueryTypeData | WidgetQueryTypeSignData | WidgetQueryTypeSentTransaction
3637
+ )
3638
+ EmojiType = EmojiTypeEmoji | EmojiTypeCustomEmoji
3639
+
3640
+ ChatShareTheme = ChatShareThemeEmoji | ChatShareThemeUniqueGift
3641
+
3426
3642
  # ─── Type Adapters ─────────────────────────────────────────────
3427
3643
  MessageIdList = TypeAdapter(List[MessageId])
3428
3644
  StickerList = TypeAdapter(List[Sticker])