Skip to content

Commit

Permalink
Handle false unfurl flags correctly (#30)
Browse files Browse the repository at this point in the history
* Handle false unfurl flags correctly

$unfurlOptions['links'] = false;
empty($unfurlOptions['links']) === true;

The issue is that if links are set to false(to unfurl) they never get sent to the API

* Update SlackApiServiceTest.php

* use isset instead
  • Loading branch information
lucidlogic authored May 27, 2023
1 parent 8144cd1 commit 262be3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Services/SlackApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ protected function buildMessageOptions(array $options): array
if (!empty($options['unfurl'])) {
$unfurlOptions = $options['unfurl'];

if (!empty($unfurlOptions['media'])) $payload['unfurl_media'] = $unfurlOptions['media'];
if (!empty($unfurlOptions['links'])) $payload['unfurl_links'] = $unfurlOptions['links'];
if (isset($unfurlOptions['media'])) $payload['unfurl_media'] = $unfurlOptions['media'];
if (isset($unfurlOptions['links'])) $payload['unfurl_links'] = $unfurlOptions['links'];
}

if (!empty($options['thread'])) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Services/SlackApiServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function sendTextMessageOptionsDataProvider(): array
],
'unfurl' => [
'media' => true,
'links' => true,
'links' => false,
],
'thread' => [
'ts' => 'test',
Expand All @@ -383,7 +383,7 @@ public function sendTextMessageOptionsDataProvider(): array
'username' => 'Test User',
'icon_url' => 'https://example.com',
'unfurl_media' => true,
'unfurl_links' => true,
'unfurl_links' => false,
'thread_ts' => 'test',
'reply_broadcast' => true,
'mrkdwn' => true,
Expand Down

0 comments on commit 262be3d

Please sign in to comment.