javascript - Telegram Bot 付款 - 付款成功后显示收据

标签 javascript node.js telegram telegram-bot telegram-api

我有一个处理付款的 Telegram 机器人。付款正常工作,但是,我无法在成功付款后显示收据。
目前的行为是:

  • 用户点击支付按钮,填写卡信息并支付服务费用
  • 处理付款并发送有关成功交易的消息
  • 此时,我希望 PAY 按钮更改为 RECEIPT 按钮

  • 屏幕截图上的当前行为:
    current behavior
    期望的行为:
    desired behavior
    从与 @ShopBot 的聊天中截取了所需的行为,在 Telegram 文档中提到它是一种测试工具。
    我在 Telegram 文档中唯一提到的关于如何处理“收据”的是这两个句子,位于 https://core.telegram.org/bots/payments :

    If the invoice message was sent in the chat with @merchantbot, it becomes a Receipt in the UI for the user — they can open this receipt at any time and see all the details of the transaction.


    If the message was sent to any other chat, the Pay button remains and can be used again. It is up to the merchant bot whether to actually accept multiple payments.


    但是,我不明白如何在代码中实现这一点。据我所知,发票消息已发送到与我的机器人的聊天中(如第一句话),因此它应该成为收据。
    该机器人是用 Node.js 编写的,并使用 webhook 来处理消息。 webhook 的代码部分对这个问题很重要:
    router.route('/')
        .post(async (req, res) => {
            try {
    
                // if pre_checkout_query is defined, there was an attempt for payment
                if (req.body.pre_checkout_query) {
                    // use answerPreCheckoutQuery Telegram method
                    ...
                }
    
                const message = req.body.message || req.body.edited_message;
    
                // this means user's payment was successful
                if (message.successful_payment) {
                    // success, deliver goods or services
                    // send message about successful payment
                    ...
                }
    
    
            } catch (err) {
                ...
            }
        })
    
    发票是用 sendInvoice 发送的像这样的方法:
    
    const url = `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendInvoice`;
    const response = await axios.get(url, {
       params: {
          chat_id: chatID,
          title: 'SOME TITLE',
          description: 'some decription',
          payload: 'SOME-PAYLOAD',
          provider_token: process.env.STRIPE_API_TOKEN,
          currency: 'EUR',
          prices: JSON.stringify([
             {
                label: 'some label',
                amount: 200,
             },
          ]),
       },
    });
    
    API 中用于处理付款的两种方法是 sendInvoiceanswerPreCheckoutQuery但它们都不包含任何可能以我想要的方式改变输出的参数。我错过了什么吗?
    最后请注意:尽管如此,付款仍然有效。这只是我想实现的外观上的改变。

    最佳答案

    我也有这个问题,指定一个参数:start_parameter='unique-string'

    关于javascript - Telegram Bot 付款 - 付款成功后显示收据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69003183/

    相关文章:

    javascript - 在 tableview 单元格中突出显示 uiwebview 文本

    javascript - 表达多个匹配规则的优先级

    android - 如果我在Android中使用Telegram api,是否需要服务器?

    ssl - 为 Telegram Webhook 创建和使用自签名证书的简单方法是什么?

    javascript - navigator.geolocation api 的替代方案

    javascript - 第一个 AJAX 示例无法运行

    node.js - AWS Lambda(Node.js,8.10 版)和 Mongoose : MongoNetworkError connection to DB timed out

    javascript - 为什么这个 Javascript promise 不起作用?

    Telegram ,跟踪消息编辑/删除和编辑我自己的消息(客户端,而不是 Bot API)

    javascript - 加载数据时,Angular 的 Resource Promise 不会重新呈现