TelegramBots / Telegram.Bot

.NET Client for Telegram Bot API
https://telegrambots.github.io/book
MIT License
3.22k stars 691 forks source link

TelegramBotClient.SetWebhookAsync not working #880

Closed YanivHakim closed 4 years ago

YanivHakim commented 4 years ago

When calling SetWebhookASync I don't get any error and still do not recieve any webhook updates... I read all the guidelines for verified certificates and tested them all (https://core.telegram.org/bots/webhooks) . I know have a valid verfied certificate and still cannot set any web hooks... Does this works? Someone knows if this is a bug? anyone made webhooks works???

I tried with or without a pem/cer file:


InputFileStream certFile = new InputFileStream(File.OpenRead("c:\\data\\certs\\cert.cer"));

m_client.SetWebhookAsync("https://mydomain:443/telegram/realtimeupdates/", certificate: certFile, allowedUpdates: new UpdateType[0]).Wait();

m_client.SetWebhookAsync("https://mydomain:443/telegram/realtimeupdates/, allowedUpdates: new UpdateType[0]).Wait();

tuscen commented 4 years ago

Try making this request in the browser https://api.telegram.org/botYOURTOKEN/getWebhookInfo. What does it return?

YanivHakim commented 4 years ago

thanks @tuscen ! I tried it an got: {"ok":true,"result":{"url":"https://mydomain:443/telegram/realtimeupdates/Z3_bBAbmEdP3veUDHGv9HSg%3d%3d","has_custom_certificate":false,"pending_update_count":0,"max_connections":40,"allowed_updates":["message","channel_post"]}}

which looks good, but, I still don't get ANY updates to this URL. What am I missing???

tuscen commented 4 years ago

You have allowed_updates set to only channel posts. Is that what you wanted?

YanivHakim commented 4 years ago

@tuscen channel post and messages. no? "allowed_updates":["message","channel_post"] i want to receive user sent messages mainly

tuscen commented 4 years ago

I see, I missed the first entry in the array. Are you sure you're sending correct url and path? I couldn't reproduce the problem on my local machine with ngrok. Webhook worked correctly.

YanivHakim commented 4 years ago

@tuscen yes. the url and domain are good and also tested, but i don't seem to get a request from telegram to that url. It's just a regular request right? https/post with application/json content-type right?

tuscen commented 4 years ago

Correct, it's always a post request with json payload. What happens when you send some messages and then call getWebhookInfo? Does it return non-zero pending messages count?

YanivHakim commented 4 years ago

@tuscen No, I checked that... it's always 0... really frustrating

tuscen commented 4 years ago

That might mean two things: a bug in telegram bot api servers which for some reason not only prevents updates to be sent to your server, but also don't register new updates on their server (which is unlikely, too many problems at once, but who knows), or that messages are sent and your server acknowledges them with 200 OK. Maybe you configured something incorrectly? Could you show me your receiving code and your startup class (I assume you're using ASP.NET Core)? By the way, try testing your webhook locally with ngrok.

YanivHakim commented 4 years ago

@tuscen I'm not using .net core, we're using .NET framework 4+. And also I can't show you the code because it's complicated and part of a really big platform. But, I'm testing post messages to the same URL from postman and I see them entering good, but from telegram i can't see them... thanks anyway for your help, is there a way to contact Telegram and ask for support?

tuscen commented 4 years ago

In that case check if TLS 1.2 is enabled on your server with appropriate ciphers. Telegram disabled everything older than TLS 1.2. #867 might help.

YanivHakim commented 4 years ago

@tuscen Just checked and it is tls 1.2 with a trusted certificate from telegram's list

YanivHakim commented 4 years ago

@tuscen this is the URL : https://devapi.commbox.xyz/telegram/realtimeupdates/Z3_bBAbmEdP3veUDHGv9HSg%3d%3d

and this is a monitor url: https://devapi.commbox.xyz/status

if you have any idea i'll be very thankfull

tuscen commented 4 years ago

I've checked available ciphers on your domain and the required ones are seems to be enabled. I'm out of ideas what might be wrong.

karb0f0s commented 4 years ago

I’m closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version.

Please reopen if you still encounter this issue with the latest stable version and then please use the issue template.