Sending push notifications
Closed this issue · 2 comments
RaedElNABOULSI commented
How do I send a push notification to all users, or to a specific segment?
dbitsdanish commented
How do I send a push notification to all users, or to a specific segment?
Here is the helper function I use to send notification to targeted devices
<?php
use Illuminate\Support\Facades\Log;
use Ladumor\OneSignal\OneSignal;
if (!function_exists('sendNotification')) {
function sendNotification(array $deviceIds, string $title, string $subtitle = null, array $data = [])
{
try {
$fields['include_player_ids'] = $deviceIds;
$fields['headings'] = array(
'en' => $title,
);
if ($subtitle) {
$fields['contents'] = array(
"en" => $subtitle,
);
}
if (!empty($data)) {
$fields['data'] = $data;
}
return OneSignal::sendPush($fields);
} catch (Exception $e) {
Log::error('Send Notification Failed: ' . $e->getMessage());
}
}
}
shailesh-ladumor commented
@RaedElNABOULSI you just need to set param like this $fields['included_segments'] = ["Subscribed Users"]
instead of include_player_ids
here