pub trait CommandReplExt {
// Required methods
fn repl<'a, R, H, Args>(bot: R, handler: H) -> BoxFuture<'a, ()>
where R: Requester + Clone + Send + Sync + 'static,
<R as Requester>::GetUpdates: Send,
<R as Requester>::GetWebhookInfo: Send,
<R as Requester>::GetMe: Send,
<R as Requester>::DeleteWebhook: Send,
H: Injectable<ResponseResult<()>, Args> + Send + Sync + 'static;
fn repl_with_listener<'a, R, H, L, Args>(
bot: R,
handler: H,
listener: L,
) -> BoxFuture<'a, ()>
where H: Injectable<ResponseResult<()>, Args> + Send + Sync + 'static,
L: UpdateListener + Send + 'a,
L::Err: Debug + Send + 'a,
R: Requester + Clone + Send + Sync + 'static,
<R as Requester>::GetMe: Send;
}ctrlc_handler only.Expand description
A REPL for commands.
REPLs are meant only for simple bots and rapid prototyping. If you need to
supply dependencies or describe more complex dispatch logic, please use
Dispatcher. See also: “Dispatching or
REPLs?”.
All errors from the handler and update listener will be logged.
This trait extends your BotCommands type with REPL facilities.
§Signatures
Don’t be scared by many trait bounds in the signatures, in essence they require:
botis a bot, client for the Telegram bot API. It is represented via theRequestertrait.handleris anasyncfunction that takes arguments fromDependencyMap(see below) and returnsResponseResult.listeneris something that takes updates from a Telegram server and implementsUpdateListener.
All the other requirements are about thread safety and data validity and can be ignored for most of the time.
§Handler arguments
teloxide provides the following types to the handler:
Each of these types can be accepted as a handler parameter. Note that they
aren’t all required at the same time: e.g., you can take only the bot and
the command without Me and Message.
§Stopping
To stop a REPL, simply press Ctrl+C in the terminal where you run the program.
Note that graceful shutdown may take some time (we plan to improve this, see #711).
§Caution
DO NOT use this function together with Dispatcher and other REPLs,
because Telegram disallow multiple requests at the same time from the same bot.
Required Methods§
Sourcefn repl<'a, R, H, Args>(bot: R, handler: H) -> BoxFuture<'a, ()>where
R: Requester + Clone + Send + Sync + 'static,
<R as Requester>::GetUpdates: Send,
<R as Requester>::GetWebhookInfo: Send,
<R as Requester>::GetMe: Send,
<R as Requester>::DeleteWebhook: Send,
H: Injectable<ResponseResult<()>, Args> + Send + Sync + 'static,
fn repl<'a, R, H, Args>(bot: R, handler: H) -> BoxFuture<'a, ()>where
R: Requester + Clone + Send + Sync + 'static,
<R as Requester>::GetUpdates: Send,
<R as Requester>::GetWebhookInfo: Send,
<R as Requester>::GetMe: Send,
<R as Requester>::DeleteWebhook: Send,
H: Injectable<ResponseResult<()>, Args> + Send + Sync + 'static,
A REPL for commands.
See CommandReplExt for more details.
Sourcefn repl_with_listener<'a, R, H, L, Args>(
bot: R,
handler: H,
listener: L,
) -> BoxFuture<'a, ()>
fn repl_with_listener<'a, R, H, L, Args>( bot: R, handler: H, listener: L, ) -> BoxFuture<'a, ()>
A REPL for commands with a custom UpdateListener.
See CommandReplExt for more details.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.