GithubHelp home page GithubHelp logo

hgrecco / telegram-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from telegram-rs/telegram-bot

0.0 2.0 2.0 14.39 MB

Rust Library for creating a Telegram Bot

License: MIT License

Shell 0.87% Rust 99.13%

telegram-bot's Introduction

Rust Telegram Bot Library

Build Status License Crates.io

Documentation

A library for writing your own Telegram bots. More information here. Official API here. Note: It's usable, but not feature complete yet.

Example

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.

Usage

This library is available via crates.io. In order to use it, just add this to your Cargo.toml:

telegram-bot = "0.4"

Collaboration

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 dev branch, unless all changes are just documentation fixes.

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

telegram-bot's People

Contributors

dns2utf8 avatar hgrecco avatar knsd avatar lukaskalbertodt avatar neuschaefer avatar rockneurotiko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.