I’m working on a Telegram bot that handles payments and everything works fine. But I’m stuck on one thing - I want the PAY button to change into a RECEIPT button after the user completes their payment.
Right now what happens is:
- User clicks PAY button and enters card details
- Payment goes through successfully
- Bot sends confirmation message
- PAY button stays the same instead of changing to RECEIPT
I checked the Telegram docs and found this info about receipts:
When an invoice message is sent in chat with the merchant bot, it turns into a Receipt in the UI. Users can open this receipt anytime to view transaction details.
If sent to other chats, the Pay button stays active for multiple payments.
My invoice gets sent to the chat with my bot, so it should become a receipt automatically. But it’s not happening.
I’m using Node.js with webhooks. Here’s my payment handling code:
app.post('/webhook', async (req, res) => {
try {
// Handle pre-checkout validation
if (req.body.pre_checkout_query) {
// Process with answerPreCheckoutQuery method
...
}
const msg = req.body.message || req.body.edited_message;
// Payment completed successfully
if (msg.successful_payment) {
// Process successful payment
// Send confirmation message
...
}
} catch (error) {
...
}
})
For sending invoices I use:
const apiUrl = `https://api.telegram.org/bot${process.env.BOT_TOKEN}/sendInvoice`;
const result = await axios.post(apiUrl, {
chat_id: userId,
title: 'Product Purchase',
description: 'Purchase description here',
payload: 'PURCHASE-DATA',
provider_token: process.env.PAYMENT_TOKEN,
currency: 'USD',
prices: JSON.stringify([{
label: 'Product price',
amount: 500
}])
});
I’ve looked at both sendInvoice and answerPreCheckoutQuery methods but can’t find any parameter that would control this button transformation. What am I missing here?