/** * @internal * * @param string $method * @param array $params * * @return \Psr\Http\Message\ResponseInterface|string */ public function doRequest($method, $params = []) { $token = $this->telegram->getConfig()['token']; $path = ['https://api.telegram.org/', 'bot', $token, $method]; $sendAsMultiData = false; foreach ($params as $key => $value) { if ($value instanceof InputFile) { $sendAsMultiData = true; } } //TODO : Refactor this hell if ($sendAsMultiData) { return $this->postMultidata(implode('', $path), $params); } else { return $this->post(implode('', $path), $params); } }
/** * setWebhook * Use this method to specify a url and receive incoming updates via an outgoing webhook. * * @param string $url * @param InputFile $certificate * * @return array */ public function setWebhook($url = '', $certificate = null) { $params = []; if ($url) { $params['url'] = $url; } if ($certificate instanceof InputFile) { $params['certificate'] = $certificate; } $json = $this->Telegram->getNet()->doRequest('/setWebhook', $params); return json_decode($json, true); }
/** * @param Chat $chat * * @return string */ protected function getCurrentState(Chat $chat) { if (isset($this->currentState[$chat->getId()])) { return $this->currentState[$chat->getId()]; } $cacheKey = sprintf('state_%s', $chat->getId()); if ($this->telegram->getCache()->contains($cacheKey)) { return $this->telegram->getCache()->fetch($cacheKey); } else { $this->setCurrentState($chat, State::INITIAL); return State::INITIAL; } }
<?php /** * This file is part of the NeonXPTelegramApi package. * * (c) Alexander NeonXP Kiryukhin <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use NeonXP\TelegramApi\Telegram; use Doctrine\Common\Annotations\AnnotationRegistry; require_once __DIR__ . '/../vendor/autoload.php'; AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', __DIR__ . '/../vendor/jms/serializer/src'); $script = (require_once __DIR__ . '/script.php'); $cache = new \Doctrine\Common\Cache\ApcuCache(); $telegram = new Telegram(['token' => getenv('TELEGRAM_BOT_TOKEN')]); $telegram->setCache($cache); $telegram->setScript($script($telegram)); while (true) { $telegram->handleGetUpdates(); sleep(1); }