Telegram bot Inline键盘发送过多回调PHP

时间:2017-07-20 08:29:06

标签: php telegram-bot

问题是我在我的机器人中使用内联键盘。当我试图推动这个键盘时,它给了我3-5个回调。我不知道我的错误在哪里。

EDIT
我不知道为什么但是当我使用mysqli-> fetch_assoc()时会导致这个错误;

我使用内置键盘时没有完整的代码和平

 if ($callback_data!=Null){
        checkJSON(3124,$order_id);
        $message_id = $update['callback_query']['message']['message_id'];
        $callback_data = json_decode($callback_data,true);
        checkJSON(3125,$callback_data["order_id"]);
        $order_id = $callback_data["order_id"];
        checkJSON(3126,$order_id);
        $rs = $mysqli->query("SELECT manager_id FROM orders WHERE id=".$order_id);
        $row = $rs->fetch_assoc();
        $manager = $row['manager_id'];

        if ($manager!=Null){
            $rs = $mysqli->query("SELECT telegram_id FROM managers WHERE id=".$manager);
            $row = $rs->fetch_assoc();
            $manager_telegram_id = $row['telegram_id'];
            if ($chatID==$manager_telegram_id){
                $callback_data = json_decode($callback_data);
                $order_id = $callback_data["order_id"];
                $status = $callback_data["status"];
                checkJSON(1231234,$callback_data);
                if($status == '3'){
                    editMessage($chatID,$message_id,"Заказ N".$order_id." подтвержден");
                }
                else{
                    editMessage($chatID,$message_id,"Заказ N".$order_id." отклонен");
                }
                $mysqli->query("UPDATE orders SET status=".$status." WHERE id=".$order_id);
            }
            sendMessage($chatID,$update['callback_query']['message']['message_id']);
            editMessage($chatID,$message_id,
            "Данный заказ уже в оброботке");

        }
        else{
            $get_manager_query = $mysqli->query("SELECT id FROM managers WHERE telegram_id=".$chatID);
            $row = $get_manager_query->fetch_assoc();
            $manager = $row['id'];

            $data1 = json_encode(array("order_id"=>$order_id,"status"=>3));
            $data2 = json_encode(array("order_id"=>$order_id,"status"=>4));
            $inline_button1 = array("text"=>"Принять","callback_data"=>$data1);
            $inline_button2 = array("text"=>"Отказать","callback_data"=>$data2);
            $inline_keyboard = [[$inline_button1,$inline_button2]];
            $keyboard=json_encode(array("inline_keyboard"=>$inline_keyboard));
            editMessage($chatID,$message_id,
                "Вы приняли данный заказ",$keyboard);
            $rs = $mysqli->query("UPDATE orders SET status=1, manager_id=".$manager." WHERE id=".$order_id);
        }

}
    function sendMessage($chatID,$text){
    $sendto =API_URL."sendmessage?chat_id=".$chatID."&text=".urlencode($text);
    file_get_contents($sendto);
}
function editMessage($chatId, $messageId, $message,$replyMarkup=Null) {

    $url = API_URL."editMessageText?chat_id=".$chatId."&message_id=".$messageId.
        "&text=".urlencode($message)."&reply_markup=".$replyMarkup;
    file_get_contents($url);

}

1 个答案:

答案 0 :(得分:1)

这不是你的错! Telegram Server在内联查询中发送myObj.myEvent |> Observable.SubscribeWeakly ...的回调 您可以使用myObj.myEvent.SubscribeWeakly ...命令在every changes中将其设置为关闭 有关更多信息,请访问this