RubigramClient 1.7.0__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.0.dist-info → rubigramclient-1.7.2.dist-info}/METADATA +12 -8
- 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.0.dist-info/RECORD +0 -15
- {rubigramclient-1.7.0.dist-info → rubigramclient-1.7.2.dist-info}/WHEEL +0 -0
- {rubigramclient-1.7.0.dist-info → rubigramclient-1.7.2.dist-info}/licenses/LICENSE +0 -0
- {rubigramclient-1.7.0.dist-info → rubigramclient-1.7.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class RequestSendFile:
|
|
6
|
+
async def request_send_file(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
type: Optional[str] = "File"
|
|
9
|
+
) -> str:
|
|
10
|
+
"""Request a file upload URL from the server.
|
|
11
|
+
|
|
12
|
+
This method asks the server to generate an upload URL for sending
|
|
13
|
+
a file. The type of file can be specified.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
17
|
+
type (Optional[str], optional): Type of file. Defaults to "File".
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
str: The upload URL to send the file.
|
|
21
|
+
|
|
22
|
+
Example:
|
|
23
|
+
>>> upload_url = await client.request_send_file()
|
|
24
|
+
>>> print(upload_url)
|
|
25
|
+
"""
|
|
26
|
+
data = {"type": type}
|
|
27
|
+
response = await self.request("requestSendFile", data)
|
|
28
|
+
return response["upload_url"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from typing import Union, Optional
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from aiohttp import FormData
|
|
4
|
+
import rubigram
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class RequestUploadFile:
|
|
8
|
+
async def request_upload_file(
|
|
9
|
+
self: "rubigram.Client",
|
|
10
|
+
upload_url: str,
|
|
11
|
+
file: Union[str, bytes],
|
|
12
|
+
name: Optional[str] = None
|
|
13
|
+
) -> str:
|
|
14
|
+
"""Upload a file and return its file ID.
|
|
15
|
+
|
|
16
|
+
Supports local file paths, URLs, or raw bytes. If sending raw bytes,
|
|
17
|
+
the `name` argument must be provided.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
21
|
+
upload_url (str): The URL to upload the file to (from `request_send_file`).
|
|
22
|
+
file (Union[str, bytes]): File path, URL, or raw bytes.
|
|
23
|
+
name (Optional[str], optional): File name for raw bytes or to override the default.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
str: The uploaded file's ID.
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
>>> file_id = await client.request_upload(
|
|
30
|
+
>>> upload_url="https://upload.rubigram.com",
|
|
31
|
+
>>> file="path/to/file.png"
|
|
32
|
+
>>> )
|
|
33
|
+
>>> print(file_id)
|
|
34
|
+
"""
|
|
35
|
+
if isinstance(file, str):
|
|
36
|
+
path = Path(file)
|
|
37
|
+
if path.is_file():
|
|
38
|
+
data, filename = path.read_bytes(), name or path.name
|
|
39
|
+
elif file.startswith("http"):
|
|
40
|
+
data = await self.get_bytes(file)
|
|
41
|
+
filename = name or await self.get_file_name(file)
|
|
42
|
+
else:
|
|
43
|
+
raise FileNotFoundError("File not found : {}".format(file))
|
|
44
|
+
elif isinstance(file, bytes):
|
|
45
|
+
if not name:
|
|
46
|
+
raise ValueError("A name must be provided for bytes file")
|
|
47
|
+
data, filename = file, name
|
|
48
|
+
else:
|
|
49
|
+
raise TypeError("`file` must be a string path, URL, or bytes")
|
|
50
|
+
|
|
51
|
+
form = FormData()
|
|
52
|
+
form.add_field(
|
|
53
|
+
"file",
|
|
54
|
+
data,
|
|
55
|
+
filename=filename,
|
|
56
|
+
content_type="application/octet-stream"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
async with self.http.session.post(upload_url, data=form) as response:
|
|
60
|
+
response.raise_for_status()
|
|
61
|
+
result = await response.json()
|
|
62
|
+
return result.get("data", {}).get("file_id")
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendDocument:
|
|
6
|
+
async def send_document(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
document: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
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 document to a chat.
|
|
19
|
+
|
|
20
|
+
This is a wrapper around `send_file` to explicitly indicate
|
|
21
|
+
that the file is a document. It supports local files, URLs, or raw bytes.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The ID of the chat to send the document to.
|
|
26
|
+
document (Union[str, bytes]): Local path, URL, or raw bytes of the document.
|
|
27
|
+
caption (Optional[str], optional): Text caption for the document. Defaults to None.
|
|
28
|
+
filename (Optional[str], optional): Filename to use for raw bytes. Defaults to None.
|
|
29
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
30
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
31
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
32
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
33
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
rubigram.types.UMessage: The sent message object containing message ID, file ID, and chat ID.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> message = await client.send_document(
|
|
40
|
+
>>> chat_id="chat_id",
|
|
41
|
+
>>> document="path/to/file.pdf",
|
|
42
|
+
>>> caption="Here is the document"
|
|
43
|
+
>>> )
|
|
44
|
+
>>> print(message.message_id)
|
|
45
|
+
>>> print(message.file_id)
|
|
46
|
+
"""
|
|
47
|
+
return await self.send_file(
|
|
48
|
+
chat_id=chat_id,
|
|
49
|
+
file=document,
|
|
50
|
+
caption=caption,
|
|
51
|
+
filename=filename,
|
|
52
|
+
type="File",
|
|
53
|
+
chat_keypad=chat_keypad,
|
|
54
|
+
inline_keypad=inline_keypad,
|
|
55
|
+
chat_keypad_type=chat_keypad_type,
|
|
56
|
+
disable_notification=disable_notification,
|
|
57
|
+
reply_to_message_id=reply_to_message_id
|
|
58
|
+
)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendFile:
|
|
6
|
+
async def send_file(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
file: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
12
|
+
type: Optional[Union[str, "rubigram.enums.FileType"]] = "File",
|
|
13
|
+
chat_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
14
|
+
inline_keypad: Optional["rubigram.types.Keypad"] = None,
|
|
15
|
+
chat_keypad_type: Optional["rubigram.enums.ChatKeypadType"] = None,
|
|
16
|
+
disable_notification: Optional[bool] = False,
|
|
17
|
+
reply_to_message_id: Optional[str] = None
|
|
18
|
+
) -> "rubigram.types.UMessage":
|
|
19
|
+
"""Send a file to a chat.
|
|
20
|
+
|
|
21
|
+
Uploads a file (local path, URL, or raw bytes) and sends it to the specified chat,
|
|
22
|
+
optionally with caption, keypads, or as a reply.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
26
|
+
chat_id (str): The ID of the chat to send the file to.
|
|
27
|
+
file (Union[str, bytes]): File path, URL, or raw bytes to send.
|
|
28
|
+
caption (Optional[str], optional): Text caption for the file. Defaults to None.
|
|
29
|
+
filename (Optional[str], optional): Filename to use for raw bytes. Defaults to None.
|
|
30
|
+
type (Optional[Union[str, rubigram.enums.FileType]], optional): Type of file. Defaults to "File".
|
|
31
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
32
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
33
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
34
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
35
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
rubigram.types.UMessage: The sent message object containing message ID, file ID, and chat ID.
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
>>> message = await client.send_file(
|
|
42
|
+
>>> chat_id="chat_id",
|
|
43
|
+
>>> file="path/to/file.png",
|
|
44
|
+
>>> caption="Hello!",
|
|
45
|
+
>>> )
|
|
46
|
+
>>> print(message.message_id)
|
|
47
|
+
>>> print(message.file_id)
|
|
48
|
+
"""
|
|
49
|
+
upload_url = await self.request_send_file(type)
|
|
50
|
+
file_id = await self.request_upload_file(upload_url, file, filename)
|
|
51
|
+
|
|
52
|
+
data = {
|
|
53
|
+
"chat_id": chat_id,
|
|
54
|
+
"file_id": file_id,
|
|
55
|
+
"text": caption
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if chat_keypad:
|
|
59
|
+
data["chat_keypad"] = chat_keypad.asdict()
|
|
60
|
+
|
|
61
|
+
if inline_keypad:
|
|
62
|
+
data["inline_keypad"] = inline_keypad.asdict()
|
|
63
|
+
|
|
64
|
+
if chat_keypad_type:
|
|
65
|
+
data["chat_keypad_type"] = chat_keypad_type
|
|
66
|
+
|
|
67
|
+
if disable_notification:
|
|
68
|
+
data["disable_notification"] = disable_notification
|
|
69
|
+
|
|
70
|
+
if reply_to_message_id:
|
|
71
|
+
data["reply_to_message_id"] = reply_to_message_id
|
|
72
|
+
|
|
73
|
+
response = await self.request("sendFile", data)
|
|
74
|
+
message = rubigram.types.UMessage.parse(response)
|
|
75
|
+
message.chat_id = chat_id
|
|
76
|
+
message.file_id = file_id
|
|
77
|
+
message.client = self
|
|
78
|
+
return message
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendGif:
|
|
6
|
+
async def send_gif(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
document: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
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 GIF file to a chat.
|
|
19
|
+
|
|
20
|
+
This is a wrapper around `send_file` to specifically send GIFs.
|
|
21
|
+
Supports local files, URLs, or raw bytes.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The ID of the chat to send the GIF to.
|
|
26
|
+
document (Union[str, bytes]): Local path, URL, or raw bytes of the GIF.
|
|
27
|
+
caption (Optional[str], optional): Text caption for the GIF. Defaults to None.
|
|
28
|
+
filename (Optional[str], optional): Filename to use for raw bytes. Defaults to None.
|
|
29
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
30
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
31
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
32
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
33
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
rubigram.types.UMessage: The sent message object containing message ID, file ID, and chat ID.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> message = await client.send_gif(
|
|
40
|
+
>>> chat_id="chat_id",
|
|
41
|
+
>>> document="path/to/animation.gif",
|
|
42
|
+
>>> caption="Funny GIF"
|
|
43
|
+
>>> )
|
|
44
|
+
>>> print(message.message_id)
|
|
45
|
+
>>> print(message.file_id)
|
|
46
|
+
"""
|
|
47
|
+
return await self.send_file(
|
|
48
|
+
chat_id=chat_id,
|
|
49
|
+
file=document,
|
|
50
|
+
caption=caption,
|
|
51
|
+
filename=filename,
|
|
52
|
+
type="Gif",
|
|
53
|
+
chat_keypad=chat_keypad,
|
|
54
|
+
inline_keypad=inline_keypad,
|
|
55
|
+
chat_keypad_type=chat_keypad_type,
|
|
56
|
+
disable_notification=disable_notification,
|
|
57
|
+
reply_to_message_id=reply_to_message_id
|
|
58
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendMusic:
|
|
6
|
+
async def send_music(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
document: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
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 music file to a chat.
|
|
19
|
+
|
|
20
|
+
This is a wrapper around `send_file` to specifically send audio/music files.
|
|
21
|
+
Supports local files, URLs, or raw bytes.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The ID of the chat to send the music to.
|
|
26
|
+
document (Union[str, bytes]): Local path, URL, or raw bytes of the music file.
|
|
27
|
+
caption (Optional[str], optional): Text caption for the music. Defaults to None.
|
|
28
|
+
filename (Optional[str], optional): Filename to use for raw bytes. Defaults to None.
|
|
29
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
30
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
31
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
32
|
+
disable_notification (Optional[bool], optional): Whether to disable notifications. Defaults to False.
|
|
33
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
rubigram.types.UMessage: The sent message object containing message ID, file ID, and chat ID.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> message = await client.send_music(
|
|
40
|
+
>>> chat_id="chat_id",
|
|
41
|
+
>>> document="path/to/song.mp3",
|
|
42
|
+
>>> caption="My favorite song"
|
|
43
|
+
>>> )
|
|
44
|
+
>>> print(message.message_id)
|
|
45
|
+
>>> print(message.file_id)
|
|
46
|
+
"""
|
|
47
|
+
return await self.send_file(
|
|
48
|
+
chat_id=chat_id,
|
|
49
|
+
file=document,
|
|
50
|
+
caption=caption,
|
|
51
|
+
filename=filename,
|
|
52
|
+
type="Music",
|
|
53
|
+
chat_keypad=chat_keypad,
|
|
54
|
+
inline_keypad=inline_keypad,
|
|
55
|
+
chat_keypad_type=chat_keypad_type,
|
|
56
|
+
disable_notification=disable_notification,
|
|
57
|
+
reply_to_message_id=reply_to_message_id
|
|
58
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendPhoto:
|
|
6
|
+
async def send_photo(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
document: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
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 photo to a chat.
|
|
19
|
+
|
|
20
|
+
This method allows sending an image file from a local path, URL, or raw bytes.
|
|
21
|
+
You can also attach chat or inline keypads and set notification options.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The ID of the chat to send the photo to.
|
|
26
|
+
document (Union[str, bytes]): Local path, URL, or raw bytes of the photo.
|
|
27
|
+
caption (Optional[str], optional): Caption text for the photo. Defaults to None.
|
|
28
|
+
filename (Optional[str], optional): Filename to use for raw bytes. Defaults to None.
|
|
29
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
30
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
31
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
32
|
+
disable_notification (Optional[bool], optional): Disable notification for this message. Defaults to False.
|
|
33
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
rubigram.types.UMessage: The sent message object containing message ID, file ID, and chat ID.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> message = await client.send_photo(
|
|
40
|
+
>>> chat_id="chat_id",
|
|
41
|
+
>>> document="path/to/photo.jpg",
|
|
42
|
+
>>> caption="Check this out!"
|
|
43
|
+
>>> )
|
|
44
|
+
>>> print(message.message_id)
|
|
45
|
+
>>> print(message.file_id)
|
|
46
|
+
"""
|
|
47
|
+
return await self.send_file(
|
|
48
|
+
chat_id=chat_id,
|
|
49
|
+
file=document,
|
|
50
|
+
caption=caption,
|
|
51
|
+
filename=filename,
|
|
52
|
+
type="Image",
|
|
53
|
+
chat_keypad=chat_keypad,
|
|
54
|
+
inline_keypad=inline_keypad,
|
|
55
|
+
chat_keypad_type=chat_keypad_type,
|
|
56
|
+
disable_notification=disable_notification,
|
|
57
|
+
reply_to_message_id=reply_to_message_id
|
|
58
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendVideo:
|
|
6
|
+
async def send_video(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
document: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
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 video to a chat.
|
|
19
|
+
|
|
20
|
+
This method allows sending a video file from a local path, URL, or raw bytes.
|
|
21
|
+
You can also attach chat or inline keypads and set notification options.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
25
|
+
chat_id (str): The ID of the chat to send the video to.
|
|
26
|
+
document (Union[str, bytes]): Local path, URL, or raw bytes of the video.
|
|
27
|
+
caption (Optional[str], optional): Caption text for the video. Defaults to None.
|
|
28
|
+
filename (Optional[str], optional): Filename to use for raw bytes. Defaults to None.
|
|
29
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
30
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
31
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
32
|
+
disable_notification (Optional[bool], optional): Disable notification for this message. Defaults to False.
|
|
33
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
rubigram.types.UMessage: The sent message object containing message ID, file ID, and chat ID.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> message = await client.send_video(
|
|
40
|
+
>>> chat_id="chat_id",
|
|
41
|
+
>>> document="path/to/video.mp4",
|
|
42
|
+
>>> caption="Watch this!"
|
|
43
|
+
>>> )
|
|
44
|
+
>>> print(message.message_id)
|
|
45
|
+
>>> print(message.file_id)
|
|
46
|
+
"""
|
|
47
|
+
return await self.send_file(
|
|
48
|
+
chat_id=chat_id,
|
|
49
|
+
file=document,
|
|
50
|
+
caption=caption,
|
|
51
|
+
filename=filename,
|
|
52
|
+
type="Video",
|
|
53
|
+
chat_keypad=chat_keypad,
|
|
54
|
+
inline_keypad=inline_keypad,
|
|
55
|
+
chat_keypad_type=chat_keypad_type,
|
|
56
|
+
disable_notification=disable_notification,
|
|
57
|
+
reply_to_message_id=reply_to_message_id
|
|
58
|
+
)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
import rubigram
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SendVoice:
|
|
6
|
+
async def send_voice(
|
|
7
|
+
self: "rubigram.Client",
|
|
8
|
+
chat_id: str,
|
|
9
|
+
document: Union[str, bytes],
|
|
10
|
+
caption: Optional[str] = None,
|
|
11
|
+
filename: Optional[str] = None,
|
|
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 voice message to a chat.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
22
|
+
chat_id (str): The ID of the chat to send the voice message to.
|
|
23
|
+
document (Union[str, bytes]): Local path, URL, or raw bytes of the voice file.
|
|
24
|
+
caption (Optional[str], optional): Caption text. Defaults to None.
|
|
25
|
+
filename (Optional[str], optional): Filename for raw bytes. Defaults to None.
|
|
26
|
+
chat_keypad (Optional[rubigram.types.Keypad], optional): Chat keypad to include. Defaults to None.
|
|
27
|
+
inline_keypad (Optional[rubigram.types.Keypad], optional): Inline keypad to include. Defaults to None.
|
|
28
|
+
chat_keypad_type (Optional[rubigram.enums.ChatKeypadType], optional): Chat keypad type. Defaults to None.
|
|
29
|
+
disable_notification (Optional[bool], optional): Disable notification for this message. Defaults to False.
|
|
30
|
+
reply_to_message_id (Optional[str], optional): ID of message to reply to. Defaults to None.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
rubigram.types.UMessage: The sent message object with message ID, file ID, and chat ID.
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
>>> message = await client.send_voice(
|
|
37
|
+
>>> chat_id="chat_id",
|
|
38
|
+
>>> document="path/to/voice.ogg",
|
|
39
|
+
>>> caption="Listen!"
|
|
40
|
+
>>> )
|
|
41
|
+
>>> print(message.message_id)
|
|
42
|
+
>>> print(message.file_id)
|
|
43
|
+
"""
|
|
44
|
+
return await self.send_file(
|
|
45
|
+
chat_id=chat_id,
|
|
46
|
+
file=document,
|
|
47
|
+
caption=caption,
|
|
48
|
+
filename=filename,
|
|
49
|
+
type="Voice",
|
|
50
|
+
chat_keypad=chat_keypad,
|
|
51
|
+
inline_keypad=inline_keypad,
|
|
52
|
+
chat_keypad_type=chat_keypad_type,
|
|
53
|
+
disable_notification=disable_notification,
|
|
54
|
+
reply_to_message_id=reply_to_message_id
|
|
55
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from .send_message import SendMessage
|
|
2
|
+
from .send_poll import SendPoll
|
|
3
|
+
from .send_location import SendLocation
|
|
4
|
+
from .send_contact import SendContact
|
|
5
|
+
from .send_sticker import SendSticker
|
|
6
|
+
from .delete_message import DeleteMessage
|
|
7
|
+
from .remove_chat_keypad import RemoveChatKeypad
|
|
8
|
+
from .edit_chat_keypad import EditChatKeypad
|
|
9
|
+
from .edit_message_keypad import EditMessageKeypad
|
|
10
|
+
from .edit_message_text import EditMessageText
|
|
11
|
+
from .edit_message import EditMessage
|
|
12
|
+
from .forward_message import ForwardMessage
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Message(
|
|
16
|
+
SendMessage,
|
|
17
|
+
SendPoll,
|
|
18
|
+
SendLocation,
|
|
19
|
+
SendContact,
|
|
20
|
+
SendSticker,
|
|
21
|
+
DeleteMessage,
|
|
22
|
+
RemoveChatKeypad,
|
|
23
|
+
EditChatKeypad,
|
|
24
|
+
EditMessageKeypad,
|
|
25
|
+
EditMessageText,
|
|
26
|
+
EditMessage,
|
|
27
|
+
ForwardMessage
|
|
28
|
+
):
|
|
29
|
+
pass
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
import asyncio
|
|
3
|
+
import rubigram
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DeleteMessage:
|
|
7
|
+
async def delete_message(
|
|
8
|
+
self: "rubigram.Client",
|
|
9
|
+
chat_id: str,
|
|
10
|
+
message_id: Union[str, list[str]]
|
|
11
|
+
):
|
|
12
|
+
"""Delete one or more messages from a chat.
|
|
13
|
+
|
|
14
|
+
This method deletes a single message or multiple messages
|
|
15
|
+
from a specific chat.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
self (rubigram.Client): The active Rubigram client instance.
|
|
19
|
+
chat_id (str): The unique identifier of the chat.
|
|
20
|
+
message_id (Union[str, list[str]]): A message ID or list of message IDs to delete.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
Any: API response for a single message, or the number of deletions for multiple messages.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
>>> await client.delete_message("chat_id", "msg_id")
|
|
27
|
+
>>> await client.delete_message("chat_id", ["msg1", "msg2"])
|
|
28
|
+
"""
|
|
29
|
+
if isinstance(message_id, str):
|
|
30
|
+
return await self.request(
|
|
31
|
+
"deleteMessage",
|
|
32
|
+
{
|
|
33
|
+
"chat_id": chat_id,
|
|
34
|
+
"message_id": message_id
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
tasks = [
|
|
39
|
+
self.request(
|
|
40
|
+
"deleteMessage",
|
|
41
|
+
{
|
|
42
|
+
"chat_id": chat_id,
|
|
43
|
+
"message_id": i
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
for i in message_id
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
responses = await asyncio.gather(*tasks, return_exceptions=True)
|
|
50
|
+
return len(responses)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import rubigram
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EditChatKeypad:
|
|
5
|
+
async def edit_chat_keypad(
|
|
6
|
+
self: "rubigram.Client",
|
|
7
|
+
chat_id: str,
|
|
8
|
+
chat_keypad: "rubigram.types.Keypad"
|
|
9
|
+
):
|
|
10
|
+
"""
|
|
11
|
+
Edit the keypad (custom button layout) of a chat.
|
|
12
|
+
|
|
13
|
+
This method updates or replaces the current chat keypad
|
|
14
|
+
(custom buttons) with a new layout.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
chat_id (str): The unique identifier of the chat where the keypad should be updated.
|
|
18
|
+
chat_keypad (rubigram.bot.types.Keypad): A `Keypad` object defining the new button layout.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
Any: The API response returned by the server.
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
>>> from rubigram.bot.types import Keypad, Button
|
|
25
|
+
>>> keypad = Keypad(rows=[[Button(text="Menu"), Button(text="Help")]])
|
|
26
|
+
>>> await client.edit_chat_keypad("chat123", keypad)
|
|
27
|
+
"""
|
|
28
|
+
data = {
|
|
29
|
+
"chat_id": chat_id,
|
|
30
|
+
"chat_keypad_type": "New",
|
|
31
|
+
"chat_keypad": chat_keypad.asdict()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return await self.request("editChatKeypad", data)
|