Expand description
Contexts for update handlers.
A context is a struct that is passed to update handlers, contains data about the update, and provides methods that infer certain data from the update. For example:
use tbot::prelude::*;
let mut bot = tbot::from_env!("BOT_TOKEN").event_loop();
bot.text(|context| async move {
let reversed: String = context.text.value.chars().rev().collect();
context.send_message_in_reply(reversed).call().await.unwrap();
});Here, we set a text handler for our bot. Whenever we
get a text message, the handler is called with a reference to a Text
context that contains data about the incoming data, e.g. the text of the
message. Then we call the send_message_in_reply method on the context,
which does what its name says: sends a message in the same chat in reply to
the incoming message, inferring your bot’s token and IDs of the chat and the
message.
All contexts have one common field named bot. Through this field, you can
call any method using a Bot:
use tbot::types::chat;
const ADMIN_CHAT: chat::Id = chat::Id(0);
bot.text(|context| async move {
context
.bot
.send_message(ADMIN_CHAT, "New message!")
.call()
.await
.unwrap();
});Most contexts implement certain traits, such as Message or Pinnable.
These traits share common methods between contexts,
e.g. send_message_in_reply you have seen above.
Modules
Structs
any_update handlers.changed_auto_delete_timer handlers.chat_member handlers.chosen_inline handlers.connected_website handlers.created_group handlers.deleted_chat_photo handlers.edited_animation handlers.edited_audio handlers.text handlers.edited_document handlers.edited_location handlers.edited_photo handlers.edited_text handlers.edited_video handlers.ended_voice_chat handlers.inline_data_callback handler.inline_game_callback handler.invited_voice_chat_participants handlers.left_member handlers.message_data_callback handler.message_game_callback handler.my_chat_member handlers.new_chat_photo handlers.new_chat_title handlers.new_members handlers.pinned_message handlers.poll_answer handlers.pre_checkout handlers.proximity_alert handlers.scheduled_voice_chat handlers.started_voice_chat handlers.updated_poll handlers.video_note handlers.