MarcL / telegram-test-bot

A test Telegram bot using serverless functions with Vercel for deployment
https://test-bot.vercel.app
28 stars 14 forks source link

Webhook works just once #1

Open ohenrydev opened 2 years ago

ohenrydev commented 2 years ago

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?

Jace254 commented 1 year ago

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

MarcL commented 1 year ago

@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 commented 1 year ago

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

opimand commented 4 months ago

The same problem @MarcL, it works only once

image
MarcL commented 4 months ago

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 commented 4 months ago

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.