@tiledesk/tiledesk-tybot-connector 0.2.90 → 0.2.91-rc2

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/CHANGELOG.md CHANGED
@@ -5,13 +5,6 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
- # v0.2.90
9
- - Added voice flow attributes: dnis, callId, ani
10
-
11
- # v0.2.89
12
- - Added convertToNumber to operations in setAttribute
13
- - Added setAttributeV2 test
14
-
15
8
  # v0.2.88
16
9
  - Added DirContactUpdate (aka LeadUpdate). No test case added for LeadUpdate. Only testable with a validation test.
17
10
  - Fixed: Attribute parameters userFullname & userEmail now are able to "bypass" the request.lead not correctly updating on the same conversation. If updated in the flow (through LeadUpdate action), they will maintain their own value through the current conversation flow.
@@ -435,15 +435,14 @@ class TiledeskChatbotUtil {
435
435
  let fullName = message.senderFullname;
436
436
  if (fullName.trim() === chatbot_name) {
437
437
  fullName = "bot:" + fullName;
438
- }
439
- else {
438
+ } else {
440
439
  fullName = "user:" + fullName;
441
440
  }
442
441
  return "<" + fullName + ">";
443
442
  }
444
443
  }
445
444
 
446
- static transcriptJSON(transcript) {
445
+ static async transcriptJSON(transcript) {
447
446
  const regexp = /(<.*>)/gm;
448
447
  const parts = transcript.split(regexp);
449
448
  // console.log("parts:", parts);
@@ -715,7 +714,7 @@ class TiledeskChatbotUtil {
715
714
  const value_type = typeof value;
716
715
  //if (projectId === "641864da99c1fb00131ba495") {console.log("641864da99c1fb00131ba495 > importing payload parameter:", key, "value:", value, "type:", value_type);}
717
716
  //await chatbot.addParameter(key, String(value));
718
- // console.log("Adding from message.attributes:", key, "->", value);
717
+ console.log("Adding from message.attributes:", key, "->", value);
719
718
  await chatbot.addParameter(key, value);
720
719
  }
721
720
  }
@@ -723,17 +722,6 @@ class TiledeskChatbotUtil {
723
722
  console.error("Error importing message payload in request variables:", err);
724
723
  }
725
724
  }
726
-
727
- // voice-vxml attributes
728
- if (message.attributes.dnis) {
729
- await chatbot.addParameter("dnis", message.attributes.dnis);
730
- }
731
- if (message.attributes.callId) {
732
- await chatbot.addParameter("callId", message.attributes.callId);
733
- }
734
- if (message.attributes.ani) {
735
- await chatbot.addParameter("ani", message.attributes.ani);
736
- }
737
725
  }
738
726
 
739
727
  const _bot = chatbot.bot; // aka FaqKB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.90",
3
+ "version": "0.2.91-rc2",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,6 +3,8 @@ const { TiledeskChatbot } = require("../../models/TiledeskChatbot");
3
3
  const { Filler } = require("../Filler");
4
4
  let https = require("https");
5
5
  const { DirIntent } = require("./DirIntent");
6
+ const { TiledeskChatbotConst } = require("../../models/TiledeskChatbotConst");
7
+ const { TiledeskChatbotUtil } = require("../../models/TiledeskChatbotUtil");
6
8
  require('dotenv').config();
7
9
 
