diff --git a/src/OneSignalPayloadFactory.php b/src/OneSignalPayloadFactory.php index 6367b8e..398ccc9 100644 --- a/src/OneSignalPayloadFactory.php +++ b/src/OneSignalPayloadFactory.php @@ -33,6 +33,8 @@ public static function make($notifiable, Notification $notification, $targeting) $payload['included_segments'] = collect($targeting['included_segments']); } elseif (static::isTargetingExcludedSegments($targeting)) { $payload['excluded_segments'] = collect($targeting['excluded_segments']); + } elseif (static::isTargetingExternalUserIds($targeting)) { + $payload['include_external_user_ids'] = collect($targeting['include_external_user_ids']); } else { $payload['include_player_ids'] = collect($targeting); } @@ -50,6 +52,16 @@ protected static function isTargetingIncludedSegments($targeting) return is_array($targeting) && array_key_exists('included_segments', $targeting); } + /** + * @param mixed $targeting + * + * @return bool + */ + protected static function isTargetingExternalUserIds($targeting) + { + return is_array($targeting) && array_key_exists('include_external_user_ids', $targeting); + } + /** * @param mixed $targeting * diff --git a/tests/ChannelTest.php b/tests/ChannelTest.php index ada7e4c..3e711db 100644 --- a/tests/ChannelTest.php +++ b/tests/ChannelTest.php @@ -235,6 +235,32 @@ public function it_can_send_a_notification_with_multiple_tags() $this->assertInstanceOf(ResponseInterface::class, $channel_response); } + /** + * @test + */ + public function it_can_send_a_notification_with_external_ids() + { + $response = new Response(200); + + $this->oneSignal->shouldReceive('sendNotificationCustom') + ->once() + ->with([ + 'contents' => ['en' => 'Body'], + 'headings' => ['en' => 'Subject'], + 'url' => 'URL', + 'chrome_web_icon' => 'Icon', + 'chrome_icon' => 'Icon', + 'adm_small_icon' => 'Icon', + 'small_icon' => 'Icon', + 'include_external_user_ids' => collect(['external_id']), + ]) + ->andReturn($response); + + $channel_response = $this->channel->send(new NotifiableIncludesExternalIds(), new TestNotification()); + + $this->assertInstanceOf(ResponseInterface::class, $channel_response); + } + /** @test */ public function it_sends_nothing_and_returns_null_when_player_id_empty() { diff --git a/tests/NotifiableIncludesExternalIds.php b/tests/NotifiableIncludesExternalIds.php new file mode 100644 index 0000000..39f5a88 --- /dev/null +++ b/tests/NotifiableIncludesExternalIds.php @@ -0,0 +1,16 @@ + ['external_id']]; + } +}