Longman\TelegramBot\Telegram::addCommandsPath PHP Метод

addCommandsPath() публичный Метод

Add a single custom commands path
public addCommandsPath ( string $path, boolean $before = true ) : Telegram
$path string Custom commands path to add
$before boolean If the path should be prepended or appended to the list
Результат Telegram
    public function addCommandsPath($path, $before = true)
    {
        if (!is_dir($path)) {
            TelegramLog::error('Commands path "' . $path . '" does not exist.');
        } elseif (!in_array($path, $this->commands_paths, true)) {
            if ($before) {
                array_unshift($this->commands_paths, $path);
            } else {
                $this->commands_paths[] = $path;
            }
        }
        return $this;
    }

Usage Example

Пример #1
0
    // Connect to Zabbix API.
    $api = new ZabbixApi($ZABBIX_HOST . 'api_jsonrpc.php', $ZABBIX_USER, $ZABBIX_PASSWORD);
    $api->setDefaultParams(array('output' => 'extend'));
    $triggers = $api->triggerGet(array('filter' => array('value' => 1)));
    foreach ($triggers as $trigger) {
        $errors[] = $trigger->description;
    }
} catch (Exception $e) {
    // Exception in ZabbixApi catched.
    echo $e->getMessage();
}
try {
    // create Telegram API object
    $telegram = new Telegram($API_KEY, $BOT_NAME);
    $telegram->enableMySQL($credentials);
    $telegram->addCommandsPath($COMMANDS_FOLDER);
    $telegram->setLogRequests(true);
    $telegram->setLogPath('logs/' . $BOT_NAME . '.log');
    $telegram->setLogVerbosity(3);
    if (!empty($errors)) {
        $results = Request::sendToActiveChats('sendMessage', array('text' => "[Zabbix]\nWe have a problem\n" . implode(', ', $errors)), false, true, null, null);
    }
    $ServerResponse = $telegram->handleGetUpdates();
    if ($ServerResponse->isOk()) {
        $n_update = count($ServerResponse->getResult());
        print date('Y-m-d H:i:s', time()) . ' - Processed ' . $n_update . " updates\n";
    } else {
        print date('Y-m-d H:i:s', time()) . " - Fail fetch updates\n";
        print $ServerResponse->printError() . "\n";
    }
} catch (TelegramException $e) {
All Usage Examples Of Longman\TelegramBot\Telegram::addCommandsPath