Skip to main content

PyRubikaBotAPI

A powerful and intuitive Python library for building Rubika bots – from simple echo bots to advanced interactive assistants.

PyPI version Python


Installation

Requires Python 3.10 or higher.

pip install PyRubikaBotAPI

To upgrade pip first:

python -m pip install --upgrade pip

Quick Start

  1. Create a bot via @BotFather and get your token.
  2. Write your first bot:
from rubibot import RubiBot

bot = RubiBot("YOUR_BOT_TOKEN")

@bot.message_handler(commands=["start"])
def start(message):
    bot.send_message(message.chat_id, "Hello! Welcome to my Rubika bot.")

bot.polling()

Run the script and your bot is live!


Core Features

Message Handlers

Handle incoming messages based on commands, content type, or custom logic. Handlers are executed in order, and only the first matching handler runs for each message.

# Handle /start and /help
@bot.message_handler(commands=["start", "help"])
def handle_commands(message):
    ...

# Handle all stickers
@bot.message_handler(content_types=["sticker"])
def sticker_handler(message):
    ...

# Catch-all for any text message
@bot.message_handler()
def echo(message):
    bot.reply_to(message, f"You said: {message.text}")

Supported content types: text, file, location, sticker, contact, poll
Supported update types: NewMessage, UpdatedMessage, RemovedMessage, StartedBot, StoppedBot


Sending Messages & Replies

  • send_message(chat_id, text, ...) – Send text (max ~4096 chars). Supports inline/chat keypads, silent notifications, reply IDs.
  • reply_to(message, text, ...) – Convenience method to reply directly to a user's message.
bot.send_message(chat_id, "Hello World!")
bot.reply_to(message, "Thanks for your message!")

Media & Files

Send photos, videos, voices, GIFs, and other files. All methods accept a file path (str) or a file-like object (BufferedReader).

Method Max Size Formats
send_photo 10 MB PNG, JPG, GIF, WEBP
send_voice – MP3
send_video 50 MB MP4
send_gif – MP4 (no sound)
send_file 50 MB Any
bot.send_photo(chat_id, "image.png", text="Check this out!")
bot.send_video(chat_id, "video.mp4", text="Watch this")

Interactive Keypads

Two types of keypads are available:

  • ChatKeypad – Persistent buttons at the bottom of the chat.
  • InlineKeypad – Buttons directly under a message.
from rubibot.types import KeypadSimpleButton, KeypadRow, InlineKeypad, ChatKeypad

# Create buttons
btn1 = KeypadSimpleButton("Option 1", "id1")
btn2 = KeypadSimpleButton("Option 2", "id2")

row = KeypadRow().add(btn1, btn2)

inline_kb = InlineKeypad().add(row)
chat_kb = ChatKeypad(resize_keyboard=True).add(row)

# Send with inline buttons
bot.send_message(chat_id, "Choose:", inline_keypad=inline_kb)

# Send with chat keypad
bot.send_message(chat_id, "Menu:", chat_keypad=chat_kb)

# Remove chat keypad
from rubibot.types import ChatKeypadRemove
bot.send_message(chat_id, "Keypad removed", chat_keypad=ChatKeypadRemove())

For advanced inputs, use KeypadCalendarButton, KeypadNumberPickerButton, KeypadStringPickerButton, KeypadLocationButton, KeypadTextboxButton. (See documentation for details.)


Polls & Contacts

from rubibot.types import ChatPoll

poll = ChatPoll("Your favorite language?")
poll.add_options("Python", "JavaScript", "Go")
bot.send_poll(chat_id, poll)

bot.send_contact(chat_id, "Ali", "Rezaei", "+989123456789")

Message Management

  • Forward: bot.forward(from_chat_id, to_chat_id, message_id)
  • Edit: bot.edit_message(chat_id, message_id, new_text="...", new_inline_keypad=...)
  • Delete: bot.delete_message(chat_id, message_id)

Bot & Chat Information

  • bot.get_me() – Get bot details (username, avatar, description, share URL).
  • bot.get_chat(chat_id) – Get chat info (title, username, type).
info = bot.get_me()
print(info.username)

chat = bot.get_chat("chat_id")
print(chat.title)

