GithubHelp home page GithubHelp logo

rockneurotiko / awesome-bot Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 1.0 8.81 MB

An awesome framework to build Telegram bots up to telegram-bot library.

Home Page: http://web.neurotiko.com/awesome-bot/awesome_bot/

License: Apache License 2.0

Shell 1.25% Rust 98.75%

awesome-bot's Introduction

Awesome Bot

Travis Crates.io

Documentation

A framework to build your own Telegram bots easily. More information here. Official API here.

This framework is based on telegram-bot library to communicate with the API.

Usage

This framework is available in crates.io. Just add this to your Cargo.toml dependencies:

[dependencies]
awesome-bot = "0.1.0"

Example

Here is a simple example (download from examples/simple.rs).

extern crate awesome_bot;

use awesome_bot::*;

fn echohandler(bot: &AwesomeBot, msg: &Message, _: String, args: Vec<String>) {
    // We can access safely because the pattern match have that argument mandatory
    let toecho = &args[1];
    let phrase = format!("Echoed: {}", toecho);
    // Send the text in a beauty way :)
    let sent = bot.answer(msg).text(&phrase).end();
    println!("{:?}", sent);
}

fn main() {
    // Create the Awesome Bot (You need TELEGRAM_BOT_TOKEN environment with the token)
    let mut bot = AwesomeBot::from_env("TELEGRAM_BOT_TOKEN");
    // Add a command, this will add the routing to that function.
    bot.command("echo (.+)", echohandler);

    // Start the bot with getUpdates
    let res = bot.simple_start();
    if let Err(e) = res {
        println!("An error occurred: {}", e);
    }
}

In the examples folder there is more code:

  • examples/simple.rs: An echo example, really simple.
  • examples/complete.rs: An example that have all (I think, probably not all, but almost all) features of awesome-bot, it's a big example ;-)

Note: To execute examples/complete.rs with all the features, you will need to add some test files that the bot will send, this files shall be: files/test.{jpg, mp3, mp4, pdf, webp} for image, audio/voice, video, document and sticker

Collaboration

All help are welcome! Open issues, open PR of code or documentation, make suggestions, tell me that my rust sucks (and why), what you want :)

You can contact me in telegram.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be triple licensed as above, without any additional terms or conditions.

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.