دکمه‌ها (Buttons)

سیستم دکمه‌های تعاملی در کتابخانه روبکا — کیبورد معمولی و شیشه‌ای (Inline & Chat Keypad)

کلاس‌های سازنده
class InlineBuilder
سازنده دکمه‌های شیشه‌ای (Inline Keypad)
from rubka.button import InlineBuilder

# ساخت کیبورد شیشه‌ای
builder = InlineBuilder()
builder.row(
    InlineBuilder().button_simple(id="btn1", text="دکمه 1"),
    InlineBuilder().button_simple(id="btn2", text="دکمه 2")
).row(
    InlineBuilder().button_simple(id="btn3", text="دکمه 3")
)
keypad = builder.build()
class ChatKeypadBuilder
سازنده دکمه‌های معمولی (Chat Keypad)
from rubka.button import ChatKeypadBuilder

# ساخت کیبورد معمولی
keypad = (
    ChatKeypadBuilder()
    .row(
        ChatKeypadBuilder().button(id="one", text="button one"),
        ChatKeypadBuilder().button(id="two", text="button two")
    )
    .row(
        ChatKeypadBuilder().button(id="three", text="button three")
    )
    .build()
)
دکمه‌های ساده
button_simple(id, text)
دکمه ساده با متن ثابت
پارامترنوعتوضیحات
idstrشناسه یکتای دکمه
textstrمتن نمایشی دکمه
from rubka import Robot, Message
from rubka.button import ChatKeypadBuilder, InlineBuilder

bot = Robot("YOUR_TOKEN")

chat_keypad = (
    ChatKeypadBuilder()
    .row(
        ChatKeypadBuilder().button(id="one", text="تست")
    )
    .build()
)
inline_keypad = (
    InlineBuilder()
    .row(
        InlineBuilder().button_simple(id="one", text="تست")
    )
    .build()
)

@bot.on_message(commands=["start"])
async def start(bot: Robot, message: Message):
    await message.reply(
        "به ربات خوش آمدید",
        chat_keypad=chat_keypad,
        inline_keypad=inline_keypad
    )

@bot.on_callback('one')
async def btn_one(bot: Robot, message: Message):
    await message.answer("دکمه یک کلیک شد")


bot.run()
button(id, text)
دکمه معمولی برای ChatKeypad
ChatKeypadBuilder().button(id="one", text="button one")
دکمه‌های لینکی
button_url_link(id, text, url)
دکمه باز کردن لینک خارجی
پارامترنوعتوضیحات
idstrشناسه دکمه
textstrمتن دکمه
urlstrآدرس لینک
InlineBuilder().button_url_link(
    id="web",
    text="بازدید سایت",
    url="https://rubka.ir"
)
button_join_channel(id, text, username, ask_join=False)
دکمه عضویت در کانال
پارامترنوعتوضیحات
idstrشناسه دکمه
textstrمتن دکمه
usernamestrنام کاربری کانال (با یا بدون @)
ask_joinboolدرخواست تأیید قبل از عضویت
InlineBuilder().button_join_channel(
    id="join",
    text="عضویت در کانال",
    username="rubka_library",
    ask_join=True
)
button_open_chat(id, text, object_guid, object_type)
دکمه باز کردن چت با کاربر
InlineBuilder().button_open_chat(
    id="chat",
    text="ارسال پیام به ادمین",
    object_guid="user_guid",
    object_type="User"
)
دکمه‌های تعاملی
button_selection(id, text, selection)
دکمه انتخاب از لیست
selection = {
    "selection_id": "select1",
    "title": "انتخاب رنگ",
    "items": [
        {"text": "قرمز", "type": "TextOnly"},
        {"text": "آبی", "type": "TextOnly"}
    ],
    "is_multi_selection": False,
    "columns_count": 2
}

