【问题标题】:how to reply a photo with caption in nodejs telegram bot (telegraf)如何在nodejs电报机器人(telegraf)中回复带有标题的照片
【发布时间】:2018-06-30 19:30:31
【问题描述】:

我正在用telegraf 编写一个电报机器人。 我想在回复消息中发送一张带有文字的照片。 我写了这个:

    serviceDetailsScene.on('callback_query', async ({replyWithPhoto}) => {
        await replyWithPhoto({url: <url>})
}

它可以正常工作并正确发送图像,但我不知道如何将消息附加到它。

感谢您的帮助。

【问题讨论】:

    标签: node.js telegram-bot telegraf


    【解决方案1】:

    试试看:

    await replyWithPhoto({url: <url>}, {caption: 'Your caption'})
    

    【讨论】:

    • 虽然此代码 sn-p 可能是解决方案,但 including an explanation 确实有助于提高您的帖子质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
    【解决方案2】:

    您可以这样做以使用图像 src 和标题进行回复:

    bot.hears('photo', ctx.replyWithPhoto({ source: <pic-src> }, { caption: "cat photo" });
    

    如果你想发送图片 url,你可以这样写:

    bot.hears('photo', ctx.replyWithPhoto({ url: <pic-url> }, { caption: "cat photo" });
    

    【讨论】:

    • 是否可以在标题中添加markdown格式?
    猜你喜欢
    • 1970-01-01
    • 2021-04-20
    • 2016-08-15
    • 2021-09-28
    • 2019-04-01
    • 2016-06-29
    • 2016-10-17
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多