14 releases
Uses old Rust 2015
0.1.13 | Mar 27, 2019 |
---|---|
0.1.12 | Mar 3, 2019 |
0.1.11 | Feb 21, 2019 |
0.1.4 | Aug 27, 2018 |
#31 in #voice
51 downloads per month
69KB
2K
SLoC
relegram
Telegram bot api client. Under development.
Example
Example bot that will resend all text and voice messages to sender.
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 bot_client = BotApiClient::new(HttpClient::Default, String::from("YOUR TOKEN"));
let get_updates =
GetUpdatesRequest {
timeout: Some(20),
..GetUpdatesRequest::new()
};
let updates = bot_client.incoming_updates(get_updates, Duration::from_secs(30))
.for_each(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.file_id)))),
_ =>
return Ok(())
};
hyper::rt::spawn(
bot_client.send_message(&send, Duration::from_secs(10))
.map(|x| println!("message sent {:?}", x))
.map_err(|x| println!("error occurred {:?}", x)));
}
_ =>
return Ok(())
};
Ok(())
})
.map_err(|x| println!("error {:?}", x));
hyper::rt::run(updates);
}
Dependencies
~9–20MB
~268K SLoC