diff --git a/docs/Model/CreateNotificationSuccessResponse.md b/docs/Model/CreateNotificationSuccessResponse.md index c130cf7..3167525 100644 --- a/docs/Model/CreateNotificationSuccessResponse.md +++ b/docs/Model/CreateNotificationSuccessResponse.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**id** | **string** | Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). | [optional] +**id** | **string** | Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). All OneSignal server SDKs expose message-sent / message-not-sent narrowing helpers (named idiomatically per language — e.g. `isMessageSent`, `is_message_sent`, `message_sent?`); prefer them over comparing `id` directly. | [optional] **external_id** | **string** | Optional correlation / idempotency-related value from the API response. This is not the end-user External ID used for targeting recipients (that lives under `include_aliases.external_id`). | [optional] **errors** | **mixed** | Polymorphic field: may be an array of human-readable strings and/or an object (for example with `invalid_aliases`, `invalid_external_user_ids`, or `invalid_player_ids`) depending on the API response; HTTP may still be 200 with partial success. Typed SDKs model this loosely so both shapes deserialize. | [optional] diff --git a/lib/helpers/NotificationHelpers.php b/lib/helpers/NotificationHelpers.php index d17345c..d21029f 100644 --- a/lib/helpers/NotificationHelpers.php +++ b/lib/helpers/NotificationHelpers.php @@ -74,6 +74,41 @@ public static function createNotificationWithRetry($api, $notification, $maxRetr } } + /** + * Whether a POST /notifications 200 response is the "message sent" branch. + * + * POST /notifications returns 200 in two cases that share the + * CreateNotificationSuccessResponse shape: a notification was created + * (non-empty id), or none was (empty id, with errors carrying the reason). + * Prefer this guard over inspecting id directly. + * + * @param \onesignal\client\model\CreateNotificationSuccessResponse $response + * + * @return bool true when a notification was created + */ + public static function isMessageSent($response) + { + if ($response === null) { + return false; + } + $id = $response->getId(); + return is_string($id) && $id !== ''; + } + + /** + * Whether a POST /notifications 200 response is the "message not sent" + * branch -- no notification was created (id absent or empty); inspect + * errors for why. + * + * @param \onesignal\client\model\CreateNotificationSuccessResponse $response + * + * @return bool true when no notification was created + */ + public static function isMessageNotSent($response) + { + return !self::isMessageSent($response); + } + private static function headerValue($headers, $name) { if (!is_array($headers)) { diff --git a/lib/model/CreateNotificationSuccessResponse.php b/lib/model/CreateNotificationSuccessResponse.php index 3ca89af..1d55a9d 100644 --- a/lib/model/CreateNotificationSuccessResponse.php +++ b/lib/model/CreateNotificationSuccessResponse.php @@ -231,7 +231,7 @@ public function getId() /** * Sets id * - * @param string|null $id Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). + * @param string|null $id Notification identifier when the request created a notification. An empty string means no notification was created; read `errors` for details (HTTP may still be 200). All OneSignal server SDKs expose message-sent / message-not-sent narrowing helpers (named idiomatically per language — e.g. `isMessageSent`, `is_message_sent`, `message_sent?`); prefer them over comparing `id` directly. * * @return self */