Struct tbot::event_loop::EventLoop

source ·
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§

Turns this event loop into a stateful one. Handlers added on this event loop are kept.

Sets the bot’s username.

The username is used when checking if a command such as /command@username was directed to the bot.

Fetches the bot’s username.

The username is used when checking if a command such as /command@username was directed to the bot.

Starts polling configuration.

Starts webhook configuration.

See our wiki to learn how to use webhook with tbot.

Registers 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.

It is idiomatic to omit the leading / in the command. Even though keeping it will work as expected, tbot will emit a warning in this case.

Registers a new handler for a command and sets its description.

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.

It is idiomatic to omit the leading / in the command. Even though keeping it will work as expected, tbot will emit a warning in this case.

Registers 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.

It is idiomatic to omit the leading / in the commands. Even though keeping it will work as expected, tbot will emit a warning in this case.

Registers a new handler for the /start command.

Registers a new handler for the /start command and sets its description.

Registers a new handler for the /settings command.

Registers a new handler for the /settings command and sets its description.

Registers a new handler for the /help command.

Registers a new handler for the /help command and sets its description.

Registers a new handler for an edited command.

It is idiomatic to omit the leading / in the commands. Even though keeping it will work as expected, tbot will emit a warning in this case.

Registers a new handler for an edited command from sequence of commands.

It is idiomatic to omit the leading / in the commands. Even though keeping it will work as expected, tbot will emit a warning in this case.

Registers a new handler for all incoming updates.

any_update handlers are spawned before specialized handlers, for every update that could be deserialized (this means that processing new updates on old versions of tbot is not possible even via any_update).

Note “spawned”: every handler is executed using [tokio::spawn], and tbot won’t wait for them to finish. As such, any_update is not suitable for running some code before every specialized handler.

Also, any_update does not affect unhandled in any way. It’s executed if a specialized handler corresponding to the incoming update wasn’t registered.

Registering specialized handler is still preferred. if at least one any_update handler is registered, tbot will have to clone every update in order to execute these and specialized handlers.

Registers a new handler for animations.

Registers a new handler for audio.

Registers a new handler for changed auto-delete timers.

Registers a new handler for chat members’ updated information.

Registers a new handler for chosen inline results.

Registers a new handler for contacts.

Registers a new handler for connected websites.

Registers a new handler for created groups.

Registers a new handler for data callbacks from chat messages.

Registers a new handler for data callbacks from inline messages.

Registers a new handler for deleted chat photos.

Registers a new handler for dice.

Registers a new handler for documents.

Registers a new handler for edited animations.

Registers a new handler for edited audio.

Registers a new handler for edited documents.

Registers a new handler for edited locations.

Registers a new handler for edited photos.

Registers a new handler for edited text messages.

Registers a new handler for edited videos.

Registers a new handler for when a voice chat is ended.

Registers a new handler for game callbacks from chat messages.

Registers a new handler for game callbacks from inline messages.

Registers a new handler for game messages.

Registers a new handler for inline queries.

Registers a new handler for when users are invited to a voice chat.

Registers a new handler for invoices.

Registers a new handler for left members.

Registers a new handler for locations.

Registers a new handler for migrations.

Registers a new handler for the bot’s update chat member status.

Registers a new handler for new chat photos.

Registers a new handler for new chat titles.

Registers a new handler for new members.

Registers a new handler for passport data.

Registers a new handler for successful payments.

Registers a new handler for photos.

Registers a new handler for pinned messages.

Registers a new handler for poll messages.

Registers a new handler for pre-checkout queries.

Registers a new handler for proximity alerts.

Registers a new handler for when a voice chat is scheduled.

Registers a new handler for shipping queries.

Registers a new handler for when a voice chat is started.

Registers a new handler for stickers.

Registers a new handler for text messages.

Registers a new handler for unhandled updates.

Note that regisering any_update handlers does not affect unhandled handlers in any way. An unhandled handler is spawned if a specialized handler corresponding to the incoming update was not registered.

Registers a new handler for new states of polls.

Registers a new handler for new answers in the poll.

Registers a new handler for venues.

Registers a new handler for videos.

Registers a new handler for video notes.

Registers a new handler for voice messages.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more