forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot-qr-code.js
35 lines (28 loc) · 983 Bytes
/
chatbot-qr-code.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
var qr = require('qr-image');
var MessageTemplate = require('./lib/message-template.js');
module.exports = function(RED) {
function ChatBotQRCode(config) {
RED.nodes.createNode(this, config);
var node = this;
this.message = config.message;
this.on('input', function(msg) {
var message = node.message;
var originalMessage = msg.originalMessage;
var chatId = msg.payload.chatId || (originalMessage && originalMessage.chat.id);
var messageId = msg.payload.messageId || (originalMessage && originalMessage.message_id);
var template = MessageTemplate(msg, node);
var buffer = qr.imageSync(template(message));
// send out the picture with the qr
msg.payload = {
type: 'photo',
content: buffer,
//filename: '',
chatId: chatId,
messageId: messageId,
inbound: false
};
node.send(msg);
});
}
RED.nodes.registerType('chatbot-qrcode', ChatBotQRCode);
};