teloxide-fork 0.19.0

An elegant Telegram bots framework for Rust
Documentation
use futures::StreamExt;
use teloxide::{prelude::*, types::UpdateKind};

#[tokio::main]
async fn main() -> std::io::Result<()> {
    pretty_env_logger::init();
    let bot = Bot::from_env();
    let mut updates = bot.update_stream().build().await;
    let mut ctrl_c = std::pin::pin!(tokio::signal::ctrl_c());
    let mut stopping = false;

    loop {
        tokio::select! {
            item = updates.next() => match item {
                Some(Ok(update)) => {
                    if let UpdateKind::Message(message) = update.kind {
                        if let Some(text) = message.text() {
                            bot.send_message(text).chat_id(message.chat.id).await.log_on_error().await;
                        }
                    }
                }
                Some(Err(error)) => log::error!("Could not receive update: {error}"),
                None => break,
            },
            signal = &mut ctrl_c, if !stopping => {
                signal?;
                updates.shutdown();
                stopping = true;
            }
        }
    }

    Ok(())
}