@ingfah-ai/client 0.1.0 → 0.1.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.
- package/CHANGELOG.md +7 -1
- package/README.md +107 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,13 @@ All notable changes to this package are documented in this file. The format foll
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the package adheres to
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## [0.1.
|
|
7
|
+
## [0.1.1] - 2026-11-25
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- The README explains how to request an access token from the Ingfah API before joining a room.
|
|
12
|
+
|
|
13
|
+
## [0.1.0] - 2026-11-25
|
|
8
14
|
|
|
9
15
|
Initial release.
|
|
10
16
|
|
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ including voice agents.
|
|
|
7
7
|
- [Features](#features)
|
|
8
8
|
- [Requirements](#requirements)
|
|
9
9
|
- [Installation](#installation)
|
|
10
|
+
- [Getting an access token](#getting-an-access-token)
|
|
10
11
|
- [Usage](#usage)
|
|
11
12
|
- [React](#react)
|
|
12
13
|
- [API overview](#api-overview)
|
|
@@ -34,7 +35,8 @@ dependencies.
|
|
|
34
35
|
- A browser with WebRTC support. The package is tested on Chromium-based browsers.
|
|
35
36
|
- A secure context: `https://`, or `localhost` during development. Browsers do not allow
|
|
36
37
|
microphone access otherwise.
|
|
37
|
-
-
|
|
38
|
+
- An Ingfah API key, kept on your own server, to request an access token for each call. See
|
|
39
|
+
[Getting an access token](#getting-an-access-token).
|
|
38
40
|
- React 18 or later, only when the React bindings are used.
|
|
39
41
|
|
|
40
42
|
## Installation
|
|
@@ -47,6 +49,110 @@ npm install @ingfah-ai/client
|
|
|
47
49
|
bun add @ingfah-ai/client
|
|
48
50
|
```
|
|
49
51
|
|
|
52
|
+
## Getting an access token
|
|
53
|
+
|
|
54
|
+
A browser joins a room with a short-lived access token. Your server requests the token from the
|
|
55
|
+
Ingfah API with your API key and passes it to the browser. The API key must never be sent to the
|
|
56
|
+
browser.
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
Browser Your server Ingfah API
|
|
60
|
+
| -- start a call --> | |
|
|
61
|
+
| | -- POST /get-call-token -->|
|
|
62
|
+
| | <-- access token ----------|
|
|
63
|
+
| <-- access token -- | |
|
|
64
|
+
| -- room.connect(serverUrl, token) ------------------------> room
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Request
|
|
68
|
+
|
|
69
|
+
```http
|
|
70
|
+
POST https://api.ingfah.ai/get-call-token
|
|
71
|
+
X-Api-Key: <your API key>
|
|
72
|
+
Content-Type: application/json
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"channel_identifier": "ingfah-voice-support",
|
|
78
|
+
"customer_context": {
|
|
79
|
+
"customer_identifier": "0812345678",
|
|
80
|
+
"plan": "gold"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
| Field | Required | Description |
|
|
86
|
+
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
87
|
+
| `channel_identifier` | Yes | The channel of the AI team that answers the call. |
|
|
88
|
+
| `customer_context` | No | Text values passed to the agent as the customer's context. `customer_identifier` becomes the customer's identity in the room and defaults to `unknown`. |
|
|
89
|
+
| `sip_direction` | No | Passed to the agent unchanged. |
|
|
90
|
+
|
|
91
|
+
The API key needs the `session:get_call_token` scope.
|
|
92
|
+
|
|
93
|
+
### Response
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"status": "success",
|
|
98
|
+
"data": {
|
|
99
|
+
"token": "<access token>"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Each token is for a new room and is valid for 15 minutes. Request a new token for every call.
|
|
105
|
+
|
|
106
|
+
| Status | Meaning |
|
|
107
|
+
| ------ | -------------------------------------------------------- |
|
|
108
|
+
| `400` | The request body is not valid. |
|
|
109
|
+
| `401` | The API key is missing or not valid. |
|
|
110
|
+
| `403` | The license of the account has expired. |
|
|
111
|
+
| `404` | No AI team of the account has this `channel_identifier`. |
|
|
112
|
+
|
|
113
|
+
An error response has `"status": "error"`, a short `error` phrase and an `error_detail` message.
|
|
114
|
+
The wording of `error_detail` may change, so do not match on it.
|
|
115
|
+
|
|
116
|
+
### Example
|
|
117
|
+
|
|
118
|
+
On your server, expose an endpoint of your own that the browser can call:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// Runs on your server. Keep INGFAH_API_KEY out of the browser.
|
|
122
|
+
export async function createCallToken(customerId: string): Promise<string> {
|
|
123
|
+
const response = await fetch('https://api.ingfah.ai/get-call-token', {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: {
|
|
126
|
+
'X-Api-Key': process.env.INGFAH_API_KEY!,
|
|
127
|
+
'Content-Type': 'application/json',
|
|
128
|
+
},
|
|
129
|
+
body: JSON.stringify({
|
|
130
|
+
channel_identifier: 'ingfah-voice-support',
|
|
131
|
+
customer_context: { customer_identifier: customerId },
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
throw new Error(`Could not get a call token: ${response.status}`);
|
|
136
|
+
}
|
|
137
|
+
const body = (await response.json()) as { data: { token: string } };
|
|
138
|
+
return body.data.token;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
In the browser, fetch the token from your server and join the room:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { Room } from '@ingfah-ai/client';
|
|
146
|
+
|
|
147
|
+
const SERVER_URL = 'wss://core.ingfah.ai';
|
|
148
|
+
|
|
149
|
+
const { token } = await (await fetch('/api/call-token', { method: 'POST' })).json();
|
|
150
|
+
|
|
151
|
+
const room = new Room();
|
|
152
|
+
await room.connect(SERVER_URL, token);
|
|
153
|
+
await room.localParticipant.setMicrophoneEnabled(true);
|
|
154
|
+
```
|
|
155
|
+
|
|
50
156
|
## Usage
|
|
51
157
|
|
|
52
158
|
### Connect to a room
|