Commands Registration

from rubibot.types import BotCommand

bot.set_commands(
    BotCommand("/start", "Start the bot"),
    BotCommand("/help", "Show help menu")
)

Running the Bot

Polling (for development / testing)

bot.polling(t=1, limit=10)   # Check updates every 1 second

⚠️ Polling is not optimized for production. Use webhooks instead.

Webhooks (production)

bot.set_webhook("https://your-server.com/webhook")

Then process incoming JSON manually with process_new_updates:

from rubibot.updates import Update

# Inside your web framework endpoint:
update = Update(request.json)
bot.process_new_updates([update])

Working with Updates & Models

Message Object

When a handler is called, you receive a Message object with useful attributes: chat_id, message_id, text, sender_id, file, location, sticker, contact, poll, aux (button data), forwarded_from, etc.

@bot.message_handler()
def handler(message):
    if message.has_file():
        file_id = message.file.id
        url = bot.get_file(file_id)
        data = bot.download_file(url)
        # Save or process the file

Aux Data (Button Clicks)

When a user taps a button, message.aux.button_id gives the ID you assigned. Use it to branch logic.

Next‑Step Handlers

You can register a one‑time handler for the very next message in a specific chat or from a specific user – useful for multi‑step flows:

bot.register_next_step_message_handler_by_chat_id(chat_id, my_callback)

Complete Example

from rubibot import RubiBot
from rubibot.types import (
    Message, KeypadSimpleButton, KeypadRow,
    ChatKeypad, ChatKeypadRemove, BotCommand
)

bot = RubiBot("YOUR_TOKEN")

@bot.message_handler(commands=["start"])
def start(message: Message):
    btn = KeypadSimpleButton("Say Hello", "hello_btn")
    row = KeypadRow().add(btn)
    kb = ChatKeypad(resize_keyboard=True).add(row)

    bot.send_message(message.chat_id, "Welcome!", chat_keypad=kb)

@bot.message_handler()
def handle_all(message: Message):
    if message.aux and message.aux.button_id == "hello_btn":
        bot.reply_to(message, "Hello! Keypad removed.", chat_keypad=ChatKeypadRemove())
    else:
        bot.reply_to(message, f"You said: {message.text}")

@bot.message_handler(content_types=["file"])
def file_handler(message: Message):
    url = bot.get_file(message.file.id)
    data = bot.download_file(url)
    with open("received_file", "wb") as f:
        f.write(data)
    bot.send_message(message.chat_id, "File saved!")

if __name__ == "__main__":
    bot.set_commands(
        BotCommand("start", "Start the bot")
    )
    bot.polling()

Documentation & Community

More examples and detailed API docs are available there.


Author

Alireza Sadeghian
📧 alireza.amid110@gmail.com


License: MIT

Metadata

Release files for PyRubikaBotAPI 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyRubikaBotAPI 1.0.2
File Size Uploaded Provenance Actions
pyrubikabotapi-1.0.2.tar.gz 21.5 kB Without provenance Details for pyrubikabotapi-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyRubikaBotAPI 1.0.2
File Interpreter ABI Platform Actions
pyrubikabotapi-1.0.2-py3-none-any.whl Python 3 none any Details for pyrubikabotapi-1.0.2-py3-none-any.whl

Total release size: 44.6 kB

Release files / pyrubikabotapi-1.0.2.tar.gz

Download URL pyrubikabotapi-1.0.2.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2a60235d0b4af0ca57fe35db33d1d1bdb2f78109e5384018d886db8fa7a3548d
BLAKE2b-256 checksum
How to use checksums
f69b3bef94c7458bee5c0746608c9fcfdd02079dec1a0ef627ecc29e47e33836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / pyrubikabotapi-1.0.2-py3-none-any.whl

Download URL pyrubikabotapi-1.0.2-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a72b4f8ea3327f226f1b6a6a64a989c58f1609ed68f9ce893b2064eada8582c7
BLAKE2b-256 checksum
How to use checksums
2d01a3c2657cc01a1da71182c9d7292d7f99246c572ac0582d7e8d2aa90ddd22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for PyRubikaBotAPI 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page