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.
Files changed (132) hide show
  1. rubigram/__init__.py +15 -0
  2. rubigram/client.py +294 -0
  3. rubigram/enums/__init__.py +52 -0
  4. rubigram/enums/buttons/__init__.py +13 -0
  5. rubigram/enums/buttons/button_calendar_type.py +20 -0
  6. rubigram/enums/buttons/button_location_type.py +20 -0
  7. rubigram/enums/buttons/button_selection_get_type.py +20 -0
  8. rubigram/enums/buttons/button_selection_search_type.py +20 -0
  9. rubigram/enums/buttons/button_selection_type.py +22 -0
  10. rubigram/enums/buttons/button_textbox_type_keypad.py +20 -0
  11. rubigram/enums/buttons/button_textbox_type_line.py +20 -0
  12. rubigram/enums/buttons/button_type.py +58 -0
  13. rubigram/enums/chat_action_type.py +22 -0
  14. rubigram/enums/chat_keypad_type.py +20 -0
  15. rubigram/enums/chat_type.py +24 -0
  16. rubigram/enums/enum.py +6 -0
  17. rubigram/enums/file_type.py +28 -0
  18. rubigram/enums/forwarded_from_type.py +22 -0
  19. rubigram/enums/live_location_status.py +20 -0
  20. rubigram/enums/message_sender_type.py +20 -0
  21. rubigram/enums/metadata_type.py +18 -0
  22. rubigram/enums/parse_mode.py +20 -0
  23. rubigram/enums/payment_status_type.py +20 -0
  24. rubigram/enums/poll_status_type.py +20 -0
  25. rubigram/enums/update_endpoint_type.py +26 -0
  26. rubigram/enums/update_type.py +28 -0
  27. rubigram/errors.py +16 -0
  28. rubigram/filters.py +865 -0
  29. rubigram/http_session.py +96 -0
  30. rubigram/methods/__init__.py +26 -0
  31. rubigram/methods/chats/__init__.py +10 -0
  32. rubigram/methods/chats/get_chat.py +53 -0
  33. rubigram/methods/decorators/__init__.py +25 -0
  34. rubigram/methods/decorators/on_inline_message.py +70 -0
  35. rubigram/methods/decorators/on_message.py +62 -0
  36. rubigram/methods/decorators/on_remove_message.py +65 -0
  37. rubigram/methods/decorators/on_start.py +65 -0
  38. rubigram/methods/decorators/on_started_bot.py +70 -0
  39. rubigram/methods/decorators/on_stop.py +65 -0
  40. rubigram/methods/decorators/on_stopped_bot.py +70 -0
  41. rubigram/methods/decorators/on_update_message.py +70 -0
  42. rubigram/methods/files/__init__.py +32 -0
  43. rubigram/methods/files/download_file.py +118 -0
  44. rubigram/methods/files/get_file.py +41 -0
  45. rubigram/methods/files/get_file_name.py +41 -0
  46. rubigram/methods/files/request_send_file.py +49 -0
  47. rubigram/methods/files/send_file.py +133 -0
  48. rubigram/methods/files/send_gif.py +51 -0
  49. rubigram/methods/files/send_music.py +97 -0
  50. rubigram/methods/files/send_photo.py +95 -0
  51. rubigram/methods/files/send_video.py +96 -0
  52. rubigram/methods/files/send_voice.py +96 -0
  53. rubigram/methods/files/upload_file.py +114 -0
  54. rubigram/methods/messages/__init__.py +34 -0
  55. rubigram/methods/messages/delete_messages.py +84 -0
  56. rubigram/methods/messages/edit_chat_keypad.py +68 -0
  57. rubigram/methods/messages/edit_message.py +82 -0
  58. rubigram/methods/messages/edit_message_keypad.py +72 -0
  59. rubigram/methods/messages/edit_message_text.py +68 -0
  60. rubigram/methods/messages/forward_message.py +78 -0
  61. rubigram/methods/messages/remove_chat_keypad.py +46 -0
  62. rubigram/methods/messages/send_contact.py +114 -0
  63. rubigram/methods/messages/send_location.py +108 -0
  64. rubigram/methods/messages/send_message.py +115 -0
  65. rubigram/methods/messages/send_poll.py +104 -0
  66. rubigram/methods/messages/send_sticker.py +98 -0
  67. rubigram/methods/network/__init__.py +12 -0
  68. rubigram/methods/network/request.py +129 -0
  69. rubigram/methods/settings/__init__.py +16 -0
  70. rubigram/methods/settings/set_command.py +50 -0
  71. rubigram/methods/settings/setup_endpoints.py +48 -0
  72. rubigram/methods/settings/update_bot_endpoint.py +62 -0
  73. rubigram/methods/updates/__init__.py +14 -0
  74. rubigram/methods/updates/get_me.py +35 -0
  75. rubigram/methods/updates/get_update.py +62 -0
  76. rubigram/methods/utilities/__init__.py +14 -0
  77. rubigram/methods/utilities/dispatcher.py +66 -0
  78. rubigram/methods/utilities/run.py +118 -0
  79. rubigram/rubino/__init__.py +6 -0
  80. rubigram/rubino/client.py +374 -0
  81. rubigram/rubino/network.py +129 -0
  82. rubigram/server/__init__.py +6 -0
  83. rubigram/server/server.py +245 -0
  84. rubigram/state/__init__.py +7 -0
  85. rubigram/state/state.py +121 -0
  86. rubigram/state/storage.py +131 -0
  87. rubigram/types/__init__.py +66 -0
  88. rubigram/types/aux_data.py +28 -0
  89. rubigram/types/bot.py +51 -0
  90. rubigram/types/bot_command.py +26 -0
  91. rubigram/types/buttons/__init__.py +13 -0
  92. rubigram/types/buttons/button.py +59 -0
  93. rubigram/types/buttons/button_calendar.py +40 -0
  94. rubigram/types/buttons/button_location.py +40 -0
  95. rubigram/types/buttons/button_number_picker.py +34 -0
  96. rubigram/types/buttons/button_selection.py +48 -0
  97. rubigram/types/buttons/button_selection_item.py +32 -0
  98. rubigram/types/buttons/button_string_picker.py +29 -0
  99. rubigram/types/buttons/button_text_box.py +40 -0
  100. rubigram/types/chat.py +86 -0
  101. rubigram/types/config/__init__.py +6 -0
  102. rubigram/types/config/object.py +442 -0
  103. rubigram/types/contact_message.py +29 -0
  104. rubigram/types/file.py +78 -0
  105. rubigram/types/forwarded_from.py +39 -0
  106. rubigram/types/keypads/__init__.py +7 -0
  107. rubigram/types/keypads/keypad.py +31 -0
  108. rubigram/types/keypads/keypad_row.py +23 -0
  109. rubigram/types/live_location.py +44 -0
  110. rubigram/types/location.py +24 -0
  111. rubigram/types/messages/__init__.py +8 -0
  112. rubigram/types/messages/inline_message.py +78 -0
  113. rubigram/types/messages/message.py +117 -0
  114. rubigram/types/messages/update_message.py +341 -0
  115. rubigram/types/metadata/__init__.py +7 -0
  116. rubigram/types/metadata/metadata.py +43 -0
  117. rubigram/types/metadata/metadata_parts.py +42 -0
  118. rubigram/types/payment_status.py +30 -0
  119. rubigram/types/poll.py +32 -0
  120. rubigram/types/poll_status.py +40 -0
  121. rubigram/types/sticker.py +33 -0
  122. rubigram/types/updates/__init__.py +7 -0
  123. rubigram/types/updates/update.py +917 -0
  124. rubigram/types/updates/updates.py +56 -0
  125. rubigram/utils/__init__.py +14 -0
  126. rubigram/utils/auto_delete.py +93 -0
  127. rubigram/utils/parser.py +99 -0
  128. rubigramclient-1.7.17.dist-info/METADATA +215 -0
  129. rubigramclient-1.7.17.dist-info/RECORD +132 -0
  130. rubigramclient-1.7.17.dist-info/WHEEL +5 -0
  131. rubigramclient-1.7.17.dist-info/licenses/LICENSE +21 -0
  132. rubigramclient-1.7.17.dist-info/top_level.txt +1 -0
@@ -0,0 +1,72 @@
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 EditMessageKeypad:
12
+ async def edit_message_keypad(
13
+ self: rubigram.Client,
14
+ chat_id: str,
15
+ message_id: str,
16
+ inline_keypad: rubigram.types.Keypad
17
+ ):
18
+ """
19
+ **Edit the inline keyboard of a specific message.**
20
+ `await client.edit_message_keypad(chat_id, message_id, inline_keypad)`
21
+
22
+ This method updates the inline keyboard attached to an existing message.
23
+ The inline keyboard appears below the message content and provides
24
+ interactive buttons for users.
25
+
26
+ Args:
27
+ chat_id (`str`):
28
+ The ID of the chat where the message is located.
29
+
30
+ message_id (`str`):
31
+ The ID of the message to update.
32
+
33
+ inline_keypad (`rubigram.types.Keypad`):
34
+ The new inline keyboard object containing rows of interactive buttons.
35
+
36
+ Returns:
37
+ dict: The API response from Rubigram.
38
+
39
+ Example:
40
+ .. code-block:: python
41
+
42
+ from rubigram.types import Keypad, KeypadRow, Button
43
+
44
+ # Create an inline keyboard
45
+ inline_keypad = Keypad(
46
+ rows=[
47
+ KeypadRow(buttons=[
48
+ Button(button_text="Like", id="like_btn"),
49
+ Button(button_text="Share", id="share_btn")
50
+ ])
51
+ ]
52
+ )
53
+
54
+ # Update the message's inline keyboard
55
+ await client.edit_message_keypad(
56
+ chat_id=message_id,
57
+ message_id=message_id,
58
+ inline_keypad=inline_keypad
59
+ )
60
+
61
+ Note:
62
+ This method only affects the inline keyboard of the specified message
63
+ and does not modify the message text or other content.
64
+ """
65
+ return await self.request(
66
+ "editMessageKeypad",
67
+ {
68
+ "chat_id": chat_id,
69
+ "message_id": message_id,
70
+ "inline_keypad": inline_keypad.as_dict()
71
+ }
72
+ )
@@ -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
+ from __future__ import annotations
6
+
7
+ from typing import Optional, Union
8
+ from rubigram.utils import Parser
9
+ import rubigram
10
+
11
+
12
+ class EditMessageText:
13
+ async def edit_message_text(
14
+ self: rubigram.Client,
15
+ chat_id: str,
16
+ message_id: str,
17
+ text: str,
18
+ parse_mode: Optional[Union[str, rubigram.enums.ParseMode]] = None
19
+ ):
20
+ """
21
+ **Edit the text content of an existing message.**
22
+ `await client.edit_message_text(chat_id, message_id, text)`
23
+
24
+ This method updates the text content of a previously sent message
25
+ while preserving other message components like inline keyboards
26
+ and attachments.
27
+
28
+ Args:
29
+ chat_id (`str`):
30
+ The ID of the chat where the message is located.
31
+
32
+ message_id (`str`):
33
+ The ID of the message to update.
34
+
35
+ text (`str`):
36
+ The new text content for the message.
37
+
38
+ Returns:
39
+ dict: The API response from Rubigram containing the updated message data.
40
+
41
+ Example:
42
+ .. code-block:: python
43
+
44
+ # Edit a message's text content
45
+ await client.edit_message_text(
46
+ chat_id=chat_id
47
+ message_id=message_id,
48
+ text=text
49
+ )
50
+
51
+ Note:
52
+ This method only modifies the text content of the message.
53
+ Other message elements like inline keyboards, files, or media
54
+ remain unchanged.
55
+ """
56
+ data = {
57
+ "chat_id": chat_id,
58
+ "message_id": message_id,
59
+ "text": text
60
+ }
61
+
62
+ parse = Parser.parser(text, parse_mode or self.parse_mode)
63
+
64
+ if "metadata" in parse:
65
+ data["text"] = parse["text"]
66
+ data["metadata"] = parse["metadata"]
67
+
68
+ return await self.request("editMessageText", data)
@@ -0,0 +1,78 @@
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 typing import Optional
7
+ from rubigram.utils import AutoDelete
8
+ import rubigram
9
+
10
+
11
+ class ForwardMessage:
12
+ async def forward_message(
13
+ self: rubigram.Client,
14
+ from_chat_id: str,
15
+ message_id: str,
16
+ to_chat_id: str,
17
+ disable_notification: bool = False,
18
+ auto_delete: Optional[int] = None
19
+ ) -> rubigram.types.UMessage:
20
+ """
21
+ **Forward a message from one chat to another.**
22
+ `await client.forward_message(from_chat_id, message_id, to_chat_id)`
23
+
24
+ This method forwards an existing message from a source chat to a
25
+ destination chat while preserving all message content, attachments,
26
+ and metadata.
27
+
28
+ Args:
29
+ from_chat_id (`str`):
30
+ The ID of the chat where the original message is located.
31
+
32
+ message_id (`str`):
33
+ The ID of the message to forward.
34
+
35
+ to_chat_id (`str`):
36
+ The ID of the destination chat where the message will be forwarded.
37
+
38
+ disable_notification (`Optional[bool]`):
39
+ If True, disables notification for the forwarded message.
40
+ Defaults to False.
41
+
42
+ auto_delete (`Optional[int]`):
43
+ If set, the message will be automatically deleted after the specified number of seconds.
44
+
45
+ Returns:
46
+ rubigram.types.UMessage: The forwarded message object with client binding.
47
+
48
+ Example:
49
+ .. code-block:: python
50
+
51
+ # Forward a message from one chat to another
52
+ forwarded_message = await client.forward_message(
53
+ from_chat_id=from_chat_id,
54
+ message_id=message_id,
55
+ to_chat_id=to_chat_id,
56
+ disable_notification=True
57
+ )
58
+
59
+ Note:
60
+ The original message remains unchanged in the source chat.
61
+ The forwarded message includes all original content and attachments.
62
+ """
63
+ response = await self.request(
64
+ "forwardMessage",
65
+ {
66
+ "from_chat_id": from_chat_id,
67
+ "message_id": message_id,
68
+ "to_chat_id": to_chat_id,
69
+ "disable_notification": disable_notification
70
+ }
71
+ )
72
+ message = rubigram.types.UMessage.parse(response, self)
73
+ message.chat_id = to_chat_id
74
+
75
+ if auto_delete and auto_delete > 0:
76
+ AutoDelete.run(self, message, auto_delete)
77
+
78
+ return message
@@ -0,0 +1,46 @@
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 RemoveChatKeypad:
12
+ async def remove_chat_keypad(
13
+ self: rubigram.Client,
14
+ chat_id: str
15
+ ):
16
+ """
17
+ **Remove the custom keypad from a chat.**
18
+ `await client.remove_chat_keypad(chat_id)`
19
+
20
+ This method removes any custom keyboard (keypad) from the specified chat,
21
+ restoring the default keyboard interface for all users in the chat.
22
+
23
+ Args:
24
+ chat_id (`str`):
25
+ The ID of the chat where the keypad should be removed.
26
+
27
+ Returns:
28
+ dict: The API response from Rubigram.
29
+
30
+ Example:
31
+ .. code-block:: python
32
+
33
+ # Remove custom keypad from a chat
34
+ await client.remove_chat_keypad(chat_id=chat_id)
35
+
36
+ Note:
37
+ This action affects all users in the chat and cannot be undone
38
+ without setting a new keypad.
39
+ """
40
+ return await self.request(
41
+ "editChatKeypad",
42
+ {
43
+ "chat_id": chat_id,
44
+ "chat_keypad_type": "Remove"
45
+ }
46
+ )
@@ -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 __future__ import annotations
7
+
8
+ from typing import Optional, Union
9
+ from rubigram.utils import AutoDelete
10
+ import rubigram
11
+
12
+
13
+ class SendContact:
14
+ async def send_contact(
15
+ self: rubigram.Client,
16
+ chat_id: str,
17
+ phone_number: str,
18
+ first_name: str,
19
+ last_name: Optional[str] = None,
20
+ chat_keypad: Optional[rubigram.types.Keypad] = None,
21
+ inline_keypad: Optional[rubigram.types.Keypad] = None,
22
+ chat_keypad_type: Optional[Union[str, rubigram.enums.ChatKeypadType]] = None,
23
+ disable_notification: bool = False,
24
+ reply_to_message_id: Optional[str] = None,
25
+ auto_delete: Optional[int] = None
26
+ ) -> rubigram.types.UMessage:
27
+ """
28
+ **Send a contact to a chat.**
29
+ `await client.send_contact(chat_id, phone_number, first_name, last_name)`
30
+
31
+ This method sends a contact card with phone number and name information
32
+ to the specified chat. The contact can be saved directly to the user's
33
+ device contacts.
34
+
35
+ Args:
36
+ chat_id (`str`):
37
+ The ID of the chat where the contact will be sent.
38
+
39
+ phone_number (`str`):
40
+ The contact's phone number.
41
+
42
+ first_name (`str`):
43
+ The contact's first name.
44
+
45
+ last_name (`Optional[str]`):
46
+ The contact's last name. Defaults to None.
47
+
48
+ chat_keypad (`Optional[rubigram.types.Keypad]`):
49
+ Custom keyboard to show in the chat. Defaults to None.
50
+
51
+ inline_keypad (`Optional[rubigram.types.Keypad]`):
52
+ Inline keyboard to attach to the message. Defaults to None.
53
+
54
+ chat_keypad_type (`Optional[rubigram.enums.ChatKeypadType]`):
55
+ Type of chat keypad. Defaults to None.
56
+
57
+ disable_notification (`Optional[bool]`):
58
+ If True, disables notification for the message. Defaults to False.
59
+
60
+ reply_to_message_id (`Optional[str]`):
61
+ ID of the message to reply to. Defaults to None.
62
+
63
+ auto_delete (`Optional[int]`):
64
+ If set, the message will be automatically deleted after the specified number of seconds.
65
+
66
+ Returns:
67
+ rubigram.types.UMessage: The sent contact message object.
68
+
69
+ Example:
70
+ .. code-block:: python
71
+
72
+ # Send a contact with full details
73
+ await client.send_contact(
74
+ chat_id=chat_id,
75
+ phone_number="+1234567890",
76
+ first_name="John",
77
+ last_name="Doe",
78
+ disable_notification=True
79
+ )
80
+
81
+ Note:
82
+ The contact information will be displayed as a clickable card
83
+ that users can save to their device contacts.
84
+ """
85
+ data = {
86
+ "chat_id": chat_id,
87
+ "first_name": first_name,
88
+ "last_name": last_name,
89
+ "phone_number": phone_number
90
+ }
91
+
92
+ if chat_keypad:
93
+ data["chat_keypad"] = chat_keypad.as_dict()
94
+
95
+ if inline_keypad:
96
+ data["inline_keypad"] = inline_keypad.as_dict()
97
+
98
+ if chat_keypad_type:
99
+ data["chat_keypad_type"] = chat_keypad_type
100
+
101
+ if disable_notification:
102
+ data["disable_notification"] = disable_notification
103
+
104
+ if reply_to_message_id:
105
+ data["reply_to_message_id"] = reply_to_message_id
106
+
107
+ response = await self.request("sendContact", data)
108
+ message = rubigram.types.UMessage.parse(response, self)
109
+ message.client = self
110
+
111
+ if auto_delete and auto_delete > 0:
112
+ AutoDelete.run(self, message, auto_delete)
113
+
114
+ return message
@@ -0,0 +1,108 @@
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
+ from rubigram.utils import AutoDelete
10
+ import rubigram
11
+
12
+
13
+ class SendLocation:
14
+ async def send_location(
15
+ self: rubigram.Client,
16
+ chat_id: str,
17
+ latitude: str,
18
+ longitude: str,
19
+ chat_keypad: Optional[rubigram.types.Keypad] = None,
20
+ inline_keypad: Optional[rubigram.types.Keypad] = None,
21
+ chat_keypad_type: Optional[Union[str, rubigram.enums.ChatKeypadType]] = None,
22
+ disable_notification: bool = False,
23
+ reply_to_message_id: Optional[str] = None,
24
+ auto_delete: Optional[int] = None
25
+ ) -> rubigram.types.UMessage:
26
+ """
27
+ **Send a location to a chat.**
28
+ `await client.send_location(chat_id, latitude, longitude)`
29
+
30
+ This method sends a geographical location to the specified chat.
31
+ The location appears as an interactive map that users can tap to
32
+ open in their maps application.
33
+
34
+ Args:
35
+ chat_id (`str`):
36
+ The ID of the chat where the location will be sent.
37
+
38
+ latitude (`str`):
39
+ The latitude coordinate of the location.
40
+
41
+ longitude (`str`):
42
+ The longitude coordinate of the location.
43
+
44
+ chat_keypad (`Optional[rubigram.types.Keypad]`):
45
+ Custom keyboard to show in the chat. Defaults to None.
46
+
47
+ inline_keypad (`Optional[rubigram.types.Keypad]`):
48
+ Inline keyboard to attach to the message. Defaults to None.
49
+
50
+ chat_keypad_type (`Optional[rubigram.enums.ChatKeypadType]`):
51
+ Type of chat keypad. Defaults to None.
52
+
53
+ disable_notification (`Optional[bool]`):
54
+ If True, disables notification for the message. Defaults to False.
55
+
56
+ reply_to_message_id (`Optional[str]`):
57
+ ID of the message to reply to. Defaults to None.
58
+
59
+ auto_delete (`Optional[int]`):
60
+ If set, the message will be automatically deleted after the specified number of seconds.
61
+
62
+ Returns:
63
+ rubigram.types.UMessage: The sent location message object.
64
+
65
+ Example:
66
+ .. code-block:: python
67
+
68
+ # Send a location (Tokyo coordinates)
69
+ await client.send_location(
70
+ chat_id=chat_id,
71
+ latitude="35.6895",
72
+ longitude="139.6917",
73
+ disable_notification=True
74
+ )
75
+
76
+ Note:
77
+ The location will be displayed as an interactive map preview
78
+ that users can tap to open in their preferred maps application.
79
+ """
80
+ data = {
81
+ "chat_id": chat_id,
82
+ "latitude": latitude,
83
+ "longitude": longitude
84
+ }
85
+
86
+ if chat_keypad:
87
+ data["chat_keypad"] = chat_keypad.as_dict()
88
+
89
+ if inline_keypad:
90
+ data["inline_keypad"] = inline_keypad.as_dict()
91
+
92
+ if chat_keypad_type:
93
+ data["chat_keypad_type"] = chat_keypad_type
94
+
95
+ if disable_notification:
96
+ data["disable_notification"] = disable_notification
97
+
98
+ if reply_to_message_id:
99
+ data["reply_to_message_id"] = reply_to_message_id
100
+
101
+ response = await self.request("sendLocation", data)
102
+ message = rubigram.types.UMessage.parse(response, self)
103
+ message.chat_id = chat_id
104
+
105
+ if auto_delete and auto_delete > 0:
106
+ AutoDelete.run(self, message, auto_delete)
107
+
108
+ return message
@@ -0,0 +1,115 @@
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
+ from rubigram.utils import AutoDelete, Parser
10
+ import rubigram
11
+
12
+
13
+
14
+ class SendMessage:
15
+ async def send_message(
16
+ self: rubigram.Client,
17
+ chat_id: str,
18
+ text: str,
19
+ chat_keypad: Optional[rubigram.types.Keypad] = None,
20
+ inline_keypad: Optional[rubigram.types.Keypad] = None,
21
+ chat_keypad_type: Optional[Union[str, rubigram.enums.ChatKeypadType]] = None,
22
+ disable_notification: bool = False,
23
+ reply_to_message_id: Optional[str] = None,
24
+ parse_mode: Optional[Union[str, rubigram.enums.ParseMode]] = None,
25
+ auto_delete: Optional[int] = None
26
+ ) -> rubigram.types.UMessage:
27
+ """
28
+ **Send a text message to a chat.**
29
+ `await client.send_message(chat_id, text)`
30
+
31
+ This method sends a text message to the specified chat with optional
32
+ keyboards, notification settings, and reply functionality.
33
+
34
+ Args:
35
+ chat_id (`str`):
36
+ The ID of the chat where the message will be sent.
37
+
38
+ text (`str`):
39
+ The text content of the message.
40
+
41
+ chat_keypad (`Optional[rubigram.types.Keypad]`):
42
+ Custom keyboard to show in the chat. Defaults to None.
43
+
44
+ inline_keypad (`Optional[rubigram.types.Keypad]`):
45
+ Inline keyboard to attach below the message. Defaults to None.
46
+
47
+ chat_keypad_type (`Optional[rubigram.enums.ChatKeypadType]`):
48
+ Type of chat keypad (New, Remove). Defaults to None.
49
+
50
+ disable_notification (`Optional[bool]`):
51
+ If True, disables notification for the message. Defaults to False.
52
+
53
+ reply_to_message_id (`Optional[str]`):
54
+ ID of the message to reply to. Defaults to None.
55
+
56
+ auto_delete (`Optional[int]`):
57
+ If set, the message will be automatically deleted after the specified number of seconds.
58
+
59
+ Returns:
60
+ rubigram.types.UMessage: The sent message object with client binding.
61
+
62
+ Example:
63
+ .. code-block:: python
64
+
65
+ from rubigram.types import Keypad, KeypadRow, Button
66
+
67
+ # Create an inline keyboard
68
+ inline_keypad = Keypad(rows=[
69
+ KeypadRow(buttons=[
70
+ Button(button_text="Option 1", id="btn1"),
71
+ Button(button_text="Option 2", id="btn2")
72
+ ])
73
+ ])
74
+
75
+ # Send a message with inline keyboard
76
+ await client.send_message(
77
+ chat_id=chat_id,
78
+ text=text,
79
+ inline_keypad=inline_keypad,
80
+ disable_notification=True
81
+ )
82
+
83
+ Note:
84
+ The returned UMessage object includes methods for editing,
85
+ deleting, and forwarding the message.
86
+ """
87
+
88
+ data = {"chat_id": chat_id, "text": text}
89
+
90
+ parse = Parser.parser(text, parse_mode or self.parse_mode)
91
+
92
+ if "metadata" in parse:
93
+ data["text"] = parse["text"]
94
+ data["metadata"] = parse["metadata"]
95
+
96
+ if chat_keypad:
97
+ data["chat_keypad"] = chat_keypad.as_dict()
98
+ if inline_keypad:
99
+ data["inline_keypad"] = inline_keypad.as_dict()
100
+ if chat_keypad_type:
101
+ data["chat_keypad_type"] = chat_keypad_type
102
+ if disable_notification:
103
+ data["disable_notification"] = disable_notification
104
+ if reply_to_message_id:
105
+ data["reply_to_message_id"] = reply_to_message_id
106
+
107
+
108
+ response = await self.request("sendMessage", data)
109
+ message = rubigram.types.UMessage.parse(response, self)
110
+ message.chat_id = chat_id
111
+
112
+ if auto_delete and auto_delete > 0:
113
+ AutoDelete.run(self, message, auto_delete)
114
+
115
+ return message