Telegram Bot Telegraf:如何在成功付款后发送消息

Telegram Bot Telegraf: How to send a message after a successful payment

我正尝试在成功付款后发送 message/photo 消息,但出现以下错误:

Error: Telegraf: "replyWithPhoto" isn't available for "pre_checkout_query::"

我的代码如下:

bot.on('pre_checkout_query', (ctx) => {
    ctx.answerPreCheckoutQuery(true)
    .then(() => {
        let photo = //setup photo...
        let options = //setup caption and image url...
        ctx.replyWithPhoto(photo, options)
     })
})

在通过 Telegram Bot 成功付款后,是否完全无法跟进某些消息API?

编辑:

bot.on('pre_checkout_query', (ctx) => {
    let data = ctx.update.pre_checkout_query

    ctx.answerPreCheckoutQuery(true)
    .then(() => {
        let message = 'Thanks for the purchase!'
        bot.telegram.sendMessage(data.from.id, message)
    })
})

您可以使用 Telegraf.telegram.sendMessage(chatId, text) 来处理或 Telegraf.telegram.sendPhoto(chatId, photo) 用照片回复

多亏了这个post

设法弄清楚了如何去做

要在 'You have just successfully transferred $XXX to ...' 横幅后发送消息,我们需要监听 successful_payment 消息。这是实现:

bot.on('pre_checkout_query', (ctx) => {
    ctx.answerPreCheckoutQuery(true)
})

bot.on('message', (ctx) => {
    if (ctx.update.message.successful_payment != undefined) {
        ctx.reply('Thanks for the purchase!')
    } else {
        // Handle other message types, subtypes
    }
})