use std::env; use futures::StreamExt; use telegram_bot_ars::*; #[tokio::main] async fn main() -> Result<(), Error> { let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set"); let api = Api::new(token); tracing::subscriber::set_global_default( tracing_subscriber::FmtSubscriber::builder() .with_env_filter("telegram_bot_ars=trace") .finish(), ) .unwrap(); let mut stream = api.stream(); while let Some(update) = stream.next().await { let update = update?; if let Some(UpdateKind::Message(message)) = update.kind { if let MessageKind::Text { ref data, .. } = message.kind { api.send(message.text_reply(format!( "Hi, {}! You just wrote '{}'", &message.from.first_name, data ))) .await?; } } } Ok(()) }