diff --git a/src/SlackDriver.php b/src/SlackDriver.php index 1b28b7d..751653e 100644 --- a/src/SlackDriver.php +++ b/src/SlackDriver.php @@ -225,9 +225,9 @@ public function buildServicePayload($message, $matchingMessage, $additionalParam public function sendPayload($payload) { if ($this->resultType == self::RESULT_TOKEN) { - return $this->http->post('https://slack.com/api/chat.postMessage', [], $payload); + return $this->http->post($this->config['base_url'] . 'chat.postMessage', [], $payload); } elseif ($this->resultType == self::RESULT_DIALOG) { - return $this->http->post('https://slack.com/api/dialog.open', [], $payload); + return $this->http->post($this->config['base_url'] . 'dialog.open', [], $payload); } return JsonResponse::create($payload)->send(); @@ -387,7 +387,7 @@ public function sendRequest($endpoint, array $parameters, IncomingMessage $match 'token' => $this->config->get('token'), ], $parameters); - return $this->http->post('https://slack.com/api/'.$endpoint, [], $parameters); + return $this->http->post($this->config['base_url'] . $endpoint, [], $parameters); } /** @@ -407,7 +407,7 @@ public function verifyRequest(Request $request) */ public function getBotUserId() { - $botUserIdRequest = $this->http->post('https://slack.com/api/auth.test', [], [ + $botUserIdRequest = $this->http->post($this->config['base_url'] . 'auth.test', [], [ 'token' => $this->config->get('token'), ]); $botUserIdPayload = new ParameterBag((array) json_decode($botUserIdRequest->getContent(), true)); @@ -423,7 +423,7 @@ public function getBotUserId() */ private function getBotId() { - $botUserRequest = $this->http->post('https://slack.com/api/users.info', [], [ + $botUserRequest = $this->http->post($this->config['base_url'] . 'users.info', [], [ 'user' => $this->botUserID, 'token' => $this->config->get('token'), ]); diff --git a/stubs/slack.php b/stubs/slack.php index 445b645..4e2272e 100644 --- a/stubs/slack.php +++ b/stubs/slack.php @@ -11,5 +11,15 @@ | */ 'token' => env('SLACK_TOKEN'), + + /* + |-------------------------------------------------------------------------- + | Slack API base url + |-------------------------------------------------------------------------- + | + | Your Slack API base url. Useful if you're using Mattermost, + | + */ + 'base_url' => env('SLACK_BASE_URL', 'https://slack.com/api/'), ]; diff --git a/tests/SlackDriverTest.php b/tests/SlackDriverTest.php index 1fde918..7d22a16 100644 --- a/tests/SlackDriverTest.php +++ b/tests/SlackDriverTest.php @@ -32,7 +32,7 @@ private function getDriver($responseData, $htmlInterface = null) $htmlInterface = m::mock(Curl::class); } - $slackConfig = ['token' => 'Foo']; + $slackConfig = ['token' => 'Foo', 'base_url' => 'https://slack.com/api/']; $response = new Response('{"ok": true,"url": "https:\/\/myteam.slack.com\/","team": "My Team","user": "cal","team_id": "T12345","user_id": "U0X12345"}'); $htmlInterface->shouldReceive('post') @@ -227,6 +227,7 @@ public function it_returns_the_user_object() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -438,6 +439,7 @@ public function it_can_reply_string_messages() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -475,6 +477,7 @@ public function it_can_reply_message_objects() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -513,6 +516,7 @@ public function it_can_reply_message_objects_with_image() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -594,6 +598,7 @@ public function it_can_reply_questions_with_additional_button_parameters() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -636,6 +641,7 @@ public function it_can_reply_questions() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -678,6 +684,7 @@ public function it_can_reply_questions_with_menus() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -720,6 +727,7 @@ public function it_can_reply_with_additional_parameters() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -770,6 +778,7 @@ public function it_can_reply_in_threads() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $html); @@ -803,6 +812,7 @@ public function it_is_configured() $driver = new SlackDriver($request, [ 'slack' => [ 'token' => 'Foo', + 'base_url' => 'https://slack.com/api/' ], ], $htmlInterface);