@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 CHANGED
@@ -5,6 +5,10 @@
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ # v0.5.0
9
+ - added: AI_ENDPOINT env var
10
+ - added: ability to get 'none' as bodytype in webresponse
11
+
8
12
  # v0.4.2
9
13
  - bug-fixed: minor log fix
10
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -94,8 +94,8 @@ class DirAiPrompt {
94
94
  }
95
95
  }
96
96
 
97
- const llm_endpoint = process.env.KB_ENDPOINT_QA;
98
- if (this.log) { console.log("DirAiPrompt llm_endpoint ", llm_endpoint); }
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: llm_endpoint + '/ask',
133
+ url: AI_endpoint + '/ask',
134
134
  headers: {
135
135
  'Content-Type': 'application/json'
136
136
  },
@@ -76,7 +76,7 @@ class DirReplaceBotV2 {
76
76
  this.#myrequest(
77
77
  HTTPREQUEST, async (err, resbody) => {
78
78
  if (err) {
79
- console.log("DirReplaceBot error: ", err);
79
+ console.error("DirReplaceBot error: ", err);
80
80
  if (callback) {
81
81
  callback();
82
82
  return;
@@ -76,7 +76,7 @@ class DirReplaceBotV3 {
76
76
  this.#myrequest(
77
77
  HTTPREQUEST, async (err, resbody) => {
78
78
  if (err) {
79
- console.log("DirReplaceBot error: ", err);
79
+ console.error("DirReplaceBotv3 error: ", err);
80
80
  if (callback) {
81
81
  callback();
82
82
  return;
@@ -34,10 +34,10 @@ class DirWebResponse {
34
34
  }
35
35
 
36
36
  async go(action, callback) {
37
- console.log("Web response...");
38
- let payload = action.payload;
39
- let status = action.status;
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
- payload = filler.fill(payload, requestAttributes);
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: 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
- console.log("Published webresponse to topic:", topic);
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}