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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.14.0

Adds the ability to replace a Push Notification you already sent with a new one.

## 1.13.0

Adds custom icons and interruption levels for Push Notifications. Set `icon` to show a service logo or avatar on the notification, and `interruption_level` to deliver it as `passive`, `active`, or `time-sensitive`.
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ activitysmith.notifications.send(
)
```

### Replace a Push Notification

Every send returns a `notification_id`. Pass it to `replace` to update a Push Notification you already sent, for example when an incident you alerted on is resolved. The replacement takes the old notification's place on the Lock Screen and in history instead of stacking a second one. It arrives silently, without sound or waking the screen, and goes to the same recipients as the original.

Omit `metadata` or `tags` to keep their stored values.

```python
sent = activitysmith.notifications.send(
title="🚨 checkout-api is down",
message="500 errors on 62% of requests.",
)

activitysmith.notifications.replace(
sent.notification_id,
title="✅ checkout-api recovered",
message="Error rate is back to normal. Incident resolved.",
)
```

## Live Activities

Choose the Live Activity type that matches what you want to show:
Expand Down
45 changes: 44 additions & 1 deletion activitysmith/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from .normalization import normalize_live_activity_request, normalize_metric_request

SDK_VERSION = "1.13.0"
SDK_VERSION = "1.14.0"
SDK_HEADER_NAME = "X-ActivitySmith-SDK"
SDK_HEADER_VALUE = f"python-v{SDK_VERSION}"

Expand Down Expand Up @@ -437,6 +437,49 @@ def send(
def send_push_notification(self, push_notification_request: Any | None = None, **fields: Any):
return self.send(push_notification_request, **fields)

def replace(
self,
notification_id: str,
request: Any | None = None,
*,
title: Any | None = None,
message: Any | None = None,
subtitle: Any | None = None,
media: Any | None = None,
redirection: Any | None = None,
actions: Any | None = None,
tags: Any | None = None,
metadata: Any | None = None,
icon: Any | None = None,
):
"""Silently replace a sent Push Notification, using the notification_id returned by send()."""
request = _build_push_request(
request,
title=title,
message=message,
subtitle=subtitle,
media=media,
redirection=redirection,
actions=actions,
tags=tags,
metadata=metadata,
icon=icon,
)
normalized = normalize_metadata_request(_validate_push_request(request))
return self._api.replace_push_notification(
notification_id=notification_id,
push_notification_replace_request=normalized,
)

# Generated-style alias.
def replace_push_notification(
self,
notification_id: str,
push_notification_replace_request: Any | None = None,
**fields: Any,
):
return self.replace(notification_id, push_notification_replace_request, **fields)


class LiveActivitiesResource:
TYPE_SEGMENTED_PROGRESS = "segmented_progress"
Expand Down
2 changes: 2 additions & 0 deletions activitysmith_openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
from activitysmith_openapi.models.push_interruption_level import PushInterruptionLevel
from activitysmith_openapi.models.push_notification_action import PushNotificationAction
from activitysmith_openapi.models.push_notification_action_type import PushNotificationActionType
from activitysmith_openapi.models.push_notification_replace_request import PushNotificationReplaceRequest
from activitysmith_openapi.models.push_notification_replace_response import PushNotificationReplaceResponse
from activitysmith_openapi.models.push_notification_request import PushNotificationRequest
from activitysmith_openapi.models.push_notification_response import PushNotificationResponse
from activitysmith_openapi.models.push_notification_webhook_method import PushNotificationWebhookMethod
Expand Down
Loading
Loading