parse_mode_setter 1.0.0 parse_mode_setter: ^1.0.0 copied to clipboard
A plugin for Televerse. Let's you set parse mode all methods in one line.
ParseModeSetter for Televerse #
Consistent Message Formatting with ParseModeSetter
Overview #
Streamline your Televerse bot development with ParseModeSetter
, a Transformer
plugin that automates parse mode setting for various API methods. This plugin
ensures consistent message formatting without the need to manually specify the
parse mode each time. It simplifies you r code and saves you valuable time.
Installation #
-
Add the
parse_mode_setter
package to your project using Dart's package manager:dart pub add parse_mode_setter
Usage #
๐งช Example #
Here's a code snippet demonstrating how to integrate ParseModeSetter
with your
Televerse bot:
import 'dart:io';
import 'package:parse_mode_setter/parse_mode_setter.dart';
import 'package:televerse/televerse.dart';
final bot = Bot(Platform.environment["BOT_TOKEN"]!);
void main(List<String> args) {
// Attach ParseModeSetter, setting the parse mode to HTML in this case.
bot.use(ParseModeSetter(ParseMode.html));
bot.command('start', (ctx) async {
// Leverage HTML formatting within methods without worrying about parse mode.
await ctx.reply(
"Hello <b>World</b>\n\nThis is a <i>great story of the Detective Rajappan</i>."
" I hope you've heard of Rajappan. Well, if you haven't, he's a"
" <tg-spoiler>super detective.</tg- spoiler>",
);
});
bot.start();
}
โ๏ธ Configuration #
Customize the ParseModeSetter
class using the following properties:
allowedMethods
: A list of API methods allowed to have their parse mode set. Defaults to:[ APIMethod.sendMessage, APIMethod.copyMessage, APIMethod.sendPhoto, APIMethod.sendAudio, APIMethod.sendDocument, APIMethod.sendVideo, APIMethod.sendAnimation, APIMethod.sendVoice, APIMethod.sendPoll, APIMethod.editMessageText, APIMethod.editMessageCaption, ]
disallowedMethods
: A list of API methods that should not have their parse mode set. Defaults to an empty list.setQuestionParseMode
: A boolean indicating whether to set the parse mode for poll questions. Defaults totrue
.setExplanationParseMode
: A boolean indicating whether to set the parse mode for poll explanations. Defaults totrue
.
Example Configuration #
final parseModeSetter = ParseModeSetter(
ParseMode.markdown,
allowedMethods: [APIMethod.sendMessage, APIMethod.sendPhoto],
disallowedMethods: [APIMethod.sendVoice],
setQuestionParseMode: true,
setExplanationParseMode: false,
);
bot.use(parseModeSetter);
In this configuration:
- The parse mode is set to Markdown for
sendMessage
andsendPhoto
methods. - The parse mode is explicitly not set for the
sendVoice
method. - The parse mode is set for poll questions but not for poll explanations.
Understanding Parse Mode #
The Telegram Bot API supports basic formatting for messages, including bold, italic, underline, strikethrough, spoiler text, block quotes, inline links, and pre-formatted code. Telegram clients render these styles accordingly. You can specify text entities directly or use markdown-style or HTML-style formatting.
๐ง๐ปโ๐ป Contributing #
We appreciate your interest in ParseModeSetter
! If you find it helpful,
consider starring the repository. Feel free to report any issues or suggest
improvements on GitHub.
Get Started with Televerse #
For more information on Televerse, the Telegram Bot API library used in this plugin, visit the official repository.
Thank you for using ParseModeSetter
! We hope it simplifies your Televerse
bot development experience.