Longman\TelegramBot\Entities\Update::getUpdateType PHP Method

getUpdateType() public method

Get the update type based on the set properties
public getUpdateType ( ) : string | null
return string | null
    public function getUpdateType()
    {
        $types = ['message', 'edited_message', 'inline_query', 'chosen_inline_result', 'callback_query'];
        foreach ($types as $type) {
            if ($this->getProperty($type)) {
                return $type;
            }
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * Process bot Update request
  *
  * @param Entities\Update $update
  *
  * @return Entities\ServerResponse
  */
 public function processUpdate(Update $update)
 {
     $this->update = $update;
     //If all else fails, it's a generic message.
     $command = 'genericmessage';
     $update_type = $this->update->getUpdateType();
     if (in_array($update_type, ['inline_query', 'chosen_inline_result', 'callback_query', 'edited_message'])) {
         $command = $this->getCommandFromType($update_type);
     } elseif ($update_type === 'message') {
         $message = $this->update->getMessage();
         //Load admin commands
         if ($this->isAdmin()) {
             $this->addCommandsPath(BASE_COMMANDS_PATH . '/AdminCommands', false);
         }
         $this->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands', false);
         $type = $message->getType();
         if ($type === 'command') {
             $command = $message->getCommand();
         } elseif (in_array($type, ['channel_chat_created', 'delete_chat_photo', 'group_chat_created', 'left_chat_member', 'migrate_from_chat_id', 'migrate_to_chat_id', 'new_chat_member', 'new_chat_photo', 'new_chat_title', 'supergroup_chat_created'])) {
             $command = $this->getCommandFromType($type);
         }
     }
     //Make sure we have an up-to-date command list
     //This is necessary to "require" all the necessary command files!
     $this->getCommandsList();
     DB::insertRequest($this->update);
     return $this->executeCommand($command);
 }
All Usage Examples Of Longman\TelegramBot\Entities\Update::getUpdateType