@tiledesk/tiledesk-voice-twilio-connector 0.1.16-rc3 → 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 CHANGED
@@ -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 = {
@@ -917,6 +919,15 @@ router.post('/record/:callSid/',async (req, res) => {
917
919
 
918
920
  //SPEECH TO TEXT
919
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
+
920
931
  let textMessage = await aiService.speechToText(audioFileUrl, vxmlAttributes.STT_MODEL, key).catch((err)=>{
921
932
  console.log('errr while transcript', err.response?.data)
922
933
  })
@@ -1236,7 +1247,8 @@ async function startApp(settings, callback) {
1236
1247
 
1237
1248
  //init Services
1238
1249
  aiService = new AiService({
1239
- OPENAI_ENDPOINT: OPENAI_ENDPOINT
1250
+ OPENAI_ENDPOINT: OPENAI_ENDPOINT,
1251
+ API_URL: API_URL
1240
1252
  })
1241
1253
  integrationService = new IntegrationService({
1242
1254
  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-rc4",
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