forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot-waiting.js
40 lines (31 loc) · 1.06 KB
/
chatbot-waiting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var _ = require('underscore');
var utils = require('./lib/helpers/utils');
module.exports = function(RED) {
function ChatBotWaiting(config) {
RED.nodes.createNode(this, config);
this.waitingType = config.waitingType;
this.transports = ['telegram', 'slack', 'facebook'];
this.on('input', function(msg) {
var node = this;
var waitingType = this.waitingType;
var originalMessage = msg.originalMessage;
var chatId = msg.payload.chatId || (originalMessage && originalMessage.chat.id);
// check transport compatibility
if (!utils.matchTransport(node, msg)) {
return;
}
if (utils.getTransport(msg) === 'slack' && waitingType !== 'typing') {
node.error('Only \'typing\' is supported for slack transport');
return;
}
msg.payload = {
type: 'action',
waitingType: !_.isEmpty(waitingType) ? waitingType : 'typing',
chatId: chatId,
inbound: false
};
node.send(msg);
});
}
RED.nodes.registerType('chatbot-waiting', ChatBotWaiting);
};