chat-platform 1.2.3 → 1.3.2

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 +17 -11
  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)
@@ -213,7 +215,8 @@ const ChatExpress = function(options) {
213
215
  }
214
216
 
215
217
  function inboundMessage(payload, chatServer) {
216
- var contextProvider = chatServer.getOptions().contextProvider;
218
+ const options = chatServer.getOptions();
219
+ const contextProvider = options.contextProvider;
217
220
  if (chatServer.isDebug()) {
218
221
  // eslint-disable-next-line no-console
219
222
  console.log(orange('-- INBOUND MESSAGE --'));
@@ -243,7 +246,8 @@ const ChatExpress = function(options) {
243
246
  messageId: parsedMessage.messageId,
244
247
  transport: parsedMessage.transport,
245
248
  language: parsedMessage.language,
246
- ts: parsedMessage.ts
249
+ ts: parsedMessage.ts,
250
+ chatbotId: options.chatbotId
247
251
  }),
248
252
  payload: {
249
253
  type: parsedMessage.type,
@@ -424,9 +428,7 @@ const ChatExpress = function(options) {
424
428
  }
425
429
 
426
430
  // create empty promise
427
- let stack = new Promise(function(resolve) {
428
- resolve(message);
429
- });
431
+ let stack = new Promise(resolve => resolve(message));
430
432
  // check for chatId, if not present check for userId-chatId translator, otherwise fail
431
433
  stack = stack.then(message => {
432
434
  const { transport } = instanceOptions;
@@ -533,6 +535,13 @@ const ChatExpress = function(options) {
533
535
  });
534
536
  // finally
535
537
  return stack
538
+ .then(function(message) {
539
+ // move the sent payload to the conventional key "sentMessage", it's up to middleware to
540
+ // update there the messageId
541
+ message.sentMessage = message.payload;
542
+ delete message.payload;
543
+ return message;
544
+ })
536
545
  .catch(function(error) {
537
546
  // eslint-disable-next-line no-console
538
547
  console.log(red(error));
@@ -541,9 +550,6 @@ const ChatExpress = function(options) {
541
550
  }
542
551
  // rethrow error so it can be caught by the sender node
543
552
  throw error;
544
- })
545
- .then(function(message) {
546
- return message;
547
553
  });
548
554
  }
549
555
 
@@ -592,7 +598,7 @@ const ChatExpress = function(options) {
592
598
  }
593
599
  if (RED.httpNode._router.stack.length >= routesCount) {
594
600
  // 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.`);
601
+ chatServer.warning('Improperly removed some routes from Express. This is normal when multiple bots are running in the same server.');
596
602
  }
597
603
  }
598
604
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-platform",
3
- "version": "1.2.3",
3
+ "version": "1.3.2",
4
4
  "description": "Universal Chat Platform",
5
5
  "main": "index.js",
6
6
  "scripts": {