RubigramClient 1.7.1__py3-none-any.whl → 1.7.2__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.
Potentially problematic release.
This version of RubigramClient might be problematic. Click here for more details.
- rubigram/__init__.py +1 -5
- rubigram/client.py +102 -154
- rubigram/enums.py +4 -3
- rubigram/filters.py +600 -139
- rubigram/handler.py +24 -0
- rubigram/http.py +32 -0
- rubigram/logger.py +20 -0
- rubigram/method/__init__.py +18 -0
- rubigram/method/chat/__init__.py +10 -0
- rubigram/method/chat/get_chat.py +26 -0
- rubigram/method/chat/get_me.py +22 -0
- rubigram/method/chat/get_update.py +32 -0
- rubigram/method/decorator/__init__.py +8 -0
- rubigram/method/decorator/on_delete_message.py +37 -0
- rubigram/method/decorator/on_edit_message.py +37 -0
- rubigram/method/decorator/on_inline_message.py +40 -0
- rubigram/method/decorator/on_message.py +38 -0
- rubigram/method/decorator/on_start.py +30 -0
- rubigram/method/decorator/on_stop.py +29 -0
- rubigram/method/decorator/register.py +43 -0
- rubigram/method/file/__init__.py +32 -0
- rubigram/method/file/download_file.py +34 -0
- rubigram/method/file/get_bytes.py +25 -0
- rubigram/method/file/get_file.py +27 -0
- rubigram/method/file/get_file_name.py +29 -0
- rubigram/method/file/request_download_file.py +35 -0
- rubigram/method/file/request_send_file.py +28 -0
- rubigram/method/file/request_upload_file.py +62 -0
- rubigram/method/file/send_document.py +58 -0
- rubigram/method/file/send_file.py +78 -0
- rubigram/method/file/send_gif.py +58 -0
- rubigram/method/file/send_music.py +58 -0
- rubigram/method/file/send_photo.py +58 -0
- rubigram/method/file/send_video.py +58 -0
- rubigram/method/file/send_voice.py +55 -0
- rubigram/method/messages/__init__.py +29 -0
- rubigram/method/messages/delete_message.py +50 -0
- rubigram/method/messages/edit_chat_keypad.py +34 -0
- rubigram/method/messages/edit_message.py +41 -0
- rubigram/method/messages/edit_message_keypad.py +38 -0
- rubigram/method/messages/edit_message_text.py +34 -0
- rubigram/method/messages/forward_message.py +43 -0
- rubigram/method/messages/remove_chat_keypad.py +28 -0
- rubigram/method/messages/send_contact.py +74 -0
- rubigram/method/messages/send_location.py +70 -0
- rubigram/method/messages/send_message.py +67 -0
- rubigram/method/messages/send_poll.py +71 -0
- rubigram/method/messages/send_sticker.py +66 -0
- rubigram/method/network/__init__.py +7 -0
- rubigram/method/network/request.py +20 -0
- rubigram/method/setting/__init__.py +9 -0
- rubigram/method/setting/set_command.py +32 -0
- rubigram/method/setting/update_bot_endpoint.py +31 -0
- rubigram/method/utilities/__init__.py +11 -0
- rubigram/method/utilities/dispatch.py +25 -0
- rubigram/method/utilities/setup_endpoint.py +16 -0
- rubigram/method/utilities/updater.py +17 -0
- rubigram/state.py +14 -19
- rubigram/types/__init__.py +3 -0
- rubigram/types/messages.py +175 -0
- rubigram/types/object.py +112 -0
- rubigram/types/types.py +211 -0
- rubigram/types/updates.py +572 -0
- {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.2.dist-info}/METADATA +4 -3
- rubigramclient-1.7.2.dist-info/RECORD +68 -0
- rubigram/method.py +0 -354
- rubigram/network.py +0 -80
- rubigram/rubino/__init__.py +0 -1
- rubigram/rubino/client.py +0 -480
- rubigram/types.py +0 -538
- rubigramclient-1.7.1.dist-info/RECORD +0 -15
- {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.2.dist-info}/WHEEL +0 -0
- {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.2.dist-info}/licenses/LICENSE +0 -0
- {rubigramclient-1.7.1.dist-info → rubigramclient-1.7.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class EditMessage:
|
|
6
|
+
async def edit_message(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
message_id: Optional[str] = None,
|
|
10
|
+
text: Optional[str] = None,
|
|
11
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
12
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None
|
|
13
|
+
):
|
|
14
|
+
"""Edit various properties of a message.
|
|
15
|
+
|
|
16
|
+
This method allows updating a message's text, chat keypad, or inline keypad.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
20
|
+
chat_id (str): The unique identifier of the chat containing the message.
|
|
21
|
+
message_id (Optional[str], optional): The unique identifier of the message to edit.
|
|
22
|
+
text (Optional[str], optional): The new message text.
|
|
23
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): A new chat keypad layout.
|
|
24
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): A new inline keypad layout.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
None: This method does not return a response directly.
|
|
28
|
+
|
|
29
|
+
Example:
|
|
30
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
31
|
+
>>> button = Button(id="101", button_text="rubigram")
|
|
32
|
+
>>> row = KeypadRow(buttons=[button])
|
|
33
|
+
>>> keypad = Keypad(rows=[row])
|
|
34
|
+
>>> await client.edit_message("chat123", "msg456", text="Updated!", inline_keypad=keypad)
|
|
35
|
+
"""
|
|
36
|
+
if text:
|
|
37
|
+
await self.edit_message_text(chat_id, message_id, text)
|
|
38
|
+
if chat_keypad:
|
|
39
|
+
await self.edit_chat_keypad(chat_id, chat_keypad)
|
|
40
|
+
if inline_keypad:
|
|
41
|
+
await self.edit_message_keypad(chat_id, message_id, inline_keypad)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import rubigram
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EditMessageKeypad:
|
|
5
|
+
async def edit_message_keypad(
|
|
6
|
+
self: "rubigram.Client",
|
|
7
|
+
chat_id: str,
|
|
8
|
+
message_id: str,
|
|
9
|
+
inline_keypad: "rubigram.types.Keypad"
|
|
10
|
+
):
|
|
11
|
+
"""Edit the inline keypad (buttons) of a message.
|
|
12
|
+
|
|
13
|
+
This method updates the inline keypad of a specific message
|
|
14
|
+
in a chat with a new button layout.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
18
|
+
chat_id (str): The unique identifier of the chat containing the message.
|
|
19
|
+
message_id (str): The unique identifier of the message to update.
|
|
20
|
+
inline_keypad (rubigram.types.Keypad): A `Keypad` object defining the new inline buttons.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
dict: The response returned by the server.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
27
|
+
>>> button = Button(id="101", button_text="rubigram")
|
|
28
|
+
>>> row = KeypadRow(buttons=[button])
|
|
29
|
+
>>> keypad = Keypad(rows=[row])
|
|
30
|
+
>>> response = await client.edit_message_keypad("chat_id", "message_id", keypad)
|
|
31
|
+
>>> print(response)
|
|
32
|
+
"""
|
|
33
|
+
data = {
|
|
34
|
+
"chat_id": chat_id,
|
|
35
|
+
"message_id": message_id,
|
|
36
|
+
"inline_keypad": inline_keypad.asdict()
|
|
37
|
+
}
|
|
38
|
+
return await self.request("editMessageKeypad", data)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import rubigram
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EditMessageText:
|
|
5
|
+
async def edit_message_text(
|
|
6
|
+
self: "rubigram.Client",
|
|
7
|
+
chat_id: str,
|
|
8
|
+
message_id: str,
|
|
9
|
+
text: str
|
|
10
|
+
):
|
|
11
|
+
"""Edit the text content of a message.
|
|
12
|
+
|
|
13
|
+
This method changes the text of an existing message
|
|
14
|
+
in a specific chat.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
18
|
+
chat_id (str): The unique identifier of the chat containing the message.
|
|
19
|
+
message_id (str): The unique identifier of the message to edit.
|
|
20
|
+
text (str): The new text to replace the current message content.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
dict: The response returned by the server.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
>>> response = await client.edit_message_text("chat_id", "message_id", "New message text")
|
|
27
|
+
>>> print(response)
|
|
28
|
+
"""
|
|
29
|
+
data = {
|
|
30
|
+
"chat_id": chat_id,
|
|
31
|
+
"message_id": message_id,
|
|
32
|
+
"text": text
|
|
33
|
+
}
|
|
34
|
+
return await self.request("editMessageText", data)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ForwardMessage:
|
|
6
|
+
async def forward_message(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
from_chat_id: str,
|
|
9
|
+
message_id: str,
|
|
10
|
+
to_chat_id: str,
|
|
11
|
+
disable_notification: Optional[bool] = False
|
|
12
|
+
) -> "rubigram.types.UMessage":
|
|
13
|
+
"""Forward a message from one chat to another.
|
|
14
|
+
|
|
15
|
+
This method forwards a specific message from a source chat
|
|
16
|
+
to a target chat, optionally disabling notifications.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
20
|
+
from_chat_id (str): The unique identifier of the chat to forward the message from.
|
|
21
|
+
message_id (str): The unique identifier of the message to forward.
|
|
22
|
+
to_chat_id (str): The unique identifier of the chat to forward the message to.
|
|
23
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications for the forwarded message. Defaults to False.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
rubigram.types.UMessage: The forwarded message object.
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
>>> message = await client.forward_message("from_chat_id", "message_id", "to_chat_id")
|
|
30
|
+
>>> print(message.message_id)
|
|
31
|
+
"""
|
|
32
|
+
data = {
|
|
33
|
+
"from_chat_id": from_chat_id,
|
|
34
|
+
"message_id": message_id,
|
|
35
|
+
"to_chat_id": to_chat_id,
|
|
36
|
+
"disable_notification": disable_notification
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
response = await self.request("forwardMessage", data)
|
|
40
|
+
message = rubigram.types.UMessage.parse(response)
|
|
41
|
+
message.chat_id = to_chat_id
|
|
42
|
+
message.client = self
|
|
43
|
+
return message
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import rubigram
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class RemoveChatKeypad:
|
|
5
|
+
async def remove_chat_keypad(
|
|
6
|
+
self: "rubigram.Client",
|
|
7
|
+
chat_id: str
|
|
8
|
+
) -> dict:
|
|
9
|
+
"""Remove the chat keypad from a chat.
|
|
10
|
+
|
|
11
|
+
This method removes the custom chat keypad from a specific chat.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
15
|
+
chat_id (str): The unique identifier of the chat.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
dict: The response returned by the server.
|
|
19
|
+
|
|
20
|
+
Example:
|
|
21
|
+
>>> response = await client.remove_chat_keypad("chat_id")
|
|
22
|
+
>>> print(response)
|
|
23
|
+
"""
|
|
24
|
+
data = {
|
|
25
|
+
"chat_id": chat_id,
|
|
26
|
+
"chat_keypad_type": "Remove"
|
|
27
|
+
}
|
|
28
|
+
return await self.request("editChatKeypad", data)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendContact:
|
|
6
|
+
async def send_contact(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
first_name: str,
|
|
10
|
+
last_name: str,
|
|
11
|
+
phone_number: str,
|
|
12
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
13
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
14
|
+
chat_keypad_type: Optional["rubigram.enums.ChatKeypadType"] = None,
|
|
15
|
+
disable_notification: Optional[bool] = False,
|
|
16
|
+
reply_to_message_id: Optional[str] = None
|
|
17
|
+
) -> "rubigram.types.UMessage":
|
|
18
|
+
"""Send a contact to a chat.
|
|
19
|
+
|
|
20
|
+
This method sends a contact with first name, last name, and phone number
|
|
21
|
+
to a specified chat. Optional chat or inline keypads can be included.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The unique identifier of the target chat.
|
|
26
|
+
first_name (str): Contact's first name.
|
|
27
|
+
last_name (str): Contact's last name.
|
|
28
|
+
phone_number (str): Contact's phone number.
|
|
29
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Custom chat keypad. Defaults to None.
|
|
30
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad. Defaults to None.
|
|
31
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Type of chat keypad. Defaults to None.
|
|
32
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
33
|
+
reply_to_message_id (Optional[str], optional): Reply to a specific message ID. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
rubigram.types.UMessage: The sent message object.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
40
|
+
>>> button = Button(id="101", button_text="rubigram")
|
|
41
|
+
>>> row = KeypadRow(buttons=[button])
|
|
42
|
+
>>> keypad = Keypad(rows=[row])
|
|
43
|
+
>>> message = await client.send_contact(
|
|
44
|
+
... "chat_id",
|
|
45
|
+
... "John",
|
|
46
|
+
... "Doe",
|
|
47
|
+
... "+123456789",
|
|
48
|
+
... inline_keypad=keypad
|
|
49
|
+
... )
|
|
50
|
+
>>> print(message.message_id)
|
|
51
|
+
"""
|
|
52
|
+
data = {
|
|
53
|
+
"chat_id": chat_id,
|
|
54
|
+
"first_name": first_name,
|
|
55
|
+
"last_name": last_name,
|
|
56
|
+
"phone_number": phone_number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if chat_keypad:
|
|
60
|
+
data["chat_keypad"] = chat_keypad.asdict()
|
|
61
|
+
if inline_keypad:
|
|
62
|
+
data["inline_keypad"] = inline_keypad.asdict()
|
|
63
|
+
if chat_keypad_type:
|
|
64
|
+
data["chat_keypad_type"] = chat_keypad_type
|
|
65
|
+
if disable_notification:
|
|
66
|
+
data["disable_notification"] = disable_notification
|
|
67
|
+
if reply_to_message_id:
|
|
68
|
+
data["reply_to_message_id"] = reply_to_message_id
|
|
69
|
+
|
|
70
|
+
response = await self.request("sendContact", data)
|
|
71
|
+
message = rubigram.types.UMessage.parse(response)
|
|
72
|
+
message.chat_id = chat_id
|
|
73
|
+
message.client = self
|
|
74
|
+
return message
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendLocation:
|
|
6
|
+
async def send_location(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
latitude: str,
|
|
10
|
+
longitude: str,
|
|
11
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
12
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
13
|
+
chat_keypad_type: Optional["rubigram.enums.ChatKeypadType"] = None,
|
|
14
|
+
disable_notification: Optional[bool] = False,
|
|
15
|
+
reply_to_message_id: Optional[str] = None
|
|
16
|
+
) -> "rubigram.types.UMessage":
|
|
17
|
+
"""Send a location to a chat.
|
|
18
|
+
|
|
19
|
+
This method sends geographic coordinates to a specific chat,
|
|
20
|
+
with optional chat or inline keypads and notification settings.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
24
|
+
chat_id (str): The unique identifier of the target chat.
|
|
25
|
+
latitude (str): Latitude of the location.
|
|
26
|
+
longitude (str): Longitude of the location.
|
|
27
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Custom chat keypad. Defaults to None.
|
|
28
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad. Defaults to None.
|
|
29
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Type of chat keypad. Defaults to None.
|
|
30
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
31
|
+
reply_to_message_id (Optional[str], optional): Reply to a specific message ID. Defaults to None.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
rubigram.types.UMessage: The sent message object.
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
38
|
+
>>> button = Button(id="101", button_text="rubigram")
|
|
39
|
+
>>> row = KeypadRow(buttons=[button])
|
|
40
|
+
>>> keypad = Keypad(rows=[row])
|
|
41
|
+
>>> message = await client.send_location(
|
|
42
|
+
... "chat_id",
|
|
43
|
+
... "35.6895",
|
|
44
|
+
... "139.6917",
|
|
45
|
+
... inline_keypad=keypad
|
|
46
|
+
... )
|
|
47
|
+
>>> print(message.message_id)
|
|
48
|
+
"""
|
|
49
|
+
data = {
|
|
50
|
+
"chat_id": chat_id,
|
|
51
|
+
"latitude": latitude,
|
|
52
|
+
"longitude": longitude
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if chat_keypad:
|
|
56
|
+
data["chat_keypad"] = chat_keypad.asdict()
|
|
57
|
+
if inline_keypad:
|
|
58
|
+
data["inline_keypad"] = inline_keypad.asdict()
|
|
59
|
+
if chat_keypad_type:
|
|
60
|
+
data["chat_keypad_type"] = chat_keypad_type
|
|
61
|
+
if disable_notification:
|
|
62
|
+
data["disable_notification"] = disable_notification
|
|
63
|
+
if reply_to_message_id:
|
|
64
|
+
data["reply_to_message_id"] = reply_to_message_id
|
|
65
|
+
|
|
66
|
+
response = await self.request("sendLocation", data)
|
|
67
|
+
message = rubigram.types.UMessage.parse(response)
|
|
68
|
+
message.chat_id = chat_id
|
|
69
|
+
message.client = self
|
|
70
|
+
return message
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendMessage:
|
|
6
|
+
async def send_message(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
text: str,
|
|
10
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
11
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
12
|
+
chat_keypad_type: Optional["rubigram.enums.ChatKeypadType"] = None,
|
|
13
|
+
disable_notification: Optional[bool] = False,
|
|
14
|
+
reply_to_message_id: Optional[str] = None
|
|
15
|
+
) -> "rubigram.types.UMessage":
|
|
16
|
+
"""Send a text message to a chat.
|
|
17
|
+
|
|
18
|
+
This method sends a text message to a specific chat with optional
|
|
19
|
+
chat or inline keypads, notification settings, and reply options.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
23
|
+
chat_id (str): The unique identifier of the target chat.
|
|
24
|
+
text (str): The text content of the message.
|
|
25
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Custom chat keypad. Defaults to None.
|
|
26
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad. Defaults to None.
|
|
27
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Type of chat keypad. Defaults to None.
|
|
28
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
29
|
+
reply_to_message_id (Optional[str], optional): Reply to a specific message ID. Defaults to None.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
rubigram.types.UMessage: The sent message object.
|
|
33
|
+
|
|
34
|
+
Example:
|
|
35
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
36
|
+
>>> button = Button(id="101", button_text="rubigram")
|
|
37
|
+
>>> row = KeypadRow(buttons=[button])
|
|
38
|
+
>>> keypad = Keypad(rows=[row])
|
|
39
|
+
>>> message = await client.send_message(
|
|
40
|
+
... "chat_id",
|
|
41
|
+
... "Hello, world!",
|
|
42
|
+
... inline_keypad=keypad,
|
|
43
|
+
... disable_notification=True
|
|
44
|
+
... )
|
|
45
|
+
>>> print(message.message_id)
|
|
46
|
+
"""
|
|
47
|
+
data = {
|
|
48
|
+
"chat_id": chat_id,
|
|
49
|
+
"text": text
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if chat_keypad:
|
|
53
|
+
data["chat_keypad"] = chat_keypad.asdict()
|
|
54
|
+
if inline_keypad:
|
|
55
|
+
data["inline_keypad"] = inline_keypad.asdict()
|
|
56
|
+
if chat_keypad_type:
|
|
57
|
+
data["chat_keypad_type"] = chat_keypad_type
|
|
58
|
+
if disable_notification:
|
|
59
|
+
data["disable_notification"] = disable_notification
|
|
60
|
+
if reply_to_message_id:
|
|
61
|
+
data["reply_to_message_id"] = reply_to_message_id
|
|
62
|
+
|
|
63
|
+
response = await self.request("sendMessage", data)
|
|
64
|
+
message = rubigram.types.UMessage.parse(response)
|
|
65
|
+
message.chat_id = chat_id
|
|
66
|
+
message.client = self
|
|
67
|
+
return message
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendPoll:
|
|
6
|
+
async def send_poll(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
question: str,
|
|
10
|
+
options: list[str],
|
|
11
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
12
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
13
|
+
chat_keypad_type: Optional["rubigram.enums.ChatKeypadType"] = None,
|
|
14
|
+
disable_notification: Optional[bool] = False,
|
|
15
|
+
reply_to_message_id: Optional[str] = None
|
|
16
|
+
) -> "rubigram.types.UMessage":
|
|
17
|
+
"""Send a poll to a chat.
|
|
18
|
+
|
|
19
|
+
This method sends a poll with a question and a list of options
|
|
20
|
+
to a specific chat. Optional chat or inline keypads, notification
|
|
21
|
+
settings, and reply options can be provided.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The unique identifier of the target chat.
|
|
26
|
+
question (str): The poll question.
|
|
27
|
+
options (list[str]): List of possible answers.
|
|
28
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Custom chat keypad. Defaults to None.
|
|
29
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad. Defaults to None.
|
|
30
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Type of chat keypad. Defaults to None.
|
|
31
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
32
|
+
reply_to_message_id (Optional[str], optional): Reply to a specific message ID. Defaults to None.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
rubigram.types.UMessage: The sent poll message object.
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
39
|
+
>>> button = Button(id="101", button_text="Vote")
|
|
40
|
+
>>> row = KeypadRow(buttons=[button])
|
|
41
|
+
>>> keypad = Keypad(rows=[row])
|
|
42
|
+
>>> message = await client.send_poll(
|
|
43
|
+
... "chat_id",
|
|
44
|
+
... "What's your favorite color?",
|
|
45
|
+
... ["Red", "Blue", "Green"],
|
|
46
|
+
... inline_keypad=keypad
|
|
47
|
+
... )
|
|
48
|
+
>>> print(message.message_id)
|
|
49
|
+
"""
|
|
50
|
+
data = {
|
|
51
|
+
"chat_id": chat_id,
|
|
52
|
+
"question": question,
|
|
53
|
+
"options": options
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if chat_keypad:
|
|
57
|
+
data["chat_keypad"] = chat_keypad.asdict()
|
|
58
|
+
if inline_keypad:
|
|
59
|
+
data["inline_keypad"] = inline_keypad.asdict()
|
|
60
|
+
if chat_keypad_type:
|
|
61
|
+
data["chat_keypad_type"] = chat_keypad_type
|
|
62
|
+
if disable_notification:
|
|
63
|
+
data["disable_notification"] = disable_notification
|
|
64
|
+
if reply_to_message_id:
|
|
65
|
+
data["reply_to_message_id"] = reply_to_message_id
|
|
66
|
+
|
|
67
|
+
response = await self.request("sendPoll", data)
|
|
68
|
+
message = rubigram.types.UMessage.parse(response)
|
|
69
|
+
message.chat_id = chat_id
|
|
70
|
+
message.client = self
|
|
71
|
+
return message
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendSticker:
|
|
6
|
+
async def send_sticker(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
sticker_id: str,
|
|
10
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
11
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
12
|
+
chat_keypad_type: Optional["rubigram.enums.ChatKeypadType"] = None,
|
|
13
|
+
disable_notification: Optional[bool] = False,
|
|
14
|
+
reply_to_message_id: Optional[str] = None
|
|
15
|
+
) -> "rubigram.types.UMessage":
|
|
16
|
+
"""Send a sticker to a chat.
|
|
17
|
+
|
|
18
|
+
This method sends a sticker to a specific chat with optional
|
|
19
|
+
chat or inline keypads, notification settings, and reply options.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
23
|
+
chat_id (str): The unique identifier of the target chat.
|
|
24
|
+
sticker_id (str): The ID of the sticker to send.
|
|
25
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Custom chat keypad. Defaults to None.
|
|
26
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad. Defaults to None.
|
|
27
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Type of chat keypad. Defaults to None.
|
|
28
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
29
|
+
reply_to_message_id (Optional[str], optional): Reply to a specific message ID. Defaults to None.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
rubigram.types.UMessage: The sent sticker message object.
|
|
33
|
+
|
|
34
|
+
Example:
|
|
35
|
+
>>> from rubigram.types import Keypad, KeypadRow, Button
|
|
36
|
+
>>> button = Button(id="101", button_text="Sticker!")
|
|
37
|
+
>>> row = KeypadRow(buttons=[button])
|
|
38
|
+
>>> keypad = Keypad(rows=[row])
|
|
39
|
+
>>> message = await client.send_sticker(
|
|
40
|
+
... "chat_id",
|
|
41
|
+
... "sticker_id",
|
|
42
|
+
... inline_keypad=keypad
|
|
43
|
+
... )
|
|
44
|
+
>>> print(message.message_id)
|
|
45
|
+
"""
|
|
46
|
+
data = {
|
|
47
|
+
"chat_id": chat_id,
|
|
48
|
+
"sticker_id": sticker_id
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if chat_keypad:
|
|
52
|
+
data["chat_keypad"] = chat_keypad.asdict()
|
|
53
|
+
if inline_keypad:
|
|
54
|
+
data["inline_keypad"] = inline_keypad.asdict()
|
|
55
|
+
if chat_keypad_type:
|
|
56
|
+
data["chat_keypad_type"] = chat_keypad_type
|
|
57
|
+
if disable_notification:
|
|
58
|
+
data["disable_notification"] = disable_notification
|
|
59
|
+
if reply_to_message_id:
|
|
60
|
+
data["reply_to_message_id"] = reply_to_message_id
|
|
61
|
+
|
|
62
|
+
response = await self.request("sendSticker", data)
|
|
63
|
+
message = rubigram.types.UMessage.parse(response)
|
|
64
|
+
message.chat_id = chat_id
|
|
65
|
+
message.client = self
|
|
66
|
+
return message
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class Request:
|
|
6
|
+
def __init__(self, client: "rubigram.Client"):
|
|
7
|
+
self.client = client
|
|
8
|
+
self.api: str = f"https://botapi.rubika.ir/v3/{client.token}/"
|
|
9
|
+
|
|
10
|
+
async def request(
|
|
11
|
+
self,
|
|
12
|
+
method: str,
|
|
13
|
+
data: Optional[dict] = {}
|
|
14
|
+
) -> dict:
|
|
15
|
+
|
|
16
|
+
url = self.api + method
|
|
17
|
+
async with self.client.http.session.post(url, json=data) as response:
|
|
18
|
+
response.raise_for_status()
|
|
19
|
+
res: dict = await response.json()
|
|
20
|
+
return res.get("data")
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import rubigram
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SetCommands:
|
|
5
|
+
async def set_commands(
|
|
6
|
+
self: "rubigram.Client",
|
|
7
|
+
commands: list["rubigram.types.BotCommand"]
|
|
8
|
+
) -> dict:
|
|
9
|
+
"""Set the command for bot.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
self (rubigram.Client): ...
|
|
13
|
+
commands (list[rubigram.types.BotCommand]): ...
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
dict: response server
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
>>> commands = [
|
|
20
|
+
>>> rubigram.types.BotCommand(command="start", description="Start the bot"),
|
|
21
|
+
>>> rubigram.types.BotCommand(command="help", description="Show help")
|
|
22
|
+
>>> ]
|
|
23
|
+
>>> response = await client.set_commands(commands)
|
|
24
|
+
>>> print(response)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
data = {
|
|
28
|
+
"bot_commands": [command.asdict() for command in commands]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
response = await self.request("setCommands", data)
|
|
32
|
+
return response
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class UpdateBotEndpoints:
|
|
6
|
+
async def update_bot_endpoints(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
url: str,
|
|
9
|
+
type: Optional[Union[str, "rubigram.enums.UpdateEndpointType"]] = "ReceiveUpdate"
|
|
10
|
+
) -> dict:
|
|
11
|
+
""" Set the endpoint URL for receiving updates.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
self (rubigram.Client): ...
|
|
15
|
+
url (str): your endpoint url
|
|
16
|
+
type (Optional[Union[str, rubigram.enums.UpdateEndpointType]], optional):
|
|
17
|
+
type of endpoint Defaults to "ReceiveUpdate".
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
dict: response server
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
>>> response = await client.update_bot_endpoints("https://rubigram.bot.com")
|
|
24
|
+
>>> print(response)
|
|
25
|
+
"""
|
|
26
|
+
data = {
|
|
27
|
+
"url": url,
|
|
28
|
+
"type": type
|
|
29
|
+
}
|
|
30
|
+
response = await self.client.request("updateBotEndpoints", data)
|
|
31
|
+
return response
|