skip to Main Content

I am attempting to send a message/photo message after a successful payment has been made, but I am thrown the following error:

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

My code as follows:

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

Is there absolutely no way to follow up with some message after a successful payment has been made via the Telegram Bot API?

EDIT:

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

2

Answers


  1. Chosen as BEST ANSWER

    Managed to figure out how to do it thanks to this post.

    To send a message after the 'You have just successfully transferred $XXX to ...' banner, we need to listen for successful_payment message. Here's the implementation:

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

  2. You can use Telegraf.telegram.sendMessage(chatId, text) to handle this or Telegraf.telegram.sendPhoto(chatId, photo) to reply with photo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search