@elaras/chat-sdk
v0.2.1
Published
JavaScript SDK for the Elaras Chat API
Readme
@elaras/chat-sdk
Browser SDK for the Elaras Chat visitor API. Lets you open a chat session, stream assistant replies, render rich reply blocks (cards, forms, carousels), and capture leads — all without touching the raw HTTP surface.
For a React wrapper, see @elaras/react-chat.
For a drop-in floating widget, see @elaras/assistant-widget.
For server-side integration (webhook verification, admin API), see @elaras/sdk-node.
Install
npm install @elaras/chat-sdkQuick start
import { ChatClient } from '@elaras/chat-sdk';
const client = new ChatClient({
chatbotId: 'bot_abc123',
publicKey: 'ck_live_...', // from your Elaras dashboard
});
// Open a session
const session = await client.startSession();
// Send a message and stream the response
for await (const event of client.sendMessage(session.id, 'Hello!')) {
if (event.type === 'text') process.stdout.write(event.content);
if (event.type === 'done') console.log('\n--- done ---');
}Rich-block rendering
Elaras assistants can emit interactive UI blocks (buttons, forms, cards, carousels). Convert them to DOM with renderBlocks():
import { renderBlocks, type Block } from '@elaras/chat-sdk';
const blocks: Block[] = [...]; // from a message's enrichment field
const el = renderBlocks(blocks);
document.getElementById('chat').appendChild(el);Import the default stylesheet in your app once:
@import '@elaras/chat-sdk/blocks.css';External identity
To tie Elaras conversations to users in your own system:
await client.startSession({
externalUserId: 'u_42',
externalProfileId: 'tenant:acme', // optional
externalOrgId: 'org_xyz', // optional
});These values are forwarded to any webhook skills your chatbot calls — so your backend knows which of your users is talking.
Browser requirements
- Native
fetch,EventSource, andAbortController— all evergreen browsers. - No framework assumed.
- ~20kB gzipped (CJS + ESM dual export).
License
MIT © Elaras
