@jambonz/sdk 0.1.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/dist/client/index.cjs +119 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +58 -0
- package/dist/client/index.d.ts +58 -0
- package/dist/client/index.js +115 -0
- package/dist/client/index.js.map +1 -0
- package/dist/common-Bsqv1Brz.d.cts +69 -0
- package/dist/common-Bsqv1Brz.d.ts +69 -0
- package/dist/index.cjs +1014 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +996 -0
- package/dist/index.js.map +1 -0
- package/dist/rest-BV_FsqnH.d.cts +97 -0
- package/dist/rest-CthGXHnw.d.ts +97 -0
- package/dist/types/index.cjs +4 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/verb-builder-But-DJle.d.cts +82 -0
- package/dist/verb-builder-CO_qoYxC.d.ts +82 -0
- package/dist/verbs-B_afNNUM.d.cts +770 -0
- package/dist/verbs-B_afNNUM.d.ts +770 -0
- package/dist/webhook/index.cjs +320 -0
- package/dist/webhook/index.cjs.map +1 -0
- package/dist/webhook/index.d.cts +26 -0
- package/dist/webhook/index.d.ts +26 -0
- package/dist/webhook/index.js +313 -0
- package/dist/webhook/index.js.map +1 -0
- package/dist/websocket/index.cjs +833 -0
- package/dist/websocket/index.cjs.map +1 -0
- package/dist/websocket/index.d.cts +179 -0
- package/dist/websocket/index.d.ts +179 -0
- package/dist/websocket/index.js +822 -0
- package/dist/websocket/index.js.map +1 -0
- package/package.json +96 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1014 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var Ajv = require('ajv');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var url = require('url');
|
|
7
|
+
var crypto = require('crypto');
|
|
8
|
+
var http = require('http');
|
|
9
|
+
var ws = require('ws');
|
|
10
|
+
var events = require('events');
|
|
11
|
+
|
|
12
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
16
|
+
var http__default = /*#__PURE__*/_interopDefault(http);
|
|
17
|
+
|
|
18
|
+
// src/validator.ts
|
|
19
|
+
var COMPONENT_SCHEMAS = [
|
|
20
|
+
"auth",
|
|
21
|
+
"actionHook",
|
|
22
|
+
"synthesizer",
|
|
23
|
+
"recognizer",
|
|
24
|
+
"target",
|
|
25
|
+
"vad",
|
|
26
|
+
"bidirectionalAudio",
|
|
27
|
+
"fillerNoise",
|
|
28
|
+
"actionHookDelayAction"
|
|
29
|
+
];
|
|
30
|
+
var VERB_SCHEMAS = [
|
|
31
|
+
"answer",
|
|
32
|
+
"alert",
|
|
33
|
+
"config",
|
|
34
|
+
"say",
|
|
35
|
+
"play",
|
|
36
|
+
"gather",
|
|
37
|
+
"dial",
|
|
38
|
+
"listen",
|
|
39
|
+
"stream",
|
|
40
|
+
"llm",
|
|
41
|
+
"pipeline",
|
|
42
|
+
"conference",
|
|
43
|
+
"transcribe",
|
|
44
|
+
"enqueue",
|
|
45
|
+
"dequeue",
|
|
46
|
+
"dtmf",
|
|
47
|
+
"dub",
|
|
48
|
+
"hangup",
|
|
49
|
+
"leave",
|
|
50
|
+
"message",
|
|
51
|
+
"pause",
|
|
52
|
+
"redirect",
|
|
53
|
+
"tag",
|
|
54
|
+
"sip-decline",
|
|
55
|
+
"sip-request",
|
|
56
|
+
"sip-refer"
|
|
57
|
+
];
|
|
58
|
+
function loadSchema(schemaDir, relativePath) {
|
|
59
|
+
const fullPath = path.resolve(schemaDir, relativePath);
|
|
60
|
+
return JSON.parse(fs.readFileSync(fullPath, "utf-8"));
|
|
61
|
+
}
|
|
62
|
+
function findSchemaDir() {
|
|
63
|
+
const currentDir = typeof __dirname !== "undefined" ? __dirname : path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
64
|
+
const candidates = [
|
|
65
|
+
path.resolve(currentDir, "../../schema"),
|
|
66
|
+
// from src/
|
|
67
|
+
path.resolve(currentDir, "../../../schema")
|
|
68
|
+
// from dist/
|
|
69
|
+
];
|
|
70
|
+
for (const candidate of candidates) {
|
|
71
|
+
try {
|
|
72
|
+
fs.readFileSync(path.resolve(candidate, "jambonz-app.schema.json"), "utf-8");
|
|
73
|
+
return candidate;
|
|
74
|
+
} catch {
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
throw new Error(
|
|
78
|
+
"Could not find jambonz schema directory. Ensure the schema/ directory is present alongside the typescript/ directory."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
var JambonzValidator = class {
|
|
82
|
+
validateApp;
|
|
83
|
+
ajv;
|
|
84
|
+
constructor(schemaDir) {
|
|
85
|
+
const dir = schemaDir ?? findSchemaDir();
|
|
86
|
+
this.ajv = new Ajv__default.default({
|
|
87
|
+
allErrors: true,
|
|
88
|
+
strict: false,
|
|
89
|
+
validateSchema: false,
|
|
90
|
+
logger: false
|
|
91
|
+
});
|
|
92
|
+
for (const name of COMPONENT_SCHEMAS) {
|
|
93
|
+
const schema = loadSchema(dir, `components/${name}.schema.json`);
|
|
94
|
+
this.ajv.addSchema(schema);
|
|
95
|
+
}
|
|
96
|
+
for (const name of VERB_SCHEMAS) {
|
|
97
|
+
const schema = loadSchema(dir, `verbs/${name}.schema.json`);
|
|
98
|
+
this.ajv.addSchema(schema);
|
|
99
|
+
}
|
|
100
|
+
const appSchema = loadSchema(dir, "jambonz-app.schema.json");
|
|
101
|
+
this.validateApp = this.ajv.compile(appSchema);
|
|
102
|
+
}
|
|
103
|
+
/** Validate a complete verb array (a jambonz application). */
|
|
104
|
+
validate(app) {
|
|
105
|
+
const valid = this.validateApp(app);
|
|
106
|
+
if (valid) {
|
|
107
|
+
return { valid: true, errors: [] };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
valid: false,
|
|
111
|
+
errors: formatErrors(this.validateApp.errors)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Validate a single verb object. */
|
|
115
|
+
validateVerb(verb) {
|
|
116
|
+
return this.validate([verb]);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function formatErrors(errors) {
|
|
120
|
+
if (!errors) return [];
|
|
121
|
+
return errors.map((err) => ({
|
|
122
|
+
path: err.instancePath || "/",
|
|
123
|
+
message: err.message || "Unknown validation error"
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
var _defaultValidator = null;
|
|
127
|
+
function getValidator(schemaDir) {
|
|
128
|
+
if (!_defaultValidator) {
|
|
129
|
+
_defaultValidator = new JambonzValidator(schemaDir);
|
|
130
|
+
}
|
|
131
|
+
return _defaultValidator;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/verb-builder.ts
|
|
135
|
+
var VerbBuilder = class {
|
|
136
|
+
verbs = [];
|
|
137
|
+
validator;
|
|
138
|
+
constructor(opts) {
|
|
139
|
+
if (opts?.validate === false) {
|
|
140
|
+
this.validator = null;
|
|
141
|
+
} else {
|
|
142
|
+
this.validator = new JambonzValidator(opts?.schemaDir);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// --- Audio & Speech ---
|
|
146
|
+
say(opts) {
|
|
147
|
+
return this.addVerb({ verb: "say", ...opts });
|
|
148
|
+
}
|
|
149
|
+
play(opts) {
|
|
150
|
+
return this.addVerb({ verb: "play", ...opts });
|
|
151
|
+
}
|
|
152
|
+
gather(opts) {
|
|
153
|
+
return this.addVerb({ verb: "gather", ...opts });
|
|
154
|
+
}
|
|
155
|
+
// --- AI & Real-time ---
|
|
156
|
+
llm(opts) {
|
|
157
|
+
return this.addVerb({ verb: "llm", ...opts });
|
|
158
|
+
}
|
|
159
|
+
pipeline(opts) {
|
|
160
|
+
return this.addVerb({ verb: "pipeline", ...opts });
|
|
161
|
+
}
|
|
162
|
+
listen(opts) {
|
|
163
|
+
return this.addVerb({ verb: "listen", ...opts });
|
|
164
|
+
}
|
|
165
|
+
stream(opts) {
|
|
166
|
+
return this.addVerb({ verb: "stream", ...opts });
|
|
167
|
+
}
|
|
168
|
+
transcribe(opts) {
|
|
169
|
+
return this.addVerb({ verb: "transcribe", ...opts });
|
|
170
|
+
}
|
|
171
|
+
// --- Call Control ---
|
|
172
|
+
dial(opts) {
|
|
173
|
+
return this.addVerb({ verb: "dial", ...opts });
|
|
174
|
+
}
|
|
175
|
+
conference(opts) {
|
|
176
|
+
return this.addVerb({ verb: "conference", ...opts });
|
|
177
|
+
}
|
|
178
|
+
enqueue(opts) {
|
|
179
|
+
return this.addVerb({ verb: "enqueue", ...opts });
|
|
180
|
+
}
|
|
181
|
+
dequeue(opts) {
|
|
182
|
+
return this.addVerb({ verb: "dequeue", ...opts });
|
|
183
|
+
}
|
|
184
|
+
hangup(opts) {
|
|
185
|
+
return this.addVerb({ verb: "hangup", ...opts });
|
|
186
|
+
}
|
|
187
|
+
redirect(opts) {
|
|
188
|
+
return this.addVerb({ verb: "redirect", ...opts });
|
|
189
|
+
}
|
|
190
|
+
pause(opts) {
|
|
191
|
+
return this.addVerb({ verb: "pause", ...opts });
|
|
192
|
+
}
|
|
193
|
+
leave(opts) {
|
|
194
|
+
return this.addVerb({ verb: "leave", ...opts });
|
|
195
|
+
}
|
|
196
|
+
// --- SIP ---
|
|
197
|
+
sipDecline(opts) {
|
|
198
|
+
return this.addVerb({ verb: "sip:decline", ...opts });
|
|
199
|
+
}
|
|
200
|
+
sipRequest(opts) {
|
|
201
|
+
return this.addVerb({ verb: "sip:request", ...opts });
|
|
202
|
+
}
|
|
203
|
+
sipRefer(opts) {
|
|
204
|
+
return this.addVerb({ verb: "sip:refer", ...opts });
|
|
205
|
+
}
|
|
206
|
+
// --- Utility ---
|
|
207
|
+
config(opts) {
|
|
208
|
+
return this.addVerb({ verb: "config", ...opts });
|
|
209
|
+
}
|
|
210
|
+
answer(opts) {
|
|
211
|
+
return this.addVerb({ verb: "answer", ...opts });
|
|
212
|
+
}
|
|
213
|
+
alert(opts) {
|
|
214
|
+
return this.addVerb({ verb: "alert", ...opts });
|
|
215
|
+
}
|
|
216
|
+
tag(opts) {
|
|
217
|
+
return this.addVerb({ verb: "tag", ...opts });
|
|
218
|
+
}
|
|
219
|
+
dtmf(opts) {
|
|
220
|
+
return this.addVerb({ verb: "dtmf", ...opts });
|
|
221
|
+
}
|
|
222
|
+
dub(opts) {
|
|
223
|
+
return this.addVerb({ verb: "dub", ...opts });
|
|
224
|
+
}
|
|
225
|
+
message(opts) {
|
|
226
|
+
return this.addVerb({ verb: "message", ...opts });
|
|
227
|
+
}
|
|
228
|
+
// --- Raw JSON input (primary AI agent path) ---
|
|
229
|
+
/**
|
|
230
|
+
* Add one or more verbs from raw JSON.
|
|
231
|
+
* Validates against the JSON schemas at runtime if validation is enabled.
|
|
232
|
+
*/
|
|
233
|
+
addVerbs(verbs) {
|
|
234
|
+
if (this.validator) {
|
|
235
|
+
const result = this.validator.validate(verbs);
|
|
236
|
+
if (!result.valid) {
|
|
237
|
+
const messages = result.errors.map((e) => `${e.path}: ${e.message}`).join("; ");
|
|
238
|
+
throw new Error(`Verb validation failed: ${messages}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this.verbs.push(...verbs);
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
// --- Internal ---
|
|
245
|
+
addVerb(verb) {
|
|
246
|
+
if (this.validator) {
|
|
247
|
+
const result = this.validator.validateVerb(verb);
|
|
248
|
+
if (!result.valid) {
|
|
249
|
+
const messages = result.errors.map((e) => `${e.path}: ${e.message}`).join("; ");
|
|
250
|
+
throw new Error(`Verb '${verb.verb}' validation failed: ${messages}`);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
this.verbs.push(verb);
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
/** Get the current verb count. */
|
|
257
|
+
get length() {
|
|
258
|
+
return this.verbs.length;
|
|
259
|
+
}
|
|
260
|
+
/** Clear all queued verbs. */
|
|
261
|
+
clear() {
|
|
262
|
+
this.verbs = [];
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
/** Returns a copy of the current verb array. */
|
|
266
|
+
toJSON() {
|
|
267
|
+
return [...this.verbs];
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
var WebhookResponse = class extends VerbBuilder {
|
|
271
|
+
constructor(opts) {
|
|
272
|
+
super(opts);
|
|
273
|
+
}
|
|
274
|
+
/** Returns the verb array for JSON serialization. */
|
|
275
|
+
toJSON() {
|
|
276
|
+
return [...this.verbs];
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Express-compatible middleware for verifying jambonz webhook signatures.
|
|
280
|
+
* Uses HMAC-SHA256 with timing-safe comparison.
|
|
281
|
+
*/
|
|
282
|
+
static verifySignature(secret, opts) {
|
|
283
|
+
const tolerance = opts?.tolerance ?? 300;
|
|
284
|
+
return (req, _res, next) => {
|
|
285
|
+
try {
|
|
286
|
+
const signature = req.headers["jambonz-signature"];
|
|
287
|
+
if (!signature) {
|
|
288
|
+
throw new Error("Missing Jambonz-Signature header");
|
|
289
|
+
}
|
|
290
|
+
const parts = signature.split(",");
|
|
291
|
+
let timestamp = "";
|
|
292
|
+
const signatures = [];
|
|
293
|
+
for (const part of parts) {
|
|
294
|
+
const [key, value] = part.split("=");
|
|
295
|
+
if (key === "t") timestamp = value;
|
|
296
|
+
else if (key === "v1") signatures.push(value);
|
|
297
|
+
}
|
|
298
|
+
if (!timestamp || signatures.length === 0) {
|
|
299
|
+
throw new Error("Invalid Jambonz-Signature format");
|
|
300
|
+
}
|
|
301
|
+
const ts = parseInt(timestamp, 10);
|
|
302
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
303
|
+
if (Math.abs(now - ts) > tolerance) {
|
|
304
|
+
throw new Error("Webhook signature timestamp outside tolerance");
|
|
305
|
+
}
|
|
306
|
+
const payload = typeof req.body === "string" ? req.body : JSON.stringify(req.body);
|
|
307
|
+
const signedPayload = `${timestamp}.${payload}`;
|
|
308
|
+
const expected = crypto.createHmac("sha256", secret).update(signedPayload).digest("hex");
|
|
309
|
+
const matched = signatures.some((sig) => {
|
|
310
|
+
try {
|
|
311
|
+
return crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
|
|
312
|
+
} catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
if (!matched) {
|
|
317
|
+
throw new Error("Webhook signature verification failed");
|
|
318
|
+
}
|
|
319
|
+
next();
|
|
320
|
+
} catch (err) {
|
|
321
|
+
next(err instanceof Error ? err : new Error(String(err)));
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
var Session = class extends events.EventEmitter {
|
|
327
|
+
callSid;
|
|
328
|
+
b3;
|
|
329
|
+
data;
|
|
330
|
+
/** Application-specific storage that persists for the session. */
|
|
331
|
+
locals = {};
|
|
332
|
+
ws;
|
|
333
|
+
logger;
|
|
334
|
+
msgid;
|
|
335
|
+
acked = false;
|
|
336
|
+
builder;
|
|
337
|
+
commandQueue = [];
|
|
338
|
+
ttsCounter = 0;
|
|
339
|
+
ttsPaused = false;
|
|
340
|
+
constructor(opts) {
|
|
341
|
+
super();
|
|
342
|
+
this.ws = opts.ws;
|
|
343
|
+
this.logger = opts.logger;
|
|
344
|
+
this.msgid = opts.msg.msgid;
|
|
345
|
+
this.callSid = opts.msg.data?.call_sid ?? opts.msg.call_sid ?? "";
|
|
346
|
+
this.b3 = opts.msg.b3;
|
|
347
|
+
this.data = opts.msg.data ?? {};
|
|
348
|
+
this.builder = new VerbBuilder({
|
|
349
|
+
validate: opts.validate,
|
|
350
|
+
schemaDir: opts.schemaDir
|
|
351
|
+
});
|
|
352
|
+
this.ws.on("message", (data) => {
|
|
353
|
+
this.onMessage(data);
|
|
354
|
+
});
|
|
355
|
+
this.ws.on("close", (code, reason) => {
|
|
356
|
+
this.emit("close", code, reason);
|
|
357
|
+
});
|
|
358
|
+
this.ws.on("error", (err) => {
|
|
359
|
+
this.emit("error", err);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
// ---------------------------------------------------------------------------
|
|
363
|
+
// Verb builder delegation — same API as VerbBuilder
|
|
364
|
+
// ---------------------------------------------------------------------------
|
|
365
|
+
say(opts) {
|
|
366
|
+
this.builder.say(opts);
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
play(opts) {
|
|
370
|
+
this.builder.play(opts);
|
|
371
|
+
return this;
|
|
372
|
+
}
|
|
373
|
+
gather(opts) {
|
|
374
|
+
this.builder.gather(opts);
|
|
375
|
+
return this;
|
|
376
|
+
}
|
|
377
|
+
llm(opts) {
|
|
378
|
+
this.builder.llm(opts);
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
pipeline(opts) {
|
|
382
|
+
this.builder.pipeline(opts);
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
listen(opts) {
|
|
386
|
+
this.builder.listen(opts);
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
stream(opts) {
|
|
390
|
+
this.builder.stream(opts);
|
|
391
|
+
return this;
|
|
392
|
+
}
|
|
393
|
+
transcribe(opts) {
|
|
394
|
+
this.builder.transcribe(opts);
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
dial(opts) {
|
|
398
|
+
this.builder.dial(opts);
|
|
399
|
+
return this;
|
|
400
|
+
}
|
|
401
|
+
conference(opts) {
|
|
402
|
+
this.builder.conference(opts);
|
|
403
|
+
return this;
|
|
404
|
+
}
|
|
405
|
+
enqueue(opts) {
|
|
406
|
+
this.builder.enqueue(opts);
|
|
407
|
+
return this;
|
|
408
|
+
}
|
|
409
|
+
dequeue(opts) {
|
|
410
|
+
this.builder.dequeue(opts);
|
|
411
|
+
return this;
|
|
412
|
+
}
|
|
413
|
+
hangup(opts) {
|
|
414
|
+
this.builder.hangup(opts);
|
|
415
|
+
return this;
|
|
416
|
+
}
|
|
417
|
+
redirect(opts) {
|
|
418
|
+
this.builder.redirect(opts);
|
|
419
|
+
return this;
|
|
420
|
+
}
|
|
421
|
+
pause(opts) {
|
|
422
|
+
this.builder.pause(opts);
|
|
423
|
+
return this;
|
|
424
|
+
}
|
|
425
|
+
leave(opts) {
|
|
426
|
+
this.builder.leave(opts);
|
|
427
|
+
return this;
|
|
428
|
+
}
|
|
429
|
+
sipDecline(opts) {
|
|
430
|
+
this.builder.sipDecline(opts);
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
sipRequest(opts) {
|
|
434
|
+
this.builder.sipRequest(opts);
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
437
|
+
sipRefer(opts) {
|
|
438
|
+
this.builder.sipRefer(opts);
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
config(opts) {
|
|
442
|
+
this.builder.config(opts);
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
answer(opts) {
|
|
446
|
+
this.builder.answer(opts);
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
alert(opts) {
|
|
450
|
+
this.builder.alert(opts);
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
tag(opts) {
|
|
454
|
+
this.builder.tag(opts);
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
dtmf(opts) {
|
|
458
|
+
this.builder.dtmf(opts);
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
dub(opts) {
|
|
462
|
+
this.builder.dub(opts);
|
|
463
|
+
return this;
|
|
464
|
+
}
|
|
465
|
+
message(opts) {
|
|
466
|
+
this.builder.message(opts);
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
/** Add raw JSON verbs (primary AI agent path). */
|
|
470
|
+
addVerbs(verbs) {
|
|
471
|
+
this.builder.addVerbs(verbs);
|
|
472
|
+
return this;
|
|
473
|
+
}
|
|
474
|
+
// ---------------------------------------------------------------------------
|
|
475
|
+
// Send / Reply
|
|
476
|
+
// ---------------------------------------------------------------------------
|
|
477
|
+
/** Send queued verbs to jambonz. */
|
|
478
|
+
send(opts) {
|
|
479
|
+
const execImmediate = opts?.execImmediate ?? true;
|
|
480
|
+
const data = this.builder.toJSON();
|
|
481
|
+
this.builder.clear();
|
|
482
|
+
if (!this.acked) {
|
|
483
|
+
this.acked = true;
|
|
484
|
+
const response = {
|
|
485
|
+
type: "ack",
|
|
486
|
+
msgid: this.msgid,
|
|
487
|
+
data
|
|
488
|
+
};
|
|
489
|
+
this.wsSend(response);
|
|
490
|
+
} else {
|
|
491
|
+
const response = {
|
|
492
|
+
type: "command",
|
|
493
|
+
command: "redirect",
|
|
494
|
+
queueCommand: !execImmediate,
|
|
495
|
+
data
|
|
496
|
+
};
|
|
497
|
+
this.wsSend(response);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/** Reply to an actionHook/eventHook with queued verbs. */
|
|
501
|
+
reply(opts) {
|
|
502
|
+
const execImmediate = opts?.execImmediate ?? true;
|
|
503
|
+
const data = this.builder.toJSON();
|
|
504
|
+
this.builder.clear();
|
|
505
|
+
const response = {
|
|
506
|
+
type: "ack",
|
|
507
|
+
msgid: this.msgid,
|
|
508
|
+
data
|
|
509
|
+
};
|
|
510
|
+
if (!execImmediate) {
|
|
511
|
+
response.type = "command";
|
|
512
|
+
response.command = "redirect";
|
|
513
|
+
response.queueCommand = true;
|
|
514
|
+
}
|
|
515
|
+
this.wsSend(response);
|
|
516
|
+
}
|
|
517
|
+
// ---------------------------------------------------------------------------
|
|
518
|
+
// Inject commands (immediate execution, bypass verb queue)
|
|
519
|
+
// ---------------------------------------------------------------------------
|
|
520
|
+
/** Send an inject command for immediate execution. */
|
|
521
|
+
injectCommand(command, data, callSid) {
|
|
522
|
+
this.wsSend({
|
|
523
|
+
type: "command",
|
|
524
|
+
command: "inject",
|
|
525
|
+
data: {
|
|
526
|
+
command,
|
|
527
|
+
...typeof data === "object" && data !== null ? data : {},
|
|
528
|
+
...callSid ? { call_sid: callSid } : {}
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
/** Redirect call execution to a new webhook. */
|
|
533
|
+
injectRedirect(hook, callSid) {
|
|
534
|
+
this.injectCommand("redirect", { call_hook: hook }, callSid);
|
|
535
|
+
}
|
|
536
|
+
/** Inject a whisper verb (say/play) to one party on the call. */
|
|
537
|
+
injectWhisper(verb, callSid) {
|
|
538
|
+
this.injectCommand("whisper", Array.isArray(verb) ? verb : [verb], callSid);
|
|
539
|
+
}
|
|
540
|
+
/** Mute or unmute the call. */
|
|
541
|
+
injectMute(status, callSid) {
|
|
542
|
+
this.injectCommand("mute:status", { mute_status: status }, callSid);
|
|
543
|
+
}
|
|
544
|
+
/** Pause or resume audio streaming (listen/stream). */
|
|
545
|
+
injectListenStatus(status, callSid) {
|
|
546
|
+
this.injectCommand("listen:status", { listen_status: status }, callSid);
|
|
547
|
+
}
|
|
548
|
+
/** Control call recording. */
|
|
549
|
+
injectRecord(action, opts, callSid) {
|
|
550
|
+
this.injectCommand("record", { action, ...opts }, callSid);
|
|
551
|
+
}
|
|
552
|
+
/** Send DTMF digits into the call. */
|
|
553
|
+
injectDtmf(digit, duration, callSid) {
|
|
554
|
+
this.injectCommand("dtmf", { digit, ...duration !== void 0 ? { duration } : {} }, callSid);
|
|
555
|
+
}
|
|
556
|
+
/** Attach metadata to the call. */
|
|
557
|
+
injectTag(data, callSid) {
|
|
558
|
+
this.injectCommand("tag", data, callSid);
|
|
559
|
+
}
|
|
560
|
+
/** Send a generic command. */
|
|
561
|
+
sendCommand(command, data) {
|
|
562
|
+
this.wsSend({
|
|
563
|
+
type: "command",
|
|
564
|
+
command,
|
|
565
|
+
data
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
/** Send tool output to an active LLM conversation. */
|
|
569
|
+
sendToolOutput(toolCallId, data) {
|
|
570
|
+
this.wsSend({
|
|
571
|
+
type: "command",
|
|
572
|
+
command: "llm:tool-result",
|
|
573
|
+
data: { tool_call_id: toolCallId, ...typeof data === "object" && data !== null ? data : { result: data } }
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
/** Update an active LLM conversation. */
|
|
577
|
+
updateLlm(data) {
|
|
578
|
+
this.wsSend({
|
|
579
|
+
type: "command",
|
|
580
|
+
command: "llm:update",
|
|
581
|
+
data
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
// ---------------------------------------------------------------------------
|
|
585
|
+
// TTS Token Streaming
|
|
586
|
+
// ---------------------------------------------------------------------------
|
|
587
|
+
/** Whether TTS streaming is paused due to backpressure. */
|
|
588
|
+
get isTtsPaused() {
|
|
589
|
+
return this.ttsPaused;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Send a streaming TTS token.
|
|
593
|
+
* Returns a promise that resolves when jambonz acknowledges receipt.
|
|
594
|
+
* Backpressure is applied automatically: if jambonz signals 'full',
|
|
595
|
+
* subsequent tokens queue until a 'stream_resumed' event arrives.
|
|
596
|
+
*/
|
|
597
|
+
sendTtsTokens(text) {
|
|
598
|
+
return new Promise((resolve2, reject) => {
|
|
599
|
+
const id = ++this.ttsCounter;
|
|
600
|
+
this.commandQueue.push({ type: "tokens", id, tokens: text, resolve: resolve2, reject });
|
|
601
|
+
if (this.commandQueue.length === 1 && !this.ttsPaused) {
|
|
602
|
+
this.processQueue();
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
/** Queue a TTS flush command. Sent immediately if the queue is empty. */
|
|
607
|
+
flushTtsTokens() {
|
|
608
|
+
if (this.commandQueue.length === 0) {
|
|
609
|
+
this.sendCommand("tts:flush");
|
|
610
|
+
} else {
|
|
611
|
+
this.commandQueue.push({
|
|
612
|
+
type: "flush",
|
|
613
|
+
id: ++this.ttsCounter,
|
|
614
|
+
resolve: () => {
|
|
615
|
+
},
|
|
616
|
+
reject: () => {
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
/** Clear all pending TTS tokens and send tts:clear. */
|
|
622
|
+
clearTtsTokens() {
|
|
623
|
+
for (const entry of this.commandQueue) {
|
|
624
|
+
if (entry.type === "tokens") {
|
|
625
|
+
entry.resolve();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
this.commandQueue = [];
|
|
629
|
+
this.ttsPaused = false;
|
|
630
|
+
this.sendCommand("tts:clear");
|
|
631
|
+
}
|
|
632
|
+
processQueue() {
|
|
633
|
+
while (this.commandQueue.length > 0 && this.commandQueue[0].type === "flush") {
|
|
634
|
+
const entry = this.commandQueue.shift();
|
|
635
|
+
this.sendCommand("tts:flush");
|
|
636
|
+
entry.resolve();
|
|
637
|
+
}
|
|
638
|
+
if (this.commandQueue.length > 0 && !this.ttsPaused) {
|
|
639
|
+
const entry = this.commandQueue[0];
|
|
640
|
+
this.wsSend({
|
|
641
|
+
type: "command",
|
|
642
|
+
command: "tts:tokens",
|
|
643
|
+
data: { id: entry.id, tokens: entry.tokens }
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
handleTtsTokensResult(data) {
|
|
648
|
+
if (this.commandQueue.length === 0) return;
|
|
649
|
+
const entry = this.commandQueue[0];
|
|
650
|
+
if (entry.type !== "tokens") return;
|
|
651
|
+
const { status, reason } = data;
|
|
652
|
+
if (status === "ok") {
|
|
653
|
+
this.commandQueue.shift();
|
|
654
|
+
entry.resolve();
|
|
655
|
+
} else if (reason === "full") {
|
|
656
|
+
this.ttsPaused = true;
|
|
657
|
+
entry.resolve();
|
|
658
|
+
} else {
|
|
659
|
+
this.commandQueue.shift();
|
|
660
|
+
entry.reject(new Error(`tts-token error: ${reason}`));
|
|
661
|
+
}
|
|
662
|
+
if (this.commandQueue.length > 0 && !this.ttsPaused) {
|
|
663
|
+
this.processQueue();
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
handleUserInterruption() {
|
|
667
|
+
for (const entry of this.commandQueue) {
|
|
668
|
+
if (entry.type === "tokens") {
|
|
669
|
+
entry.resolve();
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
this.commandQueue = [];
|
|
673
|
+
this.ttsPaused = false;
|
|
674
|
+
this.emit("tts:user_interrupt");
|
|
675
|
+
}
|
|
676
|
+
resumeTtsStreaming() {
|
|
677
|
+
this.ttsPaused = false;
|
|
678
|
+
this.processQueue();
|
|
679
|
+
}
|
|
680
|
+
// ---------------------------------------------------------------------------
|
|
681
|
+
// Inbound message handling
|
|
682
|
+
// ---------------------------------------------------------------------------
|
|
683
|
+
onMessage(raw) {
|
|
684
|
+
try {
|
|
685
|
+
const str = typeof raw === "string" ? raw : Buffer.from(raw).toString("utf-8");
|
|
686
|
+
const msg = JSON.parse(str);
|
|
687
|
+
const { type, msgid, data, hook } = msg;
|
|
688
|
+
switch (type) {
|
|
689
|
+
case "verb:hook":
|
|
690
|
+
case "session:redirect":
|
|
691
|
+
case "dial:confirm":
|
|
692
|
+
this.msgid = msgid;
|
|
693
|
+
if (hook && this.listenerCount(hook) > 0) {
|
|
694
|
+
this.emit(hook, data);
|
|
695
|
+
} else if (type === "verb:hook" && this.listenerCount("verb:hook") > 0) {
|
|
696
|
+
this.emit("verb:hook", hook, data);
|
|
697
|
+
} else {
|
|
698
|
+
this.reply();
|
|
699
|
+
}
|
|
700
|
+
break;
|
|
701
|
+
case "llm:event":
|
|
702
|
+
case "llm:tool-call":
|
|
703
|
+
if (hook) {
|
|
704
|
+
this.emit(hook, data);
|
|
705
|
+
}
|
|
706
|
+
this.emit(type, data);
|
|
707
|
+
break;
|
|
708
|
+
case "tts:streaming-event":
|
|
709
|
+
if (data?.event_type === "stream_resumed") {
|
|
710
|
+
this.resumeTtsStreaming();
|
|
711
|
+
} else if (data?.event_type === "user_interruption") {
|
|
712
|
+
this.handleUserInterruption();
|
|
713
|
+
}
|
|
714
|
+
this.emit("tts:streaming-event", data);
|
|
715
|
+
break;
|
|
716
|
+
case "tts:tokens-result":
|
|
717
|
+
this.handleTtsTokensResult(data ?? {});
|
|
718
|
+
break;
|
|
719
|
+
case "call:status":
|
|
720
|
+
case "verb:status":
|
|
721
|
+
case "jambonz:error":
|
|
722
|
+
this.emit(type, data);
|
|
723
|
+
break;
|
|
724
|
+
default:
|
|
725
|
+
this.logger.debug({ type }, "Session: unhandled message type");
|
|
726
|
+
}
|
|
727
|
+
} catch (err) {
|
|
728
|
+
this.logger.info({ err }, "Session: error handling message");
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
// ---------------------------------------------------------------------------
|
|
732
|
+
// Utilities
|
|
733
|
+
// ---------------------------------------------------------------------------
|
|
734
|
+
wsSend(msg) {
|
|
735
|
+
if (this.ws.readyState === 1) {
|
|
736
|
+
this.ws.send(JSON.stringify(msg));
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
/** Close the WebSocket connection. */
|
|
740
|
+
close() {
|
|
741
|
+
this.ws.close();
|
|
742
|
+
}
|
|
743
|
+
toJSON() {
|
|
744
|
+
return this.data;
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
// src/websocket/client.ts
|
|
749
|
+
var WsClient = class extends events.EventEmitter {
|
|
750
|
+
logger;
|
|
751
|
+
path;
|
|
752
|
+
constructor(logger, path) {
|
|
753
|
+
super();
|
|
754
|
+
this.logger = logger;
|
|
755
|
+
this.path = path;
|
|
756
|
+
}
|
|
757
|
+
/** Handle a new WebSocket connection. Called by the endpoint on upgrade. */
|
|
758
|
+
handle(ws, req) {
|
|
759
|
+
const onMessage = (data) => {
|
|
760
|
+
try {
|
|
761
|
+
const raw = typeof data === "string" ? data : Buffer.from(data).toString("utf-8");
|
|
762
|
+
const msg = JSON.parse(raw);
|
|
763
|
+
this.onSessionMessage(ws, req, msg, onMessage);
|
|
764
|
+
} catch (err) {
|
|
765
|
+
this.logger.info({ err }, "WsClient: error parsing message");
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
ws.on("message", onMessage);
|
|
769
|
+
}
|
|
770
|
+
onSessionMessage(ws, req, msg, onMessage) {
|
|
771
|
+
const { type } = msg;
|
|
772
|
+
if (type === "session:new" || type === "session:adulting" || type === "session:reconnect") {
|
|
773
|
+
ws.removeListener("message", onMessage);
|
|
774
|
+
const session = new Session({ ws, msg, logger: this.logger });
|
|
775
|
+
this.emit("session:new", session, this.path, req);
|
|
776
|
+
} else if (type === "session:redirect") {
|
|
777
|
+
ws.removeListener("message", onMessage);
|
|
778
|
+
const session = new Session({ ws, msg, logger: this.logger });
|
|
779
|
+
if (this.listenerCount("session:redirect") > 0) {
|
|
780
|
+
this.emit("session:redirect", session, this.path, req);
|
|
781
|
+
} else {
|
|
782
|
+
this.emit("session:new", session, this.path, req);
|
|
783
|
+
}
|
|
784
|
+
} else {
|
|
785
|
+
this.logger.debug({ type }, "WsClient: unexpected message type before session");
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
// src/websocket/router.ts
|
|
791
|
+
var WsRouter = class {
|
|
792
|
+
routes = [];
|
|
793
|
+
wildcard = null;
|
|
794
|
+
/** Register a client for a path pattern. Use '*' for wildcard. */
|
|
795
|
+
use(path, client) {
|
|
796
|
+
if (path === "*") {
|
|
797
|
+
this.wildcard = client;
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
801
|
+
const chunks = normalized.split("/").filter(Boolean);
|
|
802
|
+
this.routes.push({ path: normalized, chunks, client });
|
|
803
|
+
this.routes.sort((a, b) => b.chunks.length - a.chunks.length);
|
|
804
|
+
}
|
|
805
|
+
/** Find the matching client for a request. Returns undefined if no match. */
|
|
806
|
+
route(req) {
|
|
807
|
+
const pathname = req.url?.split("?")[0];
|
|
808
|
+
if (!pathname) return this.wildcard ?? void 0;
|
|
809
|
+
const urlChunks = pathname.split("/").filter(Boolean);
|
|
810
|
+
for (const route of this.routes) {
|
|
811
|
+
if (route.chunks.length > urlChunks.length) continue;
|
|
812
|
+
const matched = route.chunks.every((chunk, i) => chunk === urlChunks[i]);
|
|
813
|
+
if (matched) {
|
|
814
|
+
const remaining = "/" + urlChunks.slice(route.chunks.length).join("/");
|
|
815
|
+
req.originalUrl = req.url;
|
|
816
|
+
req.url = remaining;
|
|
817
|
+
return route.client;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return this.wildcard ?? void 0;
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
// src/websocket/endpoint.ts
|
|
825
|
+
var WS_PROTOCOL = "ws.jambonz.org";
|
|
826
|
+
var defaultLogger = {
|
|
827
|
+
info: () => {
|
|
828
|
+
},
|
|
829
|
+
error: () => {
|
|
830
|
+
},
|
|
831
|
+
debug: () => {
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
function createEndpoint(opts) {
|
|
835
|
+
const { server, port, logger = defaultLogger, middlewares = [] } = opts;
|
|
836
|
+
const router = new WsRouter();
|
|
837
|
+
const wss = new ws.WebSocketServer({
|
|
838
|
+
noServer: true,
|
|
839
|
+
handleProtocols: (protocols) => {
|
|
840
|
+
if (protocols.has(WS_PROTOCOL)) return WS_PROTOCOL;
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
server.on("upgrade", (req, socket, head) => {
|
|
845
|
+
const fakeRes = new http__default.default.ServerResponse(req);
|
|
846
|
+
runMiddlewares(middlewares, req, fakeRes, (err) => {
|
|
847
|
+
if (err) {
|
|
848
|
+
logger.info({ err }, "Endpoint: middleware rejected upgrade");
|
|
849
|
+
socket.destroy();
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
const client = router.route(req);
|
|
853
|
+
if (!client) {
|
|
854
|
+
logger.debug({ url: req.url }, "Endpoint: no route for WebSocket upgrade");
|
|
855
|
+
socket.destroy();
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
859
|
+
client.handle(ws, req);
|
|
860
|
+
});
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
if (port && !server.listening) {
|
|
864
|
+
server.listen(port);
|
|
865
|
+
}
|
|
866
|
+
return function makeService({ path }) {
|
|
867
|
+
const client = new WsClient(logger, path);
|
|
868
|
+
router.use(path, client);
|
|
869
|
+
return client;
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
function runMiddlewares(middlewares, req, res, done) {
|
|
873
|
+
let i = 0;
|
|
874
|
+
function next(err) {
|
|
875
|
+
if (err) return done(err);
|
|
876
|
+
if (i >= middlewares.length) return done();
|
|
877
|
+
const mw = middlewares[i++];
|
|
878
|
+
try {
|
|
879
|
+
const result = mw(req, res, next);
|
|
880
|
+
if (result instanceof Promise) {
|
|
881
|
+
result.catch(next);
|
|
882
|
+
}
|
|
883
|
+
} catch (e) {
|
|
884
|
+
next(e instanceof Error ? e : new Error(String(e)));
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
next();
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// src/client/api.ts
|
|
891
|
+
var HttpClient = class {
|
|
892
|
+
baseUrl;
|
|
893
|
+
headers;
|
|
894
|
+
constructor(opts) {
|
|
895
|
+
this.baseUrl = opts.baseUrl.replace(/\/+$/, "") + "/v1";
|
|
896
|
+
this.headers = {
|
|
897
|
+
"Authorization": `Bearer ${opts.apiKey}`,
|
|
898
|
+
"Content-Type": "application/json"
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
async get(path) {
|
|
902
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
903
|
+
method: "GET",
|
|
904
|
+
headers: this.headers
|
|
905
|
+
});
|
|
906
|
+
if (!res.ok) throw new Error(`GET ${path} failed: ${res.status} ${res.statusText}`);
|
|
907
|
+
return res.json();
|
|
908
|
+
}
|
|
909
|
+
async post(path, body) {
|
|
910
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
911
|
+
method: "POST",
|
|
912
|
+
headers: this.headers,
|
|
913
|
+
body: JSON.stringify(body)
|
|
914
|
+
});
|
|
915
|
+
if (!res.ok) throw new Error(`POST ${path} failed: ${res.status} ${res.statusText}`);
|
|
916
|
+
return res.json();
|
|
917
|
+
}
|
|
918
|
+
async put(path, body) {
|
|
919
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
920
|
+
method: "PUT",
|
|
921
|
+
headers: this.headers,
|
|
922
|
+
body: JSON.stringify(body)
|
|
923
|
+
});
|
|
924
|
+
if (!res.ok) throw new Error(`PUT ${path} failed: ${res.status} ${res.statusText}`);
|
|
925
|
+
}
|
|
926
|
+
async del(path) {
|
|
927
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
928
|
+
method: "DELETE",
|
|
929
|
+
headers: this.headers
|
|
930
|
+
});
|
|
931
|
+
if (!res.ok) throw new Error(`DELETE ${path} failed: ${res.status} ${res.statusText}`);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
var CallsResource = class {
|
|
935
|
+
constructor(http2, accountSid) {
|
|
936
|
+
this.http = http2;
|
|
937
|
+
this.accountSid = accountSid;
|
|
938
|
+
}
|
|
939
|
+
/** Create a new outbound call. */
|
|
940
|
+
async create(opts) {
|
|
941
|
+
const result = await this.http.post(
|
|
942
|
+
`/Accounts/${this.accountSid}/Calls`,
|
|
943
|
+
opts
|
|
944
|
+
);
|
|
945
|
+
return result.sid;
|
|
946
|
+
}
|
|
947
|
+
/** Get info about an active call. */
|
|
948
|
+
async get(callSid) {
|
|
949
|
+
return this.http.get(
|
|
950
|
+
`/Accounts/${this.accountSid}/Calls/${callSid}`
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
/** Update an active call (redirect, mute, hangup, etc). */
|
|
954
|
+
async update(callSid, opts) {
|
|
955
|
+
return this.http.put(
|
|
956
|
+
`/Accounts/${this.accountSid}/Calls/${callSid}`,
|
|
957
|
+
opts
|
|
958
|
+
);
|
|
959
|
+
}
|
|
960
|
+
/** Terminate a call. */
|
|
961
|
+
async delete(callSid) {
|
|
962
|
+
return this.http.del(
|
|
963
|
+
`/Accounts/${this.accountSid}/Calls/${callSid}`
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
/** Redirect call execution to a new webhook URL. */
|
|
967
|
+
async redirect(callSid, hook) {
|
|
968
|
+
return this.update(callSid, { call_hook: hook });
|
|
969
|
+
}
|
|
970
|
+
/** Inject a whisper verb (say/play) to one party on the call. */
|
|
971
|
+
async whisper(callSid, verb) {
|
|
972
|
+
return this.update(callSid, { whisper: verb });
|
|
973
|
+
}
|
|
974
|
+
/** Mute or unmute a call. */
|
|
975
|
+
async mute(callSid, status) {
|
|
976
|
+
return this.update(callSid, { mute_status: status });
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
var MessagesResource = class {
|
|
980
|
+
constructor(http2, accountSid) {
|
|
981
|
+
this.http = http2;
|
|
982
|
+
this.accountSid = accountSid;
|
|
983
|
+
}
|
|
984
|
+
/** Send an SMS/MMS message. */
|
|
985
|
+
async create(opts) {
|
|
986
|
+
return this.http.post(
|
|
987
|
+
`/Accounts/${this.accountSid}/Messages`,
|
|
988
|
+
opts
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
var JambonzClient = class {
|
|
993
|
+
calls;
|
|
994
|
+
messages;
|
|
995
|
+
constructor(opts) {
|
|
996
|
+
const http2 = new HttpClient(opts);
|
|
997
|
+
this.calls = new CallsResource(http2, opts.accountSid);
|
|
998
|
+
this.messages = new MessagesResource(http2, opts.accountSid);
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
exports.CallsResource = CallsResource;
|
|
1003
|
+
exports.JambonzClient = JambonzClient;
|
|
1004
|
+
exports.JambonzValidator = JambonzValidator;
|
|
1005
|
+
exports.MessagesResource = MessagesResource;
|
|
1006
|
+
exports.Session = Session;
|
|
1007
|
+
exports.VerbBuilder = VerbBuilder;
|
|
1008
|
+
exports.WebhookResponse = WebhookResponse;
|
|
1009
|
+
exports.WsClient = WsClient;
|
|
1010
|
+
exports.WsRouter = WsRouter;
|
|
1011
|
+
exports.createEndpoint = createEndpoint;
|
|
1012
|
+
exports.getValidator = getValidator;
|
|
1013
|
+
//# sourceMappingURL=index.cjs.map
|
|
1014
|
+
//# sourceMappingURL=index.cjs.map
|