chat-platform 1.2.3 → 1.3.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.
Files changed (2) hide show
  1. package/chat-platform.js +13 -9
  2. package/package.json +1 -1
package/chat-platform.js CHANGED
@@ -44,6 +44,7 @@ const ChatExpress = function(options) {
44
44
  transportDescription: null,
45
45
  chatIdKey: null,
46
46
  userIdKey: null,
47
+ messageIdKey: null,
47
48
  tsKey: null,
48
49
  debug: true,
49
50
  onStart: null,
@@ -84,7 +85,7 @@ const ChatExpress = function(options) {
84
85
  }
85
86
 
86
87
  function evaluateParam(payload, newKey, optionKey, chatServer) {
87
- var options = _this.options;
88
+ const options = _this.options;
88
89
  if (options[optionKey] != null) {
89
90
  if (_.isString(options[optionKey]) && newKey != options[optionKey]) {
90
91
  payload[newKey] = payload[options[optionKey]];
@@ -111,6 +112,7 @@ const ChatExpress = function(options) {
111
112
 
112
113
  evaluateParam(payload, 'chatId', 'chatIdKey', chatServer);
113
114
  evaluateParam(payload, 'userId', 'userIdKey', chatServer);
115
+ evaluateParam(payload, 'messageId', 'messageIdKey', chatServer);
114
116
  evaluateParam(payload, 'ts', 'tsKey', chatServer);
115
117
  evaluateParam(payload, 'type', 'type', chatServer);
116
118
  evaluateParam(payload, 'language', 'language', chatServer);
@@ -118,7 +120,7 @@ const ChatExpress = function(options) {
118
120
  // on removing this constraint (some chat context may be lost)
119
121
  payload.userId = !_.isEmpty(payload.userId) ? payload.userId : payload.chatId;
120
122
  // evaluate callbacks
121
- var callbacks = chatServer.getCallbacks();
123
+ const callbacks = chatServer.getCallbacks();
122
124
  _(['chatId', 'userId', 'ts', 'type', 'language', 'messageId']).each(function(callbackName) {
123
125
  if (_.isFunction(callbacks[callbackName])) {
124
126
  payload[callbackName] = callbacks[callbackName].call(chatServer, payload)
@@ -424,9 +426,7 @@ const ChatExpress = function(options) {
424
426
  }
425
427
 
426
428
  // create empty promise
427
- let stack = new Promise(function(resolve) {
428
- resolve(message);
429
- });
429
+ let stack = new Promise(resolve => resolve(message));
430
430
  // check for chatId, if not present check for userId-chatId translator, otherwise fail
431
431
  stack = stack.then(message => {
432
432
  const { transport } = instanceOptions;
@@ -533,6 +533,13 @@ const ChatExpress = function(options) {
533
533
  });
534
534
  // finally
535
535
  return stack
536
+ .then(function(message) {
537
+ // move the sent payload to the conventional key "sentMessage", it's up to middleware to
538
+ // update there the messageId
539
+ message.sentMessage = message.payload;
540
+ delete message.payload;
541
+ return message;
542
+ })
536
543
  .catch(function(error) {
537
544
  // eslint-disable-next-line no-console
538
545
  console.log(red(error));
@@ -541,9 +548,6 @@ const ChatExpress = function(options) {
541
548
  }
542
549
  // rethrow error so it can be caught by the sender node
543
550
  throw error;
544
- })
545
- .then(function(message) {
546
- return message;
547
551
  });
548
552
  }
549
553
 
@@ -592,7 +596,7 @@ const ChatExpress = function(options) {
592
596
  }
593
597
  if (RED.httpNode._router.stack.length >= routesCount) {
594
598
  // eslint-disable-next-line no-console
595
- chatServer.warning(`Improperly removed some routes from Express. This is normal when multiple bots are running in the same server.`);
599
+ chatServer.warning('Improperly removed some routes from Express. This is normal when multiple bots are running in the same server.');
596
600
  }
597
601
  }
598
602
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-platform",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "Universal Chat Platform",
5
5
  "main": "index.js",
6
6
  "scripts": {