Tokio versions
This commit is contained in:
commit
007dd7caa0
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
.env
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "wgbot"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Max Fowler <maxhfowler@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
telegram-bot = "0.7"
|
||||||
|
dotenv = "0.15.0"
|
||||||
|
futures = "0.3.7"
|
||||||
|
tokio = { version = "0.2", features = ["macros", "time", "fs"] }
|
|
@ -0,0 +1,33 @@
|
||||||
|
use std::env;
|
||||||
|
use dotenv;
|
||||||
|
|
||||||
|
use futures::StreamExt;
|
||||||
|
use telegram_bot::*;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Error> {
|
||||||
|
dotenv::dotenv().ok();
|
||||||
|
let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
|
||||||
|
let api = Api::new(token);
|
||||||
|
|
||||||
|
// Fetch new updates via long poll method
|
||||||
|
let mut stream = api.stream();
|
||||||
|
while let Some(update) = stream.next().await {
|
||||||
|
// If the received update contains a new message...
|
||||||
|
let update = update?;
|
||||||
|
if let UpdateKind::Message(message) = update.kind {
|
||||||
|
if let MessageKind::Text { ref data, .. } = message.kind {
|
||||||
|
// Print received text message to stdout.
|
||||||
|
println!("<{}>: {}", &message.from.first_name, data);
|
||||||
|
|
||||||
|
// Answer message with "Hi".
|
||||||
|
api.send(message.text_reply(format!(
|
||||||
|
"Hi, {}! You just wrote '{}'",
|
||||||
|
&message.from.first_name, data
|
||||||
|
)))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue