telegraf-safe-md-reply

1.0.0 • Public • Published

telegraf-safe-md-reply

JavaScript Style Guide ci

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
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:

bot.use(safeReply({
  methodName: 'safeReply'
}))

bot.command('test', (ctx) => {
  ctx.safeReply('Hello-World(?)')
})

License

Copyright Manuel Spigolon, Licensed under MIT.

Package Sidebar

Install

npm i telegraf-safe-md-reply

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.23 kB

Total Files

7

Last publish

Collaborators

  • eomm