phonic 0.16.3 → 0.17.0
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 +30 -5
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -1
- package/dist/index.mjs +17 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -10,8 +10,10 @@ Node.js library for the Phonic API.
|
|
|
10
10
|
- [Get conversation by id](#get-conversation-by-id)
|
|
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 via WebSocket](#sts-via-websocket)
|
|
14
15
|
- [Messages that Phonic sends back to you](#messages-that-phonic-sends-back-to-you)
|
|
16
|
+
|
|
15
17
|
|
|
16
18
|
## Installation
|
|
17
19
|
|
|
@@ -45,7 +47,7 @@ if (error === null) {
|
|
|
45
47
|
### Get voice by id
|
|
46
48
|
|
|
47
49
|
```ts
|
|
48
|
-
const { data, error } = await phonic.voices.get("
|
|
50
|
+
const { data, error } = await phonic.voices.get("greta");
|
|
49
51
|
|
|
50
52
|
if (error === null) {
|
|
51
53
|
console.log(data.voice);
|
|
@@ -91,7 +93,25 @@ if (error === null) {
|
|
|
91
93
|
}
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
###
|
|
96
|
+
### STS outbound call
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const { data, error } = await phonic.sts.outboundCall("+19189396241", {
|
|
100
|
+
welcome_message: "Hello, how can I help you?",
|
|
101
|
+
|
|
102
|
+
// Optional fields
|
|
103
|
+
project: "main",
|
|
104
|
+
system_prompt: "You are a helpful assistant.",
|
|
105
|
+
voice_id: "greta",
|
|
106
|
+
enable_silent_audio_fallback: true,
|
|
107
|
+
vad_prebuffer_duration_ms: 1800,
|
|
108
|
+
vad_min_speech_duration_ms: 40,
|
|
109
|
+
vad_min_silence_duration_ms: 550,
|
|
110
|
+
vad_threshold: 0.6,
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### STS via WebSocket
|
|
95
115
|
|
|
96
116
|
To start a conversation, open a WebSocket connection:
|
|
97
117
|
|
|
@@ -103,8 +123,13 @@ const phonicWebSocket = phonic.sts.websocket({
|
|
|
103
123
|
project: "main",
|
|
104
124
|
system_prompt: "You are a helpful assistant.",
|
|
105
125
|
welcome_message: "Hello, how can I help you?",
|
|
106
|
-
voice_id: "
|
|
107
|
-
output_format: "mulaw_8000"
|
|
126
|
+
voice_id: "greta",
|
|
127
|
+
output_format: "mulaw_8000",
|
|
128
|
+
enable_silent_audio_fallback: true,
|
|
129
|
+
vad_prebuffer_duration_ms: 1800,
|
|
130
|
+
vad_min_speech_duration_ms: 40,
|
|
131
|
+
vad_min_silence_duration_ms: 550,
|
|
132
|
+
vad_threshold: 0.6,
|
|
108
133
|
});
|
|
109
134
|
```
|
|
110
135
|
|
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,9 @@ type PhonicConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
type FetchOptions = {
|
|
9
9
|
method: "GET";
|
|
10
|
+
} | {
|
|
11
|
+
method: "POST";
|
|
12
|
+
body: string;
|
|
10
13
|
};
|
|
11
14
|
type ErrorResponse = {
|
|
12
15
|
message: string;
|
|
@@ -121,6 +124,12 @@ type PhonicSTSWebSocketResponseMessage = {
|
|
|
121
124
|
type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
|
|
122
125
|
type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
|
|
123
126
|
type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
|
|
127
|
+
type PhonicSTSOutboundCallConfig = Omit<PhonicSTSConfig, "input_format" | "output_format"> & {
|
|
128
|
+
welcome_message: string;
|
|
129
|
+
};
|
|
130
|
+
type OutboundCallSuccessResponse = {
|
|
131
|
+
success: true;
|
|
132
|
+
};
|
|
124
133
|
|
|
125
134
|
declare class PhonicSTSWebSocket {
|
|
126
135
|
private readonly ws;
|
|
@@ -150,6 +159,7 @@ declare class SpeechToSpeech {
|
|
|
150
159
|
private readonly phonic;
|
|
151
160
|
constructor(phonic: Phonic);
|
|
152
161
|
websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
|
|
162
|
+
outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
type Voice = {
|
|
@@ -189,6 +199,13 @@ declare class Phonic {
|
|
|
189
199
|
data: T;
|
|
190
200
|
error: null;
|
|
191
201
|
}>;
|
|
202
|
+
post<T>(path: string, body: Record<string, unknown>): Promise<{
|
|
203
|
+
data: null;
|
|
204
|
+
error: ErrorResponse;
|
|
205
|
+
} | {
|
|
206
|
+
data: T;
|
|
207
|
+
error: null;
|
|
208
|
+
}>;
|
|
192
209
|
}
|
|
193
210
|
|
|
194
211
|
export { Phonic, type PhonicSTSConfig, PhonicSTSWebSocket };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ type PhonicConfig = {
|
|
|
7
7
|
};
|
|
8
8
|
type FetchOptions = {
|
|
9
9
|
method: "GET";
|
|
10
|
+
} | {
|
|
11
|
+
method: "POST";
|
|
12
|
+
body: string;
|
|
10
13
|
};
|
|
11
14
|
type ErrorResponse = {
|
|
12
15
|
message: string;
|
|
@@ -121,6 +124,12 @@ type PhonicSTSWebSocketResponseMessage = {
|
|
|
121
124
|
type OnMessageCallback = (message: PhonicSTSWebSocketResponseMessage) => void;
|
|
122
125
|
type OnCloseCallback = (event: WebSocket.CloseEvent) => void;
|
|
123
126
|
type OnErrorCallback = (event: WebSocket.ErrorEvent) => void;
|
|
127
|
+
type PhonicSTSOutboundCallConfig = Omit<PhonicSTSConfig, "input_format" | "output_format"> & {
|
|
128
|
+
welcome_message: string;
|
|
129
|
+
};
|
|
130
|
+
type OutboundCallSuccessResponse = {
|
|
131
|
+
success: true;
|
|
132
|
+
};
|
|
124
133
|
|
|
125
134
|
declare class PhonicSTSWebSocket {
|
|
126
135
|
private readonly ws;
|
|
@@ -150,6 +159,7 @@ declare class SpeechToSpeech {
|
|
|
150
159
|
private readonly phonic;
|
|
151
160
|
constructor(phonic: Phonic);
|
|
152
161
|
websocket(config: PhonicSTSConfig): PhonicSTSWebSocket;
|
|
162
|
+
outboundCall(toPhoneNumber: string, config: PhonicSTSOutboundCallConfig): DataOrError<OutboundCallSuccessResponse>;
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
type Voice = {
|
|
@@ -189,6 +199,13 @@ declare class Phonic {
|
|
|
189
199
|
data: T;
|
|
190
200
|
error: null;
|
|
191
201
|
}>;
|
|
202
|
+
post<T>(path: string, body: Record<string, unknown>): Promise<{
|
|
203
|
+
data: null;
|
|
204
|
+
error: ErrorResponse;
|
|
205
|
+
} | {
|
|
206
|
+
data: T;
|
|
207
|
+
error: null;
|
|
208
|
+
}>;
|
|
192
209
|
}
|
|
193
210
|
|
|
194
211
|
export { Phonic, type PhonicSTSConfig, PhonicSTSWebSocket };
|
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.17.0";
|
|
39
39
|
|
|
40
40
|
// src/conversations/index.ts
|
|
41
41
|
var Conversations = class {
|
|
@@ -202,6 +202,16 @@ var SpeechToSpeech = class {
|
|
|
202
202
|
});
|
|
203
203
|
return new PhonicSTSWebSocket(ws, config);
|
|
204
204
|
}
|
|
205
|
+
async outboundCall(toPhoneNumber, config) {
|
|
206
|
+
const response = await this.phonic.post(
|
|
207
|
+
"/sts/outbound_call",
|
|
208
|
+
{
|
|
209
|
+
to_phone_number: toPhoneNumber,
|
|
210
|
+
config
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
return response;
|
|
214
|
+
}
|
|
205
215
|
};
|
|
206
216
|
|
|
207
217
|
// src/voices/index.ts
|
|
@@ -294,6 +304,12 @@ var Phonic = class {
|
|
|
294
304
|
async get(path) {
|
|
295
305
|
return this.fetchRequest(path, { method: "GET" });
|
|
296
306
|
}
|
|
307
|
+
async post(path, body) {
|
|
308
|
+
return this.fetchRequest(path, {
|
|
309
|
+
method: "POST",
|
|
310
|
+
body: JSON.stringify(body)
|
|
311
|
+
});
|
|
312
|
+
}
|
|
297
313
|
};
|
|
298
314
|
// Annotate the CommonJS export names for ESM import in node:
|
|
299
315
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.17.0";
|
|
3
3
|
|
|
4
4
|
// src/conversations/index.ts
|
|
5
5
|
var Conversations = class {
|
|
@@ -166,6 +166,16 @@ var SpeechToSpeech = class {
|
|
|
166
166
|
});
|
|
167
167
|
return new PhonicSTSWebSocket(ws, config);
|
|
168
168
|
}
|
|
169
|
+
async outboundCall(toPhoneNumber, config) {
|
|
170
|
+
const response = await this.phonic.post(
|
|
171
|
+
"/sts/outbound_call",
|
|
172
|
+
{
|
|
173
|
+
to_phone_number: toPhoneNumber,
|
|
174
|
+
config
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
return response;
|
|
178
|
+
}
|
|
169
179
|
};
|
|
170
180
|
|
|
171
181
|
// src/voices/index.ts
|
|
@@ -258,6 +268,12 @@ var Phonic = class {
|
|
|
258
268
|
async get(path) {
|
|
259
269
|
return this.fetchRequest(path, { method: "GET" });
|
|
260
270
|
}
|
|
271
|
+
async post(path, body) {
|
|
272
|
+
return this.fetchRequest(path, {
|
|
273
|
+
method: "POST",
|
|
274
|
+
body: JSON.stringify(body)
|
|
275
|
+
});
|
|
276
|
+
}
|
|
261
277
|
};
|
|
262
278
|
export {
|
|
263
279
|
Phonic
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phonic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Phonic Node.js SDK",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@biomejs/biome": "1.9.4",
|
|
40
40
|
"@changesets/changelog-github": "0.5.1",
|
|
41
|
-
"@changesets/cli": "2.
|
|
42
|
-
"@types/bun": "1.2.
|
|
41
|
+
"@changesets/cli": "2.29.2",
|
|
42
|
+
"@types/bun": "1.2.10",
|
|
43
|
+
"@types/ws": "8.18.1",
|
|
43
44
|
"tsup": "8.4.0",
|
|
44
45
|
"typescript": "5.8.3",
|
|
45
|
-
"zod": "3.24.
|
|
46
|
+
"zod": "3.24.3"
|
|
46
47
|
},
|
|
47
48
|
"files": ["dist/**"],
|
|
48
49
|
"author": {
|