Skip to content

Feat: Add OneSignal push provider adapter (#7726)#131

Open
deepshekhardas wants to merge 2 commits into
utopia-php:mainfrom
deepshekhardas:feat/7726-onesignal-adapter
Open

Feat: Add OneSignal push provider adapter (#7726)#131
deepshekhardas wants to merge 2 commits into
utopia-php:mainfrom
deepshekhardas:feat/7726-onesignal-adapter

Conversation

@deepshekhardas

Copy link
Copy Markdown

No description provided.

@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a OneSignal push notification adapter that maps the shared Push message contract to OneSignal's v1 REST API, batching up to 2000 recipients per request.

  • The adapter correctly calls parent::__construct(), maps Android fields (icon, color, tag), badge, image attachments, priority, and data payload to their OneSignal equivalents.
  • The error-response branch unsafely accesses $results['response']['errors'][0] without first checking that $results['response'] is an array; when a non-JSON body is returned (e.g., an HTML 5xx from a proxy), PHP string-offset access silently produces a garbage single-character error string rather than falling back to 'Unknown error'.
  • The content_available branch writes a hardcoded true regardless of the caller's boolean value, so a message constructed with contentAvailable: false still enables background/silent push on device.

Confidence Score: 3/5

The adapter is functional for happy-path delivery but has two defects in the error-handling and content_available branches that produce incorrect output rather than failing gracefully.

The unsafe response parsing in the error path corrupts every recipient's error message when OneSignal (or an intervening proxy) returns a non-JSON body, turning actionable error strings into a single garbage character. The content_available branch independently ignores the caller's boolean and always enables silent/background push, which inverts the caller's intent when they explicitly pass false. Both defects are in the changed file and affect observable output.

Files Needing Attention: src/Utopia/Messaging/Adapter/Push/OneSignal.php — error-response parsing (line 112-114) and content_available handling (line 84-85) need fixes before merging.

Important Files Changed

Filename Overview
src/Utopia/Messaging/Adapter/Push/OneSignal.php New OneSignal push adapter — correctly calls parent constructor, maps most Push fields, and handles priority; error-response parsing is unsafe when the body is non-JSON, and content_available is always forced to true regardless of the caller's boolean value.
tests/Messaging/Adapter/Push/OneSignalTest.php Minimal integration test that delegates to the shared push Base suite; reads credentials from environment variables, no issues.

Reviews (5): Last reviewed commit: "fix: add parent constructor, fix deliver..." | Re-trigger Greptile

Comment thread src/Utopia/Messaging/Adapter/Push/OneSignal.php
Comment thread src/Utopia/Messaging/Adapter/Push/OneSignal.php
Comment thread src/Utopia/Messaging/Adapter/Push/OneSignal.php
Comment thread src/Utopia/Messaging/Adapter/Push/OneSignal.php
Comment on lines +65 to +68
if (!\is_null($message->getSound())) {
$payload['android_sound'] = $message->getSound();
$payload['ios_sound'] = $message->getSound() . '.wav';
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Do not rewrite sounds

Other push adapters pass the message sound through unchanged, and callers may pass values like default or an already-qualified filename. Appending .wav here changes default to default.wav and chime.wav to chime.wav.wav, which can make iOS use the wrong sound or no custom sound at all.

Suggested change
if (!\is_null($message->getSound())) {
$payload['android_sound'] = $message->getSound();
$payload['ios_sound'] = $message->getSound() . '.wav';
}
if (!\is_null($message->getSound())) {
$payload['android_sound'] = $message->getSound();
$payload['ios_sound'] = $message->getSound();
}

Comment thread src/Utopia/Messaging/Adapter/Push/OneSignal.php
Comment thread src/Utopia/Messaging/Adapter/Push/OneSignal.php Outdated
Comment on lines +84 to +86
if (!\is_null($message->getContentAvailable())) {
$payload['content_available'] = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 content_available condition inverts intent when explicitly set to false

The guard !\is_null($message->getContentAvailable()) is true for both true and false. If a caller explicitly constructs Push with contentAvailable: false, the adapter still writes 'content_available' => true into the payload, silently enabling silent/background push on OneSignal devices when the caller's intent was the opposite. The fix is to check the boolean value directly: if ($message->getContentAvailable()).

@deepshekhardas

Copy link
Copy Markdown
Author

Following up - OneSignal push adapter. Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant