Crates.io | telegrambot |
lib.rs | telegrambot |
version | 0.1.3 |
source | src |
created_at | 2019-04-19 08:29:23.960606 |
updated_at | 2019-04-24 09:30:57.721019 |
description | Telegram bot api |
homepage | |
repository | https://github.com/fewensa/telegrambot |
max_upload_size | |
id | 128939 |
size | 166,803 |
A telegram bot api for rust.
telegrambot = "0.1"
use futures::future::Future;
use telegrambot::api::SendMessage;
use telegrambot::TelegramBot;
fn main() {
let token = env::var("TELEGRAM_BOT_TOKEN").unwrap();
let cfg = Config::builder(token)
.proxy("http://127.0.0.1:1081")
.build()
.unwrap();
TelegramBot::new(cfg).unwrap()
.on_text(|(api, vtm)| {
let first_name = vtm.message.from.unwrap().first_name;
println!("<{}>: {}", first_name, vtm.text);
telegrambot::spawn(
api.send_message(&SendMessage::new(vtm.message.chat.id(),
format!("Hi, {}! You just wrote '{}'", first_name, vtm.text)))
.map(|_| {})
.map_err(|_| {})
);
})
.start()
.unwrap();
}
use futures::future::Future;
use telegrambot::api::SendMessage;
use telegrambot::TelegramBot;
fn main() {
let token = env::var("TELEGRAM_BOT_TOKEN").unwrap();
let cfg = Config::builder(token)
.proxy("http://127.0.0.1:1081")
.build()
.unwrap();
TelegramBot::new(cfg).unwrap()
.on_command("/list", |(api, vcm)| {
telegrambot::spawn(
api.send_message(&SendMessage::new(vcm.message.chat.id(),
format!("Call list command")))
.map(|_| {})
.map_err(|_| {})
);
})
.on_command("/page", |(api, vcm)| {
telegrambot::spawn(
api.send_message(&SendMessage::new(vcm.message.chat.id(),
format!("Call page command, and arguments for this command: {:?}", vcm.args)))
.map(|_| {})
.map_err(|_| {})
);
})
.start()
.unwrap();
}
Support for parameter analysis. Some example:
/page 1 10
args: ["1", "10"]
/start "Just do it" 'from now on'
args: ["Just do it", "from now on"]
/run 'Just do it'
args: ["Just do it"]
More example you can see examples
Thanks to telegram-rs/telegram-bot project, telegram is a modification to telegram-rs/telegram-bot