@tiledesk/tiledesk-tybot-connector 0.2.31 → 0.2.32

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.2.32
9
+ - Added attributes filling to message.metadata.src
10
+ - Added attributes filling to message.metadata.name
11
+
8
12
  # v0.2.31
9
13
  - Removed patch: Added support for removing empty text from replies: TiledeskChatbotUtil.removeEmptyReplyCommands()
10
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,6 +9,7 @@ require('dotenv').config();
9
9
  class DirMake {
10
10
 
11
11
  constructor(context) {
12
+ console.log('context object LOG: ', context.log)
12
13
  if (!context) {
13
14
  throw new Error('context object is mandatory');
14
15
  }
@@ -37,6 +38,9 @@ class DirMake {
37
38
 
38
39
  async go(action, callback) {
39
40
  if (this.log) { console.log("DirMake action:", JSON.stringify(action)); }
41
+ let trueIntent = action.trueIntent;
42
+ let falseIntent = action.falseIntent;
43
+ //console.log('DirMake trueIntent',trueIntent)
40
44
  if (!this.tdcache) {
41
45
  console.error("Error: DirMake tdcache is mandatory");
42
46
  callback();
@@ -55,7 +59,7 @@ class DirMake {
55
59
  if (this.log) { console.log("DirMake request parameter:", key, "value:", value, "type:", typeof value) }
56
60
  }
57
61
  }
58
-
62
+
59
63
  let webhook_url = action.url;
60
64
  let bodyParameters = action.bodyParameters;
61
65
  if (this.log) {
@@ -69,37 +73,38 @@ class DirMake {
69
73
  }
70
74
  if (!webhook_url || webhook_url === '') {
71
75
  console.error("DirMake ERROR - webhook_url is undefined or null or empty string");
72
- callback();
76
+ let status = 422;
77
+ let error = 'Missing make webhook url';
78
+ await this.#assignAttributes(action, status, error);
79
+ this.#executeCondition(false, trueIntent, null, falseIntent, null, () => {
80
+ callback(); // stop the flow
81
+ });
73
82
  return;
74
83
  }
75
84
  let url;
76
85
  try {
77
86
  let make_base_url = process.env.MAKE_ENDPOINT;
78
- if (make_base_url) {
79
- url = make_base_url + "/make/";
80
- } else {
81
- url = action.url;
82
- }
83
- const filler = new Filler();
84
-
85
-
87
+ if (make_base_url) {
88
+ url = make_base_url + "/make/";
89
+ } else {
90
+ url = action.url;
91
+ }
92
+ const filler = new Filler();
86
93
  for (const [key, value] of Object.entries(bodyParameters)) {
87
- if (this.log) {console.log("bodyParam:", key, "value:", value)}
94
+ //if (this.log) {console.log("bodyParam:", key, "value:", value)}
88
95
  let filled_value = filler.fill(value, requestVariables);
89
96
  bodyParameters[key] = filled_value;
90
97
  }
98
+ if (this.log) {console.log('DirMake bodyParameters filler: ',bodyParameters)}
91
99
 
92
- console.log('CIAO',bodyParameters)
93
-
94
-
95
100
 
96
101
 
97
102
  // Condition branches
98
- let trueIntent = action.trueIntent;
99
- let falseIntent = action.falseIntent;
100
- console.log('trueIntent',trueIntent)
103
+ //let trueIntent = action.trueIntent;
104
+ //let falseIntent = action.falseIntent;
105
+ //console.log('DirMake trueIntent',trueIntent)
101
106
 
102
- if (this.log) { console.log("DirMake MakeEndpoint URL: ", make_base_url); }
107
+ if (this.log) { console.log("DirMake MakeEndpoint URL: ", url); }
103
108
  const MAKE_HTTPREQUEST = {
104
109
  url: url,
105
110
  headers: {
@@ -131,8 +136,8 @@ class DirMake {
131
136
  await this.#executeCondition(true, trueIntent, null, falseIntent, null, () => {
132
137
  callback(); // stop the flow
133
138
  });
134
- console.log('myrequest/status: ',status)
135
- callback();
139
+ if (this.log) {console.log('myrequest/status: ',status)}
140
+ //callback();
136
141
  }
137
142
  }
138
143
  );
@@ -54,6 +54,15 @@ class DirReply {
54
54
  const filler = new Filler();
55
55
  // fill text attribute
56
56
  message.text = filler.fill(message.text, requestAttributes);
57
+ if (message.metadata) {
58
+ if (this.log) {console.log("filling message 'metadata':", JSON.stringify(message.metadata));}
59
+ if (message.metadata.src) {
60
+ message.metadata.src = filler.fill(message.metadata.src, requestAttributes);
61
+ }
62
+ if (message.metadata.name) {
63
+ message.metadata.name = filler.fill(message.metadata.name, requestAttributes);
64
+ }
65
+ }
57
66
  if (this.log) {console.log("filling commands'. Message:", JSON.stringify(message));}
58
67
  if (message.attributes && message.attributes.commands) {
59
68
  if (this.log) {console.log("filling commands'. commands found.");}