/** * Initialises the client and loads Configuration. * * @param array $args Array of initialisation arguments */ protected function init($args) { $botConfig = $this->getBotConfig($args); if (!$botConfig) { Output::log(new Fatal("Config should be specified!")); } $config = new Config($botConfig); $this->timeout = $config->getTimeout(); $this->executor = Handler::getInstance(); $this->executor->initWithConfig($config); }
/** * Returns url for request to Telegram's bot API * * @param string $methodName The name of Telegram's method to query * @param null|string $args String with arguments to pass to the method via GET * * @return string */ protected function buildUrl($methodName, $args = null) { $url = sprintf('%s/%s%s/%s', $this->config->getUrl(), Config::BOT_PREFIX, $this->config->getToken(), $methodName); if (!empty($args)) { $url .= '?' . $args; } return $url; }
/** * Returns mapped event class from the configuration (if it was previously defined) * * @param AbstractEntity $entity Entity for which the corresponding event should be triggered * be treated as a command * @return null|string */ protected function getEventClass(AbstractEntity $entity) { $preDefinedEvents = $this->config->getEvents(); $entityEventType = $entity->getEntityType(); if (!is_array($preDefinedEvents)) { return null; } foreach ($preDefinedEvents as $preDefinedEvent) { if ($preDefinedEvent['type'] == $entityEventType) { $className = $preDefinedEvent['class']; if ($entity instanceof MessageEntity && $entity->isCommand()) { if (!$this->isCommandSupported($preDefinedEvent, $entity->getCommand())) { continue; } } if (class_exists($className)) { return $className; } } } return null; }