phonic 0.30.2 → 0.30.4
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 +2 -771
- package/dist/cjs/Client.js +2 -2
- package/dist/cjs/api/resources/agents/client/Client.d.ts +3 -3
- package/dist/cjs/api/resources/agents/client/Client.js +27 -21
- package/dist/cjs/api/resources/agents/client/requests/AgentsCreateRequest.d.ts +2 -4
- package/dist/cjs/api/resources/agents/client/requests/AgentsDeleteRequest.d.ts +1 -3
- package/dist/cjs/api/resources/agents/client/requests/AgentsGetRequest.d.ts +1 -3
- package/dist/cjs/api/resources/agents/client/requests/AgentsListRequest.d.ts +1 -3
- package/dist/cjs/api/resources/agents/client/requests/UpdateAgentRequest.d.ts +2 -4
- package/dist/cjs/api/resources/agents/client/requests/UpsertAgentRequest.d.ts +2 -4
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsListRequest.d.ts +9 -27
- package/dist/cjs/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.ts +5 -15
- package/dist/cjs/api/resources/conversations/client/requests/OutboundCallRequest.d.ts +1 -1
- package/dist/cjs/api/resources/extractionSchemas/client/Client.js +20 -15
- package/dist/cjs/api/resources/extractionSchemas/client/requests/CreateExtractionSchemaRequest.d.ts +1 -3
- package/dist/cjs/api/resources/extractionSchemas/client/requests/ExtractionSchemasDeleteRequest.d.ts +1 -3
- package/dist/cjs/api/resources/extractionSchemas/client/requests/ExtractionSchemasGetRequest.d.ts +1 -3
- package/dist/cjs/api/resources/extractionSchemas/client/requests/ExtractionSchemasListRequest.d.ts +1 -3
- package/dist/cjs/api/resources/extractionSchemas/client/requests/UpdateExtractionSchemaRequest.d.ts +1 -3
- package/dist/cjs/api/resources/projects/client/Client.js +28 -21
- package/dist/cjs/api/resources/tools/client/Client.d.ts +10 -0
- package/dist/cjs/api/resources/tools/client/Client.js +30 -15
- package/dist/cjs/api/resources/tools/client/requests/CreateToolRequest.d.ts +15 -4
- package/dist/cjs/api/resources/tools/client/requests/CreateToolRequest.js +1 -0
- package/dist/cjs/api/resources/tools/client/requests/ToolsDeleteRequest.d.ts +1 -3
- package/dist/cjs/api/resources/tools/client/requests/ToolsGetRequest.d.ts +6 -3
- package/dist/cjs/api/resources/tools/client/requests/ToolsListRequest.d.ts +1 -3
- package/dist/cjs/api/resources/tools/client/requests/UpdateToolRequest.d.ts +5 -4
- package/dist/cjs/api/resources/tools/client/requests/UpdateToolRequest.js +1 -0
- package/dist/cjs/api/resources/voices/client/Client.js +8 -6
- package/dist/cjs/api/resources/voices/client/requests/VoicesListRequest.d.ts +1 -3
- package/dist/cjs/api/types/Conversation.d.ts +2 -0
- package/dist/cjs/api/types/ConversationItem.d.ts +0 -2
- package/dist/cjs/api/types/IsUserSpeakingPayload.d.ts +8 -0
- package/dist/cjs/api/types/IsUserSpeakingPayload.js +5 -0
- package/dist/cjs/api/types/OutboundCallConfig.d.ts +1 -1
- package/dist/cjs/api/types/Tool.d.ts +4 -1
- package/dist/cjs/api/types/Tool.js +1 -0
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +4 -0
- package/dist/cjs/core/auth/AuthProvider.js +2 -0
- package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
- package/dist/cjs/core/auth/AuthRequest.js +2 -0
- package/dist/cjs/core/auth/index.d.ts +2 -0
- package/dist/cjs/core/fetcher/Fetcher.js +2 -2
- package/dist/cjs/core/fetcher/index.d.ts +5 -5
- package/dist/cjs/core/fetcher/index.js +5 -5
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.mjs +2 -2
- package/dist/esm/api/resources/agents/client/Client.d.mts +3 -3
- package/dist/esm/api/resources/agents/client/Client.mjs +27 -21
- package/dist/esm/api/resources/agents/client/requests/AgentsCreateRequest.d.mts +2 -4
- package/dist/esm/api/resources/agents/client/requests/AgentsDeleteRequest.d.mts +1 -3
- package/dist/esm/api/resources/agents/client/requests/AgentsGetRequest.d.mts +1 -3
- package/dist/esm/api/resources/agents/client/requests/AgentsListRequest.d.mts +1 -3
- package/dist/esm/api/resources/agents/client/requests/UpdateAgentRequest.d.mts +2 -4
- package/dist/esm/api/resources/agents/client/requests/UpsertAgentRequest.d.mts +2 -4
- package/dist/esm/api/resources/conversations/client/requests/ConversationsListRequest.d.mts +9 -27
- package/dist/esm/api/resources/conversations/client/requests/ConversationsSipOutboundCallRequest.d.mts +5 -15
- package/dist/esm/api/resources/conversations/client/requests/OutboundCallRequest.d.mts +1 -1
- package/dist/esm/api/resources/extractionSchemas/client/Client.mjs +20 -15
- package/dist/esm/api/resources/extractionSchemas/client/requests/CreateExtractionSchemaRequest.d.mts +1 -3
- package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasDeleteRequest.d.mts +1 -3
- package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasGetRequest.d.mts +1 -3
- package/dist/esm/api/resources/extractionSchemas/client/requests/ExtractionSchemasListRequest.d.mts +1 -3
- package/dist/esm/api/resources/extractionSchemas/client/requests/UpdateExtractionSchemaRequest.d.mts +1 -3
- package/dist/esm/api/resources/projects/client/Client.mjs +28 -21
- package/dist/esm/api/resources/tools/client/Client.d.mts +10 -0
- package/dist/esm/api/resources/tools/client/Client.mjs +30 -15
- package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.d.mts +15 -4
- package/dist/esm/api/resources/tools/client/requests/CreateToolRequest.mjs +1 -0
- package/dist/esm/api/resources/tools/client/requests/ToolsDeleteRequest.d.mts +1 -3
- package/dist/esm/api/resources/tools/client/requests/ToolsGetRequest.d.mts +6 -3
- package/dist/esm/api/resources/tools/client/requests/ToolsListRequest.d.mts +1 -3
- package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.d.mts +5 -4
- package/dist/esm/api/resources/tools/client/requests/UpdateToolRequest.mjs +1 -0
- package/dist/esm/api/resources/voices/client/Client.mjs +8 -6
- package/dist/esm/api/resources/voices/client/requests/VoicesListRequest.d.mts +1 -3
- package/dist/esm/api/types/Conversation.d.mts +2 -0
- package/dist/esm/api/types/ConversationItem.d.mts +0 -2
- package/dist/esm/api/types/IsUserSpeakingPayload.d.mts +8 -0
- package/dist/esm/api/types/IsUserSpeakingPayload.mjs +4 -0
- package/dist/esm/api/types/OutboundCallConfig.d.mts +1 -1
- package/dist/esm/api/types/Tool.d.mts +4 -1
- package/dist/esm/api/types/Tool.mjs +1 -0
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +4 -0
- package/dist/esm/core/auth/AuthProvider.mjs +1 -0
- package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
- package/dist/esm/core/auth/AuthRequest.mjs +1 -0
- package/dist/esm/core/auth/index.d.mts +2 -0
- package/dist/esm/core/fetcher/Fetcher.mjs +2 -2
- package/dist/esm/core/fetcher/index.d.mts +5 -5
- package/dist/esm/core/fetcher/index.mjs +2 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +2 -2
- package/reference.md +4 -4
- package/dist/index.d.mts +0 -686
- package/dist/index.d.ts +0 -686
- package/dist/index.js +0 -643
- package/dist/index.mjs +0 -606
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FPhonic-Co%2Fphonic-node)
|
|
4
4
|
[](https://www.npmjs.com/package/phonic)
|
|
5
5
|
|
|
6
|
-
The Phonic TypeScript library provides convenient access to the Phonic
|
|
6
|
+
The Phonic TypeScript library provides convenient access to the Phonic APIs from TypeScript.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -11,775 +11,6 @@ The Phonic TypeScript library provides convenient access to the Phonic API from
|
|
|
11
11
|
npm i -s phonic
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
## Setup
|
|
15
|
-
|
|
16
|
-
Grab an API key from the [Phonic API Keys](https://phonic.co/api-keys) section and pass it to the Phonic constructor.
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { Phonic } from "phonic";
|
|
20
|
-
|
|
21
|
-
const phonic = new Phonic("ph_...");
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Agents
|
|
25
|
-
|
|
26
|
-
### List agents
|
|
27
|
-
|
|
28
|
-
```ts
|
|
29
|
-
const result = await phonic.agents.list({ project: "main" });
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Get agent
|
|
33
|
-
|
|
34
|
-
Returns an agent by name or ID.
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
const result = await phonic.agents.get("chris", { project: "main" });
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Create agent
|
|
41
|
-
|
|
42
|
-
```ts
|
|
43
|
-
const result = await phonic.agents.create({
|
|
44
|
-
name: "chris",
|
|
45
|
-
|
|
46
|
-
// Optional fields
|
|
47
|
-
project: "main", // Defaults to "main"
|
|
48
|
-
phoneNumber: "assign-automatically", // Defaults to null
|
|
49
|
-
timezone: "Australia/Melbourne", // Defaults to "America/Los_Angeles"
|
|
50
|
-
audioFormat: "mulaw_8000", // Defaults to "pcm_44100". Must be "mulaw_8000" when `phoneNumber` is "assign-automatically"
|
|
51
|
-
voiceId: "sarah", // Defaults to "grant"
|
|
52
|
-
audioSpeed: 1.1, // Defaults to 1.0. Must be between 0.5 and 1.5, multiple of 0.1
|
|
53
|
-
welcomeMessage: "Hello, how can I help you?", // Defaults to ""
|
|
54
|
-
systemPrompt: "You are an expert in {{subject}}. Be kind to {{user_name}}.", // Defaults to "Respond in 1-2 sentences."
|
|
55
|
-
templateVariables: {
|
|
56
|
-
subject: {
|
|
57
|
-
defaultValue: "Maths",
|
|
58
|
-
},
|
|
59
|
-
user_name: {
|
|
60
|
-
defaultValue: null,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
tools: ["keypad_input", "natural_conversation_ending", "my-custom-tool"], // Defaults to []
|
|
64
|
-
noInputPokeSec: 30, // Defaults to null
|
|
65
|
-
noInputPokeText: "Hey, are you with me?", // Defaults to "Are you still there?"
|
|
66
|
-
noInputEndConversationSec: 150, // Defaults to 180
|
|
67
|
-
boostedKeywords: ["Salamanca Market", "Bonorong Wildlife Sanctuary"], // Defaults to []
|
|
68
|
-
configurationEndpoint: {
|
|
69
|
-
url: "https://myapp.com/webhooks/phonic-config",
|
|
70
|
-
headers: {
|
|
71
|
-
Authorization: "Bearer 123",
|
|
72
|
-
},
|
|
73
|
-
timeoutMs: 10000, // Defaults to 3000
|
|
74
|
-
}, // Defaults to null
|
|
75
|
-
});
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Update agent
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
const result = await phonic.agents.update("chris", {
|
|
82
|
-
name: "chris",
|
|
83
|
-
|
|
84
|
-
// Optional fields
|
|
85
|
-
project: "main",
|
|
86
|
-
phoneNumber: "assign-automatically", // or null
|
|
87
|
-
timezone: "Australia/Melbourne",
|
|
88
|
-
voiceId: "sarah",
|
|
89
|
-
audioFormat: "mulaw_8000", // Must be "mulaw_8000" when `phoneNumber` is "assign-automatically"
|
|
90
|
-
audioSpeed: 1.1, // Must be between 0.5 and 1.5, multiple of 0.1
|
|
91
|
-
welcomeMessage: "Hello, how can I help you?",
|
|
92
|
-
systemPrompt: "You are an expert in {{subject}}. Be kind to {{user_name}}.",
|
|
93
|
-
templateVariables: {
|
|
94
|
-
subject: {
|
|
95
|
-
defaultValue: "Maths",
|
|
96
|
-
},
|
|
97
|
-
user_name: {
|
|
98
|
-
defaultValue: null,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
tools: ["keypad_input", "natural_conversation_ending", "my-custom-tool"],
|
|
102
|
-
noInputPokeSec: 30,
|
|
103
|
-
noInputPokeText: "Hey, are you with me?",
|
|
104
|
-
noInputEndConversationSec: 150,
|
|
105
|
-
boostedKeywords: ["Salamanca Market", "Bonorong Wildlife Sanctuary"],
|
|
106
|
-
configurationEndpoint: {
|
|
107
|
-
url: "https://myapp.com/webhooks/phonic-config",
|
|
108
|
-
headers: {
|
|
109
|
-
Authorization: "Bearer 123",
|
|
110
|
-
},
|
|
111
|
-
timeoutMs: 7000,
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Upsert agent
|
|
117
|
-
|
|
118
|
-
```ts
|
|
119
|
-
const result = await phonic.agents.upsert({
|
|
120
|
-
name: "chris",
|
|
121
|
-
|
|
122
|
-
// Optional fields
|
|
123
|
-
project: "main",
|
|
124
|
-
phoneNumber: "assign-automatically", // or null
|
|
125
|
-
timezone: "Australia/Melbourne",
|
|
126
|
-
voiceId: "sarah",
|
|
127
|
-
audioFormat: "mulaw_8000", // Must be "mulaw_8000" when `phoneNumber` is "assign-automatically"
|
|
128
|
-
audioSpeed: 1.1, // Defaults to 1.0. Must be between 0.5 and 1.5, multiple of 0.1
|
|
129
|
-
welcomeMessage: "Hello, how can I help you?",
|
|
130
|
-
systemPrompt: "You are an expert in {{subject}}. Be kind to {{user_name}}.",
|
|
131
|
-
templateVariables: {
|
|
132
|
-
subject: {
|
|
133
|
-
defaultValue: "Maths",
|
|
134
|
-
},
|
|
135
|
-
user_name: {
|
|
136
|
-
defaultValue: null,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
tools: ["keypad_input", "natural_conversation_ending", "my-custom-tool"],
|
|
140
|
-
noInputPokeSec: 30,
|
|
141
|
-
noInputPokeText: "Hey, are you with me?",
|
|
142
|
-
noInputEndConversationSec: 150,
|
|
143
|
-
boostedKeywords: ["Salamanca Market", "Bonorong Wildlife Sanctuary"],
|
|
144
|
-
configurationEndpoint: {
|
|
145
|
-
url: "https://myapp.com/webhooks/phonic-config",
|
|
146
|
-
headers: {
|
|
147
|
-
Authorization: "Bearer 123",
|
|
148
|
-
},
|
|
149
|
-
timeoutMs: 7000,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Delete agent
|
|
155
|
-
|
|
156
|
-
```ts
|
|
157
|
-
const result = await phonic.agents.delete("chris", {
|
|
158
|
-
// Optional fields
|
|
159
|
-
project: "main",
|
|
160
|
-
});
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
## Tools
|
|
164
|
-
|
|
165
|
-
### List tools
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
const result = await phonic.tools.list({
|
|
169
|
-
project: "customer-support", // Optional. Defaults to "main".
|
|
170
|
-
});
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Get tool
|
|
174
|
-
|
|
175
|
-
Returns a tool by name or ID.
|
|
176
|
-
|
|
177
|
-
```ts
|
|
178
|
-
const result = await phonic.tools.get("next_invoice", {
|
|
179
|
-
project: "customer-support", // Optional. Defaults to "main".
|
|
180
|
-
});
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### Create tool
|
|
184
|
-
|
|
185
|
-
#### Create webhook tool
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
const result = await phonic.tools.create({
|
|
189
|
-
project: "customer-support", // Optional. Defaults to "main".
|
|
190
|
-
name: "next_invoice",
|
|
191
|
-
description: "Returns the next invoice of the given user",
|
|
192
|
-
type: "custom_webhook",
|
|
193
|
-
executionMode: "sync",
|
|
194
|
-
endpointMethod: "POST",
|
|
195
|
-
endpointUrl: "https://myapp.com/webhooks/next-invoice",
|
|
196
|
-
endpointHeaders: {
|
|
197
|
-
Authorization: "Bearer 123",
|
|
198
|
-
},
|
|
199
|
-
endpointTimeoutMs: 20000, // Optional, defaults to 15000
|
|
200
|
-
parameters: [
|
|
201
|
-
{
|
|
202
|
-
type: "string",
|
|
203
|
-
name: "user",
|
|
204
|
-
description: "Full name of the user to get the invoice for",
|
|
205
|
-
isRequired: true,
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
type: "array",
|
|
209
|
-
itemType: "string",
|
|
210
|
-
name: "invoice_items",
|
|
211
|
-
description: "List of invoice items",
|
|
212
|
-
isRequired: false,
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
type: "number",
|
|
216
|
-
name: "invoice_total",
|
|
217
|
-
description: "Total invoice amount in USD",
|
|
218
|
-
isRequired: true,
|
|
219
|
-
},
|
|
220
|
-
],
|
|
221
|
-
});
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
#### Create WebSocket tool
|
|
225
|
-
|
|
226
|
-
WebSocket tools allow you to handle tool execution through the WebSocket connection. When the agent calls a WebSocket tool, you'll receive a `tool_call` message and must respond with a `tool_call_output` message that contains the tool result.
|
|
227
|
-
|
|
228
|
-
```ts
|
|
229
|
-
const result = await phonic.tools.create({
|
|
230
|
-
project: "customer-support", // Optional. Defaults to "main".
|
|
231
|
-
name: "get_product_recommendations",
|
|
232
|
-
description: "Gets personalized product recommendations",
|
|
233
|
-
type: "custom_websocket",
|
|
234
|
-
executionMode: "async",
|
|
235
|
-
toolCallOutputTimeoutMs: 5000, // Optional, defaults to 15000
|
|
236
|
-
parameters: [
|
|
237
|
-
{
|
|
238
|
-
type: "string",
|
|
239
|
-
name: "category",
|
|
240
|
-
description: "Product category (e.g., 'handbags', 'shoes', 'electronics')",
|
|
241
|
-
isRequired: true,
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
});
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
To use this tool in a conversation, add it to your agent or config:
|
|
248
|
-
|
|
249
|
-
```ts
|
|
250
|
-
// When creating an agent
|
|
251
|
-
const result = await phonic.agents.create({
|
|
252
|
-
name: "shopping-assistant",
|
|
253
|
-
tools: ["get_product_recommendations"],
|
|
254
|
-
// ... other config
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
// Or, override agent settings when starting a WebSocket conversation
|
|
258
|
-
const phonicWebSocket = phonic.sts.websocket({
|
|
259
|
-
name: "shopping-assistant",
|
|
260
|
-
tools: ["get_product_recommendations"],
|
|
261
|
-
// ... other config
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// Handle the tool call when it's invoked
|
|
265
|
-
phonicWebSocket.onMessage(async (message) => {
|
|
266
|
-
if (message.type === "tool_call" && message.name === "get_product_recommendations") {
|
|
267
|
-
const category = message.parameters.category;
|
|
268
|
-
|
|
269
|
-
// Execute your business logic
|
|
270
|
-
const recommendations = fetchRecommendations(category);
|
|
271
|
-
|
|
272
|
-
// Send the result back
|
|
273
|
-
phonicWebSocket.[sendToolCallOutput](#send-tool-output-to-phonic)({
|
|
274
|
-
toolCallId: message.tool_call_id,
|
|
275
|
-
output: {
|
|
276
|
-
products: recommendations,
|
|
277
|
-
total: recommendations.length
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Update tool
|
|
285
|
-
|
|
286
|
-
Updates a tool by ID or name. All fields are optional - only provided fields will be updated.
|
|
287
|
-
|
|
288
|
-
```ts
|
|
289
|
-
const result = await phonic.tools.update("next_invoice", {
|
|
290
|
-
project: "customer-support", // Optional. Defaults to "main".
|
|
291
|
-
name: "next_invoice_updated",
|
|
292
|
-
description: "Updated description.",
|
|
293
|
-
type: "custom_webhook",
|
|
294
|
-
executionMode: "sync",
|
|
295
|
-
endpointMethod: "POST",
|
|
296
|
-
endpointUrl: "https://myapp.com/webhooks/next-invoice-updated",
|
|
297
|
-
endpointHeaders: {
|
|
298
|
-
Authorization: "Bearer 456",
|
|
299
|
-
},
|
|
300
|
-
endpointTimeoutMs: 30000,
|
|
301
|
-
parameters: [
|
|
302
|
-
{
|
|
303
|
-
type: "string",
|
|
304
|
-
name: "user",
|
|
305
|
-
description: "Full name of the user to get the invoice for",
|
|
306
|
-
isRequired: true,
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
type: "array",
|
|
310
|
-
itemType: "string",
|
|
311
|
-
name: "invoice_items",
|
|
312
|
-
description: "List of invoice items",
|
|
313
|
-
isRequired: true,
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
type: "number",
|
|
317
|
-
name: "invoice_total",
|
|
318
|
-
description: "Total invoice amount in USD",
|
|
319
|
-
isRequired: true,
|
|
320
|
-
},
|
|
321
|
-
],
|
|
322
|
-
});
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
For WebSocket tools, you would use `toolCallOutputTimeoutMs` instead of the endpoint fields:
|
|
326
|
-
|
|
327
|
-
```ts
|
|
328
|
-
const result = await phonic.tools.update("get_product_recommendations", {
|
|
329
|
-
description: "Updated product recommendation tool",
|
|
330
|
-
toolCallOutputTimeoutMs: 7000,
|
|
331
|
-
});
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
### Delete tool
|
|
335
|
-
|
|
336
|
-
Deletes a tool by ID or name.
|
|
337
|
-
|
|
338
|
-
```ts
|
|
339
|
-
const result = await phonic.tools.delete("next_invoice", {
|
|
340
|
-
project: "customer-support", // Optional. Defaults to "main".
|
|
341
|
-
});
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## Voices
|
|
345
|
-
|
|
346
|
-
### List voices
|
|
347
|
-
|
|
348
|
-
```ts
|
|
349
|
-
const result = await phonic.voices.list({ model: "merritt" });
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### Get voice
|
|
353
|
-
|
|
354
|
-
```ts
|
|
355
|
-
const result = await phonic.voices.get("grant");
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
## Conversations
|
|
359
|
-
|
|
360
|
-
### List conversations
|
|
361
|
-
|
|
362
|
-
```ts
|
|
363
|
-
const result = await phonic.conversations.list({
|
|
364
|
-
project: "main",
|
|
365
|
-
durationMin: 10, // sec
|
|
366
|
-
durationMax: 20, // sec
|
|
367
|
-
startedAtMin: "2025-04-17", // 00:00:00 UTC time is assumed
|
|
368
|
-
startedAtMax: "2025-09-05T10:30:00.000Z",
|
|
369
|
-
});
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
### Get conversation by id
|
|
373
|
-
|
|
374
|
-
```ts
|
|
375
|
-
const result = await phonic.conversations.get("conv_b1804883-5be4-42fe-b1cf-aa84450d5c84");
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### Get conversation by external id
|
|
379
|
-
|
|
380
|
-
```ts
|
|
381
|
-
const result = await phonic.conversations.getByExternalId({
|
|
382
|
-
project: "main",
|
|
383
|
-
externalId: "CAdb9c032c809fec7feb932ea4c96d71e1",
|
|
384
|
-
});
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
### Outbound call
|
|
388
|
-
|
|
389
|
-
```ts
|
|
390
|
-
const result = await phonic.conversations.outboundCall("+19189396241", {
|
|
391
|
-
// Optional fields
|
|
392
|
-
agent: "chris",
|
|
393
|
-
template_variables: {
|
|
394
|
-
customer_name: "David",
|
|
395
|
-
subject: "Chess",
|
|
396
|
-
},
|
|
397
|
-
});
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
### Outbound call using own Twilio account
|
|
401
|
-
|
|
402
|
-
In Twilio, create a restricted API key with the following permissions: `voice -> calls -> read` and `voice -> calls -> create`.
|
|
403
|
-
|
|
404
|
-
```ts
|
|
405
|
-
const result = await phonic.conversations.twilio.outboundCall(
|
|
406
|
-
{
|
|
407
|
-
account_sid: "AC...",
|
|
408
|
-
api_key_sid: "SK...",
|
|
409
|
-
api_key_secret: "...",
|
|
410
|
-
from_phone_number: "+19189372905",
|
|
411
|
-
to_phone_number: "+19189396241",
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
// Optional fields
|
|
415
|
-
agent: "chris",
|
|
416
|
-
welcome_message: "Hello, how can I help you?",
|
|
417
|
-
project: "main",
|
|
418
|
-
system_prompt: "You are a helpful assistant.",
|
|
419
|
-
voice_id: "grant",
|
|
420
|
-
enable_silent_audio_fallback: true,
|
|
421
|
-
vad_prebuffer_duration_ms: 1800,
|
|
422
|
-
vad_min_speech_duration_ms: 40,
|
|
423
|
-
vad_min_silence_duration_ms: 550,
|
|
424
|
-
vad_threshold: 0.6,
|
|
425
|
-
tools: ["keypad_input", "natural_conversation_ending"],
|
|
426
|
-
},
|
|
427
|
-
);
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
## STS via WebSocket
|
|
431
|
-
|
|
432
|
-
To start a conversation, open a WebSocket connection:
|
|
433
|
-
|
|
434
|
-
```ts
|
|
435
|
-
const phonicWebSocket = phonic.sts.websocket({
|
|
436
|
-
input_format: "mulaw_8000",
|
|
437
|
-
|
|
438
|
-
// Optional fields
|
|
439
|
-
agent: "chris",
|
|
440
|
-
template_variables: {
|
|
441
|
-
customer_name: "David",
|
|
442
|
-
subject: "Chess",
|
|
443
|
-
},
|
|
444
|
-
welcome_message: "Hello, how can I help you?",
|
|
445
|
-
voice_id: "grant",
|
|
446
|
-
output_format: "mulaw_8000",
|
|
447
|
-
});
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
Stream input (user) audio chunks:
|
|
451
|
-
|
|
452
|
-
```ts
|
|
453
|
-
phonicWebSocket.audioChunk({
|
|
454
|
-
audio: "...", // base64 encoded audio chunk
|
|
455
|
-
});
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
Process messages that Phonic sends back to you:
|
|
459
|
-
|
|
460
|
-
```ts
|
|
461
|
-
phonicWebSocket.onMessage((message) => {
|
|
462
|
-
switch (message.type) {
|
|
463
|
-
case "input_text": {
|
|
464
|
-
console.log(`User: ${message.text}`);
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
case "audio_chunk": {
|
|
469
|
-
// Send the audio chunk to Twilio, for example:
|
|
470
|
-
twilioWebSocket.send(
|
|
471
|
-
JSON.stringify({
|
|
472
|
-
event: "media",
|
|
473
|
-
streamSid: "...",
|
|
474
|
-
media: {
|
|
475
|
-
payload: message.audio,
|
|
476
|
-
},
|
|
477
|
-
}),
|
|
478
|
-
);
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
case "tool_call": {
|
|
483
|
-
// Handle WebSocket tool calls
|
|
484
|
-
console.log(`Tool ${message.tool_name} called with parameters:`, message.parameters);
|
|
485
|
-
|
|
486
|
-
// Example: Process a product recommendations tool call
|
|
487
|
-
if (message.tool_name === "get_product_recommendations") {
|
|
488
|
-
const category = message.parameters.category;
|
|
489
|
-
const recommendations = fetchRecommendations(category);
|
|
490
|
-
|
|
491
|
-
phonicWebSocket.[sendToolCallOutput](#send-tool-output-to-phonic)({
|
|
492
|
-
toolCallId: message.tool_call_id,
|
|
493
|
-
output: {
|
|
494
|
-
products: recommendations,
|
|
495
|
-
total: recommendations.length
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
```
|
|
504
|
-
|
|
505
|
-
Update the system prompt mid-conversation:
|
|
506
|
-
|
|
507
|
-
```ts
|
|
508
|
-
phonicWebSocket.updateSystemPrompt({
|
|
509
|
-
systemPrompt: "...",
|
|
510
|
-
});
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
Set an external id for the conversation (can be the Twilio Call SID, for example):
|
|
514
|
-
|
|
515
|
-
```ts
|
|
516
|
-
phonicWebSocket.setExternalId({
|
|
517
|
-
externalId: "...",
|
|
518
|
-
});
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
### Send tool output to Phonic
|
|
522
|
-
|
|
523
|
-
When you receive a `tool_call` message for a WebSocket tool, you must respond with the tool's output using `sendToolCallOutput()`. This method sends the execution result back to Phonic so the conversation can continue.
|
|
524
|
-
|
|
525
|
-
```ts
|
|
526
|
-
phonicWebSocket.sendToolCallOutput({
|
|
527
|
-
toolCallId: "tool_call_123...", // The tool_call_id from the tool_call message
|
|
528
|
-
output: "Success! Found 2 items", // Can be any JSON-serializable value (string, number, object, array, etc.)
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
// Or with an object:
|
|
532
|
-
phonicWebSocket.sendToolCallOutput({
|
|
533
|
-
toolCallId: message.tool_call_id,
|
|
534
|
-
output: {
|
|
535
|
-
result: "success",
|
|
536
|
-
data: {
|
|
537
|
-
items: ["item1", "item2"],
|
|
538
|
-
total: 2,
|
|
539
|
-
},
|
|
540
|
-
},
|
|
541
|
-
});
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
**Important notes:**
|
|
545
|
-
|
|
546
|
-
- You must use the exact `tool_call_id` received in the `tool_call` message
|
|
547
|
-
- The `output` can be any JSON-serializable value (string, number, boolean, object, array, etc.)
|
|
548
|
-
- If you don't send a response within `toolCallOutputTimeoutMs`, the tool call will be marked as failed.
|
|
549
|
-
|
|
550
|
-
To end the conversation, close the WebSocket:
|
|
551
|
-
|
|
552
|
-
```ts
|
|
553
|
-
phonicWebSocket.close();
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
You can also listen for close and error events:
|
|
557
|
-
|
|
558
|
-
```ts
|
|
559
|
-
phonicWebSocket.onClose((event) => {
|
|
560
|
-
console.log(`Phonic WebSocket closed with code ${event.code} and reason "${event.reason}"`);
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
phonicWebSocket.onError((event) => {
|
|
564
|
-
console.log(`Error from Phonic WebSocket: ${event.message}`);
|
|
565
|
-
});
|
|
566
|
-
```
|
|
567
|
-
|
|
568
|
-
### Messages that Phonic sends back to you
|
|
569
|
-
|
|
570
|
-
#### `conversation_created`
|
|
571
|
-
|
|
572
|
-
```ts
|
|
573
|
-
{
|
|
574
|
-
type: "conversation_created";
|
|
575
|
-
conversation_id: string;
|
|
576
|
-
}
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
Sent when the conversation has been successfully created.
|
|
580
|
-
|
|
581
|
-
#### `ready_to_start_conversation`
|
|
582
|
-
|
|
583
|
-
```ts
|
|
584
|
-
{
|
|
585
|
-
type: "ready_to_start_conversation";
|
|
586
|
-
}
|
|
587
|
-
```
|
|
588
|
-
|
|
589
|
-
Sent when Phonic is ready to begin processing audio. You should start sending audio chunks after receiving this message.
|
|
590
|
-
|
|
591
|
-
#### `input_text`
|
|
592
|
-
|
|
593
|
-
```ts
|
|
594
|
-
{
|
|
595
|
-
type: "input_text";
|
|
596
|
-
text: string;
|
|
597
|
-
}
|
|
598
|
-
```
|
|
599
|
-
|
|
600
|
-
Phonic sends this message once user's audio is transcribed.
|
|
601
|
-
|
|
602
|
-
#### `audio_chunk`
|
|
603
|
-
|
|
604
|
-
```ts
|
|
605
|
-
{
|
|
606
|
-
type: "audio_chunk";
|
|
607
|
-
audio: string; // base64 encoded array of audio data (each value is in range [-32768..32767] for "pcm_44100" output format, and in range [0..255] for "mulaw_8000" output format)
|
|
608
|
-
text: string; // May potentially be "", but will typically be one word.
|
|
609
|
-
}
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
These are the assistant response audio chunks.
|
|
613
|
-
|
|
614
|
-
#### `audio_finished`
|
|
615
|
-
|
|
616
|
-
```ts
|
|
617
|
-
{
|
|
618
|
-
type: "audio_finished";
|
|
619
|
-
}
|
|
620
|
-
```
|
|
621
|
-
|
|
622
|
-
Sent after the last "audio_chunk" is sent.
|
|
623
|
-
|
|
624
|
-
#### `user_started_speaking`
|
|
625
|
-
|
|
626
|
-
```ts
|
|
627
|
-
{
|
|
628
|
-
type: "user_started_speaking";
|
|
629
|
-
}
|
|
630
|
-
```
|
|
631
|
-
|
|
632
|
-
Sent when the user begins speaking.
|
|
633
|
-
|
|
634
|
-
#### `user_finished_speaking`
|
|
635
|
-
|
|
636
|
-
```ts
|
|
637
|
-
{
|
|
638
|
-
type: "user_finished_speaking";
|
|
639
|
-
}
|
|
640
|
-
```
|
|
641
|
-
|
|
642
|
-
Sent when the user stops speaking.
|
|
643
|
-
|
|
644
|
-
#### `interrupted_response`
|
|
645
|
-
|
|
646
|
-
```ts
|
|
647
|
-
{
|
|
648
|
-
type: "interrupted_response",
|
|
649
|
-
text: string, // partial assistant response that cuts off approximately where the user interrupted
|
|
650
|
-
}
|
|
651
|
-
```
|
|
652
|
-
|
|
653
|
-
Sent when the user interrupts the assistant, after the user has finished speaking.
|
|
654
|
-
|
|
655
|
-
#### `assistant_chose_not_to_respond`
|
|
656
|
-
|
|
657
|
-
```ts
|
|
658
|
-
{
|
|
659
|
-
type: "assistant_chose_not_to_respond";
|
|
660
|
-
}
|
|
661
|
-
```
|
|
662
|
-
|
|
663
|
-
Sent when the assistant decides not to respond to the user's input.
|
|
664
|
-
|
|
665
|
-
#### `assistant_ended_conversation`
|
|
666
|
-
|
|
667
|
-
```ts
|
|
668
|
-
{
|
|
669
|
-
type: "assistant_ended_conversation";
|
|
670
|
-
}
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
Sent when the assistant decides to end the conversation.
|
|
674
|
-
|
|
675
|
-
#### `tool_call`
|
|
676
|
-
|
|
677
|
-
```ts
|
|
678
|
-
{
|
|
679
|
-
type: "tool_call";
|
|
680
|
-
tool_call_id: string;
|
|
681
|
-
tool_name: string;
|
|
682
|
-
parameters: Record<string, unknown>;
|
|
683
|
-
}
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
Sent when a WebSocket tool is called during the conversation. When you receive this message, you should:
|
|
687
|
-
|
|
688
|
-
1. Process the tool call using the provided `tool_name` and `parameters`
|
|
689
|
-
2. Send back the result using [`phonicWebSocket.sendToolCallOutput`](#send-tool-output-to-phonic)
|
|
690
|
-
|
|
691
|
-
This is only sent for tools created with `type: "custom_websocket"`. Webhook tools are executed server-side and only send `tool_call_output_processed` messages.
|
|
692
|
-
|
|
693
|
-
#### `tool_call_output_processed`
|
|
694
|
-
|
|
695
|
-
```ts
|
|
696
|
-
{
|
|
697
|
-
type: "tool_call_output_processed";
|
|
698
|
-
tool_call_id: string;
|
|
699
|
-
tool: {
|
|
700
|
-
id: string;
|
|
701
|
-
name: string;
|
|
702
|
-
};
|
|
703
|
-
endpoint_url: string | null;
|
|
704
|
-
endpoint_timeout_ms: number | null;
|
|
705
|
-
endpoint_called_at: string | null;
|
|
706
|
-
request_body: {
|
|
707
|
-
call_info: {
|
|
708
|
-
from_phone_number: string;
|
|
709
|
-
to_phone_number: string;
|
|
710
|
-
} | null;
|
|
711
|
-
[key: string]: unknown;
|
|
712
|
-
} | null;
|
|
713
|
-
response_body: Record<string, unknown> | null;
|
|
714
|
-
response_status_code: number | null;
|
|
715
|
-
timed_out: boolean | null;
|
|
716
|
-
error_message: string | null;
|
|
717
|
-
}
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
Sent when a tool is called during the conversation. Built-in tools will have null values for endpoint-related fields.
|
|
721
|
-
|
|
722
|
-
When a custom tool is called, the `request_body` field always includes a `call_info` field.
|
|
723
|
-
If the conversation is not a phone call, `call_info` will be `null`. If it is a phone call, `call_info` will be an object with `from_phone_number` and `to_phone_number` fields, both formatted as E.164 phone numbers (e.g., "+1234567890").
|
|
724
|
-
|
|
725
|
-
#### `error`
|
|
726
|
-
|
|
727
|
-
```ts
|
|
728
|
-
{
|
|
729
|
-
type: "error";
|
|
730
|
-
error: {
|
|
731
|
-
message: string;
|
|
732
|
-
code?: string;
|
|
733
|
-
};
|
|
734
|
-
param_errors?: Record<string, string>;
|
|
735
|
-
}
|
|
736
|
-
```
|
|
737
|
-
|
|
738
|
-
Sent when an error occurs during the conversation.
|
|
739
|
-
|
|
740
|
-
## Projects
|
|
741
|
-
|
|
742
|
-
### List projects
|
|
743
|
-
|
|
744
|
-
```ts
|
|
745
|
-
const result = await phonic.projects.list();
|
|
746
|
-
```
|
|
747
|
-
|
|
748
|
-
### Get project
|
|
749
|
-
|
|
750
|
-
Returns a project by name or ID.
|
|
751
|
-
|
|
752
|
-
```ts
|
|
753
|
-
const result = await phonic.projects.get("main");
|
|
754
|
-
```
|
|
755
|
-
|
|
756
|
-
### Create project
|
|
757
|
-
|
|
758
|
-
```ts
|
|
759
|
-
const result = await phonic.projects.create({
|
|
760
|
-
name: "customer-support",
|
|
761
|
-
});
|
|
762
|
-
```
|
|
763
|
-
|
|
764
|
-
### Update project
|
|
765
|
-
|
|
766
|
-
```ts
|
|
767
|
-
const result = await phonic.projects.update("customer-support", {
|
|
768
|
-
name: "updated-customer-support",
|
|
769
|
-
defaultAgent: "another-agent",
|
|
770
|
-
});
|
|
771
|
-
```
|
|
772
|
-
|
|
773
|
-
### Delete project
|
|
774
|
-
|
|
775
|
-
```ts
|
|
776
|
-
const result = await phonic.projects.delete("customer-support");
|
|
777
|
-
```
|
|
778
|
-
|
|
779
|
-
## License
|
|
780
|
-
|
|
781
|
-
MIT
|
|
782
|
-
|
|
783
14
|
## Reference
|
|
784
15
|
|
|
785
16
|
A full reference for this library is available [here](https://github.com/Phonic-Co/phonic-node/blob/HEAD/./reference.md).
|
|
@@ -798,7 +29,7 @@ await client.agents.create({
|
|
|
798
29
|
name: "support-agent",
|
|
799
30
|
phone_number: "assign-automatically",
|
|
800
31
|
timezone: "America/Los_Angeles",
|
|
801
|
-
voice_id: "
|
|
32
|
+
voice_id: "grant",
|
|
802
33
|
audio_speed: 1,
|
|
803
34
|
welcome_message: "Hi {{customer_name}}. How can I help you today?",
|
|
804
35
|
system_prompt: "You are an expert in {{subject}}. Be friendly, helpful and concise.",
|