Telegram bot api client. Under development.
Example bot that will resend all text and voice messages to sender.
``` rust extern crate relegram; extern crate hyper;
use relegram::api::{BotApiClient, HttpClient}; use hyper::rt::{Future, Stream}; use std::time::Duration; use relegram::requests::; use relegram::responses::;
fn main() { let botclient = BotApiClient::new(HttpClient::Default, String::from("YOUR TOKEN")); let getupdates = GetUpdatesRequest { timeout: Some(20), ..GetUpdatesRequest::new() }; let updates = botclient.incomingupdates(getupdates, Duration::fromsecs(30)) .foreach(move |x| { match x.kind { UpdateKind::Message(Message { from: MessageFrom::User { chat, .. }, kind: msg, .. }) => { let send = match msg { MessageKind::Text { text, .. } => SendMessageRequest::new(ChatId::Id(chat.id), SendMessageKind::Text(SendText::new(text))), MessageKind::Voice { voice, .. } => SendMessageRequest::new(ChatId::Id(chat.id), SendMessageKind::Voice(SendVoice::new(FileKind::FileId(voice.fileid)))), _ => return Ok(()) }; hyper::rt::spawn( botclient.sendmessage(&send, Duration::fromsecs(10)) .map(|x| println!("message sent {:?}", x)) .maperr(|x| println!("error occurred {:?}", x))); } _ => return Ok(())
};
Ok(())
})
.map_err(|x| println!("error {:?}", x));
hyper::rt::run(updates);
} ```