Powerful yet blazingly fast Telegram Bot API framework written in Rust, featuring advanced abstractions and Tokio-powered concurrency.
Open chat with @BotFather in Telegram.
Create a bot with /newbot command.
In the end, you will receive token - a string like that 1234567890:ABCdefGH-AbCd318_someRandom.
Don't share the token with anybody (token is like a password to control bot), don't store it directly in code and don't
commit to VCS.
Instead, create .env file and put it there:
TOKEN=1234567890:ABCdefGH-AbCd318_someRandom[dependencies]
dotenv = "..."
pretty_env_logger = "..." # You can use whatever logger you like
tokio = { version = "...", features = ["rt-multi-thread", "macros"] }use std::pin::Pin;
use xgram::bot::Bot;
use xgram::command::context::CommandContext;
use xgram::proc::command_handler;
use xgram::utils::config::GlobalConfig;
#[tokio::main]
async fn main() {
pretty_env_logger::init();
dotenv::dotenv().unwrap();
let token = std::env::var("TOKEN").unwrap();
let config = GlobalConfig {
..Default::default()
};
let mut bot = Bot::new(token, config);
bot.register_command(String::from("start"), Box::new(command_start));
bot.run().await
}
#[command_handler]
async fn command_start(ctx: CommandContext) {
ctx.reply(String::from("Hello XGram.rs World!")).await.unwrap();
}Run your bot and try sending /start command.
Complete documentation available here: *crickets sound*