@tiledesk/tiledesk-voice-twilio-connector 0.2.0-rc3 β†’ 0.2.0-rc6

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 CHANGED
@@ -1,44 +1,515 @@
1
- # Hello Node!
1
+ # Tiledesk Voice Twilio Connector
2
2
 
3
- This project includes a Node.js server script and a web page that connects to it. The front-end page presents a form the visitor can use to submit a color name, sending the submitted value to the back-end API running on the server. The server returns info to the page that allows it to update the display with the chosen color. 🎨
3
+ [![npm version](https://img.shields.io/npm/v/@tiledesk/tiledesk-voice-twilio-connector.svg)](https://www.npmjs.com/package/@tiledesk/tiledesk-voice-twilio-connector)
4
+ [![Node.js Version](https://img.shields.io/node/v/@tiledesk/tiledesk-voice-twilio-connector.svg)](https://nodejs.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
6
 
5
- [Node.js](https://nodejs.org/en/about/) is a popular runtime that lets you run server-side JavaScript. This project uses the [Fastify](https://www.fastify.io/) framework and explores basic templating with [Handlebars](https://handlebarsjs.com/).
7
+ A production-ready Node.js connector that bridges **Twilio Voice API** with the **Tiledesk** conversational platform, enabling real-time voice interactions with AI-powered chatbots and human agents.
6
8
 
7
- _Last updated: 14 August 2023_
9
+ ## πŸ“‹ Table of Contents
8
10
 
9
- ## Prerequisites
11
+ - [What is it?](#what-is-it)
12
+ - [What does it do?](#what-does-it-do)
13
+ - [How does it work?](#how-does-it-work)
14
+ - [Installation](#installation)
15
+ - [Quick Start](#quick-start)
16
+ - [Configuration](#configuration)
17
+ - [Architecture](#architecture)
18
+ - [API Reference](#api-reference)
19
+ - [Usage Examples](#usage-examples)
20
+ - [Deployment](#deployment)
10
21
 
11
- You'll get best use out of this project if you're familiar with basic JavaScript. If you've written JavaScript for client-side web pages this is a little different because it uses server-side JS, but the syntax is the same!
22
+ ---
12
23
 
13
- ## What's in this project?
24
+ ## 🎯 What is it?
14
25
 
15
- ← `README.md`: That’s this file, where you can tell people what your cool website does and how you built it.
26
+ The **Tiledesk Voice Twilio Connector** is a middleware service that enables voice-based conversations through Twilio's telephony infrastructure, integrated seamlessly with Tiledesk's messaging and AI platform.
16
27
 
17
- ← `public/style.css`: The styling rules for the pages in your site.
28
+ ### Key Features
18
29
 
19
- ← `server.js`: The **Node.js** server script for your new site. The JavaScript defines the endpoints in the site back-end, one to return the homepage and one to update with the submitted color. Each one sends data to a Handlebars template which builds these parameter values into the web page the visitor sees.
30
+ - πŸŽ™οΈ **Real-time Voice Calls**: Handle inbound and outbound voice calls via Twilio
31
+ - πŸ€– **AI Integration**: Connect voice interactions with Tiledesk's AI chatbots
32
+ - πŸ’¬ **Unified Messaging**: Convert voice to text and text to voice for seamless conversations
33
+ - πŸ”„ **Bidirectional Communication**: Sync messages between Twilio and Tiledesk in real-time
34
+ - πŸ“Š **Session Management**: Track and manage call sessions with Redis and MongoDB
35
+ - 🎚️ **Speech Services**: Support for OpenAI Whisper (STT) and ElevenLabs (TTS)
36
+ - ⚑ **Event-Driven**: Asynchronous message processing with queue-based architecture
20
37
 
21
- ← `package.json`: The NPM packages for your project's dependencies.
38
+ ---
22
39
 
23
- ← `src/`: This folder holds the site template along with some basic data files.
40
+ ## πŸš€ What does it do?
24
41
 
25
- ← `src/pages/index.hbs`: This is the main page template for your site. The template receives parameters from the server script, which it includes in the page HTML. The page sends the user submitted color value in the body of a request, or as a query parameter to choose a random color.
42
+ The connector acts as a **translation layer** between two systems:
26
43
 
27
- ← `src/colors.json`: A collection of CSS color names. We use this in the server script to pick a random color, and to match searches against color names.
44
+ 1. **Twilio Voice API** - Handles telephony infrastructure (calls, recordings, speech recognition)
45
+ 2. **Tiledesk Platform** - Manages conversations, AI chatbots, and agent routing
28
46
 
29
- ← `src/seo.json`: When you're ready to share your new site or add a custom domain, change SEO/meta settings in here.
47
+ ### Use Cases
30
48
 
31
- ## Try this next πŸ—οΈ
49
+ - **Voice-Enabled Customer Support**: Allow customers to call and interact with AI chatbots via voice
50
+ - **IVR Systems**: Build interactive voice response systems with natural language understanding
51
+ - **Voice Assistants**: Create voice-powered assistants that can handle complex conversations
52
+ - **Call Center Integration**: Route voice calls to human agents through Tiledesk's routing system
53
+ - **Multi-Channel Support**: Unify voice, chat, and messaging in a single conversation thread
32
54
 
33
- Take a look in `TODO.md` for next steps you can try out in your new site!
55
+ ### Workflow Example
34
56
 
35
- ___Want a minimal version of this project to build your own Node.js app? Check out [Blank Node](https://glitch.com/edit/#!/remix/glitch-blank-node)!___
57
+ ```
58
+ 1. Customer calls Twilio number
59
+ ↓
60
+ 2. Connector receives call webhook
61
+ ↓
62
+ 3. Creates Tiledesk conversation session
63
+ ↓
64
+ 4. Converts speech to text (OpenAI Whisper)
65
+ ↓
66
+ 5. Sends message to Tiledesk AI chatbot
67
+ ↓
68
+ 6. Receives AI response from Tiledesk
69
+ ↓
70
+ 7. Converts text to speech (ElevenLabs)
71
+ ↓
72
+ 8. Plays audio to caller via Twilio
73
+ ```
36
74
 
37
- ![Glitch](https://cdn.glitch.com/a9975ea6-8949-4bab-addb-8a95021dc2da%2FLogo_Color.svg?v=1602781328576)
75
+ ---
38
76
 
39
- ## You built this with Glitch!
77
+ ## βš™οΈ How does it work?
40
78
 
41
- [Glitch](https://glitch.com) is a friendly community where millions of people come together to build web apps and websites.
79
+ ### Core Components
80
+
81
+ #### 1. **Voice Channel** (`VoiceChannel`)
82
+ - Manages call session lifecycle
83
+ - Implements message queue polling with exponential backoff
84
+ - Handles Redis-based state management
85
+ - Coordinates event-driven communication
86
+
87
+ #### 2. **Tiledesk Channel** (`TiledeskChannel`)
88
+ - Communicates with Tiledesk REST API
89
+ - Manages conversation sessions
90
+ - Handles message queuing and retrieval
91
+ - Syncs call status with Tiledesk
92
+
93
+ #### 3. **Twilio Translator** (`TiledeskTwilioTranslator`)
94
+ - Converts Tiledesk message format to Twilio TwiML
95
+ - Generates TwiML verbs (Say, Play, Gather, Record)
96
+ - Handles audio file generation and streaming
97
+ - Manages call flow state transitions
98
+
99
+ #### 4. **AI Services** (`AiService`)
100
+ - **Speech-to-Text**: Uses OpenAI Whisper API to transcribe audio
101
+ - **Text-to-Speech**: Uses ElevenLabs API to generate natural voice audio
102
+ - Supports both SDK and HTTP-based implementations
103
+ - Automatic fallback mechanisms
104
+
105
+ #### 5. **Session Service** (`SessionService`)
106
+ - Creates and manages call sessions
107
+ - Handles conversation initialization
108
+ - Manages integration settings per project
109
+ - Tracks call metadata
110
+
111
+ #### 6. **Message Service** (`MessageService`)
112
+ - Polls Tiledesk for new messages
113
+ - Implements intelligent polling with delay management
114
+ - Handles message queuing and processing
115
+ - Manages message lifecycle
116
+
117
+ ### Message Flow
118
+
119
+ ```
120
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
121
+ β”‚ Twilio │◄───────►│ Connector │◄───────►│ Tiledesk β”‚
122
+ β”‚ Voice API β”‚ Webhooksβ”‚ (This App) β”‚ REST APIβ”‚ Platform β”‚
123
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
124
+ β”‚
125
+ β”‚
126
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
127
+ β”‚ β”‚
128
+ β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
129
+ β”‚ Redis β”‚ β”‚ MongoDB β”‚
130
+ β”‚ (Queue) β”‚ β”‚ (Storage) β”‚
131
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
132
+ ```
133
+
134
+ ### Request/Response Cycle
135
+
136
+ 1. **Incoming Call**:
137
+ - Twilio sends webhook to `/webhook/:projectId`
138
+ - Connector creates Tiledesk conversation
139
+ - Returns TwiML to start call flow
140
+
141
+ 2. **Voice Input**:
142
+ - User speaks β†’ Twilio records audio
143
+ - Connector receives audio URL
144
+ - Transcribes with OpenAI Whisper
145
+ - Sends text to Tiledesk
146
+
147
+ 3. **AI Response**:
148
+ - Tiledesk processes message
149
+ - AI generates response
150
+ - Connector polls for response
151
+ - Converts text to speech with ElevenLabs
152
+ - Returns TwiML to play audio
153
+
154
+ 4. **Call Management**:
155
+ - Status updates via webhooks
156
+ - Session state in Redis
157
+ - Call metadata in MongoDB
158
+
159
+ ---
160
+
161
+ ## πŸ“¦ Installation
162
+
163
+ ### Prerequisites
164
+
165
+ - **Node.js** >= 18.0.0
166
+ - **npm** >= 8.15.0
167
+ - **MongoDB** (for session storage)
168
+ - **Redis** (for message queue, recommended)
169
+
170
+ ### Install as NPM Package
171
+
172
+ ```bash
173
+ npm install @tiledesk/tiledesk-voice-twilio-connector
174
+ ```
175
+
176
+ ### Install from Source
177
+
178
+ ```bash
179
+ git clone https://github.com/Tiledesk/tiledesk-voice-twilio-connector.git
180
+ cd tiledesk-voice-twilio-connector
181
+ npm install
182
+ ```
183
+
184
+ ---
185
+
186
+ ## πŸƒ Quick Start
187
+
188
+ ### Standalone Mode
189
+
190
+ 1. **Set environment variables**:
191
+
192
+ ```bash
193
+ export API_URL=https://api.tiledesk.com
194
+ export MONGODB_URI=mongodb://localhost:27017/tiledesk
195
+ export REDIS_HOST=localhost
196
+ export REDIS_PORT=6379
197
+ export GPT_KEY=your-openai-api-key
198
+ ```
199
+
200
+ 2. **Start the server**:
201
+
202
+ ```bash
203
+ npm start
204
+ ```
205
+
206
+ The server will start on port `3000` (or `PORT` environment variable).
207
+
208
+ ### As NPM Package
209
+
210
+ ```javascript
211
+ const { startServer } = require('@tiledesk/tiledesk-voice-twilio-connector');
212
+
213
+ // Start with environment variables
214
+ await startServer();
215
+
216
+ // Or pass configuration directly
217
+ await startServer({
218
+ MONGODB_URI: 'mongodb://localhost:27017/tiledesk',
219
+ API_URL: 'https://api.tiledesk.com',
220
+ REDIS_HOST: 'localhost',
221
+ REDIS_PORT: 6379,
222
+ GPT_KEY: 'your-openai-key'
223
+ });
224
+ ```
225
+
226
+ ---
227
+
228
+ ## βš™οΈ Configuration
229
+
230
+ ### Environment Variables
231
+
232
+ | Variable | Required | Description | Default |
233
+ |----------|----------|-------------|---------|
234
+ | `PORT` | No | Server port | `3000` |
235
+ | `API_URL` | Yes | Tiledesk API base URL | - |
236
+ | `BASE_URL` | Yes | Base URL for webhooks | - |
237
+ | `BASE_FILE_URL` | Yes | Base URL for file uploads | - |
238
+ | `MONGODB_URI` | Yes | MongoDB connection string | - |
239
+ | `REDIS_HOST` | Recommended | Redis host | - |
240
+ | `REDIS_PORT` | Recommended | Redis port | `6379` |
241
+ | `REDIS_PASSWORD` | No | Redis password | - |
242
+ | `GPT_KEY` | Yes | OpenAI API key for STT | - |
243
+ | `OPENAI_ENDPOINT` | No | OpenAI API endpoint | `https://api.openai.com/v1` |
244
+ | `ELEVENLABS_ENDPOINT` | No | ElevenLabs API endpoint | `https://api.elevenlabs.io` |
245
+ | `USE_ELEVENLABS_SDK` | No | Use ElevenLabs SDK (vs HTTP) | `false` |
246
+ | `BRAND_NAME` | No | Brand name for customization | - |
247
+ | `BASE_POOLING_DELAY` | No | Base polling delay (ms) | - |
248
+ | `MAX_POLLING_TIME` | No | Max polling time (ms) | - |
249
+ | `VOICE_TWILIO_LOG` | No | Log level | `info` |
250
+
251
+ ### Configuration Priority
252
+
253
+ 1. **Options parameter** (highest priority)
254
+ 2. **Environment variables** (`process.env`)
255
+ 3. **Default values** (lowest priority)
256
+
257
+ ```javascript
258
+ // Example: Options override environment variables
259
+ startServer({
260
+ MONGODB_URI: 'mongodb://custom-host:27017/tiledesk', // Overrides process.env.MONGODB_URI
261
+ API_URL: 'https://custom-api.tiledesk.com' // Overrides process.env.API_URL
262
+ });
263
+ ```
264
+
265
+ ---
266
+
267
+ ## πŸ—οΈ Architecture
268
+
269
+ ### Project Structure
270
+
271
+ ```
272
+ tiledesk-voice-twilio-connector/
273
+ β”œβ”€β”€ src/
274
+ β”‚ β”œβ”€β”€ app.js # Express app setup
275
+ β”‚ β”œβ”€β”€ config/ # Configuration management
276
+ β”‚ β”‚ β”œβ”€β”€ index.js # Environment config
277
+ β”‚ β”‚ └── logger.js # Winston logger config
278
+ β”‚ β”œβ”€β”€ controllers/ # HTTP request handlers
279
+ β”‚ β”‚ └── VoiceController.js # Main voice controller
280
+ β”‚ β”œβ”€β”€ middlewares/ # Express middlewares
281
+ β”‚ β”‚ └── httpLogger.js # HTTP request logging
282
+ β”‚ β”œβ”€β”€ models/ # Data models
283
+ β”‚ β”‚ └── KeyValueStore.js # MongoDB abstraction
284
+ β”‚ β”œβ”€β”€ routes/ # Express routes
285
+ β”‚ β”‚ β”œβ”€β”€ voice.js # Voice API routes
286
+ β”‚ β”‚ └── manageApp.js # Management routes
287
+ β”‚ β”œβ”€β”€ services/ # Business logic
288
+ β”‚ β”‚ β”œβ”€β”€ channels/ # Channel implementations
289
+ β”‚ β”‚ β”‚ β”œβ”€β”€ TiledeskChannel.js
290
+ β”‚ β”‚ β”‚ └── VoiceChannel.js
291
+ β”‚ β”‚ β”œβ”€β”€ clients/ # API clients
292
+ β”‚ β”‚ β”‚ └── TiledeskSubscriptionClient.js
293
+ β”‚ β”‚ β”œβ”€β”€ translators/ # Protocol translators
294
+ β”‚ β”‚ β”‚ └── TiledeskTwilioTranslator.js
295
+ β”‚ β”‚ β”œβ”€β”€ AiService.js # AI/LLM services
296
+ β”‚ β”‚ β”œβ”€β”€ AiService.sdk.js # SDK-based AI service
297
+ β”‚ β”‚ β”œβ”€β”€ IntegrationService.js
298
+ β”‚ β”‚ β”œβ”€β”€ MessageService.js
299
+ β”‚ β”‚ β”œβ”€β”€ SessionService.js
300
+ β”‚ β”‚ β”œβ”€β”€ SpeechService.js
301
+ β”‚ β”‚ β”œβ”€β”€ TwilioService.js
302
+ β”‚ β”‚ └── UploadService.js
303
+ β”‚ └── utils/ # Utilities
304
+ β”‚ β”œβ”€β”€ constants.js
305
+ β”‚ β”œβ”€β”€ errors.js
306
+ β”‚ β”œβ”€β”€ logger.js
307
+ β”‚ └── utils.js
308
+ β”œβ”€β”€ index.js # Entry point
309
+ └── package.json
310
+ ```
311
+
312
+ ### Design Patterns
313
+
314
+ - **Service Layer Pattern**: Business logic separated from HTTP handling
315
+ - **Dependency Injection**: Services receive dependencies via constructor
316
+ - **Event-Driven Architecture**: Side effects handled via EventEmitter
317
+ - **Repository Pattern**: Data access abstracted through models
318
+ - **Strategy Pattern**: Multiple implementations for AI services (SDK vs HTTP)
319
+
320
+ ---
321
+
322
+ ## πŸ“‘ API Reference
323
+
324
+ ### Main Exports
325
+
326
+ #### `startServer(options?)`
327
+
328
+ Starts the Express server and initializes all services.
329
+
330
+ **Parameters:**
331
+ - `options` (Object, optional): Configuration object (see [Configuration](#configuration))
332
+
333
+ **Returns:** `Promise<void>`
334
+
335
+ **Example:**
336
+ ```javascript
337
+ const { startServer } = require('@tiledesk/tiledesk-voice-twilio-connector');
338
+
339
+ await startServer({
340
+ MONGODB_URI: 'mongodb://localhost:27017/tiledesk',
341
+ API_URL: 'https://api.tiledesk.com'
342
+ });
343
+ ```
344
+
345
+ #### `app`
346
+
347
+ Express application instance (before server starts).
348
+
349
+ **Example:**
350
+ ```javascript
351
+ const { app } = require('@tiledesk/tiledesk-voice-twilio-connector');
352
+
353
+ // Mount in existing Express app
354
+ mainApp.use('/voice', app);
355
+ ```
356
+
357
+ ### API Endpoints
358
+
359
+ #### `POST /webhook/:id_project`
360
+ Receives Twilio call webhooks and initiates call flow.
361
+
362
+ #### `POST /tiledesk`
363
+ Receives messages from Tiledesk platform.
364
+
365
+ #### `POST /nextblock/:callSid`
366
+ Handles call flow progression.
367
+
368
+ #### `POST /speechresult/:callSid`
369
+ Processes speech recognition results.
370
+
371
+ #### `GET /health-check`
372
+ Health check endpoint.
373
+
374
+ See [USAGE.md](./USAGE.md) for detailed usage examples.
375
+
376
+ ---
377
+
378
+ ## πŸ’‘ Usage Examples
379
+
380
+ ### Example 1: Basic Integration
381
+
382
+ ```javascript
383
+ const { startServer } = require('@tiledesk/tiledesk-voice-twilio-connector');
384
+
385
+ async function main() {
386
+ try {
387
+ await startServer({
388
+ MONGODB_URI: process.env.MONGODB_URI,
389
+ API_URL: process.env.API_URL,
390
+ BASE_URL: process.env.BASE_URL,
391
+ BASE_FILE_URL: process.env.BASE_FILE_URL,
392
+ REDIS_HOST: process.env.REDIS_HOST,
393
+ REDIS_PORT: parseInt(process.env.REDIS_PORT),
394
+ GPT_KEY: process.env.GPT_KEY
395
+ });
396
+ console.log('Voice connector started successfully');
397
+ } catch (error) {
398
+ console.error('Failed to start:', error);
399
+ process.exit(1);
400
+ }
401
+ }
402
+
403
+ main();
404
+ ```
405
+
406
+ ### Example 2: Integration with Existing Express App
407
+
408
+ ```javascript
409
+ const express = require('express');
410
+ const { app: voiceApp } = require('@tiledesk/tiledesk-voice-twilio-connector');
411
+
412
+ const mainApp = express();
413
+
414
+ // Configure environment
415
+ process.env.API_URL = 'https://api.tiledesk.com';
416
+ process.env.MONGODB_URI = 'mongodb://localhost:27017/tiledesk';
417
+
418
+ // Mount voice connector
419
+ mainApp.use('/voice', voiceApp);
420
+
421
+ // Your other routes
422
+ mainApp.get('/', (req, res) => {
423
+ res.json({ status: 'ok' });
424
+ });
425
+
426
+ mainApp.listen(3000);
427
+ ```
428
+
429
+ ### Example 3: Using with dotenv
430
+
431
+ ```javascript
432
+ require('dotenv').config();
433
+ const { startServer } = require('@tiledesk/tiledesk-voice-twilio-connector');
434
+
435
+ startServer().catch(console.error);
436
+ ```
437
+
438
+ ---
439
+
440
+ ## 🐳 Deployment
441
+
442
+ ### Docker
443
+
444
+ ```bash
445
+ # Build image
446
+ docker build -t tiledesk-voice-twilio-connector .
447
+
448
+ # Run container
449
+ docker run -d \
450
+ -p 3000:3000 \
451
+ -e PORT=3000 \
452
+ -e API_URL=https://api.tiledesk.com \
453
+ -e MONGODB_URI=mongodb://mongo:27017/tiledesk \
454
+ -e REDIS_HOST=redis \
455
+ -e REDIS_PORT=6379 \
456
+ -e GPT_KEY=your-openai-key \
457
+ --name voice-connector \
458
+ tiledesk-voice-twilio-connector
459
+ ```
460
+
461
+ ### Docker Compose
462
+
463
+ ```yaml
464
+ version: '3.8'
465
+ services:
466
+ voice-connector:
467
+ build: .
468
+ ports:
469
+ - "3000:3000"
470
+ environment:
471
+ - PORT=3000
472
+ - API_URL=https://api.tiledesk.com
473
+ - MONGODB_URI=mongodb://mongo:27017/tiledesk
474
+ - REDIS_HOST=redis
475
+ - REDIS_PORT=6379
476
+ depends_on:
477
+ - mongo
478
+ - redis
479
+ ```
480
+
481
+ ---
482
+
483
+ ## πŸ“š Additional Resources
484
+
485
+ - [USAGE.md](./USAGE.md) - Detailed usage guide
486
+ - [Tiledesk Documentation](https://developer.tiledesk.com)
487
+ - [Twilio Voice API Docs](https://www.twilio.com/docs/voice)
488
+
489
+ ---
490
+
491
+ ## 🀝 Contributing
492
+
493
+ Contributions are welcome! Please read our contributing guidelines before submitting PRs.
494
+
495
+ ---
496
+
497
+ ## πŸ“„ License
498
+
499
+ MIT License - see [LICENSE](./LICENSE) file for details.
500
+
501
+ ---
502
+
503
+ ## πŸ‘₯ Authors
504
+
505
+ - **Gabriele Panico** - Initial work
506
+
507
+ ---
508
+
509
+ ## πŸ™ Acknowledgments
510
+
511
+ - [Tiledesk](https://tiledesk.com) - Conversational platform
512
+ - [Twilio](https://www.twilio.com) - Voice API infrastructure
513
+ - [OpenAI](https://openai.com) - Speech-to-text services
514
+ - [ElevenLabs](https://elevenlabs.io) - Text-to-speech services
42
515
 
43
- - Need more help? [Check out our Help Center](https://help.glitch.com/) for answers to any common questions.
44
- - Ready to make it official? [Become a paid Glitch member](https://glitch.com/pricing) to boost your app with private sharing, more storage and memory, domains and more.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-voice-twilio-connector",
3
- "version": "0.2.0-rc3",
3
+ "version": "0.2.0-rc6",
4
4
  "description": "Tiledesk VOICE Twilio connector",
5
5
  "license": "MIT",
6
6
  "author": "Gabriele Panico",
@@ -33,7 +33,8 @@
33
33
  "redis": "^4.6.13",
34
34
  "remove-markdown": "^0.6.2",
35
35
  "twilio": "^5.2.1",
36
- "winston": "^3.3.3"
36
+ "winston": "^3.3.3",
37
+ "uuid": "^9.0.0"
37
38
  },
38
39
  "engines": {
39
40
  "node": ">=18.0.0",
package/src/app.js CHANGED
@@ -81,10 +81,18 @@ async function startServer(options = {}) {
81
81
  logger.error("Missing redis parameters");
82
82
  }
83
83
 
84
- // Mongo
84
+ // Mongo - Reuse existing connection if provided, otherwise create new one
85
85
  const db = new KVBaseMongo('kvstore');
86
- await db.connect(mergedConfig.database.mongodbUri);
87
- logger.info("KVBaseMongo successfully connected.");
86
+ if (options.dbconnection) {
87
+ await db.reuseConnection(options.dbconnection);
88
+ logger.debug("KVBaseMongo reused existing db connection");
89
+ } else {
90
+ if (!mergedConfig.database.mongodbUri) {
91
+ throw new Error("MONGODB_URI is required when dbconnection is not provided");
92
+ }
93
+ await db.connect(mergedConfig.database.mongodbUri);
94
+ logger.info("KVBaseMongo successfully connected.");
95
+ }
88
96
 
89
97
  // Services
90
98
  const voiceChannel = new VoiceChannel({