1use std::{env::VarError, time::Duration};
2
3use teloxide_core_ng::{adaptors::trace, prelude::*, types::ChatAction};
4
5#[tokio::main]
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 pretty_env_logger::init();
8
9 let chat_id =
10 ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
11
12 let trace_settings = match std::env::var("TRACE").as_deref() {
13 Ok("EVERYTHING_VERBOSE") => trace::Settings::TRACE_EVERYTHING_VERBOSE,
14 Ok("EVERYTHING") => trace::Settings::TRACE_EVERYTHING,
15 Ok("REQUESTS_VERBOSE") => trace::Settings::TRACE_REQUESTS_VERBOSE,
16 Ok("REQUESTS") => trace::Settings::TRACE_REQUESTS,
17 Ok("RESPONSES_VERBOSE") => trace::Settings::TRACE_RESPONSES_VERBOSE,
18 Ok("RESPONSES") => trace::Settings::TRACE_RESPONSES,
19 Ok("EMPTY") | Ok("") | Err(VarError::NotPresent) => trace::Settings::empty(),
20 Ok(_) | Err(VarError::NotUnicode(_)) => {
21 panic!(
22 "Expected `TRACE` environment variable to be equal to any of the following: \
23 `EVERYTHING_VERBOSE`, `EVERYTHING`, `REQUESTS_VERBOSE`, `REQUESTS`, \
24 `RESPONSES_VERBOSE`, `RESPONSES`, `EMPTY`, `` (empty string)"
25 )
26 }
27 };
28
29 log::info!("Trace settings: {trace_settings:?}");
30
31 let bot = if trace_settings.is_empty() {
32 Bot::from_env().erase()
33 } else {
34 Bot::from_env().trace(trace_settings).erase()
35 };
36
37 bot.send_chat_action(chat_id, ChatAction::Typing).await?;
38 tokio::time::sleep(Duration::from_secs(1)).await;
39 bot.send_message(chat_id, "Hey hey hey").await?;
40
41 Ok(())
42}