Telegram\Bot\Api::commandsHandler PHP Method

commandsHandler() public method

Processes Inbound Commands.
public commandsHandler ( boolean $webhook = false ) : Update | Update[]
$webhook boolean
return Telegram\Bot\Objects\Update | Telegram\Bot\Objects\Update[]
    public function commandsHandler($webhook = false)
    {
        if ($webhook) {
            $update = $this->getWebhookUpdates();
            $this->processCommand($update);
            return $update;
        }
        $updates = $this->getUpdates();
        $highestId = -1;
        foreach ($updates as $update) {
            $highestId = $update->getUpdateId();
            $this->processCommand($update);
        }
        //An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
        if ($highestId != -1) {
            $params = [];
            $params['offset'] = $highestId + 1;
            $params['limit'] = 1;
            $this->markUpdateAsRead($params);
        }
        return $updates;
    }

Usage Example

Example #1
0
unset($acheck['message']['message_id']);
unset($acheck['message']['from']);
unset($acheck['message']['chat']);
unset($acheck['message']['date']);
foreach ($commands as $command) {
    $command = substr_replace($command, '', 0, 7);
    $command = substr_replace($command, '', -4);
    $telegram->addCommand('Commands\\' . $command);
}
foreach ($acheck['message'] as $vc => $avalue) {
    switch ($vc) {
        case "text":
            if ($arup['message']['text'][0] != "/") {
                $telegram->sendMessage($arup['message']['chat']['id'], $lang['error_command']);
            } else {
                $telegram->commandsHandler(true);
            }
            break;
        case "photo":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_photo']);
            break;
        case "voice":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_voice']);
            break;
        case "audio":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_audio']);
            break;
        case "document":
            $telegram->sendMessage($arup['message']['chat']['id'], $lang['recv_document']);
            break;
        case "sticker":
All Usage Examples Of Telegram\Bot\Api::commandsHandler