Tokio versions

This commit is contained in:
Max Fowler 2020-11-05 22:32:12 +01:00
commit 007dd7caa0
4 changed files with 1251 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
.env

1203
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
Cargo.toml Normal file
View File

@ -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"] }

33
src/main.rs Normal file
View File

@ -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(())
}