Rubka 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rubka-0.1.0/PKG-INFO +315 -0
- rubka-0.1.0/README.md +284 -0
- rubka-0.1.0/Rubka.egg-info/PKG-INFO +315 -0
- rubka-0.1.0/Rubka.egg-info/SOURCES.txt +14 -0
- rubka-0.1.0/Rubka.egg-info/dependency_links.txt +1 -0
- rubka-0.1.0/Rubka.egg-info/requires.txt +1 -0
- rubka-0.1.0/Rubka.egg-info/top_level.txt +1 -0
- rubka-0.1.0/rubka/__init__.py +11 -0
- rubka-0.1.0/rubka/api.py +211 -0
- rubka-0.1.0/rubka/config.py +3 -0
- rubka-0.1.0/rubka/decorators.py +30 -0
- rubka-0.1.0/rubka/keyboards.py +16 -0
- rubka-0.1.0/rubka/logger.py +12 -0
- rubka-0.1.0/rubka/utils.py +3 -0
- rubka-0.1.0/setup.cfg +4 -0
- rubka-0.1.0/setup.py +34 -0
rubka-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Rubka
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for interacting with Rubika Bot API.
|
|
5
|
+
Home-page: https://github.com/Mahdy-Ahmadi/Rubka
|
|
6
|
+
Download-URL: https://github.com/Mahdy-Ahmadi/Rubka/archive/refs/tags/v0.1.0.tar.gz
|
|
7
|
+
Author: Mahdi Ahmadi
|
|
8
|
+
Author-email: mahdiahmadi.1208@gmail.com
|
|
9
|
+
Maintainer: Mahdi Ahmadi
|
|
10
|
+
Maintainer-email: mahdiahmadi.1208@gmail.com
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Communications :: Chat
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.6
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: download-url
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: maintainer
|
|
27
|
+
Dynamic: maintainer-email
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# rubibot
|
|
34
|
+
|
|
35
|
+
A Python library for interacting with the Rubika Bot API using the Robot class.
|
|
36
|
+
|
|
37
|
+
## Overview
|
|
38
|
+
rubibot is a powerful and easy-to-use Python SDK designed to simplify building bots for the Rubika platform.
|
|
39
|
+
It supports sending messages, editing, polls, locations, contacts, keyboards, and managing bot commands with a clean and modern interface.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install rubibot
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or install from source:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/Mahdy-Ahmadi/rubibot.git
|
|
51
|
+
cd rubibot
|
|
52
|
+
pip install .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from rubibot import Robot, on_message
|
|
59
|
+
|
|
60
|
+
bot = Robot(token="YOUR_BOT_TOKEN")
|
|
61
|
+
|
|
62
|
+
@on_message
|
|
63
|
+
def handle_message(bot, chat_id, message_id, text, sender_id):
|
|
64
|
+
if text == "/start":
|
|
65
|
+
bot.send_message(chat_id, "Hello! Welcome to rubibot.")
|
|
66
|
+
|
|
67
|
+
updates = bot.get_updates(limit=10)
|
|
68
|
+
for update in updates.get("updates", []):
|
|
69
|
+
handle_message(update, bot)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API Reference
|
|
73
|
+
|
|
74
|
+
### Class: Robot
|
|
75
|
+
|
|
76
|
+
The main class to interact with Rubika Bot API.
|
|
77
|
+
|
|
78
|
+
#### Methods:
|
|
79
|
+
|
|
80
|
+
- **get_me()**
|
|
81
|
+
|
|
82
|
+
Retrieve information about the bot.
|
|
83
|
+
|
|
84
|
+
Returns: `dict` — Bot information object.
|
|
85
|
+
|
|
86
|
+
Example:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
info = bot.get_me()
|
|
90
|
+
print(info)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **send_message(chat_id: str, text: str, chat_keypad: dict = None, inline_keypad: dict = None, disable_notification: bool = False, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
94
|
+
|
|
95
|
+
Send a message to a chat with optional keypads.
|
|
96
|
+
|
|
97
|
+
Parameters:
|
|
98
|
+
|
|
99
|
+
- `chat_id` — Chat identifier.
|
|
100
|
+
- `text` — Message text.
|
|
101
|
+
- `chat_keypad` — (Optional) Custom keypad attached to chat.
|
|
102
|
+
- `inline_keypad` — (Optional) Inline keypad attached to message.
|
|
103
|
+
- `disable_notification` — (Optional) Disable notification for the message (default False).
|
|
104
|
+
- `reply_to_message_id` — (Optional) Message ID to reply to.
|
|
105
|
+
- `chat_keypad_type` — (Optional) Type of keypad ("New" or "Removed").
|
|
106
|
+
|
|
107
|
+
Returns: `dict` — Response including the sent message ID.
|
|
108
|
+
|
|
109
|
+
Example:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
bot.send_message(
|
|
113
|
+
chat_id="12345",
|
|
114
|
+
text="Welcome!",
|
|
115
|
+
inline_keypad={
|
|
116
|
+
"rows": [
|
|
117
|
+
{
|
|
118
|
+
"buttons": [
|
|
119
|
+
{"id": "100", "type": "Simple", "button_text": "Add Account"}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- **send_poll(chat_id: str, question: str, options: list[str])**
|
|
128
|
+
|
|
129
|
+
Send a poll to a chat.
|
|
130
|
+
|
|
131
|
+
Parameters:
|
|
132
|
+
|
|
133
|
+
- `chat_id` — Chat identifier.
|
|
134
|
+
- `question` — Poll question text.
|
|
135
|
+
- `options` — List of poll options.
|
|
136
|
+
|
|
137
|
+
Returns: `dict` — Response with poll message ID.
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
bot.send_poll(
|
|
143
|
+
chat_id="12345",
|
|
144
|
+
question="Do you like this bot?",
|
|
145
|
+
options=["Yes", "No"]
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- **send_location(chat_id: str, latitude: str, longitude: str, disable_notification: bool = False, inline_keypad: dict = None, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
150
|
+
|
|
151
|
+
Send a location to a chat.
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
|
|
155
|
+
- `chat_id` — Chat identifier.
|
|
156
|
+
- `latitude` — Latitude coordinate.
|
|
157
|
+
- `longitude` — Longitude coordinate.
|
|
158
|
+
- `disable_notification` — (Optional) Disable notification.
|
|
159
|
+
- `inline_keypad` — (Optional) Inline keypad.
|
|
160
|
+
- `reply_to_message_id` — (Optional) Reply message ID.
|
|
161
|
+
- `chat_keypad_type` — (Optional) Keypad type.
|
|
162
|
+
|
|
163
|
+
Returns: `dict` — Response with message ID.
|
|
164
|
+
|
|
165
|
+
- **send_contact(chat_id: str, first_name: str, last_name: str, phone_number: str, chat_keypad: dict = None, disable_notification: bool = False, inline_keypad: dict = None, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
166
|
+
|
|
167
|
+
Send a contact to a chat.
|
|
168
|
+
|
|
169
|
+
Parameters:
|
|
170
|
+
|
|
171
|
+
- `chat_id` — Chat identifier.
|
|
172
|
+
- `first_name` — Contact's first name.
|
|
173
|
+
- `last_name` — Contact's last name.
|
|
174
|
+
- `phone_number` — Contact's phone number.
|
|
175
|
+
|
|
176
|
+
Additional optional keypad and notification parameters.
|
|
177
|
+
|
|
178
|
+
Returns: `dict` — Response with message ID.
|
|
179
|
+
|
|
180
|
+
- **get_chat(chat_id: str)**
|
|
181
|
+
|
|
182
|
+
Get information about a chat.
|
|
183
|
+
|
|
184
|
+
Parameters:
|
|
185
|
+
|
|
186
|
+
- `chat_id` — Chat identifier.
|
|
187
|
+
|
|
188
|
+
Returns: `dict` — Chat info object.
|
|
189
|
+
|
|
190
|
+
- **get_updates(offset_id: str = None, limit: int = None)**
|
|
191
|
+
|
|
192
|
+
Get recent updates/messages sent to the bot.
|
|
193
|
+
|
|
194
|
+
Parameters:
|
|
195
|
+
|
|
196
|
+
- `offset_id` — (Optional) Start offset for updates.
|
|
197
|
+
- `limit` — (Optional) Max number of updates to retrieve.
|
|
198
|
+
|
|
199
|
+
Returns: `dict` — Updates list.
|
|
200
|
+
|
|
201
|
+
- **forward_message(from_chat_id: str, message_id: str, to_chat_id: str, disable_notification: bool = False)**
|
|
202
|
+
|
|
203
|
+
Forward a message from one chat to another.
|
|
204
|
+
|
|
205
|
+
Parameters:
|
|
206
|
+
|
|
207
|
+
- `from_chat_id` — Source chat ID.
|
|
208
|
+
- `message_id` — Message ID to forward.
|
|
209
|
+
- `to_chat_id` — Target chat ID.
|
|
210
|
+
- `disable_notification` — (Optional) Disable notification.
|
|
211
|
+
|
|
212
|
+
Returns: `dict` — Response with new message ID.
|
|
213
|
+
|
|
214
|
+
- **edit_message_text(chat_id: str, message_id: str, text: str)**
|
|
215
|
+
|
|
216
|
+
Edit the text of a previously sent message.
|
|
217
|
+
|
|
218
|
+
Parameters:
|
|
219
|
+
|
|
220
|
+
- `chat_id` — Chat ID.
|
|
221
|
+
- `message_id` — Message ID to edit.
|
|
222
|
+
- `text` — New text.
|
|
223
|
+
|
|
224
|
+
Returns: `dict` — Response status.
|
|
225
|
+
|
|
226
|
+
- **edit_inline_keypad(chat_id: str, message_id: str, inline_keypad: dict)**
|
|
227
|
+
|
|
228
|
+
Edit the inline keypad of a message.
|
|
229
|
+
|
|
230
|
+
Parameters:
|
|
231
|
+
|
|
232
|
+
- `chat_id` — Chat ID.
|
|
233
|
+
- `message_id` — Message ID.
|
|
234
|
+
- `inline_keypad` — New inline keypad structure.
|
|
235
|
+
|
|
236
|
+
Returns: `dict` — Response status.
|
|
237
|
+
|
|
238
|
+
- **delete_message(chat_id: str, message_id: str)**
|
|
239
|
+
|
|
240
|
+
Delete a message in a chat.
|
|
241
|
+
|
|
242
|
+
Parameters:
|
|
243
|
+
|
|
244
|
+
- `chat_id` — Chat ID.
|
|
245
|
+
- `message_id` — Message ID.
|
|
246
|
+
|
|
247
|
+
Returns: `dict` — Response status.
|
|
248
|
+
|
|
249
|
+
- **set_commands(bot_commands: list[dict])**
|
|
250
|
+
|
|
251
|
+
Set the list of bot commands for the bot menu.
|
|
252
|
+
|
|
253
|
+
Parameters:
|
|
254
|
+
|
|
255
|
+
- `bot_commands` — List of commands as dictionaries with "command" and "description".
|
|
256
|
+
|
|
257
|
+
Returns: `dict` — Response status.
|
|
258
|
+
|
|
259
|
+
- **update_bot_endpoint(url: str, type: str)**
|
|
260
|
+
|
|
261
|
+
Update the bot's webhook or API endpoint URL.
|
|
262
|
+
|
|
263
|
+
Parameters:
|
|
264
|
+
|
|
265
|
+
- `url` — New URL.
|
|
266
|
+
- `type` — Type of update endpoint (e.g. "GetSelectionItem").
|
|
267
|
+
|
|
268
|
+
Returns: `dict` — Response status.
|
|
269
|
+
|
|
270
|
+
- **remove_keypad(chat_id: str)**
|
|
271
|
+
|
|
272
|
+
Remove keypad from a chat.
|
|
273
|
+
|
|
274
|
+
Parameters:
|
|
275
|
+
|
|
276
|
+
- `chat_id` — Chat ID.
|
|
277
|
+
|
|
278
|
+
Returns: `dict` — Response status.
|
|
279
|
+
|
|
280
|
+
- **edit_chat_keypad(chat_id: str, chat_keypad: dict)**
|
|
281
|
+
|
|
282
|
+
Edit or set a new keypad for a chat.
|
|
283
|
+
|
|
284
|
+
Parameters:
|
|
285
|
+
|
|
286
|
+
- `chat_id` — Chat ID.
|
|
287
|
+
- `chat_keypad` — Keypad object.
|
|
288
|
+
|
|
289
|
+
Returns: `dict` — Response status.
|
|
290
|
+
|
|
291
|
+
## Decorators
|
|
292
|
+
|
|
293
|
+
- **@on_message**
|
|
294
|
+
|
|
295
|
+
Decorator for defining a message handler function.
|
|
296
|
+
|
|
297
|
+
Automatically parses incoming updates and calls your handler with parameters: `bot, chat_id, message_id, text, sender_id`.
|
|
298
|
+
|
|
299
|
+
Usage:
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
from rubibot import on_message
|
|
303
|
+
|
|
304
|
+
@on_message
|
|
305
|
+
def my_handler(bot, chat_id, message_id, text, sender_id):
|
|
306
|
+
# your code here
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Contributing
|
|
310
|
+
|
|
311
|
+
Contributions and feedback are welcome! Please submit issues or pull requests on GitHub.
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
rubka-0.1.0/README.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
|
|
2
|
+
# rubibot
|
|
3
|
+
|
|
4
|
+
A Python library for interacting with the Rubika Bot API using the Robot class.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
rubibot is a powerful and easy-to-use Python SDK designed to simplify building bots for the Rubika platform.
|
|
8
|
+
It supports sending messages, editing, polls, locations, contacts, keyboards, and managing bot commands with a clean and modern interface.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install rubibot
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or install from source:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/Mahdy-Ahmadi/rubibot.git
|
|
20
|
+
cd rubibot
|
|
21
|
+
pip install .
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from rubibot import Robot, on_message
|
|
28
|
+
|
|
29
|
+
bot = Robot(token="YOUR_BOT_TOKEN")
|
|
30
|
+
|
|
31
|
+
@on_message
|
|
32
|
+
def handle_message(bot, chat_id, message_id, text, sender_id):
|
|
33
|
+
if text == "/start":
|
|
34
|
+
bot.send_message(chat_id, "Hello! Welcome to rubibot.")
|
|
35
|
+
|
|
36
|
+
updates = bot.get_updates(limit=10)
|
|
37
|
+
for update in updates.get("updates", []):
|
|
38
|
+
handle_message(update, bot)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### Class: Robot
|
|
44
|
+
|
|
45
|
+
The main class to interact with Rubika Bot API.
|
|
46
|
+
|
|
47
|
+
#### Methods:
|
|
48
|
+
|
|
49
|
+
- **get_me()**
|
|
50
|
+
|
|
51
|
+
Retrieve information about the bot.
|
|
52
|
+
|
|
53
|
+
Returns: `dict` — Bot information object.
|
|
54
|
+
|
|
55
|
+
Example:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
info = bot.get_me()
|
|
59
|
+
print(info)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- **send_message(chat_id: str, text: str, chat_keypad: dict = None, inline_keypad: dict = None, disable_notification: bool = False, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
63
|
+
|
|
64
|
+
Send a message to a chat with optional keypads.
|
|
65
|
+
|
|
66
|
+
Parameters:
|
|
67
|
+
|
|
68
|
+
- `chat_id` — Chat identifier.
|
|
69
|
+
- `text` — Message text.
|
|
70
|
+
- `chat_keypad` — (Optional) Custom keypad attached to chat.
|
|
71
|
+
- `inline_keypad` — (Optional) Inline keypad attached to message.
|
|
72
|
+
- `disable_notification` — (Optional) Disable notification for the message (default False).
|
|
73
|
+
- `reply_to_message_id` — (Optional) Message ID to reply to.
|
|
74
|
+
- `chat_keypad_type` — (Optional) Type of keypad ("New" or "Removed").
|
|
75
|
+
|
|
76
|
+
Returns: `dict` — Response including the sent message ID.
|
|
77
|
+
|
|
78
|
+
Example:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
bot.send_message(
|
|
82
|
+
chat_id="12345",
|
|
83
|
+
text="Welcome!",
|
|
84
|
+
inline_keypad={
|
|
85
|
+
"rows": [
|
|
86
|
+
{
|
|
87
|
+
"buttons": [
|
|
88
|
+
{"id": "100", "type": "Simple", "button_text": "Add Account"}
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- **send_poll(chat_id: str, question: str, options: list[str])**
|
|
97
|
+
|
|
98
|
+
Send a poll to a chat.
|
|
99
|
+
|
|
100
|
+
Parameters:
|
|
101
|
+
|
|
102
|
+
- `chat_id` — Chat identifier.
|
|
103
|
+
- `question` — Poll question text.
|
|
104
|
+
- `options` — List of poll options.
|
|
105
|
+
|
|
106
|
+
Returns: `dict` — Response with poll message ID.
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
bot.send_poll(
|
|
112
|
+
chat_id="12345",
|
|
113
|
+
question="Do you like this bot?",
|
|
114
|
+
options=["Yes", "No"]
|
|
115
|
+
)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- **send_location(chat_id: str, latitude: str, longitude: str, disable_notification: bool = False, inline_keypad: dict = None, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
119
|
+
|
|
120
|
+
Send a location to a chat.
|
|
121
|
+
|
|
122
|
+
Parameters:
|
|
123
|
+
|
|
124
|
+
- `chat_id` — Chat identifier.
|
|
125
|
+
- `latitude` — Latitude coordinate.
|
|
126
|
+
- `longitude` — Longitude coordinate.
|
|
127
|
+
- `disable_notification` — (Optional) Disable notification.
|
|
128
|
+
- `inline_keypad` — (Optional) Inline keypad.
|
|
129
|
+
- `reply_to_message_id` — (Optional) Reply message ID.
|
|
130
|
+
- `chat_keypad_type` — (Optional) Keypad type.
|
|
131
|
+
|
|
132
|
+
Returns: `dict` — Response with message ID.
|
|
133
|
+
|
|
134
|
+
- **send_contact(chat_id: str, first_name: str, last_name: str, phone_number: str, chat_keypad: dict = None, disable_notification: bool = False, inline_keypad: dict = None, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
135
|
+
|
|
136
|
+
Send a contact to a chat.
|
|
137
|
+
|
|
138
|
+
Parameters:
|
|
139
|
+
|
|
140
|
+
- `chat_id` — Chat identifier.
|
|
141
|
+
- `first_name` — Contact's first name.
|
|
142
|
+
- `last_name` — Contact's last name.
|
|
143
|
+
- `phone_number` — Contact's phone number.
|
|
144
|
+
|
|
145
|
+
Additional optional keypad and notification parameters.
|
|
146
|
+
|
|
147
|
+
Returns: `dict` — Response with message ID.
|
|
148
|
+
|
|
149
|
+
- **get_chat(chat_id: str)**
|
|
150
|
+
|
|
151
|
+
Get information about a chat.
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
|
|
155
|
+
- `chat_id` — Chat identifier.
|
|
156
|
+
|
|
157
|
+
Returns: `dict` — Chat info object.
|
|
158
|
+
|
|
159
|
+
- **get_updates(offset_id: str = None, limit: int = None)**
|
|
160
|
+
|
|
161
|
+
Get recent updates/messages sent to the bot.
|
|
162
|
+
|
|
163
|
+
Parameters:
|
|
164
|
+
|
|
165
|
+
- `offset_id` — (Optional) Start offset for updates.
|
|
166
|
+
- `limit` — (Optional) Max number of updates to retrieve.
|
|
167
|
+
|
|
168
|
+
Returns: `dict` — Updates list.
|
|
169
|
+
|
|
170
|
+
- **forward_message(from_chat_id: str, message_id: str, to_chat_id: str, disable_notification: bool = False)**
|
|
171
|
+
|
|
172
|
+
Forward a message from one chat to another.
|
|
173
|
+
|
|
174
|
+
Parameters:
|
|
175
|
+
|
|
176
|
+
- `from_chat_id` — Source chat ID.
|
|
177
|
+
- `message_id` — Message ID to forward.
|
|
178
|
+
- `to_chat_id` — Target chat ID.
|
|
179
|
+
- `disable_notification` — (Optional) Disable notification.
|
|
180
|
+
|
|
181
|
+
Returns: `dict` — Response with new message ID.
|
|
182
|
+
|
|
183
|
+
- **edit_message_text(chat_id: str, message_id: str, text: str)**
|
|
184
|
+
|
|
185
|
+
Edit the text of a previously sent message.
|
|
186
|
+
|
|
187
|
+
Parameters:
|
|
188
|
+
|
|
189
|
+
- `chat_id` — Chat ID.
|
|
190
|
+
- `message_id` — Message ID to edit.
|
|
191
|
+
- `text` — New text.
|
|
192
|
+
|
|
193
|
+
Returns: `dict` — Response status.
|
|
194
|
+
|
|
195
|
+
- **edit_inline_keypad(chat_id: str, message_id: str, inline_keypad: dict)**
|
|
196
|
+
|
|
197
|
+
Edit the inline keypad of a message.
|
|
198
|
+
|
|
199
|
+
Parameters:
|
|
200
|
+
|
|
201
|
+
- `chat_id` — Chat ID.
|
|
202
|
+
- `message_id` — Message ID.
|
|
203
|
+
- `inline_keypad` — New inline keypad structure.
|
|
204
|
+
|
|
205
|
+
Returns: `dict` — Response status.
|
|
206
|
+
|
|
207
|
+
- **delete_message(chat_id: str, message_id: str)**
|
|
208
|
+
|
|
209
|
+
Delete a message in a chat.
|
|
210
|
+
|
|
211
|
+
Parameters:
|
|
212
|
+
|
|
213
|
+
- `chat_id` — Chat ID.
|
|
214
|
+
- `message_id` — Message ID.
|
|
215
|
+
|
|
216
|
+
Returns: `dict` — Response status.
|
|
217
|
+
|
|
218
|
+
- **set_commands(bot_commands: list[dict])**
|
|
219
|
+
|
|
220
|
+
Set the list of bot commands for the bot menu.
|
|
221
|
+
|
|
222
|
+
Parameters:
|
|
223
|
+
|
|
224
|
+
- `bot_commands` — List of commands as dictionaries with "command" and "description".
|
|
225
|
+
|
|
226
|
+
Returns: `dict` — Response status.
|
|
227
|
+
|
|
228
|
+
- **update_bot_endpoint(url: str, type: str)**
|
|
229
|
+
|
|
230
|
+
Update the bot's webhook or API endpoint URL.
|
|
231
|
+
|
|
232
|
+
Parameters:
|
|
233
|
+
|
|
234
|
+
- `url` — New URL.
|
|
235
|
+
- `type` — Type of update endpoint (e.g. "GetSelectionItem").
|
|
236
|
+
|
|
237
|
+
Returns: `dict` — Response status.
|
|
238
|
+
|
|
239
|
+
- **remove_keypad(chat_id: str)**
|
|
240
|
+
|
|
241
|
+
Remove keypad from a chat.
|
|
242
|
+
|
|
243
|
+
Parameters:
|
|
244
|
+
|
|
245
|
+
- `chat_id` — Chat ID.
|
|
246
|
+
|
|
247
|
+
Returns: `dict` — Response status.
|
|
248
|
+
|
|
249
|
+
- **edit_chat_keypad(chat_id: str, chat_keypad: dict)**
|
|
250
|
+
|
|
251
|
+
Edit or set a new keypad for a chat.
|
|
252
|
+
|
|
253
|
+
Parameters:
|
|
254
|
+
|
|
255
|
+
- `chat_id` — Chat ID.
|
|
256
|
+
- `chat_keypad` — Keypad object.
|
|
257
|
+
|
|
258
|
+
Returns: `dict` — Response status.
|
|
259
|
+
|
|
260
|
+
## Decorators
|
|
261
|
+
|
|
262
|
+
- **@on_message**
|
|
263
|
+
|
|
264
|
+
Decorator for defining a message handler function.
|
|
265
|
+
|
|
266
|
+
Automatically parses incoming updates and calls your handler with parameters: `bot, chat_id, message_id, text, sender_id`.
|
|
267
|
+
|
|
268
|
+
Usage:
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
from rubibot import on_message
|
|
272
|
+
|
|
273
|
+
@on_message
|
|
274
|
+
def my_handler(bot, chat_id, message_id, text, sender_id):
|
|
275
|
+
# your code here
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Contributing
|
|
279
|
+
|
|
280
|
+
Contributions and feedback are welcome! Please submit issues or pull requests on GitHub.
|
|
281
|
+
|
|
282
|
+
## License
|
|
283
|
+
|
|
284
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Rubka
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python library for interacting with Rubika Bot API.
|
|
5
|
+
Home-page: https://github.com/Mahdy-Ahmadi/Rubka
|
|
6
|
+
Download-URL: https://github.com/Mahdy-Ahmadi/Rubka/archive/refs/tags/v0.1.0.tar.gz
|
|
7
|
+
Author: Mahdi Ahmadi
|
|
8
|
+
Author-email: mahdiahmadi.1208@gmail.com
|
|
9
|
+
Maintainer: Mahdi Ahmadi
|
|
10
|
+
Maintainer-email: mahdiahmadi.1208@gmail.com
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Communications :: Chat
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.6
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Dynamic: author
|
|
20
|
+
Dynamic: author-email
|
|
21
|
+
Dynamic: classifier
|
|
22
|
+
Dynamic: description
|
|
23
|
+
Dynamic: description-content-type
|
|
24
|
+
Dynamic: download-url
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: maintainer
|
|
27
|
+
Dynamic: maintainer-email
|
|
28
|
+
Dynamic: requires-dist
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# rubibot
|
|
34
|
+
|
|
35
|
+
A Python library for interacting with the Rubika Bot API using the Robot class.
|
|
36
|
+
|
|
37
|
+
## Overview
|
|
38
|
+
rubibot is a powerful and easy-to-use Python SDK designed to simplify building bots for the Rubika platform.
|
|
39
|
+
It supports sending messages, editing, polls, locations, contacts, keyboards, and managing bot commands with a clean and modern interface.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install rubibot
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or install from source:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
git clone https://github.com/Mahdy-Ahmadi/rubibot.git
|
|
51
|
+
cd rubibot
|
|
52
|
+
pip install .
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from rubibot import Robot, on_message
|
|
59
|
+
|
|
60
|
+
bot = Robot(token="YOUR_BOT_TOKEN")
|
|
61
|
+
|
|
62
|
+
@on_message
|
|
63
|
+
def handle_message(bot, chat_id, message_id, text, sender_id):
|
|
64
|
+
if text == "/start":
|
|
65
|
+
bot.send_message(chat_id, "Hello! Welcome to rubibot.")
|
|
66
|
+
|
|
67
|
+
updates = bot.get_updates(limit=10)
|
|
68
|
+
for update in updates.get("updates", []):
|
|
69
|
+
handle_message(update, bot)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API Reference
|
|
73
|
+
|
|
74
|
+
### Class: Robot
|
|
75
|
+
|
|
76
|
+
The main class to interact with Rubika Bot API.
|
|
77
|
+
|
|
78
|
+
#### Methods:
|
|
79
|
+
|
|
80
|
+
- **get_me()**
|
|
81
|
+
|
|
82
|
+
Retrieve information about the bot.
|
|
83
|
+
|
|
84
|
+
Returns: `dict` — Bot information object.
|
|
85
|
+
|
|
86
|
+
Example:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
info = bot.get_me()
|
|
90
|
+
print(info)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **send_message(chat_id: str, text: str, chat_keypad: dict = None, inline_keypad: dict = None, disable_notification: bool = False, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
94
|
+
|
|
95
|
+
Send a message to a chat with optional keypads.
|
|
96
|
+
|
|
97
|
+
Parameters:
|
|
98
|
+
|
|
99
|
+
- `chat_id` — Chat identifier.
|
|
100
|
+
- `text` — Message text.
|
|
101
|
+
- `chat_keypad` — (Optional) Custom keypad attached to chat.
|
|
102
|
+
- `inline_keypad` — (Optional) Inline keypad attached to message.
|
|
103
|
+
- `disable_notification` — (Optional) Disable notification for the message (default False).
|
|
104
|
+
- `reply_to_message_id` — (Optional) Message ID to reply to.
|
|
105
|
+
- `chat_keypad_type` — (Optional) Type of keypad ("New" or "Removed").
|
|
106
|
+
|
|
107
|
+
Returns: `dict` — Response including the sent message ID.
|
|
108
|
+
|
|
109
|
+
Example:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
bot.send_message(
|
|
113
|
+
chat_id="12345",
|
|
114
|
+
text="Welcome!",
|
|
115
|
+
inline_keypad={
|
|
116
|
+
"rows": [
|
|
117
|
+
{
|
|
118
|
+
"buttons": [
|
|
119
|
+
{"id": "100", "type": "Simple", "button_text": "Add Account"}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- **send_poll(chat_id: str, question: str, options: list[str])**
|
|
128
|
+
|
|
129
|
+
Send a poll to a chat.
|
|
130
|
+
|
|
131
|
+
Parameters:
|
|
132
|
+
|
|
133
|
+
- `chat_id` — Chat identifier.
|
|
134
|
+
- `question` — Poll question text.
|
|
135
|
+
- `options` — List of poll options.
|
|
136
|
+
|
|
137
|
+
Returns: `dict` — Response with poll message ID.
|
|
138
|
+
|
|
139
|
+
Example:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
bot.send_poll(
|
|
143
|
+
chat_id="12345",
|
|
144
|
+
question="Do you like this bot?",
|
|
145
|
+
options=["Yes", "No"]
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- **send_location(chat_id: str, latitude: str, longitude: str, disable_notification: bool = False, inline_keypad: dict = None, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
150
|
+
|
|
151
|
+
Send a location to a chat.
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
|
|
155
|
+
- `chat_id` — Chat identifier.
|
|
156
|
+
- `latitude` — Latitude coordinate.
|
|
157
|
+
- `longitude` — Longitude coordinate.
|
|
158
|
+
- `disable_notification` — (Optional) Disable notification.
|
|
159
|
+
- `inline_keypad` — (Optional) Inline keypad.
|
|
160
|
+
- `reply_to_message_id` — (Optional) Reply message ID.
|
|
161
|
+
- `chat_keypad_type` — (Optional) Keypad type.
|
|
162
|
+
|
|
163
|
+
Returns: `dict` — Response with message ID.
|
|
164
|
+
|
|
165
|
+
- **send_contact(chat_id: str, first_name: str, last_name: str, phone_number: str, chat_keypad: dict = None, disable_notification: bool = False, inline_keypad: dict = None, reply_to_message_id: str = None, chat_keypad_type: str = None)**
|
|
166
|
+
|
|
167
|
+
Send a contact to a chat.
|
|
168
|
+
|
|
169
|
+
Parameters:
|
|
170
|
+
|
|
171
|
+
- `chat_id` — Chat identifier.
|
|
172
|
+
- `first_name` — Contact's first name.
|
|
173
|
+
- `last_name` — Contact's last name.
|
|
174
|
+
- `phone_number` — Contact's phone number.
|
|
175
|
+
|
|
176
|
+
Additional optional keypad and notification parameters.
|
|
177
|
+
|
|
178
|
+
Returns: `dict` — Response with message ID.
|
|
179
|
+
|
|
180
|
+
- **get_chat(chat_id: str)**
|
|
181
|
+
|
|
182
|
+
Get information about a chat.
|
|
183
|
+
|
|
184
|
+
Parameters:
|
|
185
|
+
|
|
186
|
+
- `chat_id` — Chat identifier.
|
|
187
|
+
|
|
188
|
+
Returns: `dict` — Chat info object.
|
|
189
|
+
|
|
190
|
+
- **get_updates(offset_id: str = None, limit: int = None)**
|
|
191
|
+
|
|
192
|
+
Get recent updates/messages sent to the bot.
|
|
193
|
+
|
|
194
|
+
Parameters:
|
|
195
|
+
|
|
196
|
+
- `offset_id` — (Optional) Start offset for updates.
|
|
197
|
+
- `limit` — (Optional) Max number of updates to retrieve.
|
|
198
|
+
|
|
199
|
+
Returns: `dict` — Updates list.
|
|
200
|
+
|
|
201
|
+
- **forward_message(from_chat_id: str, message_id: str, to_chat_id: str, disable_notification: bool = False)**
|
|
202
|
+
|
|
203
|
+
Forward a message from one chat to another.
|
|
204
|
+
|
|
205
|
+
Parameters:
|
|
206
|
+
|
|
207
|
+
- `from_chat_id` — Source chat ID.
|
|
208
|
+
- `message_id` — Message ID to forward.
|
|
209
|
+
- `to_chat_id` — Target chat ID.
|
|
210
|
+
- `disable_notification` — (Optional) Disable notification.
|
|
211
|
+
|
|
212
|
+
Returns: `dict` — Response with new message ID.
|
|
213
|
+
|
|
214
|
+
- **edit_message_text(chat_id: str, message_id: str, text: str)**
|
|
215
|
+
|
|
216
|
+
Edit the text of a previously sent message.
|
|
217
|
+
|
|
218
|
+
Parameters:
|
|
219
|
+
|
|
220
|
+
- `chat_id` — Chat ID.
|
|
221
|
+
- `message_id` — Message ID to edit.
|
|
222
|
+
- `text` — New text.
|
|
223
|
+
|
|
224
|
+
Returns: `dict` — Response status.
|
|
225
|
+
|
|
226
|
+
- **edit_inline_keypad(chat_id: str, message_id: str, inline_keypad: dict)**
|
|
227
|
+
|
|
228
|
+
Edit the inline keypad of a message.
|
|
229
|
+
|
|
230
|
+
Parameters:
|
|
231
|
+
|
|
232
|
+
- `chat_id` — Chat ID.
|
|
233
|
+
- `message_id` — Message ID.
|
|
234
|
+
- `inline_keypad` — New inline keypad structure.
|
|
235
|
+
|
|
236
|
+
Returns: `dict` — Response status.
|
|
237
|
+
|
|
238
|
+
- **delete_message(chat_id: str, message_id: str)**
|
|
239
|
+
|
|
240
|
+
Delete a message in a chat.
|
|
241
|
+
|
|
242
|
+
Parameters:
|
|
243
|
+
|
|
244
|
+
- `chat_id` — Chat ID.
|
|
245
|
+
- `message_id` — Message ID.
|
|
246
|
+
|
|
247
|
+
Returns: `dict` — Response status.
|
|
248
|
+
|
|
249
|
+
- **set_commands(bot_commands: list[dict])**
|
|
250
|
+
|
|
251
|
+
Set the list of bot commands for the bot menu.
|
|
252
|
+
|
|
253
|
+
Parameters:
|
|
254
|
+
|
|
255
|
+
- `bot_commands` — List of commands as dictionaries with "command" and "description".
|
|
256
|
+
|
|
257
|
+
Returns: `dict` — Response status.
|
|
258
|
+
|
|
259
|
+
- **update_bot_endpoint(url: str, type: str)**
|
|
260
|
+
|
|
261
|
+
Update the bot's webhook or API endpoint URL.
|
|
262
|
+
|
|
263
|
+
Parameters:
|
|
264
|
+
|
|
265
|
+
- `url` — New URL.
|
|
266
|
+
- `type` — Type of update endpoint (e.g. "GetSelectionItem").
|
|
267
|
+
|
|
268
|
+
Returns: `dict` — Response status.
|
|
269
|
+
|
|
270
|
+
- **remove_keypad(chat_id: str)**
|
|
271
|
+
|
|
272
|
+
Remove keypad from a chat.
|
|
273
|
+
|
|
274
|
+
Parameters:
|
|
275
|
+
|
|
276
|
+
- `chat_id` — Chat ID.
|
|
277
|
+
|
|
278
|
+
Returns: `dict` — Response status.
|
|
279
|
+
|
|
280
|
+
- **edit_chat_keypad(chat_id: str, chat_keypad: dict)**
|
|
281
|
+
|
|
282
|
+
Edit or set a new keypad for a chat.
|
|
283
|
+
|
|
284
|
+
Parameters:
|
|
285
|
+
|
|
286
|
+
- `chat_id` — Chat ID.
|
|
287
|
+
- `chat_keypad` — Keypad object.
|
|
288
|
+
|
|
289
|
+
Returns: `dict` — Response status.
|
|
290
|
+
|
|
291
|
+
## Decorators
|
|
292
|
+
|
|
293
|
+
- **@on_message**
|
|
294
|
+
|
|
295
|
+
Decorator for defining a message handler function.
|
|
296
|
+
|
|
297
|
+
Automatically parses incoming updates and calls your handler with parameters: `bot, chat_id, message_id, text, sender_id`.
|
|
298
|
+
|
|
299
|
+
Usage:
|
|
300
|
+
|
|
301
|
+
```python
|
|
302
|
+
from rubibot import on_message
|
|
303
|
+
|
|
304
|
+
@on_message
|
|
305
|
+
def my_handler(bot, chat_id, message_id, text, sender_id):
|
|
306
|
+
# your code here
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Contributing
|
|
310
|
+
|
|
311
|
+
Contributions and feedback are welcome! Please submit issues or pull requests on GitHub.
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
Rubka.egg-info/PKG-INFO
|
|
4
|
+
Rubka.egg-info/SOURCES.txt
|
|
5
|
+
Rubka.egg-info/dependency_links.txt
|
|
6
|
+
Rubka.egg-info/requires.txt
|
|
7
|
+
Rubka.egg-info/top_level.txt
|
|
8
|
+
rubka/__init__.py
|
|
9
|
+
rubka/api.py
|
|
10
|
+
rubka/config.py
|
|
11
|
+
rubka/decorators.py
|
|
12
|
+
rubka/keyboards.py
|
|
13
|
+
rubka/logger.py
|
|
14
|
+
rubka/utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rubka
|
rubka-0.1.0/rubka/api.py
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import List, Optional, Dict, Any, Literal
|
|
3
|
+
from .exceptions import APIRequestError
|
|
4
|
+
from .logger import logger
|
|
5
|
+
|
|
6
|
+
API_URL = "https://botapi.rubika.ir/v3"
|
|
7
|
+
|
|
8
|
+
class Robot:
|
|
9
|
+
"""
|
|
10
|
+
Main class to interact with Rubika Bot API.
|
|
11
|
+
Initialized with bot token.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, token: str):
|
|
15
|
+
self.token = token
|
|
16
|
+
self.session = requests.Session()
|
|
17
|
+
logger.info(f"Initialized RubikaBot with token: {token[:8]}***")
|
|
18
|
+
|
|
19
|
+
def _post(self, method: str, data: Dict[str, Any]) -> Dict[str, Any]:
|
|
20
|
+
url = f"{API_URL}/{self.token}/{method}"
|
|
21
|
+
try:
|
|
22
|
+
response = self.session.post(url, json=data, timeout=10)
|
|
23
|
+
response.raise_for_status()
|
|
24
|
+
json_resp = response.json()
|
|
25
|
+
logger.debug(f"API Response from {method}: {json_resp}")
|
|
26
|
+
return json_resp
|
|
27
|
+
except requests.RequestException as e:
|
|
28
|
+
logger.error(f"API request failed: {e}")
|
|
29
|
+
raise APIRequestError(f"API request failed: {e}") from e
|
|
30
|
+
|
|
31
|
+
def get_me(self) -> Dict[str, Any]:
|
|
32
|
+
"""Get info about the bot itself."""
|
|
33
|
+
return self._post("getMe", {})
|
|
34
|
+
|
|
35
|
+
def send_message(
|
|
36
|
+
self,
|
|
37
|
+
chat_id: str,
|
|
38
|
+
text: str,
|
|
39
|
+
chat_keypad: Optional[Dict[str, Any]] = None,
|
|
40
|
+
inline_keypad: Optional[Dict[str, Any]] = None,
|
|
41
|
+
disable_notification: bool = False,
|
|
42
|
+
reply_to_message_id: Optional[str] = None,
|
|
43
|
+
chat_keypad_type: Optional[Literal["New", "Removed"]] = None
|
|
44
|
+
) -> Dict[str, Any]:
|
|
45
|
+
"""
|
|
46
|
+
Send a text message to a chat.
|
|
47
|
+
"""
|
|
48
|
+
payload = {
|
|
49
|
+
"chat_id": chat_id,
|
|
50
|
+
"text": text,
|
|
51
|
+
"disable_notification": disable_notification
|
|
52
|
+
}
|
|
53
|
+
if chat_keypad:
|
|
54
|
+
payload["chat_keypad"] = chat_keypad
|
|
55
|
+
if inline_keypad:
|
|
56
|
+
payload["inline_keypad"] = inline_keypad
|
|
57
|
+
if reply_to_message_id:
|
|
58
|
+
payload["reply_to_message_id"] = reply_to_message_id
|
|
59
|
+
if chat_keypad_type:
|
|
60
|
+
payload["chat_keypad_type"] = chat_keypad_type
|
|
61
|
+
|
|
62
|
+
return self._post("sendMessage", payload)
|
|
63
|
+
|
|
64
|
+
def send_poll(
|
|
65
|
+
self,
|
|
66
|
+
chat_id: str,
|
|
67
|
+
question: str,
|
|
68
|
+
options: List[str]
|
|
69
|
+
) -> Dict[str, Any]:
|
|
70
|
+
"""
|
|
71
|
+
Send a poll to a chat.
|
|
72
|
+
"""
|
|
73
|
+
return self._post("sendPoll", {
|
|
74
|
+
"chat_id": chat_id,
|
|
75
|
+
"question": question,
|
|
76
|
+
"options": options
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
def send_location(
|
|
80
|
+
self,
|
|
81
|
+
chat_id: str,
|
|
82
|
+
latitude: str,
|
|
83
|
+
longitude: str,
|
|
84
|
+
disable_notification: bool = False,
|
|
85
|
+
inline_keypad: Optional[Dict[str, Any]] = None,
|
|
86
|
+
reply_to_message_id: Optional[str] = None,
|
|
87
|
+
chat_keypad_type: Optional[Literal["New", "Removed"]] = None
|
|
88
|
+
) -> Dict[str, Any]:
|
|
89
|
+
"""
|
|
90
|
+
Send a location to a chat.
|
|
91
|
+
"""
|
|
92
|
+
payload = {
|
|
93
|
+
"chat_id": chat_id,
|
|
94
|
+
"latitude": latitude,
|
|
95
|
+
"longitude": longitude,
|
|
96
|
+
"disable_notification": disable_notification,
|
|
97
|
+
"inline_keypad": inline_keypad,
|
|
98
|
+
"reply_to_message_id": reply_to_message_id,
|
|
99
|
+
"chat_keypad_type": chat_keypad_type
|
|
100
|
+
}
|
|
101
|
+
# Remove None values
|
|
102
|
+
payload = {k: v for k, v in payload.items() if v is not None}
|
|
103
|
+
return self._post("sendLocation", payload)
|
|
104
|
+
|
|
105
|
+
def send_contact(
|
|
106
|
+
self,
|
|
107
|
+
chat_id: str,
|
|
108
|
+
first_name: str,
|
|
109
|
+
last_name: str,
|
|
110
|
+
phone_number: str
|
|
111
|
+
) -> Dict[str, Any]:
|
|
112
|
+
"""
|
|
113
|
+
Send a contact to a chat.
|
|
114
|
+
"""
|
|
115
|
+
return self._post("sendContact", {
|
|
116
|
+
"chat_id": chat_id,
|
|
117
|
+
"first_name": first_name,
|
|
118
|
+
"last_name": last_name,
|
|
119
|
+
"phone_number": phone_number
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
def get_chat(self, chat_id: str) -> Dict[str, Any]:
|
|
123
|
+
"""Get chat info."""
|
|
124
|
+
return self._post("getChat", {"chat_id": chat_id})
|
|
125
|
+
|
|
126
|
+
def get_updates(
|
|
127
|
+
self,
|
|
128
|
+
offset_id: Optional[str] = None,
|
|
129
|
+
limit: Optional[int] = None
|
|
130
|
+
) -> Dict[str, Any]:
|
|
131
|
+
"""Get updates."""
|
|
132
|
+
data = {}
|
|
133
|
+
if offset_id:
|
|
134
|
+
data["offset_id"] = offset_id
|
|
135
|
+
if limit:
|
|
136
|
+
data["limit"] = limit
|
|
137
|
+
return self._post("getUpdates", data)
|
|
138
|
+
|
|
139
|
+
def forward_message(
|
|
140
|
+
self,
|
|
141
|
+
from_chat_id: str,
|
|
142
|
+
message_id: str,
|
|
143
|
+
to_chat_id: str,
|
|
144
|
+
disable_notification: bool = False
|
|
145
|
+
) -> Dict[str, Any]:
|
|
146
|
+
"""Forward a message from one chat to another."""
|
|
147
|
+
return self._post("forwardMessage", {
|
|
148
|
+
"from_chat_id": from_chat_id,
|
|
149
|
+
"message_id": message_id,
|
|
150
|
+
"to_chat_id": to_chat_id,
|
|
151
|
+
"disable_notification": disable_notification
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
def edit_message_text(
|
|
155
|
+
self,
|
|
156
|
+
chat_id: str,
|
|
157
|
+
message_id: str,
|
|
158
|
+
text: str
|
|
159
|
+
) -> Dict[str, Any]:
|
|
160
|
+
"""Edit text of an existing message."""
|
|
161
|
+
return self._post("editMessageText", {
|
|
162
|
+
"chat_id": chat_id,
|
|
163
|
+
"message_id": message_id,
|
|
164
|
+
"text": text
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
def edit_inline_keypad(
|
|
168
|
+
self,
|
|
169
|
+
chat_id: str,
|
|
170
|
+
message_id: str,
|
|
171
|
+
inline_keypad: Dict[str, Any]
|
|
172
|
+
) -> Dict[str, Any]:
|
|
173
|
+
"""Edit inline keypad of a message."""
|
|
174
|
+
return self._post("editInlineKeypad", {
|
|
175
|
+
"chat_id": chat_id,
|
|
176
|
+
"message_id": message_id,
|
|
177
|
+
"inline_keypad": inline_keypad
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
def delete_message(self, chat_id: str, message_id: str) -> Dict[str, Any]:
|
|
181
|
+
"""Delete a message from chat."""
|
|
182
|
+
return self._post("deleteMessage", {
|
|
183
|
+
"chat_id": chat_id,
|
|
184
|
+
"message_id": message_id
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
def set_commands(self, bot_commands: List[Dict[str, str]]) -> Dict[str, Any]:
|
|
188
|
+
"""Set bot commands."""
|
|
189
|
+
return self._post("setCommands", {"bot_commands": bot_commands})
|
|
190
|
+
|
|
191
|
+
def update_bot_endpoint(self, url: str, type: str) -> Dict[str, Any]:
|
|
192
|
+
"""Update bot endpoint (Webhook or Polling)."""
|
|
193
|
+
return self._post("updateBotEndpoints", {
|
|
194
|
+
"url": url,
|
|
195
|
+
"type": type
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
def remove_keypad(self, chat_id: str) -> Dict[str, Any]:
|
|
199
|
+
"""Remove chat keypad."""
|
|
200
|
+
return self._post("editChatKeypad", {
|
|
201
|
+
"chat_id": chat_id,
|
|
202
|
+
"chat_keypad_type": "Removed"
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
def edit_chat_keypad(self, chat_id: str, chat_keypad: Dict[str, Any]) -> Dict[str, Any]:
|
|
206
|
+
"""Edit or add new chat keypad."""
|
|
207
|
+
return self._post("editChatKeypad", {
|
|
208
|
+
"chat_id": chat_id,
|
|
209
|
+
"chat_keypad_type": "New",
|
|
210
|
+
"chat_keypad": chat_keypad
|
|
211
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from typing import Callable, Dict, Any
|
|
2
|
+
import functools
|
|
3
|
+
|
|
4
|
+
def on_message(func: Callable):
|
|
5
|
+
"""
|
|
6
|
+
Decorator to handle incoming message updates from Rubika.
|
|
7
|
+
Extracts message details and passes them to decorated function.
|
|
8
|
+
"""
|
|
9
|
+
@functools.wraps(func)
|
|
10
|
+
def wrapper(update: Dict[str, Any], bot: 'Robot'):
|
|
11
|
+
message_data = {}
|
|
12
|
+
if 'update' in update and update['update'].get('type') == 'NewMessage':
|
|
13
|
+
msg = update['update']['new_message']
|
|
14
|
+
message_data = {
|
|
15
|
+
'chat_id': update['update']['chat_id'],
|
|
16
|
+
'message_id': msg.get('message_id'),
|
|
17
|
+
'text': msg.get('text'),
|
|
18
|
+
'sender_id': msg.get('sender_id')
|
|
19
|
+
}
|
|
20
|
+
elif 'inline_message' in update:
|
|
21
|
+
msg = update['inline_message']
|
|
22
|
+
message_data = {
|
|
23
|
+
'chat_id': msg.get('chat_id'),
|
|
24
|
+
'message_id': msg.get('message_id'),
|
|
25
|
+
'text': msg.get('text'),
|
|
26
|
+
'sender_id': msg.get('sender_id')
|
|
27
|
+
}
|
|
28
|
+
if message_data:
|
|
29
|
+
return func(bot=bot, **message_data)
|
|
30
|
+
return wrapper
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
|
|
3
|
+
def create_simple_keyboard(buttons: List[List[str]]) -> Dict:
|
|
4
|
+
"""
|
|
5
|
+
Create a simple chat keypad (keyboard) structure for Rubika.
|
|
6
|
+
buttons: List of button rows, each row is a list of button texts.
|
|
7
|
+
Example:
|
|
8
|
+
[
|
|
9
|
+
["Button1", "Button2"],
|
|
10
|
+
["Button3"]
|
|
11
|
+
]
|
|
12
|
+
"""
|
|
13
|
+
keyboard = {"rows": []}
|
|
14
|
+
for row in buttons:
|
|
15
|
+
keyboard["rows"].append({"buttons": [{"text": text} for text in row]})
|
|
16
|
+
return keyboard
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
logger = logging.getLogger("rubka")
|
|
4
|
+
logger.setLevel(logging.DEBUG)
|
|
5
|
+
|
|
6
|
+
ch = logging.StreamHandler()
|
|
7
|
+
ch.setLevel(logging.DEBUG)
|
|
8
|
+
|
|
9
|
+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
10
|
+
ch.setFormatter(formatter)
|
|
11
|
+
|
|
12
|
+
logger.addHandler(ch)
|
rubka-0.1.0/setup.cfg
ADDED
rubka-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
with open('README.md', encoding='utf-8') as f:
|
|
5
|
+
long_description = f.read()
|
|
6
|
+
except FileNotFoundError:
|
|
7
|
+
long_description = ''
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name='Rubka',
|
|
11
|
+
version='0.1.0',
|
|
12
|
+
description='A Python library for interacting with Rubika Bot API.',
|
|
13
|
+
long_description=long_description,
|
|
14
|
+
long_description_content_type='text/markdown',
|
|
15
|
+
author='Mahdi Ahmadi',
|
|
16
|
+
author_email='mahdiahmadi.1208@gmail.com',
|
|
17
|
+
maintainer='Mahdi Ahmadi',
|
|
18
|
+
maintainer_email='mahdiahmadi.1208@gmail.com',
|
|
19
|
+
url='https://github.com/Mahdy-Ahmadi/Rubka',
|
|
20
|
+
download_url='https://github.com/Mahdy-Ahmadi/Rubka/archive/refs/tags/v0.1.0.tar.gz',
|
|
21
|
+
packages=find_packages(),
|
|
22
|
+
include_package_data=True,
|
|
23
|
+
classifiers=[
|
|
24
|
+
'Programming Language :: Python :: 3',
|
|
25
|
+
'License :: OSI Approved :: MIT License',
|
|
26
|
+
'Operating System :: OS Independent',
|
|
27
|
+
'Topic :: Communications :: Chat',
|
|
28
|
+
'Topic :: Software Development :: Libraries',
|
|
29
|
+
],
|
|
30
|
+
python_requires='>=3.6',
|
|
31
|
+
install_requires=[
|
|
32
|
+
'requests',
|
|
33
|
+
],
|
|
34
|
+
)
|