Telegram bot开发,机器人第一次拉进群组会报错
机器人第一次拉入群组的时候会报错,显示获取不到用户发的信息
$path = "https://api.telegram.org/botMytoken";
$update = json_decode(file_get_contents("php://input"), TRUE);
$id = $update["update_id"];
$chatId = $update["message"]["chat"]["id"];
$username = $update["message"]["from"]["username"];
$message = $update["message"]["text"];
会显示获取不到 message 或者 text ,我用的 webhook,然后等pending_update_count为0,就可以正常用了,这是什么原因?
而且现在用 webhook 有个弊端,如果有报错,就会一直卡着,必须等推送完报错才能用机器人
我前一陣子也接入過 telegram bot
用的是 botman 套件 botman.io/
我在前端做一個 Enable Notification 的按鈕來把 Bot 加入 Telegram Channel
你可以試一下,這個套件整合的挺好的
後端生成 Verification Key 來驗証
驗証成功就把 chat_id 儲存起來