Telegrambot

Build Status

A telegram bot api for rust.

Usage

toml telegrambot = "0.1"

Example

A simple example. (example/simple)

```rust use futures::future::Future;

use telegrambot::api::SendMessage; use telegrambot::TelegramBot;

fn main() { let token = env::var("TELEGRAMBOTTOKEN").unwrap(); let cfg = Config::builder(token) .proxy("http://127.0.0.1:1081") .build() .unwrap();

TelegramBot::new(cfg).unwrap() .ontext(|(api, vtm)| { let firstname = vtm.message.from.unwrap().firstname; println!("<{}>: {}", firstname, vtm.text); telegrambot::spawn( api.sendmessage(&SendMessage::new(vtm.message.chat.id(), format!("Hi, {}! You just wrote '{}'", firstname, vtm.text))) .map(|| {}) .maperr(|_| {}) ); }) .start() .unwrap(); } ```

A Command example (example/command.rs)

```rust use futures::future::Future;

use telegrambot::api::SendMessage; use telegrambot::TelegramBot;

fn main() { let token = env::var("TELEGRAMBOTTOKEN").unwrap(); let cfg = Config::builder(token) .proxy("http://127.0.0.1:1081") .build() .unwrap();

TelegramBot::new(cfg).unwrap() .oncommand("/list", |(api, vcm)| { telegrambot::spawn( api.sendmessage(&SendMessage::new(vcm.message.chat.id(), format!("Call list command"))) .map(|| {}) .maperr(|| {}) ); }) .oncommand("/page", |(api, vcm)| { telegrambot::spawn( api.sendmessage(&SendMessage::new(vcm.message.chat.id(), format!("Call page command, and arguments for this command: {:?}", vcm.args))) .map(|| {}) .maperr(|| {}) ); }) .start() .unwrap(); } ```

Support for parameter analysis. Some example:

More

More example you can see examples

Other

Thanks to telegram-rs/telegram-bot project, telegram is a modification to telegram-rs/telegram-bot