protected function rtmStart(Bot $bot) { $this->logger->debug('Try rtm.start for bot ' . $bot->id . ' with token ' . $bot->bot_token); $response = $this->curl->get('https://slack.com/api/rtm.start', ['token' => $bot->bot_token, 'simple_latest' => 1, 'no_unreads' => 1, 'mpim_aware' => 1]); if (empty($response) || !is_object($response)) { throw new \Exception(); } if (!empty($response->ok)) { $this->logger->debug('Success rtm.start for bot ' . $bot->id . ' with token ' . $bot->bot_token); return $response; } else { if ($this->isTokenError($response->error)) { throw new InvalidTokenException($response->error); } $this->logger->err('Fail rtm.start for bot ' . $bot->id . ' with token ' . $bot->bot_token . ' error:' . $response->error); throw new \Exception(); } }
use Bot2Hook\Logger; $config = (require __DIR__ . '/../../app/bootstrap.php'); if (!$config['debug']) { exit('Only in debug'); } header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); $logger = new Logger($config['logger']); $signature = new \Bot2Hook\Signature($config['signature_key']); $uri = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; if ($_SERVER['SERVER_PORT'] != '80') { $uri .= ':' . $_SERVER['SERVER_PORT']; } $uri .= $_SERVER['SCRIPT_NAME']; $b2h_signature = empty($_SERVER['HTTP_X_BOT2HOOK_SIGNATURE']) ? '' : $_SERVER['HTTP_X_BOT2HOOK_SIGNATURE']; $request = $_SERVER['REQUEST_METHOD'] == 'GET' ? $_GET : $_POST; try { if (!$signature->isValid($b2h_signature, $uri, $request)) { throw new \Exception('not_valid_signature'); } if (!isset($request['webhook_event'])) { throw new \Exception('No webhook_event in incoming web hook'); } $logger->debug("Sample webhook event received: \n" . json_encode(json_decode($request['webhook_event']), JSON_PRETTY_PRINT)); echo json_encode(['ok' => true]); } catch (\Exception $e) { $logger->err("Sample webhook error: " . $e->getMessage() . "\n" . json_encode($request) . "\n"); $logger->err("Sample webhook error trace: " . $e->getTraceAsString()); http_response_code(400); echo json_encode(['error' => $e->getMessage()]); }
error_log("[CLI] Empty task provided in '{$caller}'\n", 3, DIR_LOGS . '/error-cli.log'); exit(1); } use Bot2Hook\Consumer\Incoming; use Bot2Hook\Consumer\Outgoing; use Bot2Hook\Logger; use Bot2Hook\Rabbitmq; $config = (require __DIR__ . '/../app/bootstrap.php'); $logger = new Logger($config['logger']); $rabbitmq = new Rabbitmq($config['rabbitmq']); try { switch ($task) { case 'b2h_outgoing': $body = $argv[2]; $retry = isset($argv[3]) ? $argv[3] : 0; $logger->debug('Boot2Hook consume outgoing queue'); $outgoing = new Outgoing($config['server'], $rabbitmq, $logger, $config['signature_key']); $outgoing->process($body, $retry); break; case 'b2h_incoming': $body = $argv[2]; $retry = isset($argv[3]) ? $argv[3] : 0; $logger->debug('Boot2Hook consume incoming queue'); $incoming = new Incoming($config['server'], $rabbitmq, $logger); $incoming->process($body, $retry); break; default: error_log("[CLI] Unknwon task '{$task}'\n", 3, DIR_LOGS . '/error-cli.log'); exit(1); } } catch (\Exception $e) {