1

I set webhook my telegram bot with setwebhook method but when I send a message in bot don't take this in my URL.

    https://api.telegram.org/bot<token>/setwebhook?url=https://www.example.com/bot/temp.php

In my host I use PHP language for take and analysis and answer that. and I user this command for get updates from bot.

    $update = file_get_contents(“php://input”);

But after run this line $update is empty. I haven't problem with take updates without setwebhook bot when I use webhook don't take data.

result run getWebhookinfo is:

    {"ok":true,"result":{"url":"https://example.com/bot/temp.php","has_custom_certificate":false,"pending_update_count":0,"max_connections":40}}

Do I have to be true "has_custom_cere"? Thanks for help me

mohammad
  • 33
  • 1
  • 1
  • 7

4 Answers4

3

Mohammad, I think a PHP error occurred when telegram sends the request to you. Following code should works fine for getting the Telegram request.

$json = file_get_contents('php://input');
$request = json_decode($json);

I think your script stop before this code. I suggest you to enable PHP debug mode and check the error log.

Hossein
  • 2,592
  • 4
  • 23
  • 39
2

You can find out problem via following method:

Check getWebhookInfo method, make sure your webhook URL is correct, and no last_error_message field.

POST similar data to your server, here is some data you can use in curl -d JSON, just copy it and run on your own server.

At last, check your CDN config (if you had applied on that server), temporary disable flooding or any check.

Sean Wei
  • 7,433
  • 1
  • 19
  • 39
0

What is the outcome of the /getwebhookinfo method and could you post it here? Please check if you SSL certificate valid (happend once to me) and what shows if you call the website in your browser (any php errors?).

I would have commented that, but I don´t have enough rep... Sorry :/

creyD
  • 1,972
  • 3
  • 26
  • 55
  • SSL/TLS1.2 is accepted telegram there are in my hosting. – mohammad Apr 20 '17 at 09:47
  • Okay and the `/getwebhookinfo`says? – creyD Apr 20 '17 at 09:49
  • {"ok":true,"result":{"url":"https://example.com/bot/temp.php","has_custom_certificate":false,"pending_update_count":0,"max_connections":40}} – mohammad Apr 20 '17 at 10:01
  • I check error log but I haven't any error about this php file. :( – mohammad Apr 20 '17 at 20:41
  • What I would do in your case: Reduce the php to just send an echo (one line php), check if the api query works without the bot `/sendmessage` and check if I got everywhere the right bot token... And to answer your question: no the **custom cert doesn´t have to be true**. – creyD Apr 21 '17 at 07:25
  • you still have the problem? Did the suggestion help? @mohammad – creyD Apr 26 '17 at 09:55
0

Please follow this way and if you don't get answer, your PHP has problem :
1- Revoke your Auth Key from BotFather by typing /revoke
2- Reset your Webbhook by new Auth Key :

https://api.telegram.org/bot<token>/setWebhook?url=https://www.website.com/bot_path

Notice #1 : setWebhook is case sensitive and W keyword must be capital.
Notice #2 : If you're using CMS such as Codeigniter, Laravel, Zend etc. It doesn't need to put .php after your bot_path and if not use it.
Notice #3 : If you want to delete last Webhook that you have set, You just need to write above url without ?url= at the rest.
3- After all you receive this message from telegram :

{"ok":true,"result":true,"description":"Webhook was set"}

Now you can test your Bot, But be aware that do this way to check your Auth Key and If there is no problem, absolutely your PHP code has problem. If you have problem yet please contact me on website to solve it Graphap and then put the right answer here.
I've told to recheck this way because I had problem frequently because of Auth Key which not working But now it works as well.

Hamed
  • 565
  • 3
  • 17