@chaterafrikang/sdk 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -0
- package/dist/index.cjs +2119 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1072 -0
- package/dist/index.d.ts +1072 -0
- package/dist/index.js +2098 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @chatafrika/sdk
|
|
2
|
+
|
|
3
|
+
Headless JavaScript SDK for ChatAfrika chat, presence, typing, and support features.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @chatafrika/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
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`).
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { ChatAfrika } from '@chatafrika/sdk';
|
|
17
|
+
|
|
18
|
+
// token from your backend—never use keys in the frontend
|
|
19
|
+
const sdk = new ChatAfrika({
|
|
20
|
+
wsUrl: 'wss://ws.dev.chaterafrika.com/ws',
|
|
21
|
+
token,
|
|
22
|
+
debug: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await sdk.connect();
|
|
26
|
+
|
|
27
|
+
const convo = sdk.conversations.get('conv-123');
|
|
28
|
+
await sdk.conversations.join('conv-123');
|
|
29
|
+
|
|
30
|
+
convo.on('message', (msg) => {
|
|
31
|
+
console.log('Message:', msg.content);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
convo.sendMessage('Hello!');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- ✅ WebSocket transport with auto-reconnection
|
|
40
|
+
- ✅ Optimistic message updates
|
|
41
|
+
- ✅ Message deduplication & reconciliation
|
|
42
|
+
- ✅ Typing indicators with auto-expiry
|
|
43
|
+
- ✅ Presence tracking
|
|
44
|
+
- ✅ Read receipts lifecycle
|
|
45
|
+
- ✅ Support session semantics (customer/agent roles)
|
|
46
|
+
- ✅ Event-driven architecture
|
|
47
|
+
- ✅ TypeScript support
|
|
48
|
+
|
|
49
|
+
## Development
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install
|
|
53
|
+
npm run build
|
|
54
|
+
npm run typecheck
|
|
55
|
+
npm run test:quick # Quick test against real server
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Testing
|
|
59
|
+
|
|
60
|
+
See [TESTING.md](./TESTING.md) for detailed testing guide.
|
|
61
|
+
|
|
62
|
+
Quick test (use a token from your backend, e.g. `POST /apps/:id/tokens`):
|
|
63
|
+
```bash
|
|
64
|
+
WS_URL=ws://localhost:8080/ws SDK_TOKEN=<token-from-backend> npm run test:quick
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API Documentation
|
|
68
|
+
|
|
69
|
+
### Core
|
|
70
|
+
|
|
71
|
+
- `ChatAfrika` - Main SDK class
|
|
72
|
+
- `ConnectionState` - Connection state enum
|
|
73
|
+
- `ClientConfig` - Configuration interface
|
|
74
|
+
|
|
75
|
+
### Conversations
|
|
76
|
+
|
|
77
|
+
- `sdk.conversations.get(id)` - Get conversation
|
|
78
|
+
- `sdk.conversations.join(id)` - Join conversation
|
|
79
|
+
- `sdk.conversations.leave(id)` - Leave conversation
|
|
80
|
+
|
|
81
|
+
### Support Sessions
|
|
82
|
+
|
|
83
|
+
- `sdk.support.get(id, role?)` - Get support session
|
|
84
|
+
- `session.isCustomer()` - Check if customer
|
|
85
|
+
- `session.isAgent()` - Check if agent
|
|
86
|
+
- `session.getStatus()` - Get session status
|
|
87
|
+
|
|
88
|
+
### Events
|
|
89
|
+
|
|
90
|
+
All classes extend EventEmitter. Listen to:
|
|
91
|
+
- `message` - New message received
|
|
92
|
+
- `typing` - Typing indicator
|
|
93
|
+
- `presence` - Presence update
|
|
94
|
+
- `receipt` - Receipt update
|
|
95
|
+
- `assigned` - Support session assigned
|
|
96
|
+
- `bot_takeover` - Bot took over
|
|
97
|
+
- `closed` - Support session closed
|
|
98
|
+
|
|
99
|
+
## Publish for testing
|
|
100
|
+
|
|
101
|
+
Base URL for **dev**: **https://dev.chaterafrika.com/** (API: `https://dev.chaterafrika.com/api/v1`, WebSocket: `wss://ws.dev.chaterafrika.com/ws`).
|
|
102
|
+
|
|
103
|
+
See **[PUBLISH_FOR_TESTING.md](./PUBLISH_FOR_TESTING.md)** for:
|
|
104
|
+
|
|
105
|
+
- Publishing to npm with `--tag beta` (`npm install @chatafrika/sdk@beta`)
|
|
106
|
+
- Installing from Git or local path (no publish)
|
|
107
|
+
- Using `npm link` for local development
|
|
108
|
+
- Dev vs local URLs
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
- [Capabilities & Usage Guide](./CAPABILITIES.md) - What the SDK can do and where to use it
|
|
113
|
+
- [Testing Guide](./TESTING.md) - How to test the SDK
|
|
114
|
+
- [Publish for testing](./PUBLISH_FOR_TESTING.md) - Publish / install SDK for testing with dev
|
|
115
|
+
|
|
116
|
+
## License
|
|
117
|
+
|
|
118
|
+
UNLICENSED
|