RubigramClient 1.7.17__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.
- rubigram/__init__.py +15 -0
- rubigram/client.py +294 -0
- rubigram/enums/__init__.py +52 -0
- rubigram/enums/buttons/__init__.py +13 -0
- rubigram/enums/buttons/button_calendar_type.py +20 -0
- rubigram/enums/buttons/button_location_type.py +20 -0
- rubigram/enums/buttons/button_selection_get_type.py +20 -0
- rubigram/enums/buttons/button_selection_search_type.py +20 -0
- rubigram/enums/buttons/button_selection_type.py +22 -0
- rubigram/enums/buttons/button_textbox_type_keypad.py +20 -0
- rubigram/enums/buttons/button_textbox_type_line.py +20 -0
- rubigram/enums/buttons/button_type.py +58 -0
- rubigram/enums/chat_action_type.py +22 -0
- rubigram/enums/chat_keypad_type.py +20 -0
- rubigram/enums/chat_type.py +24 -0
- rubigram/enums/enum.py +6 -0
- rubigram/enums/file_type.py +28 -0
- rubigram/enums/forwarded_from_type.py +22 -0
- rubigram/enums/live_location_status.py +20 -0
- rubigram/enums/message_sender_type.py +20 -0
- rubigram/enums/metadata_type.py +18 -0
- rubigram/enums/parse_mode.py +20 -0
- rubigram/enums/payment_status_type.py +20 -0
- rubigram/enums/poll_status_type.py +20 -0
- rubigram/enums/update_endpoint_type.py +26 -0
- rubigram/enums/update_type.py +28 -0
- rubigram/errors.py +16 -0
- rubigram/filters.py +865 -0
- rubigram/http_session.py +96 -0
- rubigram/methods/__init__.py +26 -0
- rubigram/methods/chats/__init__.py +10 -0
- rubigram/methods/chats/get_chat.py +53 -0
- rubigram/methods/decorators/__init__.py +25 -0
- rubigram/methods/decorators/on_inline_message.py +70 -0
- rubigram/methods/decorators/on_message.py +62 -0
- rubigram/methods/decorators/on_remove_message.py +65 -0
- rubigram/methods/decorators/on_start.py +65 -0
- rubigram/methods/decorators/on_started_bot.py +70 -0
- rubigram/methods/decorators/on_stop.py +65 -0
- rubigram/methods/decorators/on_stopped_bot.py +70 -0
- rubigram/methods/decorators/on_update_message.py +70 -0
- rubigram/methods/files/__init__.py +32 -0
- rubigram/methods/files/download_file.py +118 -0
- rubigram/methods/files/get_file.py +41 -0
- rubigram/methods/files/get_file_name.py +41 -0
- rubigram/methods/files/request_send_file.py +49 -0
- rubigram/methods/files/send_file.py +133 -0
- rubigram/methods/files/send_gif.py +51 -0
- rubigram/methods/files/send_music.py +97 -0
- rubigram/methods/files/send_photo.py +95 -0
- rubigram/methods/files/send_video.py +96 -0
- rubigram/methods/files/send_voice.py +96 -0
- rubigram/methods/files/upload_file.py +114 -0
- rubigram/methods/messages/__init__.py +34 -0
- rubigram/methods/messages/delete_messages.py +84 -0
- rubigram/methods/messages/edit_chat_keypad.py +68 -0
- rubigram/methods/messages/edit_message.py +82 -0
- rubigram/methods/messages/edit_message_keypad.py +72 -0
- rubigram/methods/messages/edit_message_text.py +68 -0
- rubigram/methods/messages/forward_message.py +78 -0
- rubigram/methods/messages/remove_chat_keypad.py +46 -0
- rubigram/methods/messages/send_contact.py +114 -0
- rubigram/methods/messages/send_location.py +108 -0
- rubigram/methods/messages/send_message.py +115 -0
- rubigram/methods/messages/send_poll.py +104 -0
- rubigram/methods/messages/send_sticker.py +98 -0
- rubigram/methods/network/__init__.py +12 -0
- rubigram/methods/network/request.py +129 -0
- rubigram/methods/settings/__init__.py +16 -0
- rubigram/methods/settings/set_command.py +50 -0
- rubigram/methods/settings/setup_endpoints.py +48 -0
- rubigram/methods/settings/update_bot_endpoint.py +62 -0
- rubigram/methods/updates/__init__.py +14 -0
- rubigram/methods/updates/get_me.py +35 -0
- rubigram/methods/updates/get_update.py +62 -0
- rubigram/methods/utilities/__init__.py +14 -0
- rubigram/methods/utilities/dispatcher.py +66 -0
- rubigram/methods/utilities/run.py +118 -0
- rubigram/rubino/__init__.py +6 -0
- rubigram/rubino/client.py +374 -0
- rubigram/rubino/network.py +129 -0
- rubigram/server/__init__.py +6 -0
- rubigram/server/server.py +245 -0
- rubigram/state/__init__.py +7 -0
- rubigram/state/state.py +121 -0
- rubigram/state/storage.py +131 -0
- rubigram/types/__init__.py +66 -0
- rubigram/types/aux_data.py +28 -0
- rubigram/types/bot.py +51 -0
- rubigram/types/bot_command.py +26 -0
- rubigram/types/buttons/__init__.py +13 -0
- rubigram/types/buttons/button.py +59 -0
- rubigram/types/buttons/button_calendar.py +40 -0
- rubigram/types/buttons/button_location.py +40 -0
- rubigram/types/buttons/button_number_picker.py +34 -0
- rubigram/types/buttons/button_selection.py +48 -0
- rubigram/types/buttons/button_selection_item.py +32 -0
- rubigram/types/buttons/button_string_picker.py +29 -0
- rubigram/types/buttons/button_text_box.py +40 -0
- rubigram/types/chat.py +86 -0
- rubigram/types/config/__init__.py +6 -0
- rubigram/types/config/object.py +442 -0
- rubigram/types/contact_message.py +29 -0
- rubigram/types/file.py +78 -0
- rubigram/types/forwarded_from.py +39 -0
- rubigram/types/keypads/__init__.py +7 -0
- rubigram/types/keypads/keypad.py +31 -0
- rubigram/types/keypads/keypad_row.py +23 -0
- rubigram/types/live_location.py +44 -0
- rubigram/types/location.py +24 -0
- rubigram/types/messages/__init__.py +8 -0
- rubigram/types/messages/inline_message.py +78 -0
- rubigram/types/messages/message.py +117 -0
- rubigram/types/messages/update_message.py +341 -0
- rubigram/types/metadata/__init__.py +7 -0
- rubigram/types/metadata/metadata.py +43 -0
- rubigram/types/metadata/metadata_parts.py +42 -0
- rubigram/types/payment_status.py +30 -0
- rubigram/types/poll.py +32 -0
- rubigram/types/poll_status.py +40 -0
- rubigram/types/sticker.py +33 -0
- rubigram/types/updates/__init__.py +7 -0
- rubigram/types/updates/update.py +917 -0
- rubigram/types/updates/updates.py +56 -0
- rubigram/utils/__init__.py +14 -0
- rubigram/utils/auto_delete.py +93 -0
- rubigram/utils/parser.py +99 -0
- rubigramclient-1.7.17.dist-info/METADATA +215 -0
- rubigramclient-1.7.17.dist-info/RECORD +132 -0
- rubigramclient-1.7.17.dist-info/WHEEL +5 -0
- rubigramclient-1.7.17.dist-info/licenses/LICENSE +21 -0
- rubigramclient-1.7.17.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Optional, Union, BinaryIO
|
|
9
|
+
import rubigram
|
|
10
|
+
|
|
11
|
+
class SendPhoto:
|
|
12
|
+
"""
|
|
13
|
+
Photo sender for Rubika API.
|
|
14
|
+
|
|
15
|
+
This class provides an asynchronous method to send photos/images
|
|
16
|
+
to a chat. It is a specialized wrapper around `send_file` that
|
|
17
|
+
automatically sets the file type to Image and supports captions,
|
|
18
|
+
keypads, notifications, replies, and auto-deletion.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__slots__ = ()
|
|
22
|
+
|
|
23
|
+
async def send_photo(
|
|
24
|
+
self: rubigram.Client,
|
|
25
|
+
chat_id: str,
|
|
26
|
+
photo: Union[str, bytes, BinaryIO],
|
|
27
|
+
caption: Optional[str] = None,
|
|
28
|
+
filename: Optional[str] = None,
|
|
29
|
+
chat_keypad: Optional[rubigram.types.Keypad] = None,
|
|
30
|
+
inline_keypad: Optional[rubigram.types.Keypad] = None,
|
|
31
|
+
chat_keypad_type: Optional[rubigram.enums.ChatKeypadType] = None,
|
|
32
|
+
disable_notification: bool = False,
|
|
33
|
+
reply_to_message_id: Optional[str] = None,
|
|
34
|
+
parse_mode: Optional[Union[str, rubigram.enums.ParseMode]] = None,
|
|
35
|
+
auto_delete: Optional[int] = None
|
|
36
|
+
) -> rubigram.types.UMessage:
|
|
37
|
+
"""
|
|
38
|
+
Send a photo/image to a chat on Rubika.
|
|
39
|
+
|
|
40
|
+
Parameters:
|
|
41
|
+
chat_id (str):
|
|
42
|
+
Unique identifier of the target chat.
|
|
43
|
+
photo (Union[str, bytes, BinaryIO]):
|
|
44
|
+
Photo source. Can be a local file path, URL, bytes,
|
|
45
|
+
file-like object, or an existing File ID.
|
|
46
|
+
caption (Optional[str], default=None):
|
|
47
|
+
Caption or text to send with the photo.
|
|
48
|
+
filename (Optional[str], default=None):
|
|
49
|
+
Custom filename for the uploaded photo.
|
|
50
|
+
chat_keypad (Optional[rubigram.types.Keypad], default=None):
|
|
51
|
+
Custom chat keypad to attach to the message.
|
|
52
|
+
inline_keypad (Optional[rubigram.types.Keypad], default=None):
|
|
53
|
+
Inline keypad to attach to the message.
|
|
54
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], default=None):
|
|
55
|
+
Type of chat keypad.
|
|
56
|
+
disable_notification (bool, default=False):
|
|
57
|
+
If True, sends the message silently.
|
|
58
|
+
reply_to_message_id (Optional[str], default=None):
|
|
59
|
+
Message ID to reply to.
|
|
60
|
+
auto_delete (Optional[int], default=None):
|
|
61
|
+
Time in seconds after which the message will be
|
|
62
|
+
automatically deleted.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
rubigram.types.UMessage:
|
|
66
|
+
The sent photo message object.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
.. code-block:: python
|
|
70
|
+
# Send a local photo
|
|
71
|
+
message = await client.send_photo(chat_id="chat_id", photo="image.jpg")
|
|
72
|
+
|
|
73
|
+
# Send a photo from URL
|
|
74
|
+
message = await client.send_photo(chat_id="chat_id", photo="https://example.com/image.png")
|
|
75
|
+
|
|
76
|
+
# Send an existing photo by File ID
|
|
77
|
+
message = await client.send_photo(chat_id="chat_id", photo="file_id")
|
|
78
|
+
|
|
79
|
+
# Send photo bytes
|
|
80
|
+
message = await client.send_photo(chat_id="chat_id", photo=b"binary data")
|
|
81
|
+
"""
|
|
82
|
+
return await self.send_file(
|
|
83
|
+
chat_id,
|
|
84
|
+
photo,
|
|
85
|
+
caption,
|
|
86
|
+
filename,
|
|
87
|
+
rubigram.enums.FileType.IMAGE,
|
|
88
|
+
chat_keypad,
|
|
89
|
+
inline_keypad,
|
|
90
|
+
chat_keypad_type,
|
|
91
|
+
disable_notification,
|
|
92
|
+
reply_to_message_id,
|
|
93
|
+
parse_mode,
|
|
94
|
+
auto_delete
|
|
95
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Optional, Union, BinaryIO
|
|
9
|
+
import rubigram
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SendVideo:
|
|
13
|
+
"""
|
|
14
|
+
Video sender for Rubika API.
|
|
15
|
+
|
|
16
|
+
This class provides an asynchronous method to send video files
|
|
17
|
+
to a chat. It is a specialized wrapper around `send_file` that
|
|
18
|
+
automatically sets the file type to Video and supports captions,
|
|
19
|
+
keypads, notifications, replies, and auto-deletion.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
__slots__ = ()
|
|
23
|
+
|
|
24
|
+
async def send_video(
|
|
25
|
+
self: rubigram.Client,
|
|
26
|
+
chat_id: str,
|
|
27
|
+
video: Union[str, bytes, BinaryIO],
|
|
28
|
+
caption: Optional[str] = None,
|
|
29
|
+
filename: Optional[str] = None,
|
|
30
|
+
chat_keypad: Optional[rubigram.types.Keypad] = None,
|
|
31
|
+
inline_keypad: Optional[rubigram.types.Keypad] = None,
|
|
32
|
+
chat_keypad_type: Optional[rubigram.enums.ChatKeypadType] = None,
|
|
33
|
+
disable_notification: bool = False,
|
|
34
|
+
reply_to_message_id: Optional[str] = None,
|
|
35
|
+
parse_mode: Optional[Union[str, rubigram.enums.ParseMode]] = None,
|
|
36
|
+
auto_delete: Optional[int] = None
|
|
37
|
+
) -> rubigram.types.UMessage:
|
|
38
|
+
"""
|
|
39
|
+
Send a video to a chat on Rubika.
|
|
40
|
+
|
|
41
|
+
Parameters:
|
|
42
|
+
chat_id (str):
|
|
43
|
+
Unique identifier of the target chat.
|
|
44
|
+
video (Union[str, bytes, BinaryIO]):
|
|
45
|
+
Video source. Can be a local file path, URL, bytes,
|
|
46
|
+
file-like object, or an existing File ID.
|
|
47
|
+
caption (Optional[str], default=None):
|
|
48
|
+
Caption or text to send with the video.
|
|
49
|
+
filename (Optional[str], default=None):
|
|
50
|
+
Custom filename for the uploaded video.
|
|
51
|
+
chat_keypad (Optional[rubigram.types.Keypad], default=None):
|
|
52
|
+
Custom chat keypad to attach to the message.
|
|
53
|
+
inline_keypad (Optional[rubigram.types.Keypad], default=None):
|
|
54
|
+
Inline keypad to attach to the message.
|
|
55
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], default=None):
|
|
56
|
+
Type of chat keypad.
|
|
57
|
+
disable_notification (bool, default=False):
|
|
58
|
+
If True, sends the message silently.
|
|
59
|
+
reply_to_message_id (Optional[str], default=None):
|
|
60
|
+
Message ID to reply to.
|
|
61
|
+
auto_delete (Optional[int], default=None):
|
|
62
|
+
Time in seconds after which the message will be
|
|
63
|
+
automatically deleted.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
rubigram.types.UMessage:
|
|
67
|
+
The sent video message object.
|
|
68
|
+
|
|
69
|
+
Example:
|
|
70
|
+
.. code-block:: python
|
|
71
|
+
# Send a local video
|
|
72
|
+
message = await client.send_video(chat_id="chat_id", video="video.mp4")
|
|
73
|
+
|
|
74
|
+
# Send a video from URL
|
|
75
|
+
message = await client.send_video(chat_id="chat_id", video="https://example.com/video.mp4")
|
|
76
|
+
|
|
77
|
+
# Send an existing video by File ID
|
|
78
|
+
message = await client.send_video(chat_id="chat_id", video="file_id")
|
|
79
|
+
|
|
80
|
+
# Send video bytes
|
|
81
|
+
message = await client.send_video(chat_id="chat_id", video=b"binary data")
|
|
82
|
+
"""
|
|
83
|
+
return await self.send_file(
|
|
84
|
+
chat_id,
|
|
85
|
+
video,
|
|
86
|
+
caption,
|
|
87
|
+
filename,
|
|
88
|
+
rubigram.enums.FileType.VIDEO,
|
|
89
|
+
chat_keypad,
|
|
90
|
+
inline_keypad,
|
|
91
|
+
chat_keypad_type,
|
|
92
|
+
disable_notification,
|
|
93
|
+
reply_to_message_id,
|
|
94
|
+
parse_mode,
|
|
95
|
+
auto_delete
|
|
96
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Optional, Union, BinaryIO
|
|
9
|
+
import rubigram
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SendVoice:
|
|
13
|
+
"""
|
|
14
|
+
Voice message sender for Rubika API.
|
|
15
|
+
|
|
16
|
+
This class provides an asynchronous method to send voice/audio
|
|
17
|
+
messages to a chat. It is a specialized wrapper around `send_file`
|
|
18
|
+
that automatically sets the file type to Voice and supports
|
|
19
|
+
captions, keypads, notifications, replies, and auto-deletion.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
__slots__ = ()
|
|
23
|
+
|
|
24
|
+
async def send_voice(
|
|
25
|
+
self: rubigram.Client,
|
|
26
|
+
chat_id: str,
|
|
27
|
+
voice: Union[str, bytes, BinaryIO],
|
|
28
|
+
caption: Optional[str] = None,
|
|
29
|
+
filename: Optional[str] = None,
|
|
30
|
+
chat_keypad: Optional[rubigram.types.Keypad] = None,
|
|
31
|
+
inline_keypad: Optional[rubigram.types.Keypad] = None,
|
|
32
|
+
chat_keypad_type: Optional[rubigram.enums.ChatKeypadType] = None,
|
|
33
|
+
disable_notification: bool = False,
|
|
34
|
+
reply_to_message_id: Optional[str] = None,
|
|
35
|
+
parse_mode: Optional[Union[str, rubigram.enums.ParseMode]] = None,
|
|
36
|
+
auto_delete: Optional[int] = None
|
|
37
|
+
) -> rubigram.types.UMessage:
|
|
38
|
+
"""
|
|
39
|
+
Send a voice message to a chat on Rubika.
|
|
40
|
+
|
|
41
|
+
Parameters:
|
|
42
|
+
chat_id (str):
|
|
43
|
+
Unique identifier of the target chat.
|
|
44
|
+
voice (Union[str, bytes, BinaryIO]):
|
|
45
|
+
Voice source. Can be a local file path, URL, bytes,
|
|
46
|
+
file-like object, or an existing File ID.
|
|
47
|
+
caption (Optional[str], default=None):
|
|
48
|
+
Caption or text to send with the voice message.
|
|
49
|
+
filename (Optional[str], default=None):
|
|
50
|
+
Custom filename for the uploaded voice file.
|
|
51
|
+
chat_keypad (Optional[rubigram.types.Keypad], default=None):
|
|
52
|
+
Custom chat keypad to attach to the message.
|
|
53
|
+
inline_keypad (Optional[rubigram.types.Keypad], default=None):
|
|
54
|
+
Inline keypad to attach to the message.
|
|
55
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], default=None):
|
|
56
|
+
Type of chat keypad.
|
|
57
|
+
disable_notification (Optional[bool], default=False):
|
|
58
|
+
If True, sends the message silently.
|
|
59
|
+
reply_to_message_id (Optional[str], default=None):
|
|
60
|
+
Message ID to reply to.
|
|
61
|
+
auto_delete (Optional[int], default=None):
|
|
62
|
+
Time in seconds after which the message will be
|
|
63
|
+
automatically deleted.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
rubigram.types.UMessage:
|
|
67
|
+
The sent voice message object.
|
|
68
|
+
|
|
69
|
+
Example:
|
|
70
|
+
.. code-block:: python
|
|
71
|
+
# Send a local voice file
|
|
72
|
+
message = await client.send_voice(chat_id="chat_id", voice="voice.ogg")
|
|
73
|
+
|
|
74
|
+
# Send a voice message from URL
|
|
75
|
+
message = await client.send_voice(chat_id="chat_id", voice="https://example.com/voice.ogg")
|
|
76
|
+
|
|
77
|
+
# Send an existing voice by File ID
|
|
78
|
+
message = await client.send_voice(chat_id="chat_id", voice="file_id")
|
|
79
|
+
|
|
80
|
+
# Send voice bytes
|
|
81
|
+
message = await client.send_voice(chat_id="chat_id", voice=b"binary data")
|
|
82
|
+
"""
|
|
83
|
+
return await self.send_file(
|
|
84
|
+
chat_id,
|
|
85
|
+
voice,
|
|
86
|
+
caption,
|
|
87
|
+
filename,
|
|
88
|
+
rubigram.enums.FileType.VOICE,
|
|
89
|
+
chat_keypad,
|
|
90
|
+
inline_keypad,
|
|
91
|
+
chat_keypad_type,
|
|
92
|
+
disable_notification,
|
|
93
|
+
reply_to_message_id,
|
|
94
|
+
parse_mode,
|
|
95
|
+
auto_delete
|
|
96
|
+
)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from aiohttp import FormData, ClientError
|
|
7
|
+
from aiohttp import FormData, ClientError, payload
|
|
8
|
+
from typing import Union, Optional, BinaryIO
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from aiohttp import FormData
|
|
11
|
+
import asyncio
|
|
12
|
+
import rubigram
|
|
13
|
+
import logging
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class UploadFile:
|
|
20
|
+
"""
|
|
21
|
+
File uploader for Rubika API.
|
|
22
|
+
|
|
23
|
+
This class provides an asynchronous method to upload files to a
|
|
24
|
+
temporary Rubika upload URL. It supports local file paths, remote
|
|
25
|
+
URLs, bytes, and file-like objects, and handles network and timeout
|
|
26
|
+
errors.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
__slots__ = ()
|
|
30
|
+
|
|
31
|
+
async def upload_file(
|
|
32
|
+
self: "rubigram.Client",
|
|
33
|
+
upload_url: str,
|
|
34
|
+
file: Union[str, bytes, BinaryIO],
|
|
35
|
+
name: Optional[str] = None,
|
|
36
|
+
) -> Union[str, None]:
|
|
37
|
+
"""
|
|
38
|
+
Upload a file to a temporary Rubika upload URL.
|
|
39
|
+
|
|
40
|
+
Parameters:
|
|
41
|
+
upload_url (str):
|
|
42
|
+
The temporary URL obtained from `request_send_file`.
|
|
43
|
+
file (Union[str, bytes, BinaryIO]):
|
|
44
|
+
File path, remote URL, bytes, or file-like object to upload.
|
|
45
|
+
name (Optional[str], default=None):
|
|
46
|
+
Custom name for the uploaded file. If None, the name
|
|
47
|
+
is inferred from the file path or URL, or defaults to "file".
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Union(str, None):
|
|
51
|
+
The file_id returned by Rubika after a successful upload,
|
|
52
|
+
or None if the server response does not contain a file_id.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
TimeoutError:
|
|
56
|
+
If the upload times out.
|
|
57
|
+
ConnectionError:
|
|
58
|
+
If a network error occurs during upload.
|
|
59
|
+
|
|
60
|
+
Example:
|
|
61
|
+
.. code-block:: python
|
|
62
|
+
# Upload a local file
|
|
63
|
+
file_id = await client.upload_file(upload_url, "example.jpg")
|
|
64
|
+
|
|
65
|
+
# Upload from URL
|
|
66
|
+
file_id = await client.upload_file(upload_url, "https://example.com/file.png")
|
|
67
|
+
|
|
68
|
+
# Upload from bytes
|
|
69
|
+
file_id = await client.upload_file(upload_url, b"binary data")
|
|
70
|
+
"""
|
|
71
|
+
if isinstance(file, str):
|
|
72
|
+
if file.startswith(("http://", "https://")):
|
|
73
|
+
async with self.http.session.get(file) as response:
|
|
74
|
+
response.raise_for_status()
|
|
75
|
+
data = await response.read()
|
|
76
|
+
if not name:
|
|
77
|
+
if response.content_type == "application/octet-stream":
|
|
78
|
+
ext = "ogg"
|
|
79
|
+
else:
|
|
80
|
+
ext = f"{str(response.content_type).split("/")[1]}"
|
|
81
|
+
name = await self.get_file_name(file) or f"rubigram.{ext}"
|
|
82
|
+
else:
|
|
83
|
+
data = Path(file).read_bytes()
|
|
84
|
+
name = name or Path(file).name
|
|
85
|
+
else:
|
|
86
|
+
data = file.read() if hasattr(file, "read") else file
|
|
87
|
+
name = file.name if hasattr(file, "name") else "file.bin"
|
|
88
|
+
|
|
89
|
+
form = FormData()
|
|
90
|
+
form.add_field(
|
|
91
|
+
"file", payload.BytesPayload(data), filename=name
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
async with self.http.session.post(upload_url, data=form) as response:
|
|
96
|
+
result: dict = await response.json()
|
|
97
|
+
if result.get("status") == "OK":
|
|
98
|
+
logger.debug("Upload file, name=%s", name)
|
|
99
|
+
return result.get("data", {}).get("file_id")
|
|
100
|
+
|
|
101
|
+
elif result.get("status") == "INVALID_INPUT":
|
|
102
|
+
raise rubigram.errors.InvalidInput(result)
|
|
103
|
+
|
|
104
|
+
elif result.get("status") == "INVALID_ACCESS":
|
|
105
|
+
raise rubigram.errors.InvalidAccess(result)
|
|
106
|
+
|
|
107
|
+
else:
|
|
108
|
+
raise Exception(str(result))
|
|
109
|
+
|
|
110
|
+
except asyncio.TimeoutError as error:
|
|
111
|
+
raise TimeoutError(str(error))
|
|
112
|
+
|
|
113
|
+
except ClientError as error:
|
|
114
|
+
raise ConnectionError(str(error))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from .delete_messages import DeleteMessage
|
|
7
|
+
from .edit_chat_keypad import EditChatKeypad
|
|
8
|
+
from .edit_message_keypad import EditMessageKeypad
|
|
9
|
+
from .edit_message_text import EditMessageText
|
|
10
|
+
from .edit_message import EditMessage
|
|
11
|
+
from .forward_message import ForwardMessage
|
|
12
|
+
from .remove_chat_keypad import RemoveChatKeypad
|
|
13
|
+
from .send_contact import SendContact
|
|
14
|
+
from .send_location import SendLocation
|
|
15
|
+
from .send_message import SendMessage
|
|
16
|
+
from .send_poll import SendPoll
|
|
17
|
+
from .send_sticker import SendSticker
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Messages(
|
|
21
|
+
DeleteMessage,
|
|
22
|
+
EditChatKeypad,
|
|
23
|
+
EditMessageKeypad,
|
|
24
|
+
EditMessageText,
|
|
25
|
+
EditMessage,
|
|
26
|
+
ForwardMessage,
|
|
27
|
+
RemoveChatKeypad,
|
|
28
|
+
SendContact,
|
|
29
|
+
SendLocation,
|
|
30
|
+
SendMessage,
|
|
31
|
+
SendPoll,
|
|
32
|
+
SendSticker
|
|
33
|
+
):
|
|
34
|
+
pass
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Union
|
|
9
|
+
import asyncio
|
|
10
|
+
import rubigram
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DeleteMessage:
|
|
14
|
+
async def delete_messages(
|
|
15
|
+
self: rubigram.Client,
|
|
16
|
+
chat_id: str,
|
|
17
|
+
message_ids: Union[str, int, list[Union[str, int]]]
|
|
18
|
+
) -> dict:
|
|
19
|
+
"""
|
|
20
|
+
**Delete one or multiple messages from a chat.**
|
|
21
|
+
`await client.delete_message(chat_id, message_id)`
|
|
22
|
+
|
|
23
|
+
This method can delete a single message or multiple messages in bulk.
|
|
24
|
+
When deleting multiple messages, it uses asyncio.gather for efficient
|
|
25
|
+
parallel execution.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
chat_id (`str`):
|
|
29
|
+
The ID of the chat where the message(s) are located.
|
|
30
|
+
|
|
31
|
+
message_ids (`Union[str, int, list[Union[str, int]]]`):
|
|
32
|
+
Single message ID or list of message IDs to delete.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
dict: A dictionary containing deletion results with the following keys:
|
|
36
|
+
- success (int): Number of successfully deleted messages
|
|
37
|
+
- failed (int): Number of messages that failed to delete
|
|
38
|
+
- details (list): List of individual deletion responses
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
.. code-block:: python
|
|
42
|
+
|
|
43
|
+
# Delete a single message
|
|
44
|
+
result = await client.delete_message(
|
|
45
|
+
chat_id=chat_id,
|
|
46
|
+
message_ids=message_id
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# Delete multiple messages
|
|
50
|
+
message_ids = ["12345", "12346", "12347"]
|
|
51
|
+
result = await client.delete_message(
|
|
52
|
+
chat_id=chat_id,
|
|
53
|
+
message_ids=message_ids
|
|
54
|
+
)
|
|
55
|
+
print(f"Success: {result['success']}, Failed: {result['failed']}")
|
|
56
|
+
|
|
57
|
+
Note:
|
|
58
|
+
When deleting multiple messages, the operation continues even if
|
|
59
|
+
some deletions fail. Check the 'failed' count and 'details' for
|
|
60
|
+
individual results.
|
|
61
|
+
"""
|
|
62
|
+
if isinstance(message_ids, (str, int)):
|
|
63
|
+
return await self.request("deleteMessage", {"chat_id": chat_id, "message_id": str(message_ids)})
|
|
64
|
+
|
|
65
|
+
elif isinstance(message_ids, list):
|
|
66
|
+
ids = [str(i) for i in message_ids]
|
|
67
|
+
|
|
68
|
+
tasks = [
|
|
69
|
+
self.request(
|
|
70
|
+
"deleteMessage",
|
|
71
|
+
{"chat_id": chat_id, "message_id": id}
|
|
72
|
+
)
|
|
73
|
+
for id in ids
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
responses = await asyncio.gather(*tasks, return_exceptions=True)
|
|
77
|
+
success = sum(1 for r in responses if not isinstance(r, Exception))
|
|
78
|
+
failed = len(responses) - success
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
"success": success,
|
|
82
|
+
"failed": failed,
|
|
83
|
+
"details": responses
|
|
84
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import rubigram
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class EditChatKeypad:
|
|
12
|
+
async def edit_chat_keypad(
|
|
13
|
+
self: rubigram.Client,
|
|
14
|
+
chat_id: str,
|
|
15
|
+
chat_keypad: rubigram.types.Keypad
|
|
16
|
+
):
|
|
17
|
+
"""
|
|
18
|
+
**Edit the chat keypad for a specific chat.**
|
|
19
|
+
`await client.edit_chat_keypad(chat_id, chat_keypad)`
|
|
20
|
+
|
|
21
|
+
This method updates the custom keyboard (keypad) for the specified chat.
|
|
22
|
+
The new keypad will be displayed to all users in the chat.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
chat_id (`str`):
|
|
26
|
+
The ID of the chat where the keypad should be updated.
|
|
27
|
+
|
|
28
|
+
chat_keypad (`rubigram.types.Keypad`):
|
|
29
|
+
The new keypad object containing rows of buttons and display settings.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
dict: The API response from Rubigram.
|
|
33
|
+
|
|
34
|
+
Example:
|
|
35
|
+
.. code-block:: python
|
|
36
|
+
|
|
37
|
+
from rubigram.types import Keypad, KeypadRow, Button
|
|
38
|
+
|
|
39
|
+
# Create a new keypad
|
|
40
|
+
keypad = Keypad(
|
|
41
|
+
rows=[
|
|
42
|
+
KeypadRow(buttons=[
|
|
43
|
+
Button(button_text="Option 1", id="btn1"),
|
|
44
|
+
Button(button_text="Option 2", id="btn2")
|
|
45
|
+
])
|
|
46
|
+
],
|
|
47
|
+
resize_keyboard=True
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Update the chat keypad
|
|
51
|
+
await client.edit_chat_keypad(
|
|
52
|
+
chat_id=chat_id,
|
|
53
|
+
chat_keypad=keypad
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
Note:
|
|
57
|
+
This method sets the keypad type to "New" by default, replacing
|
|
58
|
+
any existing keypad in the chat.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
return await self.request(
|
|
62
|
+
"editChatKeypad",
|
|
63
|
+
{
|
|
64
|
+
"chat_id": chat_id,
|
|
65
|
+
"chat_keypad_type": "New",
|
|
66
|
+
"chat_keypad": chat_keypad.as_dict()
|
|
67
|
+
}
|
|
68
|
+
)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# RubigramClient - Rubika API library for python
|
|
2
|
+
# Copyright (C) 2025-present Javad <https://github.com/DevJavad>
|
|
3
|
+
# Github - https://github.com/DevJavad/rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Optional, Union
|
|
9
|
+
import rubigram
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class EditMessage:
|
|
13
|
+
async def edit_message(
|
|
14
|
+
self: rubigram.Client,
|
|
15
|
+
chat_id: str,
|
|
16
|
+
message_id: Optional[str] = None,
|
|
17
|
+
text: Optional[str] = None,
|
|
18
|
+
chat_keypad: Optional[rubigram.types.Keypad] = None,
|
|
19
|
+
inline_keypad: Optional[rubigram.types.Keypad] = None,
|
|
20
|
+
parse_mode: Optional[Union[str, rubigram.enums.ParseMode]] = None
|
|
21
|
+
):
|
|
22
|
+
"""
|
|
23
|
+
**Edit various components of a message or chat.**
|
|
24
|
+
`await client.edit_message(chat_id, message_id, text=text, inline_keypad=keypad)`
|
|
25
|
+
|
|
26
|
+
This method provides a unified way to update message text, chat keypads,
|
|
27
|
+
and inline keyboards in a single call. You can update one or more
|
|
28
|
+
components simultaneously.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
chat_id (`str`):
|
|
32
|
+
The ID of the chat where the edits should be applied.
|
|
33
|
+
|
|
34
|
+
message_id (`Optional[str]`):
|
|
35
|
+
The ID of the message to edit (required for text and inline keyboard edits).
|
|
36
|
+
|
|
37
|
+
text (`Optional[str]`):
|
|
38
|
+
New text content for the message. If provided, updates the message text.
|
|
39
|
+
|
|
40
|
+
chat_keypad (`Optional[rubigram.types.Keypad]`):
|
|
41
|
+
New chat keypad to set for the chat. Updates the keyboard for all users.
|
|
42
|
+
|
|
43
|
+
inline_keypad (`Optional[rubigram.types.Keypad]`):
|
|
44
|
+
New inline keyboard to attach to the message. Updates buttons below the message.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
None: This method doesn't return a value as it may perform multiple operations.
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
.. code-block:: python
|
|
51
|
+
|
|
52
|
+
from rubigram.types import Keypad, KeypadRow, Button
|
|
53
|
+
|
|
54
|
+
# Create an inline keyboard
|
|
55
|
+
inline_keypad = Keypad(rows=[
|
|
56
|
+
KeypadRow(buttons=[
|
|
57
|
+
Button(button_text="Option 1", id="btn1"),
|
|
58
|
+
Button(button_text="Option 2", id="btn2")
|
|
59
|
+
])
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
# Edit message text and inline keyboard
|
|
63
|
+
await client.edit_message(
|
|
64
|
+
chat_id=chat_id,
|
|
65
|
+
message_id=message_id,
|
|
66
|
+
text=text,
|
|
67
|
+
inline_keypad=inline_keypad
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
Note:
|
|
71
|
+
- At least one of `text`, `chat_keypad`, or `inline_keypad` must be provided
|
|
72
|
+
- `message_id` is required when editing text or inline keyboards
|
|
73
|
+
- Chat keypad updates affect the entire chat, not just a specific message
|
|
74
|
+
"""
|
|
75
|
+
if text:
|
|
76
|
+
return await self.edit_message_text(chat_id, message_id, text, parse_mode)
|
|
77
|
+
|
|
78
|
+
if chat_keypad:
|
|
79
|
+
return await self.edit_chat_keypad(chat_id, chat_keypad)
|
|
80
|
+
|
|
81
|
+
if inline_keypad:
|
|
82
|
+
return await self.edit_message_keypad(chat_id, message_id, inline_keypad)
|