Skip to content

RashingPro/xgram-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XGram.rs

Crates.io Version Crates.io Total Downloads Telegram API Version Badge Deps.rs Crate Dependencies (latest)

Powerful yet blazingly fast Telegram Bot API framework written in Rust, featuring advanced abstractions and Tokio-powered concurrency.

Using

Creating bot

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

Adding dependencies

[dependencies]
dotenv = "..."
pretty_env_logger = "..." # You can use whatever logger you like
tokio = { version = "...", features = ["rt-multi-thread", "macros"] }

Hello World Bot

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*

About

Powerful yet blazingly fast Telegram Bot API framework written in Rust, featuring advanced abstractions and Tokio-powered concurrency.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages