public function testKeyboard() { $keyboard = ReplyKeyboardEntry::create()->addRow([KeyboardButtonEntry::create('first_line_1'), KeyboardButtonEntry::create('first_line_2')])->addRow([KeyboardButtonEntry::create('contact', true)])->addRow([KeyboardButtonEntry::create('location', false, true)])->setResizeKeyboard(true)->setSelective(false)->setOneTimeKeyboard(true); /** @var MessageEntry $message */ $message = MessageEntry::create()->text($this->faker->text)->to(self::CHAT_ID)->withReplyKeyboard($keyboard); $this->bot->sendMessage($message); $message->hideReplyKeyboard(); $this->bot->sendMessage($message); $this->bot->sendTextMessage(self::CHAT_ID, $this->faker->text); }
/** * @param string $message * @param bool $forwarded */ public function reply($message, $forwarded = false) { $this->bot->getApi()->sendMessage($this->chat->id, $message, null, $forwarded ? $this->message->message_id : null, null); }
$this->movies($message); break; } } catch (\Exception $e) { echo 'Something bad happened'; } } protected function say($el) { if ($text = str_replace(self::SAY_COMMAND, '', $el['message']['text'])) { $cinemas = Crawler::findCinemas($this->google_movies_endpoint . '?near=' . urlencode($text)); //creazione tastiera $content = array('chat_id' => $el['message']['chat']['id'], 'reply_markup' => json_encode(array('keyboard' => $cinemas)), 'text' => "Ecco i cinema di" . $text); $res = $this->httpPost(sprintf($this->base_api . $this->send_message_api, $this->getToken()), $content); } } protected function movies($el) { if ($cinema_name = str_replace(self::GET_PROGRAMMAZIONE_COMMAND, '', $el['message']['text'])) { if (isset($el['message']['reply_to_message'])) { if ($city_name = str_replace(self::SAY_COMMAND, '', $el['message']['reply_to_message']['text'])) { $movies = Crawler::findMovies($this->google_movies_endpoint . '?near=' . urlencode($city_name), strtolower($cinema_name)); $content = array('chat_id' => $el['message']['chat']['id'], 'reply_markup' => json_encode(array('keyboard' => array("A", "B"))), 'text' => "Ecco la programmazione"); $res = $this->httpPost(sprintf($this->base_api . $this->send_message_api, $this->getToken()), $content); } } } } } $tb = new Bot(); $result = $tb->process();