Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param CallbackQuery $query
- * @param Telegram $telegram
- * @param Update $update
- * @return \Longman\TelegramBot\Entities\ServerResponse
- * @throws \Longman\TelegramBot\Exception\TelegramException
- */
- public function newOrder(CallbackQuery $query, Telegram $telegram, Update $update) {
- $callback_data = $query->getData();
- $message = $query->getMessage();
- $user = $message->getFrom();
- $user_id = $user->getId();
- $chat_id = $message->getChat()->getId();
- $text = $message->getText();
- if (strpos($callback_data, 'newOrder_') !== 0) {
- return Request::emptyResponse();
- }
- $current = substr($callback_data, strlen('newOrder_')); // ID услуги
- $conversation = new Conversation($user->getIsBot() ? $chat_id : $user_id, $chat_id, 'neworder');
- $notes = &$conversation->notes;
- !is_array($notes) && $notes = [];
- $state = 0;
- if (isset($notes['state'])) {
- $state = $notes['state'];
- }
- $text = $current;
- $result = Request::emptyResponse();
- switch ($state) {
- case 0:
- if ($text === '' || !is_numeric($text) || self::searchService($text) == false) {
- $notes['state'] = 0;
- $conversation->update();
- $data['text'] = 'Укажите ID услуги';
- if ($text !== '')
- $data['text'] = 'Пожалуйста, укажите ID услуги.';
- $result = Request::sendMessage($data);
- break;
- }
- $notes['order_id'] = $text;
- $text = '';
- case 1:
- if ($text === '' || !is_numeric($text)) {
- $notes['state'] = 1;
- $conversation->update();
- $data['text'] = 'OrderID: ' . $notes['order_id'];
- if ($text !== '')
- $data['text'] = 'Пожалуйста, укажите ID услуги.';
- $result = Request::sendMessage($data);
- break;
- }
- $notes['order_id '] = $text;
- $text = '';
- // no break
- case 2:
- $conversation->update();
- unset($notes['state']);
- /**
- * Выводим уведомление
- */
- $data['text'] = '✅ Сообщение успешно отправлено! Мы свяжемся с Вами в ближайшее время.';
- $data['reply_markup'] = Keyboard::remove();
- $conversation->stop();
- $result =Request::sendMessage($data);
- break;
- }
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement