chat-platform 2.0.0 → 2.1.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/chat-platform.js +20 -16
- package/helpers/lcd.js +4 -0
- package/package.json +1 -3
package/chat-platform.js
CHANGED
|
@@ -73,15 +73,15 @@ const ChatExpress = function(options) {
|
|
|
73
73
|
// configuration warnings
|
|
74
74
|
if (_.isEmpty(this.options.chatIdKey) && !_.isFunction(this.options.chatIdKey)) {
|
|
75
75
|
// eslint-disable-next-line no-console
|
|
76
|
-
console.log(yellow('WARNING: chatIdKey option is empty'));
|
|
76
|
+
console.log(lcd.timestamp() + yellow('WARNING: chatIdKey option is empty'));
|
|
77
77
|
}
|
|
78
78
|
if (_.isEmpty(this.options.userIdKey) && !_.isFunction(this.options.userIdKey)) {
|
|
79
79
|
// eslint-disable-next-line no-console
|
|
80
|
-
console.log(yellow('WARNING: userIdKey option is empty'));
|
|
80
|
+
console.log(lcd.timestamp() + yellow('WARNING: userIdKey option is empty'));
|
|
81
81
|
}
|
|
82
82
|
if (_.isEmpty(this.options.transport)) {
|
|
83
83
|
// eslint-disable-next-line no-console
|
|
84
|
-
console.log(yellow('WARNING: transport option is empty'));
|
|
84
|
+
console.log(lcd.timestamp() + yellow('WARNING: transport option is empty'));
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function evaluateParam(payload, newKey, optionKey, chatServer) {
|
|
@@ -154,11 +154,11 @@ const ChatExpress = function(options) {
|
|
|
154
154
|
// check if message is null, perhaps someone forgot to resolve a promise
|
|
155
155
|
if (message == null) {
|
|
156
156
|
// eslint-disable-next-line no-console
|
|
157
|
-
console.log(yellow('WARNING: a middleware is returning an empty message'));
|
|
157
|
+
console.log(lcd.timestamp() + yellow('WARNING: a middleware is returning an empty message'));
|
|
158
158
|
}
|
|
159
159
|
if (message.payload == null) {
|
|
160
160
|
// eslint-disable-next-line no-console
|
|
161
|
-
console.log(yellow('WARNING: a middleware is returning an empty payload in message'));
|
|
161
|
+
console.log(lcd.timestamp() + yellow('WARNING: a middleware is returning an empty payload in message'));
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -191,9 +191,13 @@ const ChatExpress = function(options) {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
if (_.isEmpty(chatId) && !_.isEmpty(userId)) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
if (userId === 'simulator') {
|
|
195
|
+
chatId = 0; // for simulators conventionally set zero
|
|
196
|
+
} else {
|
|
197
|
+
chatId = await contextProvider.getChatId(userId, options.transport);
|
|
198
|
+
if (_.isEmpty(chatId)) {
|
|
199
|
+
throw `Unable to resolve chatId from userId "${userId}" (${options.transport}). That means either the userId "${userId}" doesn't exist or it's not possible to find a valid chatId for the platform ${options.transport}.`;
|
|
200
|
+
}
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
|
|
@@ -333,7 +337,7 @@ const ChatExpress = function(options) {
|
|
|
333
337
|
.then(() => when(message));
|
|
334
338
|
} else {
|
|
335
339
|
// eslint-disable-next-line no-console
|
|
336
|
-
console.log(yellow('WARNING: context provider was not specified'));
|
|
340
|
+
console.log(lcd.timestamp() + yellow('WARNING: context provider was not specified'));
|
|
337
341
|
}
|
|
338
342
|
// run general middleware
|
|
339
343
|
_(_this.uses.concat(chatServer.getUseMiddleWares())).each(function(filter) {
|
|
@@ -604,9 +608,9 @@ const ChatExpress = function(options) {
|
|
|
604
608
|
const uiPort = RED.settings.get('uiPort');
|
|
605
609
|
const options = chatServer.getOptions();
|
|
606
610
|
// eslint-disable-next-line no-console
|
|
607
|
-
console.log('');
|
|
611
|
+
console.log(lcd.timestamp() + '');
|
|
608
612
|
// eslint-disable-next-line no-console
|
|
609
|
-
console.log(grey('------ WebHooks for ' + options.transport.toUpperCase() + '----------------'));
|
|
613
|
+
console.log(lcd.timestamp() + grey('------ WebHooks for ' + options.transport.toUpperCase() + '----------------'));
|
|
610
614
|
_(routes).map((middleware, route) => {
|
|
611
615
|
const host = 'http://localhost' + (uiPort != '80' ? ':' + uiPort : '');
|
|
612
616
|
const callback = generateCallback(route, chatServer);
|
|
@@ -618,14 +622,14 @@ const ChatExpress = function(options) {
|
|
|
618
622
|
description = routesDescription[route].call(chatServer);
|
|
619
623
|
}
|
|
620
624
|
// eslint-disable-next-line no-console
|
|
621
|
-
console.log(green(host + callback) + (description != null ? grey(' - ') + white(description) : ''));
|
|
625
|
+
console.log(lcd.timestamp() + green(host + callback) + (description != null ? grey(' - ') + white(description) : ''));
|
|
622
626
|
// attach to Express instance
|
|
623
627
|
const escaped = String(`^${callback}$`).replace(RegExp('/', 'g'), '\\/');
|
|
624
628
|
RED.httpNode.use(new RegExp(escaped), middleware.bind(chatServer));
|
|
625
629
|
return null;
|
|
626
630
|
});
|
|
627
631
|
// eslint-disable-next-line no-console
|
|
628
|
-
console.log('');
|
|
632
|
+
console.log(lcd.timestamp() + '');
|
|
629
633
|
}
|
|
630
634
|
return when(true);
|
|
631
635
|
}
|
|
@@ -976,7 +980,7 @@ const ChatExpress = function(options) {
|
|
|
976
980
|
.then(function() {
|
|
977
981
|
if (_this.isDebug()) {
|
|
978
982
|
// eslint-disable-next-line no-console
|
|
979
|
-
console.log(green('Chat server started, transport: ') + white(options.transport));
|
|
983
|
+
console.log(green(lcd.timestamp() + 'Chat server started, transport: ') + white(options.transport));
|
|
980
984
|
}
|
|
981
985
|
// listen to inbound event
|
|
982
986
|
var connector = options.connector;
|
|
@@ -1025,7 +1029,7 @@ const ChatExpress = function(options) {
|
|
|
1025
1029
|
} catch(e) {
|
|
1026
1030
|
// todo better error displaying
|
|
1027
1031
|
// eslint-disable-next-line no-console
|
|
1028
|
-
console.log('Error in resolver chatId<->userId', e);
|
|
1032
|
+
console.log(lcd.timestamp() + 'Error in resolver chatId<->userId', e);
|
|
1029
1033
|
throw new Error('Error in resolver chatId<->userId', e);
|
|
1030
1034
|
}
|
|
1031
1035
|
};
|
|
@@ -1041,7 +1045,7 @@ const ChatExpress = function(options) {
|
|
|
1041
1045
|
} catch(e) {
|
|
1042
1046
|
// todo better error displaying
|
|
1043
1047
|
// eslint-disable-next-line no-console
|
|
1044
|
-
console.log('Error in resolver chatId<->preferred transport', e);
|
|
1048
|
+
console.log(lcd.timestamp() + 'Error in resolver chatId<->preferred transport', e);
|
|
1045
1049
|
throw new Error('Error in resolver chatId<->preferred transport', e);
|
|
1046
1050
|
}
|
|
1047
1051
|
};
|
package/helpers/lcd.js
CHANGED
|
@@ -21,6 +21,10 @@ var LCD = {
|
|
|
21
21
|
orange: orange,
|
|
22
22
|
red: red,
|
|
23
23
|
|
|
24
|
+
timestamp() {
|
|
25
|
+
return LCD.white(moment().format('DD MMM HH:mm:ss') + ' - [info] ');
|
|
26
|
+
},
|
|
27
|
+
|
|
24
28
|
dump: function(e, title) {
|
|
25
29
|
this.title(!_.isEmpty(title) ? title : 'Error');
|
|
26
30
|
if (e instanceof Error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chat-platform",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Universal Chat Platform",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,8 +14,6 @@
|
|
|
14
14
|
"cli-color": "^1.4.0",
|
|
15
15
|
"cli-table": "^0.3.1",
|
|
16
16
|
"moment": "^2.24.0",
|
|
17
|
-
"np": "^5.0.2",
|
|
18
|
-
"npm": "^6.9.0",
|
|
19
17
|
"prettyjson": "^1.2.1",
|
|
20
18
|
"request": "^2.88.0",
|
|
21
19
|
"sequelize": "^5.21.6",
|