pub struct EventLoop { /* private fields */ }
Expand description
Provides an event loop for handling Telegram updates.
With EventLoop
, you can configure handlers and start listening to updates
via either polling or webhook.
let mut bot = tbot::from_env!("BOT_TOKEN").event_loop();
bot.text(|_| async { println!("Got a text message") });
bot.polling().start();
tbot
has many update handlers, such as text
you have seen
in the example. You can find all of them below on this page.
Implementations§
Source§impl EventLoop
impl EventLoop
Sourcepub fn into_stateful<S>(self, state: S) -> StatefulEventLoop<S>
pub fn into_stateful<S>(self, state: S) -> StatefulEventLoop<S>
Turns this event loop into a stateful one. Handlers added on this event loop are kept.
Sourcepub fn username(&mut self, username: String)
pub fn username(&mut self, username: String)
Sets the bot’s username.
The username is used when checking if a command such as
/command@username
was directed to the bot.
Sourcepub fn webhook(self, url: &str, port: u16) -> Webhook<'_>
pub fn webhook(self, url: &str, port: u16) -> Webhook<'_>
Starts webhook configuration.
See our wiki to learn how to use webhook with tbot
.
Sourcepub fn command<H, F>(&mut self, command: &'static str, handler: H)
pub fn command<H, F>(&mut self, command: &'static str, handler: H)
Adds a new handler for a command.
Note that commands such as /command@username
will be completely
ignored unless you configure the event loop with your bot’s username
with either username
or fetch_username
.
Sourcepub fn command_if<H, HF, P, PF>(
&mut self,
command: &'static str,
predicate: P,
handler: H,
)
pub fn command_if<H, HF, P, PF>( &mut self, command: &'static str, predicate: P, handler: H, )
Adds a new handler for a command which is run if the predicate returns true.
Note that commands such as /command@username
will be completely
ignored unless you configure the event loop with your bot’s username
with either username
or fetch_username
.
Sourcepub fn commands<Cm, H, F>(&mut self, commands: Cm, handler: H)
pub fn commands<Cm, H, F>(&mut self, commands: Cm, handler: H)
Adds a new handler for a sequence of commands.
Note that commands such as /command@username
will be completely
ignored unless you configure the event loop with your bot’s username
with either username
or fetch_username
.
Sourcepub fn commands_if<Cm, H, HF, P, PF>(
&mut self,
commands: Cm,
predicate: P,
handler: H,
)
pub fn commands_if<Cm, H, HF, P, PF>( &mut self, commands: Cm, predicate: P, handler: H, )
Adds a new handler for a sequence of commands which is run if the predicate returns true.
Note that commands such as /command@username
will be completely
ignored unless you configure the event loop with your bot’s username
with either username
or fetch_username
.
Sourcepub fn start_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn start_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for the /start
command which is run
if the predicate returns true.
Sourcepub fn settings_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn settings_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for the /settings
command which is run
if the predicate returns true.
Sourcepub fn help_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn help_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for the /help
command which is run if the predicate
returns true.
Sourcepub fn edited_command<H, F>(&mut self, command: &'static str, handler: H)
pub fn edited_command<H, F>(&mut self, command: &'static str, handler: H)
Adds a new handler for an edited command.
Sourcepub fn edited_command_if<H, HF, P, PF>(
&mut self,
command: &'static str,
predicate: P,
handler: H,
)
pub fn edited_command_if<H, HF, P, PF>( &mut self, command: &'static str, predicate: P, handler: H, )
Adds a new handler for an edited command which is run if the predicate returns true.
Sourcepub fn edited_commands<Cm, H, F>(&mut self, commands: Cm, handler: H)
pub fn edited_commands<Cm, H, F>(&mut self, commands: Cm, handler: H)
Adds a new handler for an edited command from sequence of commands.
Sourcepub fn edited_commands_if<Cm, H, HF, P, PF>(
&mut self,
commands: Cm,
predicate: P,
handler: H,
)
pub fn edited_commands_if<Cm, H, HF, P, PF>( &mut self, commands: Cm, predicate: P, handler: H, )
Adds a new handler for a sequence of edited commands which is run if the predicate returns true.
Sourcepub fn after_update<H, F>(&mut self, handler: H)
pub fn after_update<H, F>(&mut self, handler: H)
Adds a new handler which is run after handling an update.
Sourcepub fn after_update_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn after_update_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler which is run after handling an update and if the predicate returns true.
Sourcepub fn animation_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn animation_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for animations which is run if the predicate returns true.
Sourcepub fn audio_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn audio_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for audio which is run if the predicate returns true.
Sourcepub fn before_update<H, F>(&mut self, handler: H)
pub fn before_update<H, F>(&mut self, handler: H)
Adds a new handler which is run before handling an update.
Sourcepub fn before_update_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn before_update_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler which is run before handling an update and if the predicate returns true.
Sourcepub fn chosen_inline<H, F>(&mut self, handler: H)
pub fn chosen_inline<H, F>(&mut self, handler: H)
Adds a new handler for chosen inline results.
Sourcepub fn chosen_inline_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn chosen_inline_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for chosen inline results which is run if the predicate returns true.
Sourcepub fn contact_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn contact_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for contacts which is run if the predicate returns true.
Sourcepub fn connected_website<H, F>(&mut self, handler: H)
pub fn connected_website<H, F>(&mut self, handler: H)
Adds a new handler for connected websites.
Sourcepub fn connected_website_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn connected_website_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for connected websites which is run if the predicate returns true.
Sourcepub fn created_group<H, F>(&mut self, handler: H)
pub fn created_group<H, F>(&mut self, handler: H)
Adds a new handler for created groups.
Sourcepub fn created_group_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn created_group_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for created groups which is run if the predicate returns true.
Sourcepub fn data_callback<H, F>(&mut self, handler: H)
pub fn data_callback<H, F>(&mut self, handler: H)
Adds a new handler for data callbacks.
Sourcepub fn data_callback_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn data_callback_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for data callbacks which is run if the predicate returns true.
Sourcepub fn deleted_chat_photo<H, F>(&mut self, handler: H)
pub fn deleted_chat_photo<H, F>(&mut self, handler: H)
Adds a new handler for deleted chat photos.
Sourcepub fn deleted_chat_photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn deleted_chat_photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for deleted chat photos which is run if the predicate returns true.
Sourcepub fn dice_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn dice_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for dice which is run if the predicate returns true.
Sourcepub fn document_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn document_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for documents which is run if the predicate returns true.
Sourcepub fn edited_animation<H, F>(&mut self, handler: H)
pub fn edited_animation<H, F>(&mut self, handler: H)
Adds a new handler for edited animations.
Sourcepub fn edited_animation_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_animation_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited animations which is run if the predicate returns true.
Sourcepub fn edited_audio<H, F>(&mut self, handler: H)
pub fn edited_audio<H, F>(&mut self, handler: H)
Adds a new handler for edited audio.
Sourcepub fn edited_audio_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_audio_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited audio which is run if the predicate returns true.
Sourcepub fn edited_document<H, F>(&mut self, handler: H)
pub fn edited_document<H, F>(&mut self, handler: H)
Adds a new handler for edited documents.
Sourcepub fn edited_document_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_document_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited documents which is run if the predicate returns true.
Sourcepub fn edited_location<H, F>(&mut self, handler: H)
pub fn edited_location<H, F>(&mut self, handler: H)
Adds a new handler for edited locations.
Sourcepub fn edited_location_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_location_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited locations which is run if the predicate returns true.
Sourcepub fn edited_photo<H, F>(&mut self, handler: H)
pub fn edited_photo<H, F>(&mut self, handler: H)
Adds a new handler for edited photos.
Sourcepub fn edited_photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited photos which is run if the predicate returns true.
Sourcepub fn edited_text<H, F>(&mut self, handler: H)
pub fn edited_text<H, F>(&mut self, handler: H)
Adds a new handler for edited text messages.
Sourcepub fn edited_text_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_text_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited text messages which is run if the predicate returns true.
Sourcepub fn edited_video<H, F>(&mut self, handler: H)
pub fn edited_video<H, F>(&mut self, handler: H)
Adds a new handler for edited videos.
Sourcepub fn edited_video_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn edited_video_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for edited videos which is run if the predicate returns true.
Sourcepub fn game_callback<H, F>(&mut self, handler: H)
pub fn game_callback<H, F>(&mut self, handler: H)
Adds a new handler for game callbacks.
Sourcepub fn game_callback_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn game_callback_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for game callbacks which is run if the predicate returns true.
Sourcepub fn game_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn game_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for game messages which is run if the predicate returns true.
Sourcepub fn inline_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn inline_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for inline queries which is run if the predicate returns true.
Sourcepub fn invoice_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn invoice_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for invoices which is run if the predicate returns true.
Sourcepub fn left_member<H, F>(&mut self, handler: H)
pub fn left_member<H, F>(&mut self, handler: H)
Adds a new handler for left members.
Sourcepub fn left_member_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn left_member_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for left members which is run if the predicate returns true.
Sourcepub fn location_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn location_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for locations which is run if the predicate returns true.
Sourcepub fn migration_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn migration_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for migrations which is run if the predicate returns true.
Sourcepub fn new_chat_photo<H, F>(&mut self, handler: H)
pub fn new_chat_photo<H, F>(&mut self, handler: H)
Adds a new handler for new chat photos.
Sourcepub fn new_chat_photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn new_chat_photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for new chat photos which is run if the predicate returns true.
Sourcepub fn new_chat_title<H, F>(&mut self, handler: H)
pub fn new_chat_title<H, F>(&mut self, handler: H)
Adds a new handler for new chat titles.
Sourcepub fn new_chat_title_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn new_chat_title_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for new chat titles which is run if the predicate returns true.
Sourcepub fn new_members<H, F>(&mut self, handler: H)
pub fn new_members<H, F>(&mut self, handler: H)
Adds a new handler for new members.
Sourcepub fn new_members_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn new_members_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for new members which is run if the predicate returns true.
Sourcepub fn passport_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn passport_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for passport data which is run if the predicate returns true.
Sourcepub fn payment_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn payment_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for successful payments which is run if the predicate returns true.
Sourcepub fn photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn photo_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for photos which is run if the predicate returns true.
Sourcepub fn pinned_message<H, F>(&mut self, handler: H)
pub fn pinned_message<H, F>(&mut self, handler: H)
Adds a new handler for pinned messages.
Sourcepub fn pinned_message_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn pinned_message_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for pinned messages which is run if the predicate returns true.
Sourcepub fn poll_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn poll_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for poll messages which is run if the predicate returns true.1
Sourcepub fn pre_checkout<H, F>(&mut self, handler: H)
pub fn pre_checkout<H, F>(&mut self, handler: H)
Adds a new handler for pre-checkout queries.
Sourcepub fn pre_checkout_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn pre_checkout_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for pre-checkout queries which is run if the predicate returns true.
Sourcepub fn shipping_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn shipping_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for shipping queries which is run if the predicate returns true.
Sourcepub fn sticker_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn sticker_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for stickers which is run if the predicate returns true.
Sourcepub fn text_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn text_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for text messages which is run if the predicate returns true.
Sourcepub fn unhandled_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn unhandled_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for unhandled updates which is run if the predicate returns true.
Sourcepub fn updated_poll<H, F>(&mut self, handler: H)
pub fn updated_poll<H, F>(&mut self, handler: H)
Adds a new handler for new states of polls.
Sourcepub fn updated_poll_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn updated_poll_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for new states of polls which is run if the predicate returns true.
Sourcepub fn poll_answer<H, F>(&mut self, handler: H)
pub fn poll_answer<H, F>(&mut self, handler: H)
Adds a new handler for new answers in the poll.
Sourcepub fn poll_answer_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn poll_answer_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for new answers in the poll which is run if the predicate returns true.
Sourcepub fn venue_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn venue_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for venues which is run if the predicate returns true.
Sourcepub fn video_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn video_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for videos which is run if the predicate returns true.
Sourcepub fn video_note<H, F>(&mut self, handler: H)
pub fn video_note<H, F>(&mut self, handler: H)
Adds a new handler for video notes.
Sourcepub fn video_note_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn video_note_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for video notes which is run if the predicate returns true.
Sourcepub fn voice_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
pub fn voice_if<H, HF, P, PF>(&mut self, predicate: P, handler: H)
Adds a new handler for voice messages which is run if the predicate returns true.
Sourcepub async fn fetch_username(&mut self) -> Result<(), MethodCall>
pub async fn fetch_username(&mut self) -> Result<(), MethodCall>
Fetches the bot’s username.
The username is used when checking if a command such as
/command@username
was directed to the bot.