1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//! # Write a telegram bot in Rust //! //! This library allows you to write a Telegram Bot in Rust. It's an almost complete wrapper for the Telegram Bot API and uses hyper to send a request to the Telegram server. Each Telegram function call returns a future and carries the actual bot and the answer. //! You can find all available functions in src/functions.rs. The crate telebot-derive implements all //! required getter, setter and send functions automatically. //! //! # Example usage //! //! ``` //! extern crate telebot; //! extern crate tokio_core; //! extern crate futures; //! use telebot::bot; //! use tokio_core::reactor::Core; //! use futures::stream::Stream; //! use futures::Future; //! use std::fs::File; //! //! // import all available functions //! use telebot::functions::*; //! //! fn main() { //! // create a new event loop //! let mut lp = Core::new().unwrap(); //! //! // init the bot with the bot key and an update interval of 200ms //! let bot = bot::RcBot::new(lp.handle(), "<TELEGRAM-BOT-TOKEN>") //! .update_interval(200); //! //! // register a new command "reply" which replies all received messages //! let handle = bot.new_cmd("/reply") //! .and_then(|(bot, msg)| { //! let mut text = msg.text.unwrap().clone(); //! //! // when the text is empty send a dummy text //! if text.is_empty() { //! text = "<empty>".into(); //! } //! //! // construct a message and return a new future which will be resolved by tokio //! bot.message(msg.chat.id, text).send() //! }); //! //! // register the new command //! bot.register(handle); //! //! // start the event loop //! bot.run(&mut lp).unwrap(); //! } //! ``` #![feature(custom_attribute)] #![feature(try_from)] #![allow(unused_attributes)] #[macro_use] extern crate telebot_derive; #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; extern crate erased_serde; extern crate futures; extern crate hyper; extern crate hyper_multipart_rfc7578 as hyper_multipart; extern crate hyper_tls; extern crate native_tls; extern crate serde; extern crate serde_json; extern crate tokio_core; extern crate uuid; #[macro_use] extern crate failure; pub use bot::RcBot; //pub use error::Error; pub use file::File; pub mod bot; pub mod error; pub mod objects; pub mod functions; pub mod file;