@solo3li/backend-node 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +69 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @solo3li/backend-node
2
+
3
+ The official Node.js Server SDK for the **Voice AI CPaaS**.
4
+ This library allows SaaS backends to securely authenticate with the CPaaS API and generate short-lived LiveKit access tokens for their front-end users.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install @solo3li/backend-node
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ **Security Warning:** This SDK must **ONLY** be used on your secure backend server. Never expose your `apiKey` in a client-side application (React, Angular, iOS, etc.).
15
+
16
+ ### 1. Initialize the Client
17
+
18
+ ```typescript
19
+ import { CPaaSClient } from '@solo3li/backend-node';
20
+
21
+ // Initialize the client with your secret API Key from the Dashboard
22
+ const cpaas = new CPaaSClient({
23
+ apiKey: 'sk_1234567890abcdef...', // Your Secret API Key
24
+ baseUrl: 'https://api.yourcpaas.com' // Optional: Custom CPaaS URL
25
+ });
26
+ ```
27
+
28
+ ### 2. Generate a Connection Token
29
+
30
+ When a user on your frontend clicks "Call AI", your frontend should make a REST request to your backend. Your backend then uses this SDK to generate a secure token.
31
+
32
+ ```typescript
33
+ import express from 'express';
34
+ const app = express();
35
+
36
+ app.post('/api/get-voice-token', async (req, res) => {
37
+ try {
38
+ // Generate a token for the AI Agent
39
+ const connection = await cpaas.createConnectionToken({
40
+ agentId: '550e8400-e29b-41d4-a716-446655440000', // The ID of the Agent from your Dashboard
41
+ participantName: 'Ahmed (Premium User)', // Name of the end-user
42
+ metadata: {
43
+ 'StoreName': 'Noon E-commerce', // Dynamic context to inject into the AI's prompt
44
+ 'Language': 'Arabic'
45
+ }
46
+ });
47
+
48
+ // Send the token and URL back to your Frontend (React/iOS)
49
+ res.json({
50
+ token: connection.token,
51
+ livekitUrl: connection.livekitUrl
52
+ });
53
+
54
+ } catch (error) {
55
+ console.error('Failed to generate CPaaS token:', error);
56
+ res.status(500).json({ error: 'Failed to connect to AI' });
57
+ }
58
+ });
59
+ ```
60
+
61
+ ## Response Object
62
+
63
+ The `createConnectionToken` method returns an object containing:
64
+ - `token`: A secure JWT access token valid for this specific session.
65
+ - `roomName`: The unique ID of the generated voice room.
66
+ - `livekitUrl`: The WebSocket URL that the Client SDK should connect to.
67
+
68
+ ## License
69
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solo3li/backend-node",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Node.js SDK for Voice AI CPaaS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",