auto_chat_action 1.1.0 copy "auto_chat_action: ^1.1.0" to clipboard
auto_chat_action: ^1.1.0 copied to clipboard

A plugin for Televerse. Let's you automatically send Chat Actions based on the invoking API method.

AutoChatAction for Televerse #

Overview #

AutoChatAction is a plugin for Televerse, a Telegram Bot API library in Dart, that automatically sends chat actions like "typing..." or "uploading photo..." based on the invoked method. This feature enhances user experience by indicating ongoing bot activity.

Installation #

Add the auto_chat_action package to your project using Dart's package manager:

dart pub add auto_chat_action

Usage #

Using AutoChatAction is pretty simple. At first, create your Televerse bot instance as always.

final bot = Bot(Platform.environment["BOT_TOKEN"]!);

Now, let's attach the AutoChatAction plugin to the bot. We can make use of the Bot.use method for this.

  void main() {
    bot.use(AutoChatAction());

    // Rest of the code...
  }

Yeah, it's easy as one line :)

Now for every time you call one of sendVideo, sendDocument, sendSticker, sendVoice, sendMessage, sendLocation, sendVideoNote, sendPhoto the matching Chat Action is automatically send to the respective end user.

Use it for only one context. #

If, for some reason, you don't want to use the plugin for every API call and prefer to apply it only within a specific context, you can attach the plugin to the context using the Context.use() method instead of the Bot.use().

bot.command('test', (ctx) async {
  ctx.use(AutoChatAction());

  // Rest of the code
});

Configuration #

The AutoChatAction class can be customized using the following properties:

  • allowedMethods: A list of API methods that are allowed to send chat actions. Defaults to:
    [
      APIMethod.sendVideo, 
      APIMethod.sendDocument, 
      APIMethod.sendSticker, 
      APIMethod.sendVoice, 
      APIMethod.sendMessage, 
      APIMethod.sendLocation, 
      APIMethod.sendVideoNote, 
      APIMethod.sendPhoto, 
    ]
    
  • disallowedMethods: A list of API methods that are not allowed to send chat actions. Defaults to an empty list.
  • interval: The duration between repeated chat action sends. Defaults to 3 seconds.

Example Configuration #

const autoChatAction = AutoChatAction(
  allowedMethods: [APIMethod.sendMessage, APIMethod.sendPhoto],
  disallowedMethods: [APIMethod.sendVoice],
  interval: Duration(seconds: 5),
);

bot.use(autoChatAction);

In this configuration, automatic chat actions will only be sent for sendMessage and sendPhoto methods. The sendVoice method is explicitly disallowed, and the interval between repeated actions is set to 5 seconds.

Thank You #

Thank you for using AutoChatAction! We hope this plugin enhances your bot development experience with Televerse. If you encounter any issues or have suggestions, feel free to contribute or raise an issue on the GitHub repository.

1
likes
160
points
62
downloads

Publisher

verified publisherxooniverse.com

Weekly Downloads

A plugin for Televerse. Let's you automatically send Chat Actions based on the invoking API method.

Repository (GitHub)
View/report issues

Topics

#televerse #telegram-bot #plugin #telegram

Documentation

API reference

Funding

Consider supporting this project:

buymeacoffee.com

License

MIT (license)

Dependencies

televerse

More

Packages that depend on auto_chat_action