无法在 Telegram 中发送发票 ("Bad Request: can\'t parse prices JSON object")

Can't send Invoice in Telegram ("Bad Request: can\'t parse prices JSON object")

我正在尝试在 Telegram 机器人中发送发票消息,但出现错误 {"ok":false,"error_code":400,"description":"错误请求:无法解析价格 JSON 对象"} 这是我发送的发票 def:

def sendInvoice(chat_id):

    invoice = {'chat_id': chat_id,
               'title': 'Оплата услуги',
               'description': 'Лайки на фото для инстаграм',
               'payload': 'Payload',
               'provider_token': 'provider_token',
               'start_parameter': 'insta pay',
               'currency': 'UAH',
               'prices': {'label': 'Цена', 'amount': 300000},
               }


    url = URL + 'sendInvoice'
    response = requests.post(url, invoice)
    print(response.__dict__)

你可以使用 telebot 库 :

pip install pyTelegramBotAPI

代码:

import telebot

bot = telebot.TeleBot("TOKEN")
bot.send_invoice()

您可以在 github 中看到 send_invoice 个参数。

您需要将价格列表转换为 json 可序列化 - 使用在 python

中构建的 json 模块
json.dumps([
    {
        "label": "My product",
        "amount": 999999
    }
])