Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for defining API base url, defaulting to Slack #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/SlackDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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));
Expand All @@ -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'),
]);
Expand Down
10 changes: 10 additions & 0 deletions stubs/slack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/'),

];
12 changes: 11 additions & 1 deletion tests/SlackDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -636,6 +641,7 @@ public function it_can_reply_questions()
$driver = new SlackDriver($request, [
'slack' => [
'token' => 'Foo',
'base_url' => 'https://slack.com/api/'
],
], $html);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -803,6 +812,7 @@ public function it_is_configured()
$driver = new SlackDriver($request, [
'slack' => [
'token' => 'Foo',
'base_url' => 'https://slack.com/api/'
],
], $htmlInterface);

Expand Down