Redirect user in Telegram Bot to an external link with POST request

Viewed 1179

Since I'm new to this POST/GET HTTP stuff, I might be getting things wrong, that's why I'll put my question in 2 ways. Maybe one way will be better than the other :)

I'm developing a Telegram Bot using PyTelegramBotAPI, and it needs to include an online payment. For the online payment I need the user to follow a link with POST method (it's an external link + I need to pass form data), but that's what causes difficulties for me.

I.

In my code I perform the following:

req = requests.post(url=url, data=data)

Where url is the URL of the website to which the client must be redirected, and data is the data that it needs to pass with the POST request when redirecting.

It works fine as a request in Python, but obviously it can't redirect the client to the website needed.

I tried to generate a URL and pass it to the client using

url = url + urlencode(data=data)

Where url is again the URL of the website. But in this case the website tells me that the method used is incorrect. I guess the link becomes a GET request, instead of a POST request.

How can I redirect the client to that link with POST method?

II.

Another way of putting this question is this:

The company which processes the online payments requires them to be performed using the following HTML form:

<form action=”https://securesandbox.webpay.by/” method="post">
    <input type=”hidden” name=”*scart” >
    <input type=”hidden” name=”wsb_storeid” value=”11111111”>
    <input type=”hidden” name=”wsb_order_num” value=”ORDER-12345678”>
    <input type=”hidden” name=”wsb_currency_id” value=”BYN”>
    <input type=”hidden” name=”wsb_version” value=”2”>
    <input type=”hidden” name=”wsb_seed” value=”1242649174”>
    <input type=”hidden” name=”wsb_signature” value=”124264917411111111ORDER-123456781BYN10123456”>
    <input type=”hidden” name=”wsb_test” value=”1”>
    <input type=”hidden” name=”wsb_invoice_item_name[0]” value=”Товар 1”>
    <input type=”hidden” name=”wsb_invoice_item_quantity[0]” value=”2”>
    <input type=”hidden” name=”wsb_invoice_item_price[0]” value=”10”>
    <input type=”hidden” name=”wsb_total” value=”10”>

    <input type="submit" value="Купить">
</form>

This would work well if I used HTML pages, but since my web app is a Telegram Bot, hence this wouldn't work. Therefore I need to generate this HTML form automatically in Python (namely, I need to change the "value" fields for every payment).

How can I imitate this HTML form in my Telegram Bot and redirect the client after some trigger?

0 Answers
Related