G
G
Galdar Turin2021-04-17 13:25:50
Node.js
Galdar Turin, 2021-04-17 13:25:50

How to register webhook telegram?

The cart writes the answer that the webhook is deleted, this answer should be if you send an empty request

https://api.telegram.org/bot1111111:aaaaaaa/setWebhook
but I write from-data and put it in the body, it is logical to assume that I am not correctly forming from-data, who knows what the error is?
cart response

{ ok: true, result: true, description: 'Webhook is already deleted' }


code
var formdata = new FormData();
    //for( let key in body ) formdata.append( key, body[ key ] );

    formdata.append("url", "https://api.domain.ru/telegram/bot1111111:aaaaaaa");
    formdata.append("certificate", fs.readFileSync("/etc/api.domain.ru/cert.pem"), { filename: 'cert.pem' });

    console.log(formdata)

    var requestOptions = {
        method: 'POST',
        headers: { "Content-Type": "application/json" },
        body: formdata
    };

    fetch("https://api.telegram.org/bot1111111:aaaaaaa/setWebhook", requestOptions)
    .then(response => response.json())
    .then(result => console.log(result))
    .catch(error => console.log('error', error));


this request works fine through postman, but does not work on my server.
https is checked, the certificate is signed and works, if you connect through a third-party library, then the webhook works fine. But I need to write my own methods and functions with requests to the cart.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question