Skip to content

Commit b2c6ebe

Browse files
authored
Merge pull request #11 from ActivitySmithHQ/docs/readme-polish
docs: improve Node README examples
2 parents e061687 + 3c1a1cf commit b2c6ebe

File tree

1 file changed

+76
-18
lines changed

1 file changed

+76
-18
lines changed

README.md

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,14 @@ See [API reference](https://activitysmith.com/docs/api-reference/introduction)
1212
npm install activitysmith
1313
```
1414

15-
## Usage
16-
17-
ESM:
15+
## Setup
1816

1917
```ts
2018
import ActivitySmith from "activitysmith";
2119

2220
const activitysmith = new ActivitySmith({
2321
apiKey: process.env.ACTIVITYSMITH_API_KEY,
2422
});
25-
26-
// Push Notifications
27-
await activitysmith.notifications.send({
28-
// See PushNotificationRequest for fields
29-
});
30-
31-
// Live Activities
32-
await activitysmith.liveActivities.start({
33-
// See LiveActivityStartRequest for fields
34-
});
3523
```
3624

3725
CommonJS:
@@ -44,14 +32,84 @@ const activitysmith = new ActivitySmith({
4432
});
4533
```
4634

47-
## API Surface
35+
## Usage
4836

49-
The client exposes grouped resources:
37+
### Send a Push Notification
5038

51-
- `activitysmith.liveActivities`
52-
- `activitysmith.notifications`
39+
```ts
40+
const response = await activitysmith.notifications.send({
41+
title: "Build Failed",
42+
message: "CI pipeline failed on main branch",
43+
});
44+
45+
console.log(response.success);
46+
console.log(response.devices_notified);
47+
```
48+
49+
### Start a Live Activity
50+
51+
```ts
52+
const start = await activitysmith.liveActivities.start({
53+
content_state: {
54+
title: "ActivitySmith API Deployment",
55+
subtitle: "start",
56+
number_of_steps: 4,
57+
current_step: 1,
58+
type: "segmented_progress",
59+
color: "yellow",
60+
},
61+
});
62+
63+
const activityId = start.activity_id;
64+
```
5365

54-
Each method is fully typed. Request and response types are included in the type definitions.
66+
### Update a Live Activity
67+
68+
```ts
69+
const update = await activitysmith.liveActivities.update({
70+
activity_id: activityId,
71+
content_state: {
72+
title: "ActivitySmith API Deployment",
73+
subtitle: "npm i & pm2",
74+
current_step: 3,
75+
},
76+
});
77+
78+
console.log(update.devices_notified);
79+
```
80+
81+
### End a Live Activity
82+
83+
```ts
84+
const end = await activitysmith.liveActivities.end({
85+
activity_id: activityId,
86+
content_state: {
87+
title: "ActivitySmith API Deployment",
88+
subtitle: "done",
89+
current_step: 4,
90+
auto_dismiss_minutes: 3,
91+
},
92+
});
93+
94+
console.log(end.success);
95+
```
96+
97+
## Error Handling
98+
99+
```ts
100+
try {
101+
await activitysmith.notifications.send({
102+
title: "Build Failed",
103+
});
104+
} catch (error) {
105+
console.error(error);
106+
}
107+
```
108+
109+
## API Surface
110+
111+
- `activitysmith.notifications`
112+
- `activitysmith.liveActivities`
55113

56114
## TypeScript Support
57115

0 commit comments

Comments
 (0)