From fd899cecfcf9db12e2fd22c0d7646299aa0baa4e Mon Sep 17 00:00:00 2001 From: Adam Burton Date: Mon, 14 May 2018 09:33:50 +0100 Subject: [PATCH 1/3] Update slack.php --- stubs/slack.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stubs/slack.php b/stubs/slack.php index 445b645..d208d82 100644 --- a/stubs/slack.php +++ b/stubs/slack.php @@ -11,5 +11,15 @@ | */ 'token' => env('SLACK_TOKEN'), + + /* + |-------------------------------------------------------------------------- + | Slack API endpoint + |-------------------------------------------------------------------------- + | + | Your Slack API endpoint. Useful if you're using Mattermost, + | + */ + 'endpoint' => env('SLACK_ENDPOINT'), ]; From 94d68328bc138e2715597082bfd91ade64c7e2bb Mon Sep 17 00:00:00 2001 From: Adam Burton Date: Mon, 14 May 2018 09:46:24 +0100 Subject: [PATCH 2/3] Allow configuration of API base url for Slack driver --- src/SlackDriver.php | 10 +++++----- stubs/slack.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) 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 d208d82..4e2272e 100644 --- a/stubs/slack.php +++ b/stubs/slack.php @@ -14,12 +14,12 @@ /* |-------------------------------------------------------------------------- - | Slack API endpoint + | Slack API base url |-------------------------------------------------------------------------- | - | Your Slack API endpoint. Useful if you're using Mattermost, + | Your Slack API base url. Useful if you're using Mattermost, | */ - 'endpoint' => env('SLACK_ENDPOINT'), + 'base_url' => env('SLACK_BASE_URL', 'https://slack.com/api/'), ]; From 5d89e490268981b2956bf0364ac596915058fa39 Mon Sep 17 00:00:00 2001 From: Adam Burton Date: Mon, 14 May 2018 09:59:38 +0100 Subject: [PATCH 3/3] Add base_url to tests --- tests/SlackDriverTest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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);