| Crates.io | rust_rubka |
| lib.rs | rust_rubka |
| version | 0.1.0 |
| created_at | 2025-12-17 22:29:37.569105+00 |
| updated_at | 2025-12-17 22:29:37.569105+00 |
| description | A Rust library for interacting with Rubika Bot API |
| homepage | |
| repository | https://github.com/AmirrezaJalilian/RustRubka |
| max_upload_size | |
| id | 1991234 |
| size | 109,726 |
A Rust library for interacting with the Rubika Bot API. This is a Rust port of the Python rubka library.
Add this to your Cargo.toml:
[dependencies]
rust_rubka = { version = "0.1.0", path = "." }
Or from crates.io (when published):
[dependencies]
rust_rubka = "0.1.0"
use rust_rubka::{Robot, Message};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let bot = Arc::new(Robot::new(
"YOUR_TOKEN_HERE".to_string(),
None,
None,
None,
None,
None,
));
let bot_clone = bot.clone();
bot.on_message(None, Some(vec!["start".to_string()]), move |bot, msg| {
let bot = bot.clone();
let msg = msg.clone();
tokio::spawn(async move {
let _ = msg.reply("سلام! خوش آمدید!").await;
});
});
bot.run().await?;
Ok(())
}
You can handle incoming text messages using on_message():
use rust_rubka::{Robot, Message};
use std::sync::Arc;
let bot = Arc::new(Robot::new("TOKEN".to_string(), None, None, None, None, None));
bot.on_message(None, Some(vec!["hello".to_string()]), move |bot, msg| {
let bot = bot.clone();
let msg = msg.clone();
tokio::spawn(async move {
let _ = msg.reply("سلام کاربر عزیز 👋").await;
});
});
use rust_rubka::{Robot, Message, ChatKeypadBuilder};
use std::sync::Arc;
let bot = Arc::new(Robot::new("TOKEN".to_string(), None, None, None, None, None));
let bot_clone = bot.clone();
bot.on_message(None, Some(vec!["gender".to_string()]), move |bot, msg| {
let bot = bot.clone();
let msg = msg.clone();
tokio::spawn(async move {
let builder = ChatKeypadBuilder::new();
let btn1 = builder.button("male", "👨 مرد", None);
let btn2 = builder.button("female", "👩 زن", None);
let keypad = builder.row(&[btn1, btn2]).build(None, None);
let _ = msg.reply_keypad("جنسیت خود را انتخاب کنید:", &keypad).await;
});
});
let bot_clone2 = bot.clone();
bot.on_callback(Some("male".to_string()), move |bot, msg| {
let msg = msg.clone();
tokio::spawn(async move {
let _ = msg.reply("شما مرد هستید").await;
});
});
let bot_clone3 = bot.clone();
bot.on_callback(Some("female".to_string()), move |bot, msg| {
let msg = msg.clone();
tokio::spawn(async move {
let _ = msg.reply("شما زن هستید").await;
});
});
use rust_rubka::InlineBuilder;
let builder = InlineBuilder::new();
let btn = builder.button_simple("info", "اطلاعات");
let inline_keypad = builder.row(&[btn]).build();
| Method | Description |
|---|---|
get_chat(chat_id) |
Get chat information |
get_name(chat_id) |
Get user name |
get_username(chat_id) |
Get username |
send_message(...) |
Send text message |
edit_message_text(...) |
Edit message |
delete_message(...) |
Delete message |
send_location(...) |
Send location |
send_poll(...) |
Send poll |
send_contact(...) |
Send contact |
forward_message(...) |
Forward message |
Supported inline button types include:
SimplePaymentCalendarLocationCameraImage, CameraVideoGalleryImage, GalleryVideoFile, Audio, RecordAudioMyPhoneNumber, MyLocationTextbox, Barcode, Linkuse rust_rubka::ChatKeypadBuilder;
let builder = ChatKeypadBuilder::new();
let btn1 = builder.button("play", "🎮 بازی کن", None);
let btn2 = builder.button("exit", "❌ خروج", None);
let keypad = builder.row(&[btn1, btn2]).build(None, None);
use serde_json::json;
let commands = vec![
json!({"command": "start", "description": "شروع"}),
json!({"command": "help", "description": "راهنما"}),
];
let _ = bot.set_commands(&commands).await;
Bot updates are handled using get_updates() and offset_id is managed internally in the run() method.
update_bot_endpoint() – Set webhook or pollingremove_keypad() – Remove chat keypadedit_chat_keypad() – Edit or add chat keypadResult<T, E> instead of exceptionsArc for shared ownership of the Robot instanceThis project is licensed under the MIT License.