@jambonz/sdk 0.2.0 → 0.3.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.
Files changed (74) hide show
  1. package/AGENTS.md +715 -0
  2. package/dist/client/index.cjs +3 -3
  3. package/dist/client/index.cjs.map +1 -1
  4. package/dist/client/index.d.cts +4 -4
  5. package/dist/client/index.d.ts +4 -4
  6. package/dist/client/index.js +3 -3
  7. package/dist/client/index.js.map +1 -1
  8. package/dist/index.cjs +14 -14
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +4 -4
  11. package/dist/index.d.ts +4 -4
  12. package/dist/index.js +14 -14
  13. package/dist/index.js.map +1 -1
  14. package/dist/{rest-B_GQITxM.d.cts → rest-BvOtq44O.d.cts} +3 -3
  15. package/dist/{rest-DgctQy2b.d.ts → rest-DAAEUWsa.d.ts} +3 -3
  16. package/dist/{session-DVGHbtan.d.cts → session-DKaSRkIo.d.cts} +19 -19
  17. package/dist/{session-DVGHbtan.d.ts → session-DKaSRkIo.d.ts} +19 -19
  18. package/dist/types/index.d.cts +3 -3
  19. package/dist/types/index.d.ts +3 -3
  20. package/dist/{verb-builder-B7RIVi0t.d.ts → verb-builder-CFPD9yWI.d.cts} +3 -3
  21. package/dist/{verb-builder-B6zPuGd1.d.cts → verb-builder-D5XRbTtu.d.ts} +3 -3
  22. package/dist/{verbs-B18Kazd9.d.cts → verbs-DKy6nGIH.d.cts} +6 -6
  23. package/dist/{verbs-B18Kazd9.d.ts → verbs-DKy6nGIH.d.ts} +6 -6
  24. package/dist/webhook/index.cjs +3 -3
  25. package/dist/webhook/index.cjs.map +1 -1
  26. package/dist/webhook/index.d.cts +2 -2
  27. package/dist/webhook/index.d.ts +2 -2
  28. package/dist/webhook/index.js +3 -3
  29. package/dist/webhook/index.js.map +1 -1
  30. package/dist/websocket/index.cjs +11 -11
  31. package/dist/websocket/index.cjs.map +1 -1
  32. package/dist/websocket/index.d.cts +7 -7
  33. package/dist/websocket/index.d.ts +7 -7
  34. package/dist/websocket/index.js +11 -11
  35. package/dist/websocket/index.js.map +1 -1
  36. package/examples/agent/ws-app.ts +138 -0
  37. package/examples/assemblyai-autogenerate-prompt/app.js +92 -0
  38. package/examples/assemblyai-autogenerate-prompt/package.json +14 -0
  39. package/examples/bedrock-agent.ts +267 -0
  40. package/examples/call-recording/README.md +24 -0
  41. package/examples/call-recording/app.ts +70 -0
  42. package/examples/call-recording/ws-app.ts +47 -0
  43. package/examples/deepgram-voice-agent/ws-app.ts +118 -0
  44. package/examples/dial/app.ts +22 -0
  45. package/examples/echo/app.ts +65 -0
  46. package/examples/echo/ws-app.ts +67 -0
  47. package/examples/elevenlabs-voice-agent/ws-app.ts +81 -0
  48. package/examples/hello-world/README.md +15 -0
  49. package/examples/hello-world/app.js +20 -0
  50. package/examples/hello-world/app.ts +19 -0
  51. package/examples/hello-world/ws-app.ts +18 -0
  52. package/examples/ivr-menu/README.md +15 -0
  53. package/examples/ivr-menu/app.js +85 -0
  54. package/examples/ivr-menu/app.ts +70 -0
  55. package/examples/listen-record/app.ts +22 -0
  56. package/examples/llm-streaming/ws-app.ts +96 -0
  57. package/examples/openai-realtime/ws-app.ts +131 -0
  58. package/examples/queue-with-hold/README.md +19 -0
  59. package/examples/queue-with-hold/app.ts +68 -0
  60. package/examples/queue-with-hold/ws-app.ts +41 -0
  61. package/examples/realtime-translator/src/app.ts +21 -0
  62. package/examples/realtime-translator/src/routes/translator.ts +108 -0
  63. package/examples/realtime-translator/src/utils/config.ts +21 -0
  64. package/examples/realtime-translator/src/utils/translate.ts +23 -0
  65. package/examples/retell-hosted/src/app.ts +22 -0
  66. package/examples/retell-hosted/src/config.ts +53 -0
  67. package/examples/retell-hosted/src/retell.ts +166 -0
  68. package/examples/two-stage-dialer/app.ts +96 -0
  69. package/examples/ultravox-voice-agent/ws-app.ts +116 -0
  70. package/examples/voice-agent/README.md +19 -0
  71. package/examples/voice-agent/app.js +133 -0
  72. package/examples/voice-agent/app.ts +132 -0
  73. package/examples/voice-agent/ws-app.ts +137 -0
  74. package/package.json +9 -4
