@tiledesk/tiledesk-tybot-connector 0.1.28 → 0.1.30

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/.env CHANGED
@@ -1,8 +1,7 @@
1
1
  API_ENDPOINT=http://localhost:10002
2
2
  mongoUrl=mongodb://tiledesk-user1:YB62b7gQNGg3G9OW@tiledesk-prod-shard-00-00-vmvst.mongodb.net:27017,tiledesk-prod-shard-00-01-vmvst.mongodb.net:27017,tiledesk-prod-shard-00-02-vmvst.mongodb.net:27017/tiledesk-pre?ssl=true&replicaSet=tiledesk-prod-shard-0&authSource=admin&retryWrites=true
3
- REDIS_HOST=redis-17533.c135.eu-central-1-1.ec2.cloud.redislabs.com
4
- REDIS_PASSWORD=ZSKKrWfnR6o5Gkt17ZgPkKGu1DcrUTge
5
- REDIS_PORT=17533
3
+ REDIS_HOST=localhost
4
+ REDIS_PORT=6379
6
5
  TYBOT_ENDPOINT=http://localhost:10001
7
6
  CHATBOT_TOKEN=JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ3ZWJob29rX2VuYWJsZWQiOmZhbHNlLCJ0eXBlIjoiZXh0ZXJuYWwiLCJsYW5ndWFnZSI6ImVuIiwicHVibGljIjpmYWxzZSwiX2lkIjoiNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwibmFtZSI6IlRoZSBGb3JtIHYyIC0gZXh0IiwidXJsIjoiaHR0cHM6Ly90aWxlYm90LWRldi5oZXJva3VhcHAuY29tL2V4dC82MzhjNzhkNzFkYjQ0OTAwMzUxMTAxYzIiLCJpZF9wcm9qZWN0IjoiNjM4Yzc4YTYxZGI0NDkwMDM1MTBmZjkxIiwidHJhc2hlZCI6ZmFsc2UsImNyZWF0ZWRCeSI6IjVlMDlkMTZkNGQzNjExMDAxNzUwNmQ3ZiIsImNyZWF0ZWRBdCI6IjIwMjItMTItMDRUMTA6NDA6MDQuMjA3WiIsInVwZGF0ZWRBdCI6IjIwMjItMTItMDVUMDc6MjE6MDIuOTIxWiIsIl9fdiI6MCwiZGVzY3JpcHRpb24iOiJPbiBIZXJva3UiLCJpYXQiOjE2NzA2NzE4ODksImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tL2JvdHMvNjM4Yzc5MDQxZGI0NDkwMDM1MTEwMjYwIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJib3QiLCJqdGkiOiJmNDVlZGIwYS0zNzVhLTQ0NjMtYjFhZi1jM2ZiZDg4YmE3ZGQifQ.FbW3csHl1sQgSyRz5Jg0qaTvvpXWXgWHlJ1JWoVbv3s
8
7
  CHATBOT_ENDPOINT=http://localhost:10001
package/CHANGELOG.md CHANGED
@@ -1,10 +1,17 @@
1
1
  # Tiledesk tybotRoute
2
2
 
3
- **npm @tiledesk/tiledesk-tybot-connector@0.1.23**
3
+ **npm @tiledesk/tiledesk-tybot-connector**
4
4
 
5
5
  available on:
6
6
  ▶️ https://www.npmjs.com/package/@tiledesk/tiledesk-tybot-connector
7
7
 
8
+ ### 0.1.30 - online
9
+ - Fixed wrong bot_answer["_raw_message"]
10
+
11
+ ### 0.1.29 - online
12
+ - Added process.exit(1) in tybot-route.startApp when no Redis connection is available to facilitate Cluster start
13
+ - Debug console.log() removed.
14
+
8
15
  ### 0.1.28 - online
9
16
  - Added a 'serious' integration test for chatbot
10
17
  - Removed reference to requestId and depId from processInlineDirectives()
package/TdCache.js CHANGED
@@ -19,7 +19,6 @@ class TdCache {
19
19
  password: this.redis_password
20
20
  });
