Telegram messenger允许程序员构建自己的机器人。我的机器人有一个键盘。用户可以选择每个按键和机器人显示适当的反应。在我的例子中,当用户按下"mobile“或"/mobile”时,机器人的回复是新键盘:“索尼”、“诺基亚”、"Lg“。通过按下nokia,机器人可以显示正确的响应,用户也可以直接输入"Nokia“,机器人也可以回复它
我的问题是:为什么要强迫用户选择诺基亚,“只”在按下手机之后?也就是说,当用户直接输入诺基亚时,机器人会显示:“你需要先选择手机”。
$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);
}
?>发布于 2017-03-17 16:46:32
您可以将名为menu的字段添加到users表中,默认设置为SelectMobile。当用户按除mobile以外的键时,请勾选该字段,如果是SelectMobile,则要求他这样做。当用户按下mobile时,将该字段更新为SelectBrand。同样,如果用户发送的不是品牌,则告诉他需要发送指定的品牌。
https://stackoverflow.com/questions/33665250
复制相似问题