getCache()->save("link_{$message->getChat()->getId()}", $message->getText()); $telegram->getMethods()->sendMessage($message->getChat(), 'Ок, записал: ' . $message->getText()); return State::INITIAL; }; $showLink = function (Message $message, Telegram $telegram) { $link = $telegram->getCache()->fetch("link_{$message->getChat()->getId()}"); if (!$link) { $link = 'Ссылка не задана! Используй /setlink'; } $telegram->getMethods()->sendMessage($message->getChat(), $link); return State::INITIAL; }; $sendCode = function (Message $message, Telegram $telegram) use ($dozorApi) { $code = trim(substr($message->getText(),1)); $result = false; try { $result = $dozorApi->sendCode($message->getChat(), $code); }catch (\Exception $e) { $telegram->getMethods()->sendMessage($message->getChat(), 'Ошибка сети', true); } if ($result) { $telegram->getMethods()->sendMessage($message->getChat(), $result, true); } return State::INITIAL; //Set initial state }; $goBack = function (Message $message, Telegram $telegram) { return State::INITIAL; }; $pause = function (Message $message, Telegram $telegram) { return 'STATE_PAUSE'; }; return (new Script($telegram))-> state(State::INITIAL)-> //Start initial state action(new isText('/link'), $showLink)-> action(new isText('/setlink'), [ 'Пришлите ссылку с пином /cancel', 'STATE_SET_LINK' ])-> action(new isText('/pause'), [ 'Замер. /resume для возврата', 'STATE_PAUSE' ])-> action(new isMatch('/^\!.+?$/i'), $sendCode)-> action(new isAnyText(), $goBack)-> end()-> state('STATE_SET_LINK')-> action(new isText('/cancel'), $goBack)-> action(new isAnyText(), $saveLink)-> end()-> state('STATE_PAUSE')-> action(new isText('/resume'), ['Я вернулся!', State::INITIAL])-> action(new isAnyText(), $pause)-> end(); } }