3
votes

I've already read the few questions about bot API, but can't find a solution.

My bot works fine without setting a webhook and processing /getUpdates. But I can't get it working setting "https://www.domain.com/page.php" as webhook.

I've got a shared hosting behind Cloudflare's Flexible SSL cert and browsers doesn't warn about it, so I assume it's working fine.

I'm trying to get Telegram's POST to a file to have a clue if webhook need diferent parsing, but it is empty and can't see ssl_acces.log, so I can't even watch if Telegram reach the page...

Here is the snippet:

$message = json_decode(file_get_contents('php://input'), true);
file_put_contents('telegram.txt', var_dump($message));

What am I doing wrong? Thanks.

[SOLUTION]

The way to log is:

$debug = file_get_contents('php://input');
$fp = fopen('debug.txt', 'w');
fwrite($fp, $debug);
fclose($fp);

And the solution is that the webhook must be set without wwww: /setwebhook?url=https://domain.com/page.php

1
Also tried: $debug = file_get_contents('php://input'); $fp = fopen('debug.txt', 'w'); fwrite($fp, $debug); fclose($fp); - edumgui
$message = json_decode($_POST, true); file_put_contents('telegram.txt', $message); why don't you try that way? Telegram webhook seems to be making a POST request. - Ugur
Done @Ugur. Thanks but, no luck. I'm sending messages to my bot, but txt files are not showing... I think that Telegram is not reaching the page, but I don't know how to test it. If I try /getUpdates only says that is active: {"ok":false,"error_code":409,"description":"Error: Conflict: another webhook is active"} - edumgui
You can try to reach the page on your own and see if it is generating output. Also as the error message describes, web hook is not reaching your page at all. - Ugur
@Ugur, did you tried it? Reading de API I think the message is saying that a webhook is set. If not, /getUpdates will show a json. Maybe I'm wrong... - edumgui

1 Answers

-2
votes

I had a similar issue, and fixed it removing a line

 (RewriteCond %{HTTP_USER_AGENT} ^$ [OR]) 

from the .htaccess file