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
80 changes: 72 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ See [API reference](https://activitysmith.com/docs/api-reference/introduction).
- [Start & Update Live Activity](#start--update-live-activity)
- [End Live Activity](#end-live-activity)
- [Live Activity Action](#live-activity-action)
- [Icons and Badges](#icons-and-badges)
- [Live Activity Colors](#live-activity-colors)
- [Channels](#channels)
- [Widgets](#widgets)

Expand All @@ -35,6 +37,7 @@ composer require activitysmith/activitysmith
declare(strict_types=1);

use ActivitySmith\ActivitySmith;
use ActivitySmith\LiveActivities;
use ActivitySmith\LiveActivityAction;
use ActivitySmith\LiveActivityAlertBadge;
use ActivitySmith\LiveActivityAlertIcon;
Expand Down Expand Up @@ -258,14 +261,6 @@ $activitysmith->liveActivities->stream(
);
```

The `icon` symbol value is an Apple SF Symbol name. Browse the catalog with one of these tools:

- [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
- [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
- [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography

`icon` and `badge` are optional. If you omit either one, that element is not shown in the Live Activity.

### End Live Activity

Call `endStream(...)` with the same `streamKey` to dismiss the Live Activity. You can include final values before it is removed. By default, iOS removes the Live Activity after two minutes. Set `autoDismissMinutes` to choose a different dismissal time, including `0` for immediate dismissal.
Expand Down Expand Up @@ -346,6 +341,75 @@ $activitysmith->liveActivities->stream(
);
```

### Icons and Badges

Add more context to Live Activities with icons and badges.

#### Icon

Supported Live Activity types: `stats`, `metrics`, `progress`, `segmented_progress`, and `alert`.

<p align="center">
<img
src="https://cdn.activitysmith.com/features/metrics-live-activity-with-icon.png"
alt="Metrics Live Activity with an SF Symbol icon on the iPhone Lock Screen"
width="680"
/>
</p>

```php
$activitysmith->liveActivities->stream(
'prod-web-1',
contentState: LiveActivityContentState::make(
title: 'Server Health',
subtitle: 'prod-web-1',
type: LiveActivities::TYPE_METRICS,
icon: LiveActivityAlertIcon::make(symbol: 'server.rack', color: 'blue'),
metrics: [
LiveActivityMetric::make(label: 'CPU', value: 18, unit: '%'),
LiveActivityMetric::make(label: 'MEM', value: 42, unit: '%'),
],
),
);
```

The `icon` symbol value is an Apple SF Symbol name. Browse the catalog with one of these tools:

- [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
- [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
- [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography

#### Badge

Badges are supported by `alert`, `progress`, and `segmented_progress` Live Activities.

<p align="center">
<img
src="https://cdn.activitysmith.com/features/progress-live-activity-with-badge.png"
alt="Progress Live Activity with a badge on the iPhone Lock Screen"
width="680"
/>
</p>

```php
$activitysmith->liveActivities->stream(
'nightly-database-backup',
contentState: LiveActivityContentState::make(
title: 'Nightly Database Backup',
subtitle: 'verify restore',
type: LiveActivities::TYPE_PROGRESS,
badge: LiveActivityAlertBadge::make(title: 'S3', color: 'cyan'),
percentage: 62,
),
);
```

### Live Activity Colors

Choose from these colors for the Live Activity accent, including progress bars and action buttons, or apply them to an individual icon or badge:

`lime`, `green`, `cyan`, `blue`, `purple`, `magenta`, `red`, `orange`, `yellow`, `gray`

## Channels

Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.
Expand Down
6 changes: 3 additions & 3 deletions generated/Model/ContentStateEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* ContentStateEnd Class Doc Comment
*
* @category Class
* @description End payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics and stats include a non-empty metrics array. For alert include message, with optional icon and badge. Type is optional when ending an existing activity. You can send an updated number_of_steps here if the workflow changed after start.
* @description End payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics and stats include a non-empty metrics array. For alert include message. Optional icon is supported by all Live Activity types. Optional badge is supported by alert, progress, and segmented_progress. Type is optional when ending an existing activity. You can send an updated number_of_steps here if the workflow changed after start.
* @package ActivitySmith\Generated
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
Expand Down Expand Up @@ -857,7 +857,7 @@ public function getIcon()
/**
* Sets icon
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
*
* @return self
*/
Expand All @@ -884,7 +884,7 @@ public function getBadge()
/**
* Sets badge
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge. Supported by alert, progress, and segmented_progress.
*
* @return self
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/Model/ContentStateStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* ContentStateStart Class Doc Comment
*
* @category Class
* @description Start payload requires title and type. For segmented_progress include number_of_steps and current_step. For progress include percentage or value with upper_limit. For metrics and stats include a non-empty metrics array. For alert include message, with optional icon and badge. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls.
* @description Start payload requires title and type. For segmented_progress include number_of_steps and current_step. For progress include percentage or value with upper_limit. For metrics and stats include a non-empty metrics array. For alert include message. Optional icon is supported by all Live Activity types. Optional badge is supported by alert, progress, and segmented_progress. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls.
* @package ActivitySmith\Generated
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
Expand Down Expand Up @@ -849,7 +849,7 @@ public function getIcon()
/**
* Sets icon
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
*
* @return self
*/
Expand All @@ -876,7 +876,7 @@ public function getBadge()
/**
* Sets badge
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge. Supported by alert, progress, and segmented_progress.
*
* @return self
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/Model/ContentStateUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* ContentStateUpdate Class Doc Comment
*
* @category Class
* @description Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics and stats include a non-empty metrics array. For alert include message, with optional icon and badge. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
* @description Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics and stats include a non-empty metrics array. For alert include message. Optional icon is supported by all Live Activity types. Optional badge is supported by alert, progress, and segmented_progress. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
* @package ActivitySmith\Generated
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
Expand Down Expand Up @@ -846,7 +846,7 @@ public function getIcon()
/**
* Sets icon
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
*
* @return self
*/
Expand All @@ -873,7 +873,7 @@ public function getBadge()
/**
* Sets badge
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge. Supported by alert, progress, and segmented_progress.
*
* @return self
*/
Expand Down
24 changes: 15 additions & 9 deletions generated/Model/LiveActivityAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,15 @@ public function listInvalidProperties()
if ($this->container['url'] === null) {
$invalidProperties[] = "'url' can't be null";
}
if (!preg_match("/^https:\/\//", $this->container['url'])) {
$invalidProperties[] = "invalid value for 'url', must be conform to the pattern /^https:\/\//.";
if ($this->container['url'] !== null) {
$actionType = $this->container['type'];
if ($actionType === LiveActivityActionType::OPEN_URL && !preg_match('/^(https|shortcuts):\/\//', (string) $this->container['url'])) {
$invalidProperties[] = "invalid value for 'url', open_url must use https or shortcuts.";
}
if ($actionType === LiveActivityActionType::WEBHOOK && !preg_match('/^https:\/\//', (string) $this->container['url'])) {
$invalidProperties[] = "invalid value for 'url', webhook must use https.";
}
}

return $invalidProperties;
}

Expand Down Expand Up @@ -398,7 +403,7 @@ public function getUrl()
/**
* Sets url
*
* @param string $url HTTPS URL. For open_url it is opened in browser. For webhook it is called by ActivitySmith backend.
* @param string $url Action URL. For open_url, use an HTTPS or shortcuts:// URL. For webhook, use an HTTPS URL called by the ActivitySmith backend.
*
* @return self
*/
Expand All @@ -407,11 +412,13 @@ public function setUrl($url)
if (is_null($url)) {
throw new \InvalidArgumentException('non-nullable url cannot be null');
}

if ((!preg_match("/^https:\/\//", ObjectSerializer::toString($url)))) {
throw new \InvalidArgumentException("invalid value for \$url when calling LiveActivityAction., must conform to the pattern /^https:\/\//.");
$actionType = $this->container['type'] ?? null;
if ($actionType === LiveActivityActionType::OPEN_URL && !preg_match('/^(https|shortcuts):\/\//', (string) $url)) {
throw new \InvalidArgumentException("invalid value for \$url when calling LiveActivityAction., open_url must use https or shortcuts.");
}
if ($actionType === LiveActivityActionType::WEBHOOK && !preg_match('/^https:\/\//', (string) $url)) {
throw new \InvalidArgumentException("invalid value for \$url when calling LiveActivityAction., webhook must use https.");
}

$this->container['url'] = $url;

return $this;
Expand Down Expand Up @@ -561,4 +568,3 @@ public function toHeaderValue()
}
}


2 changes: 1 addition & 1 deletion generated/Model/LiveActivityAlertBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* LiveActivityAlertBadge Class Doc Comment
*
* @category Class
* @description Optional badge for Alert Live Activities.
* @description Optional badge for Live Activities.
* @package ActivitySmith\Generated
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
Expand Down
2 changes: 1 addition & 1 deletion generated/Model/LiveActivityAlertIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* LiveActivityAlertIcon Class Doc Comment
*
* @category Class
* @description Optional SF Symbol icon for Alert Live Activities.
* @description Optional SF Symbol icon for Live Activities.
* @package ActivitySmith\Generated
* @author OpenAPI Generator team
* @link https://openapi-generator.tech
Expand Down
24 changes: 15 additions & 9 deletions generated/Model/PushNotificationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,15 @@ public function listInvalidProperties()
if ($this->container['url'] === null) {
$invalidProperties[] = "'url' can't be null";
}
if (!preg_match("/^https:\/\//", $this->container['url'])) {
$invalidProperties[] = "invalid value for 'url', must be conform to the pattern /^https:\/\//.";
if ($this->container['url'] !== null) {
$actionType = $this->container['type'];
if ($actionType === PushNotificationActionType::OPEN_URL && !preg_match('/^(https|shortcuts):\/\//', (string) $this->container['url'])) {
$invalidProperties[] = "invalid value for 'url', open_url must use https or shortcuts.";
}
if ($actionType === PushNotificationActionType::WEBHOOK && !preg_match('/^https:\/\//', (string) $this->container['url'])) {
$invalidProperties[] = "invalid value for 'url', webhook must use https.";
}
}

return $invalidProperties;
}

Expand Down Expand Up @@ -397,7 +402,7 @@ public function getUrl()
/**
* Sets url
*
* @param string $url HTTPS URL. For open_url it is opened in browser. For webhook it is called by ActivitySmith backend.
* @param string $url Action URL. For open_url, use an HTTPS or shortcuts:// URL. For webhook, use an HTTPS URL called by the ActivitySmith backend.
*
* @return self
*/
Expand All @@ -406,11 +411,13 @@ public function setUrl($url)
if (is_null($url)) {
throw new \InvalidArgumentException('non-nullable url cannot be null');
}

if ((!preg_match("/^https:\/\//", ObjectSerializer::toString($url)))) {
throw new \InvalidArgumentException("invalid value for \$url when calling PushNotificationAction., must conform to the pattern /^https:\/\//.");
$actionType = $this->container['type'] ?? null;
if ($actionType === PushNotificationActionType::OPEN_URL && !preg_match('/^(https|shortcuts):\/\//', (string) $url)) {
throw new \InvalidArgumentException("invalid value for \$url when calling PushNotificationAction., open_url must use https or shortcuts.");
}
if ($actionType === PushNotificationActionType::WEBHOOK && !preg_match('/^https:\/\//', (string) $url)) {
throw new \InvalidArgumentException("invalid value for \$url when calling PushNotificationAction., webhook must use https.");
}

$this->container['url'] = $url;

return $this;
Expand Down Expand Up @@ -560,4 +567,3 @@ public function toHeaderValue()
}
}


10 changes: 5 additions & 5 deletions generated/Model/PushNotificationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ public function listInvalidProperties()
$invalidProperties[] = "invalid value for 'media', must be conform to the pattern /^https:\/\//.";
}

if (!is_null($this->container['redirection']) && !preg_match("/^https:\/\//", $this->container['redirection'])) {
$invalidProperties[] = "invalid value for 'redirection', must be conform to the pattern /^https:\/\//.";
if (!is_null($this->container['redirection']) && !preg_match("/^(https|shortcuts):\/\//", $this->container['redirection'])) {
$invalidProperties[] = "invalid value for 'redirection', must be conform to the pattern /^(https|shortcuts):\/\//.";
}

if (!is_null($this->container['actions']) && (count($this->container['actions']) > 4)) {
Expand Down Expand Up @@ -493,7 +493,7 @@ public function getRedirection()
/**
* Sets redirection
*
* @param string|null $redirection Optional HTTPS URL opened when user taps the notification body. Overrides the default tap target from `media` when both are provided.
* @param string|null $redirection Optional HTTPS or shortcuts:// URL opened when user taps the notification body. Overrides the default tap target from `media` when both are provided.
*
* @return self
*/
Expand All @@ -503,8 +503,8 @@ public function setRedirection($redirection)
throw new \InvalidArgumentException('non-nullable redirection cannot be null');
}

if ((!preg_match("/^https:\/\//", ObjectSerializer::toString($redirection)))) {
throw new \InvalidArgumentException("invalid value for \$redirection when calling PushNotificationRequest., must conform to the pattern /^https:\/\//.");
if ((!preg_match("/^(https|shortcuts):\/\//", ObjectSerializer::toString($redirection)))) {
throw new \InvalidArgumentException("invalid value for \$redirection when calling PushNotificationRequest., must conform to the pattern /^(https|shortcuts):\/\//.");
}

$this->container['redirection'] = $redirection;
Expand Down
4 changes: 2 additions & 2 deletions generated/Model/StreamContentState.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ public function getIcon()
/**
* Sets icon
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertIcon|null $icon Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
*
* @return self
*/
Expand All @@ -1042,7 +1042,7 @@ public function getBadge()
/**
* Sets badge
*
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge for type=alert.
* @param \ActivitySmith\Generated\Model\LiveActivityAlertBadge|null $badge Optional badge. Supported by alert, progress, and segmented_progress.
*
* @return self
*/
Expand Down
1 change: 1 addition & 0 deletions src/LiveActivityColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ final class LiveActivityColor
public const RED = 'red';
public const ORANGE = 'orange';
public const YELLOW = 'yellow';
public const GRAY = 'gray';
}
Loading