Skip to main content

Installation

To install the ActivitySmith Node SDK, you can use npm:
Node
npm install activitysmith

Usage

  1. Create an API key
  2. Set the API key as an environment variable named ACTIVITYSMITH_API_KEY or pass it as apiKey when creating the client.
Here’s an example of how to use the SDK with error handling:
Node
import ActivitySmith from "activitysmith";

const activitysmith = new ActivitySmith({
  apiKey: process.env.ACTIVITYSMITH_API_KEY,
});

Send a Push Notification

Use activitysmith.notifications.send with a push payload. title is required; message and subtitle are optional. Push Notification
Node
const response = await activitysmith.notifications.send({
  title: "New subscription 💸",
  message: "Customer upgraded to Pro plan",
});

console.log(response.devices_notified, response.timestamp);

Start a Live Activity

Use activitysmith.liveActivities.start with a content_state payload. For the segmented progress type, title, number_of_steps, current_step, and type are required. Start Live Activity
Node
const start = await activitysmith.liveActivities.start({
  content_state: {
    title: "Nightly database backup",
    subtitle: "create snapshot",
    number_of_steps: 3,
    current_step: 1,
    type: "segmented_progress",
    color: "yellow",
  },
});

const activityId = start.activity_id;

Update a Live Activity

Use activitysmith.liveActivities.update with the activity_id you received from start. Update Live Activity
Node
await activitysmith.liveActivities.update({
  activity_id: activityId,
  content_state: {
    title: "Nightly database backup",
    subtitle: "upload archive",
    current_step: 2,
  },
});

End a Live Activity

Use activitysmith.liveActivities.end with the activity_id. You can optionally control how long the ended Live Activity stays visible using auto_dismiss_minutes (default 3, 0 for immediate dismissal). End Live Activity
Node
await activitysmith.liveActivities.end({
  activity_id: activityId,
  content_state: {
    title: "Nightly database backup",
    subtitle: "verify restore",
    current_step: 3,
    auto_dismiss_minutes: 2,
  },
});

Channels

You can target specific channels when sending a push or starting a Live Activity.
Node
await activitysmith.notifications.send({
  title: "New subscription 💸",
  message: "Customer upgraded to Pro plan",
  channels: ["ios-builds", "engineering"],
});

await activitysmith.liveActivities.start({
  channels: ["ios-builds"],
  content_state: {
    title: "Nightly database backup",
    number_of_steps: 3,
    current_step: 1,
    type: "segmented_progress",
  },
});

Error Handling

Handle errors with try/catch around API calls:
Node
try {
  await activitysmith.notifications.send({ title: "Hello" });
} catch (error) {
  console.error(error);
}

Additional Resources