A library for writing your own Telegram bots. More information here. Official API here.
This library will undergo a major rewrite in the next few months. Currently the development is stalled and many new API parts are not supported right now! If you need to write a production ready application, either wait or use another (non-Rust) library. We're sorry :(
Here is a simple example (see example/simple.rs
):
extern crate telegram_bot;
use telegram_bot::*;
fn main() {
// Create bot, test simple API call and print bot information
let api = Api::from_env("TELEGRAM_BOT_TOKEN").unwrap();
println!("getMe: {:?}", api.get_me());
let mut listener = api.listener(ListeningMethod::LongPoll(None));
// Fetch new updates via long poll method
let res = listener.listen(|u| {
// If the received update contains a message...
if let Some(m) = u.message {
let name = m.from.first_name;
// Match message type
match m.msg {
MessageType::Text(t) => {
// Print received text message to stdout
println!("<{}> {}", name, t);
if t == "/exit" {
return Ok(ListeningAction::Stop);
}
// Answer message with "Hi"
try!(api.send_message(
m.chat.id(),
format!("Hi, {}! You just wrote '{}'", name, t),
None, None, None, None));
},
_ => {}
}
}
// If none of the "try!" statements returned an error: It's Ok!
Ok(ListeningAction::Continue)
});
if let Err(e) = res {
println!("An error occured: {}", e);
}
}
You can find a bigger example in the examples
folder and run them like this:
TELEGRAM_BOT_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXxx cargo run --example features
This library is available via crates.io
. In order to use it, just add this to your Cargo.toml
:
telegram-bot = "0.4"
Yes please! Every type of contribution is welcome: Create issues, hack some code or make suggestions. If you don't know where to start, just contact me (my email is on my github profile).
Please submit pull request against the master
branch, unless all changes are just documentation fixes.
- "getMe"
- Methods without files
- "getMe"
- "sendMessage"
- "forwardMessage"
- "sendLocation"
- "sendChatAction"
- "getUserProfilePhotos"
- "getUpdates" and
long_poll
- "setWebhook" and
listen
- sending files ("sendAudio", "sendDocument", ...)
- More good documentation and examples
- Maybe think about multithreading stuff