diff --git a/docs/CreateNotificationSuccessResponse.md b/docs/CreateNotificationSuccessResponse.md index 3c715fc..1979319 100644 --- a/docs/CreateNotificationSuccessResponse.md +++ b/docs/CreateNotificationSuccessResponse.md @@ -4,7 +4,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**id** | **str** | 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** | **str** | 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** | **str, none_type** | 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** | **bool, date, datetime, dict, float, int, list, str, none_type** | 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] **any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] diff --git a/onesignal/helpers.py b/onesignal/helpers.py index 45a85a8..f44c150 100644 --- a/onesignal/helpers.py +++ b/onesignal/helpers.py @@ -96,3 +96,30 @@ def create_notification_with_retry(api, notification, max_retries=3, base_delay= if delay > 0: time.sleep(delay) attempt += 1 + + +def is_message_sent(response): + """Return True when a POST /notifications 200 response is the "message + sent" branch -- a notification was created and ``id`` is a non-empty string. + + 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 response: a ``CreateNotificationSuccessResponse`` + :return: True if a notification was created + """ + notification_id = getattr(response, 'id', None) + return isinstance(notification_id, str) and len(notification_id) > 0 + + +def is_message_not_sent(response): + """Return True when a POST /notifications 200 response is the "message not + sent" branch -- no notification was created (``id`` is absent or empty); + inspect ``errors`` for why. + + :param response: a ``CreateNotificationSuccessResponse`` + :return: True if no notification was created + """ + return not is_message_sent(response) diff --git a/onesignal/model/create_notification_success_response.py b/onesignal/model/create_notification_success_response.py index 4065ce0..e2a74d0 100644 --- a/onesignal/model/create_notification_success_response.py +++ b/onesignal/model/create_notification_success_response.py @@ -139,7 +139,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) - id (str): 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] # noqa: E501 + id (str): 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] # noqa: E501 external_id (str, none_type): 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] # noqa: E501 errors (bool, date, datetime, dict, float, int, list, str, none_type): 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] # noqa: E501 """ @@ -227,7 +227,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 Animal class but this time we won't travel through its discriminator because we passed in _visited_composed_classes = (Animal,) - id (str): 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] # noqa: E501 + id (str): 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] # noqa: E501 external_id (str, none_type): 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] # noqa: E501 errors (bool, date, datetime, dict, float, int, list, str, none_type): 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] # noqa: E501 """