设置 WebHook

设置漫游器隐私(可选

发送/setprivacy@BotFather

设置 WebHook

访问https://api.telegram.org/bot{my_bot_token}/setWebhook?url={url_to_send_updates_to}

WebHook 地址需要 https 协议

查看当前 WebHook 设置

访问https://api.telegram.org/bot{my_bot_token}/getWebhookInfo

PHP 处理 WebHook

 1<?php define('BOT_TOKEN', 'my_bot_token');
 2define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
 3// read incoming info and grab the chatID
 4$content = file_get_contents("php://input");
 5$update = json_decode($content, true);
 6$chatID = $update["message"]["chat"]["id"];
 7$got_message = $update["message"]["text"];
 8// compose reply
 9$reply =  $got_message;  // send reply
10$sendto =API_URL."sendMessage?chat_id=".$chatID."&text=".$reply;file_get_contents($sendto);