مستندات کامل متدها — ساخت رباتهای قدرتمند در پیامرسان روبیکا
| پارامتر | نوع | توضیحات |
|---|---|---|
| token | str | توکن ربات دریافتی از روبیکا (اجباری) |
| session_name | str | None | نام نشست برای ذخیره اطلاعات |
| auth | str | None | اوث (Authentication) |
| Key | str | None | کلید خصوصی (Private Key) |
| platform | str | پلتفرم (پیشفرض "web") |
| web_hook | str | None | آدرس وبهوک برای دریافت آپدیت |
| timeout | int | زمان تایماوت درخواستها (پیشفرض 10) |
| show_progress | bool | نمایش نوار پیشرفت آپلود/دانلود |
| raise_errors | bool | در صورت خطا استثنا پرتاب شود (پیشفرض True) |
| proxy | str | None | آدرس پروکسی (مثال: http://user:pass@host:port) |
| retries | int | تعداد دفعات تلاش مجدد (پیشفرض 2) |
| retry_delay | float | زمان استراحت بین تلاش مجدد (پیشفرض 0.5 ثانیه) |
| user_agent | str | None | اطلاعات مرورگر درخواستدهنده |
| safeSendMode | bool | حالت ارسال ایمن (اجرای ترتیبی دستورات) |
| max_cache_size | int | حداکثر اندازه کش برای پیامها (پیشفرض 2000) |
| max_msg_age | int | حداکثر عمر پیام در صف (به ثانیه، پیشفرض 60) |
| chunk_size | int | سایز تکههای آپلود (پیشفرض 64KB) |
| parse_mode | Literal["HTML", "Markdown"] | None | حالت پارس کردن متن (پیشفرض "Markdown") |
| api_endpoint | Literal["botapi", "messenger"] | نقطه پایانی API (پیشفرض "botapi") |
| target_language | str | None | زبان هدف (پیشفرض "en") |
| save_interval_offset_id | int | None | فاصله ذخیرهسازی offset_id (پیشفرض 120) |
| enable_offset | bool | None | فعالسازی offset (پیشفرض False) |
| show_logger | bool | None | نمایش لاگر (پیشفرض False) |
| None | شیء Robot ساخته میشود |
from rubka import Robot
bot = Robot(
token="YOUR_TOKEN",
session_name="my_session",
timeout=15,
show_progress=True,
retries=3,
safeSendMode=True,
parse_mode="HTML",
api_endpoint="botapi"
)| — | ندارد |
| dict | شامل id، username، first_name، last_name، is_bot |
me = await bot.get_me() print(me['username'])
| پارامتر | نوع | توضیحات |
|---|---|---|
| debug | bool | فعالسازی حالت اشکالزدایی |
| sleep_time | float | تأخیر بین درخواستها (پیشفرض 0.1) |
| allowed_update_types | list[str] | None | فیلتر نوع آپدیت (مثل NewMessage) |
| process_in_background | bool | پردازش در پسزمینه با صف |
| None | ربات تا زمان قطع اجرا میشود |
await bot.run(debug=True, sleep_time=0.05)
| پارامتر | نوع | توضیحات |
|---|---|---|
| chat_id | str | شناسه چت |
| text | str | متن پیام |
| inline_keypad | dict | None | دکمههای شیشهای |
| chat_keypad | dict | None | دکمه های کیبوردی |
| reply_to_message_id | str | None | پاسخ به پیام مشخص |
| disable_notification | bool | غیرفعال کردن اعلان |
| str | شناسه پیام ارسالشده |
from rubka import Robot,Message
from rubka.button import ChatKeypadBuilder,InlineBuilder
bot = Robot(
"token",
#web_hook="https://....." #برای دریافت اپدیت های اینلاین نیاز به وبهوک هست
)
#دکمه کیبورد
chat_keypad = (
ChatKeypadBuilder()
.row(
ChatKeypadBuilder().button(id="one", text="button one"),
ChatKeypadBuilder().button(id="two", text="button two")
)
.row( #برای اضافه شدن یه ردیف جدید باید row کنید
ChatKeypadBuilder().button(id="three", text="button three")
)
.build()
)
#دکمه اینلاین (شیشه ای)
inline_keypad = (
InlineBuilder()
.row(
InlineBuilder().button_simple(id="one", text="button one"),
InlineBuilder().button_simple(id="two", text="button two")
)
.row( #برای اضافه شدن یه ردیف جدید باید row کنید
InlineBuilder().button_simple(id="three", text="button three")
)
.build()
)
@bot.on_message()
async def start(bot:Robot,message:Message):
await message.reply(
"ارسال کیبورد",
chat_keypad=chat_keypad,
)
#await bot.send_message(message.chat_id,"ارسال کیبورد",chat_keypad=chat_keypad) #مثال با سند مسیج
await message.reply(
"ارسال اینلاین",
inline_keypad=inline_keypad,
)
#await bot.send_message(message.chat_id,"ارسال اینلاین",inline_keypad=inline_keypad) #مثال با سند مسیج
@bot.on_callback('one')
async def btn_help(bot: Robot, message: Message):
await message.answer("پاسخ به دکمه یک")
@bot.on_callback('two')
async def btn_help(bot: Robot, message: Message):
await message.answer("پاسخ به دکمه دو")
@bot.on_callback('three')
async def btn_help(bot: Robot, message: Message):
await message.answer("پاسخ به دکمه سه")
bot.run()| پارامتر | نوع | توضیحات |
|---|---|---|
| chat_id | str | شناسه چت |
| path | str | Path | مسیر فایل یا URL |
| file_name | str | None | نام فایل (اختیاری) |
| caption | str | None | توضیحات |
| str | شناسه پیام |
await bot.send_file("chat_id", "document.pdf", caption="فایل پی دی اف")| chat_id | str | شناسه چت |
| path | str | مسیر عکس |
| caption | str | None | کپشن |
| str | message_id |
await bot.send_image("chat", "photo.jpg", caption="منظره زیبا")| chat_id | str |
| path | str |
| caption | str | None |
| str |
await bot.send_video("chat", "video.mp4")| chat_id | str |
| path | str |
| str |
await bot.send_voice("chat", "voice.ogg")| chat_id | str |
| path | str |
| str |
await bot.send_gif("chat", "animation.gif")| پارامتر | نوع | توضیحات |
|---|---|---|
| chat_id | str | |
| question | str | سوال |
| options | list[str] | گزینهها |
| type | Literal["Regular","Quiz"] | نوع نظرسنجی |
| correct_option_index | int | None | شاخص پاسخ صحیح (Quiz) |
| is_anonymous | bool | ناشناس بودن (پیشفرض True) |
| str | شناسه پیام نظرسنجی |
await bot.send_poll("chat", "رنگ مورد علاقه؟", ["قرمز","آبی"], type="Regular")| chat_id | str | |
| latitude | str | عرض جغرافیایی |
| longitude | str | طول جغرافیایی |
| str | message_id |
await bot.send_location("chat", "35.6892", "51.3890")| chat_id | str |
| first_name | str |
| last_name | str |
| phone_number | str |
| str |
await bot.send_contact("chat", "علی", "رضایی", "09123456789")| chat_id | str | |
| title_button | str | list | متن دکمه یا لیست دکمهها |
| url | str | list | لینک یا لیست لینکها |
| text | str | متن پیام |
| dict | اطلاعات پیام |
await bot.send_button_link("chat", "گوگل", "https://google.com", "کلیک کنید")| chat_id | str |
| message_id | str |
| text | str |
| bool | موفقیت |
await bot.edit_message_text("chat", "msg_id", "متن جدید")| chat_id | str | |
| message_id | str | |
| inline_keypad | dict | کیبورد جدید |
| text | str | None | متن جدید (اختیاری) |
| bool |
await bot.edit_inline_keypad("chat", "msg_id", new_keypad)| chat_id | str |
| message_id | str |
| dict |
await bot.delete_message("chat", "msg_id")| from_chat_id | str |
| message_id | str |
| to_chat_id | str |
| str | شناسه پیام جدید |
await bot.forward_message("from_chat", "msg_id", "to_chat")| to_chat_id | str | |
| message_id | str | پیام اصلی (اختیاری) |
| str | message_id جدید |
await message.copy_message("target_chat")| chat_id | str |
| message_id | str |
| dict |
await bot.pin_chat_message("group", "msg_id")| chat_id | str |
| message_id | str |
| dict |
await bot.unpin_chat_message("group", "msg_id")| chat_id | str |
| Chat | شیء حاوی اطلاعات چت |
chat = await bot.get_chat("chat_id")
print(chat.title)| dict | شامل title، type، description، members_count |
info = await bot.get_chat_info("channel_id")| list[dict] | لیست مدیران |
admins = await bot.get_chat_admins("group_id")| dict | لیست اعضا |
members = await bot.get_chat_members("group", start_id="...")| chat_id | str | |
| title | str | عنوان جدید |
| dict |
await bot.set_chat_title("group", "عنوان جدید")| chat_id | str |
| description | str |
| dict |
await bot.set_chat_description("group", "توضیحات جدید")| chat_id | str |
| user_id | str |
| dict |
await bot.ban_member_chat("group", "user_id")| chat_id | str |
| user_id | str |
| dict |
await bot.unban_chat_member("group", "user_id")| channel_guid | str |
| search_text | str | None |
| just_get_guids | bool |
| list | لیست اعضا یا لیست guidها |
members = await bot.get_all_member("channel_id", just_get_guids=True)| channel_guid | str |
| chat_id | str |
| bool |
is_joined = await bot.check_join("channel", "user_id")| chat_id | str |
| str | None |
username = await bot.get_username("chat_id")| chat_id | str |
| str |
name = await bot.get_name("user_id")| save_as | str | None | مسیر ذخیره (اختیاری) |
| str | لینک آواتار |
url = await bot.get_avatar_me(save_as="avatar.png")
| پارامتر | نوع | توضیحات |
|---|---|---|
| chat_id | str | شناسه چت |
| message_id | str | شناسه پیام |
| dict | اطلاعات کامل پیام (متن، فرستنده، زمان، نوع رسانه و...) |
msg_data = await bot.get_message("chat_id", "message_id")
print(msg_data['text'])| پارامتر | نوع | توضیحات |
|---|---|---|
| chat_id | str | شناسه چت |
| photo_path | str | مسیر فایل تصویر جدید |
| dict | نتیجه عملیات |
await bot.set_chat_photo("group_id", "new_photo.jpg")| پارامتر | نوع | توضیحات |
|---|---|---|
| filters | callable | None | تابع فیلتر سفارشی |
| commands | list[str] | None | لیست دستورات |
| Message | شیء پیام |
@bot.on_message_reply()
async def reply_handler(bot, message):
await message.reply("شما به پیام دیگری پاسخ دادید")| پارامتر | نوع | توضیحات |
|---|---|---|
| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_media()
async def media_handler(bot, message):
await message.reply("رسانه دریافت شد 📷")| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_sticker()
async def sticker_handler(bot, message):
await message.reply("استیکر قشنگی بود 😊")| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_contact()
async def contact_handler(bot, message):
await message.reply("مخاطب دریافت شد 👤")| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_location()
async def location_handler(bot, message):
await message.reply("موقعیت دریافت شد 📍")| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_poll()
async def poll_handler(bot, message):
await message.reply("نظرسنجی جدید دریافت شد 📊")| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_forwarded()
async def forwarded_handler(bot, message):
await message.reply("این پیام فوروارد شده است 🔁")| پارامتر | نوع | توضیحات |
|---|---|---|
| filters | callable | None | تابع فیلتر سفارشی |
| commands | list[str] | None | لیست دستورات |
| Message | شیء پیام |
@bot.on_message_text(commands=["help"])
async def help_command(bot, message):
await message.reply("راهنمای ربات...")| filters | callable | None | تابع فیلتر سفارشی |
| Message | شیء پیام |
@bot.on_message_file()
async def file_handler(bot, message):
await message.reply("فایل دریافت شد 📁")| media_type | Literal["File","Image","Voice","Music","Gif","Video"] |
| str | لینک آپلود |
upload_url = await bot.get_upload_url("Image")| upload_url | str |
| name | str |
| path | str | Path |
| str | file_id |
file_id = await bot.upload_media_file(url, "photo.jpg", "local.jpg")
| file_id | str |
| save_as | str |
| chunk_size | int |
| str | مسیر ذخیره شده |
await bot.download("file_id", "downloaded.pdf")| file_id | str |
| str |
link = await bot.get_url_file("file_id")| chat_id | str |
| message_id | str |
| dict |
await bot.close_poll("chat", "poll_msg_id")| commands | list[dict] | لیست دستورات با کلیدهای command و description |
| bool |
await bot.set_commands([{"command":"start","description":"شروع"}])| offset_id | str | None |
| limit | int | None |
| list[dict] |
updates = await bot.update_webhook(limit=10)
| offset_id | str | None |
| limit | int | None |
| dict |
updates = await bot.get_updates(limit=5)
| chat_id | str |
| str | لینک دعوت |
link = await bot.export_chat_invite_link("group")| chat_id | str |
| link | str |
| dict |
await bot.revoke_chat_invite_link("group", "https://rubika.ir/...")| chat_ids | list[str] |
| text | str |
| concurrency | int |
| dict[str, dict] |
results = await bot.send_bulk_message(["id1","id2"], "متن گروهی")
| chat_id | str |
| message_ids | list[str] |
| list |
await bot.delete_bulk_message("chat", ["msg1","msg2"])| chat_id | str | |
| messages | dict[str, str] | کلید: message_id، مقدار: متن جدید |
| list |
await bot.edit_bulk_message("chat", {"msg1":"متن جدید"})| chat_id | str | |
| message_id | str | |
| delay | int | تأخیر به ثانیه |
| asyncio.Task |
task = await bot.delete_after("chat", "msg_id", delay=10)| chat_id | str |
| message_id | str |
| text | str |
| delay | int |
| asyncio.Task |
await bot.edit_after("chat", "msg_id", "جدید", delay=5)| chat_id | str |
| text | str |
| delay | int |
| dict |
await bot.send_scheduled_message("chat", "پیام بعد 20 ثانیه", delay=20)| chat_id | str |
| message_id | str |
| text | str |
| dict |
await bot.disable_inline_keyboard("chat", "msg_id", text="غیرفعال شد")| — |
| None |
await bot.close()
| filters | callable | None |
| commands | list[str] | None |
| Message |
@bot.on_message(commands=["start"])
async def start(bot, message):
await message.reply("شروع شد")| button_id | str | None | فیلتر بر اساس آیدی دکمه |
| InlineMessage |
@bot.on_callback(button_id="info")
async def info_callback(query):
await query.answer("اطلاعات محصول")| filters | callable | None |
| commands | list[str] | None |
| Message |
@bot.on_edited_message()
async def edited(bot, msg):
await msg.reply("ویرایش شد")| chat_id | str | list | None |
| commands | list[str] | None |
| allow_files | bool |
| contains | str | None |
| Message |
@bot.on_message_private(contains="سلام")
async def hello_private(bot, msg):
await msg.reply("سلام کاربر عزیز")| allow_forwarded | bool |
| min_text_length | int | None |
| Message |
@bot.on_message_group(allow_stickers=False)
async def group_handler(bot, msg):
await msg.reply("پیام گروهی")| chat_id | str | list | None |
| commands | list[str] | None |
| Message |
@bot.on_message_channel(contains="اطلاعیه")
async def announce(bot, msg):
print("اطلاعیه جدید:", msg.text)| func | callable | تابع هندلر |
| None |
bot.remove_handler(my_handler_function)