InlineBuilder().button_selection(
    id="color_select",
    text="انتخاب رنگ",
    selection=selection
)
button_calendar(id, title, type_, default_value, min_year, max_year)
دکمه تقویم (انتخاب تاریخ)
InlineBuilder().button_calendar(
    id="date",
    title="انتخاب تاریخ",
    type_="DatePersian",
    default_value="1403-01-01",
    min_year="1400",
    max_year="1410"
)
button_number_picker(id, title, min_value, max_value, default_value)
دکمه انتخاب عدد
InlineBuilder().button_number_picker(
    id="age",
    title="انتخاب سن",
    min_value="1",
    max_value="100",
    default_value="25"
)
button_string_picker(id, title, items, default_value)
دکمه انتخاب رشته از لیست
InlineBuilder().button_string_picker(
    id="city",
    title="انتخاب شهر",
    items=["تهران", "اصفهان", "شیراز", "مشهد"],
    default_value="تهران"
)
button_textbox(id, title, type_line, type_keypad, place_holder, default_value)
دکمه ورود متن
InlineBuilder().button_textbox(
    id="input",
    title="ورود نام",
    type_line="SingleLine",
    type_keypad="String",
    place_holder="نام خود را وارد کنید"
)
button_location(id, type_, location_image_url, default_pointer_location, default_map_location, title)
دکمه موقعیت مکانی
InlineBuilder().button_location(
    id="loc",
    type_="Picker",
    location_image_url="https://example.com/map.png",
    title="انتخاب موقعیت"
)
دکمه‌های دوربین و گالری
button_camera_image(id, title)
دکمه گرفتن عکس با دوربین
InlineBuilder().button_camera_image(id="camera_img", title="گرفتن عکس")
button_camera_video(id, title)
دکمه گرفتن ویدیو با دوربین
InlineBuilder().button_camera_video(id="camera_vid", title="گرفتن ویدیو")
button_gallery_image(id, title)
دکمه انتخاب عکس از گالری
InlineBuilder().button_gallery_image(id="gallery_img", title="انتخاب عکس")
button_gallery_video(id, title)
دکمه انتخاب ویدیو از گالری
InlineBuilder().button_gallery_video(id="gallery_vid", title="انتخاب ویدیو")
دکمه‌های فایل و صدا
button_file(id, title)
دکمه انتخاب فایل
InlineBuilder().button_file(id="file", title="انتخاب فایل")
button_audio(id, title)
دکمه انتخاب فایل صوتی
InlineBuilder().button_audio(id="audio", title="انتخاب آهنگ")
button_record_audio(id, title)
دکمه ضبط صدا
InlineBuilder().button_record_audio(id="record", title="ضبط صدا")
دکمه‌های اطلاعات کاربر
button_ask_my_phone_number(id, title)
درخواست شماره تلفن کاربر
InlineBuilder().button_ask_my_phone_number(id="phone", title="ارسال شماره")
button_ask_location(id, title)
درخواست موقعیت مکانی کاربر
InlineBuilder().button_ask_location(id="loc_req", title="ارسال موقعیت")
button_my_location(id, title)
ارسال موقعیت فعلی کاربر
InlineBuilder().button_my_location(id="my_loc", title="موقعیت من")
button_barcode(id, title)
اسکن بارکد
InlineBuilder().button_barcode(id="barcode", title="اسکن بارکد")
دکمه پرداخت
button_payment(id, title, amount, description)
دکمه پرداخت
پارامترنوعتوضیحات
idstrشناسه دکمه
titlestrعنوان دکمه
amountintمبلغ به تومان
descriptionstr | Noneتوضیحات پرداخت
InlineBuilder().button_payment(
    id="pay",
    title="پرداخت ۱۰,۰۰۰ تومان",
    amount=10000,
    description="شارژ حساب کاربری"
)
متدهای سازنده
row(*buttons)
افزودن یک ردیف جدید به کیبورد
builder.row(
    InlineBuilder().button_simple(id="btn1", text="دکمه 1"),
    InlineBuilder().button_simple(id="btn2", text="دکمه 2")
)
build()
ساخت کیبورد نهایی
keypad = builder.build()
await message.reply_inline("متن پیام", inline_keypad=keypad)
مثال کامل
نمونه کد کامل
استفاده از دکمه‌ها در یک ربات
from rubka import Robot, Message
from rubka.button import ChatKeypadBuilder, InlineBuilder

bot = Robot("YOUR_TOKEN")

# کیبورد معمولی
chat_keypad = (
    ChatKeypadBuilder()
    .row(
        ChatKeypadBuilder().button(id="one", text="دکمه یک"),
        ChatKeypadBuilder().button(id="two", text="دکمه دو")
    )
    .row(
        ChatKeypadBuilder().button(id="three", text="دکمه سه")
    )
    .build()
)

# کیبورد شیشه‌ای
inline_keypad = (
    InlineBuilder()
    .row(
        InlineBuilder().button_simple(id="info", text="اطلاعات"),
        InlineBuilder().button_ask_location(id="loc", text="لوکیشن من")
    )
    .row(
        InlineBuilder().button_ask_my_phone_number(id="phone", text="ارسال شماره")
    )
    .build()
)

@bot.on_message(commands=["start"])
async def start(bot: Robot, message: Message):
    await message.reply(
        "به ربات خوش آمدید",
        chat_keypad=chat_keypad,
        inline_keypad=inline_keypad
    )

@bot.on_callback('one')
async def btn_one(bot: Robot, message: Message):
    await message.answer("دکمه یک کلیک شد")

@bot.on_callback('info')
async def btn_info(bot: Robot, message: Message):
    await message.answer("اطلاعات ربات")

bot.run()