@tiledesk/tiledesk-voice-twilio-connector 0.1.11 → 0.1.13
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/index.js
CHANGED
|
@@ -82,7 +82,7 @@ router.post("/tiledesk", async (req, res) => {
|
|
|
82
82
|
|
|
83
83
|
// TWILIO WEBHOOK : message from user to tiledesk
|
|
84
84
|
router.post('/webhook/:id_project', async (req, res) => {
|
|
85
|
-
winston.
|
|
85
|
+
winston.verbose('(voice) called POST /webhook/:id_project '+ new Date(), req.params)
|
|
86
86
|
|
|
87
87
|
let project_id = req.params.id_project;
|
|
88
88
|
let callSid = req.body.CallSid;
|
|
@@ -185,8 +185,8 @@ router.post('/webhook/:id_project', async (req, res) => {
|
|
|
185
185
|
|
|
186
186
|
|
|
187
187
|
router.post('/nextblock/:callSid/', async(req, res) => {
|
|
188
|
-
winston.
|
|
189
|
-
winston.
|
|
188
|
+
winston.verbose("(vxml) called POST /nextblock" + new Date(), req.body);
|
|
189
|
+
winston.verbose("(vxml) called POST /nextblock query", req.query);
|
|
190
190
|
|
|
191
191
|
let usertext = req.body.SpeechResult;
|
|
192
192
|
let confidence = req.body.Confidence
|
|
@@ -279,6 +279,7 @@ router.post('/nextblock/:callSid/', async(req, res) => {
|
|
|
279
279
|
// convert response to vxml
|
|
280
280
|
let messageToVXML = await tdTranslator.toVXML(message, callSid, vxmlAttributes)
|
|
281
281
|
winston.debug("(voice) VXML to SEND: "+ messageToVXML);
|
|
282
|
+
winston.debug("(voice) send response to TWILIO : "+ new Date());
|
|
282
283
|
|
|
283
284
|
// Render the response as XML in reply to the webhook request
|
|
284
285
|
res.set('Content-Type', 'text/xml');
|
|
@@ -287,8 +288,8 @@ router.post('/nextblock/:callSid/', async(req, res) => {
|
|
|
287
288
|
|
|
288
289
|
|
|
289
290
|
router.post('/menublock/:callSid', async (req, res) => {
|
|
290
|
-
winston.
|
|
291
|
-
winston.
|
|
291
|
+
winston.verbose("(voice) called POST /menu", req.body);
|
|
292
|
+
winston.verbose("(voice) called POST /menu query" , req.query);
|
|
292
293
|
|
|
293
294
|
let message_text = '';
|
|
294
295
|
let attributes = {};
|
|
@@ -372,7 +373,6 @@ router.post('/menublock/:callSid', async (req, res) => {
|
|
|
372
373
|
channel: { name: CHANNEL_NAME },
|
|
373
374
|
attributes: attributes
|
|
374
375
|
};
|
|
375
|
-
console.log('messssss', tiledeskMessage)
|
|
376
376
|
let tdMessage = await tdChannel.send(tiledeskMessage, user.token, conversation_id);
|
|
377
377
|
|
|
378
378
|
//generate Tiledesk wait message
|
|
@@ -391,9 +391,9 @@ router.post('/menublock/:callSid', async (req, res) => {
|
|
|
391
391
|
});
|
|
392
392
|
|
|
393
393
|
router.post('/handle/:callSid/:event', async (req, res) => {
|
|
394
|
-
winston.
|
|
395
|
-
winston.
|
|
396
|
-
winston.
|
|
394
|
+
winston.verbose("(voice) called POST /handle", req.body);
|
|
395
|
+
winston.debug("(voice) called POST /handle query -->", req.query);
|
|
396
|
+
winston.debug("(voice) called POST /handle params-->", req.params);
|
|
397
397
|
|
|
398
398
|
let event = req.params.event;
|
|
399
399
|
let callSid = req.params.callSid;
|
|
@@ -468,7 +468,7 @@ router.post('/handle/:callSid/:event', async (req, res) => {
|
|
|
468
468
|
|
|
469
469
|
/* ----> catch Event block <----- */
|
|
470
470
|
router.post('/event/:callSid/:event', async(req, res)=> {
|
|
471
|
-
winston.
|
|
471
|
+
winston.verbose("(voice) called POST /event" , req.params);
|
|
472
472
|
winston.debug("(voice) called POST /event query" , req.query);
|
|
473
473
|
winston.debug("(voice) called POST /event body" , req.body);
|
|
474
474
|
|
|
@@ -565,7 +565,7 @@ router.post('/event/:callSid/:event', async(req, res)=> {
|
|
|
565
565
|
|
|
566
566
|
/* ----> catch Twilio Events <----- */
|
|
567
567
|
router.post('/twilio/status',async (req, res) => {
|
|
568
|
-
winston.
|
|
568
|
+
winston.verbose('+++++++++++(voice) called POST twilio/status ', req.body);
|
|
569
569
|
|
|
570
570
|
let event = req.body.CallStatus;
|
|
571
571
|
let callSid = req.body.CallSid;
|
|
@@ -636,7 +636,7 @@ router.post('/twilio/status',async (req, res) => {
|
|
|
636
636
|
})
|
|
637
637
|
|
|
638
638
|
router.post('/twilio/fail',async (req, res) => {
|
|
639
|
-
winston.
|
|
639
|
+
winston.verbose('+++++++++++(voice) called POST twilio/fail ', req.params)
|
|
640
640
|
winston.debug('+++++++++++(voice) called POST twilio/fail ', req.body)
|
|
641
641
|
|
|
642
642
|
res.set('Content-Type', 'text/xml');
|
|
@@ -646,7 +646,7 @@ router.post('/twilio/fail',async (req, res) => {
|
|
|
646
646
|
|
|
647
647
|
/* ----> catch Twilio Events <----- */
|
|
648
648
|
router.post('/record/:callSid/',async (req, res) => {
|
|
649
|
-
winston.
|
|
649
|
+
winston.verbose('+++++++++++(voice) called POST record/:callSid ', req.body);
|
|
650
650
|
|
|
651
651
|
let callSid = req.body.CallSid;
|
|
652
652
|
|
|
@@ -690,7 +690,7 @@ router.post('/record/:callSid/',async (req, res) => {
|
|
|
690
690
|
if(!textMessage){
|
|
691
691
|
//case NO_INPUT
|
|
692
692
|
const queryString = utils.buildQueryString(req.query);
|
|
693
|
-
|
|
693
|
+
winston.debug('case no input.. redirect '+ queryString)
|
|
694
694
|
|
|
695
695
|
return await axios({
|
|
696
696
|
url: "http://localhost:3000/handle/" + callSid + '/no_input'+ queryString,
|
|
@@ -730,8 +730,8 @@ router.post('/record/:callSid/',async (req, res) => {
|
|
|
730
730
|
|
|
731
731
|
|
|
732
732
|
router.get('/addon/transcript', async (req, res) => {
|
|
733
|
-
winston.
|
|
734
|
-
winston.
|
|
733
|
+
winston.verbose("(vxml) called GET /transcript query-->" , req.query);
|
|
734
|
+
winston.debug("(vxml) called GET /transcript body -->" , req.body);
|
|
735
735
|
|
|
736
736
|
res.status(200).send('ok');
|
|
737
737
|
|
|
@@ -739,7 +739,7 @@ router.get('/addon/transcript', async (req, res) => {
|
|
|
739
739
|
|
|
740
740
|
/** --> only for test purpose <-- **/
|
|
741
741
|
router.get('/test', async (req, res) => {
|
|
742
|
-
winston.
|
|
742
|
+
winston.verbose("(vxml) called GET /test" , req.query);
|
|
743
743
|
|
|
744
744
|
let project_id = req.query.id_project;
|
|
745
745
|
let callSid = req.body.CallSid;
|
|
@@ -828,7 +828,7 @@ router.get('/test', async (req, res) => {
|
|
|
828
828
|
type: 'wait',
|
|
829
829
|
time: 0
|
|
830
830
|
},
|
|
831
|
-
{
|
|
831
|
+
/*{
|
|
832
832
|
type: 'settings',
|
|
833
833
|
subType: 'blind_transfer',
|
|
834
834
|
settings: {
|
|
@@ -837,25 +837,26 @@ router.get('/test', async (req, res) => {
|
|
|
837
837
|
falseIntent: "#falseIntenttt",
|
|
838
838
|
trueIntent: "#trueIntennt"
|
|
839
839
|
}
|
|
840
|
-
}
|
|
840
|
+
}*/
|
|
841
841
|
/*{
|
|
842
842
|
type: 'settings',
|
|
843
843
|
subType: 'dtmf_form',
|
|
844
844
|
settings: {
|
|
845
845
|
minDigits: 5,
|
|
846
846
|
maxDigits: 5,
|
|
847
|
-
terminators: "#"
|
|
847
|
+
terminators: "#",
|
|
848
|
+
noInputIntent: "#a",
|
|
849
|
+
noInputTimeout: 2000,
|
|
848
850
|
}
|
|
849
851
|
}*/
|
|
850
|
-
|
|
852
|
+
{
|
|
851
853
|
type: 'settings',
|
|
852
854
|
subType: 'speech_form',
|
|
853
855
|
settings: {
|
|
854
856
|
noInputIntent: "#a",
|
|
855
857
|
noInputTimeout: 2000,
|
|
856
|
-
incompleteSpeechTimeout: 2000
|
|
857
858
|
}
|
|
858
|
-
}
|
|
859
|
+
}
|
|
859
860
|
]
|
|
860
861
|
}
|
|
861
862
|
}
|
|
@@ -905,15 +906,15 @@ async function connectRedis() {
|
|
|
905
906
|
|
|
906
907
|
|
|
907
908
|
redis_client.on('error', err => {
|
|
908
|
-
winston.
|
|
909
|
+
winston.debug('(voice) Connect Redis Error ' + err);
|
|
909
910
|
})
|
|
910
911
|
/*
|
|
911
912
|
redis_client.on('connect', () => {
|
|
912
|
-
winston.
|
|
913
|
+
winston.debug('Redis Connected!'); // Connected!
|
|
913
914
|
});
|
|
914
915
|
*/
|
|
915
916
|
redis_client.on('ready', () => {
|
|
916
|
-
winston.
|
|
917
|
+
winston.debug("(voice) Redis ready!")
|
|
917
918
|
})
|
|
918
919
|
await redis_client.connect(); // only for v4
|
|
919
920
|
require('bluebird').promisifyAll(redis_client)
|
|
@@ -934,14 +935,14 @@ async function startApp(settings, callback) {
|
|
|
934
935
|
} else {
|
|
935
936
|
API_URL = settings.API_URL;
|
|
936
937
|
}
|
|
937
|
-
winston.
|
|
938
|
+
winston.debug("(voice) API_URL: " + API_URL)
|
|
938
939
|
|
|
939
940
|
if (!settings.BASE_URL) {
|
|
940
941
|
winston.error("(voice) BASE_URL is mandatory. Exit...");
|
|
941
942
|
return callback('Missing parameter: BASE_URL');
|
|
942
943
|
} else {
|
|
943
944
|
BASE_URL = settings.BASE_URL;
|
|
944
|
-
winston.
|
|
945
|
+
winston.debug("(voice) BASE_URL: " + BASE_URL);
|
|
945
946
|
}
|
|
946
947
|
|
|
947
948
|
if (settings.BRAND_NAME) {
|
|
@@ -965,14 +966,14 @@ async function startApp(settings, callback) {
|
|
|
965
966
|
|
|
966
967
|
if (settings.dbconnection) {
|
|
967
968
|
db.reuseConnection(settings.dbconnection, () => {
|
|
968
|
-
winston.
|
|
969
|
+
winston.debug("(voice) KVBaseMongo reused exsisting db connection");
|
|
969
970
|
if (callback) {
|
|
970
971
|
callback(null);
|
|
971
972
|
}
|
|
972
973
|
})
|
|
973
974
|
} else {
|
|
974
975
|
db.connect(settings.MONGODB_URI, () => {
|
|
975
|
-
winston.
|
|
976
|
+
winston.debug("(voice) KVBaseMongo successfully connected.");
|
|
976
977
|
|
|
977
978
|
if (callback) {
|
|
978
979
|
callback(null);
|
|
@@ -990,7 +991,7 @@ async function startApp(settings, callback) {
|
|
|
990
991
|
if (!err) {
|
|
991
992
|
winston.info("Manage route succesfully started.");
|
|
992
993
|
} else {
|
|
993
|
-
winston.
|
|
994
|
+
winston.error("(voice) Unable to start API route.")
|
|
994
995
|
}
|
|
995
996
|
})
|
|
996
997
|
|
package/package.json
CHANGED
package/tiledesk/KVBaseMongo.js
CHANGED
|
@@ -63,8 +63,7 @@ class KVBaseMongo {
|
|
|
63
63
|
return new Promise((resolve, reject) => {
|
|
64
64
|
//this.db.get(k).then(value => {resolve(value)});
|
|
65
65
|
|
|
66
|
-
winston.debug("Searching on " + this.
|
|
67
|
-
winston.verbose("Searching on Collection " + this.KV_COLLECTION + ' for key: ', k)
|
|
66
|
+
winston.debug("Searching on Collection " + this.KV_COLLECTION + ' for key: '+ k)
|
|
68
67
|
|
|
69
68
|
this.db.collection(this.KV_COLLECTION).findOne({ key: k }, function(err, doc) {
|
|
70
69
|
if (err) {
|
|
@@ -73,7 +72,7 @@ class KVBaseMongo {
|
|
|
73
72
|
}
|
|
74
73
|
else {
|
|
75
74
|
if (doc) {
|
|
76
|
-
winston.
|
|
75
|
+
winston.debug("Doc found with key: " + doc.key);
|
|
77
76
|
resolve(doc.value);
|
|
78
77
|
}
|
|
79
78
|
else {
|
|
@@ -213,7 +213,6 @@ class TiledeskChannel {
|
|
|
213
213
|
})
|
|
214
214
|
|
|
215
215
|
const base64 = Buffer.from(stream.data, 'binary').toString('base64');
|
|
216
|
-
console.log('baseeeeeeee', base64)
|
|
217
216
|
return 'text'
|
|
218
217
|
|
|
219
218
|
|
|
@@ -258,17 +257,17 @@ class TiledeskChannel {
|
|
|
258
257
|
|
|
259
258
|
/*SKIP INFO MESSAGES*/
|
|
260
259
|
if(utils.messageType(TYPE_MESSAGE.INFO, message)){
|
|
261
|
-
winston.
|
|
260
|
+
winston.debug("> SKIPPING INFO message: " + JSON.stringify(message) );
|
|
262
261
|
return;
|
|
263
262
|
}
|
|
264
263
|
|
|
265
264
|
/*SKIP CURRENT USER MESSAGES*/
|
|
266
265
|
if (message.sender.indexOf(CHANNEL_NAME) > -1) {
|
|
267
|
-
winston.
|
|
266
|
+
winston.debug("> SKIPPING ECHO message: " + JSON.stringify(message) );
|
|
268
267
|
return;
|
|
269
268
|
}
|
|
270
269
|
|
|
271
|
-
winston.
|
|
270
|
+
winston.debug("> SAVE message TO QUEUE: " + JSON.stringify(message) );
|
|
272
271
|
/*SAVE MESSAGE TO QUEUE WITH KET tiledesk:queue:+conversation_id*/
|
|
273
272
|
let conversation_id = message.recipient
|
|
274
273
|
let redis_data = [ message ]
|
|
@@ -59,7 +59,7 @@ class TiledeskSubscriptionClient {
|
|
|
59
59
|
if (callback) {
|
|
60
60
|
callback(null, resbody);
|
|
61
61
|
}
|
|
62
|
-
winston.
|
|
62
|
+
winston.debug("[TiledeskSubscriptionClient] Subscribed");
|
|
63
63
|
resolve(resbody);
|
|
64
64
|
}
|
|
65
65
|
}, true);
|
|
@@ -92,7 +92,7 @@ class TiledeskSubscriptionClient {
|
|
|
92
92
|
if (callback) {
|
|
93
93
|
callback(null, resbody);
|
|
94
94
|
}
|
|
95
|
-
winston.
|
|
95
|
+
winston.debug("[TiledeskSubscriptionClient] Unsubscribed");
|
|
96
96
|
resolve(resbody);
|
|
97
97
|
}
|
|
98
98
|
}, true);
|
|
@@ -263,21 +263,24 @@ class TiledeskTwilioTranslator {
|
|
|
263
263
|
|
|
264
264
|
const gather = rootEle.ele("Gather", { input: "speech"})
|
|
265
265
|
|
|
266
|
-
if(xmlAttributes && xmlAttributes.noInputTimeout){
|
|
267
|
-
gather.att("timeout", xmlAttributes.noInputTimeout/1000 ).up();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
266
|
const queryUrl = '?intentName='+ querystring.encode(xmlAttributes.intentName) + "&previousIntentTimestamp="+Date.now();
|
|
271
267
|
gather.att("action", this.BASE_URL + '/nextblock/' + xmlAttributes.callSid + queryUrl)
|
|
272
268
|
.att("method", "POST")
|
|
273
269
|
.att("language", xmlAttributes.voiceLanguage)
|
|
270
|
+
.att('speechTimeout', "auto")
|
|
274
271
|
|
|
272
|
+
if(xmlAttributes && xmlAttributes.noInputTimeout){
|
|
273
|
+
gather.att("timeout", xmlAttributes.noInputTimeout/1000 ).up();
|
|
274
|
+
}
|
|
275
|
+
if(xmlAttributes && xmlAttributes.incompleteSpeechTimeout){
|
|
276
|
+
gather.att("speechTimeout", xmlAttributes.incompleteSpeechTimeout/1000 ).up();
|
|
277
|
+
}
|
|
275
278
|
|
|
276
279
|
const prompt = this.promptVXML(gather, message, xmlAttributes);
|
|
277
280
|
|
|
278
281
|
const handleNoInputNoMatchQuery = await this.handleNoInputNoMatch(rootEle, message, xmlAttributes);
|
|
279
282
|
if(handleNoInputNoMatchQuery && handleNoInputNoMatchQuery.queryNoInput){
|
|
280
|
-
rootEle.ele("Redirect", {}, this.BASE_URL + '/handle/' + xmlAttributes.callSid + '/no_input?'+ handleNoInputNoMatchQuery.queryNoInput)
|
|
283
|
+
rootEle.ele("Redirect", {method: "POST"}, this.BASE_URL + '/handle/' + xmlAttributes.callSid + '/no_input?'+ handleNoInputNoMatchQuery.queryNoInput)
|
|
281
284
|
}
|
|
282
285
|
|
|
283
286
|
|
|
@@ -355,7 +358,7 @@ class TiledeskTwilioTranslator {
|
|
|
355
358
|
|
|
356
359
|
const handleNoInputNoMatchQuery = await this.handleNoInputNoMatch(rootEle, message, xmlAttributes);
|
|
357
360
|
if(handleNoInputNoMatchQuery && handleNoInputNoMatchQuery.queryNoInput){
|
|
358
|
-
rootEle.ele("Redirect", {}, this.BASE_URL + '/handle/' + xmlAttributes.callSid + '/no_input?'+ handleNoInputNoMatchQuery.queryNoInput)
|
|
361
|
+
rootEle.ele("Redirect", {method: "POST"}, this.BASE_URL + '/handle/' + xmlAttributes.callSid + '/no_input?'+ handleNoInputNoMatchQuery.queryNoInput)
|
|
359
362
|
}
|
|
360
363
|
|
|
361
364
|
//.ele('disconnect')
|