/** * Process Handle bot request * * @return \Longman\TelegramBot\Telegram */ public function processUpdate(update $update) { //Load admin Commands if ($this->admin_enabled) { $message = $update->getMessage(); //$from = $message->getFrom(); //$user_id = $from->getId(); //Admin command avaiable only in single chat with the bot $chat = $message->getChat(); $user_id = $chat->getId(); if (in_array($user_id, $this->admins_list)) { $this->addCommandsPath(BASE_PATH . '/Admin'); } } DB::insertRequest($update); // check type $message = $update->getMessage(); $type = $message->getType(); switch ($type) { default: case 'text': return $this->executeCommand('Genericmessage', $update); break; case 'command': // execute command $command = $message->getCommand(); return $this->executeCommand($command, $update); break; case 'new_chat_participant': // trigger new participant return $this->executeCommand('Newchatparticipant', $update); break; case 'left_chat_participant': // trigger left chat participant return $this->executeCommand('Leftchatparticipant', $update); break; case 'new_chat_title': // trigger new_chat_title return $this->executeCommand('Newchattitle', $update); break; case 'delete_chat_photo': // trigger delete_chat_photo return $this->executeCommand('Deletechatphoto', $update); break; case 'group_chat_created': // trigger group_chat_created return $this->executeCommand('Groupchatcreated', $update); break; } }
/** * 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); }
/** * Process Handle bot request * * @return \Longman\TelegramBot\Telegram */ public function processUpdate(update $update) { $update_type = $update->getUpdateType(); if ($update_type == 'message') { //Load admin Commands if ($this->admin_enabled) { $message = $update->getMessage(); //Admin command avaiable in any chats //$from = $message->getFrom(); //$user_id = $from->getId(); //Admin command avaiable only in single chat with the bot $chat = $message->getChat(); $user_id = $chat->getId(); if (in_array($user_id, $this->admins_list)) { $this->addCommandsPath(BASE_PATH . '/Admin'); } } // check type $message = $update->getMessage(); $type = $message->getType(); switch ($type) { default: case 'Message': case 'Photo': case 'Audio': case 'Document': case 'Sticker': case 'Video': case 'Voice': case 'Location': $command = 'Genericmessage'; break; case 'command': // execute command $command = $message->getCommand(); break; case 'new_chat_participant': // trigger new participant $command = 'Newchatparticipant'; break; case 'left_chat_participant': // trigger left chat participant $command = 'Leftchatparticipant'; break; case 'new_chat_title': // trigger new_chat_title $command = 'Newchattitle'; break; case 'delete_chat_photo': // trigger delete_chat_photo $command = 'Deletechatphoto'; break; case 'group_chat_created': // trigger group_chat_created $command = 'Groupchatcreated'; break; case 'supergroup_chat_created': // trigger super_group_chat_created $command = 'Supergroupchatcreated'; break; case 'channel_chat_created': // trigger channel_chat_created $command = 'Channelchatcreated'; break; } } elseif ($update_type == 'inline_query') { $command = 'Inlinequery'; } elseif ($update_type == 'chosen_inline_result') { $command = 'Choseninlineresult'; } DB::insertRequest($update); $result = $this->executeCommand($command, $update); return $result; }