@chaterafrikang/sdk
v0.1.0-beta.5
Published
Headless JavaScript SDK for ChatAfrika chat, presence, typing, and support features
Maintainers
Readme
@chatafrika/sdk
Headless JavaScript SDK for ChatAfrika chat, presence, typing, and support features.
Installation
npm install @chatafrika/sdkQuick Start
Your backend issues SDK tokens via POST /api/v1/apps/:appId/tokens (JWT or API key). Your frontend receives only the token—never App ID, public key, or secret key. See the ChatAfrika API docs for Issue SDK Token (POST /apps/:id/tokens).
import { ChatAfrika } from '@chatafrika/sdk';
// token from your backend—never use keys in the frontend
const sdk = new ChatAfrika({
wsUrl: 'wss://ws.dev.chaterafrika.com/ws',
token,
debug: true,
});
await sdk.connect();
const convo = sdk.conversations.get('conv-123');
await sdk.conversations.join('conv-123');
convo.on('message', (msg) => {
console.log('Message:', msg.content);
});
convo.sendMessage('Hello!');Features
- ✅ WebSocket transport with auto-reconnection
- ✅ Optimistic message updates
- ✅ Message deduplication & reconciliation
- ✅ Typing indicators with auto-expiry
- ✅ Presence tracking
- ✅ Read receipts lifecycle
- ✅ Support session semantics (customer/agent roles)
- ✅ Event-driven architecture
- ✅ TypeScript support
Development
npm install
npm run build
npm run typecheck
npm run test:quick # Quick test against real serverTesting
See TESTING.md for detailed testing guide.
Quick test (use a token from your backend, e.g. POST /apps/:id/tokens):
WS_URL=ws://localhost:8080/ws SDK_TOKEN=<token-from-backend> npm run test:quickAPI Documentation
Core
ChatAfrika- Main SDK classConnectionState- Connection state enumClientConfig- Configuration interface
Conversations
sdk.conversations.get(id)- Get conversationsdk.conversations.join(id)- Join conversationsdk.conversations.leave(id)- Leave conversationsdk.conversations.list({ externalUserId })- List EXTERNAL conversations (inbox). RequiresapiUrlandapiKey+apiSecretorgetRestHeadersin config.convo.fetchMessages({ externalUserId, cursor?, limit? })- Fetch paginated message history for an EXTERNAL conversation. Same config aslist().
Support Sessions
sdk.support.get(id, role?)- Get support sessionsession.isCustomer()- Check if customersession.isAgent()- Check if agentsession.getStatus()- Get session status
Events
All classes extend EventEmitter. Listen to:
message- New message receivedtyping- Typing indicatorpresence- Presence updatereceipt- Receipt updateassigned- Support session assignedbot_takeover- Bot took overclosed- Support session closed
Publish for testing
Base URL for dev: https://dev.chaterafrika.com/ (API: https://dev.chaterafrika.com/api/v1, WebSocket: wss://ws.dev.chaterafrika.com/ws).
See PUBLISH_FOR_TESTING.md for:
- Publishing to npm with
--tag beta(npm install @chatafrika/sdk@beta) - Installing from Git or local path (no publish)
- Using
npm linkfor local development - Dev vs local URLs
Documentation
- Capabilities & Usage Guide - What the SDK can do and where to use it
- Testing Guide - How to test the SDK
- Publish for testing - Publish / install SDK for testing with dev
License
UNLICENSED
