botapi-py 1.4.4__tar.gz → 1.4.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: botapi-py
3
- Version: 1.4.4
3
+ Version: 1.4.6
4
4
  Summary: A simple and flexible Python library to conveniently build fast Telegram bots using the Bot API.
5
5
  Requires-Dist: httpx>=0.28.1
6
6
  Requires-Dist: pydantic>=2.12.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "botapi-py"
3
- version = "1.4.4"
3
+ version = "1.4.6"
4
4
  description = "A simple and flexible Python library to conveniently build fast Telegram bots using the Bot API."
5
5
  # readme = "README.md"
6
6
  # authors = [
@@ -22,14 +22,14 @@ class GetUpdatesAsyncDispatcher(BaseAsyncDispatcher):
22
22
  tasks: set[asyncio.Task] # prevent gc from collecting tasks before they finish
23
23
  bot: botapi.methods.Bot
24
24
  reconnect_delay: float
25
- allowed_updates: list[str]
25
+ allowed_updates: list[botapi.enums.UpdateType]
26
26
  offset: int
27
27
 
28
28
  def __init__(
29
29
  self,
30
30
  update_handler: UpdateHandler,
31
31
  bot: botapi.methods.Bot,
32
- allowed_updates: list[str], # botapi.enums.UpdateType
32
+ allowed_updates: list[botapi.enums.UpdateType],
33
33
  reconnect_delay: float = 5,
34
34
  shutdown_wait_timeout: float = 3
35
35
  ) -> None:
