我使用php开发简单的电报机器人并将其托管在koding上但是电报没有触发我的webhook;为什么?!
如何调试webhook?
下面的代码是我的机器人。
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()
]);
}
我将请求消息保存到文件中并将调试请求发送到bot php文件,以读取通过电报和挂钩发送的内容以设置webhook和uhook来取消挂钩。
谢谢
答案 0 :(得分:1)
与IIS的Testet !!!
示例