如何使用 Telegraf(用于 Node.js 的 Telegram Bot Framework)向照片标题添加 Markdown 格式 [英] How to add markdown formatting to photo caption using Telegraf (Telegram Bot Framework for Node.js)

查看:51
本文介绍了如何使用 Telegraf(用于 Node.js 的 Telegram Bot Framework)向照片标题添加 Markdown 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Telegraf 来构建 Node.js Telegram 机器人.

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:

这是*鲍比*!

如何使标题看起来像 Markdown 格式?像这样:

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

这是鲍比

推荐答案

您需要提供 parse_mode 在您的第二个参数中.目前可能的选项有 htmlMarkdownMarkdownV2(更多详情,请参阅 此处).

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'
  }
));

这篇关于如何使用 Telegraf(用于 Node.js 的 Telegram Bot Framework)向照片标题添加 Markdown 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