wingbot 3.34.0-alpha.1 → 3.35.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.34.0-alpha.1",
3
+ "version": "3.35.1",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -46,7 +46,7 @@
46
46
  "eslint-plugin-react": "^7.29.4",
47
47
  "graphql-markdown": "^6.0.0",
48
48
  "jsdoc-to-markdown": "^7.1.1",
49
- "mocha": "^9.2.2",
49
+ "mocha": "^10.0.0",
50
50
  "nyc": "^15.1.0",
51
51
  "rimraf": "^3.0.2",
52
52
  "sinon": "^13.0.1",
package/src/BotApp.js CHANGED
@@ -46,6 +46,15 @@ const DEFAULT_API_URL = 'https://orchestrator-api.wingbot.ai';
46
46
  * @prop {object} headers
47
47
  */
48
48
 
49
+ function defaultMsg (senderId, pageId) {
50
+ return {
51
+ sender: { id: senderId },
52
+ recipient: { id: pageId },
53
+ mid: null,
54
+ timestamp: Date.now()
55
+ };
56
+ }
57
+
49
58
  /**
50
59
  * Adapter for Wingbot flight director
51
60
  *
@@ -239,32 +248,55 @@ class BotApp {
239
248
  };
240
249
  }
241
250
 
251
+ const sender = await this.createSender(senderId, pageId, message, secret, appId);
252
+ const res = await this._processor.processMessage(message, pageId, sender, { appId });
253
+ await this._processSenderResponses(sender, senderId, pageId, headers);
254
+
255
+ return {
256
+ status: res.status,
257
+ response_to_mid: message.mid,
258
+ messaging: []
259
+ };
260
+ }
261
+
262
+ /**
263
+ * Creates a Sender to be able, for example, to upload files
264
+ *
265
+ * @param {string} senderId
266
+ * @param {string} pageId
267
+ * @param {object} [message]
268
+ * @param {string|Promise<string>} [secret]
269
+ * @param {string} appId
270
+ * @returns {Promise<BotAppSender>}
271
+ */
272
+ async createSender (
273
+ senderId,
274
+ pageId,
275
+ message = defaultMsg(senderId, pageId),
276
+ secret = this._secret,
277
+ appId = this._appId
278
+ ) {
279
+ const useSecret = await Promise.resolve(secret);
280
+
281
+ const setResponseToMid = message.response_to_mid || message.mid;
282
+
242
283
  const options = {
243
284
  ...this._returnSenderOptions,
244
285
  apiUrl: this._apiUrl,
245
286
  pageId,
246
287
  appId,
247
- secret,
288
+ secret: useSecret,
248
289
  mid: setResponseToMid,
249
290
  fetch: this._fetch,
250
291
  tls: this._tls
251
292
  };
252
293
 
253
- const sender = new BotAppSender(options, senderId, message, this._senderLogger);
254
- const res = await this._processor.processMessage(message, pageId, sender, { appId });
255
- await this._processSenderResponses(sender, senderId, pageId, headers);
256
-
257
- return {
258
- status: res.status,
259
- response_to_mid: message.mid,
260
- messaging: []
261
- };
294
+ return new BotAppSender(options, senderId, message, this._senderLogger);
262
295
  }
263
296
 
264
297
  /**
265
298
  * Compatibility method for Notification engine
266
299
  *
267
- * @deprecated
268
300
  * @param {object} message - wingbot chat event
269
301
  * @param {string} senderId - chat event sender identifier
270
302
  * @param {string} pageId - channel/page identifier
@@ -31,19 +31,11 @@ const { makeAbsolute } = require('../utils');
31
31
  * @param {Payload} payload
32
32
  * @returns {EncodedPayload}
33
33
  */
34
- function encodePayload (payload) {
35
- const encodedPayload = {
36
- content: payload.content,
37
- content_type: payload.contentType
34
+ function encodePayload ({ content, contentType }) {
35
+ return {
36
+ content: Buffer.from(content).toString('base64'),
37
+ content_type: contentType
38
38
  };
39
-
40
- switch (payload.contentType) {
41
- default:
42
- encodedPayload.content = Buffer.from(payload.content).toString('base64');
43
- break;
44
- }
45
-
46
- return encodedPayload;
47
39
  }
48
40
 
49
41
  /**