21
21
  this.client.on('error', err => {
22
- console.log('Redis connection error', err);
23
22
  reject(err);
24
23
  if (callback) {
25
24
  callback(err);
package/index.js CHANGED
@@ -189,6 +189,8 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
189
189
  if (log) {console.log("request...", request);}
190
190
  let directivesPlug = new DirectivesChatbotPlug({supportRequest: request, TILEDESK_API_ENDPOINT: APIURL, TILEBOT_ENDPOINT:process.env.TYBOT_ENDPOINT, token: token, log: log, HELP_CENTER_API_ENDPOINT: process.env.HELP_CENTER_API_ENDPOINT, cache: tdcache});
191
191
  // PIPELINE-EXT
192
+ if (log) {console.log("answer to process:", JSON.stringify(answer));}
193
+ const original_answer_text = answer.text;
192
194
  const bot_answer = await ExtUtil.execPipelineExt(request, answer, directivesPlug, tdcache, log);
193
195
  // console.log("bot_answer", bot_answer)
194
196
  //const bot_answer = answer;
@@ -215,7 +217,9 @@ router.post('/ext/:projectId/requests/:requestId/messages', async (req, res) =>
215
217
  // triggeredByMessageId: '6392e5e8408e0000437aa383'
216
218
  // }
217
219
  if (bot_answer) {
218
- bot_answer["_raw_message"] = answer.text;
220
+ if (log) {console.log("adding to bot_answer original_answer_text:", JSON.stringify(original_answer_text));}
221
+ bot_answer["_raw_message"] = original_answer_text;
222
+ if (log) {console.log("bot_answer", JSON.stringify(bot_answer));}
219
223
  tdclient.sendSupportMessage(requestId, bot_answer, (err, response) => {
220
224
  if (err) {
221
225
  console.error("Error sending message", err);
@@ -291,13 +295,15 @@ function startApp(settings, completionCallback) {
291
295
  console.log("(Tilebot) mongodb connection ok.");
292
296
  if (tdcache) {
293
297
  try {
298
+ console.log("(Tilebot) Connecting Redis...");
294
299
  await tdcache.connect();
295
300
  }
296
301
  catch (error) {
297
302
  tdcache = null;
298
- console.error("(Tilebot) tdcache (Redis) connection error:", error);
303
+ console.error("(Tilebot) Redis connection error:", error);
304
+ process.exit(1);
299
305
  }
300
- console.log("(Tilebot) tdcache (Redis) connected.");
306
+ console.log("(Tilebot) Redis connected.");
301
307
  }
302
308
  console.info("Tilebot started.");
303
309
  if (completionCallback) {
@@ -258,9 +258,9 @@ class TiledeskChatbot {
258
258
  await this.lockIntent(this.requestId, intent_name);
259
259
  const user_reply = message.text;
260
260
  let form_reply = await this.execIntentForm(user_reply, intent_form);
261
- console.log("got form reply", form_reply)
261
+ // console.log("got form reply", form_reply)
262
262
  if (!form_reply.canceled && form_reply.message) {
263
- console.log("Form replying for next field...");
263
+ // console.log("Form replying for next field...");
264
264
  if (this.log) {console.log("Sending form reply...", form_reply.message)}
265
265
  // reply with this message (ex. please enter your fullname)
266
266
  if (!form_reply.message.attributes) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-tybot-connector",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "Tiledesk Tybot connector",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "mocha",
7
+ "test": "mocha --exit",
8
8
  "start": "node index.js"
9
9
  },
10
10
  "keywords": [],
@@ -8,8 +8,12 @@ app.use("/", tybotRoute);
8
8
  require('dotenv').config();
9
9
  const bodyParser = require('body-parser');
10
10
 
11
- const REQUEST_ID = "support-group-" + process.env.TEST_PROJECT_ID + "-" + Date.now();
12
- console.log("REQUEST_ID:", REQUEST_ID);
11
+ const PROJECT_ID = process.env.TEST_PROJECT_ID;
12
+ const REQUEST_ID = "support-group-" + PROJECT_ID + "-" + Date.now();
13
+ const BOT_ID = process.env.TEST_BOT_ID;
14
+ const CHATBOT_TOKEN = process.env.CHATBOT_TOKEN;
15
+
16
+ // console.log("REQUEST_ID:", REQUEST_ID);
13
17
  let app_listener;
14
18
 
15
19
  before( () => {
@@ -82,7 +86,7 @@ describe('Conversation1', async() => {
82
86
  // console.log('endpointServer started', listener.address());
83
87
  });
84
88
 
85
- const botId = process.env.TEST_BOT_ID;
89
+ // const botId = process.env.TEST_BOT_ID;
86
90
  // console.log("botId:", botId);
87
91
  let request = {
88
92
  "payload": {
@@ -92,15 +96,15 @@ describe('Conversation1', async() => {
92
96
  "sender": "A-SENDER",
93
97
  "recipient": REQUEST_ID,
94
98
  "text": "/start",
95
- "id_project": process.env.TEST_PROJECT_ID,
99
+ "id_project": PROJECT_ID,
96
100
  "metadata": "",
97
101
  "request": {
98
102
  "request_id": REQUEST_ID
99
103
  }
100
104
  },
101
- "token": process.env.CHATBOT_TOKEN
105
+ "token": CHATBOT_TOKEN
102
106
  }
103
- sendMessageToBot(request, botId, process.env.CHATBOT_TOKEN, () => {
107
+ sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
104
108
  // console.log("Message sent.");
105
109
  });
106
110
  });
@@ -128,10 +132,10 @@ describe('Conversation1', async() => {
128
132
 
129
133
  listener = endpointServer.listen(10002, '0.0.0.0', function () {
130
134
  // console.log('endpointServer started', listener.address());
131
- const botId = process.env.TEST_BOT_ID;
132
- const PROJECT_ID = process.env.TEST_PROJECT_ID;
133
- console.log("botId:", botId);
134
- console.log("REQUEST_ID:", REQUEST_ID);
135
+ // const botId = process.env.TEST_BOT_ID;
136
+ // const PROJECT_ID = process.env.TEST_PROJECT_ID;
137
+ // console.log("botId:", botId);
138
+ // console.log("REQUEST_ID:", REQUEST_ID);
135
139
  let request = {
136
140
  "payload": {
137
141
  "_id": "ID",
@@ -147,9 +151,78 @@ describe('Conversation1', async() => {
147
151
  "id_project": PROJECT_ID
148
152
  }
149
153
  },
150
- "token": process.env.CHATBOT_TOKEN
154
+ "token": CHATBOT_TOKEN
155
+ }
156
+ sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
157
+ // console.log("Message sent.");
158
+ });
159
+ });
160
+ });
161
+
162
+ it('/good_form', (done) => {
163
+ console.log("/good_form...");
164
+ let listener;
165
+ let endpointServer = express();
166
+ endpointServer.use(bodyParser.json());
167
+ endpointServer.post('/:projectId/requests/:requestId/messages', function (req, res) {
168
+ // console.log("req.body:", JSON.stringify(req.body));
169
+ res.send({success: true});
170
+ const message = req.body;
171
+
172
+ if (message.text === "Your name?") {
173
+ const reply_text = "Andrea";
174
+ let request = {
175
+ "payload": {
176
+ "_id": "ID",
177
+ "senderFullname": "guest#367e",
178
+ "type": "text",
179
+ "sender": "A-SENDER",
180
+ "recipient": REQUEST_ID,
181
+ "text": reply_text,
182
+ "id_project": PROJECT_ID,
183
+ "request": {
184
+ "request_id": REQUEST_ID,
185
+ "id_project": PROJECT_ID
186
+ }
187
+ },
188
+ "token": CHATBOT_TOKEN
189
+ }
190
+ sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
191
+ // console.log("Message sent.", request);
192
+ });
193
+ }
194
+ else if (message.text === "It's a good form Andrea") {
195
+ listener.close( () => {
196
+ done();
197
+ });
198
+ }
199
+ else {
200
+ console.error("Unexpected message.");
201
+ assert.ok(false);
202
+ }
203
+
204
+ });
205
+
206
+ listener = endpointServer.listen(10002, '0.0.0.0', function () {
207
+ // console.log('endpointServer started', listener.address());
208
+ // console.log("REQUEST_ID:", REQUEST_ID);
209
+ let request = {
210
+ "payload": {
211
+ "_id": "ID",
212
+ "senderFullname": "guest#367e",
213
+ "type": "text",
214
+ "sender": "A-SENDER",
215
+ "recipient": REQUEST_ID,
216
+ "text": "/good_form",
217
+ "id_project": PROJECT_ID,
218
+ "request": {
219
+ "request_id": REQUEST_ID,
220
+ "id_project": PROJECT_ID
221
+ }
222
+ },
223
+ "token": CHATBOT_TOKEN
151
224
  }
152
- sendMessageToBot(request, botId, process.env.CHATBOT_TOKEN, () => {
225
+ sendMessageToBot(request, BOT_ID, CHATBOT_TOKEN, () => {
153
226
  // console.log("Message sent.");
154
227
  });
155
228
  });
@@ -32,7 +32,7 @@ class MarkbotChatbotPlug {
32
32
  // console.log("message.text:", incoming_message_text);
33
33
  // console.log("message commands:", commands)
34
34
  if (incoming_message_text === "" && !commands) {
35
- console.log("message with no content. Ignoring");
35
+ // console.log("message with no content. Ignoring");
36
36
  pipeline.message = null;
37
37
  pipeline.nextplug();
38
38
  return;
@@ -9,7 +9,7 @@ class DirLockIntent {
9
9
  }
10
10
 
11
11
  async execute(directive, requestId, callback) {
12
- console.log("Locking intent");
12
+ // console.log("Locking intent");
13
13
  if (directive.parameter) {
14
14
  let intent_name = directive.parameter.trim();
15
15
  await this.lockIntent(requestId, intent_name);
@@ -22,7 +22,7 @@ class DirLockIntent {
22
22
 
23
23
  async lockIntent(requestId, intent_name) {
24
24
  await this.tdcache.set("tilebot:requests:" + requestId + ":locked", intent_name);
25
- console.log("locked.", intent_name);
25
+ // console.log("locked.", intent_name);
26
26
  }
27
27
 
28
28
  }