#teloxide #telegram #bot

teloxide-listener

A listener extension for teloxide

1 unstable release

0.1.0-beta.1 Mar 11, 2022

#7 in #teloxide

Download history 37/week @ 2023-08-01 28/week @ 2023-08-08 17/week @ 2023-08-15 41/week @ 2023-08-22 8/week @ 2023-08-29 20/week @ 2023-09-05 14/week @ 2023-09-12 8/week @ 2023-09-19 46/week @ 2023-09-26 16/week @ 2023-10-03 43/week @ 2023-10-10 15/week @ 2023-10-17 18/week @ 2023-10-24 13/week @ 2023-10-31 21/week @ 2023-11-07 46/week @ 2023-11-14

99 downloads per month

MIT license

16KB
252 lines

teloxide-listener

A listener extension for teloxide.

Currently supports the following modes:

  • polling
  • webhook (axum, need to be enabled by feature flag)

Usage

Construct a Listener builder, build it, and pass it to with_listener versions of teloxide functions (e.g., repl_with_listener).

There are two ways to construct a Listener builder.

From environment variables

Listener::from_env can be used to construct a Listener from environment variables.

If compiled with webhook feature enabled, it tries to read TELOXIDE_WEBHOOK_URL, TELOXIDE_WEBHOOK_PATH, and TELOXIDE_BIND_ADDR to build a webhook updates listener first.

Otherwise, it falls back to long polling updates listener.

To customize the TELOXIDE_ prefix, use Listener::from_env_with_prefix.

Constructing a Listener manually

Example

use teloxide_listener::Listener;

let listener = Listener::from_env().build(bot.clone());

teloxide::repls2::repl_with_listener(
    bot,
    |msg: Message, bot: Bot| async move {
        bot.send_message(msg.chat.id, "pong").send().await?;
        respond(())
    },
    listener,
)

License

This project is licensed under the MIT license.

Dependencies

~12–26MB
~419K SLoC