phonic 0.17.0 → 0.18.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/README.md +31 -1
- package/dist/index.d.mts +35 -8
- package/dist/index.d.ts +35 -8
- package/dist/index.js +35 -5
- package/dist/index.mjs +35 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ Node.js library for the Phonic API.
|
|
|
11
11
|
- [Get conversation by external id](#get-conversation-by-external-id)
|
|
12
12
|
- [List conversations](#list-conversations)
|
|
13
13
|
- [STS outbound call](#sts-outbound-call)
|
|
14
|
+
- [STS outbound call using own Twilio account](#sts-outbound-call-using-own-twilio-account)
|
|
14
15
|
- [STS via WebSocket](#sts-via-websocket)
|
|
15
16
|
- [Messages that Phonic sends back to you](#messages-that-phonic-sends-back-to-you)
|
|
16
17
|
|
|
@@ -108,7 +109,36 @@ const { data, error } = await phonic.sts.outboundCall("+19189396241", {
|
|
|
108
109
|
vad_min_speech_duration_ms: 40,
|
|
109
110
|
vad_min_silence_duration_ms: 550,
|
|
110
111
|
vad_threshold: 0.6,
|
|
111
|
-
})
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### STS outbound call using own Twilio account
|
|
116
|
+
|
|
117
|
+
In Twilio, create a restricted API key with the following permission: voice -> calls -> create
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const { data, error } = await phonic.sts.twilio.outboundCall(
|
|
121
|
+
{
|
|
122
|
+
account_sid: "AC...",
|
|
123
|
+
api_key_sid: "SK...",
|
|
124
|
+
api_key_secret: "...",
|
|
125
|
+
from_phone_number: "+19189372905",
|
|
126
|
+
to_phone_number: "+19189396241",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
welcome_message: "Hello, how can I help you?",
|
|
130
|
+
|
|
131
|
+
// Optional fields
|
|
132
|
+
project: "main",
|
|
133
|
+
system_prompt: "You are a helpful assistant.",
|
|
134
|
+
voice_id: "greta",
|
|
135
|
+
enable_silent_audio_fallback: true,
|
|
136
|
+
vad_prebuffer_duration_ms: 1800,
|
|
137
|
+
vad_min_speech_duration_ms: 40,
|
|
138
|
+
vad_min_silence_duration_ms: 550,
|
|
139
|
+
vad_threshold: 0.6,
|
|
140
|
+
}
|
|
141
|
+
);
|
|
112
142
|
```
|
|
113
143
|
|
|
114
144
|
### STS via WebSocket
|
package/dist/index.d.mts
CHANGED
|
@@ -7,20 +7,21 @@ type PhonicConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
type FetchOptions = {
|
|
9
9
|
method: "GET";
|
|
10
|
+
headers?: Record<string, string>;
|
|
10
11
|
} | {
|
|
11
12
|
method: "POST";
|
|
13
|
+
headers?: Record<string, string>;
|
|
12
14
|
body: string;
|
|
13
15
|
};
|
|
14
|
-
type ErrorResponse = {
|
|
15
|
-
message: string;
|
|
16
|
-
code?: string;
|
|
17
|
-
};
|
|
18
16
|
type DataOrError<T> = Promise<{
|
|
19
17
|
data: T;
|
|
20
18
|
error: null;
|
|
21
19
|
} | {
|
|
22
20
|
data: null;
|
|
23
|
-
error:
|
|
21
|
+
error: {
|
|
22
|
+
message: string;
|
|
23
|
+
code?: string;
|
|
24
|
+
};
|
|
24
25
|
}>;
|
|
25
26
|
type ISODate = `${string}-${string}-${string}`;
|
|
26
27
|
type ISODateTime$1 = `${string}Z`;
|
|
@@ -131,6 +132,25 @@ type OutboundCallSuccessResponse = {
|
|
|
131
132
|
success: true;
|
|
132
133
|
};
|
|
133
134
|
|
|
135
|
+
type PhonicSTSTwilioOutboundCallParams = {
|
|
136
|
+
account_sid: string;
|
|
137
|
+
api_key_sid: string;
|
|
138
|
+
api_key_secret: string;
|
|
139
|
+
from_phone_number: string;
|
|
140
|
+
to_phone_number: string;
|
|
141
|
+
};
|
|
142
|
+
type PhonicSTSTwilioOutboundCallConfig = PhonicSTSOutboundCallConfig;
|
|
143
|
+
type TwilioOutboundCallSuccessResponse = {
|
|
144
|
+
success: true;
|
|
145
|
+
callSid: string;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
declare class Twilio {
|
|
149
|
+
private readonly phonic;
|
|
150
|
+
constructor(phonic: Phonic);
|
|
151
|
+
outboundCall(params: PhonicSTSTwilioOutboundCallParams, config: PhonicSTSTwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
|
|
152
|
+
}
|
|
153
|
+
|
|
134
154
|
declare class PhonicSTSWebSocket {
|
|
135
155
|
private readonly ws;
|
|
136
156
|
private readonly config;
|
|
@@ -157,6 +177,7 @@ declare class PhonicSTSWebSocket {
|
|
|
157
177
|
|
|
158
178
|
declare class SpeechToSpeech {
|
|
159
179
|
private readonly phonic;
|
|
180
|
+
readonly twilio: Twilio;
|
|
160
181
|
constructor(phonic: Phonic);
|
|
161
182
|
websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
|
|
162
183
|
outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
|
|
@@ -194,14 +215,20 @@ declare class Phonic {
|
|
|
194
215
|
fetchRequest<T>(path: string, options: FetchOptions): DataOrError<T>;
|
|
195
216
|
get<T>(path: string): Promise<{
|
|
196
217
|
data: null;
|
|
197
|
-
error:
|
|
218
|
+
error: {
|
|
219
|
+
message: string;
|
|
220
|
+
code?: string;
|
|
221
|
+
};
|
|
198
222
|
} | {
|
|
199
223
|
data: T;
|
|
200
224
|
error: null;
|
|
201
225
|
}>;
|
|
202
|
-
post<T>(path: string, body: Record<string, unknown>): Promise<{
|
|
226
|
+
post<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
|
|
203
227
|
data: null;
|
|
204
|
-
error:
|
|
228
|
+
error: {
|
|
229
|
+
message: string;
|
|
230
|
+
code?: string;
|
|
231
|
+
};
|
|
205
232
|
} | {
|
|
206
233
|
data: T;
|
|
207
234
|
error: null;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,20 +7,21 @@ type PhonicConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
type FetchOptions = {
|
|
9
9
|
method: "GET";
|
|
10
|
+
headers?: Record<string, string>;
|
|
10
11
|
} | {
|
|
11
12
|
method: "POST";
|
|
13
|
+
headers?: Record<string, string>;
|
|
12
14
|
body: string;
|
|
13
15
|
};
|
|
14
|
-
type ErrorResponse = {
|
|
15
|
-
message: string;
|
|
16
|
-
code?: string;
|
|
17
|
-
};
|
|
18
16
|
type DataOrError<T> = Promise<{
|
|
19
17
|
data: T;
|
|
20
18
|
error: null;
|
|
21
19
|
} | {
|
|
22
20
|
data: null;
|
|
23
|
-
error:
|
|
21
|
+
error: {
|
|
22
|
+
message: string;
|
|
23
|
+
code?: string;
|
|
24
|
+
};
|
|
24
25
|
}>;
|
|
25
26
|
type ISODate = `${string}-${string}-${string}`;
|
|
26
27
|
type ISODateTime$1 = `${string}Z`;
|
|
@@ -131,6 +132,25 @@ type OutboundCallSuccessResponse = {
|
|
|
131
132
|
success: true;
|
|
132
133
|
};
|
|
133
134
|
|
|
135
|
+
type PhonicSTSTwilioOutboundCallParams = {
|
|
136
|
+
account_sid: string;
|
|
137
|
+
api_key_sid: string;
|
|
138
|
+
api_key_secret: string;
|
|
139
|
+
from_phone_number: string;
|
|
140
|
+
to_phone_number: string;
|
|
141
|
+
};
|
|
142
|
+
type PhonicSTSTwilioOutboundCallConfig = PhonicSTSOutboundCallConfig;
|
|
143
|
+
type TwilioOutboundCallSuccessResponse = {
|
|
144
|
+
success: true;
|
|
145
|
+
callSid: string;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
declare class Twilio {
|
|
149
|
+
private readonly phonic;
|
|
150
|
+
constructor(phonic: Phonic);
|
|
151
|
+
outboundCall(params: PhonicSTSTwilioOutboundCallParams, config: PhonicSTSTwilioOutboundCallConfig): DataOrError<TwilioOutboundCallSuccessResponse>;
|
|
152
|
+
}
|
|
153
|
+
|
|
134
154
|
declare class PhonicSTSWebSocket {
|
|
135
155
|
private readonly ws;
|
|
136
156
|
private readonly config;
|
|
@@ -157,6 +177,7 @@ declare class PhonicSTSWebSocket {
|
|
|
157
177
|
|
|
158
178
|
declare class SpeechToSpeech {
|
|
159
179
|
private readonly phonic;
|
|
180
|
+
readonly twilio: Twilio;
|
|
160
181
|
constructor(phonic: Phonic);
|
|
161
182
|
websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
|
|
162
183
|
outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
|
|
@@ -194,14 +215,20 @@ declare class Phonic {
|
|
|
194
215
|
fetchRequest<T>(path: string, options: FetchOptions): DataOrError<T>;
|
|
195
216
|
get<T>(path: string): Promise<{
|
|
196
217
|
data: null;
|
|
197
|
-
error:
|
|
218
|
+
error: {
|
|
219
|
+
message: string;
|
|
220
|
+
code?: string;
|
|
221
|
+
};
|
|
198
222
|
} | {
|
|
199
223
|
data: T;
|
|
200
224
|
error: null;
|
|
201
225
|
}>;
|
|
202
|
-
post<T>(path: string, body: Record<string, unknown>): Promise<{
|
|
226
|
+
post<T>(path: string, body: Record<string, unknown>, headers?: Record<string, string>): Promise<{
|
|
203
227
|
data: null;
|
|
204
|
-
error:
|
|
228
|
+
error: {
|
|
229
|
+
message: string;
|
|
230
|
+
code?: string;
|
|
231
|
+
};
|
|
205
232
|
} | {
|
|
206
233
|
data: T;
|
|
207
234
|
error: null;
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// package.json
|
|
38
|
-
var version = "0.
|
|
38
|
+
var version = "0.18.1";
|
|
39
39
|
|
|
40
40
|
// src/conversations/index.ts
|
|
41
41
|
var Conversations = class {
|
|
@@ -85,6 +85,29 @@ var Conversations = class {
|
|
|
85
85
|
// src/sts/index.ts
|
|
86
86
|
var import_ws = __toESM(require("ws"));
|
|
87
87
|
|
|
88
|
+
// src/sts/twilio/index.ts
|
|
89
|
+
var Twilio = class {
|
|
90
|
+
constructor(phonic) {
|
|
91
|
+
this.phonic = phonic;
|
|
92
|
+
}
|
|
93
|
+
async outboundCall(params, config) {
|
|
94
|
+
const response = await this.phonic.post(
|
|
95
|
+
"/sts/twilio/outbound_call",
|
|
96
|
+
{
|
|
97
|
+
from_phone_number: params.from_phone_number,
|
|
98
|
+
to_phone_number: params.to_phone_number,
|
|
99
|
+
config
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"X-Twilio-Account-Sid": params.account_sid,
|
|
103
|
+
"X-Twilio-Api-Key-Sid": params.api_key_sid,
|
|
104
|
+
"X-Twilio-Api-Key-Secret": params.api_key_secret
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
return response;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
88
111
|
// src/sts/websocket.ts
|
|
89
112
|
var PhonicSTSWebSocket = class {
|
|
90
113
|
constructor(ws, config) {
|
|
@@ -188,7 +211,9 @@ var PhonicSTSWebSocket = class {
|
|
|
188
211
|
var SpeechToSpeech = class {
|
|
189
212
|
constructor(phonic) {
|
|
190
213
|
this.phonic = phonic;
|
|
214
|
+
this.twilio = new Twilio(phonic);
|
|
191
215
|
}
|
|
216
|
+
twilio;
|
|
192
217
|
websocket(config) {
|
|
193
218
|
const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
|
|
194
219
|
const queryString = new URLSearchParams({
|
|
@@ -266,9 +291,13 @@ var Phonic = class {
|
|
|
266
291
|
sts = new SpeechToSpeech(this);
|
|
267
292
|
async fetchRequest(path, options) {
|
|
268
293
|
try {
|
|
294
|
+
const { headers, ...restOptions } = options;
|
|
269
295
|
const response = await fetch(`${this.baseUrl}/v1${path}`, {
|
|
270
|
-
headers:
|
|
271
|
-
|
|
296
|
+
headers: {
|
|
297
|
+
...this.headers,
|
|
298
|
+
...headers
|
|
299
|
+
},
|
|
300
|
+
...restOptions
|
|
272
301
|
});
|
|
273
302
|
if (response.ok) {
|
|
274
303
|
const data = await response.json();
|
|
@@ -304,10 +333,11 @@ var Phonic = class {
|
|
|
304
333
|
async get(path) {
|
|
305
334
|
return this.fetchRequest(path, { method: "GET" });
|
|
306
335
|
}
|
|
307
|
-
async post(path, body) {
|
|
336
|
+
async post(path, body, headers) {
|
|
308
337
|
return this.fetchRequest(path, {
|
|
309
338
|
method: "POST",
|
|
310
|
-
body: JSON.stringify(body)
|
|
339
|
+
body: JSON.stringify(body),
|
|
340
|
+
headers
|
|
311
341
|
});
|
|
312
342
|
}
|
|
313
343
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.18.1";
|
|
3
3
|
|
|
4
4
|
// src/conversations/index.ts
|
|
5
5
|
var Conversations = class {
|
|
@@ -49,6 +49,29 @@ var Conversations = class {
|
|
|
49
49
|
// src/sts/index.ts
|
|
50
50
|
import WebSocket from "ws";
|
|
51
51
|
|
|
52
|
+
// src/sts/twilio/index.ts
|
|
53
|
+
var Twilio = class {
|
|
54
|
+
constructor(phonic) {
|
|
55
|
+
this.phonic = phonic;
|
|
56
|
+
}
|
|
57
|
+
async outboundCall(params, config) {
|
|
58
|
+
const response = await this.phonic.post(
|
|
59
|
+
"/sts/twilio/outbound_call",
|
|
60
|
+
{
|
|
61
|
+
from_phone_number: params.from_phone_number,
|
|
62
|
+
to_phone_number: params.to_phone_number,
|
|
63
|
+
config
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"X-Twilio-Account-Sid": params.account_sid,
|
|
67
|
+
"X-Twilio-Api-Key-Sid": params.api_key_sid,
|
|
68
|
+
"X-Twilio-Api-Key-Secret": params.api_key_secret
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
return response;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
52
75
|
// src/sts/websocket.ts
|
|
53
76
|
var PhonicSTSWebSocket = class {
|
|
54
77
|
constructor(ws, config) {
|
|
@@ -152,7 +175,9 @@ var PhonicSTSWebSocket = class {
|
|
|
152
175
|
var SpeechToSpeech = class {
|
|
153
176
|
constructor(phonic) {
|
|
154
177
|
this.phonic = phonic;
|
|
178
|
+
this.twilio = new Twilio(phonic);
|
|
155
179
|
}
|
|
180
|
+
twilio;
|
|
156
181
|
websocket(config) {
|
|
157
182
|
const wsBaseUrl = this.phonic.baseUrl.replace(/^http/, "ws");
|
|
158
183
|
const queryString = new URLSearchParams({
|
|
@@ -230,9 +255,13 @@ var Phonic = class {
|
|
|
230
255
|
sts = new SpeechToSpeech(this);
|
|
231
256
|
async fetchRequest(path, options) {
|
|
232
257
|
try {
|
|
258
|
+
const { headers, ...restOptions } = options;
|
|
233
259
|
const response = await fetch(`${this.baseUrl}/v1${path}`, {
|
|
234
|
-
headers:
|
|
235
|
-
|
|
260
|
+
headers: {
|
|
261
|
+
...this.headers,
|
|
262
|
+
...headers
|
|
263
|
+
},
|
|
264
|
+
...restOptions
|
|
236
265
|
});
|
|
237
266
|
if (response.ok) {
|
|
238
267
|
const data = await response.json();
|
|
@@ -268,10 +297,11 @@ var Phonic = class {
|
|
|
268
297
|
async get(path) {
|
|
269
298
|
return this.fetchRequest(path, { method: "GET" });
|
|
270
299
|
}
|
|
271
|
-
async post(path, body) {
|
|
300
|
+
async post(path, body, headers) {
|
|
272
301
|
return this.fetchRequest(path, {
|
|
273
302
|
method: "POST",
|
|
274
|
-
body: JSON.stringify(body)
|
|
303
|
+
body: JSON.stringify(body),
|
|
304
|
+
headers
|
|
275
305
|
});
|
|
276
306
|
}
|
|
277
307
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phonic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Phonic Node.js SDK",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"url": "https://github.com/Phonic-Co/phonic-node/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"ws": "8.18.
|
|
36
|
+
"ws": "8.18.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@biomejs/biome": "1.9.4",
|
|
40
40
|
"@changesets/changelog-github": "0.5.1",
|
|
41
41
|
"@changesets/cli": "2.29.2",
|
|
42
|
-
"@types/bun": "1.2.
|
|
42
|
+
"@types/bun": "1.2.12",
|
|
43
43
|
"@types/ws": "8.18.1",
|
|
44
44
|
"tsup": "8.4.0",
|
|
45
45
|
"typescript": "5.8.3",
|
|
46
|
-
"zod": "3.24.
|
|
46
|
+
"zod": "3.24.4"
|
|
47
47
|
},
|
|
48
48
|
"files": ["dist/**"],
|
|
49
49
|
"author": {
|