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:bashdart 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:dart[ APIMethod.sendMessage, APIMethod.copyMessage, APIMethod.sendPhoto, APIMethod.sendAudio, APIMethod.sendDocument, APIMethod.sendVideo, APIMethod.sendAnimation, APIMethod.sendVoice, APIMethod.sendPoll, APIMethod.editMessageText, APIMethod.editMessageCaption, APIMethod.editMessageCaption, APIMethod.answerInlineQuery, APIMethod.editMessageMedia, APIMethod.sendMediaGroup, ],
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.