@tiledesk/tiledesk-voice-twilio-connector 0.2.0-rc3 β 0.2.0-rc7
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 +494 -23
- package/package.json +3 -2
- package/src/app.js +14 -5
- package/src/controllers/VoiceController.js +33 -28
- package/src/middlewares/httpLogger.js +25 -13
- package/src/models/KeyValueStore.js +5 -5
- package/src/routes/manageApp.js +7 -7
- package/src/services/AiService.js +8 -8
- package/src/services/AiService.sdk.js +13 -13
- package/src/services/IntegrationService.js +2 -2
- package/src/services/MessageService.js +12 -6
- package/src/services/SessionService.js +5 -5
- package/src/services/SpeechService.js +3 -3
- package/src/services/TwilioService.js +9 -2
- package/src/services/UploadService.js +1 -1
- package/src/services/channels/TiledeskChannel.js +54 -55
- package/src/services/channels/VoiceChannel.js +4 -4
- package/src/services/clients/TiledeskSubscriptionClient.js +2 -2
- package/src/services/translators/TiledeskTwilioTranslator.js +20 -15
- package/src/controllers/VoiceController.original.js +0 -811
- package/src/services/translators/TiledeskTwilioTranslator.original.js +0 -614
package/README.md
CHANGED
|
@@ -1,44 +1,515 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Tiledesk Voice Twilio Connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@tiledesk/tiledesk-voice-twilio-connector)
|
|
4
|
+
[](https://nodejs.org/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
6
|
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
## π Table of Contents
|
|
8
10
|
|
|
9
|
-
|
|
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
|
-
|
|
22
|
+
---
|
|
12
23
|
|
|
13
|
-
## What
|
|
24
|
+
## π― What is it?
|
|
14
25
|
|
|
15
|
-
|
|
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
|
-
|
|
28
|
+
### Key Features
|
|
18
29
|
|
|
19
|
-
|
|
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
|
-
|
|
38
|
+
---
|
|
22
39
|
|
|
23
|
-
|
|
40
|
+
## π What does it do?
|
|
24
41
|
|
|
25
|
-
|
|
42
|
+
The connector acts as a **translation layer** between two systems:
|
|
26
43
|
|
|
27
|
-
|
|
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
|
-
|
|
47
|
+
### Use Cases
|
|
30
48
|
|
|
31
|
-
|
|
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
|
-
|
|
55
|
+
### Workflow Example
|
|
34
56
|
|
|
35
|
-
|
|
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
|
-
|
|
75
|
+
---
|
|
38
76
|
|
|
39
|
-
##
|
|
77
|
+
## βοΈ How does it work?
|
|
40
78
|
|
|
41
|
-
|
|
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-
|
|
3
|
+
"version": "0.2.0-rc7",
|
|
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
|
@@ -2,6 +2,7 @@ const express = require('express');
|
|
|
2
2
|
const config = require('./config');
|
|
3
3
|
const logger = require('./utils/logger');
|
|
4
4
|
const redis = require('redis');
|
|
5
|
+
const { BASE_POOLING_DELAY, MAX_POLLING_TIME } = require('./utils/constants');
|
|
5
6
|
|
|
6
7
|
// Services
|
|
7
8
|
const { VoiceChannel } = require('./services/channels/VoiceChannel');
|
|
@@ -56,8 +57,8 @@ function mergeConfig(options = {}) {
|
|
|
56
57
|
},
|
|
57
58
|
app: {
|
|
58
59
|
brandName: options.BRAND_NAME || config.app.brandName,
|
|
59
|
-
basePoolingDelay: options.BASE_POOLING_DELAY || config.app.basePoolingDelay,
|
|
60
|
-
maxPollingTime: options.MAX_POLLING_TIME || config.app.maxPollingTime,
|
|
60
|
+
basePoolingDelay: options.BASE_POOLING_DELAY || config.app.basePoolingDelay || BASE_POOLING_DELAY,
|
|
61
|
+
maxPollingTime: options.MAX_POLLING_TIME || config.app.maxPollingTime || MAX_POLLING_TIME,
|
|
61
62
|
logLevel: options.VOICE_TWILIO_LOG || config.app.logLevel || "info"
|
|
62
63
|
}
|
|
63
64
|
};
|
|
@@ -81,10 +82,18 @@ async function startServer(options = {}) {
|
|
|
81
82
|
logger.error("Missing redis parameters");
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
// Mongo
|
|
85
|
+
// Mongo - Reuse existing connection if provided, otherwise create new one
|
|
85
86
|
const db = new KVBaseMongo('kvstore');
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
if (options.dbconnection) {
|
|
88
|
+
await db.reuseConnection(options.dbconnection);
|
|
89
|
+
logger.debug("KVBaseMongo reused existing db connection");
|
|
90
|
+
} else {
|
|
91
|
+
if (!mergedConfig.database.mongodbUri) {
|
|
92
|
+
throw new Error("MONGODB_URI is required when dbconnection is not provided");
|
|
93
|
+
}
|
|
94
|
+
await db.connect(mergedConfig.database.mongodbUri);
|
|
95
|
+
logger.info("KVBaseMongo successfully connected.");
|
|
96
|
+
}
|
|
88
97
|
|
|
89
98
|
// Services
|
|
90
99
|
const voiceChannel = new VoiceChannel({
|