Notifications alert you when workflows complete, fail, or detect data changes. You can receive them via email, webhooks, or WebSockets. The SDK handles channel management automatically.
Quick Start
import { KadoaClient } from "@kadoa/node-sdk";
const client = new KadoaClient({ apiKey: "your-api-key" });
await client.notification.setupForWorkflow({
workflowId: "your-workflow-id",
events: ["workflow_data_change"],
channels: {
WEBHOOK: {
name: "my-webhook",
webhookUrl: "https://your-server.com/webhook",
httpMethod: "POST",
},
},
});
The SDK reuses existing channels with the same name. Running setup multiple times won’t create duplicates.
Channel Types
Email
// Use account email
await client.notification.setupForWorkflow({
workflowId: workflowId,
events: ["workflow_finished", "workflow_failed"],
channels: { EMAIL: true },
});
// Or specify recipients
await client.notification.setupForWorkflow({
workflowId: workflowId,
events: ["workflow_finished"],
channels: {
EMAIL: {
name: "team-notifications",
recipients: ["[email protected]"],
},
},
});
Slack
await client.notification.setupForWorkflow({
workflowId: workflowId,
events: ["workflow_failed"],
channels: {
SLACK: {
name: "team-notifications",
slackChannelId: "C1234567890",
slackChannelName: "alerts",
webhookUrl: "https://hooks.slack.com/services/YOUR/WEBHOOK",
},
},
});
Webhook
await client.notification.setupForWorkflow({
workflowId: workflowId,
events: ["workflow_data_change", "workflow_finished"],
channels: {
WEBHOOK: {
name: "api-integration",
webhookUrl: "https://api.example.com/webhooks/kadoa",
httpMethod: "POST",
},
},
});
WebSocket
Receive events in real-time
const client = new KadoaClient({ apiKey });
const realtime = await client.connectRealtime();
// Subscribe to all events
realtime.onEvent((event) => {
console.log("Event received:", event.eventType, event.message);
});
// Filter events by type
realtime.onEvent((event) => {
if (event.eventType === "workflow_finished") {
console.log("Workflow completed:", event.message);
}
});
// Handle errors
realtime.onError((error) => {
console.error("WebSocket error:", error);
});
realtime.close();
Subscribe to All Events
await client.notification.setupForWorkflow({
workflowId: workflowId,
events: "all",
channels: { EMAIL: true },
});
Reusing Channels
Reference existing channels by ID
// List channels
const channels = await client.notification.channels.listChannels({});
const webhookChannel = channels.find(c => c.name === "my-webhook");
await client.notification.setupForWorkflow({
workflowId: newWorkflowId,
events: ["workflow_data_change"],
channels: {
WEBHOOK: { channelId: webhookChannel.id },
},
});
Setup Notifications via API
Step 1: Create Notification Channels
First, create the channels you want to use for notifications. See Emails, Webhooks and WebSockets for channel creation examples.
Step 2: Subscribe to Events
Subscribe to events by sending a POST request to /v5/notifications/settings.
Workspace-Level Subscription
Apply notifications to all workflows:
// POST /v5/notifications/settings
{
"eventType": "workflow_finished",
"eventConfiguration": {},
"enabled": true,
"channelIds": ["<channel-id>"]
}
Workflow-Level Subscription
Apply notifications to a specific workflow:
// POST /v5/notifications/settings
{
"workflowId": "<your-workflow-id>",
"eventType": "workflow_data_change",
"eventConfiguration": {},
"enabled": true,
"channelIds": ["<channel-id>"]
}
Step 3: Update Existing Settings
To add more channels to existing settings, use a PUT request:
// PUT /v5/notifications/settings/<settings-id>
{
"channelIds": ["existing-channel-id", "new-channel-id"]
}