@@ -140,6 +140,7 @@ from .types import (
140
140
  BusinessLocation,
141
141
  BusinessOpeningHoursInterval,
142
142
  BusinessOpeningHours,
143
+ UserRating,
143
144
  StoryAreaPosition,
144
145
  LocationAddress,
145
146
  StoryAreaType,
@@ -160,12 +161,14 @@ from .types import (
160
161
  MessageReactionUpdated,
161
162
  MessageReactionCountUpdated,
162
163
  ForumTopic,
164
+ GiftBackground,
163
165
  Gift,
164
166
  Gifts,
165
167
  UniqueGiftModel,
166
168
  UniqueGiftSymbol,
167
169
  UniqueGiftBackdropColors,
168
170
  UniqueGiftBackdrop,
171
+ UniqueGiftColors,
169
172
  UniqueGift,
170
173
  GiftInfo,
171
174
  UniqueGiftInfo,
@@ -522,6 +525,7 @@ class Bot(core.BaseBot):
522
525
  video_start_timestamp: Optional[int] = None,
523
526
  disable_notification: Optional[bool] = None,
524
527
  protect_content: Optional[bool] = None,
528
+ message_effect_id: Optional[str] = None,
525
529
  suggested_post_parameters: Optional[SuggestedPostParameters] = None,
526
530
  ) -> Message:
527
531
  '''
@@ -541,6 +545,7 @@ class Bot(core.BaseBot):
541
545
  'video_start_timestamp': video_start_timestamp,
542
546
  'disable_notification': disable_notification,
543
547
  'protect_content': protect_content,
548
+ 'message_effect_id': message_effect_id,
544
549
  'suggested_post_parameters': suggested_post_parameters,
545
550
  'message_id': message_id,
546
551
  })
@@ -594,6 +599,7 @@ class Bot(core.BaseBot):
594
599
  disable_notification: Optional[bool] = None,
595
600
  protect_content: Optional[bool] = None,
596
601
  allow_paid_broadcast: Optional[bool] = None,
602
+ message_effect_id: Optional[str] = None,
597
603
  suggested_post_parameters: Optional[SuggestedPostParameters] = None,
598
604
  reply_parameters: Optional[ReplyParameters] = None,
599
605
  reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None,
@@ -627,6 +633,7 @@ class Bot(core.BaseBot):
627
633
  'disable_notification': disable_notification,
628
634
  'protect_content': protect_content,
629
635
  'allow_paid_broadcast': allow_paid_broadcast,
636
+ 'message_effect_id': message_effect_id,
630
637
  'suggested_post_parameters': suggested_post_parameters,
631
638
  'reply_parameters': reply_parameters,
632
639
  'reply_markup': reply_markup,
@@ -1418,6 +1425,34 @@ class Bot(core.BaseBot):
1418
1425
  })
1419
1426
  return Message.model_validate(response)
1420
1427
 
1428
+ async def send_message_draft(
1429
+ self,
1430
+ chat_id: int,
1431
+ draft_id: int,
1432
+ text: str,
1433
+ message_thread_id: Optional[int] = None,
1434
+ parse_mode: Optional[enums.ParseMode] = enums.ParseMode.HTML,
1435
+ entities: Optional[List[MessageEntity]] = None,
1436
+ ) -> bool:
1437
+ '''
1438
+ Use this method to stream a partial message
1439
+ to a user while the message is being
1440
+ generated; supported only for bots with forum topic
1441
+ mode enabled. Returns True on success.
1442
+
1443
+ Reference: https://core.telegram.org/bots/api#sendmessagedraft
1444
+ '''
1445
+
1446
+ response = await self._send_request('sendMessageDraft', {
1447
+ 'chat_id': chat_id,
1448
+ 'message_thread_id': message_thread_id,
1449
+ 'draft_id': draft_id,
1450
+ 'text': text,
1451
+ 'parse_mode': parse_mode if not entities else None, # FIX,
1452
+ 'entities': entities,
1453
+ })
1454
+ return BoolAdapter.validate_python(response)
1455
+
1421
1456
  async def send_chat_action(
1422
1457
  self,
1423
1458
  chat_id: Union[int, str],
@@ -2303,11 +2338,13 @@ class Bot(core.BaseBot):
2303
2338
  ) -> bool:
2304
2339
  '''
2305
2340
  Use this method to edit name and icon
2306
- of a topic in a forum supergroup chat.
2307
- The bot must be an administrator in the
2308
- chat for this to work and must have
2309
- the can_manage_topics administrator rights, unless it is the
2310
- creator of the topic. Returns True on success.
2341
+ of a topic in a forum supergroup chat
2342
+ or a private chat with a user. In
2343
+ the case of a supergroup chat the bot
2344
+ must be an administrator in the chat for
2345
+ this to work and must have the can_manage_topics
2346
+ administrator rights, unless it is the creator of
2347
+ the topic. Returns True on success.
2311
2348
 
2312
2349
  Reference: https://core.telegram.org/bots/api#editforumtopic
2313
2350
  '''
@@ -2372,10 +2409,11 @@ class Bot(core.BaseBot):
2372
2409
  '''
2373
2410
  Use this method to delete a forum topic
2374
2411
  along with all its messages in a forum
2375
- supergroup chat. The bot must be an administrator
2376
- in the chat for this to work and
2377
- must have the can_delete_messages administrator rights. Returns True
2378
- on success.
2412
+ supergroup chat or a private chat with a
2413
+ user. In the case of a supergroup chat
2414
+ the bot must be an administrator in the
2415
+ chat for this to work and must have
2416
+ the can_delete_messages administrator rights. Returns True on success.
2379
2417
 
2380
2418
  Reference: https://core.telegram.org/bots/api#deleteforumtopic
2381
2419
  '''
@@ -2393,11 +2431,13 @@ class Bot(core.BaseBot):
2393
2431
  ) -> bool:
2394
2432
  '''
2395
2433
  Use this method to clear the list of
2396
- pinned messages in a forum topic. The bot
2397
- must be an administrator in the chat for
2398
- this to work and must have the can_pin_messages
2399
- administrator right in the supergroup. Returns True on
2400
- success.
2434
+ pinned messages in a forum topic in a
2435
+ forum supergroup chat or a private chat with
2436
+ a user. In the case of a supergroup
2437
+ chat the bot must be an administrator in
2438
+ the chat for this to work and must
2439
+ have the can_pin_messages administrator right in the supergroup.
2440
+ Returns True on success.
2401
2441
 
2402
2442
  Reference: https://core.telegram.org/bots/api#unpinallforumtopicmessages
2403
2443
  '''
@@ -3186,8 +3226,10 @@ class Bot(core.BaseBot):
3186
3226
  exclude_unsaved: Optional[bool] = None,
3187
3227
  exclude_saved: Optional[bool] = None,
3188
3228
  exclude_unlimited: Optional[bool] = None,
3189
- exclude_limited: Optional[bool] = None,
3229
+ exclude_limited_upgradable: Optional[bool] = None,
3230
+ exclude_limited_non_upgradable: Optional[bool] = None,
3190
3231
  exclude_unique: Optional[bool] = None,
3232
+ exclude_from_blockchain: Optional[bool] = None,
3191
3233
  sort_by_price: Optional[bool] = None,
3192
3234
  offset: Optional[str] = None,
3193
3235
  limit: Optional[int] = None,
@@ -3205,7 +3247,77 @@ class Bot(core.BaseBot):
3205
3247
  'exclude_unsaved': exclude_unsaved,
3206
3248
  'exclude_saved': exclude_saved,
3207
3249
  'exclude_unlimited': exclude_unlimited,
3208
- 'exclude_limited': exclude_limited,
3250
+ 'exclude_limited_upgradable': exclude_limited_upgradable,
3251
+ 'exclude_limited_non_upgradable': exclude_limited_non_upgradable,
3252
+ 'exclude_unique': exclude_unique,
3253
+ 'exclude_from_blockchain': exclude_from_blockchain,
3254
+ 'sort_by_price': sort_by_price,
3255
+ 'offset': offset,
3256
+ 'limit': limit,
3257
+ })
3258
+ return OwnedGifts.model_validate(response)
3259
+
3260
+ async def get_user_gifts(
3261
+ self,
3262
+ user_id: int,
3263
+ exclude_unlimited: Optional[bool] = None,
3264
+ exclude_limited_upgradable: Optional[bool] = None,
3265
+ exclude_limited_non_upgradable: Optional[bool] = None,
3266
+ exclude_from_blockchain: Optional[bool] = None,
3267
+ exclude_unique: Optional[bool] = None,
3268
+ sort_by_price: Optional[bool] = None,
3269
+ offset: Optional[str] = None,
3270
+ limit: Optional[int] = None,
3271
+ ) -> OwnedGifts:
3272
+ '''
3273
+ Returns the gifts owned and hosted by a
3274
+ user. Returns OwnedGifts on success.
3275
+
3276
+ Reference: https://core.telegram.org/bots/api#getusergifts
3277
+ '''
3278
+
3279
+ response = await self._send_request('getUserGifts', {
3280
+ 'user_id': user_id,
3281
+ 'exclude_unlimited': exclude_unlimited,
3282
+ 'exclude_limited_upgradable': exclude_limited_upgradable,
3283
+ 'exclude_limited_non_upgradable': exclude_limited_non_upgradable,
3284
+ 'exclude_from_blockchain': exclude_from_blockchain,
3285
+ 'exclude_unique': exclude_unique,
3286
+ 'sort_by_price': sort_by_price,
3287
+ 'offset': offset,
3288
+ 'limit': limit,
3289
+ })
3290
+ return OwnedGifts.model_validate(response)
3291
+
3292
+ async def get_chat_gifts(
3293
+ self,
3294
+ chat_id: Union[int, str],
3295
+ exclude_unsaved: Optional[bool] = None,
3296
+ exclude_saved: Optional[bool] = None,
3297
+ exclude_unlimited: Optional[bool] = None,
3298
+ exclude_limited_upgradable: Optional[bool] = None,
3299
+ exclude_limited_non_upgradable: Optional[bool] = None,
3300
+ exclude_from_blockchain: Optional[bool] = None,
3301
+ exclude_unique: Optional[bool] = None,
3302
+ sort_by_price: Optional[bool] = None,
3303
+ offset: Optional[str] = None,
3304
+ limit: Optional[int] = None,
3305
+ ) -> OwnedGifts:
3306
+ '''
3307
+ Returns the gifts owned by a chat. Returns
3308
+ OwnedGifts on success.
3309
+
3310
+ Reference: https://core.telegram.org/bots/api#getchatgifts
3311
+ '''
3312
+
3313
+ response = await self._send_request('getChatGifts', {
3314
+ 'chat_id': chat_id,
3315
+ 'exclude_unsaved': exclude_unsaved,
3316
+ 'exclude_saved': exclude_saved,
3317
+ 'exclude_unlimited': exclude_unlimited,
3318
+ 'exclude_limited_upgradable': exclude_limited_upgradable,
3319
+ 'exclude_limited_non_upgradable': exclude_limited_non_upgradable,
3320
+ 'exclude_from_blockchain': exclude_from_blockchain,
3209
3321
  'exclude_unique': exclude_unique,
3210
3322
  'sort_by_price': sort_by_price,
3211
3323
  'offset': offset,
@@ -3313,6 +3425,37 @@ class Bot(core.BaseBot):
3313
3425
  })
3314
3426
  return Story.model_validate(response)
3315
3427
 
3428
+ async def repost_story(
3429
+ self,
3430
+ business_connection_id: str,
3431
+ from_chat_id: int,
3432
+ from_story_id: int,
3433
+ active_period: int,
3434
+ post_to_chat_page: Optional[bool] = None,
3435
+ protect_content: Optional[bool] = None,
3436
+ ) -> Story:
3437
+ '''
3438
+ Reposts a story on behalf of a business
3439
+ account from another business account. Both business accounts
3440
+ must be managed by the same bot, and
3441
+ the story on the source account must have
3442
+ been posted (or reposted) by the bot. Requires
3443
+ the can_manage_stories business bot right for both business
3444
+ accounts. Returns Story on success.
3445
+
3446
+ Reference: https://core.telegram.org/bots/api#repoststory
3447
+ '''
3448
+
3449
+ response = await self._send_request('repostStory', {
3450
+ 'business_connection_id': business_connection_id,
3451
+ 'from_chat_id': from_chat_id,
3452
+ 'from_story_id': from_story_id,
3453
+ 'active_period': active_period,
3454
+ 'post_to_chat_page': post_to_chat_page,
3455
+ 'protect_content': protect_content,
3456
+ })
3457
+ return Story.model_validate(response)
3458
+
3316
3459
  async def edit_story(
3317
3460
  self,
3318
3461
  business_connection_id: str,
@@ -95,6 +95,7 @@ class Message(MaybeInaccessibleMessage, frozen=True):
95
95
  chat_shared: Optional[ChatShared] = Field(default=None)
96
96
  gift: Optional[GiftInfo] = Field(default=None)
97
97
  unique_gift: Optional[UniqueGiftInfo] = Field(default=None)
98
+ gift_upgrade_sent: Optional[GiftInfo] = Field(default=None)
98
99
  connected_website: Optional[str] = Field(default=None)
99
100
  write_access_allowed: Optional[WriteAccessAllowed] = Field(default=None)
100
101
  passport_data: Optional[PassportData] = Field(default=None)
@@ -871,7 +872,9 @@ class OwnedGiftRegular(OwnedGift, frozen=True):
871
872
  can_be_upgraded: Optional[bool] = Field(default=None)
872
873
  was_refunded: Optional[bool] = Field(default=None)
873
874
  convert_star_count: Optional[int] = Field(default=None)
874
- prepaid_upgrade_star_count: Optional[int] = Field(default=None)
875
+ prepaid_upgrade_star_count: Optional[int] = Field(default=None)
876
+ is_upgrade_separate: Optional[bool] = Field(default=None)
877
+ unique_gift_number: Optional[int] = Field(default=None)
875
878
 
876
879
  class OwnedGiftUnique(OwnedGift, frozen=True):
877
880
  '''
@@ -2250,7 +2253,8 @@ class User(BaseModel, frozen=True):
2250
2253
  can_read_all_group_messages: Optional[bool] = Field(default=None)
2251
2254
  supports_inline_queries: Optional[bool] = Field(default=None)
2252
2255
  can_connect_to_business: Optional[bool] = Field(default=None)
2253
- has_main_web_app: Optional[bool] = Field(default=None)
2256
+ has_main_web_app: Optional[bool] = Field(default=None)
2257
+ has_topics_enabled: Optional[bool] = Field(default=None)
2254
2258
 
2255
2259
  class Chat(BaseModel, frozen=True):
2256
2260
  '''
@@ -2321,7 +2325,10 @@ class ChatFullInfo(BaseModel, frozen=True):
2321
2325
  can_set_sticker_set: Optional[bool] = Field(default=None)
2322
2326
  custom_emoji_sticker_set_name: Optional[str] = Field(default=None)
2323
2327
  linked_chat_id: Optional[int] = Field(default=None)
2324
- location: Optional[ChatLocation] = Field(default=None)
2328
+ location: Optional[ChatLocation] = Field(default=None)
2329
+ rating: Optional[UserRating] = Field(default=None)
2330
+ unique_gift_colors: Optional[UniqueGiftColors] = Field(default=None)
2331
+ paid_message_star_count: Optional[int] = Field(default=None)
2325
2332
 
2326
2333
  class MessageId(BaseModel, frozen=True):
2327
2334
  '''
@@ -2659,6 +2666,7 @@ class ChecklistTask(BaseModel, frozen=True):
2659
2666
  text: str
2660
2667
  text_entities: Optional[List[MessageEntity]] = Field(default=None)
2661
2668
  completed_by_user: Optional[User] = Field(default=None)
2669
+ completed_by_chat: Optional[Chat] = Field(default=None)
2662
2670
  completion_date: Optional[int] = Field(default=None)
2663
2671
 
2664
2672
  class Checklist(BaseModel, frozen=True):
@@ -2815,7 +2823,8 @@ class ForumTopicCreated(BaseModel, frozen=True):
2815
2823
 
2816
2824
  name: str
2817
2825
  icon_color: int
2818
- icon_custom_emoji_id: Optional[str] = Field(default=None)
2826
+ icon_custom_emoji_id: Optional[str] = Field(default=None)
2827
+ is_name_implicit: Optional[bool] = Field(default=None)
2819
2828
 
2820
2829
  class ForumTopicClosed(BaseModel, frozen=True):
2821
2830
  '''
@@ -3638,6 +3647,19 @@ class BusinessOpeningHours(BaseModel, frozen=True):
3638
3647
  time_zone_name: str
3639
3648
  opening_hours: List[BusinessOpeningHoursInterval]
3640
3649
 
3650
+ class UserRating(BaseModel, frozen=True):
3651
+ '''
3652
+ This object describes the rating of a user
3653
+ based on their Telegram Star spendings.
3654
+
3655
+ Reference: https://core.telegram.org/bots/api#userrating
3656
+ '''
3657
+
3658
+ level: int
3659
+ rating: int
3660
+ current_level_rating: int
3661
+ next_level_rating: Optional[int] = Field(default=None)
3662
+
3641
3663
  class StoryAreaPosition(BaseModel, frozen=True):
3642
3664
  '''
3643
3665
  Describes the position of a clickable area within
@@ -3736,7 +3758,19 @@ class ForumTopic(BaseModel, frozen=True):
3736
3758
  message_thread_id: int
3737
3759
  name: str
3738
3760
  icon_color: int
3739
- icon_custom_emoji_id: Optional[str] = Field(default=None)
3761
+ icon_custom_emoji_id: Optional[str] = Field(default=None)
3762
+ is_name_implicit: Optional[bool] = Field(default=None)
3763
+
3764
+ class GiftBackground(BaseModel, frozen=True):
3765
+ '''
3766
+ This object describes the background of a gift.
3767
+
3768
+ Reference: https://core.telegram.org/bots/api#giftbackground
3769
+ '''
3770
+
3771
+ center_color: int
3772
+ edge_color: int
3773
+ text_color: int
3740
3774
 
3741
3775
  class Gift(BaseModel, frozen=True):
3742
3776
  '''
@@ -3750,8 +3784,14 @@ class Gift(BaseModel, frozen=True):
3750
3784
  sticker: Sticker
3751
3785
  star_count: int
3752
3786
  upgrade_star_count: Optional[int] = Field(default=None)
3787
+ is_premium: Optional[bool] = Field(default=None)
3788
+ has_colors: Optional[bool] = Field(default=None)
3753
3789
  total_count: Optional[int] = Field(default=None)
3754
3790
  remaining_count: Optional[int] = Field(default=None)
3791
+ personal_total_count: Optional[int] = Field(default=None)
3792
+ personal_remaining_count: Optional[int] = Field(default=None)
3793
+ background: Optional[GiftBackground] = Field(default=None)
3794
+ unique_gift_variant_count: Optional[int] = Field(default=None)
3755
3795
  publisher_chat: Optional[Chat] = Field(default=None)
3756
3796
 
3757
3797
  class Gifts(BaseModel, frozen=True):
@@ -3812,6 +3852,22 @@ class UniqueGiftBackdrop(BaseModel, frozen=True):
3812
3852
  colors: UniqueGiftBackdropColors
3813
3853
  rarity_per_mille: int
3814
3854
 
3855
+ class UniqueGiftColors(BaseModel, frozen=True):
3856
+ '''
3857
+ This object contains information about the color scheme
3858
+ for a user's name, message replies and link
3859
+ previews based on a unique gift.
3860
+
3861
+ Reference: https://core.telegram.org/bots/api#uniquegiftcolors
3862
+ '''
3863
+
3864
+ model_custom_emoji_id: str
3865
+ symbol_custom_emoji_id: str
3866
+ light_theme_main_color: int
3867
+ light_theme_other_colors: List[int]
3868
+ dark_theme_main_color: int
3869
+ dark_theme_other_colors: List[int]
3870
+
3815
3871
  class UniqueGift(BaseModel, frozen=True):
3816
3872
  '''
3817
3873
  This object describes a unique gift that was
@@ -3820,12 +3876,16 @@ class UniqueGift(BaseModel, frozen=True):
3820
3876
  Reference: https://core.telegram.org/bots/api#uniquegift
3821
3877
  '''
3822
3878
 
3879
+ gift_id: str
3823
3880
  base_name: str
3824
3881
  name: str
3825
3882
  number: int
3826
3883
  model: UniqueGiftModel
3827
3884
  symbol: UniqueGiftSymbol
3828
3885
  backdrop: UniqueGiftBackdrop
3886
+ is_premium: Optional[bool] = Field(default=None)
3887
+ is_from_blockchain: Optional[bool] = Field(default=None)
3888
+ colors: Optional[UniqueGiftColors] = Field(default=None)
3829
3889
  publisher_chat: Optional[Chat] = Field(default=None)
3830
3890
 
3831
3891
  class GiftInfo(BaseModel, frozen=True):
@@ -3840,10 +3900,12 @@ class GiftInfo(BaseModel, frozen=True):
3840
3900
  owned_gift_id: Optional[str] = Field(default=None)
3841
3901
  convert_star_count: Optional[int] = Field(default=None)
3842
3902
  prepaid_upgrade_star_count: Optional[int] = Field(default=None)
3903
+ is_upgrade_separate: Optional[bool] = Field(default=None)
3843
3904
  can_be_upgraded: Optional[bool] = Field(default=None)
3844
3905
  text: Optional[str] = Field(default=None)
3845
3906
  entities: Optional[List[MessageEntity]] = Field(default=None)
3846
- is_private: Optional[bool] = Field(default=None)
3907
+ is_private: Optional[bool] = Field(default=None)
3908
+ unique_gift_number: Optional[int] = Field(default=None)
3847
3909
 
3848
3910
  class UniqueGiftInfo(BaseModel, frozen=True):
3849
3911
  '''
@@ -3855,7 +3917,8 @@ class UniqueGiftInfo(BaseModel, frozen=True):
3855
3917
 
3856
3918
  gift: UniqueGift
3857
3919
  origin: str
3858
- last_resale_star_count: Optional[int] = Field(default=None)
3920
+ last_resale_currency: Optional[str] = Field(default=None)
3921
+ last_resale_amount: Optional[int] = Field(default=None)
3859
3922
  owned_gift_id: Optional[str] = Field(default=None)
3860
3923
  transfer_star_count: Optional[int] = Field(default=None)
3861
3924
  next_transfer_date: Optional[int] = Field(default=None)
@@ -3884,7 +3947,8 @@ class AcceptedGiftTypes(BaseModel, frozen=True):
3884
3947
  unlimited_gifts: bool
3885
3948
  limited_gifts: bool
3886
3949
  unique_gifts: bool
3887
- premium_subscription: bool
3950
+ premium_subscription: bool
3951
+ gifts_from_channels: bool
3888
3952
 
3889
3953
  class StarAmount(BaseModel, frozen=True):
3890
3954
  '''
File without changes
File without changes
File without changes