telegram-test-bot icon indicating copy to clipboard operation
telegram-test-bot copied to clipboard

Webhook works just once

Open ohenrydev opened this issue 3 years ago • 6 comments

Hi Marc, first of all I want to thank you for your repositories, they are helping me. My name is Henrique and I'm from Brazil and I'm having difficulties with the Telegram Bot using webhooks. I deployed it on Vercel, however, after setting the URL, it only works once.

I define the webhook, then use the getWebhookInfo endpoint and get the following return:

{
"ok": true,
"result": {
"url": "<my_url>",
"has_custom_certificate": false,
"pending_update_count": 0,
"max_connections": 40,
"ip_address": "<my_ip>"
}
}

However, when performing a test (deleting the message sent to the Bot), it works, and then it doesn't work anymore. it works exactly 1 time. after that, when using getWebhookInfo again, I get the following return:

{
"ok": true,
"result": {
"url": "",
"has_custom_certificate": false,
"pending_update_count": 1
}
}

my url just disappears

I didn't find anything similar in the forums, neither from Vercel nor from telegram, I'm lost, do you have any insights on this subject?

ohenrydev avatar Feb 24 '22 12:02 ohenrydev

The serverless function runs for 10 seconds and afterwards stops until it is invoked, This causes the webhook to work only once

Jace254 avatar Apr 11 '23 15:04 Jace254

@Jace254 - With a serverless function it won't be running all of the time and it should be started by an HTTP event being sent to it via the Telegram webhook. It may take more time for it to start up when it's considered "cold" (not been used for a while) but it should still respond. Have you got anything in the Vercel logs that show it being started?

MarcL avatar May 01 '23 18:05 MarcL

@ohenrydevopr - I'm really sorry - I didn't spot your comment. Have you got it working now?

MarcL avatar May 01 '23 18:05 MarcL

The same problem @MarcL, it works only once

image

opimand avatar May 02 '24 00:05 opimand

Hey @opimand! 👋

That looks like an ngrok URL - is this for local testing? Are you hitting the /api/webhook path too?

I'm using Insomnia to POST a request. Here's the message body I send to this URL https://your-ngrok-id.ngrok-free.app/api/webhook:

{
    "message": {
        "chat": {
            "id": "your-telegram-user-id"
        },
        "text": "Hello from Insomnia!"
    }
}

Or try a CURL request:

curl -X POST -H "Content-Type: application/json" -d '{"message": {"chat": {"id": "your-telegram-user-id"}, "text": "Hello from curl!"}}' https://your-ngrok-id.ngrok-free.app/api/webhook

Let me know if you're still having problems.

MarcL avatar May 02 '24 10:05 MarcL

I should add that I've redeployed to Vercel too and it responds multiple times for me. Let me know any more details and I'll help you to debug it.

I've done similar for Netlify too and I need to create a repo and blog post for that too.

MarcL avatar May 02 '24 11:05 MarcL