8
10
  class DirGptTask {
@@ -12,6 +14,7 @@ class DirGptTask {
12
14
  throw new Error('context object is mandatory');
13
15
  }
14
16
  this.context = context;
17
+ this.chatbot = this.context.chatbot;
15
18
  this.tdcache = this.context.tdcache;
16
19
  this.requestId = this.context.requestId;
17
20
  this.intentDir = new DirIntent(context);
@@ -47,6 +50,7 @@ class DirGptTask {
47
50
  let falseIntent = action.falseIntent;
48
51
  let trueIntentAttributes = action.trueIntentAttributes;
49
52
  let falseIntentAttributes = action.falseIntentAttributes;
53
+ let transcript;
50
54
 
51
55
  if (this.log) {
52
56
  console.log("DirGptTask trueIntent", trueIntent)
@@ -62,6 +66,7 @@ class DirGptTask {
62
66
  if (!action.question || action.question === '') {
63
67
  console.error("Error: DirGptTask question attribute is mandatory. Executing condition false...")
64
68
  if (falseIntent) {
69
+ await this.chatbot.addParameter("flowError", "GPT Error: question attribute is undefined");
65
70
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
66
71
  callback(true);
67
72
  return;
@@ -92,6 +97,18 @@ class DirGptTask {
92
97
  console.log("DirGptTask temperature: ", temperature);
93
98
  }
94
99
 
100
+ if (action.history) {
101
+ let transcript_string = await TiledeskChatbot.getParameterStatic(
102
+ this.context.tdcache,
103
+ this.context.requestId,
104
+ TiledeskChatbotConst.REQ_TRANSCRIPT_KEY);
105
+ if (this.log) { console.log("DirGptTask transcript string: ", transcript_string) }
106
+
107
+ transcript = await TiledeskChatbotUtil.transcriptJSON(transcript_string);
108
+ if (this.log) { console.log("DirGptTask transcript: ", transcript) }
109
+ }
110
+
111
+
95
112
  const server_base_url = process.env.API_ENDPOINT || process.env.API_URL;
96
113
  const openai_url = process.env.OPENAI_ENDPOINT + "/chat/completions";
97
114
  if (this.log) {
@@ -115,6 +132,7 @@ class DirGptTask {
115
132
  console.error("DirGptTask gptkey is mandatory");
116
133
  await this.#assignAttributes(action, answer);
117
134
  if (falseIntent) {
135
+ await this.chatbot.addParameter("flowError", "GPT Error: gpt apikey is undefined");
118
136
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
119
137
  callback(true);
120
138
  return;
@@ -134,22 +152,39 @@ class DirGptTask {
134
152
 
135
153
  let json = {
136
154
  model: action.model,
137
- messages: [
138
- {
139
- role: "user",
140
- content: filled_question
141
- }
142
- ],
155
+ messages: [],
156
+ // messages: [
157
+ // {
158
+ // role: "user",
159
+ // content: filled_question
160
+ // }
161
+ // ],
143
162
  max_tokens: action.max_tokens,
144
- temperature: action.temperature
163
+ temperature: action.temperature,
145
164
  }
146
165
 
147
166
  let message = { role: "", content: "" };
167
+
148
168
  if (action.context) {
149
- message.role = "system";
150
- message.content = filled_context;
151
- json.messages.unshift(message);
169
+ let message = {
170
+ role: "system",
171
+ content: filled_context
172
+ }
173
+ json.messages.push(message);
152
174
  }
175
+
176
+ if (transcript) {
177
+ transcript.forEach(msg => {
178
+ if (!msg.content.startsWith('/')) {
179
+ let message = {
180
+ role: msg.role,
181
+ content: msg.content
182
+ }
183
+ json.messages.push(message)
184
+ }
185
+ })
186
+ }
187
+
153
188
  if (this.log) { console.log("DirGptTask json: ", json) }
154
189
 
155
190
  const HTTPREQUEST = {
@@ -167,10 +202,11 @@ class DirGptTask {
167
202
  if (err) {
168
203
  if (this.log) {
169
204
  console.error("(httprequest) DirGptTask openai err:", err);
170
- console.error("(httprequest) DirGptTask openai err:", err.response.data);
205
+ console.error("(httprequest) DirGptTask openai err:", err.response?.data?.error?.message);
171
206
  }
172
207
  await this.#assignAttributes(action, answer);
173
208
  if (falseIntent) {
209
+ await this.chatbot.addParameter("flowError", "GPT Error: " + err.response?.data?.error?.message);
174
210
  await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
175
211
  callback(true);
176
212
  return;