botapi-py 1.1.0__py3-none-any.whl

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.
botapi/api.py ADDED
@@ -0,0 +1,4532 @@
1
+ # This is an autogenerated file. Do not edit this file directly.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Union, Optional, List
6
+
7
+ from . import core
8
+
9
+ from .types import (
10
+ Update,
11
+ WebhookInfo,
12
+ User,
13
+ Chat,
14
+ ChatFullInfo,
15
+ Message,
16
+ MessageId,
17
+ InaccessibleMessage,
18
+ MessageEntity,
19
+ TextQuote,
20
+ ExternalReplyInfo,
21
+ ReplyParameters,
22
+ MessageOriginUser,
23
+ MessageOriginHiddenUser,
24
+ MessageOriginChat,
25
+ MessageOriginChannel,
26
+ PhotoSize,
27
+ Animation,
28
+ Audio,
29
+ Document,
30
+ Story,
31
+ Video,
32
+ VideoNote,
33
+ Voice,
34
+ PaidMediaInfo,
35
+ PaidMediaPreview,
36
+ PaidMediaPhoto,
37
+ PaidMediaVideo,
38
+ Contact,
39
+ Dice,
40
+ PollOption,
41
+ InputPollOption,
42
+ PollAnswer,
43
+ Poll,
44
+ ChecklistTask,
45
+ Checklist,
46
+ InputChecklistTask,
47
+ InputChecklist,
48
+ ChecklistTasksDone,
49
+ ChecklistTasksAdded,
50
+ Location,
51
+ Venue,
52
+ WebAppData,
53
+ ProximityAlertTriggered,
54
+ MessageAutoDeleteTimerChanged,
55
+ ChatBoostAdded,
56
+ BackgroundFillSolid,
57
+ BackgroundFillGradient,
58
+ BackgroundFillFreeformGradient,
59
+ BackgroundTypeFill,
60
+ BackgroundTypeWallpaper,
61
+ BackgroundTypePattern,
62
+ BackgroundTypeChatTheme,
63
+ ChatBackground,
64
+ ForumTopicCreated,
65
+ ForumTopicClosed,
66
+ ForumTopicEdited,
67
+ ForumTopicReopened,
68
+ GeneralForumTopicHidden,
69
+ GeneralForumTopicUnhidden,
70
+ SharedUser,
71
+ UsersShared,
72
+ ChatShared,
73
+ WriteAccessAllowed,
74
+ VideoChatScheduled,
75
+ VideoChatStarted,
76
+ VideoChatEnded,
77
+ VideoChatParticipantsInvited,
78
+ PaidMessagePriceChanged,
79
+ DirectMessagePriceChanged,
80
+ SuggestedPostApproved,
81
+ SuggestedPostApprovalFailed,
82
+ SuggestedPostDeclined,
83
+ SuggestedPostPaid,
84
+ SuggestedPostRefunded,
85
+ GiveawayCreated,
86
+ Giveaway,
87
+ GiveawayWinners,
88
+ GiveawayCompleted,
89
+ LinkPreviewOptions,
90
+ SuggestedPostPrice,
91
+ SuggestedPostInfo,
92
+ SuggestedPostParameters,
93
+ DirectMessagesTopic,
94
+ UserProfilePhotos,
95
+ File,
96
+ WebAppInfo,
97
+ ReplyKeyboardMarkup,
98
+ KeyboardButton,
99
+ KeyboardButtonRequestUsers,
100
+ KeyboardButtonRequestChat,
101
+ KeyboardButtonPollType,
102
+ ReplyKeyboardRemove,
103
+ InlineKeyboardMarkup,
104
+ InlineKeyboardButton,
105
+ LoginUrl,
106
+ SwitchInlineQueryChosenChat,
107
+ CopyTextButton,
108
+ CallbackQuery,
109
+ ForceReply,
110
+ ChatPhoto,
111
+ ChatInviteLink,
112
+ ChatAdministratorRights,
113
+ ChatMemberUpdated,
114
+ ChatMemberOwner,
115
+ ChatMemberAdministrator,
116
+ ChatMemberMember,
117
+ ChatMemberRestricted,
118
+ ChatMemberLeft,
119
+ ChatMemberBanned,
120
+ ChatJoinRequest,
121
+ ChatPermissions,
122
+ Birthdate,
123
+ BusinessIntro,
124
+ BusinessLocation,
125
+ BusinessOpeningHoursInterval,
126
+ BusinessOpeningHours,
127
+ StoryAreaPosition,
128
+ LocationAddress,
129
+ StoryAreaTypeLocation,
130
+ StoryAreaTypeSuggestedReaction,
131
+ StoryAreaTypeLink,
132
+ StoryAreaTypeWeather,
133
+ StoryAreaTypeUniqueGift,
134
+ StoryArea,
135
+ ChatLocation,
136
+ ReactionTypeEmoji,
137
+ ReactionTypeCustomEmoji,
138
+ ReactionTypePaid,
139
+ ReactionCount,
140
+ MessageReactionUpdated,
141
+ MessageReactionCountUpdated,
142
+ ForumTopic,
143
+ Gift,
144
+ Gifts,
145
+ UniqueGiftModel,
146
+ UniqueGiftSymbol,
147
+ UniqueGiftBackdropColors,
148
+ UniqueGiftBackdrop,
149
+ UniqueGift,
150
+ GiftInfo,
151
+ UniqueGiftInfo,
152
+ OwnedGiftRegular,
153
+ OwnedGiftUnique,
154
+ OwnedGifts,
155
+ AcceptedGiftTypes,
156
+ StarAmount,
157
+ BotCommand,
158
+ BotCommandScopeDefault,
159
+ BotCommandScopeAllPrivateChats,
160
+ BotCommandScopeAllGroupChats,
161
+ BotCommandScopeAllChatAdministrators,
162
+ BotCommandScopeChat,
163
+ BotCommandScopeChatAdministrators,
164
+ BotCommandScopeChatMember,
165
+ BotName,
166
+ BotDescription,
167
+ BotShortDescription,
168
+ MenuButtonCommands,
169
+ MenuButtonWebApp,
170
+ MenuButtonDefault,
171
+ ChatBoostSourcePremium,
172
+ ChatBoostSourceGiftCode,
173
+ ChatBoostSourceGiveaway,
174
+ ChatBoost,
175
+ ChatBoostUpdated,
176
+ ChatBoostRemoved,
177
+ UserChatBoosts,
178
+ BusinessBotRights,
179
+ BusinessConnection,
180
+ BusinessMessagesDeleted,
181
+ ResponseParameters,
182
+ InputMediaPhoto,
183
+ InputMediaVideo,
184
+ InputMediaAnimation,
185
+ InputMediaAudio,
186
+ InputMediaDocument,
187
+ InputFile,
188
+ InputPaidMediaPhoto,
189
+ InputPaidMediaVideo,
190
+ InputProfilePhotoStatic,
191
+ InputProfilePhotoAnimated,
192
+ InputStoryContentPhoto,
193
+ InputStoryContentVideo,
194
+ Sticker,
195
+ StickerSet,
196
+ MaskPosition,
197
+ InputSticker,
198
+ InlineQuery,
199
+ InlineQueryResultsButton,
200
+ InlineQueryResultArticle,
201
+ InlineQueryResultPhoto,
202
+ InlineQueryResultGif,
203
+ InlineQueryResultMpeg4Gif,
204
+ InlineQueryResultVideo,
205
+ InlineQueryResultAudio,
206
+ InlineQueryResultVoice,
207
+ InlineQueryResultDocument,
208
+ InlineQueryResultLocation,
209
+ InlineQueryResultVenue,
210
+ InlineQueryResultContact,
211
+ InlineQueryResultGame,
212
+ InlineQueryResultCachedPhoto,
213
+ InlineQueryResultCachedGif,
214
+ InlineQueryResultCachedMpeg4Gif,
215
+ InlineQueryResultCachedSticker,
216
+ InlineQueryResultCachedDocument,
217
+ InlineQueryResultCachedVideo,
218
+ InlineQueryResultCachedVoice,
219
+ InlineQueryResultCachedAudio,
220
+ InputTextMessageContent,
221
+ InputLocationMessageContent,
222
+ InputVenueMessageContent,
223
+ InputContactMessageContent,
224
+ InputInvoiceMessageContent,
225
+ ChosenInlineResult,
226
+ SentWebAppMessage,
227
+ PreparedInlineMessage,
228
+ LabeledPrice,
229
+ Invoice,
230
+ ShippingAddress,
231
+ OrderInfo,
232
+ ShippingOption,
233
+ SuccessfulPayment,
234
+ RefundedPayment,
235
+ ShippingQuery,
236
+ PreCheckoutQuery,
237
+ PaidMediaPurchased,
238
+ RevenueWithdrawalStatePending,
239
+ RevenueWithdrawalStateSucceeded,
240
+ RevenueWithdrawalStateFailed,
241
+ AffiliateInfo,
242
+ TransactionPartnerUser,
243
+ TransactionPartnerChat,
244
+ TransactionPartnerAffiliateProgram,
245
+ TransactionPartnerFragment,
246
+ TransactionPartnerTelegramAds,
247
+ TransactionPartnerTelegramApi,
248
+ TransactionPartnerOther,
249
+ StarTransaction,
250
+ StarTransactions,
251
+ PassportData,
252
+ PassportFile,
253
+ EncryptedPassportElement,
254
+ EncryptedCredentials,
255
+ PassportElementErrorDataField,
256
+ PassportElementErrorFrontSide,
257
+ PassportElementErrorReverseSide,
258
+ PassportElementErrorSelfie,
259
+ PassportElementErrorFile,
260
+ PassportElementErrorFiles,
261
+ PassportElementErrorTranslationFile,
262
+ PassportElementErrorTranslationFiles,
263
+ PassportElementErrorUnspecified,
264
+ Game,
265
+ CallbackGame,
266
+ GameHighScore,
267
+ MaybeInaccessibleMessage,
268
+ MaybeInaccessibleMessageAdapter,
269
+ MessageOrigin,
270
+ MessageOriginAdapter,
271
+ PaidMedia,
272
+ PaidMediaAdapter,
273
+ BackgroundFill,
274
+ BackgroundFillAdapter,
275
+ BackgroundType,
276
+ BackgroundTypeAdapter,
277
+ ChatMember,
278
+ ChatMemberAdapter,
279
+ StoryAreaType,
280
+ StoryAreaTypeAdapter,
281
+ ReactionType,
282
+ ReactionTypeAdapter,
283
+ OwnedGift,
284
+ OwnedGiftAdapter,
285
+ BotCommandScope,
286
+ BotCommandScopeAdapter,
287
+ MenuButton,
288
+ MenuButtonAdapter,
289
+ ChatBoostSource,
290
+ ChatBoostSourceAdapter,
291
+ InputMedia,
292
+ InputMediaAdapter,
293
+ InputPaidMedia,
294
+ InputPaidMediaAdapter,
295
+ InputProfilePhoto,
296
+ InputProfilePhotoAdapter,
297
+ InputStoryContent,
298
+ InputStoryContentAdapter,
299
+ InlineQueryResult,
300
+ InlineQueryResultAdapter,
301
+ InputMessageContent,
302
+ InputMessageContentAdapter,
303
+ RevenueWithdrawalState,
304
+ RevenueWithdrawalStateAdapter,
305
+ TransactionPartner,
306
+ TransactionPartnerAdapter,
307
+ PassportElementError,
308
+ PassportElementErrorAdapter,
309
+ IntAdapter,
310
+ StrAdapter,
311
+ FloatAdapter,
312
+ BoolAdapter,
313
+ )
314
+
315
+ class BotAPI(core.BaseBotAPI):
316
+ '''
317
+ Creates an instance of a new Bot API client.
318
+
319
+ _Remember to pass an existing `httpx.AsyncClient` instance
320
+ to avoid significant performance degradation in production._
321
+ '''
322
+
323
+ async def get_updates(
324
+ self,
325
+ offset: Optional[int] = None,
326
+ limit: Optional[int] = None,
327
+ timeout: Optional[int] = None,
328
+ allowed_updates: Optional[List[str]] = None,
329
+ ) -> List[Update]:
330
+ '''
331
+ Use this method to receive incoming updates using
332
+ long polling (wiki). Returns an Array of Update
333
+ objects.
334
+
335
+ Reference: https://core.telegram.org/bots/api#getupdates
336
+ '''
337
+
338
+ response = await self._send_request('getUpdates', {
339
+ 'offset': offset,
340
+ 'limit': limit,
341
+ 'timeout': timeout,
342
+ 'allowed_updates': allowed_updates,
343
+ })
344
+ return [Update.model_validate(x) for x in response]
345
+
346
+ async def set_webhook(
347
+ self,
348
+ url: str,
349
+ certificate: Optional[InputFile] = None,
350
+ ip_address: Optional[str] = None,
351
+ max_connections: Optional[int] = None,
352
+ allowed_updates: Optional[List[str]] = None,
353
+ drop_pending_updates: Optional[bool] = None,
354
+ secret_token: Optional[str] = None,
355
+ ) -> bool:
356
+ '''
357
+ Use this method to specify a URL and
358
+ receive incoming updates via an outgoing webhook. Whenever
359
+ there is an update for the bot, we
360
+ will send an HTTPS POST request to the
361
+ specified URL, containing a JSON-serialized Update. In case
362
+ of an unsuccessful request (a request with response
363
+ HTTP status code different from 2XY), we will
364
+ repeat the request and give up after a
365
+ reasonable amount of attempts. Returns True on success.
366
+
367
+ Reference: https://core.telegram.org/bots/api#setwebhook
368
+ '''
369
+
370
+ response = await self._send_request('setWebhook', {
371
+ 'url': url,
372
+ 'certificate': certificate,
373
+ 'ip_address': ip_address,
374
+ 'max_connections': max_connections,
375
+ 'allowed_updates': allowed_updates,
376
+ 'drop_pending_updates': drop_pending_updates,
377
+ 'secret_token': secret_token,
378
+ })
379
+ return BoolAdapter.validate_python(response)
380
+
381
+ async def delete_webhook(
382
+ self,
383
+ drop_pending_updates: Optional[bool] = None,
384
+ ) -> bool:
385
+ '''
386
+ Use this method to remove webhook integration if
387
+ you decide to switch back to getUpdates. Returns
388
+ True on success.
389
+
390
+ Reference: https://core.telegram.org/bots/api#deletewebhook
391
+ '''
392
+
393
+ response = await self._send_request('deleteWebhook', {
394
+ 'drop_pending_updates': drop_pending_updates,
395
+ })
396
+ return BoolAdapter.validate_python(response)
397
+
398
+ async def get_webhook_info(
399
+ self,
400
+ ) -> WebhookInfo:
401
+ '''
402
+ Use this method to get current webhook status.
403
+ Requires no parameters. On success, returns a WebhookInfo
404
+ object. If the bot is using getUpdates, will
405
+ return an object with the url field empty.
406
+
407
+ Reference: https://core.telegram.org/bots/api#getwebhookinfo
408
+ '''
409
+
410
+ response = await self._send_request('getWebhookInfo', {})
411
+ return WebhookInfo.model_validate(response)
412
+
413
+ async def get_me(
414
+ self,
415
+ ) -> User:
416
+ '''
417
+ A simple method for testing your bot's authentication
418
+ token. Requires no parameters. Returns basic information about
419
+ the bot in form of a User object.
420
+
421
+ Reference: https://core.telegram.org/bots/api#getme
422
+ '''
423
+
424
+ response = await self._send_request('getMe', {})
425
+ return User.model_validate(response)
426
+
427
+ async def log_out(
428
+ self,
429
+ ) -> bool:
430
+ '''
431
+ Use this method to log out from the
432
+ cloud Bot API server before launching the bot
433
+ locally. You must log out the bot before
434
+ running it locally, otherwise there is no guarantee
435
+ that the bot will receive updates. After a
436
+ successful call, you can immediately log in on
437
+ a local server, but will not be able
438
+ to log in back to the cloud Bot
439
+ API server for 10 minutes. Returns True on
440
+ success. Requires no parameters.
441
+
442
+ Reference: https://core.telegram.org/bots/api#logout
443
+ '''
444
+
445
+ response = await self._send_request('logOut', {})
446
+ return BoolAdapter.validate_python(response)
447
+
448
+ async def close(
449
+ self,
450
+ ) -> bool:
451
+ '''
452
+ Use this method to close the bot instance
453
+ before moving it from one local server to
454
+ another. You need to delete the webhook before
455
+ calling this method to ensure that the bot
456
+ isn't launched again after server restart. The method
457
+ will return error 429 in the first 10
458
+ minutes after the bot is launched. Returns True
459
+ on success. Requires no parameters.
460
+
461
+ Reference: https://core.telegram.org/bots/api#close
462
+ '''
463
+
464
+ response = await self._send_request('close', {})
465
+ return BoolAdapter.validate_python(response)
466
+
467
+ async def send_message(
468
+ self,
469
+ chat_id: Union[int, str],
470
+ text: str,
471
+ business_connection_id: Optional[str] = None,
472
+ message_thread_id: Optional[int] = None,
473
+ direct_messages_topic_id: Optional[int] = None,
474
+ parse_mode: Optional[str] = 'HTML',
475
+ entities: Optional[List[MessageEntity]] = None,
476
+ link_preview_options: Optional[LinkPreviewOptions] = None,
477
+ disable_notification: Optional[bool] = None,
478
+ protect_content: Optional[bool] = None,
479
+ allow_paid_broadcast: Optional[bool] = None,
480
+ message_effect_id: Optional[str] = None,
481
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
482
+ reply_parameters: Optional[ReplyParameters] = None,
483
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
484
+ ) -> Message:
485
+ '''
486
+ Use this method to send text messages. On
487
+ success, the sent Message is returned.
488
+
489
+ Reference: https://core.telegram.org/bots/api#sendmessage
490
+ '''
491
+
492
+ response = await self._send_request('sendMessage', {
493
+ 'business_connection_id': business_connection_id,
494
+ 'chat_id': chat_id,
495
+ 'message_thread_id': message_thread_id,
496
+ 'direct_messages_topic_id': direct_messages_topic_id,
497
+ 'text': text,
498
+ 'parse_mode': parse_mode if not entities else None, # FIX,
499
+ 'entities': entities,
500
+ 'link_preview_options': link_preview_options,
501
+ 'disable_notification': disable_notification,
502
+ 'protect_content': protect_content,
503
+ 'allow_paid_broadcast': allow_paid_broadcast,
504
+ 'message_effect_id': message_effect_id,
505
+ 'suggested_post_parameters': suggested_post_parameters,
506
+ 'reply_parameters': reply_parameters,
507
+ 'reply_markup': reply_markup,
508
+ })
509
+ return Message.model_validate(response)
510
+
511
+ async def forward_message(
512
+ self,
513
+ chat_id: Union[int, str],
514
+ from_chat_id: Union[int, str],
515
+ message_id: int,
516
+ message_thread_id: Optional[int] = None,
517
+ direct_messages_topic_id: Optional[int] = None,
518
+ video_start_timestamp: Optional[int] = None,
519
+ disable_notification: Optional[bool] = None,
520
+ protect_content: Optional[bool] = None,
521
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
522
+ ) -> Message:
523
+ '''
524
+ Use this method to forward messages of any
525
+ kind. Service messages and messages with protected content
526
+ can't be forwarded. On success, the sent Message
527
+ is returned.
528
+
529
+ Reference: https://core.telegram.org/bots/api#forwardmessage
530
+ '''
531
+
532
+ response = await self._send_request('forwardMessage', {
533
+ 'chat_id': chat_id,
534
+ 'message_thread_id': message_thread_id,
535
+ 'direct_messages_topic_id': direct_messages_topic_id,
536
+ 'from_chat_id': from_chat_id,
537
+ 'video_start_timestamp': video_start_timestamp,
538
+ 'disable_notification': disable_notification,
539
+ 'protect_content': protect_content,
540
+ 'suggested_post_parameters': suggested_post_parameters,
541
+ 'message_id': message_id,
542
+ })
543
+ return Message.model_validate(response)
544
+
545
+ async def forward_messages(
546
+ self,
547
+ chat_id: Union[int, str],
548
+ from_chat_id: Union[int, str],
549
+ message_ids: List[int],
550
+ message_thread_id: Optional[int] = None,
551
+ direct_messages_topic_id: Optional[int] = None,
552
+ disable_notification: Optional[bool] = None,
553
+ protect_content: Optional[bool] = None,
554
+ ) -> List[MessageId]:
555
+ '''
556
+ Use this method to forward multiple messages of
557
+ any kind. If some of the specified messages
558
+ can't be found or forwarded, they are skipped.
559
+ Service messages and messages with protected content can't
560
+ be forwarded. Album grouping is kept for forwarded
561
+ messages. On success, an array of MessageId of
562
+ the sent messages is returned.
563
+
564
+ Reference: https://core.telegram.org/bots/api#forwardmessages
565
+ '''
566
+
567
+ response = await self._send_request('forwardMessages', {
568
+ 'chat_id': chat_id,
569
+ 'message_thread_id': message_thread_id,
570
+ 'direct_messages_topic_id': direct_messages_topic_id,
571
+ 'from_chat_id': from_chat_id,
572
+ 'message_ids': message_ids,
573
+ 'disable_notification': disable_notification,
574
+ 'protect_content': protect_content,
575
+ })
576
+ return [MessageId.model_validate(x) for x in response]
577
+
578
+ async def copy_message(
579
+ self,
580
+ chat_id: Union[int, str],
581
+ from_chat_id: Union[int, str],
582
+ message_id: int,
583
+ message_thread_id: Optional[int] = None,
584
+ direct_messages_topic_id: Optional[int] = None,
585
+ video_start_timestamp: Optional[int] = None,
586
+ caption: Optional[str] = None,
587
+ parse_mode: Optional[str] = 'HTML',
588
+ caption_entities: Optional[List[MessageEntity]] = None,
589
+ show_caption_above_media: Optional[bool] = None,
590
+ disable_notification: Optional[bool] = None,
591
+ protect_content: Optional[bool] = None,
592
+ allow_paid_broadcast: Optional[bool] = None,
593
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
594
+ reply_parameters: Optional[ReplyParameters] = None,
595
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
596
+ ) -> MessageId:
597
+ '''
598
+ Use this method to copy messages of any
599
+ kind. Service messages, paid media messages, giveaway messages,
600
+ giveaway winners messages, and invoice messages can't be
601
+ copied. A quiz poll can be copied only
602
+ if the value of the field correct_option_id is
603
+ known to the bot. The method is analogous
604
+ to the method forwardMessage, but the copied message
605
+ doesn't have a link to the original message.
606
+ Returns the MessageId of the sent message on
607
+ success.
608
+
609
+ Reference: https://core.telegram.org/bots/api#copymessage
610
+ '''
611
+
612
+ response = await self._send_request('copyMessage', {
613
+ 'chat_id': chat_id,
614
+ 'message_thread_id': message_thread_id,
615
+ 'direct_messages_topic_id': direct_messages_topic_id,
616
+ 'from_chat_id': from_chat_id,
617
+ 'message_id': message_id,
618
+ 'video_start_timestamp': video_start_timestamp,
619
+ 'caption': caption,
620
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
621
+ 'caption_entities': caption_entities,
622
+ 'show_caption_above_media': show_caption_above_media,
623
+ 'disable_notification': disable_notification,
624
+ 'protect_content': protect_content,
625
+ 'allow_paid_broadcast': allow_paid_broadcast,
626
+ 'suggested_post_parameters': suggested_post_parameters,
627
+ 'reply_parameters': reply_parameters,
628
+ 'reply_markup': reply_markup,
629
+ })
630
+ return MessageId.model_validate(response)
631
+
632
+ async def copy_messages(
633
+ self,
634
+ chat_id: Union[int, str],
635
+ from_chat_id: Union[int, str],
636
+ message_ids: List[int],
637
+ message_thread_id: Optional[int] = None,
638
+ direct_messages_topic_id: Optional[int] = None,
639
+ disable_notification: Optional[bool] = None,
640
+ protect_content: Optional[bool] = None,
641
+ remove_caption: Optional[bool] = None,
642
+ ) -> List[MessageId]:
643
+ '''
644
+ Use this method to copy messages of any
645
+ kind. If some of the specified messages can't
646
+ be found or copied, they are skipped. Service
647
+ messages, paid media messages, giveaway messages, giveaway winners
648
+ messages, and invoice messages can't be copied. A
649
+ quiz poll can be copied only if the
650
+ value of the field correct_option_id is known to
651
+ the bot. The method is analogous to the
652
+ method forwardMessages, but the copied messages don't have
653
+ a link to the original message. Album grouping
654
+ is kept for copied messages. On success, an
655
+ array of MessageId of the sent messages is
656
+ returned.
657
+
658
+ Reference: https://core.telegram.org/bots/api#copymessages
659
+ '''
660
+
661
+ response = await self._send_request('copyMessages', {
662
+ 'chat_id': chat_id,
663
+ 'message_thread_id': message_thread_id,
664
+ 'direct_messages_topic_id': direct_messages_topic_id,
665
+ 'from_chat_id': from_chat_id,
666
+ 'message_ids': message_ids,
667
+ 'disable_notification': disable_notification,
668
+ 'protect_content': protect_content,
669
+ 'remove_caption': remove_caption,
670
+ })
671
+ return [MessageId.model_validate(x) for x in response]
672
+
673
+ async def send_photo(
674
+ self,
675
+ chat_id: Union[int, str],
676
+ photo: Union[InputFile, str],
677
+ business_connection_id: Optional[str] = None,
678
+ message_thread_id: Optional[int] = None,
679
+ direct_messages_topic_id: Optional[int] = None,
680
+ caption: Optional[str] = None,
681
+ parse_mode: Optional[str] = 'HTML',
682
+ caption_entities: Optional[List[MessageEntity]] = None,
683
+ show_caption_above_media: Optional[bool] = None,
684
+ has_spoiler: Optional[bool] = None,
685
+ disable_notification: Optional[bool] = None,
686
+ protect_content: Optional[bool] = None,
687
+ allow_paid_broadcast: Optional[bool] = None,
688
+ message_effect_id: Optional[str] = None,
689
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
690
+ reply_parameters: Optional[ReplyParameters] = None,
691
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
692
+ ) -> Message:
693
+ '''
694
+ Use this method to send photos. On success,
695
+ the sent Message is returned.
696
+
697
+ Reference: https://core.telegram.org/bots/api#sendphoto
698
+ '''
699
+
700
+ response = await self._send_request('sendPhoto', {
701
+ 'business_connection_id': business_connection_id,
702
+ 'chat_id': chat_id,
703
+ 'message_thread_id': message_thread_id,
704
+ 'direct_messages_topic_id': direct_messages_topic_id,
705
+ 'photo': photo,
706
+ 'caption': caption,
707
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
708
+ 'caption_entities': caption_entities,
709
+ 'show_caption_above_media': show_caption_above_media,
710
+ 'has_spoiler': has_spoiler,
711
+ 'disable_notification': disable_notification,
712
+ 'protect_content': protect_content,
713
+ 'allow_paid_broadcast': allow_paid_broadcast,
714
+ 'message_effect_id': message_effect_id,
715
+ 'suggested_post_parameters': suggested_post_parameters,
716
+ 'reply_parameters': reply_parameters,
717
+ 'reply_markup': reply_markup,
718
+ })
719
+ return Message.model_validate(response)
720
+
721
+ async def send_audio(
722
+ self,
723
+ chat_id: Union[int, str],
724
+ audio: Union[InputFile, str],
725
+ business_connection_id: Optional[str] = None,
726
+ message_thread_id: Optional[int] = None,
727
+ direct_messages_topic_id: Optional[int] = None,
728
+ caption: Optional[str] = None,
729
+ parse_mode: Optional[str] = 'HTML',
730
+ caption_entities: Optional[List[MessageEntity]] = None,
731
+ duration: Optional[int] = None,
732
+ performer: Optional[str] = None,
733
+ title: Optional[str] = None,
734
+ thumbnail: Optional[Union[InputFile, str]] = None,
735
+ disable_notification: Optional[bool] = None,
736
+ protect_content: Optional[bool] = None,
737
+ allow_paid_broadcast: Optional[bool] = None,
738
+ message_effect_id: Optional[str] = None,
739
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
740
+ reply_parameters: Optional[ReplyParameters] = None,
741
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
742
+ ) -> Message:
743
+ '''
744
+ Use this method to send audio files, if
745
+ you want Telegram clients to display them in
746
+ the music player. Your audio must be in
747
+ the .MP3 or .M4A format. On success, the
748
+ sent Message is returned. Bots can currently send
749
+ audio files of up to 50 MB in
750
+ size, this limit may be changed in the
751
+ future.
752
+
753
+ Reference: https://core.telegram.org/bots/api#sendaudio
754
+ '''
755
+
756
+ response = await self._send_request('sendAudio', {
757
+ 'business_connection_id': business_connection_id,
758
+ 'chat_id': chat_id,
759
+ 'message_thread_id': message_thread_id,
760
+ 'direct_messages_topic_id': direct_messages_topic_id,
761
+ 'audio': audio,
762
+ 'caption': caption,
763
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
764
+ 'caption_entities': caption_entities,
765
+ 'duration': duration,
766
+ 'performer': performer,
767
+ 'title': title,
768
+ 'thumbnail': thumbnail,
769
+ 'disable_notification': disable_notification,
770
+ 'protect_content': protect_content,
771
+ 'allow_paid_broadcast': allow_paid_broadcast,
772
+ 'message_effect_id': message_effect_id,
773
+ 'suggested_post_parameters': suggested_post_parameters,
774
+ 'reply_parameters': reply_parameters,
775
+ 'reply_markup': reply_markup,
776
+ })
777
+ return Message.model_validate(response)
778
+
779
+ async def send_document(
780
+ self,
781
+ chat_id: Union[int, str],
782
+ document: Union[InputFile, str],
783
+ business_connection_id: Optional[str] = None,
784
+ message_thread_id: Optional[int] = None,
785
+ direct_messages_topic_id: Optional[int] = None,
786
+ thumbnail: Optional[Union[InputFile, str]] = None,
787
+ caption: Optional[str] = None,
788
+ parse_mode: Optional[str] = 'HTML',
789
+ caption_entities: Optional[List[MessageEntity]] = None,
790
+ disable_content_type_detection: Optional[bool] = None,
791
+ disable_notification: Optional[bool] = None,
792
+ protect_content: Optional[bool] = None,
793
+ allow_paid_broadcast: Optional[bool] = None,
794
+ message_effect_id: Optional[str] = None,
795
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
796
+ reply_parameters: Optional[ReplyParameters] = None,
797
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
798
+ ) -> Message:
799
+ '''
800
+ Use this method to send general files. On
801
+ success, the sent Message is returned. Bots can
802
+ currently send files of any type of up
803
+ to 50 MB in size, this limit may
804
+ be changed in the future.
805
+
806
+ Reference: https://core.telegram.org/bots/api#senddocument
807
+ '''
808
+
809
+ response = await self._send_request('sendDocument', {
810
+ 'business_connection_id': business_connection_id,
811
+ 'chat_id': chat_id,
812
+ 'message_thread_id': message_thread_id,
813
+ 'direct_messages_topic_id': direct_messages_topic_id,
814
+ 'document': document,
815
+ 'thumbnail': thumbnail,
816
+ 'caption': caption,
817
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
818
+ 'caption_entities': caption_entities,
819
+ 'disable_content_type_detection': disable_content_type_detection,
820
+ 'disable_notification': disable_notification,
821
+ 'protect_content': protect_content,
822
+ 'allow_paid_broadcast': allow_paid_broadcast,
823
+ 'message_effect_id': message_effect_id,
824
+ 'suggested_post_parameters': suggested_post_parameters,
825
+ 'reply_parameters': reply_parameters,
826
+ 'reply_markup': reply_markup,
827
+ })
828
+ return Message.model_validate(response)
829
+
830
+ async def send_video(
831
+ self,
832
+ chat_id: Union[int, str],
833
+ video: Union[InputFile, str],
834
+ business_connection_id: Optional[str] = None,
835
+ message_thread_id: Optional[int] = None,
836
+ direct_messages_topic_id: Optional[int] = None,
837
+ duration: Optional[int] = None,
838
+ width: Optional[int] = None,
839
+ height: Optional[int] = None,
840
+ thumbnail: Optional[Union[InputFile, str]] = None,
841
+ cover: Optional[Union[InputFile, str]] = None,
842
+ start_timestamp: Optional[int] = None,
843
+ caption: Optional[str] = None,
844
+ parse_mode: Optional[str] = 'HTML',
845
+ caption_entities: Optional[List[MessageEntity]] = None,
846
+ show_caption_above_media: Optional[bool] = None,
847
+ has_spoiler: Optional[bool] = None,
848
+ supports_streaming: Optional[bool] = None,
849
+ disable_notification: Optional[bool] = None,
850
+ protect_content: Optional[bool] = None,
851
+ allow_paid_broadcast: Optional[bool] = None,
852
+ message_effect_id: Optional[str] = None,
853
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
854
+ reply_parameters: Optional[ReplyParameters] = None,
855
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
856
+ ) -> Message:
857
+ '''
858
+ Use this method to send video files, Telegram
859
+ clients support MPEG4 videos (other formats may be
860
+ sent as Document). On success, the sent Message
861
+ is returned. Bots can currently send video files
862
+ of up to 50 MB in size, this
863
+ limit may be changed in the future.
864
+
865
+ Reference: https://core.telegram.org/bots/api#sendvideo
866
+ '''
867
+
868
+ response = await self._send_request('sendVideo', {
869
+ 'business_connection_id': business_connection_id,
870
+ 'chat_id': chat_id,
871
+ 'message_thread_id': message_thread_id,
872
+ 'direct_messages_topic_id': direct_messages_topic_id,
873
+ 'video': video,
874
+ 'duration': duration,
875
+ 'width': width,
876
+ 'height': height,
877
+ 'thumbnail': thumbnail,
878
+ 'cover': cover,
879
+ 'start_timestamp': start_timestamp,
880
+ 'caption': caption,
881
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
882
+ 'caption_entities': caption_entities,
883
+ 'show_caption_above_media': show_caption_above_media,
884
+ 'has_spoiler': has_spoiler,
885
+ 'supports_streaming': supports_streaming,
886
+ 'disable_notification': disable_notification,
887
+ 'protect_content': protect_content,
888
+ 'allow_paid_broadcast': allow_paid_broadcast,
889
+ 'message_effect_id': message_effect_id,
890
+ 'suggested_post_parameters': suggested_post_parameters,
891
+ 'reply_parameters': reply_parameters,
892
+ 'reply_markup': reply_markup,
893
+ })
894
+ return Message.model_validate(response)
895
+
896
+ async def send_animation(
897
+ self,
898
+ chat_id: Union[int, str],
899
+ animation: Union[InputFile, str],
900
+ business_connection_id: Optional[str] = None,
901
+ message_thread_id: Optional[int] = None,
902
+ direct_messages_topic_id: Optional[int] = None,
903
+ duration: Optional[int] = None,
904
+ width: Optional[int] = None,
905
+ height: Optional[int] = None,
906
+ thumbnail: Optional[Union[InputFile, str]] = None,
907
+ caption: Optional[str] = None,
908
+ parse_mode: Optional[str] = 'HTML',
909
+ caption_entities: Optional[List[MessageEntity]] = None,
910
+ show_caption_above_media: Optional[bool] = None,
911
+ has_spoiler: Optional[bool] = None,
912
+ disable_notification: Optional[bool] = None,
913
+ protect_content: Optional[bool] = None,
914
+ allow_paid_broadcast: Optional[bool] = None,
915
+ message_effect_id: Optional[str] = None,
916
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
917
+ reply_parameters: Optional[ReplyParameters] = None,
918
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
919
+ ) -> Message:
920
+ '''
921
+ Use this method to send animation files (GIF
922
+ or H.264/MPEG-4 AVC video without sound). On success,
923
+ the sent Message is returned. Bots can currently
924
+ send animation files of up to 50 MB
925
+ in size, this limit may be changed in
926
+ the future.
927
+
928
+ Reference: https://core.telegram.org/bots/api#sendanimation
929
+ '''
930
+
931
+ response = await self._send_request('sendAnimation', {
932
+ 'business_connection_id': business_connection_id,
933
+ 'chat_id': chat_id,
934
+ 'message_thread_id': message_thread_id,
935
+ 'direct_messages_topic_id': direct_messages_topic_id,
936
+ 'animation': animation,
937
+ 'duration': duration,
938
+ 'width': width,
939
+ 'height': height,
940
+ 'thumbnail': thumbnail,
941
+ 'caption': caption,
942
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
943
+ 'caption_entities': caption_entities,
944
+ 'show_caption_above_media': show_caption_above_media,
945
+ 'has_spoiler': has_spoiler,
946
+ 'disable_notification': disable_notification,
947
+ 'protect_content': protect_content,
948
+ 'allow_paid_broadcast': allow_paid_broadcast,
949
+ 'message_effect_id': message_effect_id,
950
+ 'suggested_post_parameters': suggested_post_parameters,
951
+ 'reply_parameters': reply_parameters,
952
+ 'reply_markup': reply_markup,
953
+ })
954
+ return Message.model_validate(response)
955
+
956
+ async def send_voice(
957
+ self,
958
+ chat_id: Union[int, str],
959
+ voice: Union[InputFile, str],
960
+ business_connection_id: Optional[str] = None,
961
+ message_thread_id: Optional[int] = None,
962
+ direct_messages_topic_id: Optional[int] = None,
963
+ caption: Optional[str] = None,
964
+ parse_mode: Optional[str] = 'HTML',
965
+ caption_entities: Optional[List[MessageEntity]] = None,
966
+ duration: Optional[int] = None,
967
+ disable_notification: Optional[bool] = None,
968
+ protect_content: Optional[bool] = None,
969
+ allow_paid_broadcast: Optional[bool] = None,
970
+ message_effect_id: Optional[str] = None,
971
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
972
+ reply_parameters: Optional[ReplyParameters] = None,
973
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
974
+ ) -> Message:
975
+ '''
976
+ Use this method to send audio files, if
977
+ you want Telegram clients to display the file
978
+ as a playable voice message. For this to
979
+ work, your audio must be in an .OGG
980
+ file encoded with OPUS, or in .MP3 format,
981
+ or in .M4A format (other formats may be
982
+ sent as Audio or Document). On success, the
983
+ sent Message is returned. Bots can currently send
984
+ voice messages of up to 50 MB in
985
+ size, this limit may be changed in the
986
+ future.
987
+
988
+ Reference: https://core.telegram.org/bots/api#sendvoice
989
+ '''
990
+
991
+ response = await self._send_request('sendVoice', {
992
+ 'business_connection_id': business_connection_id,
993
+ 'chat_id': chat_id,
994
+ 'message_thread_id': message_thread_id,
995
+ 'direct_messages_topic_id': direct_messages_topic_id,
996
+ 'voice': voice,
997
+ 'caption': caption,
998
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
999
+ 'caption_entities': caption_entities,
1000
+ 'duration': duration,
1001
+ 'disable_notification': disable_notification,
1002
+ 'protect_content': protect_content,
1003
+ 'allow_paid_broadcast': allow_paid_broadcast,
1004
+ 'message_effect_id': message_effect_id,
1005
+ 'suggested_post_parameters': suggested_post_parameters,
1006
+ 'reply_parameters': reply_parameters,
1007
+ 'reply_markup': reply_markup,
1008
+ })
1009
+ return Message.model_validate(response)
1010
+
1011
+ async def send_video_note(
1012
+ self,
1013
+ chat_id: Union[int, str],
1014
+ video_note: Union[InputFile, str],
1015
+ business_connection_id: Optional[str] = None,
1016
+ message_thread_id: Optional[int] = None,
1017
+ direct_messages_topic_id: Optional[int] = None,
1018
+ duration: Optional[int] = None,
1019
+ length: Optional[int] = None,
1020
+ thumbnail: Optional[Union[InputFile, str]] = None,
1021
+ disable_notification: Optional[bool] = None,
1022
+ protect_content: Optional[bool] = None,
1023
+ allow_paid_broadcast: Optional[bool] = None,
1024
+ message_effect_id: Optional[str] = None,
1025
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
1026
+ reply_parameters: Optional[ReplyParameters] = None,
1027
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1028
+ ) -> Message:
1029
+ '''
1030
+ As of v.4.0, Telegram clients support rounded square
1031
+ MPEG4 videos of up to 1 minute long.
1032
+ Use this method to send video messages. On
1033
+ success, the sent Message is returned.
1034
+
1035
+ Reference: https://core.telegram.org/bots/api#sendvideonote
1036
+ '''
1037
+
1038
+ response = await self._send_request('sendVideoNote', {
1039
+ 'business_connection_id': business_connection_id,
1040
+ 'chat_id': chat_id,
1041
+ 'message_thread_id': message_thread_id,
1042
+ 'direct_messages_topic_id': direct_messages_topic_id,
1043
+ 'video_note': video_note,
1044
+ 'duration': duration,
1045
+ 'length': length,
1046
+ 'thumbnail': thumbnail,
1047
+ 'disable_notification': disable_notification,
1048
+ 'protect_content': protect_content,
1049
+ 'allow_paid_broadcast': allow_paid_broadcast,
1050
+ 'message_effect_id': message_effect_id,
1051
+ 'suggested_post_parameters': suggested_post_parameters,
1052
+ 'reply_parameters': reply_parameters,
1053
+ 'reply_markup': reply_markup,
1054
+ })
1055
+ return Message.model_validate(response)
1056
+
1057
+ async def send_paid_media(
1058
+ self,
1059
+ chat_id: Union[int, str],
1060
+ star_count: int,
1061
+ media: List[InputPaidMedia],
1062
+ business_connection_id: Optional[str] = None,
1063
+ message_thread_id: Optional[int] = None,
1064
+ direct_messages_topic_id: Optional[int] = None,
1065
+ payload: Optional[str] = None,
1066
+ caption: Optional[str] = None,
1067
+ parse_mode: Optional[str] = 'HTML',
1068
+ caption_entities: Optional[List[MessageEntity]] = None,
1069
+ show_caption_above_media: Optional[bool] = None,
1070
+ disable_notification: Optional[bool] = None,
1071
+ protect_content: Optional[bool] = None,
1072
+ allow_paid_broadcast: Optional[bool] = None,
1073
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
1074
+ reply_parameters: Optional[ReplyParameters] = None,
1075
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1076
+ ) -> Message:
1077
+ '''
1078
+ Use this method to send paid media. On
1079
+ success, the sent Message is returned.
1080
+
1081
+ Reference: https://core.telegram.org/bots/api#sendpaidmedia
1082
+ '''
1083
+
1084
+ response = await self._send_request('sendPaidMedia', {
1085
+ 'business_connection_id': business_connection_id,
1086
+ 'chat_id': chat_id,
1087
+ 'message_thread_id': message_thread_id,
1088
+ 'direct_messages_topic_id': direct_messages_topic_id,
1089
+ 'star_count': star_count,
1090
+ 'media': media,
1091
+ 'payload': payload,
1092
+ 'caption': caption,
1093
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
1094
+ 'caption_entities': caption_entities,
1095
+ 'show_caption_above_media': show_caption_above_media,
1096
+ 'disable_notification': disable_notification,
1097
+ 'protect_content': protect_content,
1098
+ 'allow_paid_broadcast': allow_paid_broadcast,
1099
+ 'suggested_post_parameters': suggested_post_parameters,
1100
+ 'reply_parameters': reply_parameters,
1101
+ 'reply_markup': reply_markup,
1102
+ })
1103
+ return Message.model_validate(response)
1104
+
1105
+ async def send_media_group(
1106
+ self,
1107
+ chat_id: Union[int, str],
1108
+ media: List[Union[InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo]],
1109
+ business_connection_id: Optional[str] = None,
1110
+ message_thread_id: Optional[int] = None,
1111
+ direct_messages_topic_id: Optional[int] = None,
1112
+ disable_notification: Optional[bool] = None,
1113
+ protect_content: Optional[bool] = None,
1114
+ allow_paid_broadcast: Optional[bool] = None,
1115
+ message_effect_id: Optional[str] = None,
1116
+ reply_parameters: Optional[ReplyParameters] = None,
1117
+ ) -> List[Message]:
1118
+ '''
1119
+ Use this method to send a group of
1120
+ photos, videos, documents or audios as an album.
1121
+ Documents and audio files can be only grouped
1122
+ in an album with messages of the same
1123
+ type. On success, an array of Message objects
1124
+ that were sent is returned.
1125
+
1126
+ Reference: https://core.telegram.org/bots/api#sendmediagroup
1127
+ '''
1128
+
1129
+ response = await self._send_request('sendMediaGroup', {
1130
+ 'business_connection_id': business_connection_id,
1131
+ 'chat_id': chat_id,
1132
+ 'message_thread_id': message_thread_id,
1133
+ 'direct_messages_topic_id': direct_messages_topic_id,
1134
+ 'media': media,
1135
+ 'disable_notification': disable_notification,
1136
+ 'protect_content': protect_content,
1137
+ 'allow_paid_broadcast': allow_paid_broadcast,
1138
+ 'message_effect_id': message_effect_id,
1139
+ 'reply_parameters': reply_parameters,
1140
+ })
1141
+ return [Message.model_validate(x) for x in response]
1142
+
1143
+ async def send_location(
1144
+ self,
1145
+ chat_id: Union[int, str],
1146
+ latitude: float,
1147
+ longitude: float,
1148
+ business_connection_id: Optional[str] = None,
1149
+ message_thread_id: Optional[int] = None,
1150
+ direct_messages_topic_id: Optional[int] = None,
1151
+ horizontal_accuracy: Optional[float] = None,
1152
+ live_period: Optional[int] = None,
1153
+ heading: Optional[int] = None,
1154
+ proximity_alert_radius: Optional[int] = None,
1155
+ disable_notification: Optional[bool] = None,
1156
+ protect_content: Optional[bool] = None,
1157
+ allow_paid_broadcast: Optional[bool] = None,
1158
+ message_effect_id: Optional[str] = None,
1159
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
1160
+ reply_parameters: Optional[ReplyParameters] = None,
1161
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1162
+ ) -> Message:
1163
+ '''
1164
+ Use this method to send point on the
1165
+ map. On success, the sent Message is returned.
1166
+
1167
+ Reference: https://core.telegram.org/bots/api#sendlocation
1168
+ '''
1169
+
1170
+ response = await self._send_request('sendLocation', {
1171
+ 'business_connection_id': business_connection_id,
1172
+ 'chat_id': chat_id,
1173
+ 'message_thread_id': message_thread_id,
1174
+ 'direct_messages_topic_id': direct_messages_topic_id,
1175
+ 'latitude': latitude,
1176
+ 'longitude': longitude,
1177
+ 'horizontal_accuracy': horizontal_accuracy,
1178
+ 'live_period': live_period,
1179
+ 'heading': heading,
1180
+ 'proximity_alert_radius': proximity_alert_radius,
1181
+ 'disable_notification': disable_notification,
1182
+ 'protect_content': protect_content,
1183
+ 'allow_paid_broadcast': allow_paid_broadcast,
1184
+ 'message_effect_id': message_effect_id,
1185
+ 'suggested_post_parameters': suggested_post_parameters,
1186
+ 'reply_parameters': reply_parameters,
1187
+ 'reply_markup': reply_markup,
1188
+ })
1189
+ return Message.model_validate(response)
1190
+
1191
+ async def send_venue(
1192
+ self,
1193
+ chat_id: Union[int, str],
1194
+ latitude: float,
1195
+ longitude: float,
1196
+ title: str,
1197
+ address: str,
1198
+ business_connection_id: Optional[str] = None,
1199
+ message_thread_id: Optional[int] = None,
1200
+ direct_messages_topic_id: Optional[int] = None,
1201
+ foursquare_id: Optional[str] = None,
1202
+ foursquare_type: Optional[str] = None,
1203
+ google_place_id: Optional[str] = None,
1204
+ google_place_type: Optional[str] = None,
1205
+ disable_notification: Optional[bool] = None,
1206
+ protect_content: Optional[bool] = None,
1207
+ allow_paid_broadcast: Optional[bool] = None,
1208
+ message_effect_id: Optional[str] = None,
1209
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
1210
+ reply_parameters: Optional[ReplyParameters] = None,
1211
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1212
+ ) -> Message:
1213
+ '''
1214
+ Use this method to send information about a
1215
+ venue. On success, the sent Message is returned.
1216
+
1217
+ Reference: https://core.telegram.org/bots/api#sendvenue
1218
+ '''
1219
+
1220
+ response = await self._send_request('sendVenue', {
1221
+ 'business_connection_id': business_connection_id,
1222
+ 'chat_id': chat_id,
1223
+ 'message_thread_id': message_thread_id,
1224
+ 'direct_messages_topic_id': direct_messages_topic_id,
1225
+ 'latitude': latitude,
1226
+ 'longitude': longitude,
1227
+ 'title': title,
1228
+ 'address': address,
1229
+ 'foursquare_id': foursquare_id,
1230
+ 'foursquare_type': foursquare_type,
1231
+ 'google_place_id': google_place_id,
1232
+ 'google_place_type': google_place_type,
1233
+ 'disable_notification': disable_notification,
1234
+ 'protect_content': protect_content,
1235
+ 'allow_paid_broadcast': allow_paid_broadcast,
1236
+ 'message_effect_id': message_effect_id,
1237
+ 'suggested_post_parameters': suggested_post_parameters,
1238
+ 'reply_parameters': reply_parameters,
1239
+ 'reply_markup': reply_markup,
1240
+ })
1241
+ return Message.model_validate(response)
1242
+
1243
+ async def send_contact(
1244
+ self,
1245
+ chat_id: Union[int, str],
1246
+ phone_number: str,
1247
+ first_name: str,
1248
+ business_connection_id: Optional[str] = None,
1249
+ message_thread_id: Optional[int] = None,
1250
+ direct_messages_topic_id: Optional[int] = None,
1251
+ last_name: Optional[str] = None,
1252
+ vcard: Optional[str] = None,
1253
+ disable_notification: Optional[bool] = None,
1254
+ protect_content: Optional[bool] = None,
1255
+ allow_paid_broadcast: Optional[bool] = None,
1256
+ message_effect_id: Optional[str] = None,
1257
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
1258
+ reply_parameters: Optional[ReplyParameters] = None,
1259
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1260
+ ) -> Message:
1261
+ '''
1262
+ Use this method to send phone contacts. On
1263
+ success, the sent Message is returned.
1264
+
1265
+ Reference: https://core.telegram.org/bots/api#sendcontact
1266
+ '''
1267
+
1268
+ response = await self._send_request('sendContact', {
1269
+ 'business_connection_id': business_connection_id,
1270
+ 'chat_id': chat_id,
1271
+ 'message_thread_id': message_thread_id,
1272
+ 'direct_messages_topic_id': direct_messages_topic_id,
1273
+ 'phone_number': phone_number,
1274
+ 'first_name': first_name,
1275
+ 'last_name': last_name,
1276
+ 'vcard': vcard,
1277
+ 'disable_notification': disable_notification,
1278
+ 'protect_content': protect_content,
1279
+ 'allow_paid_broadcast': allow_paid_broadcast,
1280
+ 'message_effect_id': message_effect_id,
1281
+ 'suggested_post_parameters': suggested_post_parameters,
1282
+ 'reply_parameters': reply_parameters,
1283
+ 'reply_markup': reply_markup,
1284
+ })
1285
+ return Message.model_validate(response)
1286
+
1287
+ async def send_poll(
1288
+ self,
1289
+ chat_id: Union[int, str],
1290
+ question: str,
1291
+ options: List[InputPollOption],
1292
+ business_connection_id: Optional[str] = None,
1293
+ message_thread_id: Optional[int] = None,
1294
+ question_parse_mode: Optional[str] = None,
1295
+ question_entities: Optional[List[MessageEntity]] = None,
1296
+ is_anonymous: Optional[bool] = None,
1297
+ type: Optional[str] = None,
1298
+ allows_multiple_answers: Optional[bool] = None,
1299
+ correct_option_id: Optional[int] = None,
1300
+ explanation: Optional[str] = None,
1301
+ explanation_parse_mode: Optional[str] = None,
1302
+ explanation_entities: Optional[List[MessageEntity]] = None,
1303
+ open_period: Optional[int] = None,
1304
+ close_date: Optional[int] = None,
1305
+ is_closed: Optional[bool] = None,
1306
+ disable_notification: Optional[bool] = None,
1307
+ protect_content: Optional[bool] = None,
1308
+ allow_paid_broadcast: Optional[bool] = None,
1309
+ message_effect_id: Optional[str] = None,
1310
+ reply_parameters: Optional[ReplyParameters] = None,
1311
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1312
+ ) -> Message:
1313
+ '''
1314
+ Use this method to send a native poll.
1315
+ On success, the sent Message is returned.
1316
+
1317
+ Reference: https://core.telegram.org/bots/api#sendpoll
1318
+ '''
1319
+
1320
+ response = await self._send_request('sendPoll', {
1321
+ 'business_connection_id': business_connection_id,
1322
+ 'chat_id': chat_id,
1323
+ 'message_thread_id': message_thread_id,
1324
+ 'question': question,
1325
+ 'question_parse_mode': question_parse_mode,
1326
+ 'question_entities': question_entities,
1327
+ 'options': options,
1328
+ 'is_anonymous': is_anonymous,
1329
+ 'type': type,
1330
+ 'allows_multiple_answers': allows_multiple_answers,
1331
+ 'correct_option_id': correct_option_id,
1332
+ 'explanation': explanation,
1333
+ 'explanation_parse_mode': explanation_parse_mode,
1334
+ 'explanation_entities': explanation_entities,
1335
+ 'open_period': open_period,
1336
+ 'close_date': close_date,
1337
+ 'is_closed': is_closed,
1338
+ 'disable_notification': disable_notification,
1339
+ 'protect_content': protect_content,
1340
+ 'allow_paid_broadcast': allow_paid_broadcast,
1341
+ 'message_effect_id': message_effect_id,
1342
+ 'reply_parameters': reply_parameters,
1343
+ 'reply_markup': reply_markup,
1344
+ })
1345
+ return Message.model_validate(response)
1346
+
1347
+ async def send_checklist(
1348
+ self,
1349
+ business_connection_id: str,
1350
+ chat_id: int,
1351
+ checklist: InputChecklist,
1352
+ disable_notification: Optional[bool] = None,
1353
+ protect_content: Optional[bool] = None,
1354
+ message_effect_id: Optional[str] = None,
1355
+ reply_parameters: Optional[ReplyParameters] = None,
1356
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
1357
+ ) -> Message:
1358
+ '''
1359
+ Use this method to send a checklist on
1360
+ behalf of a connected business account. On success,
1361
+ the sent Message is returned.
1362
+
1363
+ Reference: https://core.telegram.org/bots/api#sendchecklist
1364
+ '''
1365
+
1366
+ response = await self._send_request('sendChecklist', {
1367
+ 'business_connection_id': business_connection_id,
1368
+ 'chat_id': chat_id,
1369
+ 'checklist': checklist,
1370
+ 'disable_notification': disable_notification,
1371
+ 'protect_content': protect_content,
1372
+ 'message_effect_id': message_effect_id,
1373
+ 'reply_parameters': reply_parameters,
1374
+ 'reply_markup': reply_markup,
1375
+ })
1376
+ return Message.model_validate(response)
1377
+
1378
+ async def send_dice(
1379
+ self,
1380
+ chat_id: Union[int, str],
1381
+ business_connection_id: Optional[str] = None,
1382
+ message_thread_id: Optional[int] = None,
1383
+ direct_messages_topic_id: Optional[int] = None,
1384
+ emoji: Optional[str] = None,
1385
+ disable_notification: Optional[bool] = None,
1386
+ protect_content: Optional[bool] = None,
1387
+ allow_paid_broadcast: Optional[bool] = None,
1388
+ message_effect_id: Optional[str] = None,
1389
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
1390
+ reply_parameters: Optional[ReplyParameters] = None,
1391
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
1392
+ ) -> Message:
1393
+ '''
1394
+ Use this method to send an animated emoji
1395
+ that will display a random value. On success,
1396
+ the sent Message is returned.
1397
+
1398
+ Reference: https://core.telegram.org/bots/api#senddice
1399
+ '''
1400
+
1401
+ response = await self._send_request('sendDice', {
1402
+ 'business_connection_id': business_connection_id,
1403
+ 'chat_id': chat_id,
1404
+ 'message_thread_id': message_thread_id,
1405
+ 'direct_messages_topic_id': direct_messages_topic_id,
1406
+ 'emoji': emoji,
1407
+ 'disable_notification': disable_notification,
1408
+ 'protect_content': protect_content,
1409
+ 'allow_paid_broadcast': allow_paid_broadcast,
1410
+ 'message_effect_id': message_effect_id,
1411
+ 'suggested_post_parameters': suggested_post_parameters,
1412
+ 'reply_parameters': reply_parameters,
1413
+ 'reply_markup': reply_markup,
1414
+ })
1415
+ return Message.model_validate(response)
1416
+
1417
+ async def send_chat_action(
1418
+ self,
1419
+ chat_id: Union[int, str],
1420
+ action: str,
1421
+ business_connection_id: Optional[str] = None,
1422
+ message_thread_id: Optional[int] = None,
1423
+ ) -> bool:
1424
+ '''
1425
+ Use this method when you need to tell
1426
+ the user that something is happening on the
1427
+ bot's side. The status is set for 5
1428
+ seconds or less (when a message arrives from
1429
+ your bot, Telegram clients clear its typing status).
1430
+ Returns True on success.
1431
+
1432
+ Reference: https://core.telegram.org/bots/api#sendchataction
1433
+ '''
1434
+
1435
+ response = await self._send_request('sendChatAction', {
1436
+ 'business_connection_id': business_connection_id,
1437
+ 'chat_id': chat_id,
1438
+ 'message_thread_id': message_thread_id,
1439
+ 'action': action,
1440
+ })
1441
+ return BoolAdapter.validate_python(response)
1442
+
1443
+ async def set_message_reaction(
1444
+ self,
1445
+ chat_id: Union[int, str],
1446
+ message_id: int,
1447
+ reaction: Optional[List[ReactionType]] = None,
1448
+ is_big: Optional[bool] = None,
1449
+ ) -> bool:
1450
+ '''
1451
+ Use this method to change the chosen reactions
1452
+ on a message. Service messages of some types
1453
+ can't be reacted to. Automatically forwarded messages from
1454
+ a channel to its discussion group have the
1455
+ same available reactions as messages in the channel.
1456
+ Bots can't use paid reactions. Returns True on
1457
+ success.
1458
+
1459
+ Reference: https://core.telegram.org/bots/api#setmessagereaction
1460
+ '''
1461
+
1462
+ response = await self._send_request('setMessageReaction', {
1463
+ 'chat_id': chat_id,
1464
+ 'message_id': message_id,
1465
+ 'reaction': reaction,
1466
+ 'is_big': is_big,
1467
+ })
1468
+ return BoolAdapter.validate_python(response)
1469
+
1470
+ async def get_user_profile_photos(
1471
+ self,
1472
+ user_id: int,
1473
+ offset: Optional[int] = None,
1474
+ limit: Optional[int] = None,
1475
+ ) -> UserProfilePhotos:
1476
+ '''
1477
+ Use this method to get a list of
1478
+ profile pictures for a user. Returns a UserProfilePhotos
1479
+ object.
1480
+
1481
+ Reference: https://core.telegram.org/bots/api#getuserprofilephotos
1482
+ '''
1483
+
1484
+ response = await self._send_request('getUserProfilePhotos', {
1485
+ 'user_id': user_id,
1486
+ 'offset': offset,
1487
+ 'limit': limit,
1488
+ })
1489
+ return UserProfilePhotos.model_validate(response)
1490
+
1491
+ async def set_user_emoji_status(
1492
+ self,
1493
+ user_id: int,
1494
+ emoji_status_custom_emoji_id: Optional[str] = None,
1495
+ emoji_status_expiration_date: Optional[int] = None,
1496
+ ) -> bool:
1497
+ '''
1498
+ Changes the emoji status for a given user
1499
+ that previously allowed the bot to manage their
1500
+ emoji status via the Mini App method requestEmojiStatusAccess.
1501
+ Returns True on success.
1502
+
1503
+ Reference: https://core.telegram.org/bots/api#setuseremojistatus
1504
+ '''
1505
+
1506
+ response = await self._send_request('setUserEmojiStatus', {
1507
+ 'user_id': user_id,
1508
+ 'emoji_status_custom_emoji_id': emoji_status_custom_emoji_id,
1509
+ 'emoji_status_expiration_date': emoji_status_expiration_date,
1510
+ })
1511
+ return BoolAdapter.validate_python(response)
1512
+
1513
+ async def get_file(
1514
+ self,
1515
+ file_id: str,
1516
+ ) -> File:
1517
+ '''
1518
+ Use this method to get basic information about
1519
+ a file and prepare it for downloading. For
1520
+ the moment, bots can download files of up
1521
+ to 20MB in size. On success, a File
1522
+ object is returned. The file can then be
1523
+ downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is
1524
+ taken from the response. It is guaranteed that
1525
+ the link will be valid for at least
1526
+ 1 hour. When the link expires, a new
1527
+ one can be requested by calling getFile again.
1528
+
1529
+ Reference: https://core.telegram.org/bots/api#getfile
1530
+ '''
1531
+
1532
+ response = await self._send_request('getFile', {
1533
+ 'file_id': file_id,
1534
+ })
1535
+ return File.model_validate(response)
1536
+
1537
+ async def ban_chat_member(
1538
+ self,
1539
+ chat_id: Union[int, str],
1540
+ user_id: int,
1541
+ until_date: Optional[int] = None,
1542
+ revoke_messages: Optional[bool] = None,
1543
+ ) -> bool:
1544
+ '''
1545
+ Use this method to ban a user in
1546
+ a group, a supergroup or a channel. In
1547
+ the case of supergroups and channels, the user
1548
+ will not be able to return to the
1549
+ chat on their own using invite links, etc.,
1550
+ unless unbanned first. The bot must be an
1551
+ administrator in the chat for this to work
1552
+ and must have the appropriate administrator rights. Returns
1553
+ True on success.
1554
+
1555
+ Reference: https://core.telegram.org/bots/api#banchatmember
1556
+ '''
1557
+
1558
+ response = await self._send_request('banChatMember', {
1559
+ 'chat_id': chat_id,
1560
+ 'user_id': user_id,
1561
+ 'until_date': until_date,
1562
+ 'revoke_messages': revoke_messages,
1563
+ })
1564
+ return BoolAdapter.validate_python(response)
1565
+
1566
+ async def unban_chat_member(
1567
+ self,
1568
+ chat_id: Union[int, str],
1569
+ user_id: int,
1570
+ only_if_banned: Optional[bool] = None,
1571
+ ) -> bool:
1572
+ '''
1573
+ Use this method to unban a previously banned
1574
+ user in a supergroup or channel. The user
1575
+ will not return to the group or channel
1576
+ automatically, but will be able to join via
1577
+ link, etc. The bot must be an administrator
1578
+ for this to work. By default, this method
1579
+ guarantees that after the call the user is
1580
+ not a member of the chat, but will
1581
+ be able to join it. So if the
1582
+ user is a member of the chat they
1583
+ will also be removed from the chat. If
1584
+ you don't want this, use the parameter only_if_banned.
1585
+ Returns True on success.
1586
+
1587
+ Reference: https://core.telegram.org/bots/api#unbanchatmember
1588
+ '''
1589
+
1590
+ response = await self._send_request('unbanChatMember', {
1591
+ 'chat_id': chat_id,
1592
+ 'user_id': user_id,
1593
+ 'only_if_banned': only_if_banned,
1594
+ })
1595
+ return BoolAdapter.validate_python(response)
1596
+
1597
+ async def restrict_chat_member(
1598
+ self,
1599
+ chat_id: Union[int, str],
1600
+ user_id: int,
1601
+ permissions: ChatPermissions,
1602
+ use_independent_chat_permissions: Optional[bool] = None,
1603
+ until_date: Optional[int] = None,
1604
+ ) -> bool:
1605
+ '''
1606
+ Use this method to restrict a user in
1607
+ a supergroup. The bot must be an administrator
1608
+ in the supergroup for this to work and
1609
+ must have the appropriate administrator rights. Pass True
1610
+ for all permissions to lift restrictions from a
1611
+ user. Returns True on success.
1612
+
1613
+ Reference: https://core.telegram.org/bots/api#restrictchatmember
1614
+ '''
1615
+
1616
+ response = await self._send_request('restrictChatMember', {
1617
+ 'chat_id': chat_id,
1618
+ 'user_id': user_id,
1619
+ 'permissions': permissions,
1620
+ 'use_independent_chat_permissions': use_independent_chat_permissions,
1621
+ 'until_date': until_date,
1622
+ })
1623
+ return BoolAdapter.validate_python(response)
1624
+
1625
+ async def promote_chat_member(
1626
+ self,
1627
+ chat_id: Union[int, str],
1628
+ user_id: int,
1629
+ is_anonymous: Optional[bool] = None,
1630
+ can_manage_chat: Optional[bool] = None,
1631
+ can_delete_messages: Optional[bool] = None,
1632
+ can_manage_video_chats: Optional[bool] = None,
1633
+ can_restrict_members: Optional[bool] = None,
1634
+ can_promote_members: Optional[bool] = None,
1635
+ can_change_info: Optional[bool] = None,
1636
+ can_invite_users: Optional[bool] = None,
1637
+ can_post_stories: Optional[bool] = None,
1638
+ can_edit_stories: Optional[bool] = None,
1639
+ can_delete_stories: Optional[bool] = None,
1640
+ can_post_messages: Optional[bool] = None,
1641
+ can_edit_messages: Optional[bool] = None,
1642
+ can_pin_messages: Optional[bool] = None,
1643
+ can_manage_topics: Optional[bool] = None,
1644
+ can_manage_direct_messages: Optional[bool] = None,
1645
+ ) -> bool:
1646
+ '''
1647
+ Use this method to promote or demote a
1648
+ user in a supergroup or a channel. The
1649
+ bot must be an administrator in the chat
1650
+ for this to work and must have the
1651
+ appropriate administrator rights. Pass False for all boolean
1652
+ parameters to demote a user. Returns True on
1653
+ success.
1654
+
1655
+ Reference: https://core.telegram.org/bots/api#promotechatmember
1656
+ '''
1657
+
1658
+ response = await self._send_request('promoteChatMember', {
1659
+ 'chat_id': chat_id,
1660
+ 'user_id': user_id,
1661
+ 'is_anonymous': is_anonymous,
1662
+ 'can_manage_chat': can_manage_chat,
1663
+ 'can_delete_messages': can_delete_messages,
1664
+ 'can_manage_video_chats': can_manage_video_chats,
1665
+ 'can_restrict_members': can_restrict_members,
1666
+ 'can_promote_members': can_promote_members,
1667
+ 'can_change_info': can_change_info,
1668
+ 'can_invite_users': can_invite_users,
1669
+ 'can_post_stories': can_post_stories,
1670
+ 'can_edit_stories': can_edit_stories,
1671
+ 'can_delete_stories': can_delete_stories,
1672
+ 'can_post_messages': can_post_messages,
1673
+ 'can_edit_messages': can_edit_messages,
1674
+ 'can_pin_messages': can_pin_messages,
1675
+ 'can_manage_topics': can_manage_topics,
1676
+ 'can_manage_direct_messages': can_manage_direct_messages,
1677
+ })
1678
+ return BoolAdapter.validate_python(response)
1679
+
1680
+ async def set_chat_administrator_custom_title(
1681
+ self,
1682
+ chat_id: Union[int, str],
1683
+ user_id: int,
1684
+ custom_title: str,
1685
+ ) -> bool:
1686
+ '''
1687
+ Use this method to set a custom title
1688
+ for an administrator in a supergroup promoted by
1689
+ the bot. Returns True on success.
1690
+
1691
+ Reference: https://core.telegram.org/bots/api#setchatadministratorcustomtitle
1692
+ '''
1693
+
1694
+ response = await self._send_request('setChatAdministratorCustomTitle', {
1695
+ 'chat_id': chat_id,
1696
+ 'user_id': user_id,
1697
+ 'custom_title': custom_title,
1698
+ })
1699
+ return BoolAdapter.validate_python(response)
1700
+
1701
+ async def ban_chat_sender_chat(
1702
+ self,
1703
+ chat_id: Union[int, str],
1704
+ sender_chat_id: int,
1705
+ ) -> bool:
1706
+ '''
1707
+ Use this method to ban a channel chat
1708
+ in a supergroup or a channel. Until the
1709
+ chat is unbanned, the owner of the banned
1710
+ chat won't be able to send messages on
1711
+ behalf of any of their channels. The bot
1712
+ must be an administrator in the supergroup or
1713
+ channel for this to work and must have
1714
+ the appropriate administrator rights. Returns True on success.
1715
+
1716
+ Reference: https://core.telegram.org/bots/api#banchatsenderchat
1717
+ '''
1718
+
1719
+ response = await self._send_request('banChatSenderChat', {
1720
+ 'chat_id': chat_id,
1721
+ 'sender_chat_id': sender_chat_id,
1722
+ })
1723
+ return BoolAdapter.validate_python(response)
1724
+
1725
+ async def unban_chat_sender_chat(
1726
+ self,
1727
+ chat_id: Union[int, str],
1728
+ sender_chat_id: int,
1729
+ ) -> bool:
1730
+ '''
1731
+ Use this method to unban a previously banned
1732
+ channel chat in a supergroup or channel. The
1733
+ bot must be an administrator for this to
1734
+ work and must have the appropriate administrator rights.
1735
+ Returns True on success.
1736
+
1737
+ Reference: https://core.telegram.org/bots/api#unbanchatsenderchat
1738
+ '''
1739
+
1740
+ response = await self._send_request('unbanChatSenderChat', {
1741
+ 'chat_id': chat_id,
1742
+ 'sender_chat_id': sender_chat_id,
1743
+ })
1744
+ return BoolAdapter.validate_python(response)
1745
+
1746
+ async def set_chat_permissions(
1747
+ self,
1748
+ chat_id: Union[int, str],
1749
+ permissions: ChatPermissions,
1750
+ use_independent_chat_permissions: Optional[bool] = None,
1751
+ ) -> bool:
1752
+ '''
1753
+ Use this method to set default chat permissions
1754
+ for all members. The bot must be an
1755
+ administrator in the group or a supergroup for
1756
+ this to work and must have the can_restrict_members
1757
+ administrator rights. Returns True on success.
1758
+
1759
+ Reference: https://core.telegram.org/bots/api#setchatpermissions
1760
+ '''
1761
+
1762
+ response = await self._send_request('setChatPermissions', {
1763
+ 'chat_id': chat_id,
1764
+ 'permissions': permissions,
1765
+ 'use_independent_chat_permissions': use_independent_chat_permissions,
1766
+ })
1767
+ return BoolAdapter.validate_python(response)
1768
+
1769
+ async def export_chat_invite_link(
1770
+ self,
1771
+ chat_id: Union[int, str],
1772
+ ) -> str:
1773
+ '''
1774
+ Use this method to generate a new primary
1775
+ invite link for a chat; any previously generated
1776
+ primary link is revoked. The bot must be
1777
+ an administrator in the chat for this to
1778
+ work and must have the appropriate administrator rights.
1779
+ Returns the new invite link as String on
1780
+ success.
1781
+
1782
+ Reference: https://core.telegram.org/bots/api#exportchatinvitelink
1783
+ '''
1784
+
1785
+ response = await self._send_request('exportChatInviteLink', {
1786
+ 'chat_id': chat_id,
1787
+ })
1788
+ return StrAdapter.validate_python(response)
1789
+
1790
+ async def create_chat_invite_link(
1791
+ self,
1792
+ chat_id: Union[int, str],
1793
+ name: Optional[str] = None,
1794
+ expire_date: Optional[int] = None,
1795
+ member_limit: Optional[int] = None,
1796
+ creates_join_request: Optional[bool] = None,
1797
+ ) -> ChatInviteLink:
1798
+ '''
1799
+ Use this method to create an additional invite
1800
+ link for a chat. The bot must be
1801
+ an administrator in the chat for this to
1802
+ work and must have the appropriate administrator rights.
1803
+ The link can be revoked using the method
1804
+ revokeChatInviteLink. Returns the new invite link as ChatInviteLink
1805
+ object.
1806
+
1807
+ Reference: https://core.telegram.org/bots/api#createchatinvitelink
1808
+ '''
1809
+
1810
+ response = await self._send_request('createChatInviteLink', {
1811
+ 'chat_id': chat_id,
1812
+ 'name': name,
1813
+ 'expire_date': expire_date,
1814
+ 'member_limit': member_limit,
1815
+ 'creates_join_request': creates_join_request,
1816
+ })
1817
+ return ChatInviteLink.model_validate(response)
1818
+
1819
+ async def edit_chat_invite_link(
1820
+ self,
1821
+ chat_id: Union[int, str],
1822
+ invite_link: str,
1823
+ name: Optional[str] = None,
1824
+ expire_date: Optional[int] = None,
1825
+ member_limit: Optional[int] = None,
1826
+ creates_join_request: Optional[bool] = None,
1827
+ ) -> ChatInviteLink:
1828
+ '''
1829
+ Use this method to edit a non-primary invite
1830
+ link created by the bot. The bot must
1831
+ be an administrator in the chat for this
1832
+ to work and must have the appropriate administrator
1833
+ rights. Returns the edited invite link as a
1834
+ ChatInviteLink object.
1835
+
1836
+ Reference: https://core.telegram.org/bots/api#editchatinvitelink
1837
+ '''
1838
+
1839
+ response = await self._send_request('editChatInviteLink', {
1840
+ 'chat_id': chat_id,
1841
+ 'invite_link': invite_link,
1842
+ 'name': name,
1843
+ 'expire_date': expire_date,
1844
+ 'member_limit': member_limit,
1845
+ 'creates_join_request': creates_join_request,
1846
+ })
1847
+ return ChatInviteLink.model_validate(response)
1848
+
1849
+ async def create_chat_subscription_invite_link(
1850
+ self,
1851
+ chat_id: Union[int, str],
1852
+ subscription_period: int,
1853
+ subscription_price: int,
1854
+ name: Optional[str] = None,
1855
+ ) -> ChatInviteLink:
1856
+ '''
1857
+ Use this method to create a subscription invite
1858
+ link for a channel chat. The bot must
1859
+ have the can_invite_users administrator rights. The link can
1860
+ be edited using the method editChatSubscriptionInviteLink or revoked
1861
+ using the method revokeChatInviteLink. Returns the new invite
1862
+ link as a ChatInviteLink object.
1863
+
1864
+ Reference: https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
1865
+ '''
1866
+
1867
+ response = await self._send_request('createChatSubscriptionInviteLink', {
1868
+ 'chat_id': chat_id,
1869
+ 'name': name,
1870
+ 'subscription_period': subscription_period,
1871
+ 'subscription_price': subscription_price,
1872
+ })
1873
+ return ChatInviteLink.model_validate(response)
1874
+
1875
+ async def edit_chat_subscription_invite_link(
1876
+ self,
1877
+ chat_id: Union[int, str],
1878
+ invite_link: str,
1879
+ name: Optional[str] = None,
1880
+ ) -> ChatInviteLink:
1881
+ '''
1882
+ Use this method to edit a subscription invite
1883
+ link created by the bot. The bot must
1884
+ have the can_invite_users administrator rights. Returns the edited
1885
+ invite link as a ChatInviteLink object.
1886
+
1887
+ Reference: https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
1888
+ '''
1889
+
1890
+ response = await self._send_request('editChatSubscriptionInviteLink', {
1891
+ 'chat_id': chat_id,
1892
+ 'invite_link': invite_link,
1893
+ 'name': name,
1894
+ })
1895
+ return ChatInviteLink.model_validate(response)
1896
+
1897
+ async def revoke_chat_invite_link(
1898
+ self,
1899
+ chat_id: Union[int, str],
1900
+ invite_link: str,
1901
+ ) -> ChatInviteLink:
1902
+ '''
1903
+ Use this method to revoke an invite link
1904
+ created by the bot. If the primary link
1905
+ is revoked, a new link is automatically generated.
1906
+ The bot must be an administrator in the
1907
+ chat for this to work and must have
1908
+ the appropriate administrator rights. Returns the revoked invite
1909
+ link as ChatInviteLink object.
1910
+
1911
+ Reference: https://core.telegram.org/bots/api#revokechatinvitelink
1912
+ '''
1913
+
1914
+ response = await self._send_request('revokeChatInviteLink', {
1915
+ 'chat_id': chat_id,
1916
+ 'invite_link': invite_link,
1917
+ })
1918
+ return ChatInviteLink.model_validate(response)
1919
+
1920
+ async def approve_chat_join_request(
1921
+ self,
1922
+ chat_id: Union[int, str],
1923
+ user_id: int,
1924
+ ) -> bool:
1925
+ '''
1926
+ Use this method to approve a chat join
1927
+ request. The bot must be an administrator in
1928
+ the chat for this to work and must
1929
+ have the can_invite_users administrator right. Returns True on
1930
+ success.
1931
+
1932
+ Reference: https://core.telegram.org/bots/api#approvechatjoinrequest
1933
+ '''
1934
+
1935
+ response = await self._send_request('approveChatJoinRequest', {
1936
+ 'chat_id': chat_id,
1937
+ 'user_id': user_id,
1938
+ })
1939
+ return BoolAdapter.validate_python(response)
1940
+
1941
+ async def decline_chat_join_request(
1942
+ self,
1943
+ chat_id: Union[int, str],
1944
+ user_id: int,
1945
+ ) -> bool:
1946
+ '''
1947
+ Use this method to decline a chat join
1948
+ request. The bot must be an administrator in
1949
+ the chat for this to work and must
1950
+ have the can_invite_users administrator right. Returns True on
1951
+ success.
1952
+
1953
+ Reference: https://core.telegram.org/bots/api#declinechatjoinrequest
1954
+ '''
1955
+
1956
+ response = await self._send_request('declineChatJoinRequest', {
1957
+ 'chat_id': chat_id,
1958
+ 'user_id': user_id,
1959
+ })
1960
+ return BoolAdapter.validate_python(response)
1961
+
1962
+ async def set_chat_photo(
1963
+ self,
1964
+ chat_id: Union[int, str],
1965
+ photo: InputFile,
1966
+ ) -> bool:
1967
+ '''
1968
+ Use this method to set a new profile
1969
+ photo for the chat. Photos can't be changed
1970
+ for private chats. The bot must be an
1971
+ administrator in the chat for this to work
1972
+ and must have the appropriate administrator rights. Returns
1973
+ True on success.
1974
+
1975
+ Reference: https://core.telegram.org/bots/api#setchatphoto
1976
+ '''
1977
+
1978
+ response = await self._send_request('setChatPhoto', {
1979
+ 'chat_id': chat_id,
1980
+ 'photo': photo,
1981
+ })
1982
+ return BoolAdapter.validate_python(response)
1983
+
1984
+ async def delete_chat_photo(
1985
+ self,
1986
+ chat_id: Union[int, str],
1987
+ ) -> bool:
1988
+ '''
1989
+ Use this method to delete a chat photo.
1990
+ Photos can't be changed for private chats. The
1991
+ bot must be an administrator in the chat
1992
+ for this to work and must have the
1993
+ appropriate administrator rights. Returns True on success.
1994
+
1995
+ Reference: https://core.telegram.org/bots/api#deletechatphoto
1996
+ '''
1997
+
1998
+ response = await self._send_request('deleteChatPhoto', {
1999
+ 'chat_id': chat_id,
2000
+ })
2001
+ return BoolAdapter.validate_python(response)
2002
+
2003
+ async def set_chat_title(
2004
+ self,
2005
+ chat_id: Union[int, str],
2006
+ title: str,
2007
+ ) -> bool:
2008
+ '''
2009
+ Use this method to change the title of
2010
+ a chat. Titles can't be changed for private
2011
+ chats. The bot must be an administrator in
2012
+ the chat for this to work and must
2013
+ have the appropriate administrator rights. Returns True on
2014
+ success.
2015
+
2016
+ Reference: https://core.telegram.org/bots/api#setchattitle
2017
+ '''
2018
+
2019
+ response = await self._send_request('setChatTitle', {
2020
+ 'chat_id': chat_id,
2021
+ 'title': title,
2022
+ })
2023
+ return BoolAdapter.validate_python(response)
2024
+
2025
+ async def set_chat_description(
2026
+ self,
2027
+ chat_id: Union[int, str],
2028
+ description: Optional[str] = None,
2029
+ ) -> bool:
2030
+ '''
2031
+ Use this method to change the description of
2032
+ a group, a supergroup or a channel. The
2033
+ bot must be an administrator in the chat
2034
+ for this to work and must have the
2035
+ appropriate administrator rights. Returns True on success.
2036
+
2037
+ Reference: https://core.telegram.org/bots/api#setchatdescription
2038
+ '''
2039
+
2040
+ response = await self._send_request('setChatDescription', {
2041
+ 'chat_id': chat_id,
2042
+ 'description': description,
2043
+ })
2044
+ return BoolAdapter.validate_python(response)
2045
+
2046
+ async def pin_chat_message(
2047
+ self,
2048
+ chat_id: Union[int, str],
2049
+ message_id: int,
2050
+ business_connection_id: Optional[str] = None,
2051
+ disable_notification: Optional[bool] = None,
2052
+ ) -> bool:
2053
+ '''
2054
+ Use this method to add a message to
2055
+ the list of pinned messages in a chat.
2056
+ In private chats and channel direct messages chats,
2057
+ all non-service messages can be pinned. Conversely, the
2058
+ bot must be an administrator with the 'can_pin_messages'
2059
+ right or the 'can_edit_messages' right to pin messages
2060
+ in groups and channels respectively. Returns True on
2061
+ success.
2062
+
2063
+ Reference: https://core.telegram.org/bots/api#pinchatmessage
2064
+ '''
2065
+
2066
+ response = await self._send_request('pinChatMessage', {
2067
+ 'business_connection_id': business_connection_id,
2068
+ 'chat_id': chat_id,
2069
+ 'message_id': message_id,
2070
+ 'disable_notification': disable_notification,
2071
+ })
2072
+ return BoolAdapter.validate_python(response)
2073
+
2074
+ async def unpin_chat_message(
2075
+ self,
2076
+ chat_id: Union[int, str],
2077
+ business_connection_id: Optional[str] = None,
2078
+ message_id: Optional[int] = None,
2079
+ ) -> bool:
2080
+ '''
2081
+ Use this method to remove a message from
2082
+ the list of pinned messages in a chat.
2083
+ In private chats and channel direct messages chats,
2084
+ all messages can be unpinned. Conversely, the bot
2085
+ must be an administrator with the 'can_pin_messages' right
2086
+ or the 'can_edit_messages' right to unpin messages in
2087
+ groups and channels respectively. Returns True on success.
2088
+
2089
+ Reference: https://core.telegram.org/bots/api#unpinchatmessage
2090
+ '''
2091
+
2092
+ response = await self._send_request('unpinChatMessage', {
2093
+ 'business_connection_id': business_connection_id,
2094
+ 'chat_id': chat_id,
2095
+ 'message_id': message_id,
2096
+ })
2097
+ return BoolAdapter.validate_python(response)
2098
+
2099
+ async def unpin_all_chat_messages(
2100
+ self,
2101
+ chat_id: Union[int, str],
2102
+ ) -> bool:
2103
+ '''
2104
+ Use this method to clear the list of
2105
+ pinned messages in a chat. In private chats
2106
+ and channel direct messages chats, no additional rights
2107
+ are required to unpin all pinned messages. Conversely,
2108
+ the bot must be an administrator with the
2109
+ 'can_pin_messages' right or the 'can_edit_messages' right to unpin
2110
+ all pinned messages in groups and channels respectively.
2111
+ Returns True on success.
2112
+
2113
+ Reference: https://core.telegram.org/bots/api#unpinallchatmessages
2114
+ '''
2115
+
2116
+ response = await self._send_request('unpinAllChatMessages', {
2117
+ 'chat_id': chat_id,
2118
+ })
2119
+ return BoolAdapter.validate_python(response)
2120
+
2121
+ async def leave_chat(
2122
+ self,
2123
+ chat_id: Union[int, str],
2124
+ ) -> bool:
2125
+ '''
2126
+ Use this method for your bot to leave
2127
+ a group, supergroup or channel. Returns True on
2128
+ success.
2129
+
2130
+ Reference: https://core.telegram.org/bots/api#leavechat
2131
+ '''
2132
+
2133
+ response = await self._send_request('leaveChat', {
2134
+ 'chat_id': chat_id,
2135
+ })
2136
+ return BoolAdapter.validate_python(response)
2137
+
2138
+ async def get_chat(
2139
+ self,
2140
+ chat_id: Union[int, str],
2141
+ ) -> ChatFullInfo:
2142
+ '''
2143
+ Use this method to get up-to-date information about
2144
+ the chat. Returns a ChatFullInfo object on success.
2145
+
2146
+ Reference: https://core.telegram.org/bots/api#getchat
2147
+ '''
2148
+
2149
+ response = await self._send_request('getChat', {
2150
+ 'chat_id': chat_id,
2151
+ })
2152
+ return ChatFullInfo.model_validate(response)
2153
+
2154
+ async def get_chat_administrators(
2155
+ self,
2156
+ chat_id: Union[int, str],
2157
+ ) -> List[ChatMember]:
2158
+ '''
2159
+ Use this method to get a list of
2160
+ administrators in a chat, which aren't bots. Returns
2161
+ an Array of ChatMember objects.
2162
+
2163
+ Reference: https://core.telegram.org/bots/api#getchatadministrators
2164
+ '''
2165
+
2166
+ response = await self._send_request('getChatAdministrators', {
2167
+ 'chat_id': chat_id,
2168
+ })
2169
+ return [ChatMemberAdapter.validate_python(x) for x in response]
2170
+
2171
+ async def get_chat_member_count(
2172
+ self,
2173
+ chat_id: Union[int, str],
2174
+ ) -> int:
2175
+ '''
2176
+ Use this method to get the number of
2177
+ members in a chat. Returns Int on success.
2178
+
2179
+ Reference: https://core.telegram.org/bots/api#getchatmembercount
2180
+ '''
2181
+
2182
+ response = await self._send_request('getChatMemberCount', {
2183
+ 'chat_id': chat_id,
2184
+ })
2185
+ return IntAdapter.validate_python(response)
2186
+
2187
+ async def get_chat_member(
2188
+ self,
2189
+ chat_id: Union[int, str],
2190
+ user_id: int,
2191
+ ) -> ChatMember:
2192
+ '''
2193
+ Use this method to get information about a
2194
+ member of a chat. The method is only
2195
+ guaranteed to work for other users if the
2196
+ bot is an administrator in the chat. Returns
2197
+ a ChatMember object on success.
2198
+
2199
+ Reference: https://core.telegram.org/bots/api#getchatmember
2200
+ '''
2201
+
2202
+ response = await self._send_request('getChatMember', {
2203
+ 'chat_id': chat_id,
2204
+ 'user_id': user_id,
2205
+ })
2206
+ return ChatMemberAdapter.validate_python(response)
2207
+
2208
+ async def set_chat_sticker_set(
2209
+ self,
2210
+ chat_id: Union[int, str],
2211
+ sticker_set_name: str,
2212
+ ) -> bool:
2213
+ '''
2214
+ Use this method to set a new group
2215
+ sticker set for a supergroup. The bot must
2216
+ be an administrator in the chat for this
2217
+ to work and must have the appropriate administrator
2218
+ rights. Use the field can_set_sticker_set optionally returned in
2219
+ getChat requests to check if the bot can
2220
+ use this method. Returns True on success.
2221
+
2222
+ Reference: https://core.telegram.org/bots/api#setchatstickerset
2223
+ '''
2224
+
2225
+ response = await self._send_request('setChatStickerSet', {
2226
+ 'chat_id': chat_id,
2227
+ 'sticker_set_name': sticker_set_name,
2228
+ })
2229
+ return BoolAdapter.validate_python(response)
2230
+
2231
+ async def delete_chat_sticker_set(
2232
+ self,
2233
+ chat_id: Union[int, str],
2234
+ ) -> bool:
2235
+ '''
2236
+ Use this method to delete a group sticker
2237
+ set from a supergroup. The bot must be
2238
+ an administrator in the chat for this to
2239
+ work and must have the appropriate administrator rights.
2240
+ Use the field can_set_sticker_set optionally returned in getChat
2241
+ requests to check if the bot can use
2242
+ this method. Returns True on success.
2243
+
2244
+ Reference: https://core.telegram.org/bots/api#deletechatstickerset
2245
+ '''
2246
+
2247
+ response = await self._send_request('deleteChatStickerSet', {
2248
+ 'chat_id': chat_id,
2249
+ })
2250
+ return BoolAdapter.validate_python(response)
2251
+
2252
+ async def get_forum_topic_icon_stickers(
2253
+ self,
2254
+ ) -> List[Sticker]:
2255
+ '''
2256
+ Use this method to get custom emoji stickers,
2257
+ which can be used as a forum topic
2258
+ icon by any user. Requires no parameters. Returns
2259
+ an Array of Sticker objects.
2260
+
2261
+ Reference: https://core.telegram.org/bots/api#getforumtopiciconstickers
2262
+ '''
2263
+
2264
+ response = await self._send_request('getForumTopicIconStickers', {})
2265
+ return [Sticker.model_validate(x) for x in response]
2266
+
2267
+ async def create_forum_topic(
2268
+ self,
2269
+ chat_id: Union[int, str],
2270
+ name: str,
2271
+ icon_color: Optional[int] = None,
2272
+ icon_custom_emoji_id: Optional[str] = None,
2273
+ ) -> ForumTopic:
2274
+ '''
2275
+ Use this method to create a topic in
2276
+ a forum supergroup chat. The bot must be
2277
+ an administrator in the chat for this to
2278
+ work and must have the can_manage_topics administrator rights.
2279
+ Returns information about the created topic as a
2280
+ ForumTopic object.
2281
+
2282
+ Reference: https://core.telegram.org/bots/api#createforumtopic
2283
+ '''
2284
+
2285
+ response = await self._send_request('createForumTopic', {
2286
+ 'chat_id': chat_id,
2287
+ 'name': name,
2288
+ 'icon_color': icon_color,
2289
+ 'icon_custom_emoji_id': icon_custom_emoji_id,
2290
+ })
2291
+ return ForumTopic.model_validate(response)
2292
+
2293
+ async def edit_forum_topic(
2294
+ self,
2295
+ chat_id: Union[int, str],
2296
+ message_thread_id: int,
2297
+ name: Optional[str] = None,
2298
+ icon_custom_emoji_id: Optional[str] = None,
2299
+ ) -> bool:
2300
+ '''
2301
+ Use this method to edit name and icon
2302
+ of a topic in a forum supergroup chat.
2303
+ The bot must be an administrator in the
2304
+ chat for this to work and must have
2305
+ the can_manage_topics administrator rights, unless it is the
2306
+ creator of the topic. Returns True on success.
2307
+
2308
+ Reference: https://core.telegram.org/bots/api#editforumtopic
2309
+ '''
2310
+
2311
+ response = await self._send_request('editForumTopic', {
2312
+ 'chat_id': chat_id,
2313
+ 'message_thread_id': message_thread_id,
2314
+ 'name': name,
2315
+ 'icon_custom_emoji_id': icon_custom_emoji_id,
2316
+ })
2317
+ return BoolAdapter.validate_python(response)
2318
+
2319
+ async def close_forum_topic(
2320
+ self,
2321
+ chat_id: Union[int, str],
2322
+ message_thread_id: int,
2323
+ ) -> bool:
2324
+ '''
2325
+ Use this method to close an open topic
2326
+ in a forum supergroup chat. The bot must
2327
+ be an administrator in the chat for this
2328
+ to work and must have the can_manage_topics administrator
2329
+ rights, unless it is the creator of the
2330
+ topic. Returns True on success.
2331
+
2332
+ Reference: https://core.telegram.org/bots/api#closeforumtopic
2333
+ '''
2334
+
2335
+ response = await self._send_request('closeForumTopic', {
2336
+ 'chat_id': chat_id,
2337
+ 'message_thread_id': message_thread_id,
2338
+ })
2339
+ return BoolAdapter.validate_python(response)
2340
+
2341
+ async def reopen_forum_topic(
2342
+ self,
2343
+ chat_id: Union[int, str],
2344
+ message_thread_id: int,
2345
+ ) -> bool:
2346
+ '''
2347
+ Use this method to reopen a closed topic
2348
+ in a forum supergroup chat. The bot must
2349
+ be an administrator in the chat for this
2350
+ to work and must have the can_manage_topics administrator
2351
+ rights, unless it is the creator of the
2352
+ topic. Returns True on success.
2353
+
2354
+ Reference: https://core.telegram.org/bots/api#reopenforumtopic
2355
+ '''
2356
+
2357
+ response = await self._send_request('reopenForumTopic', {
2358
+ 'chat_id': chat_id,
2359
+ 'message_thread_id': message_thread_id,
2360
+ })
2361
+ return BoolAdapter.validate_python(response)
2362
+
2363
+ async def delete_forum_topic(
2364
+ self,
2365
+ chat_id: Union[int, str],
2366
+ message_thread_id: int,
2367
+ ) -> bool:
2368
+ '''
2369
+ Use this method to delete a forum topic
2370
+ along with all its messages in a forum
2371
+ supergroup chat. The bot must be an administrator
2372
+ in the chat for this to work and
2373
+ must have the can_delete_messages administrator rights. Returns True
2374
+ on success.
2375
+
2376
+ Reference: https://core.telegram.org/bots/api#deleteforumtopic
2377
+ '''
2378
+
2379
+ response = await self._send_request('deleteForumTopic', {
2380
+ 'chat_id': chat_id,
2381
+ 'message_thread_id': message_thread_id,
2382
+ })
2383
+ return BoolAdapter.validate_python(response)
2384
+
2385
+ async def unpin_all_forum_topic_messages(
2386
+ self,
2387
+ chat_id: Union[int, str],
2388
+ message_thread_id: int,
2389
+ ) -> bool:
2390
+ '''
2391
+ Use this method to clear the list of
2392
+ pinned messages in a forum topic. The bot
2393
+ must be an administrator in the chat for
2394
+ this to work and must have the can_pin_messages
2395
+ administrator right in the supergroup. Returns True on
2396
+ success.
2397
+
2398
+ Reference: https://core.telegram.org/bots/api#unpinallforumtopicmessages
2399
+ '''
2400
+
2401
+ response = await self._send_request('unpinAllForumTopicMessages', {
2402
+ 'chat_id': chat_id,
2403
+ 'message_thread_id': message_thread_id,
2404
+ })
2405
+ return BoolAdapter.validate_python(response)
2406
+
2407
+ async def edit_general_forum_topic(
2408
+ self,
2409
+ chat_id: Union[int, str],
2410
+ name: str,
2411
+ ) -> bool:
2412
+ '''
2413
+ Use this method to edit the name of
2414
+ the 'General' topic in a forum supergroup chat.
2415
+ The bot must be an administrator in the
2416
+ chat for this to work and must have
2417
+ the can_manage_topics administrator rights. Returns True on success.
2418
+
2419
+ Reference: https://core.telegram.org/bots/api#editgeneralforumtopic
2420
+ '''
2421
+
2422
+ response = await self._send_request('editGeneralForumTopic', {
2423
+ 'chat_id': chat_id,
2424
+ 'name': name,
2425
+ })
2426
+ return BoolAdapter.validate_python(response)
2427
+
2428
+ async def close_general_forum_topic(
2429
+ self,
2430
+ chat_id: Union[int, str],
2431
+ ) -> bool:
2432
+ '''
2433
+ Use this method to close an open 'General'
2434
+ topic in a forum supergroup chat. The bot
2435
+ must be an administrator in the chat for
2436
+ this to work and must have the can_manage_topics
2437
+ administrator rights. Returns True on success.
2438
+
2439
+ Reference: https://core.telegram.org/bots/api#closegeneralforumtopic
2440
+ '''
2441
+
2442
+ response = await self._send_request('closeGeneralForumTopic', {
2443
+ 'chat_id': chat_id,
2444
+ })
2445
+ return BoolAdapter.validate_python(response)
2446
+
2447
+ async def reopen_general_forum_topic(
2448
+ self,
2449
+ chat_id: Union[int, str],
2450
+ ) -> bool:
2451
+ '''
2452
+ Use this method to reopen a closed 'General'
2453
+ topic in a forum supergroup chat. The bot
2454
+ must be an administrator in the chat for
2455
+ this to work and must have the can_manage_topics
2456
+ administrator rights. The topic will be automatically unhidden
2457
+ if it was hidden. Returns True on success.
2458
+
2459
+ Reference: https://core.telegram.org/bots/api#reopengeneralforumtopic
2460
+ '''
2461
+
2462
+ response = await self._send_request('reopenGeneralForumTopic', {
2463
+ 'chat_id': chat_id,
2464
+ })
2465
+ return BoolAdapter.validate_python(response)
2466
+
2467
+ async def hide_general_forum_topic(
2468
+ self,
2469
+ chat_id: Union[int, str],
2470
+ ) -> bool:
2471
+ '''
2472
+ Use this method to hide the 'General' topic
2473
+ in a forum supergroup chat. The bot must
2474
+ be an administrator in the chat for this
2475
+ to work and must have the can_manage_topics administrator
2476
+ rights. The topic will be automatically closed if
2477
+ it was open. Returns True on success.
2478
+
2479
+ Reference: https://core.telegram.org/bots/api#hidegeneralforumtopic
2480
+ '''
2481
+
2482
+ response = await self._send_request('hideGeneralForumTopic', {
2483
+ 'chat_id': chat_id,
2484
+ })
2485
+ return BoolAdapter.validate_python(response)
2486
+
2487
+ async def unhide_general_forum_topic(
2488
+ self,
2489
+ chat_id: Union[int, str],
2490
+ ) -> bool:
2491
+ '''
2492
+ Use this method to unhide the 'General' topic
2493
+ in a forum supergroup chat. The bot must
2494
+ be an administrator in the chat for this
2495
+ to work and must have the can_manage_topics administrator
2496
+ rights. Returns True on success.
2497
+
2498
+ Reference: https://core.telegram.org/bots/api#unhidegeneralforumtopic
2499
+ '''
2500
+
2501
+ response = await self._send_request('unhideGeneralForumTopic', {
2502
+ 'chat_id': chat_id,
2503
+ })
2504
+ return BoolAdapter.validate_python(response)
2505
+
2506
+ async def unpin_all_general_forum_topic_messages(
2507
+ self,
2508
+ chat_id: Union[int, str],
2509
+ ) -> bool:
2510
+ '''
2511
+ Use this method to clear the list of
2512
+ pinned messages in a General forum topic. The
2513
+ bot must be an administrator in the chat
2514
+ for this to work and must have the
2515
+ can_pin_messages administrator right in the supergroup. Returns True
2516
+ on success.
2517
+
2518
+ Reference: https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
2519
+ '''
2520
+
2521
+ response = await self._send_request('unpinAllGeneralForumTopicMessages', {
2522
+ 'chat_id': chat_id,
2523
+ })
2524
+ return BoolAdapter.validate_python(response)
2525
+
2526
+ async def answer_callback_query(
2527
+ self,
2528
+ callback_query_id: str,
2529
+ text: Optional[str] = None,
2530
+ show_alert: Optional[bool] = None,
2531
+ url: Optional[str] = None,
2532
+ cache_time: Optional[int] = None,
2533
+ ) -> bool:
2534
+ '''
2535
+ Use this method to send answers to callback
2536
+ queries sent from inline keyboards. The answer will
2537
+ be displayed to the user as a notification
2538
+ at the top of the chat screen or
2539
+ as an alert. On success, True is returned.
2540
+
2541
+ Reference: https://core.telegram.org/bots/api#answercallbackquery
2542
+ '''
2543
+
2544
+ response = await self._send_request('answerCallbackQuery', {
2545
+ 'callback_query_id': callback_query_id,
2546
+ 'text': text,
2547
+ 'show_alert': show_alert,
2548
+ 'url': url,
2549
+ 'cache_time': cache_time,
2550
+ })
2551
+ return BoolAdapter.validate_python(response)
2552
+
2553
+ async def get_user_chat_boosts(
2554
+ self,
2555
+ chat_id: Union[int, str],
2556
+ user_id: int,
2557
+ ) -> UserChatBoosts:
2558
+ '''
2559
+ Use this method to get the list of
2560
+ boosts added to a chat by a user.
2561
+ Requires administrator rights in the chat. Returns a
2562
+ UserChatBoosts object.
2563
+
2564
+ Reference: https://core.telegram.org/bots/api#getuserchatboosts
2565
+ '''
2566
+
2567
+ response = await self._send_request('getUserChatBoosts', {
2568
+ 'chat_id': chat_id,
2569
+ 'user_id': user_id,
2570
+ })
2571
+ return UserChatBoosts.model_validate(response)
2572
+
2573
+ async def get_business_connection(
2574
+ self,
2575
+ business_connection_id: str,
2576
+ ) -> BusinessConnection:
2577
+ '''
2578
+ Use this method to get information about the
2579
+ connection of the bot with a business account.
2580
+ Returns a BusinessConnection object on success.
2581
+
2582
+ Reference: https://core.telegram.org/bots/api#getbusinessconnection
2583
+ '''
2584
+
2585
+ response = await self._send_request('getBusinessConnection', {
2586
+ 'business_connection_id': business_connection_id,
2587
+ })
2588
+ return BusinessConnection.model_validate(response)
2589
+
2590
+ async def set_my_commands(
2591
+ self,
2592
+ commands: List[BotCommand],
2593
+ scope: Optional[BotCommandScope] = None,
2594
+ language_code: Optional[str] = None,
2595
+ ) -> bool:
2596
+ '''
2597
+ Use this method to change the list of
2598
+ the bot's commands. See this manual for more
2599
+ details about bot commands. Returns True on success.
2600
+
2601
+ Reference: https://core.telegram.org/bots/api#setmycommands
2602
+ '''
2603
+
2604
+ response = await self._send_request('setMyCommands', {
2605
+ 'commands': commands,
2606
+ 'scope': scope,
2607
+ 'language_code': language_code,
2608
+ })
2609
+ return BoolAdapter.validate_python(response)
2610
+
2611
+ async def delete_my_commands(
2612
+ self,
2613
+ scope: Optional[BotCommandScope] = None,
2614
+ language_code: Optional[str] = None,
2615
+ ) -> bool:
2616
+ '''
2617
+ Use this method to delete the list of
2618
+ the bot's commands for the given scope and
2619
+ user language. After deletion, higher level commands will
2620
+ be shown to affected users. Returns True on
2621
+ success.
2622
+
2623
+ Reference: https://core.telegram.org/bots/api#deletemycommands
2624
+ '''
2625
+
2626
+ response = await self._send_request('deleteMyCommands', {
2627
+ 'scope': scope,
2628
+ 'language_code': language_code,
2629
+ })
2630
+ return BoolAdapter.validate_python(response)
2631
+
2632
+ async def get_my_commands(
2633
+ self,
2634
+ scope: Optional[BotCommandScope] = None,
2635
+ language_code: Optional[str] = None,
2636
+ ) -> List[BotCommand]:
2637
+ '''
2638
+ Use this method to get the current list
2639
+ of the bot's commands for the given scope
2640
+ and user language. Returns an Array of BotCommand
2641
+ objects. If commands aren't set, an empty list
2642
+ is returned.
2643
+
2644
+ Reference: https://core.telegram.org/bots/api#getmycommands
2645
+ '''
2646
+
2647
+ response = await self._send_request('getMyCommands', {
2648
+ 'scope': scope,
2649
+ 'language_code': language_code,
2650
+ })
2651
+ return [BotCommand.model_validate(x) for x in response]
2652
+
2653
+ async def set_my_name(
2654
+ self,
2655
+ name: Optional[str] = None,
2656
+ language_code: Optional[str] = None,
2657
+ ) -> bool:
2658
+ '''
2659
+ Use this method to change the bot's name.
2660
+ Returns True on success.
2661
+
2662
+ Reference: https://core.telegram.org/bots/api#setmyname
2663
+ '''
2664
+
2665
+ response = await self._send_request('setMyName', {
2666
+ 'name': name,
2667
+ 'language_code': language_code,
2668
+ })
2669
+ return BoolAdapter.validate_python(response)
2670
+
2671
+ async def get_my_name(
2672
+ self,
2673
+ language_code: Optional[str] = None,
2674
+ ) -> BotName:
2675
+ '''
2676
+ Use this method to get the current bot
2677
+ name for the given user language. Returns BotName
2678
+ on success.
2679
+
2680
+ Reference: https://core.telegram.org/bots/api#getmyname
2681
+ '''
2682
+
2683
+ response = await self._send_request('getMyName', {
2684
+ 'language_code': language_code,
2685
+ })
2686
+ return BotName.model_validate(response)
2687
+
2688
+ async def set_my_description(
2689
+ self,
2690
+ description: Optional[str] = None,
2691
+ language_code: Optional[str] = None,
2692
+ ) -> bool:
2693
+ '''
2694
+ Use this method to change the bot's description,
2695
+ which is shown in the chat with the
2696
+ bot if the chat is empty. Returns True
2697
+ on success.
2698
+
2699
+ Reference: https://core.telegram.org/bots/api#setmydescription
2700
+ '''
2701
+
2702
+ response = await self._send_request('setMyDescription', {
2703
+ 'description': description,
2704
+ 'language_code': language_code,
2705
+ })
2706
+ return BoolAdapter.validate_python(response)
2707
+
2708
+ async def get_my_description(
2709
+ self,
2710
+ language_code: Optional[str] = None,
2711
+ ) -> BotDescription:
2712
+ '''
2713
+ Use this method to get the current bot
2714
+ description for the given user language. Returns BotDescription
2715
+ on success.
2716
+
2717
+ Reference: https://core.telegram.org/bots/api#getmydescription
2718
+ '''
2719
+
2720
+ response = await self._send_request('getMyDescription', {
2721
+ 'language_code': language_code,
2722
+ })
2723
+ return BotDescription.model_validate(response)
2724
+
2725
+ async def set_my_short_description(
2726
+ self,
2727
+ short_description: Optional[str] = None,
2728
+ language_code: Optional[str] = None,
2729
+ ) -> bool:
2730
+ '''
2731
+ Use this method to change the bot's short
2732
+ description, which is shown on the bot's profile
2733
+ page and is sent together with the link
2734
+ when users share the bot. Returns True on
2735
+ success.
2736
+
2737
+ Reference: https://core.telegram.org/bots/api#setmyshortdescription
2738
+ '''
2739
+
2740
+ response = await self._send_request('setMyShortDescription', {
2741
+ 'short_description': short_description,
2742
+ 'language_code': language_code,
2743
+ })
2744
+ return BoolAdapter.validate_python(response)
2745
+
2746
+ async def get_my_short_description(
2747
+ self,
2748
+ language_code: Optional[str] = None,
2749
+ ) -> BotShortDescription:
2750
+ '''
2751
+ Use this method to get the current bot
2752
+ short description for the given user language. Returns
2753
+ BotShortDescription on success.
2754
+
2755
+ Reference: https://core.telegram.org/bots/api#getmyshortdescription
2756
+ '''
2757
+
2758
+ response = await self._send_request('getMyShortDescription', {
2759
+ 'language_code': language_code,
2760
+ })
2761
+ return BotShortDescription.model_validate(response)
2762
+
2763
+ async def set_chat_menu_button(
2764
+ self,
2765
+ chat_id: Optional[int] = None,
2766
+ menu_button: Optional[MenuButton] = None,
2767
+ ) -> bool:
2768
+ '''
2769
+ Use this method to change the bot's menu
2770
+ button in a private chat, or the default
2771
+ menu button. Returns True on success.
2772
+
2773
+ Reference: https://core.telegram.org/bots/api#setchatmenubutton
2774
+ '''
2775
+
2776
+ response = await self._send_request('setChatMenuButton', {
2777
+ 'chat_id': chat_id,
2778
+ 'menu_button': menu_button,
2779
+ })
2780
+ return BoolAdapter.validate_python(response)
2781
+
2782
+ async def get_chat_menu_button(
2783
+ self,
2784
+ chat_id: Optional[int] = None,
2785
+ ) -> MenuButton:
2786
+ '''
2787
+ Use this method to get the current value
2788
+ of the bot's menu button in a private
2789
+ chat, or the default menu button. Returns MenuButton
2790
+ on success.
2791
+
2792
+ Reference: https://core.telegram.org/bots/api#getchatmenubutton
2793
+ '''
2794
+
2795
+ response = await self._send_request('getChatMenuButton', {
2796
+ 'chat_id': chat_id,
2797
+ })
2798
+ return MenuButtonAdapter.validate_python(response)
2799
+
2800
+ async def set_my_default_administrator_rights(
2801
+ self,
2802
+ rights: Optional[ChatAdministratorRights] = None,
2803
+ for_channels: Optional[bool] = None,
2804
+ ) -> bool:
2805
+ '''
2806
+ Use this method to change the default administrator
2807
+ rights requested by the bot when it's added
2808
+ as an administrator to groups or channels. These
2809
+ rights will be suggested to users, but they
2810
+ are free to modify the list before adding
2811
+ the bot. Returns True on success.
2812
+
2813
+ Reference: https://core.telegram.org/bots/api#setmydefaultadministratorrights
2814
+ '''
2815
+
2816
+ response = await self._send_request('setMyDefaultAdministratorRights', {
2817
+ 'rights': rights,
2818
+ 'for_channels': for_channels,
2819
+ })
2820
+ return BoolAdapter.validate_python(response)
2821
+
2822
+ async def get_my_default_administrator_rights(
2823
+ self,
2824
+ for_channels: Optional[bool] = None,
2825
+ ) -> ChatAdministratorRights:
2826
+ '''
2827
+ Use this method to get the current default
2828
+ administrator rights of the bot. Returns ChatAdministratorRights on
2829
+ success.
2830
+
2831
+ Reference: https://core.telegram.org/bots/api#getmydefaultadministratorrights
2832
+ '''
2833
+
2834
+ response = await self._send_request('getMyDefaultAdministratorRights', {
2835
+ 'for_channels': for_channels,
2836
+ })
2837
+ return ChatAdministratorRights.model_validate(response)
2838
+
2839
+ async def get_available_gifts(
2840
+ self,
2841
+ ) -> Gifts:
2842
+ '''
2843
+ Returns the list of gifts that can be
2844
+ sent by the bot to users and channel
2845
+ chats. Requires no parameters. Returns a Gifts object.
2846
+
2847
+ Reference: https://core.telegram.org/bots/api#getavailablegifts
2848
+ '''
2849
+
2850
+ response = await self._send_request('getAvailableGifts', {})
2851
+ return Gifts.model_validate(response)
2852
+
2853
+ async def send_gift(
2854
+ self,
2855
+ gift_id: str,
2856
+ user_id: Optional[int] = None,
2857
+ chat_id: Optional[Union[int, str]] = None,
2858
+ pay_for_upgrade: Optional[bool] = None,
2859
+ text: Optional[str] = None,
2860
+ text_parse_mode: Optional[str] = None,
2861
+ text_entities: Optional[List[MessageEntity]] = None,
2862
+ ) -> bool:
2863
+ '''
2864
+ Sends a gift to the given user or
2865
+ channel chat. The gift can't be converted to
2866
+ Telegram Stars by the receiver. Returns True on
2867
+ success.
2868
+
2869
+ Reference: https://core.telegram.org/bots/api#sendgift
2870
+ '''
2871
+
2872
+ response = await self._send_request('sendGift', {
2873
+ 'user_id': user_id,
2874
+ 'chat_id': chat_id,
2875
+ 'gift_id': gift_id,
2876
+ 'pay_for_upgrade': pay_for_upgrade,
2877
+ 'text': text,
2878
+ 'text_parse_mode': text_parse_mode,
2879
+ 'text_entities': text_entities,
2880
+ })
2881
+ return BoolAdapter.validate_python(response)
2882
+
2883
+ async def gift_premium_subscription(
2884
+ self,
2885
+ user_id: int,
2886
+ month_count: int,
2887
+ star_count: int,
2888
+ text: Optional[str] = None,
2889
+ text_parse_mode: Optional[str] = None,
2890
+ text_entities: Optional[List[MessageEntity]] = None,
2891
+ ) -> bool:
2892
+ '''
2893
+ Gifts a Telegram Premium subscription to the given
2894
+ user. Returns True on success.
2895
+
2896
+ Reference: https://core.telegram.org/bots/api#giftpremiumsubscription
2897
+ '''
2898
+
2899
+ response = await self._send_request('giftPremiumSubscription', {
2900
+ 'user_id': user_id,
2901
+ 'month_count': month_count,
2902
+ 'star_count': star_count,
2903
+ 'text': text,
2904
+ 'text_parse_mode': text_parse_mode,
2905
+ 'text_entities': text_entities,
2906
+ })
2907
+ return BoolAdapter.validate_python(response)
2908
+
2909
+ async def verify_user(
2910
+ self,
2911
+ user_id: int,
2912
+ custom_description: Optional[str] = None,
2913
+ ) -> bool:
2914
+ '''
2915
+ Verifies a user on behalf of the organization
2916
+ which is represented by the bot. Returns True
2917
+ on success.
2918
+
2919
+ Reference: https://core.telegram.org/bots/api#verifyuser
2920
+ '''
2921
+
2922
+ response = await self._send_request('verifyUser', {
2923
+ 'user_id': user_id,
2924
+ 'custom_description': custom_description,
2925
+ })
2926
+ return BoolAdapter.validate_python(response)
2927
+
2928
+ async def verify_chat(
2929
+ self,
2930
+ chat_id: Union[int, str],
2931
+ custom_description: Optional[str] = None,
2932
+ ) -> bool:
2933
+ '''
2934
+ Verifies a chat on behalf of the organization
2935
+ which is represented by the bot. Returns True
2936
+ on success.
2937
+
2938
+ Reference: https://core.telegram.org/bots/api#verifychat
2939
+ '''
2940
+
2941
+ response = await self._send_request('verifyChat', {
2942
+ 'chat_id': chat_id,
2943
+ 'custom_description': custom_description,
2944
+ })
2945
+ return BoolAdapter.validate_python(response)
2946
+
2947
+ async def remove_user_verification(
2948
+ self,
2949
+ user_id: int,
2950
+ ) -> bool:
2951
+ '''
2952
+ Removes verification from a user who is currently
2953
+ verified on behalf of the organization represented by
2954
+ the bot. Returns True on success.
2955
+
2956
+ Reference: https://core.telegram.org/bots/api#removeuserverification
2957
+ '''
2958
+
2959
+ response = await self._send_request('removeUserVerification', {
2960
+ 'user_id': user_id,
2961
+ })
2962
+ return BoolAdapter.validate_python(response)
2963
+
2964
+ async def remove_chat_verification(
2965
+ self,
2966
+ chat_id: Union[int, str],
2967
+ ) -> bool:
2968
+ '''
2969
+ Removes verification from a chat that is currently
2970
+ verified on behalf of the organization represented by
2971
+ the bot. Returns True on success.
2972
+
2973
+ Reference: https://core.telegram.org/bots/api#removechatverification
2974
+ '''
2975
+
2976
+ response = await self._send_request('removeChatVerification', {
2977
+ 'chat_id': chat_id,
2978
+ })
2979
+ return BoolAdapter.validate_python(response)
2980
+
2981
+ async def read_business_message(
2982
+ self,
2983
+ business_connection_id: str,
2984
+ chat_id: int,
2985
+ message_id: int,
2986
+ ) -> bool:
2987
+ '''
2988
+ Marks incoming message as read on behalf of
2989
+ a business account. Requires the can_read_messages business bot
2990
+ right. Returns True on success.
2991
+
2992
+ Reference: https://core.telegram.org/bots/api#readbusinessmessage
2993
+ '''
2994
+
2995
+ response = await self._send_request('readBusinessMessage', {
2996
+ 'business_connection_id': business_connection_id,
2997
+ 'chat_id': chat_id,
2998
+ 'message_id': message_id,
2999
+ })
3000
+ return BoolAdapter.validate_python(response)
3001
+
3002
+ async def delete_business_messages(
3003
+ self,
3004
+ business_connection_id: str,
3005
+ message_ids: List[int],
3006
+ ) -> bool:
3007
+ '''
3008
+ Delete messages on behalf of a business account.
3009
+ Requires the can_delete_sent_messages business bot right to delete
3010
+ messages sent by the bot itself, or the
3011
+ can_delete_all_messages business bot right to delete any message.
3012
+ Returns True on success.
3013
+
3014
+ Reference: https://core.telegram.org/bots/api#deletebusinessmessages
3015
+ '''
3016
+
3017
+ response = await self._send_request('deleteBusinessMessages', {
3018
+ 'business_connection_id': business_connection_id,
3019
+ 'message_ids': message_ids,
3020
+ })
3021
+ return BoolAdapter.validate_python(response)
3022
+
3023
+ async def set_business_account_name(
3024
+ self,
3025
+ business_connection_id: str,
3026
+ first_name: str,
3027
+ last_name: Optional[str] = None,
3028
+ ) -> bool:
3029
+ '''
3030
+ Changes the first and last name of a
3031
+ managed business account. Requires the can_change_name business bot
3032
+ right. Returns True on success.
3033
+
3034
+ Reference: https://core.telegram.org/bots/api#setbusinessaccountname
3035
+ '''
3036
+
3037
+ response = await self._send_request('setBusinessAccountName', {
3038
+ 'business_connection_id': business_connection_id,
3039
+ 'first_name': first_name,
3040
+ 'last_name': last_name,
3041
+ })
3042
+ return BoolAdapter.validate_python(response)
3043
+
3044
+ async def set_business_account_username(
3045
+ self,
3046
+ business_connection_id: str,
3047
+ username: Optional[str] = None,
3048
+ ) -> bool:
3049
+ '''
3050
+ Changes the username of a managed business account.
3051
+ Requires the can_change_username business bot right. Returns True
3052
+ on success.
3053
+
3054
+ Reference: https://core.telegram.org/bots/api#setbusinessaccountusername
3055
+ '''
3056
+
3057
+ response = await self._send_request('setBusinessAccountUsername', {
3058
+ 'business_connection_id': business_connection_id,
3059
+ 'username': username,
3060
+ })
3061
+ return BoolAdapter.validate_python(response)
3062
+
3063
+ async def set_business_account_bio(
3064
+ self,
3065
+ business_connection_id: str,
3066
+ bio: Optional[str] = None,
3067
+ ) -> bool:
3068
+ '''
3069
+ Changes the bio of a managed business account.
3070
+ Requires the can_change_bio business bot right. Returns True
3071
+ on success.
3072
+
3073
+ Reference: https://core.telegram.org/bots/api#setbusinessaccountbio
3074
+ '''
3075
+
3076
+ response = await self._send_request('setBusinessAccountBio', {
3077
+ 'business_connection_id': business_connection_id,
3078
+ 'bio': bio,
3079
+ })
3080
+ return BoolAdapter.validate_python(response)
3081
+
3082
+ async def set_business_account_profile_photo(
3083
+ self,
3084
+ business_connection_id: str,
3085
+ photo: InputProfilePhoto,
3086
+ is_public: Optional[bool] = None,
3087
+ ) -> bool:
3088
+ '''
3089
+ Changes the profile photo of a managed business
3090
+ account. Requires the can_edit_profile_photo business bot right. Returns
3091
+ True on success.
3092
+
3093
+ Reference: https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
3094
+ '''
3095
+
3096
+ response = await self._send_request('setBusinessAccountProfilePhoto', {
3097
+ 'business_connection_id': business_connection_id,
3098
+ 'photo': photo,
3099
+ 'is_public': is_public,
3100
+ })
3101
+ return BoolAdapter.validate_python(response)
3102
+
3103
+ async def remove_business_account_profile_photo(
3104
+ self,
3105
+ business_connection_id: str,
3106
+ is_public: Optional[bool] = None,
3107
+ ) -> bool:
3108
+ '''
3109
+ Removes the current profile photo of a managed
3110
+ business account. Requires the can_edit_profile_photo business bot right.
3111
+ Returns True on success.
3112
+
3113
+ Reference: https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
3114
+ '''
3115
+
3116
+ response = await self._send_request('removeBusinessAccountProfilePhoto', {
3117
+ 'business_connection_id': business_connection_id,
3118
+ 'is_public': is_public,
3119
+ })
3120
+ return BoolAdapter.validate_python(response)
3121
+
3122
+ async def set_business_account_gift_settings(
3123
+ self,
3124
+ business_connection_id: str,
3125
+ show_gift_button: bool,
3126
+ accepted_gift_types: AcceptedGiftTypes,
3127
+ ) -> bool:
3128
+ '''
3129
+ Changes the privacy settings pertaining to incoming gifts
3130
+ in a managed business account. Requires the can_change_gift_settings
3131
+ business bot right. Returns True on success.
3132
+
3133
+ Reference: https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
3134
+ '''
3135
+
3136
+ response = await self._send_request('setBusinessAccountGiftSettings', {
3137
+ 'business_connection_id': business_connection_id,
3138
+ 'show_gift_button': show_gift_button,
3139
+ 'accepted_gift_types': accepted_gift_types,
3140
+ })
3141
+ return BoolAdapter.validate_python(response)
3142
+
3143
+ async def get_business_account_star_balance(
3144
+ self,
3145
+ business_connection_id: str,
3146
+ ) -> StarAmount:
3147
+ '''
3148
+ Returns the amount of Telegram Stars owned by
3149
+ a managed business account. Requires the can_view_gifts_and_stars business
3150
+ bot right. Returns StarAmount on success.
3151
+
3152
+ Reference: https://core.telegram.org/bots/api#getbusinessaccountstarbalance
3153
+ '''
3154
+
3155
+ response = await self._send_request('getBusinessAccountStarBalance', {
3156
+ 'business_connection_id': business_connection_id,
3157
+ })
3158
+ return StarAmount.model_validate(response)
3159
+
3160
+ async def transfer_business_account_stars(
3161
+ self,
3162
+ business_connection_id: str,
3163
+ star_count: int,
3164
+ ) -> bool:
3165
+ '''
3166
+ Transfers Telegram Stars from the business account balance
3167
+ to the bot's balance. Requires the can_transfer_stars business
3168
+ bot right. Returns True on success.
3169
+
3170
+ Reference: https://core.telegram.org/bots/api#transferbusinessaccountstars
3171
+ '''
3172
+
3173
+ response = await self._send_request('transferBusinessAccountStars', {
3174
+ 'business_connection_id': business_connection_id,
3175
+ 'star_count': star_count,
3176
+ })
3177
+ return BoolAdapter.validate_python(response)
3178
+
3179
+ async def get_business_account_gifts(
3180
+ self,
3181
+ business_connection_id: str,
3182
+ exclude_unsaved: Optional[bool] = None,
3183
+ exclude_saved: Optional[bool] = None,
3184
+ exclude_unlimited: Optional[bool] = None,
3185
+ exclude_limited: Optional[bool] = None,
3186
+ exclude_unique: Optional[bool] = None,
3187
+ sort_by_price: Optional[bool] = None,
3188
+ offset: Optional[str] = None,
3189
+ limit: Optional[int] = None,
3190
+ ) -> OwnedGifts:
3191
+ '''
3192
+ Returns the gifts received and owned by a
3193
+ managed business account. Requires the can_view_gifts_and_stars business bot
3194
+ right. Returns OwnedGifts on success.
3195
+
3196
+ Reference: https://core.telegram.org/bots/api#getbusinessaccountgifts
3197
+ '''
3198
+
3199
+ response = await self._send_request('getBusinessAccountGifts', {
3200
+ 'business_connection_id': business_connection_id,
3201
+ 'exclude_unsaved': exclude_unsaved,
3202
+ 'exclude_saved': exclude_saved,
3203
+ 'exclude_unlimited': exclude_unlimited,
3204
+ 'exclude_limited': exclude_limited,
3205
+ 'exclude_unique': exclude_unique,
3206
+ 'sort_by_price': sort_by_price,
3207
+ 'offset': offset,
3208
+ 'limit': limit,
3209
+ })
3210
+ return OwnedGifts.model_validate(response)
3211
+
3212
+ async def convert_gift_to_stars(
3213
+ self,
3214
+ business_connection_id: str,
3215
+ owned_gift_id: str,
3216
+ ) -> bool:
3217
+ '''
3218
+ Converts a given regular gift to Telegram Stars.
3219
+ Requires the can_convert_gifts_to_stars business bot right. Returns True
3220
+ on success.
3221
+
3222
+ Reference: https://core.telegram.org/bots/api#convertgifttostars
3223
+ '''
3224
+
3225
+ response = await self._send_request('convertGiftToStars', {
3226
+ 'business_connection_id': business_connection_id,
3227
+ 'owned_gift_id': owned_gift_id,
3228
+ })
3229
+ return BoolAdapter.validate_python(response)
3230
+
3231
+ async def upgrade_gift(
3232
+ self,
3233
+ business_connection_id: str,
3234
+ owned_gift_id: str,
3235
+ keep_original_details: Optional[bool] = None,
3236
+ star_count: Optional[int] = None,
3237
+ ) -> bool:
3238
+ '''
3239
+ Upgrades a given regular gift to a unique
3240
+ gift. Requires the can_transfer_and_upgrade_gifts business bot right. Additionally
3241
+ requires the can_transfer_stars business bot right if the
3242
+ upgrade is paid. Returns True on success.
3243
+
3244
+ Reference: https://core.telegram.org/bots/api#upgradegift
3245
+ '''
3246
+
3247
+ response = await self._send_request('upgradeGift', {
3248
+ 'business_connection_id': business_connection_id,
3249
+ 'owned_gift_id': owned_gift_id,
3250
+ 'keep_original_details': keep_original_details,
3251
+ 'star_count': star_count,
3252
+ })
3253
+ return BoolAdapter.validate_python(response)
3254
+
3255
+ async def transfer_gift(
3256
+ self,
3257
+ business_connection_id: str,
3258
+ owned_gift_id: str,
3259
+ new_owner_chat_id: int,
3260
+ star_count: Optional[int] = None,
3261
+ ) -> bool:
3262
+ '''
3263
+ Transfers an owned unique gift to another user.
3264
+ Requires the can_transfer_and_upgrade_gifts business bot right. Requires can_transfer_stars
3265
+ business bot right if the transfer is paid.
3266
+ Returns True on success.
3267
+
3268
+ Reference: https://core.telegram.org/bots/api#transfergift
3269
+ '''
3270
+
3271
+ response = await self._send_request('transferGift', {
3272
+ 'business_connection_id': business_connection_id,
3273
+ 'owned_gift_id': owned_gift_id,
3274
+ 'new_owner_chat_id': new_owner_chat_id,
3275
+ 'star_count': star_count,
3276
+ })
3277
+ return BoolAdapter.validate_python(response)
3278
+
3279
+ async def post_story(
3280
+ self,
3281
+ business_connection_id: str,
3282
+ content: InputStoryContent,
3283
+ active_period: int,
3284
+ caption: Optional[str] = None,
3285
+ parse_mode: Optional[str] = 'HTML',
3286
+ caption_entities: Optional[List[MessageEntity]] = None,
3287
+ areas: Optional[List[StoryArea]] = None,
3288
+ post_to_chat_page: Optional[bool] = None,
3289
+ protect_content: Optional[bool] = None,
3290
+ ) -> Story:
3291
+ '''
3292
+ Posts a story on behalf of a managed
3293
+ business account. Requires the can_manage_stories business bot right.
3294
+ Returns Story on success.
3295
+
3296
+ Reference: https://core.telegram.org/bots/api#poststory
3297
+ '''
3298
+
3299
+ response = await self._send_request('postStory', {
3300
+ 'business_connection_id': business_connection_id,
3301
+ 'content': content,
3302
+ 'active_period': active_period,
3303
+ 'caption': caption,
3304
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
3305
+ 'caption_entities': caption_entities,
3306
+ 'areas': areas,
3307
+ 'post_to_chat_page': post_to_chat_page,
3308
+ 'protect_content': protect_content,
3309
+ })
3310
+ return Story.model_validate(response)
3311
+
3312
+ async def edit_story(
3313
+ self,
3314
+ business_connection_id: str,
3315
+ story_id: int,
3316
+ content: InputStoryContent,
3317
+ caption: Optional[str] = None,
3318
+ parse_mode: Optional[str] = 'HTML',
3319
+ caption_entities: Optional[List[MessageEntity]] = None,
3320
+ areas: Optional[List[StoryArea]] = None,
3321
+ ) -> Story:
3322
+ '''
3323
+ Edits a story previously posted by the bot
3324
+ on behalf of a managed business account. Requires
3325
+ the can_manage_stories business bot right. Returns Story on
3326
+ success.
3327
+
3328
+ Reference: https://core.telegram.org/bots/api#editstory
3329
+ '''
3330
+
3331
+ response = await self._send_request('editStory', {
3332
+ 'business_connection_id': business_connection_id,
3333
+ 'story_id': story_id,
3334
+ 'content': content,
3335
+ 'caption': caption,
3336
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
3337
+ 'caption_entities': caption_entities,
3338
+ 'areas': areas,
3339
+ })
3340
+ return Story.model_validate(response)
3341
+
3342
+ async def delete_story(
3343
+ self,
3344
+ business_connection_id: str,
3345
+ story_id: int,
3346
+ ) -> bool:
3347
+ '''
3348
+ Deletes a story previously posted by the bot
3349
+ on behalf of a managed business account. Requires
3350
+ the can_manage_stories business bot right. Returns True on
3351
+ success.
3352
+
3353
+ Reference: https://core.telegram.org/bots/api#deletestory
3354
+ '''
3355
+
3356
+ response = await self._send_request('deleteStory', {
3357
+ 'business_connection_id': business_connection_id,
3358
+ 'story_id': story_id,
3359
+ })
3360
+ return BoolAdapter.validate_python(response)
3361
+
3362
+ async def edit_message_text(
3363
+ self,
3364
+ text: str,
3365
+ business_connection_id: Optional[str] = None,
3366
+ chat_id: Optional[Union[int, str]] = None,
3367
+ message_id: Optional[int] = None,
3368
+ inline_message_id: Optional[str] = None,
3369
+ parse_mode: Optional[str] = 'HTML',
3370
+ entities: Optional[List[MessageEntity]] = None,
3371
+ link_preview_options: Optional[LinkPreviewOptions] = None,
3372
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3373
+ ) -> Union[Message, bool]:
3374
+ '''
3375
+ Use this method to edit text and game
3376
+ messages. On success, if the edited message is
3377
+ not an inline message, the edited Message is
3378
+ returned, otherwise True is returned. Note that business
3379
+ messages that were not sent by the bot
3380
+ and do not contain an inline keyboard can
3381
+ only be edited within 48 hours from the
3382
+ time they were sent.
3383
+
3384
+ Reference: https://core.telegram.org/bots/api#editmessagetext
3385
+ '''
3386
+
3387
+ response = await self._send_request('editMessageText', {
3388
+ 'business_connection_id': business_connection_id,
3389
+ 'chat_id': chat_id,
3390
+ 'message_id': message_id,
3391
+ 'inline_message_id': inline_message_id,
3392
+ 'text': text,
3393
+ 'parse_mode': parse_mode if not entities else None, # FIX,
3394
+ 'entities': entities,
3395
+ 'link_preview_options': link_preview_options,
3396
+ 'reply_markup': reply_markup,
3397
+ })
3398
+ if isinstance(response, (dict, list)):
3399
+ return Message.model_validate(response)
3400
+ else:
3401
+ return BoolAdapter.validate_python(response)
3402
+
3403
+ async def edit_message_caption(
3404
+ self,
3405
+ business_connection_id: Optional[str] = None,
3406
+ chat_id: Optional[Union[int, str]] = None,
3407
+ message_id: Optional[int] = None,
3408
+ inline_message_id: Optional[str] = None,
3409
+ caption: Optional[str] = None,
3410
+ parse_mode: Optional[str] = 'HTML',
3411
+ caption_entities: Optional[List[MessageEntity]] = None,
3412
+ show_caption_above_media: Optional[bool] = None,
3413
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3414
+ ) -> Union[Message, bool]:
3415
+ '''
3416
+ Use this method to edit captions of messages.
3417
+ On success, if the edited message is not
3418
+ an inline message, the edited Message is returned,
3419
+ otherwise True is returned. Note that business messages
3420
+ that were not sent by the bot and
3421
+ do not contain an inline keyboard can only
3422
+ be edited within 48 hours from the time
3423
+ they were sent.
3424
+
3425
+ Reference: https://core.telegram.org/bots/api#editmessagecaption
3426
+ '''
3427
+
3428
+ response = await self._send_request('editMessageCaption', {
3429
+ 'business_connection_id': business_connection_id,
3430
+ 'chat_id': chat_id,
3431
+ 'message_id': message_id,
3432
+ 'inline_message_id': inline_message_id,
3433
+ 'caption': caption,
3434
+ 'parse_mode': parse_mode if not caption_entities else None, # FIX,
3435
+ 'caption_entities': caption_entities,
3436
+ 'show_caption_above_media': show_caption_above_media,
3437
+ 'reply_markup': reply_markup,
3438
+ })
3439
+ if isinstance(response, (dict, list)):
3440
+ return Message.model_validate(response)
3441
+ else:
3442
+ return BoolAdapter.validate_python(response)
3443
+
3444
+ async def edit_message_media(
3445
+ self,
3446
+ media: InputMedia,
3447
+ business_connection_id: Optional[str] = None,
3448
+ chat_id: Optional[Union[int, str]] = None,
3449
+ message_id: Optional[int] = None,
3450
+ inline_message_id: Optional[str] = None,
3451
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3452
+ ) -> Union[Message, bool]:
3453
+ '''
3454
+ Use this method to edit animation, audio, document,
3455
+ photo, or video messages, or to add media
3456
+ to text messages. If a message is part
3457
+ of a message album, then it can be
3458
+ edited only to an audio for audio albums,
3459
+ only to a document for document albums and
3460
+ to a photo or a video otherwise. When
3461
+ an inline message is edited, a new file
3462
+ can't be uploaded; use a previously uploaded file
3463
+ via its file_id or specify a URL. On
3464
+ success, if the edited message is not an
3465
+ inline message, the edited Message is returned, otherwise
3466
+ True is returned. Note that business messages that
3467
+ were not sent by the bot and do
3468
+ not contain an inline keyboard can only be
3469
+ edited within 48 hours from the time they
3470
+ were sent.
3471
+
3472
+ Reference: https://core.telegram.org/bots/api#editmessagemedia
3473
+ '''
3474
+
3475
+ response = await self._send_request('editMessageMedia', {
3476
+ 'business_connection_id': business_connection_id,
3477
+ 'chat_id': chat_id,
3478
+ 'message_id': message_id,
3479
+ 'inline_message_id': inline_message_id,
3480
+ 'media': media,
3481
+ 'reply_markup': reply_markup,
3482
+ })
3483
+ if isinstance(response, (dict, list)):
3484
+ return Message.model_validate(response)
3485
+ else:
3486
+ return BoolAdapter.validate_python(response)
3487
+
3488
+ async def edit_message_live_location(
3489
+ self,
3490
+ latitude: float,
3491
+ longitude: float,
3492
+ business_connection_id: Optional[str] = None,
3493
+ chat_id: Optional[Union[int, str]] = None,
3494
+ message_id: Optional[int] = None,
3495
+ inline_message_id: Optional[str] = None,
3496
+ live_period: Optional[int] = None,
3497
+ horizontal_accuracy: Optional[float] = None,
3498
+ heading: Optional[int] = None,
3499
+ proximity_alert_radius: Optional[int] = None,
3500
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3501
+ ) -> Union[Message, bool]:
3502
+ '''
3503
+ Use this method to edit live location messages.
3504
+ A location can be edited until its live_period
3505
+ expires or editing is explicitly disabled by a
3506
+ call to stopMessageLiveLocation. On success, if the edited
3507
+ message is not an inline message, the edited
3508
+ Message is returned, otherwise True is returned.
3509
+
3510
+ Reference: https://core.telegram.org/bots/api#editmessagelivelocation
3511
+ '''
3512
+
3513
+ response = await self._send_request('editMessageLiveLocation', {
3514
+ 'business_connection_id': business_connection_id,
3515
+ 'chat_id': chat_id,
3516
+ 'message_id': message_id,
3517
+ 'inline_message_id': inline_message_id,
3518
+ 'latitude': latitude,
3519
+ 'longitude': longitude,
3520
+ 'live_period': live_period,
3521
+ 'horizontal_accuracy': horizontal_accuracy,
3522
+ 'heading': heading,
3523
+ 'proximity_alert_radius': proximity_alert_radius,
3524
+ 'reply_markup': reply_markup,
3525
+ })
3526
+ if isinstance(response, (dict, list)):
3527
+ return Message.model_validate(response)
3528
+ else:
3529
+ return BoolAdapter.validate_python(response)
3530
+
3531
+ async def stop_message_live_location(
3532
+ self,
3533
+ business_connection_id: Optional[str] = None,
3534
+ chat_id: Optional[Union[int, str]] = None,
3535
+ message_id: Optional[int] = None,
3536
+ inline_message_id: Optional[str] = None,
3537
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3538
+ ) -> Union[Message, bool]:
3539
+ '''
3540
+ Use this method to stop updating a live
3541
+ location message before live_period expires. On success, if
3542
+ the message is not an inline message, the
3543
+ edited Message is returned, otherwise True is returned.
3544
+
3545
+ Reference: https://core.telegram.org/bots/api#stopmessagelivelocation
3546
+ '''
3547
+
3548
+ response = await self._send_request('stopMessageLiveLocation', {
3549
+ 'business_connection_id': business_connection_id,
3550
+ 'chat_id': chat_id,
3551
+ 'message_id': message_id,
3552
+ 'inline_message_id': inline_message_id,
3553
+ 'reply_markup': reply_markup,
3554
+ })
3555
+ if isinstance(response, (dict, list)):
3556
+ return Message.model_validate(response)
3557
+ else:
3558
+ return BoolAdapter.validate_python(response)
3559
+
3560
+ async def edit_message_checklist(
3561
+ self,
3562
+ business_connection_id: str,
3563
+ chat_id: int,
3564
+ message_id: int,
3565
+ checklist: InputChecklist,
3566
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3567
+ ) -> Message:
3568
+ '''
3569
+ Use this method to edit a checklist on
3570
+ behalf of a connected business account. On success,
3571
+ the edited Message is returned.
3572
+
3573
+ Reference: https://core.telegram.org/bots/api#editmessagechecklist
3574
+ '''
3575
+
3576
+ response = await self._send_request('editMessageChecklist', {
3577
+ 'business_connection_id': business_connection_id,
3578
+ 'chat_id': chat_id,
3579
+ 'message_id': message_id,
3580
+ 'checklist': checklist,
3581
+ 'reply_markup': reply_markup,
3582
+ })
3583
+ return Message.model_validate(response)
3584
+
3585
+ async def edit_message_reply_markup(
3586
+ self,
3587
+ business_connection_id: Optional[str] = None,
3588
+ chat_id: Optional[Union[int, str]] = None,
3589
+ message_id: Optional[int] = None,
3590
+ inline_message_id: Optional[str] = None,
3591
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3592
+ ) -> Union[Message, bool]:
3593
+ '''
3594
+ Use this method to edit only the reply
3595
+ markup of messages. On success, if the edited
3596
+ message is not an inline message, the edited
3597
+ Message is returned, otherwise True is returned. Note
3598
+ that business messages that were not sent by
3599
+ the bot and do not contain an inline
3600
+ keyboard can only be edited within 48 hours
3601
+ from the time they were sent.
3602
+
3603
+ Reference: https://core.telegram.org/bots/api#editmessagereplymarkup
3604
+ '''
3605
+
3606
+ response = await self._send_request('editMessageReplyMarkup', {
3607
+ 'business_connection_id': business_connection_id,
3608
+ 'chat_id': chat_id,
3609
+ 'message_id': message_id,
3610
+ 'inline_message_id': inline_message_id,
3611
+ 'reply_markup': reply_markup,
3612
+ })
3613
+ if isinstance(response, (dict, list)):
3614
+ return Message.model_validate(response)
3615
+ else:
3616
+ return BoolAdapter.validate_python(response)
3617
+
3618
+ async def stop_poll(
3619
+ self,
3620
+ chat_id: Union[int, str],
3621
+ message_id: int,
3622
+ business_connection_id: Optional[str] = None,
3623
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
3624
+ ) -> Poll:
3625
+ '''
3626
+ Use this method to stop a poll which
3627
+ was sent by the bot. On success, the
3628
+ stopped Poll is returned.
3629
+
3630
+ Reference: https://core.telegram.org/bots/api#stoppoll
3631
+ '''
3632
+
3633
+ response = await self._send_request('stopPoll', {
3634
+ 'business_connection_id': business_connection_id,
3635
+ 'chat_id': chat_id,
3636
+ 'message_id': message_id,
3637
+ 'reply_markup': reply_markup,
3638
+ })
3639
+ return Poll.model_validate(response)
3640
+
3641
+ async def approve_suggested_post(
3642
+ self,
3643
+ chat_id: int,
3644
+ message_id: int,
3645
+ send_date: Optional[int] = None,
3646
+ ) -> bool:
3647
+ '''
3648
+ Use this method to approve a suggested post
3649
+ in a direct messages chat. The bot must
3650
+ have the 'can_post_messages' administrator right in the corresponding
3651
+ channel chat. Returns True on success.
3652
+
3653
+ Reference: https://core.telegram.org/bots/api#approvesuggestedpost
3654
+ '''
3655
+
3656
+ response = await self._send_request('approveSuggestedPost', {
3657
+ 'chat_id': chat_id,
3658
+ 'message_id': message_id,
3659
+ 'send_date': send_date,
3660
+ })
3661
+ return BoolAdapter.validate_python(response)
3662
+
3663
+ async def decline_suggested_post(
3664
+ self,
3665
+ chat_id: int,
3666
+ message_id: int,
3667
+ comment: Optional[str] = None,
3668
+ ) -> bool:
3669
+ '''
3670
+ Use this method to decline a suggested post
3671
+ in a direct messages chat. The bot must
3672
+ have the 'can_manage_direct_messages' administrator right in the corresponding
3673
+ channel chat. Returns True on success.
3674
+
3675
+ Reference: https://core.telegram.org/bots/api#declinesuggestedpost
3676
+ '''
3677
+
3678
+ response = await self._send_request('declineSuggestedPost', {
3679
+ 'chat_id': chat_id,
3680
+ 'message_id': message_id,
3681
+ 'comment': comment,
3682
+ })
3683
+ return BoolAdapter.validate_python(response)
3684
+
3685
+ async def delete_message(
3686
+ self,
3687
+ chat_id: Union[int, str],
3688
+ message_id: int,
3689
+ ) -> bool:
3690
+ '''
3691
+ Use this method to delete a message, including
3692
+ service messages, with the following limitations:- A message
3693
+ can only be deleted if it was sent
3694
+ less than 48 hours ago.- Service messages about
3695
+ a supergroup, channel, or forum topic creation can't
3696
+ be deleted.- A dice message in a private
3697
+ chat can only be deleted if it was
3698
+ sent more than 24 hours ago.- Bots can
3699
+ delete outgoing messages in private chats, groups, and
3700
+ supergroups.- Bots can delete incoming messages in private
3701
+ chats.- Bots granted can_post_messages permissions can delete outgoing
3702
+ messages in channels.- If the bot is an
3703
+ administrator of a group, it can delete any
3704
+ message there.- If the bot has can_delete_messages administrator
3705
+ right in a supergroup or a channel, it
3706
+ can delete any message there.- If the bot
3707
+ has can_manage_direct_messages administrator right in a channel, it
3708
+ can delete any message in the corresponding direct
3709
+ messages chat.Returns True on success.
3710
+
3711
+ Reference: https://core.telegram.org/bots/api#deletemessage
3712
+ '''
3713
+
3714
+ response = await self._send_request('deleteMessage', {
3715
+ 'chat_id': chat_id,
3716
+ 'message_id': message_id,
3717
+ })
3718
+ return BoolAdapter.validate_python(response)
3719
+
3720
+ async def delete_messages(
3721
+ self,
3722
+ chat_id: Union[int, str],
3723
+ message_ids: List[int],
3724
+ ) -> bool:
3725
+ '''
3726
+ Use this method to delete multiple messages simultaneously.
3727
+ If some of the specified messages can't be
3728
+ found, they are skipped. Returns True on success.
3729
+
3730
+ Reference: https://core.telegram.org/bots/api#deletemessages
3731
+ '''
3732
+
3733
+ response = await self._send_request('deleteMessages', {
3734
+ 'chat_id': chat_id,
3735
+ 'message_ids': message_ids,
3736
+ })
3737
+ return BoolAdapter.validate_python(response)
3738
+
3739
+ async def send_sticker(
3740
+ self,
3741
+ chat_id: Union[int, str],
3742
+ sticker: Union[InputFile, str],
3743
+ business_connection_id: Optional[str] = None,
3744
+ message_thread_id: Optional[int] = None,
3745
+ direct_messages_topic_id: Optional[int] = None,
3746
+ emoji: Optional[str] = None,
3747
+ disable_notification: Optional[bool] = None,
3748
+ protect_content: Optional[bool] = None,
3749
+ allow_paid_broadcast: Optional[bool] = None,
3750
+ message_effect_id: Optional[str] = None,
3751
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
3752
+ reply_parameters: Optional[ReplyParameters] = None,
3753
+ reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
3754
+ ) -> Message:
3755
+ '''
3756
+ Use this method to send static .WEBP, animated
3757
+ .TGS, or video .WEBM stickers. On success, the
3758
+ sent Message is returned.
3759
+
3760
+ Reference: https://core.telegram.org/bots/api#sendsticker
3761
+ '''
3762
+
3763
+ response = await self._send_request('sendSticker', {
3764
+ 'business_connection_id': business_connection_id,
3765
+ 'chat_id': chat_id,
3766
+ 'message_thread_id': message_thread_id,
3767
+ 'direct_messages_topic_id': direct_messages_topic_id,
3768
+ 'sticker': sticker,
3769
+ 'emoji': emoji,
3770
+ 'disable_notification': disable_notification,
3771
+ 'protect_content': protect_content,
3772
+ 'allow_paid_broadcast': allow_paid_broadcast,
3773
+ 'message_effect_id': message_effect_id,
3774
+ 'suggested_post_parameters': suggested_post_parameters,
3775
+ 'reply_parameters': reply_parameters,
3776
+ 'reply_markup': reply_markup,
3777
+ })
3778
+ return Message.model_validate(response)
3779
+
3780
+ async def get_sticker_set(
3781
+ self,
3782
+ name: str,
3783
+ ) -> StickerSet:
3784
+ '''
3785
+ Use this method to get a sticker set.
3786
+ On success, a StickerSet object is returned.
3787
+
3788
+ Reference: https://core.telegram.org/bots/api#getstickerset
3789
+ '''
3790
+
3791
+ response = await self._send_request('getStickerSet', {
3792
+ 'name': name,
3793
+ })
3794
+ return StickerSet.model_validate(response)
3795
+
3796
+ async def get_custom_emoji_stickers(
3797
+ self,
3798
+ custom_emoji_ids: List[str],
3799
+ ) -> List[Sticker]:
3800
+ '''
3801
+ Use this method to get information about custom
3802
+ emoji stickers by their identifiers. Returns an Array
3803
+ of Sticker objects.
3804
+
3805
+ Reference: https://core.telegram.org/bots/api#getcustomemojistickers
3806
+ '''
3807
+
3808
+ response = await self._send_request('getCustomEmojiStickers', {
3809
+ 'custom_emoji_ids': custom_emoji_ids,
3810
+ })
3811
+ return [Sticker.model_validate(x) for x in response]
3812
+
3813
+ async def upload_sticker_file(
3814
+ self,
3815
+ user_id: int,
3816
+ sticker: InputFile,
3817
+ sticker_format: str,
3818
+ ) -> File:
3819
+ '''
3820
+ Use this method to upload a file with
3821
+ a sticker for later use in the createNewStickerSet,
3822
+ addStickerToSet, or replaceStickerInSet methods (the file can be
3823
+ used multiple times). Returns the uploaded File on
3824
+ success.
3825
+
3826
+ Reference: https://core.telegram.org/bots/api#uploadstickerfile
3827
+ '''
3828
+
3829
+ response = await self._send_request('uploadStickerFile', {
3830
+ 'user_id': user_id,
3831
+ 'sticker': sticker,
3832
+ 'sticker_format': sticker_format,
3833
+ })
3834
+ return File.model_validate(response)
3835
+
3836
+ async def create_new_sticker_set(
3837
+ self,
3838
+ user_id: int,
3839
+ name: str,
3840
+ title: str,
3841
+ stickers: List[InputSticker],
3842
+ sticker_type: Optional[str] = None,
3843
+ needs_repainting: Optional[bool] = None,
3844
+ ) -> bool:
3845
+ '''
3846
+ Use this method to create a new sticker
3847
+ set owned by a user. The bot will
3848
+ be able to edit the sticker set thus
3849
+ created. Returns True on success.
3850
+
3851
+ Reference: https://core.telegram.org/bots/api#createnewstickerset
3852
+ '''
3853
+
3854
+ response = await self._send_request('createNewStickerSet', {
3855
+ 'user_id': user_id,
3856
+ 'name': name,
3857
+ 'title': title,
3858
+ 'stickers': stickers,
3859
+ 'sticker_type': sticker_type,
3860
+ 'needs_repainting': needs_repainting,
3861
+ })
3862
+ return BoolAdapter.validate_python(response)
3863
+
3864
+ async def add_sticker_to_set(
3865
+ self,
3866
+ user_id: int,
3867
+ name: str,
3868
+ sticker: InputSticker,
3869
+ ) -> bool:
3870
+ '''
3871
+ Use this method to add a new sticker
3872
+ to a set created by the bot. Emoji
3873
+ sticker sets can have up to 200 stickers.
3874
+ Other sticker sets can have up to 120
3875
+ stickers. Returns True on success.
3876
+
3877
+ Reference: https://core.telegram.org/bots/api#addstickertoset
3878
+ '''
3879
+
3880
+ response = await self._send_request('addStickerToSet', {
3881
+ 'user_id': user_id,
3882
+ 'name': name,
3883
+ 'sticker': sticker,
3884
+ })
3885
+ return BoolAdapter.validate_python(response)
3886
+
3887
+ async def set_sticker_position_in_set(
3888
+ self,
3889
+ sticker: str,
3890
+ position: int,
3891
+ ) -> bool:
3892
+ '''
3893
+ Use this method to move a sticker in
3894
+ a set created by the bot to a
3895
+ specific position. Returns True on success.
3896
+
3897
+ Reference: https://core.telegram.org/bots/api#setstickerpositioninset
3898
+ '''
3899
+
3900
+ response = await self._send_request('setStickerPositionInSet', {
3901
+ 'sticker': sticker,
3902
+ 'position': position,
3903
+ })
3904
+ return BoolAdapter.validate_python(response)
3905
+
3906
+ async def delete_sticker_from_set(
3907
+ self,
3908
+ sticker: str,
3909
+ ) -> bool:
3910
+ '''
3911
+ Use this method to delete a sticker from
3912
+ a set created by the bot. Returns True
3913
+ on success.
3914
+
3915
+ Reference: https://core.telegram.org/bots/api#deletestickerfromset
3916
+ '''
3917
+
3918
+ response = await self._send_request('deleteStickerFromSet', {
3919
+ 'sticker': sticker,
3920
+ })
3921
+ return BoolAdapter.validate_python(response)
3922
+
3923
+ async def replace_sticker_in_set(
3924
+ self,
3925
+ user_id: int,
3926
+ name: str,
3927
+ old_sticker: str,
3928
+ sticker: InputSticker,
3929
+ ) -> bool:
3930
+ '''
3931
+ Use this method to replace an existing sticker
3932
+ in a sticker set with a new one.
3933
+ The method is equivalent to calling deleteStickerFromSet, then
3934
+ addStickerToSet, then setStickerPositionInSet. Returns True on success.
3935
+
3936
+ Reference: https://core.telegram.org/bots/api#replacestickerinset
3937
+ '''
3938
+
3939
+ response = await self._send_request('replaceStickerInSet', {
3940
+ 'user_id': user_id,
3941
+ 'name': name,
3942
+ 'old_sticker': old_sticker,
3943
+ 'sticker': sticker,
3944
+ })
3945
+ return BoolAdapter.validate_python(response)
3946
+
3947
+ async def set_sticker_emoji_list(
3948
+ self,
3949
+ sticker: str,
3950
+ emoji_list: List[str],
3951
+ ) -> bool:
3952
+ '''
3953
+ Use this method to change the list of
3954
+ emoji assigned to a regular or custom emoji
3955
+ sticker. The sticker must belong to a sticker
3956
+ set created by the bot. Returns True on
3957
+ success.
3958
+
3959
+ Reference: https://core.telegram.org/bots/api#setstickeremojilist
3960
+ '''
3961
+
3962
+ response = await self._send_request('setStickerEmojiList', {
3963
+ 'sticker': sticker,
3964
+ 'emoji_list': emoji_list,
3965
+ })
3966
+ return BoolAdapter.validate_python(response)
3967
+
3968
+ async def set_sticker_keywords(
3969
+ self,
3970
+ sticker: str,
3971
+ keywords: Optional[List[str]] = None,
3972
+ ) -> bool:
3973
+ '''
3974
+ Use this method to change search keywords assigned
3975
+ to a regular or custom emoji sticker. The
3976
+ sticker must belong to a sticker set created
3977
+ by the bot. Returns True on success.
3978
+
3979
+ Reference: https://core.telegram.org/bots/api#setstickerkeywords
3980
+ '''
3981
+
3982
+ response = await self._send_request('setStickerKeywords', {
3983
+ 'sticker': sticker,
3984
+ 'keywords': keywords,
3985
+ })
3986
+ return BoolAdapter.validate_python(response)
3987
+
3988
+ async def set_sticker_mask_position(
3989
+ self,
3990
+ sticker: str,
3991
+ mask_position: Optional[MaskPosition] = None,
3992
+ ) -> bool:
3993
+ '''
3994
+ Use this method to change the mask position
3995
+ of a mask sticker. The sticker must belong
3996
+ to a sticker set that was created by
3997
+ the bot. Returns True on success.
3998
+
3999
+ Reference: https://core.telegram.org/bots/api#setstickermaskposition
4000
+ '''
4001
+
4002
+ response = await self._send_request('setStickerMaskPosition', {
4003
+ 'sticker': sticker,
4004
+ 'mask_position': mask_position,
4005
+ })
4006
+ return BoolAdapter.validate_python(response)
4007
+
4008
+ async def set_sticker_set_title(
4009
+ self,
4010
+ name: str,
4011
+ title: str,
4012
+ ) -> bool:
4013
+ '''
4014
+ Use this method to set the title of
4015
+ a created sticker set. Returns True on success.
4016
+
4017
+ Reference: https://core.telegram.org/bots/api#setstickersettitle
4018
+ '''
4019
+
4020
+ response = await self._send_request('setStickerSetTitle', {
4021
+ 'name': name,
4022
+ 'title': title,
4023
+ })
4024
+ return BoolAdapter.validate_python(response)
4025
+
4026
+ async def set_sticker_set_thumbnail(
4027
+ self,
4028
+ name: str,
4029
+ user_id: int,
4030
+ format: str,
4031
+ thumbnail: Optional[Union[InputFile, str]] = None,
4032
+ ) -> bool:
4033
+ '''
4034
+ Use this method to set the thumbnail of
4035
+ a regular or mask sticker set. The format
4036
+ of the thumbnail file must match the format
4037
+ of the stickers in the set. Returns True
4038
+ on success.
4039
+
4040
+ Reference: https://core.telegram.org/bots/api#setstickersetthumbnail
4041
+ '''
4042
+
4043
+ response = await self._send_request('setStickerSetThumbnail', {
4044
+ 'name': name,
4045
+ 'user_id': user_id,
4046
+ 'thumbnail': thumbnail,
4047
+ 'format': format,
4048
+ })
4049
+ return BoolAdapter.validate_python(response)
4050
+
4051
+ async def set_custom_emoji_sticker_set_thumbnail(
4052
+ self,
4053
+ name: str,
4054
+ custom_emoji_id: Optional[str] = None,
4055
+ ) -> bool:
4056
+ '''
4057
+ Use this method to set the thumbnail of
4058
+ a custom emoji sticker set. Returns True on
4059
+ success.
4060
+
4061
+ Reference: https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
4062
+ '''
4063
+
4064
+ response = await self._send_request('setCustomEmojiStickerSetThumbnail', {
4065
+ 'name': name,
4066
+ 'custom_emoji_id': custom_emoji_id,
4067
+ })
4068
+ return BoolAdapter.validate_python(response)
4069
+
4070
+ async def delete_sticker_set(
4071
+ self,
4072
+ name: str,
4073
+ ) -> bool:
4074
+ '''
4075
+ Use this method to delete a sticker set
4076
+ that was created by the bot. Returns True
4077
+ on success.
4078
+
4079
+ Reference: https://core.telegram.org/bots/api#deletestickerset
4080
+ '''
4081
+
4082
+ response = await self._send_request('deleteStickerSet', {
4083
+ 'name': name,
4084
+ })
4085
+ return BoolAdapter.validate_python(response)
4086
+
4087
+ async def answer_inline_query(
4088
+ self,
4089
+ inline_query_id: str,
4090
+ results: List[InlineQueryResult],
4091
+ cache_time: Optional[int] = None,
4092
+ is_personal: Optional[bool] = None,
4093
+ next_offset: Optional[str] = None,
4094
+ button: Optional[InlineQueryResultsButton] = None,
4095
+ ) -> bool:
4096
+ '''
4097
+ Use this method to send answers to an
4098
+ inline query. On success, True is returned.No more
4099
+ than 50 results per query are allowed.
4100
+
4101
+ Reference: https://core.telegram.org/bots/api#answerinlinequery
4102
+ '''
4103
+
4104
+ response = await self._send_request('answerInlineQuery', {
4105
+ 'inline_query_id': inline_query_id,
4106
+ 'results': results,
4107
+ 'cache_time': cache_time,
4108
+ 'is_personal': is_personal,
4109
+ 'next_offset': next_offset,
4110
+ 'button': button,
4111
+ })
4112
+ return BoolAdapter.validate_python(response)
4113
+
4114
+ async def answer_web_app_query(
4115
+ self,
4116
+ web_app_query_id: str,
4117
+ result: InlineQueryResult,
4118
+ ) -> SentWebAppMessage:
4119
+ '''
4120
+ Use this method to set the result of
4121
+ an interaction with a Web App and send
4122
+ a corresponding message on behalf of the user
4123
+ to the chat from which the query originated.
4124
+ On success, a SentWebAppMessage object is returned.
4125
+
4126
+ Reference: https://core.telegram.org/bots/api#answerwebappquery
4127
+ '''
4128
+
4129
+ response = await self._send_request('answerWebAppQuery', {
4130
+ 'web_app_query_id': web_app_query_id,
4131
+ 'result': result,
4132
+ })
4133
+ return SentWebAppMessage.model_validate(response)
4134
+
4135
+ async def save_prepared_inline_message(
4136
+ self,
4137
+ user_id: int,
4138
+ result: InlineQueryResult,
4139
+ allow_user_chats: Optional[bool] = None,
4140
+ allow_bot_chats: Optional[bool] = None,
4141
+ allow_group_chats: Optional[bool] = None,
4142
+ allow_channel_chats: Optional[bool] = None,
4143
+ ) -> PreparedInlineMessage:
4144
+ '''
4145
+ Stores a message that can be sent by
4146
+ a user of a Mini App. Returns a
4147
+ PreparedInlineMessage object.
4148
+
4149
+ Reference: https://core.telegram.org/bots/api#savepreparedinlinemessage
4150
+ '''
4151
+
4152
+ response = await self._send_request('savePreparedInlineMessage', {
4153
+ 'user_id': user_id,
4154
+ 'result': result,
4155
+ 'allow_user_chats': allow_user_chats,
4156
+ 'allow_bot_chats': allow_bot_chats,
4157
+ 'allow_group_chats': allow_group_chats,
4158
+ 'allow_channel_chats': allow_channel_chats,
4159
+ })
4160
+ return PreparedInlineMessage.model_validate(response)
4161
+
4162
+ async def send_invoice(
4163
+ self,
4164
+ chat_id: Union[int, str],
4165
+ title: str,
4166
+ description: str,
4167
+ payload: str,
4168
+ currency: str,
4169
+ prices: List[LabeledPrice],
4170
+ message_thread_id: Optional[int] = None,
4171
+ direct_messages_topic_id: Optional[int] = None,
4172
+ provider_token: Optional[str] = None,
4173
+ max_tip_amount: Optional[int] = None,
4174
+ suggested_tip_amounts: Optional[List[int]] = None,
4175
+ start_parameter: Optional[str] = None,
4176
+ provider_data: Optional[str] = None,
4177
+ photo_url: Optional[str] = None,
4178
+ photo_size: Optional[int] = None,
4179
+ photo_width: Optional[int] = None,
4180
+ photo_height: Optional[int] = None,
4181
+ need_name: Optional[bool] = None,
4182
+ need_phone_number: Optional[bool] = None,
4183
+ need_email: Optional[bool] = None,
4184
+ need_shipping_address: Optional[bool] = None,
4185
+ send_phone_number_to_provider: Optional[bool] = None,
4186
+ send_email_to_provider: Optional[bool] = None,
4187
+ is_flexible: Optional[bool] = None,
4188
+ disable_notification: Optional[bool] = None,
4189
+ protect_content: Optional[bool] = None,
4190
+ allow_paid_broadcast: Optional[bool] = None,
4191
+ message_effect_id: Optional[str] = None,
4192
+ suggested_post_parameters: Optional[SuggestedPostParameters] = None,
4193
+ reply_parameters: Optional[ReplyParameters] = None,
4194
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
4195
+ ) -> Message:
4196
+ '''
4197
+ Use this method to send invoices. On success,
4198
+ the sent Message is returned.
4199
+
4200
+ Reference: https://core.telegram.org/bots/api#sendinvoice
4201
+ '''
4202
+
4203
+ response = await self._send_request('sendInvoice', {
4204
+ 'chat_id': chat_id,
4205
+ 'message_thread_id': message_thread_id,
4206
+ 'direct_messages_topic_id': direct_messages_topic_id,
4207
+ 'title': title,
4208
+ 'description': description,
4209
+ 'payload': payload,
4210
+ 'provider_token': provider_token,
4211
+ 'currency': currency,
4212
+ 'prices': prices,
4213
+ 'max_tip_amount': max_tip_amount,
4214
+ 'suggested_tip_amounts': suggested_tip_amounts,
4215
+ 'start_parameter': start_parameter,
4216
+ 'provider_data': provider_data,
4217
+ 'photo_url': photo_url,
4218
+ 'photo_size': photo_size,
4219
+ 'photo_width': photo_width,
4220
+ 'photo_height': photo_height,
4221
+ 'need_name': need_name,
4222
+ 'need_phone_number': need_phone_number,
4223
+ 'need_email': need_email,
4224
+ 'need_shipping_address': need_shipping_address,
4225
+ 'send_phone_number_to_provider': send_phone_number_to_provider,
4226
+ 'send_email_to_provider': send_email_to_provider,
4227
+ 'is_flexible': is_flexible,
4228
+ 'disable_notification': disable_notification,
4229
+ 'protect_content': protect_content,
4230
+ 'allow_paid_broadcast': allow_paid_broadcast,
4231
+ 'message_effect_id': message_effect_id,
4232
+ 'suggested_post_parameters': suggested_post_parameters,
4233
+ 'reply_parameters': reply_parameters,
4234
+ 'reply_markup': reply_markup,
4235
+ })
4236
+ return Message.model_validate(response)
4237
+
4238
+ async def create_invoice_link(
4239
+ self,
4240
+ title: str,
4241
+ description: str,
4242
+ payload: str,
4243
+ currency: str,
4244
+ prices: List[LabeledPrice],
4245
+ business_connection_id: Optional[str] = None,
4246
+ provider_token: Optional[str] = None,
4247
+ subscription_period: Optional[int] = None,
4248
+ max_tip_amount: Optional[int] = None,
4249
+ suggested_tip_amounts: Optional[List[int]] = None,
4250
+ provider_data: Optional[str] = None,
4251
+ photo_url: Optional[str] = None,
4252
+ photo_size: Optional[int] = None,
4253
+ photo_width: Optional[int] = None,
4254
+ photo_height: Optional[int] = None,
4255
+ need_name: Optional[bool] = None,
4256
+ need_phone_number: Optional[bool] = None,
4257
+ need_email: Optional[bool] = None,
4258
+ need_shipping_address: Optional[bool] = None,
4259
+ send_phone_number_to_provider: Optional[bool] = None,
4260
+ send_email_to_provider: Optional[bool] = None,
4261
+ is_flexible: Optional[bool] = None,
4262
+ ) -> str:
4263
+ '''
4264
+ Use this method to create a link for
4265
+ an invoice. Returns the created invoice link as
4266
+ String on success.
4267
+
4268
+ Reference: https://core.telegram.org/bots/api#createinvoicelink
4269
+ '''
4270
+
4271
+ response = await self._send_request('createInvoiceLink', {
4272
+ 'business_connection_id': business_connection_id,
4273
+ 'title': title,
4274
+ 'description': description,
4275
+ 'payload': payload,
4276
+ 'provider_token': provider_token,
4277
+ 'currency': currency,
4278
+ 'prices': prices,
4279
+ 'subscription_period': subscription_period,
4280
+ 'max_tip_amount': max_tip_amount,
4281
+ 'suggested_tip_amounts': suggested_tip_amounts,
4282
+ 'provider_data': provider_data,
4283
+ 'photo_url': photo_url,
4284
+ 'photo_size': photo_size,
4285
+ 'photo_width': photo_width,
4286
+ 'photo_height': photo_height,
4287
+ 'need_name': need_name,
4288
+ 'need_phone_number': need_phone_number,
4289
+ 'need_email': need_email,
4290
+ 'need_shipping_address': need_shipping_address,
4291
+ 'send_phone_number_to_provider': send_phone_number_to_provider,
4292
+ 'send_email_to_provider': send_email_to_provider,
4293
+ 'is_flexible': is_flexible,
4294
+ })
4295
+ return StrAdapter.validate_python(response)
4296
+
4297
+ async def answer_shipping_query(
4298
+ self,
4299
+ shipping_query_id: str,
4300
+ ok: bool,
4301
+ shipping_options: Optional[List[ShippingOption]] = None,
4302
+ error_message: Optional[str] = None,
4303
+ ) -> bool:
4304
+ '''
4305
+ If you sent an invoice requesting a shipping
4306
+ address and the parameter is_flexible was specified, the
4307
+ Bot API will send an Update with a
4308
+ shipping_query field to the bot. Use this method
4309
+ to reply to shipping queries. On success, True
4310
+ is returned.
4311
+
4312
+ Reference: https://core.telegram.org/bots/api#answershippingquery
4313
+ '''
4314
+
4315
+ response = await self._send_request('answerShippingQuery', {
4316
+ 'shipping_query_id': shipping_query_id,
4317
+ 'ok': ok,
4318
+ 'shipping_options': shipping_options,
4319
+ 'error_message': error_message,
4320
+ })
4321
+ return BoolAdapter.validate_python(response)
4322
+
4323
+ async def answer_pre_checkout_query(
4324
+ self,
4325
+ pre_checkout_query_id: str,
4326
+ ok: bool,
4327
+ error_message: Optional[str] = None,
4328
+ ) -> bool:
4329
+ '''
4330
+ Once the user has confirmed their payment and
4331
+ shipping details, the Bot API sends the final
4332
+ confirmation in the form of an Update with
4333
+ the field pre_checkout_query. Use this method to respond
4334
+ to such pre-checkout queries. On success, True is
4335
+ returned. Note: The Bot API must receive an
4336
+ answer within 10 seconds after the pre-checkout query
4337
+ was sent.
4338
+
4339
+ Reference: https://core.telegram.org/bots/api#answerprecheckoutquery
4340
+ '''
4341
+
4342
+ response = await self._send_request('answerPreCheckoutQuery', {
4343
+ 'pre_checkout_query_id': pre_checkout_query_id,
4344
+ 'ok': ok,
4345
+ 'error_message': error_message,
4346
+ })
4347
+ return BoolAdapter.validate_python(response)
4348
+
4349
+ async def get_my_star_balance(
4350
+ self,
4351
+ ) -> StarAmount:
4352
+ '''
4353
+ A method to get the current Telegram Stars
4354
+ balance of the bot. Requires no parameters. On
4355
+ success, returns a StarAmount object.
4356
+
4357
+ Reference: https://core.telegram.org/bots/api#getmystarbalance
4358
+ '''
4359
+
4360
+ response = await self._send_request('getMyStarBalance', {})
4361
+ return StarAmount.model_validate(response)
4362
+
4363
+ async def get_star_transactions(
4364
+ self,
4365
+ offset: Optional[int] = None,
4366
+ limit: Optional[int] = None,
4367
+ ) -> StarTransactions:
4368
+ '''
4369
+ Returns the bot's Telegram Star transactions in chronological
4370
+ order. On success, returns a StarTransactions object.
4371
+
4372
+ Reference: https://core.telegram.org/bots/api#getstartransactions
4373
+ '''
4374
+
4375
+ response = await self._send_request('getStarTransactions', {
4376
+ 'offset': offset,
4377
+ 'limit': limit,
4378
+ })
4379
+ return StarTransactions.model_validate(response)
4380
+
4381
+ async def refund_star_payment(
4382
+ self,
4383
+ user_id: int,
4384
+ telegram_payment_charge_id: str,
4385
+ ) -> bool:
4386
+ '''
4387
+ Refunds a successful payment in Telegram Stars. Returns
4388
+ True on success.
4389
+
4390
+ Reference: https://core.telegram.org/bots/api#refundstarpayment
4391
+ '''
4392
+
4393
+ response = await self._send_request('refundStarPayment', {
4394
+ 'user_id': user_id,
4395
+ 'telegram_payment_charge_id': telegram_payment_charge_id,
4396
+ })
4397
+ return BoolAdapter.validate_python(response)
4398
+
4399
+ async def edit_user_star_subscription(
4400
+ self,
4401
+ user_id: int,
4402
+ telegram_payment_charge_id: str,
4403
+ is_canceled: bool,
4404
+ ) -> bool:
4405
+ '''
4406
+ Allows the bot to cancel or re-enable extension
4407
+ of a subscription paid in Telegram Stars. Returns
4408
+ True on success.
4409
+
4410
+ Reference: https://core.telegram.org/bots/api#edituserstarsubscription
4411
+ '''
4412
+
4413
+ response = await self._send_request('editUserStarSubscription', {
4414
+ 'user_id': user_id,
4415
+ 'telegram_payment_charge_id': telegram_payment_charge_id,
4416
+ 'is_canceled': is_canceled,
4417
+ })
4418
+ return BoolAdapter.validate_python(response)
4419
+
4420
+ async def set_passport_data_errors(
4421
+ self,
4422
+ user_id: int,
4423
+ errors: List[PassportElementError],
4424
+ ) -> bool:
4425
+ '''
4426
+ Informs a user that some of the Telegram
4427
+ Passport elements they provided contains errors. The user
4428
+ will not be able to re-submit their Passport
4429
+ to you until the errors are fixed (the
4430
+ contents of the field for which you returned
4431
+ the error must change). Returns True on success.
4432
+
4433
+ Reference: https://core.telegram.org/bots/api#setpassportdataerrors
4434
+ '''
4435
+
4436
+ response = await self._send_request('setPassportDataErrors', {
4437
+ 'user_id': user_id,
4438
+ 'errors': errors,
4439
+ })
4440
+ return BoolAdapter.validate_python(response)
4441
+
4442
+ async def send_game(
4443
+ self,
4444
+ chat_id: int,
4445
+ game_short_name: str,
4446
+ business_connection_id: Optional[str] = None,
4447
+ message_thread_id: Optional[int] = None,
4448
+ disable_notification: Optional[bool] = None,
4449
+ protect_content: Optional[bool] = None,
4450
+ allow_paid_broadcast: Optional[bool] = None,
4451
+ message_effect_id: Optional[str] = None,
4452
+ reply_parameters: Optional[ReplyParameters] = None,
4453
+ reply_markup: Optional[InlineKeyboardMarkup] = None,
4454
+ ) -> Message:
4455
+ '''
4456
+ Use this method to send a game. On
4457
+ success, the sent Message is returned.
4458
+
4459
+ Reference: https://core.telegram.org/bots/api#sendgame
4460
+ '''
4461
+
4462
+ response = await self._send_request('sendGame', {
4463
+ 'business_connection_id': business_connection_id,
4464
+ 'chat_id': chat_id,
4465
+ 'message_thread_id': message_thread_id,
4466
+ 'game_short_name': game_short_name,
4467
+ 'disable_notification': disable_notification,
4468
+ 'protect_content': protect_content,
4469
+ 'allow_paid_broadcast': allow_paid_broadcast,
4470
+ 'message_effect_id': message_effect_id,
4471
+ 'reply_parameters': reply_parameters,
4472
+ 'reply_markup': reply_markup,
4473
+ })
4474
+ return Message.model_validate(response)
4475
+
4476
+ async def set_game_score(
4477
+ self,
4478
+ user_id: int,
4479
+ score: int,
4480
+ force: Optional[bool] = None,
4481
+ disable_edit_message: Optional[bool] = None,
4482
+ chat_id: Optional[int] = None,
4483
+ message_id: Optional[int] = None,
4484
+ inline_message_id: Optional[str] = None,
4485
+ ) -> Message:
4486
+ '''
4487
+ Use this method to set the score of
4488
+ the specified user in a game message. On
4489
+ success, if the message is not an inline
4490
+ message, the Message is returned, otherwise True is
4491
+ returned. Returns an error, if the new score
4492
+ is not greater than the user's current score
4493
+ in the chat and force is False.
4494
+
4495
+ Reference: https://core.telegram.org/bots/api#setgamescore
4496
+ '''
4497
+
4498
+ response = await self._send_request('setGameScore', {
4499
+ 'user_id': user_id,
4500
+ 'score': score,
4501
+ 'force': force,
4502
+ 'disable_edit_message': disable_edit_message,
4503
+ 'chat_id': chat_id,
4504
+ 'message_id': message_id,
4505
+ 'inline_message_id': inline_message_id,
4506
+ })
4507
+ return Message.model_validate(response)
4508
+
4509
+ async def get_game_high_scores(
4510
+ self,
4511
+ user_id: int,
4512
+ chat_id: Optional[int] = None,
4513
+ message_id: Optional[int] = None,
4514
+ inline_message_id: Optional[str] = None,
4515
+ ) -> List[GameHighScore]:
4516
+ '''
4517
+ Use this method to get data for high
4518
+ score tables. Will return the score of the
4519
+ specified user and several of their neighbors in
4520
+ a game. Returns an Array of GameHighScore objects.
4521
+
4522
+ Reference: https://core.telegram.org/bots/api#getgamehighscores
4523
+ '''
4524
+
4525
+ response = await self._send_request('getGameHighScores', {
4526
+ 'user_id': user_id,
4527
+ 'chat_id': chat_id,
4528
+ 'message_id': message_id,
4529
+ 'inline_message_id': inline_message_id,
4530
+ })
4531
+ return [GameHighScore.model_validate(x) for x in response]
4532
+