Skip to content

ActivitySmithHQ/activitysmith-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

42 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ActivitySmith Node SDK

The ActivitySmith Node SDK provides convenient access to the ActivitySmith API from server-side JavaScript and TypeScript applications.

Documentation

See API reference

Installation

npm install activitysmith

Setup

import ActivitySmith from "activitysmith";

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

CommonJS:

const ActivitySmith = require("activitysmith");

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

Usage

Send a Push Notification

Push notification example

const response = await activitysmith.notifications.send({
  title: "New subscription ๐Ÿ’ธ",
  message: "Customer upgraded to Pro plan",
});

console.log(response.success);
console.log(response.devices_notified);

Start a Live Activity

Start live activity example

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",
  },
  channels: ["devs", "ops"], // Optional
});

const activityId = start.activity_id;

Update a Live Activity

Update live activity example

const update = await activitysmith.liveActivities.update({
  activity_id: activityId,
  content_state: {
    title: "Nightly database backup",
    subtitle: "upload archive",
    current_step: 2,
  },
});

console.log(update.devices_notified);

End a Live Activity

End live activity example

const end = await activitysmith.liveActivities.end({
  activity_id: activityId,
  content_state: {
    title: "Nightly database backup",
    subtitle: "verify restore",
    current_step: 3,
    auto_dismiss_minutes: 2,
  },
});

console.log(end.success);

Channels

Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.

const response = await activitysmith.notifications.send({
  title: "New subscription ๐Ÿ’ธ",
  message: "Customer upgraded to Pro plan",
  channels: ["sales", "customer-success"], // Optional
});

Push Notification Redirection and Actions

Push notification redirection and actions are optional and can be used to redirect the user to a specific URL when they tap the notification or to trigger a specific action when they long-press the notification. Webhooks are executed by ActivitySmith backend.

const response = await activitysmith.notifications.send({
  title: "New subscription ๐Ÿ’ธ",
  message: "Customer upgraded to Pro plan",
  redirection: "https://crm.example.com/customers/cus_9f3a1d", // Optional
  actions: [
    {
      title: "Open CRM Profile",
      type: "open_url",
      url: "https://crm.example.com/customers/cus_9f3a1d",
    },
    {
      title: "Start Onboarding Workflow",
      type: "webhook",
      url: "https://hooks.example.com/activitysmith/onboarding/start",
      method: "POST",
      body: {
        customer_id: "cus_9f3a1d",
        plan: "pro",
      },
    },
  ], // Optional (max 4)
});

Error Handling

try {
  await activitysmith.notifications.send({
    title: "New subscription ๐Ÿ’ธ",
  });
} catch (error) {
  console.error(error);
}

TypeScript Support

This package is written in TypeScript and ships with type definitions out of the box.

Requirements

  • Node.js 18 or newer

License

MIT

About

Node.js library for the ActivitySmith API

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors