简体   繁体   中英

How to add markdown formatting to photo caption using Telegraf (Telegram Bot Framework for Node.js)

I'm using Telegraf to build a Node.js Telegram bot.

When I try to send a photo I use:

const bot = new Telegraf(process.env.BOT_TOKEN);
bot.on('text', (ctx) => ctx.replyWithPhoto(
  { url: 'https://i.picsum.photos/id/237/200/300.jpg' },
  { caption: 'This is *Bobby*!' }
));
bot.launch();

The resulting message includes the photo along with a plain text caption:

This is *Bobby*!

How do I make the caption to look formatted with markdown? Like this:

This is Bobby !

You'll need to supply parse_mode in your second parameter. Possible options currently are html , Markdown and MarkdownV2 (for more details, see here ).

In your example, this would be:

bot.on('text', (ctx) => ctx.replyWithPhoto(
  { url: 'https://i.picsum.photos/id/237/200/300.jpg' },
  {
    caption: 'This is *Bobby*!',
    parse_mode: 'MarkdownV2'
  }
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM