I’m working with a Telegram bot that sends payment invoices, but my payment provider says they’re getting malformed data in the provider_data field. They need me to share the complete HTTP request details to help debug this issue.
My current code:
import json
from telegram import Bot, Update, LabeledPrice
from telegram.ext import ContextTypes
PAY_TOKEN = '111111111111111'
INV_PAYLOAD = 'Payment-Debug'
PRODUCT_CATALOG = {"202410DEBUGITEM": ["DEBUG Item",
"Testing payment integration functionality.",
50,
"https://example.com",
"https://example.com/logo.png",
"logo.png",
],
}
async def process_payment_request(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_id, first_name, last_name, user_handle = (update.effective_user.id,
update.effective_user.first_name,
update.effective_user.last_name,
update.effective_user.username)
item_key = str(context.user_data['selected_item'])
product_title = f'{PRODUCT_CATALOG[item_key][0]}'
product_desc = f'{PRODUCT_CATALOG[item_key][1]}'
price_label = f'Purchase of {item_key.upper()}'
price_value = int(PRODUCT_CATALOG[item_key][2])
currency_type = 'USD'
receipt_data = {
"receipt": {
"email": context.user_data['user_email'],
"items": [{
"description": price_label,
"quantity": "1.00",
"amount": {
"value": f'{price_value:.2f}',
"currency": currency_type,
},
"vat_code": 1,
}],
},
}
provider_json = json.dumps(receipt_data)
await context.bot.send_invoice(
user_id,
product_title,
product_desc,
INV_PAYLOAD,
PAY_TOKEN,
currency_type,
[LabeledPrice(price_label, price_value * 100)],
provider_data=provider_json,
reply_to_message_id=update.effective_message.id
)
I tried using Python’s logging module with DEBUG level but it only shows the API parameters, not the actual HTTP request body that gets sent to Telegram’s servers.
import logging
logging.basicConfig(
filename='debug_output.log',
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG
)
This gives me logs like this but not the raw HTTP data:
2024-09-14 13:58:53,713 - telegram.ext.ExtBot - DEBUG - Calling Bot API endpoint `sendInvoice` with parameters...
I’m thinking about switching to the requests library instead. How can I see the exact HTTP request being made?