I have created a telegram bot and an api.
The api has been written with Nextjs 14+ and is hosted on Vercel serverless platform which gives me a url such as https:://abcde.vercel.app . Therefore my api endpoint would be accessible at https://abcde.vercel.app/api/telegram
I have set this url as my telegram bot webhook successfully using setWebhook api using postman. It was successful.
However in almost all times I don’t get a call on my webhook api endpoint from Telegram.
I have investigated it throughly and I realised that every time I call getWebhookInfo , suddenly i get all the pending messages in my api.
My guess is telegram caches the ip of my webhook url or its DNS does that. But in a serverless platform the ip changes very frequently and should not be cached. That's why the normal callback method of Telegram is not successful. It's trying to call the previous IP which is not valid anymore.
I guess whenever I call getWebhookInfo manually it refreshes the cached IP for my url in telegram somehow and therefore all the pending messages get delivered to my api endpoint.
Has anyone else experienced that? How can I fix this issue?