UNPKG

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

33 lines (25 loc) 765 B
var ChatLog = require('../lib/chat-log.js'); var utils = require('../lib/helpers/utils'); var when = utils.when; module.exports = function(RED) { function ChatBotLog(config) { RED.nodes.createNode(this, config); var node = this; this.on('input', function(msg) { var task = when(true); var chatContext = msg.chat(); if (chatContext != null) { task = task.then(function() { return chatContext.get('firstName', 'lastName', 'chatId'); }); } when(task) .then(function(jsonContext) { var chatLog = new ChatLog(jsonContext); msg.payload = chatLog.message(msg); node.send(msg); }); }); } RED.nodes.registerType('chatbot-log', ChatBotLog); };