Skip to content

JavaScript SDK (Node and browser)

nuacemone.js is one JavaScript file that works in browsers and in Node 18 or later. It has no dependencies and wraps the Conversations API and the Workflows API.

The SDK is not published on npm. Download it from the console:

  • Open an agent or use case, go to Deploy → SDK & API, and download nuacemone.js and its types file nuacemone.d.ts.
  • Or fetch them directly: https://studio.nuacem.dev/sdk/nuacemone.js and https://studio.nuacem.dev/sdk/nuacemone.d.ts.

In a web page you can load it straight from the console:

<script src="https://studio.nuacem.dev/sdk/nuacemone.js"></script>

This sets the global NuacemOne. In Node, save the file in your project and require it:

const NuacemOne = require('./nuacemone.js');
const client = NuacemOne.client({
key: process.env.NUACEMONE_SECRET_KEY, // vcx_pk_... in a page, vcx_sk_... on a server
gateway: 'https://api.nuacem.dev/voice-gw', // chats and calls
workflows: 'https://api.nuacem.dev/workflow-api', // server only
});
Option Notes
key A publishable key in a page (only from its allowed websites), or a secret key on your server. Never put a secret key in a page.
gateway The Conversations API base URL. Needed for chats and calls.
workflows The Workflows API base URL. Server only.
fetch Your own fetch implementation. Defaults to the global one.
timeoutMs Timeout for workflow requests. Default 60000.

The client has three parts: client.agents, client.useCases and client.workflows.

const chat = client.agents.chat('agt_xxxx', { user: { id: 'cust-42' } }); // or client.useCases.chat('uc_xxxx')
const { greeting } = await chat.start();
const reply = await chat.send('When is my EMI due?', {
onDelta: (textSoFar, piece) => render(textSoFar),
});
console.log(reply.text);
await chat.feedback(5, 'Very helpful');
await chat.end();

Options for chat(id, options) and call(id, options):

Option Notes
language For example 'en' or 'hi'. Defaults to the agent’s default language.
user { id, hash }. In a page, hash is HMAC-SHA256(id, workspace identity secret) in hex, computed on your server. With a secret key, { id } alone is enough. See Signed users.
profile Answers from your own form, for example { name: 'Asha' }. Chats only. Not an identity.
visitorId A stable anonymous id. In a browser it is kept in localStorage by default. Pass false to never store one.

Chat methods:

Method What it does
start() Starts the chat, or returns the open one. send() calls it for you.
send(text, options) Sends a message and resolves with the full reply { text, block?, blockText? }. Messages are sent one at a time: a send() while a reply streams waits for it.
uploadFile(file, name?) Uploads a file. See Files.
tap({ blockId, value, label }) Sends a tap on a rich block’s option.
feedback(rating, comment?) Rates the open chat 1 to 5.
end() Ends the chat.
on(event, fn) Subscribes to an event. Returns an unsubscribe function.
session The open session (sessionId, language, richMessages, and so on), or null.

send() options: onDelta(textSoFar, piece), signal (an AbortSignal), fileIds, and replyTo: { role, text } (when the session has replies: true).

Events for chat.on(name, fn):

Event Data
start { session }
delta { text, delta }: the reply so far and the newest piece.
preparing { kind }: a rich block is likely; show a placeholder until message.
message { text, block?, blockText? }: the full reply.
error { error }
end {}
const file = await chat.uploadFile(input.files[0]); // in a page
// Node: await chat.uploadFile(fs.readFileSync('statement.pdf'), 'statement.pdf');
if (file.status === 'blocked') {
showNotice(file.message); // safe to show; do not send this file
} else {
await chat.send('Summarise this statement', { fileIds: [file.fileId] });
}

uploadFile takes a Blob or File, an ArrayBuffer or a Uint8Array (pass name with its extension for raw bytes). It resolves with { fileId, name, kind, sizeBytes, status, code, message, pages, truncated, filesLeft }. A blocked file resolves normally with status: 'blocked'; it is not an error. See Files for types and limits.

When chat.session.richMessages is true, a reply may carry block and blockText. reply.text is always the full reply, so you can ignore blocks. To draw them in a browser, load the renderer the web widget uses:

const rich = await NuacemOne.loadRenderer();
const host = document.createElement('div');
host.className = 'rb-host';
host.append(rich.render(reply.block, { onTap: (tap) => chat.tap(tap) }));

Add rich.css to your page (or shadow root) once. Block text is plain text; the renderer never builds HTML from it.

const call = await client.agents.call('agt_xxxx'); // or client.useCases.call('uc_xxxx')
// { sessionId, livekitUrl, token, maxDurationSeconds, silenceCheckSeconds, silenceEndSeconds, ... }

Connect with the LiveKit client SDK and turn on the microphone, as shown in Web voice calls. Leaving the room ends the call.

Server only, with a secret key that has no agent limit. In a browser, or with a publishable key, every workflows call rejects with secret_key_required before any request is sent. The Workflows API is in beta and must be switched on for your organisation.

const wf = client.workflows;
const run = await wf.start('flw_xxxx', { input: { appointmentId: 'A-1042' }, correlation: { patientRef: 'P-77' } });
const now = await wf.getRun(run.id);
console.log(now.status, now.statusLabel);
await wf.sendEvent('doctor.cancelled', {
eventId: 'hosp-evt-981', correlation: { doctorId: 'D-12' }, data: { doctorId: 'D-12', date: '2026-11-20' },
});
for (const task of await wf.tasks({ status: 'OPEN' })) {
await wf.decideTask(task.id, 'approved', { note: 'Checked' });
}
await wf.cancelRun(run.id);
Method API call
start(workflowId, { input, correlation, triggerId }) POST /public/v1/workflows/{workflowId}/runs
getRun(runId) GET /public/v1/runs/{runId}
cancelRun(runId) POST /public/v1/runs/{runId}/cancel
sendEvent(eventName, { eventId, correlation, data }) POST /public/v1/events
tasks({ runId, status }) GET /public/v1/tasks
decideTask(taskId, outcome, { note, data }) POST /public/v1/tasks/{taskId}/decide

Node only. Check a webhook NuacemOne sent you, or sign a call to a signed workflow hook:

const express = require('express');
app.post('/webhooks/nuacemone', express.raw({ type: 'application/json' }), (req, res) => {
const ok = NuacemOne.webhooks.verify(process.env.NUACEMONE_WEBHOOK_SECRET, req.body,
req.get('X-VoiceCX-Timestamp'), req.get('X-VoiceCX-Signature'));
res.sendStatus(ok ? 204 : 401);
});
const body = JSON.stringify({ input: { appointmentId: 'A-1042' } });
await fetch(hookUrl, {
method: 'POST', body,
headers: NuacemOne.webhooks.signedHeaders(process.env.NUACEMONE_INBOUND_SECRET, body),
});

verify rejects timestamps more than 300 seconds away; pass { toleranceSeconds } as the fifth argument to change that. See Verifying signatures.

Every failure rejects with a NuacemOne.Error that has:

  • code: the API’s error code, such as origin_not_allowed, rate_limited, session_not_found or use_case_not_ready, or network_error when the server could not be reached.
  • status: the HTTP status, or 0 for network errors.
  • message: safe to show to the user.

See Errors for every code.

nuacemone.d.ts describes every option and result. Put it next to nuacemone.js; TypeScript picks it up for require('./nuacemone.js'), and in a page it declares the global NuacemOne.

Older code using the VoiceCX global, vcx-sdk.js or vcx-workflows.js keeps working. See Older names.