Rust
Use the ActivitySmith Rust SDK to send Push Notifications and Live Activity progress updates from Rust services, workers, and Laravel Rust apps.
Installation#
Install the ActivitySmith Rust SDK with Cargo:
cargo add activitysmithQuickstart#
- Create an API key
- Pass the API key into
ActivitySmith::new.
use activitysmith::*;#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { let api_key = std::env::var("ACTIVITYSMITH_API_KEY")?; let activitysmith = ActivitySmith::new(api_key)?; let notification = PushNotification::new("Hello from Rust 🦀"); activitysmith.notifications.send(notification).await?; Ok(())}The examples use tokio and serde_json. The ones below run in an async function that returns a Result, with these imports:
use activitysmith::*;use serde_json::json;Building with Laravel Rust? Use the Laravel Rust SDK, which adds notification channels and works with Laravel's test fakes.
Push Notifications#
Send a Push Notification#
Send an immediate notification for a completed task or event.
let notification = PushNotification::new("New subscription 💸") .message("Customer upgraded to Pro plan");activitysmith.notifications.send(notification).await?;Custom Push Notification Icons#
Set icon to a publicly accessible HTTPS image URL to show a logo or avatar alongside a smaller ActivitySmith app icon. Host the image anywhere, such as on your own website or CDN. With a custom icon, iOS may omit the subtitle from the notification.
let notification = PushNotification::new("MRR just crossed $10,000 🎉") .message("Up 18% this month from 31 new subscriptions.") .icon("https://example.com/icons/stripe.png");activitysmith.notifications.send(notification).await?;Rich Push Notifications with Media#
let notification = PushNotification::new("Homepage ready") .message("Your agent finished the redesign.") .media("https://cdn.example.com/output/homepage-v2.png");activitysmith.notifications.send(notification).await?;Attach images, videos, or audio to your Push Notifications. Press and hold the notification to preview the media.
What will work:
- direct image URL:
.jpg,.png,.gif, etc. - direct audio file URL:
.mp3,.m4a, etc. - direct video file URL:
.mp4,.mov, etc. - URL that responds with a proper media
Content-Type, even if the path has no extension
media cannot be combined with action.
Push Notifications with Redirection#
Open a web page, run an iOS Shortcut, or open an app when someone taps the notification. redirection supports:
- HTTP/HTTPS: Web pages, e.g.
https://example.com - Shortcuts: Run Jarvis with
shortcuts://run-shortcut?name=Jarvis - App deep links: Installed apps or specific content within them
- Spotify: A track, e.g.
spotify:track:6rqhFgbbKwnb9MLmUQDhG6 - Termius:
termius://to open the app - Claude:
claude://codeto open the Code tab - ChatGPT:
chatgpt://to open the app
- Spotify: A track, e.g.
let notification = PushNotification::new("Homepage ready") .message("Your agent finished the redesign.") .redirection("https://github.com/acme/web/pull/482");activitysmith.notifications.send(notification).await?;Actionable Push Notifications#
open_url actions open a web page, run an iOS Shortcut, or open an app when someone taps the button. Supported links:
- HTTP/HTTPS: Web pages, e.g.
https://example.com - Shortcuts: Run Jarvis with
shortcuts://run-shortcut?name=Jarvis - App deep links: Installed apps or specific content within them
- Spotify: A track, e.g.
spotify:track:6rqhFgbbKwnb9MLmUQDhG6 - Termius:
termius://to open the app - Claude:
claude://codeto open the Code tab - ChatGPT:
chatgpt://to open the app
- Spotify: A track, e.g.
Webhooks are executed by the ActivitySmith backend and must use HTTPS.
let notification = PushNotification::new("New subscription 💸") .message("Customer upgraded to Pro plan") .action(PushNotificationAction::open_url( "Open CRM", "https://crm.example.com/customers/cus_9f3a1d", )) .action(PushNotificationAction::open_url( "Chat with Jarvis", "shortcuts://run-shortcut?name=Jarvis", )) .action( PushNotificationAction::webhook( "Start Onboarding Workflow", "https://hooks.example.com/activitysmith/onboarding/start", ) .method(WebhookMethod::Post) .body(json!({ "customer_id": "cus_9f3a1d", "plan": "pro" })), );activitysmith.notifications.send(notification).await?;Interruption Levels#
Use interruption_level to choose how urgently iOS presents a Push Notification. Omit it for normal delivery. Explicit InterruptionLevel::Active has the same behavior as the default.
| Value | Behavior |
|---|---|
InterruptionLevel::Passive | Appears quietly in the notification list, without sound or waking the screen. |
InterruptionLevel::Active | Normal delivery, subject to the device's notification settings and Focus. This is the default. |
InterruptionLevel::TimeSensitive | Can bypass Scheduled Summary and Focus when the user allows Time Sensitive Notifications for ActivitySmith. |
See Apple's interruption levels for the system behavior.
Passive#
let notification = PushNotification::new("Daily summary") .message("All scheduled jobs completed successfully.") .interruption_level(InterruptionLevel::Passive);activitysmith.notifications.send(notification).await?;Active (default)#
let notification = PushNotification::new("Deployment complete") .message("Your latest changes are live.") .interruption_level(InterruptionLevel::Active);activitysmith.notifications.send(notification).await?;Removing the interruption level from this example produces the same delivery behavior.
Time Sensitive#
let notification = PushNotification::new("🚨 checkout-api is down") .message("500 errors on 62% of requests.") .interruption_level(InterruptionLevel::TimeSensitive);activitysmith.notifications.send(notification).await?;Push Notification Sounds#
Use sound to choose the sound a Push Notification plays. Omit it to play the Push Notifications sound picked in the ActivitySmith app under Settings > Sounds.
| Value | Behavior |
|---|---|
default | Plays the sound picked on the device. This is the same as omitting sound. |
none | Plays no sound. |
| A sound name | Plays one of the sounds bundled with the app: arrive, bell, bells, bitflip, bloom, callout, chime, coin, corrupt, crest, cue, ding, drop, ember, emblem, flourish, glimmer, glint, glitch, lantern, nightfall, nudge, pixel, pop, signal, streak, tally, wand, whoosh, or zip. |
Passive Push Notifications play no sound.
let notification = PushNotification::new("💸 New sale") .message("Pro plan, $29/month") .sound("coin");activitysmith.notifications.send(notification).await?;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.
let alert = PushNotification::new("🚨 checkout-api is down") .message("500 errors on 62% of requests.");let sent = activitysmith.notifications.send(alert).await?;let recovered = PushNotificationReplacement::new( "✅ checkout-api recovered",).message("Error rate is back to normal. Incident resolved.");if let Some(id) = &sent.notification_id { activitysmith.notifications.replace(id, recovered).await?;}Dismiss a Push Notification#
Pass the notification_id to dismiss when a Push Notification no longer needs attention, for example after you answered an agent's question somewhere else.
Dismissing clears it from the Lock Screen and Notification Center on every device it was sent to. History keeps it.
Devices clear the notification in the background, so it can take a moment.
let question = PushNotification::new("🙋 Agent needs your input") .message("Approve the database migration?");let sent = activitysmith.notifications.send(question).await?;if let Some(id) = &sent.notification_id { activitysmith.notifications.dismiss(id).await?;}Live Activities#
Choose the Live Activity type that matches what you want to show:
Value
Show a single value on your Lock Screen, such as revenue, a queue count, or a temperature.
Stats
Show up to 8 labeled values on your Lock Screen, from revenue and orders to uptime and conversion.
Alert
Show status updates with a clear message, badge, and icon. When you add an action button, color controls the button tint.
Metrics
Track two related values with segmented bars, such as CPU and memory.
Segmented Progress
Show progress through a known set of steps, like build, test, deploy, and verify.
Progress
Show percentage progress for jobs that move continuously toward completion.
Timer
Count down from a duration, or count up from 00:00 while a job runs.
Start & Update Live Activity#
Use a stable stream key to identify the metric, job, deployment, or system you want to keep visible. The first stream call starts the Live Activity. Later calls with the same stream key update it.
Value#
let state = ContentState::value("Revenue", "$1,240") .color(Color::Green) .icon(Icon::new("dollarsign.circle").color(Color::Green)) .badge(Badge::new("↑ 18%").color(Color::Purple));activitysmith.live_activities.stream("revenue-today", state).await?;Send a string or number in value. Strings keep their formatting, including currency symbols, units, and decimal places.
Stats#
let state = ContentState::stats( "Sales", [ ActivityMetric::new("Revenue", "$2430").color(Color::Blue), ActivityMetric::new("Orders", "37").color(Color::Green), ActivityMetric::new("Conversion", "4.8%").color(Color::Magenta), ActivityMetric::new("Avg Order", "$65.68").color(Color::Yellow), ActivityMetric::new("Refunds", "$84").color(Color::Red), ActivityMetric::new("New Buyers", "18").color(Color::Cyan), ],).subtitle("last hour");activitysmith.live_activities.stream("sales-hourly", state).await?;Alert#
let state = ContentState::alert( "Reactivation", "Lumen came back after 2 weeks",).icon(Icon::new("cloud.sun").color(Color::Yellow)).badge(Badge::new("Customer").color(Color::Magenta));activitysmith.live_activities.stream("customer-ops", state).await?;Metrics#
let state = ContentState::metrics( "Server Health", [ ActivityMetric::new("CPU", 9).unit("%"), ActivityMetric::new("MEM", 45).unit("%"), ],).subtitle("prod-web-1");activitysmith.live_activities.stream("prod-web-1", state).await?;Segmented Progress#
// Step 2 of 3let state = ContentState::segmented_progress("Nightly Backup", 2, 3) .subtitle("upload archive");activitysmith.live_activities.stream("nightly-backup", state).await?;Progress#
let state = ContentState::progress("Search Reindex", 42) .subtitle("catalog-v2");activitysmith.live_activities.stream("search-reindex", state).await?;Timer#
let state = ContentState::timer("Benchmark Run") .subtitle("sampling") .duration_seconds(300) .color(Color::Cyan);activitysmith.live_activities.stream("benchmark-run", state).await?;For a countdown, set duration_seconds. You can update the title, subtitle, color, or any other visible field as the work changes. Leave duration_seconds out unless you want to change the timer.
To start at 00:00 and count up, call count_up and leave out duration_seconds.
To count down to a set time, set timer_end_at instead of duration_seconds. If the timer started earlier, also set timer_start_at. The progress bar then shows the time already gone. Both accept any type that converts into SystemTime, such as the ones in chrono, jiff, and time.
use std::time::{Duration, SystemTime};let started_at = SystemTime::now() - Duration::from_secs(10 * 60);let state = ContentState::timer("Nightly Backup") .subtitle("uploading archive") .timer_start_at(started_at) .timer_end_at(started_at + Duration::from_secs(60 * 60));activitysmith.live_activities.stream("nightly-backup", state).await?;End Live Activity#
Call end_stream with the same stream key to end the Live Activity in its latest state. Call end_stream_with to show final values before it is removed. Set auto_dismiss_seconds or auto_dismiss_minutes to choose how long it stays visible. Seconds take precedence when you set both. Pass 0 to remove it immediately.
let state = ContentState::metrics( "Server Health", [ ActivityMetric::new("CPU", 7).unit("%"), ActivityMetric::new("MEM", 38).unit("%"), ],).subtitle("prod-web-1").auto_dismiss_seconds(30);activitysmith .live_activities .end_stream_with("prod-web-1", state) .await?;Icons and Badges#
Add more context to Live Activities with icons and badges.
Icon#
Supported Live Activity types: value, stats, alert, metrics, segmented_progress, progress, and timer.
let state = ContentState::metrics( "Server Health", [ ActivityMetric::new("CPU", 18).unit("%"), ActivityMetric::new("MEM", 42).unit("%"), ],).subtitle("prod-web-1").icon(Icon::new("server.rack").color(Color::Blue));activitysmith.live_activities.stream("prod-web-1", state).await?;The Icon symbol is an Apple SF Symbol name. Browse the catalog with one of these tools:
- ActivitySmith app - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
- SF Symbols - Apple's official macOS app
- Interactful - free third-party iOS app listing all SF Symbols under Foundations -> Iconography
Badge#
Badges are supported by value, alert, segmented_progress, and progress Live Activities.
let state = ContentState::progress("Nightly Database Backup", 62) .subtitle("verify restore") .badge(Badge::new("S3").color(Color::Cyan));activitysmith .live_activities .stream("nightly-database-backup", state) .await?;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:
Color::Lime, Color::Green, Color::Cyan, Color::Blue, Color::Purple, Color::Magenta, Color::Red, Color::Orange, Color::Yellow, Color::Gray
Actions#
Live Activities can include an action button.
open_url: Open a web page, run an iOS Shortcut, or open an appwebhook: Trigger a backend GET/POST workflow
Open URL action#
Open a web page, run an iOS Shortcut, or open an app when someone taps the button. Supported links:
- HTTP/HTTPS: Web pages, e.g.
https://example.com - Shortcuts: Run Jarvis with
shortcuts://run-shortcut?name=Jarvis - App deep links: Installed apps or specific content within them
- Spotify: A track, e.g.
spotify:track:6rqhFgbbKwnb9MLmUQDhG6 - Termius:
termius://to open the app - Claude:
claude://codeto open the Code tab - ChatGPT:
chatgpt://to open the app
- Spotify: A track, e.g.
let stream = LiveActivityStream::new( ContentState::metrics( "Server Health", [ ActivityMetric::new("CPU", 76).unit("%"), ActivityMetric::new("MEM", 52).unit("%"), ], ) .subtitle("prod-web-1"),).action(LiveActivityAction::open_url( "Dashboard", "https://status.example.com/servers/prod-web-1",));activitysmith.live_activities.stream("prod-web-1", stream).await?;Apple Shortcut action#
let stream = LiveActivityStream::new( ContentState::metrics( "Server Health", [ ActivityMetric::new("CPU", 76).unit("%"), ActivityMetric::new("MEM", 52).unit("%"), ], ) .subtitle("prod-web-1"),).action(LiveActivityAction::open_url( "Chat with Jarvis", "shortcuts://run-shortcut?name=Jarvis",));activitysmith.live_activities.stream("prod-web-1", stream).await?;End after the tap#
Call dismiss_after_action on an open_url button to end the Live Activity when someone taps it. The button opens its link, then the Live Activity ends.
let stream = LiveActivityStream::new( ContentState::alert( "Review Ready", "Claude finished the checkout refactor.", ) .color(Color::Green),).action( LiveActivityAction::open_url("Open Claude", "claude://code") .dismiss_after_action(),);activitysmith.live_activities.stream("agent-review", stream).await?;Webhook action#
let stream = LiveActivityStream::new( ContentState::segmented_progress("Reindexing product search", 7, 12) .subtitle("Shard 7 of 12"),).action( LiveActivityAction::webhook( "Pause Reindex", "https://ops.example.com/hooks/search/reindex/pause", ) .method(WebhookMethod::Post) .body(json!({ "job_id": "reindex-2026-03-19", "requested_by": "activitysmith-rust", })),);activitysmith.live_activities.stream("search-reindex", stream).await?;Secondary action#
Use secondary_action when you want a second button beside the primary action.
The secondary action button is supported for value, alert, segmented_progress, and progress Live Activities. Both buttons use the same open_url, webhook, and Apple Shortcut payload shapes.
let stream = LiveActivityStream::new( ContentState::alert( "Approval Needed", "Should I send the follow-up email to Brightlane?", ) .color(Color::Green) .icon(Icon::new("sparkles").color(Color::Green)) .badge(Badge::new("Agent").color(Color::Green)),).action( LiveActivityAction::webhook( "Send", "https://agent.example.com/live-activity/approve", ) .body(json!({ "approval_id": "approval_01JY3J7Q9S0P8M1V5PZK7DR4M2", "decision": "send", })),).secondary_action( LiveActivityAction::webhook( "Deny", "https://agent.example.com/live-activity/deny", ) .body(json!({ "approval_id": "approval_01JY3J7Q9S0P8M1V5PZK7DR4M2", "decision": "deny", })),);activitysmith.live_activities.stream("agent-approval", stream).await?;Live Activity Sounds#
Starting a Live Activity plays the Live Activities sound picked in the ActivitySmith app. Updates and ends are silent. Set sound on a start, update, or end to choose its sound, with the same values as Push Notification Sounds. A sound on an update or end plays only while the screen is on. Use it for moments that need attention, such as a failed step.
let stream = LiveActivityStream::new( ContentState::segmented_progress("Deploying API", 3, 4) .subtitle("Step 3 failed") .color(Color::Red),).sound("glitch");activitysmith.live_activities.stream("deploy-api", stream).await?;Lock Screen Widgets#
ActivitySmith lets you display any value on your Lock Screen with widgets - SaaS metrics, revenue, signups, uptime, habits, or anything else you want to track. Send a value to a metric key, add a widget to your Lock Screen, and it fetches the latest value automatically.
Use the metric key to update its value. The first value creates the metric.
activitysmith.metrics.update("deploy.success_rate", 99.9).await?;String metric values work too.
activitysmith.metrics.update("prod.status", "healthy").await?;Create a metric#
Use create to set the label and how widgets show the value, such as currency, percent, or a unit. Omitted fields keep their current values, so you can call it every time your app starts.
let definition = MetricDefinition::new() .label("MRR") .format(MetricFormat::Currency) .currency_code("USD");activitysmith.metrics.create("mrr", definition).await?;activitysmith.metrics.update("mrr", 12450).await?;You can also create and edit metrics in the web app.
App Icon Badge#
Show the number you care about on your ActivitySmith app icon. Track MRR, a customer count, a stock price, or any other value you want to keep in view.
App Icon Badge requires Push Notifications enabled. On your iPhone, open Settings > ActivitySmith > Notifications and turn on Allow Notifications.
Set or update the badge value#
activitysmith.badge_count(8333).await?;Clear the badge#
Pass 0 to clear the badge.
activitysmith.badge_count(0).await?;Metadata#
Metadata adds extra information to Push Notification and Live Activity details in ActivitySmith. It does not appear in the notification or Live Activity on your device.
let notification = PushNotification::new("New subscription 💸") .message("Customer upgraded to Pro plan") .metadata("customer_id", "382") .metadata("plan", "Pro") .metadata("amount", 29) .metadata("trial", false);activitysmith.notifications.send(notification).await?;let stream = LiveActivityStream::new( ContentState::progress("Customer Import", 60),).metadata("job_id", "import-382").metadata("records", 1200);activitysmith .live_activities .stream("customer-import", stream) .await?;Values can be strings, numbers, or booleans. Metadata supports up to 50 entries and 16 KB of JSON, with keys up to 100 characters and strings up to 4,000 characters. Nested objects, arrays, and null values are not supported.
Tags#
Use Tags to organize and filter Push Notification and Live Activity history. Tags are created automatically when you first use them.
let notification = PushNotification::new("New subscription 💸") .message("Customer upgraded to Pro plan") .tags(["user:382", "billing"]);activitysmith.notifications.send(notification).await?;On Live Activity updates and ends, leave out tags to keep existing Tags, call tags to replace them, or call clear_tags to remove them. clear_metadata does the same for Metadata.
let state = ContentState::progress("Customer Import", 60);let update = LiveActivityUpdate::new("YOUR_ACTIVITY_ID", state) .clear_tags();activitysmith.live_activities.update(update).await?;Channels#
Use channels to target specific team members or devices when sending Push Notifications, Live Activities, or App Icon Badge updates. Omit it for account-wide delivery.
let notification = PushNotification::new("New subscription 💸") .message("Customer upgraded to Pro plan") .channels(["sales", "customer-success"]);activitysmith.notifications.send(notification).await?;let stream = LiveActivityStream::new( ContentState::segmented_progress("Nightly database backup", 1, 3),).channels(["ios-builds"]);activitysmith.live_activities.stream("nightly-backup", stream).await?;activitysmith .badge_count_for_channels(3, ["sales", "customer-success"]) .await?;Paired Devices#
List the iPhones and iPads paired to your account, for example to check that a device is paired before you send. Active devices come first:
let options = DeviceListOptions::new();let list = activitysmith.devices.list(options).await?;for device in list.devices { println!( "{:?} {:?} {}", device.device_name, device.system_name, device.is_active );}An empty list means no device is paired. Install ActivitySmith on your iPhone, sign in with the same account, and allow notifications. Channel-scoped API keys cannot list devices.
Call include_inactive to also list devices that can no longer receive deliveries:
let options = DeviceListOptions::new().include_inactive();let list = activitysmith.devices.list(options).await?;Error Handling#
Every call returns a Result. Match on Error::Api to read the API's answer:
let notification = PushNotification::new("Deployment complete");match activitysmith.notifications.send(notification).await { Ok(sent) => println!("Sent {:?}", sent.notification_id), Err(Error::Api(error)) if error.is_rate_limited() => { println!("Try again later: {}", error.message); } Err(Error::Api(error)) => { println!("{} {}", error.status, error.message); } Err(error) => return Err(error.into()),}