telegram-bot 0.1.0

A library for creating Telegram bots.
docs.rs failed to build telegram-bot-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: telegram-bot-0.8.0

Rust Telegram Bot Library

Build Status License

Documentation

A library for writing your own Telegram bots. More information here. Note: Work in progress!

Example

Here is a simple example (see example/simple.rs):

extern crate telegram_bot;

use telegram_bot::*;
use std::env;

fn main() {
    // Fetch environment variable with bot token
    let token = match env::var("TELEGRAM_BOT_TOKEN") {
        Ok(tok) => tok,
        Err(e) =>
            panic!("Environment variable 'TELEGRAM_BOT_TOKEN' missing! {}", e),
    };

    // Create bot, test simple API call and print bot information
    let mut bot = Bot::new(token);
    println!("getMe: {:?}", bot.get_me());

    // Fetch new updates via long poll method
    let res = bot.long_poll(None, |bot, 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 Err(Error::UserInterrupt);
                    }

                    // Answer message with "Hi"
                    try!(bot.send_message(
                        m.chat.id(),
                        format!("Hi, {}! You just wrote '{}'", name, t),
                        None, None, None));
                },
                _ => {}
            }
        }

        // If none of the "try!" statements returned an error: It's Ok!
        Ok(())
    });

    // When the method `long_poll` returns, its due to an error. Check it here.
    if let Err(e) = res {
        println!("An error occured: {}", e);
    }
}

You can find a bigger example in the examples folder.

Usage

Will be uploaded to crates.io soon...

Collaboration

Yes please! Every type of colaboration 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).

Todo

  • "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