Trait teloxide_core::requests::RequesterExt
source · pub trait RequesterExt: Requester {
// Provided methods
fn cache_me(self) -> CacheMe<Self> ⓘ
where Self: Sized { ... }
fn auto_send(self) -> AutoSend<Self> ⓘ
where Self: Sized { ... }
fn erase<'a>(self) -> ErasedRequester<'a, Self::Err> ⓘ
where Self: 'a + Sized { ... }
fn trace(self, settings: Settings) -> Trace<Self> ⓘ
where Self: Sized { ... }
fn throttle(self, limits: Limits) -> Throttle<Self> ⓘ
where Self: Sized + Clone + Send + Sync + 'static,
Self::Err: AsResponseParameters,
Self::GetChat: Send { ... }
fn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self> ⓘ
where Self: Sized { ... }
}
Expand description
Extensions methods for Requester
.
Provided Methods§
sourcefn cache_me(self) -> CacheMe<Self> ⓘwhere
Self: Sized,
fn cache_me(self) -> CacheMe<Self> ⓘwhere Self: Sized,
Available on crate feature
cache_me
only.Add get_me
caching ability, see CacheMe
for more.
sourcefn auto_send(self) -> AutoSend<Self> ⓘwhere
Self: Sized,
fn auto_send(self) -> AutoSend<Self> ⓘwhere Self: Sized,
👎Deprecated since 0.8.0:
AutoSend
is no longer required to .await
requests and is now noopAvailable on crate feature
auto_send
only.Send requests automatically, see AutoSend
for more.
sourcefn erase<'a>(self) -> ErasedRequester<'a, Self::Err> ⓘwhere
Self: 'a + Sized,
fn erase<'a>(self) -> ErasedRequester<'a, Self::Err> ⓘwhere Self: 'a + Sized,
Available on crate feature
erased
only.Erase requester type.
Examples found in repository?
examples/erased.rs (line 32)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
async fn main() -> Result<(), Box<dyn std::error::Error>> {
pretty_env_logger::init();
let chat_id =
ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
let trace_settings = match std::env::var("TRACE").as_deref() {
Ok("EVERYTHING_VERBOSE") => trace::Settings::TRACE_EVERYTHING_VERBOSE,
Ok("EVERYTHING") => trace::Settings::TRACE_EVERYTHING,
Ok("REQUESTS_VERBOSE") => trace::Settings::TRACE_REQUESTS_VERBOSE,
Ok("REQUESTS") => trace::Settings::TRACE_REQUESTS,
Ok("RESPONSES_VERBOSE") => trace::Settings::TRACE_RESPONSES_VERBOSE,
Ok("RESPONSES") => trace::Settings::TRACE_RESPONSES,
Ok("EMPTY") | Ok("") | Err(VarError::NotPresent) => trace::Settings::empty(),
Ok(_) | Err(VarError::NotUnicode(_)) => {
panic!(
"Expected `TRACE` environment variable to be equal to any of the following: \
`EVERYTHING_VERBOSE`, `EVERYTHING`, `REQUESTS_VERBOSE`, `REQUESTS`, \
`RESPONSES_VERBOSE`, `RESPONSES`, `EMPTY`, `` (empty string)"
)
}
};
log::info!("Trace settings: {:?}", trace_settings);
let bot = if trace_settings.is_empty() {
Bot::from_env().erase()
} else {
Bot::from_env().trace(trace_settings).erase()
};
bot.send_chat_action(chat_id, ChatAction::Typing).await?;
tokio::time::sleep(Duration::from_secs(1)).await;
bot.send_message(chat_id, "Hey hey hey").await?;
Ok(())
}
sourcefn trace(self, settings: Settings) -> Trace<Self> ⓘwhere
Self: Sized,
fn trace(self, settings: Settings) -> Trace<Self> ⓘwhere Self: Sized,
Available on crate feature
trace_adaptor
only.Trace requests, see Trace
for more.
Examples found in repository?
examples/erased.rs (line 34)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
async fn main() -> Result<(), Box<dyn std::error::Error>> {
pretty_env_logger::init();
let chat_id =
ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
let trace_settings = match std::env::var("TRACE").as_deref() {
Ok("EVERYTHING_VERBOSE") => trace::Settings::TRACE_EVERYTHING_VERBOSE,
Ok("EVERYTHING") => trace::Settings::TRACE_EVERYTHING,
Ok("REQUESTS_VERBOSE") => trace::Settings::TRACE_REQUESTS_VERBOSE,
Ok("REQUESTS") => trace::Settings::TRACE_REQUESTS,
Ok("RESPONSES_VERBOSE") => trace::Settings::TRACE_RESPONSES_VERBOSE,
Ok("RESPONSES") => trace::Settings::TRACE_RESPONSES,
Ok("EMPTY") | Ok("") | Err(VarError::NotPresent) => trace::Settings::empty(),
Ok(_) | Err(VarError::NotUnicode(_)) => {
panic!(
"Expected `TRACE` environment variable to be equal to any of the following: \
`EVERYTHING_VERBOSE`, `EVERYTHING`, `REQUESTS_VERBOSE`, `REQUESTS`, \
`RESPONSES_VERBOSE`, `RESPONSES`, `EMPTY`, `` (empty string)"
)
}
};
log::info!("Trace settings: {:?}", trace_settings);
let bot = if trace_settings.is_empty() {
Bot::from_env().erase()
} else {
Bot::from_env().trace(trace_settings).erase()
};
bot.send_chat_action(chat_id, ChatAction::Typing).await?;
tokio::time::sleep(Duration::from_secs(1)).await;
bot.send_message(chat_id, "Hey hey hey").await?;
Ok(())
}
sourcefn throttle(self, limits: Limits) -> Throttle<Self> ⓘwhere
Self: Sized + Clone + Send + Sync + 'static,
Self::Err: AsResponseParameters,
Self::GetChat: Send,
fn throttle(self, limits: Limits) -> Throttle<Self> ⓘwhere Self: Sized + Clone + Send + Sync + 'static, Self::Err: AsResponseParameters, Self::GetChat: Send,
Available on crate feature
throttle
only.Add throttling ability, see Throttle
for more.
Note: this spawns the worker, just as Throttle::new_spawn
.
sourcefn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self> ⓘwhere
Self: Sized,
fn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self> ⓘwhere Self: Sized,
Specifies default ParseMode
, which will be used during all calls to:
Examples found in repository?
examples/self_info.rs (line 13)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
async fn main() -> Result<(), Box<dyn std::error::Error>> {
pretty_env_logger::init();
let chat_id =
ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
let bot = Bot::from_env().parse_mode(ParseMode::MarkdownV2);
let Me { user: me, .. } = bot.get_me().await?;
bot.send_dice(chat_id).emoji(DiceEmoji::Dice).await?;
bot.send_message(chat_id, format!("Hi, my name is **{}** 👋", me.first_name)).await?;
Ok(())
}