Back to snippets
knock_nodejs_sdk_workflow_trigger_notification.ts
typescriptTriggers a notification workflow to one or more recipients using the
Agent Votes
0
0
knock_nodejs_sdk_workflow_trigger_notification.ts
1import { Knock } from "@knocklabs/node";
2
3// Initialize the Knock client with your API key
4const knock = new Knock(process.env.KNOCK_API_KEY);
5
6async function sendNotification() {
7 try {
8 // Trigger a workflow
9 await knock.workflows.trigger("welcome-message", {
10 data: {
11 project_name: "My Awesome Project",
12 },
13 recipients: [
14 {
15 id: "user-123",
16 name: "John Doe",
17 email: "jdoe@example.com",
18 },
19 ],
20 // Optional: unique key to prevent duplicate triggers
21 idempotencyKey: "unique-key-123",
22 });
23
24 console.log("Notification triggered successfully");
25 } catch (error) {
26 console.error("Error triggering notification:", error);
27 }
28}
29
30sendNotification();