node-red-contrib-chatbot
Version:
REDBot a Chat bot for a full featured chat bot for Telegram, Facebook Messenger and Slack. Almost no coding skills required
43 lines (35 loc) • 1.24 kB
JavaScript
var utils = require('../lib/helpers/utils');
var _ = require('underscore');
module.exports = function(RED) {
function ChatBotDialog(config) {
RED.nodes.createNode(this, config);
var node = this;
this.name = config.name;
this.elements = _.isArray(config.elements) && !_.isEmpty(config.elements) ? config.elements : null;
this.title = config.title;
this.submitLabel = config.submitLabel;
this.transports = ['slack'];
this.on('input', function(msg) {
// check transport compatibility
if (!utils.matchTransport(node, msg)) {
return;
}
var chatId = utils.getChatId(msg);
var messageId = utils.getMessageId(msg);
var title = utils.extractValue('string', 'title', node, msg, false);
var submitLabel = utils.extractValue('string', 'submitLabel', node, msg, false);
var elements = utils.extractValue('arrayOfObject', 'elements', node, msg, true);
// payload
msg.payload = {
type: 'dialog',
title: title,
submitLabel: submitLabel,
elements: elements,
chatId: chatId,
messageId: messageId
};
node.send(msg);
});
}
RED.nodes.registerType('chatbot-dialog', ChatBotDialog);
};