【问题标题】:How do I use Markdown in editMessageMedia (Telegram BOT API)?如何在 editMessageMedia (Telegram BOT API) 中使用 Markdown?
【发布时间】:2020-09-15 08:25:51
【问题描述】:

Telegram 有一个改变图像的方法,它接受 InputMedia:

{
    type: "photo",
    media: IMAGE, 
    caption: TEXT, 
    parse_mode: "Markdown", 
} 

因此,即使我指定了 parse_mode,格式化也不起作用。

我的代码

ctx.editMessageMedia({
    type: "photo",
    media: IMAGE,
    caption: TEXT,
    parse_mode: "Markdown",
}, message_id)

【问题讨论】:

  • 您使用什么编程语言和库?您是否尝试过在 parse_mode: "Markdown" 周围加上额外的花括号?
  • Node JS,Telegraf。不,我该怎么做?
  • 添加了我的答案 - 您的代码没有发现任何特别错误的地方。也许这与您调用reply / send 函数的方式有关?

标签: telegram telegram-bot telegraf


【解决方案1】:

这对我来说似乎是正确的。由于您使用的是 Telegraf,因此根据上下文,您也可以使用 ctx.replyWithPhoto(...)bot.telegram.sendPhoto(...)

举个例子:

bot.command('photo', ctx => {
    ctx.replyWithPhoto(
        {
            source: fs.createReadStream('img.jpg')
        },
        {
            caption: 'Some *really* _nice_ __images__',
            parse_mode: 'MarkdownV2'
        }
    ).catch(err => console.log(err))
})

...当我说/photo 时,它会产生以下结果:

【讨论】:

  • 这适用于 replyWithPhoto 但它不适用于 editMessageMedia pastebin.com/b0yGhEka
  • 如果只是您要编辑的标题,您可以使用以下内容吗? bot.telegram.editMessageCaption(chat_id, message_id, null, '*new* caption', { parse_mode: 'MarkdownV2' })
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-07
  • 2015-12-08
  • 2022-10-20
  • 2016-02-23
  • 2021-04-17
  • 2017-12-25
  • 2023-03-28
相关资源
最近更新 更多