@@ -0,0 +1,65 @@
1
+ import express from 'express';
2
+ import { WebhookResponse } from '@jambonz/sdk/webhook';
3
+
4
+ const app = express();
5
+ app.use(express.json());
6
+
7
+ app.post('/echo', (_req, res) => {
8
+ const jambonz = new WebhookResponse();
9
+ jambonz
10
+ .pause({ length: 1 })
11
+ .gather({
12
+ input: ['speech'],
13
+ actionHook: '/echo-result',
14
+ timeout: 25,
15
+ say: { text: 'Please say something and I will echo it back to you.' },
16
+ })
17
+ .say({ text: 'I didn\'t hear anything. Goodbye.' })
18
+ .hangup();
19
+
20
+ res.json(jambonz);
21
+ });
22
+
23
+ app.post('/echo-result', (req, res) => {
24
+ const { reason, speech } = req.body;
25
+ const jambonz = new WebhookResponse();
26
+
27
+ switch (reason) {
28
+ case 'speechDetected': {
29
+ const { transcript, confidence } = speech.alternatives[0];
30
+ jambonz
31
+ .say({
32
+ text: confidence
33
+ ? `You said: ${transcript}. The confidence score was ${confidence.toFixed(2)}.`
34
+ : `You said: ${transcript}.`,
35
+ })
36
+ .gather({
37
+ input: ['speech'],
38
+ actionHook: '/echo-result',
39
+ timeout: 25,
40
+ say: { text: 'Please say something else.' },
41
+ })
42
+ .say({ text: 'I didn\'t hear anything. Goodbye.' })
43
+ .hangup();
44
+ break;
45
+ }
46
+ case 'timeout':
47
+ jambonz
48
+ .gather({
49
+ input: ['speech'],
50
+ actionHook: '/echo-result',
51
+ timeout: 25,
52
+ say: { text: 'Are you still there? I didn\'t hear anything.' },
53
+ })
54
+ .say({ text: 'I didn\'t hear anything. Goodbye.' })
55
+ .hangup();
56
+ break;
57
+ default:
58
+ jambonz.hangup();
59
+ break;
60
+ }
61
+
62
+ res.json(jambonz);
63
+ });
64
+
65
+ app.listen(3000, () => console.log('Echo webhook app listening on port 3000'));
@@ -0,0 +1,67 @@
1
+ import http from 'http';
2
+ import { createEndpoint } from '@jambonz/sdk/websocket';
3
+
4
+ const server = http.createServer();
5
+ const makeService = createEndpoint({ server, port: 3000 });
6
+
7
+ const svc = makeService({ path: '/echo' });
8
+
9
+ svc.on('session:new', (session) => {
10
+ console.log(`New incoming call: ${session.callSid}`);
11
+
12
+ session
13
+ .on('close', (code: number, _reason: Buffer) => {
14
+ console.log(`Session ${session.callSid} closed: ${code}`);
15
+ })
16
+ .on('error', (err: Error) => {
17
+ console.error(`Session ${session.callSid} error:`, err);
18
+ })
19
+ .on('/echo', (evt: Record<string, any>) => {
20
+ console.log('Got speech event:', evt.reason);
21
+
22
+ switch (evt.reason) {
23
+ case 'speechDetected': {
24
+ const { transcript, confidence } = evt.speech.alternatives[0];
25
+ session
26
+ .say({
27
+ text: confidence
28
+ ? `You said: ${transcript}. The confidence score was ${confidence.toFixed(2)}.`
29
+ : `You said: ${transcript}.`,
30
+ })
31
+ .gather({
32
+ input: ['speech'],
33
+ actionHook: '/echo',
34
+ timeout: 25,
35
+ say: { text: 'Please say something else.' },
36
+ })
37
+ .reply();
38
+ break;
39
+ }
40
+ case 'timeout':
41
+ session
42
+ .gather({
43
+ input: ['speech'],
44
+ actionHook: '/echo',
45
+ timeout: 25,
46
+ say: { text: 'Are you still there? I didn\'t hear anything.' },
47
+ })
48
+ .reply();
49
+ break;
50
+ default:
51
+ session.reply();
52
+ break;
53
+ }
54
+ });
55
+
56
+ session
57
+ .pause({ length: 1 })
58
+ .gather({
59
+ input: ['speech'],
60
+ actionHook: '/echo',
61
+ timeout: 25,
62
+ say: { text: 'Please say something and I will echo it back to you.' },
63
+ })
64
+ .send();
65
+ });
66
+
67
+ console.log('Echo WebSocket app listening on port 3000');
@@ -0,0 +1,81 @@
1
+ import http from 'http';
2
+ import { createEndpoint } from '@jambonz/sdk/websocket';
3
+
4
+ const server = http.createServer();
5
+ const makeService = createEndpoint({
6
+ server,
7
+ port: 3000,
8
+ envVars: {
9
+ ELEVENLABS_AGENT_ID: {
10
+ type: 'string',
11
+ description: 'ElevenLabs Conversational AI agent ID',
12
+ required: true,
13
+ },
14
+ ELEVENLABS_API_KEY: {
15
+ type: 'string',
16
+ description: 'ElevenLabs API key (optional, enables signed URLs)',
17
+ obscure: true,
18
+ },
19
+ },
20
+ });
21
+
22
+ const svc = makeService({ path: '/elevenlabs-s2s' });
23
+
24
+ svc.on('session:new', (session) => {
25
+ console.log(`Incoming call: ${session.callSid}`);
26
+ console.log(' from: %s to: %s', session.data.from, session.data.to);
27
+
28
+ const agentId = session.data.env_vars?.ELEVENLABS_AGENT_ID;
29
+ const apiKey = session.data.env_vars?.ELEVENLABS_API_KEY;
30
+
31
+ if (!agentId) {
32
+ console.error('ERROR: ELEVENLABS_AGENT_ID not found in application environment variables');
33
+ return;
34
+ }
35
+
36
+ const auth: Record<string, string> = { agent_id: agentId };
37
+ if (apiKey) auth.api_key = apiKey;
38
+
39
+ session
40
+ .on('/event', (_evt: Record<string, any>) => {
41
+ // ElevenLabs events (user_transcript, agent_response, etc.)
42
+ })
43
+ .on('/toolCall', async (evt: Record<string, any>) => {
44
+ const { name, args, tool_call_id } = evt;
45
+ console.log(`Tool call: ${name}`, args);
46
+
47
+ // Return tool results in ElevenLabs client_tool_result format
48
+ session.sendToolOutput(tool_call_id, {
49
+ type: 'client_tool_result',
50
+ tool_call_id,
51
+ result: JSON.stringify({ error: `Unknown tool: ${name}` }),
52
+ is_error: true,
53
+ });
54
+ })
55
+ .on('/final', (evt: Record<string, any>) => {
56
+ console.log(`Session ${session.callSid} completed: ${evt.completion_reason}`);
57
+ session.reply();
58
+ })
59
+ .on('close', (code: number) => {
60
+ console.log(`Session ${session.callSid} closed: ${code}`);
61
+ })
62
+ .on('error', (err: Error) => {
63
+ console.error(`Session ${session.callSid} error:`, err);
64
+ });
65
+
66
+ session
67
+ .answer()
68
+ .pause({ length: 1 })
69
+ .elevenlabs_s2s({
70
+ auth,
71
+ llmOptions: {},
72
+ actionHook: '/final',
73
+ eventHook: '/event',
74
+ toolHook: '/toolCall',
75
+ events: ['all'],
76
+ })
77
+ .hangup()
78
+ .send();
79
+ });
80
+
81
+ console.log('ElevenLabs voice agent listening on port 3000');
@@ -0,0 +1,15 @@
1
+ # Hello World
2
+
3
+ The simplest jambonz application: answer a call, greet the caller, and hang up.
4
+
5
+ ## What It Demonstrates
6
+ - Basic verb array structure
7
+ - The `say` verb
8
+ - The `hangup` verb
9
+
10
+ ## Webhook Version
11
+ - `app.js` — Plain JavaScript with Express
12
+ - `app.ts` — TypeScript using `@jambonz/sdk` WebhookResponse builder
13
+
14
+ ## WebSocket Version
15
+ - `ws-app.ts` — TypeScript using `@jambonz/sdk` createEndpoint + Session
@@ -0,0 +1,20 @@
1
+ const express = require('express');
2
+ const app = express();
3
+ app.use(express.json());
4
+
5
+ // jambonz calls this URL when a call arrives
6
+ app.post('/incoming', (req, res) => {
7
+ console.log(`Incoming call from ${req.body.from} to ${req.body.to}`);
8
+
9
+ res.json([
10
+ {
11
+ verb: 'say',
12
+ text: 'Hello! Welcome to our service. Thank you for calling. Goodbye!'
13
+ },
14
+ {
15
+ verb: 'hangup'
16
+ }
17
+ ]);
18
+ });
19
+
20
+ app.listen(3000, () => console.log('jambonz app listening on port 3000'));
@@ -0,0 +1,19 @@
1
+ import express from 'express';
2
+ import { WebhookResponse } from '@jambonz/sdk/webhook';
3
+
4
+ const app = express();
5
+ app.use(express.json());
6
+
7
+ // jambonz calls this URL when a call arrives
8
+ app.post('/incoming', (req, res) => {
9
+ console.log(`Incoming call from ${req.body.from} to ${req.body.to}`);
10
+
11
+ const jambonz = new WebhookResponse();
12
+ jambonz
13
+ .say({ text: 'Hello! Welcome to our service. Thank you for calling. Goodbye!' })
14
+ .hangup();
15
+
16
+ res.json(jambonz);
17
+ });
18
+
19
+ app.listen(3000, () => console.log('jambonz app listening on port 3000'));
@@ -0,0 +1,18 @@
1
+ import http from 'http';
2
+ import { createEndpoint } from '@jambonz/sdk/websocket';
3
+
4
+ const server = http.createServer();
5
+ const makeService = createEndpoint({ server, port: 3000 });
6
+
7
+ const svc = makeService({ path: '/' });
8
+
9
+ svc.on('session:new', (session) => {
10
+ console.log(`Incoming call: ${session.callSid}`);
11
+
12
+ session
13
+ .say({ text: 'Hello! Welcome to our service. Thank you for calling. Goodbye!' })
14
+ .hangup()
15
+ .send();
16
+ });
17
+
18
+ console.log('jambonz ws app listening on port 3000');
@@ -0,0 +1,15 @@
1
+ # IVR Menu
2
+
3
+ A classic interactive voice response menu that routes callers based on DTMF or speech input.
4
+
5
+ ## What It Demonstrates
6
+ - The `gather` verb with nested `say` prompt
7
+ - Handling DTMF digit input
8
+ - Handling speech input
9
+ - Routing to different handlers based on user input
10
+ - Using `actionHook` to receive gather results and return new verbs
11
+ - Fallback when no input is received (timeout)
12
+
13
+ ## Files
14
+ - `app.js` — Plain JavaScript with Express
15
+ - `app.ts` — TypeScript using `@jambonz/sdk` WebhookResponse builder
@@ -0,0 +1,85 @@
1
+ const express = require('express');
2
+ const app = express();
3
+ app.use(express.json());
4
+
5
+ // Initial call handler — present the menu
6
+ app.post('/incoming', (req, res) => {
7
+ res.json([
8
+ {
9
+ verb: 'gather',
10
+ input: ['speech', 'digits'],
11
+ actionHook: '/menu-selection',
12
+ numDigits: 1,
13
+ timeout: 10,
14
+ say: {
15
+ text: 'Welcome to Acme Corp. Press 1 or say sales for sales. Press 2 or say support for technical support. Press 3 or say billing for billing.'
16
+ }
17
+ },
18
+ // Fallback if no input received
19
+ {
20
+ verb: 'say',
21
+ text: 'We did not receive any input. Goodbye.'
22
+ },
23
+ {
24
+ verb: 'hangup'
25
+ }
26
+ ]);
27
+ });
28
+
29
+ // Handle the menu selection
30
+ app.post('/menu-selection', (req, res) => {
31
+ const { digits, speech } = req.body;
32
+ const transcript = speech?.alternatives?.[0]?.transcript?.toLowerCase() || '';
33
+
34
+ let department;
35
+ if (digits === '1' || transcript.includes('sales')) {
36
+ department = 'sales';
37
+ } else if (digits === '2' || transcript.includes('support')) {
38
+ department = 'support';
39
+ } else if (digits === '3' || transcript.includes('billing')) {
40
+ department = 'billing';
41
+ }
42
+
43
+ if (department) {
44
+ res.json([
45
+ {
46
+ verb: 'say',
47
+ text: `Connecting you to ${department}. Please hold.`
48
+ },
49
+ {
50
+ verb: 'dial',
51
+ target: [{ type: 'user', name: `${department}-queue` }],
52
+ answerOnBridge: true,
53
+ timeout: 30,
54
+ actionHook: '/dial-result'
55
+ },
56
+ {
57
+ verb: 'say',
58
+ text: `Sorry, ${department} is not available right now. Please try again later.`
59
+ },
60
+ {
61
+ verb: 'hangup'
62
+ }
63
+ ]);
64
+ } else {
65
+ // Unrecognized input — replay the menu
66
+ res.json([
67
+ {
68
+ verb: 'say',
69
+ text: 'Sorry, I didn\'t understand that.'
70
+ },
71
+ {
72
+ verb: 'redirect',
73
+ actionHook: '/incoming'
74
+ }
75
+ ]);
76
+ }
77
+ });
78
+
79
+ // Handle dial result
80
+ app.post('/dial-result', (req, res) => {
81
+ console.log(`Call ended: ${JSON.stringify(req.body)}`);
82
+ res.json([{ verb: 'hangup' }]);
83
+ });
84
+
85
+ app.listen(3000, () => console.log('IVR app listening on port 3000'));
@@ -0,0 +1,70 @@
1
+ import express from 'express';
2
+ import { WebhookResponse } from '@jambonz/sdk/webhook';
3
+
4
+ const app = express();
5
+ app.use(express.json());
6
+
7
+ // Initial call handler — present the menu
8
+ app.post('/incoming', (_req, res) => {
9
+ const jambonz = new WebhookResponse();
10
+ jambonz
11
+ .gather({
12
+ input: ['speech', 'digits'],
13
+ actionHook: '/menu-selection',
14
+ numDigits: 1,
15
+ timeout: 10,
16
+ say: {
17
+ text: 'Welcome to Acme Corp. Press 1 or say sales for sales. Press 2 or say support for technical support. Press 3 or say billing for billing.',
18
+ },
19
+ })
20
+ .say({ text: 'We did not receive any input. Goodbye.' })
21
+ .hangup();
22
+
23
+ res.json(jambonz);
24
+ });
25
+
26
+ // Handle the menu selection
27
+ app.post('/menu-selection', (req, res) => {
28
+ const { digits, speech } = req.body;
29
+ const transcript: string = speech?.alternatives?.[0]?.transcript?.toLowerCase() || '';
30
+
31
+ let department: string | undefined;
32
+ if (digits === '1' || transcript.includes('sales')) {
33
+ department = 'sales';
34
+ } else if (digits === '2' || transcript.includes('support')) {
35
+ department = 'support';
36
+ } else if (digits === '3' || transcript.includes('billing')) {
37
+ department = 'billing';
38
+ }
39
+
40
+ const jambonz = new WebhookResponse();
41
+
42
+ if (department) {
43
+ jambonz
44
+ .say({ text: `Connecting you to ${department}. Please hold.` })
45
+ .dial({
46
+ target: [{ type: 'user', name: `${department}-queue` }],
47
+ answerOnBridge: true,
48
+ timeout: 30,
49
+ actionHook: '/dial-result',
50
+ })
51
+ .say({ text: `Sorry, ${department} is not available right now. Please try again later.` })
52
+ .hangup();
53
+ } else {
54
+ jambonz
55
+ .say({ text: "Sorry, I didn't understand that." })
56
+ .redirect({ actionHook: '/incoming' });
57
+ }
58
+
59
+ res.json(jambonz);
60
+ });
61
+
62
+ // Handle dial result
63
+ app.post('/dial-result', (req, res) => {
64
+ console.log(`Call ended: ${JSON.stringify(req.body)}`);
65
+ const jambonz = new WebhookResponse();
66
+ jambonz.hangup();
67
+ res.json(jambonz);
68
+ });
69
+
70
+ app.listen(3000, () => console.log('IVR app listening on port 3000'));
@@ -0,0 +1,22 @@
1
+ import express from 'express';
2
+ import { WebhookResponse } from '@jambonz/sdk/webhook';
3
+
4
+ const app = express();
5
+ app.use(express.json());
6
+
7
+ app.post('/record', (_req, res) => {
8
+ const wsUrl = process.env.WS_RECORD_URL;
9
+ if (!wsUrl) throw new Error('WS_RECORD_URL env variable is required');
10
+
11
+ const jambonz = new WebhookResponse();
12
+ jambonz
13
+ .pause({ length: 1 })
14
+ .say({
15
+ text: 'Hi there. Please leave a message, and we will get back to you shortly.',
16
+ })
17
+ .listen({ url: wsUrl });
18
+
19
+ res.json(jambonz);
20
+ });
21
+
22
+ app.listen(3000, () => console.log('Listen-record webhook app listening on port 3000'));
@@ -0,0 +1,96 @@
1
+ import Anthropic from '@anthropic-ai/sdk';
2
+ import http from 'http';
3
+ import { createEndpoint } from '@jambonz/sdk/websocket';
4
+
5
+ const ANTHROPIC_MODEL = 'claude-3-5-haiku-latest';
6
+ const systemPrompt = `You are a helpful conversational AI voice bot.
7
+ Please keep your answers short and to the point; the user will follow up with more questions if needed.
8
+ Please reply with unadorned text that can be read aloud to the user using a TTS engine`;
9
+
10
+ const server = http.createServer();
11
+ const makeService = createEndpoint({ server, port: 3000 });
12
+
13
+ const svc = makeService({ path: '/llm-streaming' });
14
+
15
+ svc.on('session:new', (session) => {
16
+ console.log(`Incoming call: ${session.callSid}`);
17
+
18
+ const apiKey = process.env.ANTHROPIC_API_KEY;
19
+ if (!apiKey) throw new Error('ANTHROPIC_API_KEY env variable is required');
20
+
21
+ const client = new Anthropic({ apiKey });
22
+ const messages: Array<{ role: 'user' | 'assistant'; content: string }> = [];
23
+ let assistantResponse = '';
24
+ let userInterrupt = false;
25
+
26
+ session
27
+ .on('/speech-detected', async (evt: Record<string, any>) => {
28
+ const { speech } = evt;
29
+
30
+ // Acknowledge the hook immediately so jambonz can continue
31
+ session.reply();
32
+
33
+ if (speech?.is_final) {
34
+ const { transcript } = speech.alternatives[0];
35
+ messages.push({ role: 'user', content: transcript });
36
+ userInterrupt = false;
37
+
38
+ const stream = await client.messages.create({
39
+ model: ANTHROPIC_MODEL,
40
+ max_tokens: 1024,
41
+ system: systemPrompt,
42
+ messages,
43
+ stream: true,
44
+ });
45
+
46
+ for await (const event of stream) {
47
+ if (userInterrupt) {
48
+ messages.push({ role: 'assistant', content: `${assistantResponse}...` });
49
+ assistantResponse = '';
50
+ break;
51
+ }
52
+
53
+ if ((event as any).delta?.text) {
54
+ const tokens = (event as any).delta.text;
55
+ assistantResponse += tokens;
56
+ session.sendTtsTokens(tokens).catch((err: Error) =>
57
+ console.error('Error sending TTS tokens:', err)
58
+ );
59
+ } else if (event.type === 'message_stop') {
60
+ session.flushTtsTokens();
61
+ messages.push({ role: 'assistant', content: assistantResponse });
62
+ assistantResponse = '';
63
+ }
64
+ }
65
+ }
66
+ })
67
+ .on('tts:streaming-event', (_evt: Record<string, any>) => {
68
+ // TTS streaming lifecycle events
69
+ })
70
+ .on('tts:user_interrupt', () => {
71
+ console.log(`Session ${session.callSid}: user interrupted`);
72
+ userInterrupt = true;
73
+ })
74
+ .on('close', (code: number) => {
75
+ console.log(`Session ${session.callSid} closed: ${code}`);
76
+ })
77
+ .on('error', (err: Error) => {
78
+ console.error(`Session ${session.callSid} error:`, err);
79
+ });
80
+
81
+ session
82
+ .config({
83
+ ttsStream: { enable: true },
84
+ bargeIn: {
85
+ enable: true,
86
+ sticky: true,
87
+ minBargeinWordCount: 1,
88
+ actionHook: '/speech-detected',
89
+ input: ['speech'],
90
+ },
91
+ })
92
+ .say({ text: 'Hi there, how can I help you today?' })
93
+ .send();
94
+ });
95
+
96
+ console.log('LLM streaming app listening on port 3000');