{"id":18450718,"url":"https://github.com/xooniverse/parsemodesetter","last_synced_at":"2025-10-26T02:09:16.955Z","repository":{"id":246027144,"uuid":"819909604","full_name":"xooniverse/ParseModeSetter","owner":"xooniverse","description":"A plugin for Televerse. Let's you set parse mode all methods in one line.","archived":false,"fork":false,"pushed_at":"2025-03-08T10:35:31.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-22T10:23:31.865Z","etag":null,"topics":["plugin","telegram","telegram-bot-api","televerse"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/parse_mode_setter","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xooniverse.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"custom":["https://www.buymeacoffee.com/heysreelal"]}},"created_at":"2024-06-25T12:21:49.000Z","updated_at":"2025-03-08T10:35:34.000Z","dependencies_parsed_at":"2024-09-08T08:48:13.905Z","dependency_job_id":"f999bdbd-83f8-49f0-a418-cb61ecf8ab59","html_url":"https://github.com/xooniverse/ParseModeSetter","commit_stats":null,"previous_names":["xooniverse/parsemodesetter"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xooniverse/ParseModeSetter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xooniverse%2FParseModeSetter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xooniverse%2FParseModeSetter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xooniverse%2FParseModeSetter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xooniverse%2FParseModeSetter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xooniverse","download_url":"https://codeload.github.com/xooniverse/ParseModeSetter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xooniverse%2FParseModeSetter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265049810,"owners_count":23703592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["plugin","telegram","telegram-bot-api","televerse"],"created_at":"2024-11-06T07:26:14.675Z","updated_at":"2025-10-26T02:09:16.928Z","avatar_url":"https://github.com/xooniverse.png","language":"Dart","funding_links":["https://www.buymeacoffee.com/heysreelal"],"categories":[],"sub_categories":[],"readme":"# ParseModeSetter Plugin for Televerse\n\n![Dart](https://img.shields.io/badge/Dart-0175C2?logo=dart\u0026logoColor=white)\n![Televerse](https://img.shields.io/badge/Televerse-🚀-blue)\n![Version](https://img.shields.io/badge/version-1.0.0-green)\n\n**Consistent Message Formatting with ParseModeSetter Plugin**\n\n## Overview\n\nStreamline your Televerse bot development with `ParseModeSetterPlugin`, 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 your code and saves you valuable time by automatically applying your preferred text formatting across all supported Telegram Bot API methods.\n\n## Features\n\n✨ **Automatic Parse Mode Setting** - Set parse mode once, apply everywhere  \n🎯 **Method Filtering** - Choose which API methods should have parse mode applied  \n📊 **Poll Support** - Separate controls for poll questions and explanations  \n🔧 **Highly Configurable** - Fine-tune behavior to match your needs  \n🚀 **Easy Integration** - Simple plugin installation with Televerse's new plugin system  \n\n## Installation\n\nThe `ParseModeSetterPlugin` is included with Televerse. No additional installation required!\n\n```dart\nimport 'package:televerse/televerse.dart';\n```\n\n## Usage\n\n### 🧪 Basic Example\n\nHere's a code snippet demonstrating how to integrate `ParseModeSetterPlugin` with your Televerse bot:\n\n```dart\nimport 'dart:io';\nimport 'package:televerse/televerse.dart';\n\nvoid main() async {\n  final bot = Bot\u003cContext\u003e(Platform.environment[\"BOT_TOKEN\"]!);\n\n  // Install ParseModeSetter plugin with HTML formatting\n  bot.plugin(ParseModeSetterPlugin\u003cContext\u003e(\n    parseMode: ParseMode.html,\n  ));\n\n  bot.command('start', (ctx) async {\n    // Leverage HTML formatting without worrying about parse mode\n    await ctx.reply(\n      \"Hello \u003cb\u003eWorld\u003c/b\u003e\\n\\n\"\n      \"This is a \u003ci\u003egreat story of Detective Rajappan\u003c/i\u003e. \"\n      \"I hope you've heard of Rajappan. Well, if you haven't, he's a \"\n      \"\u003ctg-spoiler\u003esuper detective.\u003c/tg-spoiler\u003e\",\n    );\n  });\n\n  bot.command('markdown', (ctx) async {\n    // This will also use HTML parse mode automatically\n    await ctx.replyWithPhoto(\n      InputFile.fromUrl('https://example.com/photo.jpg'),\n      caption: 'A \u003cb\u003ebeautiful\u003c/b\u003e photo with \u003ci\u003eformatted\u003c/i\u003e caption!',\n    );\n  });\n\n  await bot.start();\n}\n```\n\n### ⚙️ Advanced Configuration\n\nCustomize the `ParseModeSetterPlugin` using the following properties:\n\n```dart\nbot.plugin(ParseModeSetterPlugin\u003cContext\u003e(\n  parseMode: ParseMode.markdownV2,\n  \n  // Specify which methods should have parse mode set\n  allowedMethods: [\n    APIMethod.sendMessage,\n    APIMethod.sendPhoto,\n    APIMethod.sendVideo,\n    APIMethod.editMessageText,\n    APIMethod.editMessageCaption,\n  ],\n  \n  // Exclude specific methods from having parse mode set\n  disallowedMethods: [\n    APIMethod.sendVoice,\n    APIMethod.sendSticker,\n  ],\n  \n  // Control poll formatting\n  setQuestionParseMode: true,     // Format poll questions\n  setExplanationParseMode: false, // Don't format poll explanations\n));\n```\n\n### 📋 Default Configuration\n\nBy default, `ParseModeSetterPlugin` applies parse mode to these API methods:\n\n- `APIMethod.sendMessage`\n- `APIMethod.copyMessage`\n- `APIMethod.sendPhoto`\n- `APIMethod.sendAudio`\n- `APIMethod.sendDocument`\n- `APIMethod.sendVideo`\n- `APIMethod.sendAnimation`\n- `APIMethod.sendVoice`\n- `APIMethod.sendPoll`\n- `APIMethod.editMessageText`\n- `APIMethod.editMessageCaption`\n- `APIMethod.editMessageMedia`\n- `APIMethod.answerInlineQuery`\n- `APIMethod.sendMediaGroup`\n\n### 🎯 Multiple Parse Mode Scenarios\n\nYou can even install multiple parse mode setters for different scenarios:\n\n```dart\n// Global HTML formatting for most messages\nbot.plugin(ParseModeSetterPlugin\u003cContext\u003e(\n  parseMode: ParseMode.html,\n  disallowedMethods: [APIMethod.sendPoll], // Exclude polls\n));\n\n// Separate Markdown formatting specifically for polls\nbot.plugin(ParseModeSetterPlugin\u003cContext\u003e(\n  parseMode: ParseMode.markdownV2,\n  allowedMethods: [APIMethod.sendPoll], // Only polls\n  setQuestionParseMode: true,\n  setExplanationParseMode: true,\n));\n```\n\n### 🔧 Custom Context Integration\n\nThe plugin works seamlessly with custom context types:\n\n```dart\nclass MyContext extends Context {\n  MyContext(super.update, super.api, super.me);\n  \n  // Your custom context methods\n  String get userName =\u003e from?.firstName ?? 'Unknown';\n}\n\nvoid main() async {\n  final bot = Bot\u003cMyContext\u003e(\n    'YOUR_BOT_TOKEN',\n    contextFactory: MyContext.new,\n  );\n\n  // Plugin works with any context type\n  bot.plugin(ParseModeSetterPlugin\u003cMyContext\u003e(\n    parseMode: ParseMode.html,\n  ));\n\n  bot.command('greet', (MyContext ctx) async {\n    await ctx.reply('Hello \u003cb\u003e${ctx.userName}\u003c/b\u003e!');\n  });\n\n  await bot.start();\n}\n```\n\n## Configuration Options\n\n| Property | Type | Default | Description |\n|----------|------|---------|-------------|\n| `parseMode` | `ParseMode` | **Required** | The parse mode to apply (HTML, Markdown, MarkdownV2) |\n| `allowedMethods` | `List\u003cAPIMethod\u003e` | All supported methods | API methods that should have parse mode applied |\n| `disallowedMethods` | `List\u003cAPIMethod\u003e` | `[]` | API methods that should NOT have parse mode applied |\n| `setQuestionParseMode` | `bool` | `true` | Whether to apply parse mode to poll questions |\n| `setExplanationParseMode` | `bool` | `true` | Whether to apply parse mode to poll explanations |\n\n## Understanding Parse Mode\n\nThe Telegram Bot API supports rich text formatting including:\n\n### HTML Style (`ParseMode.html`)\n```html\n\u003cb\u003ebold\u003c/b\u003e\n\u003ci\u003eitalic\u003c/i\u003e\n\u003cu\u003eunderline\u003c/u\u003e\n\u003cs\u003estrikethrough\u003c/s\u003e\n\u003ctg-spoiler\u003espoiler\u003c/tg-spoiler\u003e\n\u003ccode\u003emonospace\u003c/code\u003e\n\u003cpre\u003epre-formatted\u003c/pre\u003e\n\u003ca href=\"https://example.com\"\u003elink\u003c/a\u003e\n```\n\n### MarkdownV2 Style (`ParseMode.markdownV2`)\n```markdown\n*bold*\n_italic_\n__underline__\n~strikethrough~\n||spoiler||\n`monospace`\n```preformatted```\n[link](https://example.com)\n```\n\n### Markdown Style (`ParseMode.markdown`) - Legacy\n```markdown\n*bold*\n_italic_\n`monospace`\n```preformatted```\n[link](https://example.com)\n```\n\n## Advanced Use Cases\n\n### Conditional Parse Mode Setting\n\n```dart\n// Create a custom plugin that sets parse mode based on chat type\nclass ConditionalParseModePlugin\u003cCTX extends Context\u003e \n    implements Plugin\u003cCTX\u003e {\n  \n  @override\n  String get name =\u003e 'conditional-parse-mode';\n  \n  @override\n  void install(Bot\u003cCTX\u003e bot) {\n    // HTML for private chats\n    bot.filter(\n      (ctx) =\u003e ctx.chat?.type == ChatType.private,\n      (ctx, next) async {\n        // Temporary parse mode setter for this context\n        await next();\n      },\n    );\n  }\n}\n```\n\n### Dynamic Parse Mode Based on User Preference\n\n```dart\nbot.use((ctx, next) async {\n  final userPreference = await getUserParseMode(ctx.from?.id);\n  \n  // Temporarily install parse mode setter\n  final plugin = ParseModeSetterPlugin\u003cContext\u003e(\n    parseMode: userPreference,\n    allowedMethods: [APIMethod.sendMessage],\n  );\n  \n  await next();\n});\n```\n\n## Best Practices\n\n1. **Choose One Parse Mode**: Stick to one parse mode throughout your bot for consistency\n2. **Test Formatting**: Always test your formatted messages to ensure they render correctly\n3. **Escape Special Characters**: When using user input, properly escape special characters\n4. **Consider Context**: Some messages (like error messages) might not need formatting\n5. **Performance**: The plugin adds minimal overhead but consider your specific use case\n\n## Troubleshooting\n\n### Common Issues\n\n**Parse errors in messages:**\n- Ensure you're using the correct syntax for your chosen parse mode\n- Check that special characters are properly escaped\n- Verify that HTML tags are properly closed\n\n**Plugin not working:**\n- Make sure you've installed the plugin with `bot.plugin()`\n- Check that the API method is in the `allowedMethods` list\n- Verify it's not in the `disallowedMethods` list\n\n**Conflicts with manual parse mode:**\n- The plugin will override any manually set parse mode\n- Use `disallowedMethods` to exclude specific methods where you want manual control\n\n## 🧑🻍💻 Contributing\n\nWe appreciate your interest in improving the ParseModeSetter plugin! If you find it helpful, consider starring the Televerse repository. Feel free to report any issues or suggest improvements on GitHub.\n\n## Get Started with Televerse\n\nFor more information on Televerse, the Telegram Bot API framework used with this plugin, [visit the official repository](https://github.com/HeySreelal/televerse).\n\n**Thank you for using ParseModeSetterPlugin! We hope it simplifies your Televerse bot development experience.**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxooniverse%2Fparsemodesetter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxooniverse%2Fparsemodesetter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxooniverse%2Fparsemodesetter/lists"}