SDKs
Core SDK
@channlize/core: the TypeScript client for Events (notify, createNotifier), log tracking, the contact form and chat, with typed errors.
On this page
@channlize/core (0.10.2) is the TypeScript client behind the React SDK. Use it on your server to send Events and server logs, or anywhere (browser, Node.js, edge runtimes) for the contact form, chat and browser logs.
npm install @channlize/coreKeys and environment
| Key | Where it is safe | Used for |
|---|---|---|
Widget key wk_… | Anywhere, including browser bundles | submitContactForm, chat, trackEvent |
Server API key ch_live_… | Server only | notify, trackServerEvent, the REST API |
notify needs a server key with the write scope. See API keys.
# Server only. Never commit it or expose it to the browser.
CHANNLIZE_SERVER_API_KEY=ch_live_your_server_key
CHANNLIZE_PROJECT_ID=your-project-id
# Optional: CHANNLIZE_BASE_URL=https://api.channlize.comThe client
import { ChannlizeClient } from '@channlize/core';
// Server only (API route, job, webhook handler).
export const channlize = new ChannlizeClient({
apiKey: 'wk_your_widget_key', // required by the constructor; the public widget key
projectId: process.env.CHANNLIZE_PROJECT_ID!,
serverApiKey: process.env.CHANNLIZE_SERVER_API_KEY!, // ch_live_…
timeout: 10_000, // optional, ms
});| Option | Type | Description |
|---|---|---|
apiKey | string | Required. Your widget key (wk_…). |
projectId | string | Required. The project ID. |
serverApiKey | string | Server API key (ch_live_…) for notify and trackServerEvent. Server only. |
baseUrl | string | Default https://api.channlize.com. |
timeout | number | Request timeout in ms. Default 10000. |
In the browser, create the client with the widget key only:
import { ChannlizeClient } from '@channlize/core';
// The widget key is public: safe in a browser bundle.
export const channlize = new ChannlizeClient({
apiKey: 'wk_your_widget_key',
projectId: 'your-project-id',
});notify
notify(event, data?, options?) posts a Slack message from your server when something happens. The event key picks the channel and message template you configure under Events in the dashboard; data fills the template's {{field}} placeholders.
The simplest way is the standalone createNotifier(). It reads CHANNLIZE_SERVER_API_KEY (or CHANNLIZE_API_KEY), CHANNLIZE_PROJECT_ID and CHANNLIZE_BASE_URL when it is called, so creating it at module load never throws.
import { createNotifier } from '@channlize/core';
export const notify = createNotifier();
const res = await notify('user.subscribed', { username: 'ada', plan: 'Pro' });
// res.status: 'queued' → posted to Slack shortly
// 'skipped' → not posted, see res.reason (event disabled, new draft, no Slack channel)
// Retry-safe: a key already used returns the first delivery (duplicate: true).
await notify('invoice.paid', { amount: '$49', customer: 'ada@example.com' }, {
idempotencyKey: 'invoice-in_1042',
});
// Post to another Slack channel (ID) for this call only.
await notify('deploy.finished', { version: '1.4.0' }, { channel: 'C0123456789' });createNotifier(config?) takes { serverApiKey?, projectId?, baseUrl?, timeout? }; serverApiKey, projectId and baseUrl fall back to the environment variables above, and timeout defaults to 10000 ms. ChannlizeClient#notify does the same with the client's serverApiKey and projectId.
| Argument | Description |
|---|---|
event | Event key: lowercase letters, digits, ., _ or -, starting with a letter or digit, at most 100 characters (user.subscribed, invoice_paid). Checked before sending. |
data | Any JSON object, at most 16 KB. Fills {{field}} and {{nested.field}} in the template. |
options.idempotencyKey | 1 to 255 characters, sent as the Idempotency-Key header. A key already used on the project returns the first delivery with duplicate: true and posts nothing. |
options.channel | Slack channel ID for this call instead of the event's channel. Applies only when the event is enabled. |
It resolves to a NotifyResponse:
interface NotifyResponse {
success: boolean;
id: string; // delivery ID (Events → Recent deliveries)
event: string;
status: 'queued' | 'skipped' | 'sent' | 'failed';
reason?: string; // why it was skipped
duplicate?: boolean; // same idempotencyKey as an earlier call
}The API answers queued or skipped; the delivery then becomes sent or failed under Events → Recent deliveries. An unknown event key never throws: it is saved as a disabled draft ("Seen, not configured") and answered with status: 'skipped'. See Events.
Typed events
Give createNotifier a map of event keys to data types. Keys autocomplete and data is checked; other keys still accept any object.
import { createNotifier } from '@channlize/core';
type AppEvents = {
'user.subscribed': { username: string; plan: 'Free' | 'Pro' };
'invoice.paid': { amount: string; customer: string };
};
export const notify = createNotifier<AppEvents>();
await notify('user.subscribed', { username: 'ada', plan: 'Pro' });Or type every notify() in the app at once, including ChannlizeClient#notify, by augmenting ChannlizeEvents:
declare module '@channlize/core' {
interface ChannlizeEvents {
'user.subscribed': { username: string; plan: 'Free' | 'Pro' };
}
}
export {};Idempotency
Pass an idempotencyKey derived from the thing that happened (an invoice ID, a signup ID) whenever you might retry: a queue redelivery, a webhook handler that runs twice, a RateLimitError you retry. Keys are scoped to the project and never expire. A repeat returns the first call's id, status and reason with duplicate: true, even if the first call was skipped.
Log tracking
Log tracking records log lines with a severity. They appear under Log tracking in the dashboard, and can alert a Slack channel. Use Events instead when you want a designed Slack message.
import { ChannlizeClient } from '@channlize/core';
const channlize = new ChannlizeClient({
apiKey: 'wk_your_widget_key',
projectId: process.env.CHANNLIZE_PROJECT_ID!,
serverApiKey: process.env.CHANNLIZE_SERVER_API_KEY, // only for trackServerEvent
});
// Browser or server, with the widget key
await channlize.trackEvent('checkout.started', {
properties: { cartId: 'cart_123' },
severity: 'info', // 'info' | 'warning' | 'error'
distinctId: 'user_42', // optional: who did it
});
// Server only, with the server key
await channlize.trackServerEvent('payment.failed', {
properties: { reason: 'card_declined' },
severity: 'error',
});trackEvent(name, { properties?, severity?, distinctId?, pageUrl?, userAgent? })uses the widget key. In a browser,pageUrlanduserAgentare filled in for you.trackServerEvent(name, { properties?, severity? })needsserverApiKey. Server logs also fan out to your outbound webhooks.- An unknown
severityis stored asinfo. - Both return
{ success, id }. There is no deduplication: each call is a new log line.
Slack alerts for logs are set per project on the Log tracking page: a channel, a minimum severity ("Errors only" by default) and an optional name-prefix allowlist (billing., checkout.).
Contact form and chat
The same calls the React components make, for other frameworks or your own UI. They use the widget key.
import { ChannlizeClient } from '@channlize/core';
const channlize = new ChannlizeClient({ apiKey: 'wk_your_widget_key', projectId: 'your-project-id' });
const res = await channlize.submitContactForm({
name: 'Ada Lovelace',
email: 'ada@example.com',
subject: 'Billing question', // optional, at most 200 characters
message: 'Can I switch to yearly billing?', // 10 to 10,000 characters
customFields: { plan: 'Pro' }, // optional, shown on the Slack post
});
res.conversationId; // the conversation it was filed underimport { ChannlizeClient } from '@channlize/core';
const channlize = new ChannlizeClient({ apiKey: 'wk_your_widget_key', projectId: 'your-project-id' });
// Start a session (metadata shows up on the conversation)
const { session } = await channlize.createChatSession({ plan: 'Pro' });
await channlize.sendMessage(session.id, 'Hi! Can I change my plan?');
// With files (browser File objects): sendMessage(session.id, 'Screenshot attached', [file])
const messages = await channlize.getChatMessages(session.id, 50, 0); // limit, offset
const current = await channlize.getChatSession(session.id);
await channlize.closeChatSession(session.id);The rating of a closed conversation (CSAT) goes through GET and POST /v1/chat/sessions/{sessionId}/rating ({ score: 1-5, comment? }); client methods for them come with the next minor release.
Agent replies arrive over a server-sent events stream at /v1/chat/sessions/{sessionId}/events. The React useChatSession hook handles it for you.
Channlize for Agents
createAgentsClient() (from 0.5.0), also available as ChannlizeClient.agents. Your own AI agents use it to post messages and tasks to agent channels, read and ack their inbox (or run poll), read the directory and channels, and check webhook signatures with verifyAgentWebhook / parseAgentWebhook. It takes an agent key or a multi-agent key. See the SDK section of the agents quick start.
From 0.6.0 it also reads the activity: search and searchAll (Search), insights.* (Insights), and with an unbound agents:admin key exports.* (Exports) and telemetry.* (OpenTelemetry and webhooks). verifyTelemetryWebhook / parseTelemetryWebhook check telemetry webhook batches.
Errors
Every method throws a ChannlizeError subclass. message is the API's human-readable message (field messages joined for validation failures). code is VALIDATION_ERROR, AUTHENTICATION_ERROR or RATE_LIMIT_ERROR for the three subclasses, and the API's error code for other statuses.
import {
AuthenticationError,
ChannlizeError,
RateLimitError,
ValidationError,
createNotifier,
} from '@channlize/core';
const notify = createNotifier();
try {
await notify('user.subscribed', { username: 'ada', plan: 'Pro' });
} catch (err) {
if (err instanceof ValidationError) {
// 400, or caught before sending (then err.field is 'projectId' | 'serverApiKey' | 'event')
} else if (err instanceof AuthenticationError) {
// 401: missing, mistyped or revoked key
} else if (err instanceof RateLimitError) {
// 429: back off, then retry (with the same idempotencyKey)
} else if (err instanceof ChannlizeError) {
// err.statusCode + err.code, e.g. 403 FORBIDDEN, 404 NOT_FOUND, 408 TIMEOUT
console.error(err.statusCode, err.code, err.message);
}
}| Class | Status | When |
|---|---|---|
ValidationError | 400 | Invalid input, or caught before sending (missing key or project ID, bad event key, a widget key passed to notify). field is set for checks made before sending. |
AuthenticationError | 401 | Missing, mistyped, revoked or expired key. |
RateLimitError | 429 | Too many requests. See rate limits. |
ChannlizeError | other | statusCode and code: 403 FORBIDDEN (key lacks a scope), 404 NOT_FOUND, 408 TIMEOUT (client timeout), 503 (try again). Network failures have no status. |
Exports
ChannlizeClient (also the default export), createNotifier, the error classes ChannlizeError, ValidationError, AuthenticationError, RateLimitError, and the types ChannlizeConfig, NotifierConfig, Notifier, NotifyOptions, NotifyResponse, ChannlizeEvents, NotifyEventName, NotifyEventData, TrackEventOptions, EventSeverity, ContactFormData, CreateContactResponse, ChatMessage, ChatSession, FileAttachment, CreateChatSessionResponse, SendMessageResponse, ApiResponse.