@tiledesk/tiledesk-tybot-connector 0.4.2 → 0.5.0
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 +4 -0
- package/package.json +1 -1
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +3 -3
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV2.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirReplaceBotV3.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +34 -7
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -94,8 +94,8 @@ class DirAiPrompt {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
const
|
|
98
|
-
if (this.log) { console.log("DirAiPrompt
|
|
97
|
+
const AI_endpoint = process.env.AI_ENDPOINT
|
|
98
|
+
if (this.log) { console.log("DirAiPrompt AI_endpoint ", AI_endpoint); }
|
|
99
99
|
|
|
100
100
|
let key = await this.getKeyFromIntegrations(action.llm);
|
|
101
101
|
|
|
@@ -130,7 +130,7 @@ class DirAiPrompt {
|
|
|
130
130
|
if (this.log) { console.log("DirAiPrompt json: ", json) }
|
|
131
131
|
|
|
132
132
|
const HTTPREQUEST = {
|
|
133
|
-
url:
|
|
133
|
+
url: AI_endpoint + '/ask',
|
|
134
134
|
headers: {
|
|
135
135
|
'Content-Type': 'application/json'
|
|
136
136
|
},
|
|
@@ -34,10 +34,10 @@ class DirWebResponse {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
async go(action, callback) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
if (this.log) {
|
|
38
|
+
console.log("(DirWebResponse) action:", action);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
41
|
let requestAttributes = null;
|
|
42
42
|
if (this.tdcache) {
|
|
43
43
|
requestAttributes =
|
|
@@ -45,7 +45,7 @@ class DirWebResponse {
|
|
|
45
45
|
const filler = new Filler();
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
|
-
|
|
48
|
+
let status = action.status;
|
|
49
49
|
status = filler.fill(status, requestAttributes);
|
|
50
50
|
}
|
|
51
51
|
catch(e) {
|
|
@@ -54,16 +54,19 @@ class DirWebResponse {
|
|
|
54
54
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
const json = await this.getJsonFromAction(action, filler, requestAttributes)
|
|
57
58
|
let webResponse = {
|
|
58
59
|
status: status,
|
|
59
|
-
payload:
|
|
60
|
+
payload: json
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
const topic = `/webhooks/${this.requestId}`;
|
|
63
64
|
|
|
64
65
|
try {
|
|
65
66
|
this.tdcache.publish(topic, JSON.stringify(webResponse));
|
|
66
|
-
|
|
67
|
+
if (this.log) {
|
|
68
|
+
console.log("(DirWebResponse) Published webresponse to topic:", topic);
|
|
69
|
+
}
|
|
67
70
|
}
|
|
68
71
|
catch(e) {
|
|
69
72
|
console.error(e)
|
|
@@ -72,8 +75,32 @@ class DirWebResponse {
|
|
|
72
75
|
callback();
|
|
73
76
|
|
|
74
77
|
}
|
|
78
|
+
|
|
79
|
+
async getJsonFromAction(action, filler, requestAttributes) {
|
|
80
|
+
|
|
81
|
+
return new Promise( async (resolve, reject) => {
|
|
82
|
+
|
|
83
|
+
if (action.payload && action.bodyType == "json") {
|
|
84
|
+
let jsonBody = filler.fill(action.payload, requestAttributes);
|
|
85
|
+
try {
|
|
86
|
+
let json = JSON.parse(jsonBody);
|
|
87
|
+
resolve(json);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (this.log) { console.error("Error parsing webRequest jsonBody:", jsonBody, err) };
|
|
91
|
+
reject("Error parsing jsonBody");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
resolve(null);
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
75
100
|
}
|
|
76
101
|
|
|
102
|
+
|
|
103
|
+
|
|
77
104
|
/**
|
|
78
105
|
* A stub to send message to the "ext/botId" endpoint, hosted by tilebot on:
|
|
79
106
|
* /${TILEBOT_ROUTE}/ext/${botId}
|