Rubika has created APIs for you that you can use to build your own "bot".
Requirements
python3.8 +
Installation
$ pip install rubika-bot
Steps of use
- First you have to create a bot for yourself with Bot Father.
- Hold the token it gives you and use it the following methods.
Description
After you have built your bot in Bot Father and defined your endpoint, the system will send any event or message sent to your bot to your Endpoint in one of the following two ways.
- Endpoint/
receiveUpdate - Endpoint/
receiveInlineMessage
receiveUpdate
Whenever a user sends a message or taps on a keypad , you will receive this type of request.
sample body :
{
"inline_message": {
"sender_id": "u0QFtn01dd26d72abc5c77b8e116cd79",
"text": "custom text",
"location": null,
"aux_data": {
"start_id": null,
"button_id": "61f674bd0abcd57b5b816a7c"
},
"message_id": "204216801381244279",
"chat_id": "b0QFtabc1I02214b529f1d60c9ce5b08"
}
}
- sender_id: Unique identifier assigned to the user.
- text: The text of the sent button.
- button_id: The ID you set for the button.
- message_id: The unique identifier assigned to the message.
- chat_id: Unique identifier for the conversation between the user and the bot (you must continue to use this identifier.)
receiveInlineMessage
Whenever the user taps on the inline keypad, you receive this type of request.
sample body :
{
"update": {
"type": "NewMessage",
"chat_id": "b0QFtn0C1I022abcd29f1d60c9ce5b08",
"new_message": {
"message_id": 204215121115944300,
"text": "custom text",
"time": "1643122902",
"is_edited": false,
"sender_type": "User",
"sender_id": "u0QFtn0abcded727585c77b8e116cd79",
"aux_data": {
"start_id": null,
"button_id": "61f674bd0abcd57b5b816a7c"
}
}
}
}
- type: can be NewMessage , StartedBot , StoppedBot and ....
- text: The text of the sent button.
- button_id: is the identifier you set for the button.
- message_id: The unique identifier assigned to the message.
- chat_id: Unique identifier for the conversation between the user and the bot (you must continue to use this identifier.)
Usage
from rubika_bot.requests import get_me
from rubika_bot.models import Bot
bot: Bot = get_me(token=...)
from rubika_bot.requests import send_message
from rubika_bot.models import Keypad, KeypadRow, Button
b1 = Button(id='100', type='Simple', button_text='Add Account')
b2 = Button(id='101', type='Simple', button_text='Edit Account')
b3 = Button(id='102', type='Simple', button_text='Remove Account')
keypad = Keypad(
rows=[
KeypadRow(buttons=[b1]),
KeypadRow(buttons=[b2, b3])
],
resize_keyboard=True,
on_time_keyboard=False
)
send_message(
token=...,
chat_id=...,
text='Welcome',
chat_keypad_type='New',
chat_keypad=keypad
)
from rubika_bot.requests import send_message
from rubika_bot.models import Keypad, KeypadRow, Button
b1 = Button(id='100', type='Simple', button_text='Add Account')
b2 = Button(id='101', type='Simple', button_text='Edit Account')
b3 = Button(id='102', type='Simple', button_text='Remove Account')
keypad = Keypad(
rows=[
KeypadRow(buttons=[b1]),
KeypadRow(buttons=[b2, b3])
],
)
send_message(
token=...,
chat_id=...,
text='Welcome',
inline_keypad=keypad
)
from rubika_bot.requests import send_message
send_message(
token=...,
chat_id=...,
text='Hello World',
)
from rubika_bot.requests import send_poll
send_poll(
token=...,
chat_id=...,
question='Do you have any question?',
options=['yes', 'no']
)
from rubika_bot.requests import send_location
send_location(
token=...,
chat_id=...,
latitude='35.759662741892626',
longitude='51.4036344416759'
)
from rubika_bot.requests import send_contact
send_contact(
token=...,
chat_id=...,
first_name='Ali',
last_name='Rn',
phone_number='09038754321'
)
from rubika_bot.requests import get_chat
from rubika_bot.models import Chat
chat: Chat = get_chat(
token=...,
chat_id=...,
)
from rubika_bot.requests import get_updates
from rubika_bot.models import Update
updates, _ = get_updates(
token=...,
limit=10,
)
from rubika_bot.requests import forward_message
forward_message(
token=...,
from_chat_id=...,
message_id=...,
to_chat_id=...
)
from rubika_bot.requests import edit_message_text
edit_message_text(
token=...,
chat_id=...,
message_id=...,
text='New Message Text'
)
from rubika_bot.requests import edit_message_keypad
from rubika_bot.models import Button, Keypad, KeypadRow
b1 = Button(id='100', type='Simple', button_text='Add Account')
b2 = Button(id='101', type='Simple', button_text='Edit Account')
b3 = Button(id='102', type='Simple', button_text='Remove Account')
new_keypad = Keypad(
rows=[
KeypadRow(buttons=[b1]),
KeypadRow(buttons=[b2, b3])
],
)
edit_message_keypad(
token=...,
chat_id=...,
message_id=...,
inline_keypad=new_keypad
)
from rubika_bot.requests import delete_message
delete_message(
token=...,
chat_id=...,
message_id=...,
)
TODO:
- Change the required python version from 3.10 to 3.8
Release files for rubika-bot 1.0.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rubika-bot-1.0.19.tar.gz | 8.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rubika_bot-1.0.19-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.4 kB
Release files / rubika-bot-1.0.19.tar.gz
| Download URL | rubika-bot-1.0.19.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a541803205e89a29363c266ed6a5e55151e44f684d69011611844d593904e945
|
|
BLAKE2b-256 checksum How to use checksums |
15d49deb00f8e76f30bbd2f421e9e55e72bc85e279a1bde01d2bc51e9651ad57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.10
|
Release files / rubika_bot-1.0.19-py3-none-any.whl
| Download URL | rubika_bot-1.0.19-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f961a727b758dabe7d3865136ca0814322d1a87b6631a655b712d4fbb64f28d0
|
|
BLAKE2b-256 checksum How to use checksums |
5cd5e08c6e3f748bc27456ef6218b1124a8bcccec820c59374fd5a4ec2da0afa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.10
|