@tiledesk/tiledesk-voice-twilio-connector 0.1.16-rc3 → 0.1.16

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
@@ -84,11 +84,11 @@ router.get("/", async (req, res) => {
84
84
 
85
85
  // TILEDESK WEBHOOK: message from tiledesk to user (chatbot/agent messagges)
86
86
  router.post("/tiledesk", async (req, res) => {
87
- winston.debug("(vxml) Message received from Tiledesk in projectID: "+ req.body.payload.id_project + ' ---- and text: '+req.body.payload.text )
87
+ winston.debug("(voice) Message received from Tiledesk in projectID: "+ req.body.payload.id_project + ' ---- and text: '+req.body.payload.text )
88
88
  let tiledeskMessage = req.body.payload
89
89
  let project_id = tiledeskMessage.id_project
90
90
 
91
- //const CONTENT_KEY = "vxml-" + project_id;
91
+ //const CONTENT_KEY = "voice-" + project_id;
92
92
  //let settings = await db.get(CONTENT_KEY)
93
93
 
94
94
  const tdChannel = new TiledeskChannel({
@@ -108,7 +108,7 @@ router.post("/tiledesk", async (req, res) => {
108
108
 
109
109
  await tdChannel.addMessageToQueue(tiledeskMessage)
110
110
 
111
- res.send("(vxml) Message received from Voice VXML Proxy");
111
+ res.send("(voice) Message received from Voice Twilio Proxy");
112
112
 
113
113
 
114
114
  });
@@ -165,7 +165,7 @@ router.post('/webhook/:id_project', async (req, res) => {
165
165
 
166
166
 
167
167
  //GET AND SAVE GPT-KET IF
168
- let integrations = []
168
+ let integrations = [], publicKey = false;
169
169
  let key = await integrationService.getKeyFromIntegrations(project_id, 'openai', settings.token)
170
170
  if (!key) {
171
171
  winston.debug("(voice) - Key not found in Integrations. Searching in kb settings...");
@@ -174,8 +174,10 @@ router.post('/webhook/:id_project', async (req, res) => {
174
174
  if (!key) {
175
175
  winston.debug("(voice) - Retrieve public gptkey")
176
176
  key = GPT_KEY;
177
+ publicKey = true;
178
+
177
179
  }
178
- integrations.push({type: 'openai', key: key})
180
+ integrations.push({type: 'openai', key: key, publicKey: publicKey})
179
181
 
180
182
  //save data to redis
181
183
  let session_data = {
@@ -208,7 +210,8 @@ router.post('/webhook/:id_project', async (req, res) => {
208
210
  ... req.query //send all attributes back to chatbot
209
211
  }
210
212
  },
211
- channel: { name: CHANNEL_NAME }
213
+ channel: { name: CHANNEL_NAME },
214
+ departmentid: settings.department_id
212
215
  };
213
216
 
214
217
  let message = await tdChannel.send(tiledeskMessage, user.token, conversation_id)
@@ -241,8 +244,8 @@ router.post('/webhook/:id_project', async (req, res) => {
241
244
 
242
245
  router.post('/nextblock/:callSid/', async(req, res) => {
243
246
  let start_call = new Date()
244
- winston.debug("(vxml) called POST /nextblock ", req.body);
245
- winston.debug("(vxml) called POST /nextblock query ", req.query);
247
+ winston.debug("(voice) called POST /nextblock ", req.body);
248
+ winston.debug("(voice) called POST /nextblock query ", req.query);
246
249
  console.log('/nextblock at: ', new Date(), 'with text:', req.body.SpeechResult)
247
250
 
248
251
  let usertext = req.body.SpeechResult;
@@ -398,8 +401,8 @@ async function getMessage(callSid, from, project_id, conversation_id){
398
401
  router.post('/speechresult/:callSid', async (req, res) => {
399
402
 
400
403
  let start_call = new Date();
401
- winston.verbose("(vxml) called POST /speechresult ", req.body);
402
- winston.verbose("(vxml) called POST /speechresult query ", req.query);
404
+ winston.verbose("(voice) called POST /speechresult ", req.body);
405
+ winston.verbose("(voice) called POST /speechresult query ", req.query);
403
406
  console.log('/speechresult at: ', new Date(), 'with text:', req.body.SpeechResult)
404
407
 
405
408
  let usertext = req.body.SpeechResult;
@@ -440,7 +443,7 @@ router.post('/speechresult/:callSid', async (req, res) => {
440
443
  uploadService: uploadService
441
444
  });
442
445
 
443
- winston.verbose("(vxml) usertext "+usertext);
446
+ winston.verbose("(voice) usertext "+usertext);
444
447
  let message = {};
445
448
  if(usertext){
446
449
  let tiledeskMessage= {
@@ -528,8 +531,8 @@ router.post('/menublock/:callSid', async (req, res) => {
528
531
  message_text = menu_choice.toString(); //.replace(/(\d)/g, '$1 '); //convert number to string and then add a space after each number
529
532
  }
530
533
 
531
- winston.debug("(vxml) button menu: ", button);
532
- winston.debug("(vxml) message_text menu: "+ message_text);
534
+ winston.debug("(voice) button menu: ", button);
535
+ winston.debug("(voice) message_text menu: "+ message_text);
533
536
 
534
537
 
535
538
  let sessionInfo;
@@ -666,7 +669,7 @@ router.post('/handle/:callSid/:event', async (req, res) => {
666
669
 
667
670
  // convert response to vxml
668
671
  let messageToVXML = await tdTranslator.toVXML(message, callSid, vxmlAttributes,sessionInfo)
669
- winston.debug("(vxml) VXML to SEND: "+ messageToVXML);
672
+ winston.debug("(voice) VXML to SEND: "+ messageToVXML);
670
673
 
671
674
  res.set('Content-Type', 'text/xml');
672
675
  res.status(200).send(messageToVXML);
@@ -771,7 +774,7 @@ router.post('/event/:callSid/:event', async(req, res)=> {
771
774
 
772
775
  // convert response to vxml
773
776
  let messageToVXML = await tdTranslator.toVXML(message, callSid, vxmlAttributes, sessionInfo)
774
- winston.debug("(vxml) VXML to SEND: "+ messageToVXML);
777
+ winston.debug("(voice) VXML to SEND: "+ messageToVXML);
775
778
 
776
779
  res.set('Content-Type', 'text/xml');
777
780
  res.status(200).send(messageToVXML);
@@ -917,6 +920,15 @@ router.post('/record/:callSid/',async (req, res) => {
917
920
 
918
921
  //SPEECH TO TEXT
919
922
  let key = sessionInfo.integrations.find((el => el.type === VOICE_PROVIDER.OPEN_AI))?.key
923
+ let publicKey = sessionInfo.integrations.find((el => el.type === VOICE_PROVIDER.OPEN_AI))?.publicKey
924
+ //check quotes if user is using public GPT_KEY
925
+ if(publicKey){
926
+ let keep_going = await aiService.checkQuoteAvailability(project_id, user.token);
927
+ if(!keep_going){
928
+ //no toke is available
929
+ }
930
+ }
931
+
920
932
  let textMessage = await aiService.speechToText(audioFileUrl, vxmlAttributes.STT_MODEL, key).catch((err)=>{
921
933
  console.log('errr while transcript', err.response?.data)
922
934
  })
@@ -960,7 +972,7 @@ router.post('/record/:callSid/',async (req, res) => {
960
972
 
961
973
  // convert response to vxml
962
974
  let messageToVXML = await tdTranslator.toVXML(message, callSid, vxmlAttributes, sessionInfo)
963
- winston.debug("(vxml) VXML to SEND: "+ messageToVXML);
975
+ winston.debug("(voice) VXML to SEND: "+ messageToVXML);
964
976
 
965
977
  res.set('Content-Type', 'text/xml');
966
978
  res.status(200).send(messageToVXML);
@@ -978,7 +990,7 @@ router.get('/addon/transcript', async (req, res) => {
978
990
 
979
991
  /** --> only for test purpose <-- **/
980
992
  router.get('/test', async (req, res) => {
981
- winston.verbose("(vxml) called GET /test" , req.query);
993
+ winston.verbose("(voice) called GET /test" , req.query);
982
994
 
983
995
  let project_id = req.query.id_project;
984
996
  let callSid = req.body.CallSid;
@@ -1236,7 +1248,8 @@ async function startApp(settings, callback) {
1236
1248
 
1237
1249
  //init Services
1238
1250
  aiService = new AiService({
1239
- OPENAI_ENDPOINT: OPENAI_ENDPOINT
1251
+ OPENAI_ENDPOINT: OPENAI_ENDPOINT,
1252
+ API_URL: API_URL
1240
1253
  })
1241
1254
  integrationService = new IntegrationService({
1242
1255
  API_URL: API_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-voice-twilio-connector",
3
- "version": "0.1.16-rc3",
3
+ "version": "0.1.16",
4
4
  "description": "Tiledesk VOICE Twilio connector",
5
5
  "license": "MIT",
6
6
  "author": "Gabriele Panico",
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- CHANNEL_NAME: 'voice-twilio',
2
+ CHANNEL_NAME: 'voice_twilio',
3
3
  TYPE_MESSAGE: {
4
4
  TEXT : 'text',
5
5
  IMAGE : 'image',
@@ -15,8 +15,12 @@ class AiService {
15
15
  if (!config.OPENAI_ENDPOINT) {
16
16
  throw new Error("[AiService] config.OPENAI_ENDPOINT is mandatory");
17
17
  }
18
+ if (!config.API_URL) {
19
+ throw new Error("[AiService] config.API_URL is mandatory");
20
+ }
18
21
 
19
22
  this.OPENAI_ENDPOINT = config.OPENAI_ENDPOINT;
23
+ this.API_URL = config.API_URL;
20
24
 
21
25
  }
22
26
 
@@ -87,6 +91,34 @@ class AiService {
87
91
 
88
92
  }
89
93
 
94
+ async checkQuoteAvailability(projectId, token) {
95
+
96
+ winston.debug("[AiService] checkQuoteAvailability for project: "+ projectId);
97
+
98
+ return new Promise((resolve, reject) => {
99
+
100
+ axios({
101
+ url: this.API_URL + "/" + projectId + "/quotes/tokens",
102
+ headers: {
103
+ 'Content-Type': 'application/json',
104
+ 'Authorization': token
105
+ },
106
+ method: 'GET'
107
+ }).then((resbody) => {
108
+ if (resbody && resbody.isAvailable === true) {
109
+ resolve(true)
110
+ } else {
111
+ resolve(false)
112
+ }
113
+ }).catch((err) => {
114
+ reject(err);
115
+ })
116
+
117
+ })
118
+ }
119
+
120
+
121
+
90
122
 
91
123
  }
92
124