Skip to main content

Rubika Bot Library

Project description

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 in the rest of the steps.
  • Using your desired method and token, create your URL in the following format and request POST.
https://messengerg2b1.iranlms.ir/v3/{token}/{method}
  • If you use the python language, you can also use the rubika-bot package.

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

  • Get Your Bot Information

from rubika_bot.requests import get_me
from rubika_bot.models import Bot

bot: Bot = get_me(token=...)
  • Send Start 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])
    ],
    resize_keyboard=True,
    on_time_keyboard=False
)
send_message(
    token=...,
    chat_id=...,
    text='Welcome',
    chat_keypad_type='New',
    chat_keypad=keypad
)
  • Send Inline 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
)
  • Send Message

from rubika_bot.requests import send_message

send_message(
    token=...,
    chat_id=...,
    text='Hello World',
)
  • Send Poll

from rubika_bot.requests import send_poll

send_poll(
    token=...,
    chat_id=...,
    question='Do you have any question?',
    options=['yes', 'no']
)
  • Send Location

from rubika_bot.requests import send_location

send_location(
    token=...,
    chat_id=...,
    latitude='35.759662741892626',
    longitude='51.4036344416759'
)
  • Send Sticker

from rubika_bot.requests import send_sticker

send_sticker(
    token=...,
    chat_id=...,
    sticker_id=...,
)
  • Send Sticker

from rubika_bot.requests import send_contact

send_contact(
    token=...,
    chat_id=...,
    first_name='Ali',
    last_name='Rn',
    phone_number='09038754321'
)
  • Get Chat Information

from rubika_bot.requests import get_chat
from rubika_bot.models import Chat

chat: Chat = get_chat(
    token=...,
    chat_id=...,
)   
  • Get Last 10 Updates

from rubika_bot.requests import get_updates
from rubika_bot.models import Update

updates, _ = get_updates(
    token=...,
    limit=10,
)
  • Forward Message

from rubika_bot.requests import forward_message

forward_message(
    token=...,
    from_chat_id=...,
    message_id=...,
    to_chat_id=...
)
  • Edit Message Text

from rubika_bot.requests import edit_message_text

edit_message_text(
    token=...,
    chat_id=...,
    message_id=...,
    text='New Message Text'
)
  • Edit Inline Keypad

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
)
  • Delete Message

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rubika-bot-1.0.13.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rubika_bot-1.0.13-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file rubika-bot-1.0.13.tar.gz.

File metadata

  • Download URL: rubika-bot-1.0.13.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for rubika-bot-1.0.13.tar.gz
Algorithm Hash digest
SHA256 39a089f9456a7aab3123bfd3d2f3726033baeef67ffdab829faccf027a6bfa79
MD5 b75e1da37e99537a0a673fc8a5d1f0e2
BLAKE2b-256 ecf9affa2ecf976c2394e07b778e66ba098a55f5973030bd0dba8bf2016654bb

See more details on using hashes here.

File details

Details for the file rubika_bot-1.0.13-py3-none-any.whl.

File metadata

  • Download URL: rubika_bot-1.0.13-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.10

File hashes

Hashes for rubika_bot-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a5d0c1163aef0ea94bdd9dfb11f2a10ace74ca03a2872a009c80a70f07233f5b
MD5 c429d288a96afb4f39f7a934d141f96f
BLAKE2b-256 73931067218d36a710cca32a3a0ed3efb360eff0e847fdb76e456b327e6c60e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page