@telnyx/ai-agent-lib 0.1.7 → 0.1.9
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 +27 -5
- package/dist/client.d.ts +69 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1765 -1628
- package/dist/react/client-context.d.ts +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -86,7 +86,12 @@ function VoiceChat() {
|
|
|
86
86
|
<h3>Agent State: {agentState}</h3>
|
|
87
87
|
|
|
88
88
|
<button
|
|
89
|
-
onClick={() =>
|
|
89
|
+
onClick={() =>
|
|
90
|
+
client.startConversation({
|
|
91
|
+
callerName: 'Jane Doe',
|
|
92
|
+
customHeaders: [{ name: 'X-Account-Number', value: '123456' }]
|
|
93
|
+
})
|
|
94
|
+
}
|
|
90
95
|
disabled={connectionState !== 'connected'}
|
|
91
96
|
>
|
|
92
97
|
Start Conversation
|
|
@@ -142,6 +147,7 @@ function VoiceChat() {
|
|
|
142
147
|
| `agentId` | `string` | ✅ | - | Your Telnyx AI agent ID |
|
|
143
148
|
| `versionId` | `string` | ❌ | `"main"` | Agent version to use |
|
|
144
149
|
| `environment` | `"production" \| "development"` | ❌ | `"production"` | Telnyx environment |
|
|
150
|
+
| `debug` | `boolean` | ❌ | `false` | Enable debug logging |
|
|
145
151
|
|
|
146
152
|
### Hooks
|
|
147
153
|
|
|
@@ -151,11 +157,20 @@ Returns the `TelnyxAIAgent` instance for direct API access.
|
|
|
151
157
|
**Methods:**
|
|
152
158
|
- `connect()` - Connect to Telnyx platform
|
|
153
159
|
- `disconnect()` - Disconnect and cleanup
|
|
154
|
-
- `startConversation()` - Start a new conversation
|
|
160
|
+
- `startConversation(options?)` - Start a new conversation with optional caller metadata and headers
|
|
155
161
|
- `endConversation()` - End the current conversation
|
|
156
162
|
- `sendConversationMessage(message: string)` - Send a text message during an active conversation
|
|
157
163
|
- `transcript` - Get current transcript array
|
|
158
164
|
|
|
165
|
+
**`startConversation` Options:**
|
|
166
|
+
|
|
167
|
+
| Option | Type | Description |
|
|
168
|
+
|--------|------|-------------|
|
|
169
|
+
| `destinationNumber` | `string` | [docs](https://developers.telnyx.com/development/webrtc/js-sdk/interfaces/icalloptions#destinationnumber) |
|
|
170
|
+
| `callerNumber` | `string` | [docs](https://developers.telnyx.com/development/webrtc/js-sdk/interfaces/icalloptions#callernumber) |
|
|
171
|
+
| `callerName` | `string` | [docs](https://developers.telnyx.com/development/webrtc/js-sdk/interfaces/icalloptions#callername) |
|
|
172
|
+
| `customHeaders` | `{ name: string; value: string }[]` | [docs](https://developers.telnyx.com/development/webrtc/js-sdk/interfaces/icalloptions#customheaders) |
|
|
173
|
+
|
|
159
174
|
**Events:**
|
|
160
175
|
- `agent.connected` - Agent successfully connected
|
|
161
176
|
- `agent.disconnected` - Agent disconnected
|
|
@@ -224,8 +239,16 @@ agent.on('conversation.update', (notification) => {
|
|
|
224
239
|
}
|
|
225
240
|
});
|
|
226
241
|
|
|
227
|
-
// Start a conversation
|
|
228
|
-
await agent.startConversation(
|
|
242
|
+
// Start a conversation with optional caller metadata
|
|
243
|
+
await agent.startConversation({
|
|
244
|
+
callerNumber: '+15551234567',
|
|
245
|
+
callerName: 'John Doe',
|
|
246
|
+
customHeaders: [
|
|
247
|
+
{ name: 'X-User-Plan', value: 'gold' },
|
|
248
|
+
{ name: 'X-Session-Id', value: 'session-abc' }
|
|
249
|
+
],
|
|
250
|
+
audio: { autoGainControl: true, noiseSuppression: true }
|
|
251
|
+
});
|
|
229
252
|
|
|
230
253
|
// Send messages during an active conversation
|
|
231
254
|
// Note: This will only work when there's an active call
|
|
@@ -350,4 +373,3 @@ For support, please contact Telnyx support or check the [Telnyx documentation](h
|
|
|
350
373
|
## Contributing
|
|
351
374
|
|
|
352
375
|
This library is maintained by Telnyx. For bug reports or feature requests, please contact Telnyx support.elnyx AI Agent Library
|
|
353
|
-
|
package/dist/client.d.ts
CHANGED
|
@@ -5,20 +5,88 @@ export type TelnyxAIAgentConstructorParams = {
|
|
|
5
5
|
agentId: string;
|
|
6
6
|
versionId?: string;
|
|
7
7
|
environment?: "production" | "development";
|
|
8
|
+
debug?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare class TelnyxAIAgent extends EventEmitter<AIAgentEvents> {
|
|
10
11
|
private telnyxRTC;
|
|
11
12
|
private transcription;
|
|
12
13
|
agentId: string;
|
|
13
14
|
versionId: string;
|
|
15
|
+
debug: boolean;
|
|
14
16
|
private audioStreamMonitor;
|
|
15
17
|
activeCall: Call | null;
|
|
16
18
|
constructor(params: TelnyxAIAgentConstructorParams);
|
|
19
|
+
/**
|
|
20
|
+
* Connects to the Telnyx WebRTC service and establishes a session with the AI agent.
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise that resolves when the connection is established
|
|
23
|
+
*/
|
|
17
24
|
connect(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Disconnects from the Telnyx WebRTC service and cleans up all event listeners.
|
|
27
|
+
* Emits an 'agent.disconnected' event before completing cleanup.
|
|
28
|
+
*/
|
|
18
29
|
disconnect(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Sends a text message to the AI agent during an active conversation.
|
|
32
|
+
* Requires an active conversation to be in progress.
|
|
33
|
+
*
|
|
34
|
+
* @param message - The text message to send to the AI agent
|
|
35
|
+
* @param attachments - Optional array of base64 encoded file attachments (defaults to empty array)
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* client.sendConversationMessage('Hello, I need help with my account');
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // With attachments
|
|
42
|
+
* client.sendConversationMessage('Please review this document', ['base64EncodedData...']);
|
|
43
|
+
*/
|
|
19
44
|
sendConversationMessage(message: string, attachments?: string[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the current conversation transcript.
|
|
47
|
+
*
|
|
48
|
+
* @returns Array of transcript items containing all messages exchanged during the conversation
|
|
49
|
+
*/
|
|
20
50
|
get transcript(): TranscriptItem[];
|
|
21
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Initiates a conversation with the AI agent.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Optional configuration for the call.
|
|
55
|
+
* Note: This method will ALWAYS call the AI agent, the optional parameters are primarily used for log referencing or passing parameters to the agent via the custom headers.
|
|
56
|
+
* @param options.destinationNumber - The destination phone number (defaults to "xxx"). Note, regardless of the destination number, the call will be made to the AI agent.
|
|
57
|
+
* @param options.callerNumber - The caller's phone number
|
|
58
|
+
* @param options.callerName - The caller's display name
|
|
59
|
+
* @param options.customHeaders - Custom SIP headers to pass to the AI agent. Headers with the `X-` prefix
|
|
60
|
+
* will be mapped to dynamic variables in the AI assistant (e.g., `X-Account-Number` becomes `{{account_number}}`).
|
|
61
|
+
* Note: Hyphens in header names are converted to underscores in variable names.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Start conversation with custom headers for dynamic variables
|
|
65
|
+
* client.startConversation({
|
|
66
|
+
* callerName: 'John Doe',
|
|
67
|
+
* customHeaders: [
|
|
68
|
+
* { name: 'X-User-Name', value: 'user-name' },
|
|
69
|
+
* { name: 'X-Agent-Session', value: 'session-abc' }
|
|
70
|
+
* ]
|
|
71
|
+
* });
|
|
72
|
+
* // These headers will be available in your AI assistant as {{user_name}} and {{agent_session}}
|
|
73
|
+
* @param options.audio - Audio constraints for the call (boolean or MediaTrackConstraints)
|
|
74
|
+
*/
|
|
75
|
+
startConversation(options?: {
|
|
76
|
+
destinationNumber?: string;
|
|
77
|
+
callerNumber?: string;
|
|
78
|
+
callerName?: string;
|
|
79
|
+
customHeaders?: {
|
|
80
|
+
name: string;
|
|
81
|
+
value: string;
|
|
82
|
+
}[];
|
|
83
|
+
audio?: boolean | MediaTrackConstraints;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Ends the current active conversation with the AI agent.
|
|
87
|
+
*
|
|
88
|
+
* @returns Promise that resolves when the call is hung up, or undefined if there is no active call
|
|
89
|
+
*/
|
|
22
90
|
endConversation(): void | undefined;
|
|
23
91
|
private onClientReady;
|
|
24
92
|
private onClientOrSocketError;
|
package/dist/index.d.ts
CHANGED