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
35 lines (29 loc) • 935 B
JavaScript
var _ = require('underscore');
var utils = require('../lib/helpers/utils');
var lcd = require('../lib/helpers/lcd');
var when = utils.when;
module.exports = function(RED) {
function ChatBotDebug(config) {
RED.nodes.createNode(this, config);
var node = this;
this.chatId = config.chatId;
this.on('input', function(msg) {
if (_.isFunction(msg.chat)) {
var chatContext = msg.chat();
// get all keys
when(chatContext.all())
.then(function(obj) {
// chat context
lcd.node(obj, { title: 'ChatBot context', node: node });
// message
if (msg.payload != null) {
lcd.node(msg.payload, {title: 'ChatBot message', node: node});
}
});
} else {
lcd.node(msg.payload, { title: 'Message debug', node: node });
}
});
}
RED.nodes.registerType('chatbot-debug', ChatBotDebug);
};