Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/OneSignalPayloadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
*
Expand Down
26 changes: 26 additions & 0 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
16 changes: 16 additions & 0 deletions tests/NotifiableIncludesExternalIds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace NotificationChannels\OneSignal\Test;

class NotifiableIncludesExternalIds
{
use \Illuminate\Notifications\Notifiable;

/**
* @return array
*/
public function routeNotificationForOneSignal()
{
return ['include_external_user_ids' => ['external_id']];
}
}