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
예제 #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) {
 /**
  * setUp
  */
 public function setUp()
 {
     $this->telegram = new Telegram('apikey', 'testbot');
     $this->telegram->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands');
     $this->telegram->getCommandsList();
 }