为什么电报没有触发我注册的webhook?

时间:2016-01-07 15:42:45

标签: php debugging telegram-bot

我使用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来取消挂钩。

谢谢

1 个答案:

答案 0 :(得分:1)

  1. 安装ZEND DEBUGGER
  2. 安装ZEND St​​udio
  3. 将“debug_host = 127.0.0.1&amp; start_debug = 1&amp; debug_port = 10137&amp; debug_stop = 1”添加到电报挂钩中
  4. 通过电报发送消息 - 您的Zend Studio将自动停止DEBUG
  5. 与IIS的Testet !!!

    示例

    https://elron.elropro.com/xxxx/telegramhook.php?debug_host=127.0.0.1&start_debug=1&debug_port=10137&debug_stop=1