@tiledesk/tiledesk-voice-twilio-connector 0.1.2 → 0.1.7

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
@@ -36,10 +36,11 @@ var redis = require('redis')
36
36
  var redis_client;
37
37
 
38
38
  //UTILS
39
- const utils_message = require('./tiledesk/utils-message.js')
40
39
  const CHANNEL_NAME = require('./tiledesk/constants').CHANNEL_NAME
41
40
  const TYPE_MESSAGE = require('./tiledesk/constants').TYPE_MESSAGE
42
41
  const CALL_STATUS = require('./tiledesk/constants').CALL_STATUS
42
+ const VOICE_NAME = require('./tiledesk/constants').VOICE_NAME
43
+ const VOICE_LANGUAGE = require('./tiledesk/constants').VOICE_LANGUAGE
43
44
  const utils = require('./tiledesk/utils.js')
44
45
 
45
46
  let API_URL = null;
@@ -101,8 +102,8 @@ router.post('/webhook/:id_project', async (req, res) => {
101
102
  }
102
103
 
103
104
  let vxmlAttributes = {
104
- voiceName: "Polly.Bianca",
105
- voiceLanguage: "it-IT",
105
+ voiceName: VOICE_NAME,
106
+ voiceLanguage: VOICE_LANGUAGE,
106
107
  callSid: callSid
107
108
  };
108
109
 
@@ -208,8 +209,8 @@ router.post('/nextblock/:callSid/', async(req, res) => {
208
209
  user = sessionInfo.user;
209
210
 
210
211
  let vxmlAttributes = {
211
- voiceName: "Polly.Bianca",
212
- voiceLanguage: "it-IT",
212
+ voiceName: VOICE_NAME,
213
+ voiceLanguage: VOICE_LANGUAGE,
213
214
  callSid: callSid,
214
215
  };
215
216
 
@@ -381,8 +382,8 @@ router.post('/menublock/:callSid', async (req, res) => {
381
382
  user = sessionInfo.user;
382
383
 
383
384
  let vxmlAttributes = {
384
- voiceName: "Polly.Bianca",
385
- voiceLanguage: "it-IT",
385
+ voiceName: VOICE_NAME,
386
+ voiceLanguage: VOICE_LANGUAGE,
386
387
  callSid: callSid,
387
388
  };
388
389
 
@@ -448,8 +449,8 @@ router.post('/handle/:callSid/:event', async (req, res) => {
448
449
  user = sessionInfo.user;
449
450
 
450
451
  let vxmlAttributes = {
451
- voiceName: "Polly.Bianca",
452
- voiceLanguage: "it-IT",
452
+ voiceName: VOICE_NAME,
453
+ voiceLanguage: VOICE_LANGUAGE,
453
454
  callSid: callSid,
454
455
  };
455
456
 
@@ -472,7 +473,12 @@ router.post('/handle/:callSid/:event', async (req, res) => {
472
473
  channel: { name: CHANNEL_NAME },
473
474
  attributes: {
474
475
  type: 'info',
475
- action: button_action
476
+ action: button_action,
477
+ payload: {
478
+ event: event,
479
+ lastBlock: previousIntentName,
480
+ lastTimestamp: Date.now()
481
+ }
476
482
  }
477
483
  };
478
484
  let tdMessage = await tdChannel.send(tiledeskMessage, user.token, conversation_id);
@@ -521,8 +527,8 @@ router.post('/event/:callSid/:event', async(req, res)=> {
521
527
  user = sessionInfo.user;
522
528
 
523
529
  let vxmlAttributes = {
524
- voiceName: "Polly.Bianca",
525
- voiceLanguage: "it-IT",
530
+ voiceName: VOICE_NAME,
531
+ voiceLanguage: VOICE_LANGUAGE,
526
532
  callSid: callSid,
527
533
  };
528
534
 
@@ -613,8 +619,8 @@ router.post('/twilio/status',async (req, res) => {
613
619
  user = sessionInfo.user;
614
620
 
615
621
  let vxmlAttributes = {
616
- voiceName: "Polly.Bianca",
617
- voiceLanguage: "it-IT",
622
+ voiceName: VOICE_NAME,
623
+ voiceLanguage: VOICE_LANGUAGE,
618
624
  callSid: callSid,
619
625
  };
620
626
 
@@ -693,8 +699,8 @@ router.post('/record/:callSid/',async (req, res) => {
693
699
  user = sessionInfo.user;
694
700
 
695
701
  let vxmlAttributes = {
696
- voiceName: "Polly.Bianca",
697
- voiceLanguage: "it-IT",
702
+ voiceName: VOICE_NAME,
703
+ voiceLanguage: VOICE_LANGUAGE,
698
704
  callSid: callSid,
699
705
  };
700
706
 
@@ -709,9 +715,10 @@ router.post('/record/:callSid/',async (req, res) => {
709
715
  });
710
716
 
711
717
 
712
- let audioFileUrl = req.body.RecordingUrl
718
+ //let audioFileUrl = req.body.RecordingUrl
719
+ let audioFileUrl = "https://api.twilio.com/2010-04-01/Accounts/AC7ee57312ad4e367a114028fb5743326e/Recordings/RE32355c1a7f7465db7a96b496ddb49e09"
713
720
  let textMessage = await tdChannel.speechToText(audioFileUrl, 'whisper-1')
714
- winston.debug('(voice) Message captured after STT -->', textMessage)
721
+ winston.debug('(voice) Message captured after STT -->'+ textMessage)
715
722
 
716
723
  if(!textMessage){
717
724
  //case NO_INPUT
@@ -755,6 +762,14 @@ router.post('/record/:callSid/',async (req, res) => {
755
762
  })
756
763
 
757
764
 
765
+ router.get('/addon/transcript', async (req, res) => {
766
+ winston.info("(vxml) called GET /transcript query-->" , req.query);
767
+ winston.info("(vxml) called GET /transcript body -->" , req.body);
768
+
769
+ res.status(200).send('ok');
770
+
771
+ });
772
+
758
773
  /** --> only for test purpose <-- **/
759
774
  router.get('/test', async (req, res) => {
760
775
  winston.info("(vxml) called GET /test" , req.query);
@@ -846,7 +861,7 @@ router.get('/test', async (req, res) => {
846
861
  type: 'wait',
847
862
  time: 0
848
863
  },
849
- /*{
864
+ {
850
865
  type: 'settings',
851
866
  subType: 'blind_transfer',
852
867
  settings: {
@@ -855,7 +870,7 @@ router.get('/test', async (req, res) => {
855
870
  falseIntent: "#falseIntenttt",
856
871
  trueIntent: "#trueIntennt"
857
872
  }
858
- }*/
873
+ }
859
874
  /*{
860
875
  type: 'settings',
861
876
  subType: 'dtmf_form',
@@ -865,7 +880,7 @@ router.get('/test', async (req, res) => {
865
880
  terminators: "#"
866
881
  }
867
882
  }*/
868
- {
883
+ /*{
869
884
  type: 'settings',
870
885
  subType: 'speech_form',
871
886
  settings: {
@@ -873,15 +888,15 @@ router.get('/test', async (req, res) => {
873
888
  noInputTimeout: 2000,
874
889
  incompleteSpeechTimeout: 2000
875
890
  }
876
- }
891
+ }*/
877
892
  ]
878
893
  }
879
894
  }
880
895
 
881
896
 
882
897
  let vxmlAttributes = {
883
- voiceName: "Polly.Bianca",
884
- voiceLanguage: "it-IT",
898
+ voiceName: VOICE_NAME,
899
+ voiceLanguage: VOICE_LANGUAGE,
885
900
  callSid: callSid
886
901
  };
887
902
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-voice-twilio-connector",
3
- "version": "0.1.2",
3
+ "version": "0.1.7",
4
4
  "description": "Tiledesk VOICE Twilio connector",
5
5
  "license": "MIT",
6
6
  "author": "Gabriele Panico",
@@ -189,7 +189,7 @@ class TiledeskChannel {
189
189
  async speechToText(fileUrl, model){
190
190
 
191
191
  winston.debug("[TiledeskChannel] speechToText url: "+ fileUrl);
192
- const response = await axios({
192
+ /*const response = await axios({
193
193
  url: fileUrl,
194
194
  method: 'GET',
195
195
  responseType: 'stream',
@@ -198,20 +198,47 @@ class TiledeskChannel {
198
198
  return null;
199
199
  });
200
200
 
201
- if(!response){
201
+ if(!response){
202
202
  return null;
203
203
  }
204
204
 
205
+ */
205
206
 
207
+
208
+ const stream = await axios.get(fileUrl, {
209
+ responseType: 'arraybuffer'
210
+ }).catch((err) => {
211
+ winston.error("[TiledeskChannel] speechToText GET STREAM error: ", err);
212
+ return null;
213
+ })
214
+
215
+ const base64 = Buffer.from(stream.data, 'binary').toString('base64');
216
+ console.log('baseeeeeeee', base64)
217
+ return 'text'
218
+
219
+
220
+ /*
221
+ stream.on('data', data => {
222
+ console.log('stream data', data);
223
+ });
224
+
225
+ stream.on('end', () => {
226
+ console.log("stream done");
227
+ });
228
+ */
229
+
230
+ /*
206
231
  const formFile = new FormData();
207
- formFile.append("file", response.data, { filename: fileUrl.split('/').pop() + '.wav', contentType: 'audio/wav'});// Specifica il tipo MIME del file WAV});
232
+ formFile.append("file", stream.data, { filename: fileUrl.split('/').pop() + '.wav', contentType: 'audio/wav'});// Specifica il tipo MIME del file WAV});
208
233
  formFile.append("model", model);
209
234
 
210
- return axios({
235
+ console.log('dataaaaaaa', formFile)
236
+
237
+ return axios({
211
238
  url: "https://api.openai.com/v1/audio/transcriptions",
212
239
  headers: {
213
240
  'Content-Type': 'multipart/form-data',
214
- 'Authorization': "Bearer " + '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',
241
+ 'Authorization': "Bearer " + GPT_KEY,
215
242
  ...formFile.getHeaders(),
216
243
  },
217
244
  data: formFile,
@@ -223,6 +250,7 @@ class TiledeskChannel {
223
250
  winston.error("[TiledeskChannel] speechToText error: ", err);
224
251
  return null;
225
252
  })
253
+ */
226
254
  }
227
255
 
228
256
  /** ADD MESSAGE TO REDIS QUEUE **/
@@ -218,7 +218,7 @@ class TiledeskTwilioTranslator {
218
218
  return buttons;
219
219
  }
220
220
 
221
- /** DONE **/
221
+
222
222
  async delayVXMLConverter(rootEle, message, xmlAttributes){
223
223
  const command = message.attributes.commands[0]
224
224
  rootEle.ele("Redirect", {Method: "POST"}, this.BASE_URL + '/nextblock/' + xmlAttributes.callSid).up()
@@ -226,7 +226,7 @@ class TiledeskTwilioTranslator {
226
226
  return rootEle.end({ pretty: true });
227
227
  }
228
228
 
229
- /** DONE **/
229
+
230
230
  async playPromptVXMLConverter(rootEle, message, xmlAttributes){
231
231
 
232
232
  const prompt = this.promptVXML(rootEle, message, xmlAttributes);
@@ -28,6 +28,8 @@ module.exports = {
28
28
 
29
29
  },
30
30
  WAIT_BASE_DELAY_TIME: 250,
31
+ VOICE_NAME: 'Polly.Bianca',
32
+ VOICE_LANGUAGE: 'it-IT',
31
33
  CALL_STATUS: {
32
34
  INITIATED: 'initiated',
33
35
  RINGING: 'ringing',