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
41 lines (30 loc) • 895 B
JavaScript
var utils = require('../lib/helpers/utils');
module.exports = function(RED) {
function ChatBotTopic(config) {
RED.nodes.createNode(this, config);
var node = this;
node.rules = config.rules;
this.on('input', function(msg) {
var originalMessage = msg.originalMessage;
var chatContext = msg.chat();
var rules = node.rules;
// do nothing
if (originalMessage == null || rules.length == 0) {
return;
}
var output = [];
var currentTopic = chatContext.get('topic');
var matched = false;
rules.forEach(function(rule) {
if (!matched && utils.matchContext(currentTopic, rule.topic)) {
matched = true;
output.push(msg);
} else {
output.push(null);
}
});
node.send(output);
});
}
RED.nodes.registerType('chatbot-topic', ChatBotTopic);
};