4

Telegram Messenger 允许程序员构建自己的 Bot。我的机器人有一个键盘。用户可以选择每个键,机器人会显示正确的响应。在我的示例中,当用户按下“mobile”或“/mobile”时,机器人回复是新键盘:“sony”、“Nokia”、“Lg”。并且通过按诺基亚,机器人显示正确的响应,用户也可以直接输入“诺基亚”并且机器人回复它

我的问题是:为什么要强制用户选择诺基亚,“仅”按手机后?换句话说,当用户直接输入诺基亚时,机器人会告诉他:“你需要先选择手机”

$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);
}
?>
4

1 回答 1

1

您可以在默认设置为 SelectMobile 的用户表中添加一个名为 menu 的字段。当用户按非移动时,检查该字段,如果是 SelectMobile,请他这样做。当用户按下移动时,将该字段更新为 SelectBrand。同样,如果用户发送的不是品牌,请告诉他他需要发送指定的品牌。

于 2017-03-17T08:46:31.700 回答