Function teloxide::repl_with_listener
source · pub async fn repl_with_listener<R, H, L, Args>(bot: R, handler: H, listener: L)where
R: Requester + Clone + Send + Sync + 'static,
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
L: UpdateListener + Send,
L::Err: Debug,
ctrlc_handler
only.Expand description
A REPL for messages, with a custom UpdateListener
.
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.
Signature
Don’t be scared by many trait bounds in the signature, in essence they require:
bot
is a bot, client for the Telegram bot API. It is represented via theRequester
trait.handler
is anasync
function that takes arguments fromDependencyMap
(see below) and returnsResponseResult
.listener
is something that takes updates from a Telegram server and implementsUpdateListener
.
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 message without Me
.
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.