Longman\TelegramBot\DB::insertRequest PHP Method

insertRequest() public static method

Insert request into database
public static insertRequest ( Update $update ) : boolean
$update Longman\TelegramBot\Entities\Update
return boolean
    public static function insertRequest(Update $update)
    {
        $update_id = $update->getUpdateId();
        $update_type = $update->getUpdateType();
        if ($update_type === 'message') {
            $message = $update->getMessage();
            if (self::insertMessageRequest($message)) {
                $message_id = $message->getMessageId();
                $chat_id = $message->getChat()->getId();
                return self::insertTelegramUpdate($update_id, $chat_id, $message_id, null, null, null, null);
            }
        } elseif ($update_type === 'inline_query') {
            $inline_query = $update->getInlineQuery();
            if (self::insertInlineQueryRequest($inline_query)) {
                $inline_query_id = $inline_query->getId();
                return self::insertTelegramUpdate($update_id, null, null, $inline_query_id, null, null, null);
            }
        } elseif ($update_type === 'chosen_inline_result') {
            $chosen_inline_result = $update->getChosenInlineResult();
            if (self::insertChosenInlineResultRequest($chosen_inline_result)) {
                $chosen_inline_result_local_id = self::$pdo->lastInsertId();
                return self::insertTelegramUpdate($update_id, null, null, null, $chosen_inline_result_local_id, null, null);
            }
        } elseif ($update_type === 'callback_query') {
            $callback_query = $update->getCallbackQuery();
            if (self::insertCallbackQueryRequest($callback_query)) {
                $callback_query_id = $callback_query->getId();
                return self::insertTelegramUpdate($update_id, null, null, null, null, $callback_query_id, null);
            }
        } elseif ($update_type === 'edited_message') {
            $edited_message = $update->getEditedMessage();
            if (self::insertEditedMessageRequest($edited_message)) {
                $chat_id = $edited_message->getChat()->getId();
                $edited_message_local_id = self::$pdo->lastInsertId();
                return self::insertTelegramUpdate($update_id, $chat_id, null, null, null, null, $edited_message_local_id);
            }
        }
        return false;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * 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;
     }
 }
All Usage Examples Of Longman\TelegramBot\DB::insertRequest