I develop simple telegram bot with php and host it on koding but telegram doesn't trigger my webhook; why ?!
how to debug webhook?
below code is my bot.
require_once "vendor/autoload.php";
use Telegram\Bot\Api;
$telegram=new Api('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
if (isset($_GET['hook'])){
$msg=$telegram->setWebhook([
"url" => "https://umkk50a5b157.mohsenti.koding.io/phpBot/index.php",
"certificate" => "/etc/apache2/ssl/apache.crt"
]);
echo json_encode($msg)."<br>";
echo "setup webhook ok";
exit;
}
if(isset($_GET['uhook'])){
$telegram->removeWebhook();
echo "remove webhook ok";
exit;
}
if(isset($_GET['debug'])){
$fp=fopen('debug.txt','r');
while($read=fread($fp,4096))
echo $read;
fclose($fp);
echo "debug end";
exit;
}
$updates=$telegram->getWebhookUpdates();
$fp=fopen('debug.txt','w');
fwrite($fp,"hello");
fwrite($fp,json_encode($updates));
fclose($fp);
foreach($updates as $update) {
$telegram->sendMessage([
'chat_id' => $update->getMessage()->getChat()->getId(),
'text' => "bot received : " . $update->getMessage()->getText()
]);
}
I save request message to a file and send debug request to bot php file to read what's sent by telegram and hook to set webhook and uhook to unset hook.
thank you