php—在程序中使用会话

php—在程序中使用会话,php,telegram,telegram-bot,Php,Telegram,Telegram Bot,电报信使允许程序员建立自己的机器人。 我的机器人有一个键盘。用户可以选择每个键并显示正确的响应。 在我的示例中,当用户按“mobile”或“/mobile”时,机器人的回复是新键盘:“sony”、“Nokia”、“Lg”。按下诺基亚,手机会显示正确的响应 用户还可以直接键入“Nokia”并自动回复 我的问题是: 为什么要强迫用户在按下移动键后“仅”选择诺基亚? 换句话说,当用户直接键入诺基亚时,bot会向他显示:“您需要先选择手机” $data = json_decode(file_

电报信使允许程序员建立自己的机器人。 我的机器人有一个键盘。用户可以选择每个键并显示正确的响应。 在我的示例中,当用户按“mobile”或“/mobile”时,机器人的回复是新键盘:“sony”、“Nokia”、“Lg”。按下诺基亚,手机会显示正确的响应 用户还可以直接键入“Nokia”并自动回复

我的问题是: 为什么要强迫用户在按下移动键后“仅”选择诺基亚? 换句话说,当用户直接键入诺基亚时,bot会向他显示:“您需要先选择手机”
$data       = json_decode(file_get_contents('php://input'), true);

$client     = new Zelenin\Telegram\Bot\Api($token);

$chatid     = $data['message']['chat']['id'];
$text       = $data['message']['text'];
$messageid  = $data['message']['message_id'];


if($text == "/mobile" || "mobile"){ 
        $params     = array('chat_id' => $chatid, 'action' => 'typing');
        $response   = $client -> sendChatAction($params);
                //keyboard
        $keyboard = array("sony \xF0\x9F\x93\x9E","nokia \xF0\x9F\x8E\xA5","LG \xF0\x9F\x92\xB0");
        $start_keys = array('keyboard'=>array($keyboard));
        $encodedMarkup = json_encode($start_keys);
        $message = " \xF0\x9F\x93\x8C please press correct key ...";
        $content = array('chat_id' => $chatid,'reply_markup' => $encodedMarkup,'text' => $message);
        $response   = $client -> sendMessage($content);
        $response   = $client -> forwardMessage(array('chat_id' => $agroup, 
                'message_id' => $messageid, 'from_chat_id' => $chatid));
} else {
        $params     = array('chat_id' => $chatid, 'action' => 'typing');
        $response   = $client -> sendChatAction($params);
        $message = " \xF0\x9F\x93\x8C please press ...";    
        $response   = $client -> sendMessage($content);
}
?>

您可以将名为“菜单”的字段添加到用户表中,默认设置为SelectMobile。 当用户按移动以外的键时,检查字段,如果选择了mobile,请让他这样做。当用户按mobile时,将该字段更新为SelectBrand。同样,如果用户发送的不是品牌,请告诉他需要发送指定品牌