forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot-location.js
51 lines (41 loc) · 1.27 KB
/
chatbot-location.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
41
42
43
44
45
46
47
48
49
50
51
var _ = require('underscore');
var utils = require('./lib/helpers/utils');
module.exports = function(RED) {
function ChatBotLocation(config) {
RED.nodes.createNode(this, config);
var node = this;
this.latitude = config.latitude;
this.longitude = config.longitude;
this.place = config.place;
this.transports = ['telegram', 'slack', 'facebook'];
this.on('input', function(msg) {
var chatId = utils.getChatId(msg);
var messageId = utils.getMessageId(msg);
var latitude = node.latitude;
var longitude = node.longitude;
var place = node.place;
// check transport compatibility
if (!utils.matchTransport(node, msg)) {
return;
}
if (_.isObject(msg.payload) && _.isNumber(msg.payload.latitude) && _.isNumber(msg.payload.longitude)) {
latitude = msg.payload.latitude;
longitude = msg.payload.longitude;
}
// send out the message
msg.payload = {
type: 'location',
content: {
latitude: latitude,
longitude: longitude
},
place: place,
chatId: chatId,
messageId: messageId,
inbound: false
};
node.send([msg, null]);
});
}
RED.nodes.registerType('chatbot-location', ChatBotLocation);
};