Example #1
0
 /**
  * Execute single action.
  *
  * @param string|array|callable $action
  * @param Message               $message
  *
  * @return bool Is successfully executed
  */
 protected function execute($action, Message $message)
 {
     if (is_callable($action)) {
         //Callable
         $newState = call_user_func($action, $message, $this->telegram);
         if ($newState) {
             //If specified new state...
             $this->setCurrentState($message->getChat(), $newState);
             //... set it as current state
         }
         return true;
     }
     if (is_string($action)) {
         //Simple text message
         $this->telegram->getMethods()->sendMessage($message->getChat(), $action);
         return true;
     }
     if (is_array($action)) {
         //Simple text with new state
         list($text, $newState) = $action;
         $this->telegram->getMethods()->sendMessage($message->getChat(), $text);
         if ($newState) {
             //If specified new state...
             $this->setCurrentState($message->getChat(), $newState);
             //... set it as current state
         }
         return true;
     }
     return false;
 }