@tiledesk/tiledesk-voice-twilio-connector 0.1.16-rc2 → 0.1.16-rc4
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 +29 -8
- package/package.json +1 -1
- package/tiledesk/constants.js +1 -1
- package/tiledesk/services/AiService.js +32 -0
- package/tiledesk/services/speech_voice-twilio-393892661914_CAdabf454351c9d99f0e80ff0eef820de1.wav +0 -0
- package/tiledesk/services/speech_voice-twilio-393892661914_CAa837741db2a05b0cfa946d034c0c4048.wav +0 -0
- package/tiledesk/services/speech_voice-twilio-393892661914_CAc0185fb5e550aa1e420c7076c8f9dc6c.wav +0 -0
- package/tiledesk/services/speech_voice-twilio-393892661914_CAcb69e06f3ea491f99778d58ddce7d70d.wav +0 -0
package/index.js
CHANGED
|
@@ -75,6 +75,8 @@ let time = null;
|
|
|
75
75
|
const utilsMess = require('./tiledesk/utils-message.js')
|
|
76
76
|
const TYPE_MESSAGE = require('./tiledesk/constants').TYPE_MESSAGE
|
|
77
77
|
|
|
78
|
+
let messageTimeout = null;
|
|
79
|
+
|
|
78
80
|
router.get("/", async (req, res) => {
|
|
79
81
|
res.send("Welcome to Tiledesk-voice-twilio connector");
|
|
80
82
|
});
|
|
@@ -163,7 +165,7 @@ router.post('/webhook/:id_project', async (req, res) => {
|
|
|
163
165
|
|
|
164
166
|
|
|
165
167
|
//GET AND SAVE GPT-KET IF
|
|
166
|
-
let integrations = []
|
|
168
|
+
let integrations = [], publicKey = false;
|
|
167
169
|
let key = await integrationService.getKeyFromIntegrations(project_id, 'openai', settings.token)
|
|
168
170
|
if (!key) {
|
|
169
171
|
winston.debug("(voice) - Key not found in Integrations. Searching in kb settings...");
|
|
@@ -172,8 +174,10 @@ router.post('/webhook/:id_project', async (req, res) => {
|
|
|
172
174
|
if (!key) {
|
|
173
175
|
winston.debug("(voice) - Retrieve public gptkey")
|
|
174
176
|
key = GPT_KEY;
|
|
177
|
+
publicKey = true;
|
|
178
|
+
|
|
175
179
|
}
|
|
176
|
-
integrations.push({type: 'openai', key: key})
|
|
180
|
+
integrations.push({type: 'openai', key: key, publicKey: publicKey})
|
|
177
181
|
|
|
178
182
|
//save data to redis
|
|
179
183
|
let session_data = {
|
|
@@ -252,9 +256,6 @@ router.post('/nextblock/:callSid/', async(req, res) => {
|
|
|
252
256
|
let from, to;
|
|
253
257
|
|
|
254
258
|
let redis_data = await redis_client.get('tiledesk:vxml:'+callSid+':session');
|
|
255
|
-
console.log('redissssss', redis_client)
|
|
256
|
-
console.log('redissssss 2', 'tiledesk:vxml:'+callSid+':session')
|
|
257
|
-
console.log('redissssss 3', redis_data)
|
|
258
259
|
//let redis_data = await redis_client.hGetAll('tiledesk:vxml:'+callId);
|
|
259
260
|
if (!redis_data) {
|
|
260
261
|
return res.status(500).send({ success: "false", message: "Can't retrive data for callSid ->" + callSid });
|
|
@@ -288,7 +289,7 @@ router.post('/nextblock/:callSid/', async(req, res) => {
|
|
|
288
289
|
|
|
289
290
|
|
|
290
291
|
let message = await new Promise(async (resolve, reject) => {
|
|
291
|
-
winston.debug('******* user text -->'
|
|
292
|
+
winston.debug('******* user text -->'+ usertext)
|
|
292
293
|
if(usertext === '' || !usertext){
|
|
293
294
|
|
|
294
295
|
let message = await getMessage(callSid, from, project_id, conversation_id)
|
|
@@ -381,7 +382,7 @@ async function getMessage(callSid, from, project_id, conversation_id){
|
|
|
381
382
|
let delayTime = await voiceChannel.getNextDelayTimeForCallId(callSid)
|
|
382
383
|
await voiceChannel.saveDelayIndexForCallId(callSid)
|
|
383
384
|
winston.debug('(checkQueue FN ) RECALL checkQueue FN in: '+ delayTime + '[ms]')
|
|
384
|
-
setTimeout(checkQueue, delayTime);
|
|
385
|
+
messageTimeout = setTimeout(checkQueue, delayTime);
|
|
385
386
|
|
|
386
387
|
}catch(err){
|
|
387
388
|
winston.debug("Error occurred while check message in queue: ", err);
|
|
@@ -681,6 +682,11 @@ router.post('/event/:callSid/:event', async(req, res)=> {
|
|
|
681
682
|
winston.debug("(voice) called POST /event query" , req.query);
|
|
682
683
|
winston.debug("(voice) called POST /event body" , req.body);
|
|
683
684
|
|
|
685
|
+
//clear getMessage function timeout
|
|
686
|
+
if(messageTimeout){
|
|
687
|
+
clearTimeout(messageTimeout)
|
|
688
|
+
}
|
|
689
|
+
|
|
684
690
|
let event = req.params.event;
|
|
685
691
|
let callSid = req.params.callSid;
|
|
686
692
|
let currentIntentName = req.query.intentName;
|
|
@@ -781,6 +787,11 @@ router.post('/twilio/status',async (req, res) => {
|
|
|
781
787
|
let event = req.body.CallStatus;
|
|
782
788
|
let callSid = req.body.CallSid;
|
|
783
789
|
|
|
790
|
+
//clear getMessage function timeout
|
|
791
|
+
if(messageTimeout){
|
|
792
|
+
clearTimeout(messageTimeout)
|
|
793
|
+
}
|
|
794
|
+
|
|
784
795
|
let sessionInfo;
|
|
785
796
|
let project_id, conversation_id, user;
|
|
786
797
|
let from, to;
|
|
@@ -908,6 +919,15 @@ router.post('/record/:callSid/',async (req, res) => {
|
|
|
908
919
|
|
|
909
920
|
//SPEECH TO TEXT
|
|
910
921
|
let key = sessionInfo.integrations.find((el => el.type === VOICE_PROVIDER.OPEN_AI))?.key
|
|
922
|
+
let publicKey = sessionInfo.integrations.find((el => el.type === VOICE_PROVIDER.OPEN_AI))?.publicKey
|
|
923
|
+
//check quotes if user is using public GPT_KEY
|
|
924
|
+
if(publicKey){
|
|
925
|
+
let keep_going = await aiService.checkQuoteAvailability(project_id, user.token);
|
|
926
|
+
if(!keep_going){
|
|
927
|
+
//no toke is available
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
|
|
911
931
|
let textMessage = await aiService.speechToText(audioFileUrl, vxmlAttributes.STT_MODEL, key).catch((err)=>{
|
|
912
932
|
console.log('errr while transcript', err.response?.data)
|
|
913
933
|
})
|
|
@@ -1227,7 +1247,8 @@ async function startApp(settings, callback) {
|
|
|
1227
1247
|
|
|
1228
1248
|
//init Services
|
|
1229
1249
|
aiService = new AiService({
|
|
1230
|
-
OPENAI_ENDPOINT: OPENAI_ENDPOINT
|
|
1250
|
+
OPENAI_ENDPOINT: OPENAI_ENDPOINT,
|
|
1251
|
+
API_URL: API_URL
|
|
1231
1252
|
})
|
|
1232
1253
|
integrationService = new IntegrationService({
|
|
1233
1254
|
API_URL: API_URL,
|
package/package.json
CHANGED
package/tiledesk/constants.js
CHANGED
|
@@ -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
|
|
package/tiledesk/services/speech_voice-twilio-393892661914_CAdabf454351c9d99f0e80ff0eef820de1.wav
ADDED
|
Binary file
|
package/tiledesk/services/speech_voice-twilio-393892661914_CAa837741db2a05b0cfa946d034c0c4048.wav
DELETED
|
Binary file
|