botapi-py 1.4.6__tar.gz → 1.4.8__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.6
3
+ Version: 1.4.8
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.6"
3
+ version = "1.4.8"
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 = [
@@ -10,6 +10,8 @@ from . import core
10
10
 
11
11
  from . import enums
12
12
 
13
+ from .shortcuts import BotShortcuts
14
+
13
15
  from .types import (
14
16
  Update,
15
17
  WebhookInfo,
@@ -319,7 +321,7 @@ from .types import (
319
321
  BoolAdapter,
320
322
  )
321
323
 
322
- class Bot(core.BaseBot):
324
+ class Bot(core.BaseBot, BotShortcuts):
323
325
  '''
324
326
  Creates an instance of a new Bot API client.
325
327
 
@@ -0,0 +1,221 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Optional, Union, List, cast
4
+
5
+ from . import enums
6
+ from . import types
7
+
8
+ from . import methods
9
+
10
+
11
+ class BotShortcuts:
12
+ '''
13
+ Mixin class containing shortcut bound methods for the `Bot` class.
14
+ These methods provide convenient wrappers around standard API methods.
15
+ '''
16
+
17
+ async def send_media(
18
+ self,
19
+ chat_id: Union[int, str],
20
+ media: Union[types.InputFile, str],
21
+ file_type: enums.MediaType,
22
+ caption: Optional[str] = None,
23
+ parse_mode: Optional[enums.ParseMode] = enums.ParseMode.HTML,
24
+ caption_entities: Optional[List[types.MessageEntity]] = None,
25
+ show_caption_above_media: Optional[bool] = None,
26
+ has_spoiler: Optional[bool] = None,
27
+ disable_notification: Optional[bool] = None,
28
+ protect_content: Optional[bool] = None,
29
+ reply_parameters: Optional[types.ReplyParameters] = None,
30
+ reply_markup: Optional[Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply]] = None,
31
+ message_effect_id: Optional[str] = None,
32
+ allow_paid_broadcast: Optional[bool] = None,
33
+ business_connection_id: Optional[str] = None,
34
+ message_thread_id: Optional[int] = None,
35
+ disable_content_type_detection: Optional[bool] = None, # Documents only
36
+ ) -> types.Message:
37
+ '''
38
+ Method that sends common types of media by automatically routing to the correct `send_<type>` method.
39
+
40
+ :param chat_id: Unique identifier for the target chat or username of the target channel.
41
+ :param media: File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
42
+ :param file_type: The type of media to send. Use `enums.MediaType`.
43
+ :param caption: Media caption, 0-1024 characters.
44
+ :param parse_mode: Mode for parsing entities in the media caption.
45
+ :param caption_entities: A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode.
46
+ :param show_caption_above_media: Pass True, if the caption must be shown above the message media.
47
+ :param has_spoiler: Pass True if the media needs to be covered with a spoiler animation.
48
+ :param disable_notification: Sends the message silently. Users will receive a notification with no sound.
49
+ :param protect_content: Protects the contents of the sent message from forwarding and saving.
50
+ :param reply_parameters: Description of the message to reply to.
51
+ :param reply_markup: Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user.
52
+ :param message_effect_id: Unique identifier of the message effect to be added to the message.
53
+ :param allow_paid_broadcast: Pass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance.
54
+ :param business_connection_id: Unique identifier of the business connection on behalf of which the message will be sent.
55
+ :param message_thread_id: Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.
56
+ :param disable_content_type_detection: Disables automatic server-side content type detection.
57
+ :return: On success, the sent Message is returned.
58
+ '''
59
+ self = cast(methods.Bot, self)
60
+
61
+ match file_type:
62
+
63
+ case enums.MediaType.PHOTO:
64
+ return await self.send_photo(
65
+ chat_id=chat_id,
66
+ photo=media,
67
+ caption=caption,
68
+ parse_mode=parse_mode,
69
+ caption_entities=caption_entities,
70
+ disable_notification=disable_notification,
71
+ protect_content=protect_content,
72
+ reply_parameters=reply_parameters,
73
+ reply_markup=reply_markup,
74
+ message_effect_id=message_effect_id,
75
+ allow_paid_broadcast=allow_paid_broadcast,
76
+ business_connection_id=business_connection_id,
77
+ message_thread_id=message_thread_id,
78
+ has_spoiler=has_spoiler,
79
+ show_caption_above_media=show_caption_above_media
80
+ )
81
+
82
+ case enums.MediaType.VIDEO:
83
+ return await self.send_video(
84
+ chat_id=chat_id,
85
+ video=media,
86
+ caption=caption,
87
+ parse_mode=parse_mode,
88
+ caption_entities=caption_entities,
89
+ disable_notification=disable_notification,
90
+ protect_content=protect_content,
91
+ reply_parameters=reply_parameters,
92
+ reply_markup=reply_markup,
93
+ message_effect_id=message_effect_id,
94
+ allow_paid_broadcast=allow_paid_broadcast,
95
+ business_connection_id=business_connection_id,
96
+ message_thread_id=message_thread_id,
97
+ has_spoiler=has_spoiler,
98
+ show_caption_above_media=show_caption_above_media
99
+ )
100
+
101
+ case enums.MediaType.ANIMATION:
102
+ return await self.send_animation(
103
+ chat_id=chat_id,
104
+ animation=media,
105
+ caption=caption,
106
+ parse_mode=parse_mode,
107
+ caption_entities=caption_entities,
108
+ disable_notification=disable_notification,
109
+ protect_content=protect_content,
110
+ reply_parameters=reply_parameters,
111
+ reply_markup=reply_markup,
112
+ message_effect_id=message_effect_id,
113
+ allow_paid_broadcast=allow_paid_broadcast,
114
+ business_connection_id=business_connection_id,
115
+ message_thread_id=message_thread_id,
116
+ has_spoiler=has_spoiler,
117
+ show_caption_above_media=show_caption_above_media
118
+ )
119
+
120
+ case enums.MediaType.AUDIO:
121
+ return await self.send_audio(
122
+ chat_id=chat_id,
123
+ audio=media,
124
+ caption=caption,
125
+ parse_mode=parse_mode,
126
+ caption_entities=caption_entities,
127
+ disable_notification=disable_notification,
128
+ protect_content=protect_content,
129
+ reply_parameters=reply_parameters,
130
+ reply_markup=reply_markup,
131
+ message_effect_id=message_effect_id,
132
+ allow_paid_broadcast=allow_paid_broadcast,
133
+ business_connection_id=business_connection_id,
134
+ message_thread_id=message_thread_id,
135
+ # has_spoiler=has_spoiler,
136
+ # show_caption_above_media=show_caption_above_media
137
+ )
138
+
139
+ case enums.MediaType.DOCUMENT:
140
+ return await self.send_document(
141
+ chat_id=chat_id,
142
+ document=media,
143
+ caption=caption,
144
+ parse_mode=parse_mode,
145
+ caption_entities=caption_entities,
146
+ disable_notification=disable_notification,
147
+ protect_content=protect_content,
148
+ reply_parameters=reply_parameters,
149
+ reply_markup=reply_markup,
150
+ message_effect_id=message_effect_id,
151
+ allow_paid_broadcast=allow_paid_broadcast,
152
+ business_connection_id=business_connection_id,
153
+ message_thread_id=message_thread_id,
154
+ # has_spoiler=has_spoiler,
155
+ # show_caption_above_media=show_caption_above_media,
156
+ disable_content_type_detection=disable_content_type_detection
157
+ )
158
+
159
+ case enums.MediaType.VOICE:
160
+ return await self.send_voice(
161
+ chat_id=chat_id,
162
+ voice=media,
163
+ caption=caption,
164
+ parse_mode=parse_mode,
165
+ caption_entities=caption_entities,
166
+ disable_notification=disable_notification,
167
+ protect_content=protect_content,
168
+ reply_parameters=reply_parameters,
169
+ reply_markup=reply_markup,
170
+ message_effect_id=message_effect_id,
171
+ allow_paid_broadcast=allow_paid_broadcast,
172
+ business_connection_id=business_connection_id,
173
+ message_thread_id=message_thread_id,
174
+ # has_spoiler=has_spoiler,
175
+ # show_caption_above_media=show_caption_above_media
176
+ )
177
+
178
+ case enums.MediaType.VIDEO_NOTE:
179
+ return await self.send_video_note(
180
+ chat_id=chat_id,
181
+ video_note=media,
182
+ # caption=caption,
183
+ # parse_mode=parse_mode,
184
+ # caption_entities=caption_entities,
185
+ disable_notification=disable_notification,
186
+ protect_content=protect_content,
187
+ reply_parameters=reply_parameters,
188
+ reply_markup=reply_markup,
189
+ message_effect_id=message_effect_id,
190
+ allow_paid_broadcast=allow_paid_broadcast,
191
+ business_connection_id=business_connection_id,
192
+ message_thread_id=message_thread_id,
193
+ # has_spoiler=has_spoiler,
194
+ # show_caption_above_media=show_caption_above_media
195
+ )
196
+
197
+ case enums.MediaType.STICKER:
198
+ return await self.send_sticker(
199
+ chat_id=chat_id,
200
+ sticker=media,
201
+ # caption=caption,
202
+ # parse_mode=parse_mode,
203
+ # caption_entities=caption_entities,
204
+ disable_notification=disable_notification,
205
+ protect_content=protect_content,
206
+ reply_parameters=reply_parameters,
207
+ reply_markup=reply_markup,
208
+ message_effect_id=message_effect_id,
209
+ allow_paid_broadcast=allow_paid_broadcast,
210
+ business_connection_id=business_connection_id,
211
+ message_thread_id=message_thread_id,
212
+ # has_spoiler=has_spoiler,
213
+ # show_caption_above_media=show_caption_above_media
214
+ )
215
+
216
+ case enums.MediaType.STORY, enums.MediaType.PAID_MEDIA:
217
+ raise ValueError(f'Unsupported media type: {file_type}')
218
+
219
+ case _:
220
+ raise ValueError(f'Unknown media type: {file_type}')
221
+
@@ -178,6 +178,7 @@ class Message(MaybeInaccessibleMessage, frozen=True):
178
178
  message_thread_id: Optional[int] = None,
179
179
  direct_messages_topic_id: Optional[int] = None,
180
180
  video_start_timestamp: Optional[int] = None,
181
+ message_effect_id: Optional[str] = None,
181
182
  # suggested_post_parameters: Optional[SuggestedPostParameters] = None,
182
183
  ) -> Message:
183
184
  '''
@@ -193,6 +194,7 @@ class Message(MaybeInaccessibleMessage, frozen=True):
193
194
  video_start_timestamp=video_start_timestamp,
194
195
  disable_notification=disable_notification,
195
196
  protect_content=protect_content,
197
+ message_effect_id=message_effect_id,
196
198
  # suggested_post_parameters=suggested_post_parameters
197
199
  )
198
200
 
@@ -210,6 +212,7 @@ class Message(MaybeInaccessibleMessage, frozen=True):
210
212
  disable_notification: Optional[bool] = None,
211
213
  protect_content: Optional[bool] = None,
212
214
  # allow_paid_broadcast: Optional[bool] = None,
215
+ message_effect_id: Optional[str] = None,
213
216
  # suggested_post_parameters: Optional[SuggestedPostParameters] = None,
214
217
  # reply_parameters: Optional[ReplyParameters] = None,
215
218
  # reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None
@@ -232,6 +235,7 @@ class Message(MaybeInaccessibleMessage, frozen=True):
232
235
  disable_notification=disable_notification,
233
236
  protect_content=protect_content,
234
237
  # allow_paid_broadcast=allow_paid_broadcast,
238
+ message_effect_id=message_effect_id,
235
239
  # suggested_post_parameters=suggested_post_parameters,
236
240
  # reply_parameters=reply_parameters,
237
241
  # reply_markup=reply_markup
@@ -338,19 +342,7 @@ class Message(MaybeInaccessibleMessage, frozen=True):
338
342
  )
339
343
 
340
344
  @property
341
- def media(self) -> Union[
342
- Animation,
343
- Audio,
344
- Document,
345
- list[PhotoSize],
346
- Sticker,
347
- Video,
348
- VideoNote,
349
- Voice,
350
- Story,
351
- PaidMedia,
352
- None
353
- ]:
345
+ def media(self) -> Optional[MediaTypeUnion]:
354
346
  '''
355
347
  Actual multimedia content of this message.
356
348
 
@@ -4525,3 +4517,5 @@ IntAdapter = TypeAdapter[int](int)
4525
4517
  StrAdapter = TypeAdapter[str](str)
4526
4518
  FloatAdapter = TypeAdapter[float](float)
4527
4519
  BoolAdapter = TypeAdapter[bool](bool)
4520
+
4521
+ MediaTypeUnion = Union[Animation, Audio, Document, List[PhotoSize], Sticker, Video, VideoNote, Voice, Story, PaidMedia]
File without changes
File without changes
File without changes