https://github.com/eomm/telegraf-safe-md-reply
Reply safely with markdown!
https://github.com/eomm/telegraf-safe-md-reply
middleware telegraf telegraf-plugin telegram
Last synced: 6 months ago
JSON representation
Reply safely with markdown!
- Host: GitHub
- URL: https://github.com/eomm/telegraf-safe-md-reply
- Owner: Eomm
- License: mit
- Created: 2023-10-15T08:48:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-15T09:29:33.000Z (over 1 year ago)
- Last Synced: 2024-10-19T23:19:51.288Z (8 months ago)
- Topics: middleware, telegraf, telegraf-plugin, telegram
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# telegraf-safe-md-reply
[](https://standardjs.com)
[](https://github.com/Eomm/telegraf-safe-md-reply/actions/workflows/ci.yml)Reply safely with markdown!
Are you tired of this error?!
```
"type": "TelegramError",
"message": "400: Bad Request: can't parse entities: Character '-' is reserved and must be escaped with the preceding '\\'",
```This package is for you!
## Usage
The `telegraf-safe-md-reply` middleware will add new methods to the `ctx` object:
- `replyWithSafeMarkdownV2`: reply with markdown escaping all the reserved characters
- `escapeMarkdown`: escape a string escaping all the reserved markdown characters```js
const Telegraf = require('telegraf')
const safeReply = require('telegraf-safe-md-reply')const bot = new Telegraf(process.env.BOT_TOKEN)
bot.use(safeReply())
bot.command('test', async (ctx) => {
// use the new method to reply
ctx.replyWithSafeMarkdownV2('Hello-World(?)')// or escape manually:
ctx.replyWithMarkdownV2(`*Hello*${ctx.escapeMarkdown('-World(?)')}`)
})
```## Options
You can pass an object with options to the middleware:
```js
bot.use(safeReply({
methodName: 'safeReply'
}))bot.command('test', (ctx) => {
ctx.safeReply('Hello-World(?)')
})
```## License
Copyright [Manuel Spigolon](https://github.com/Eomm), Licensed under [MIT](./LICENSE).