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

28 lines (23 loc) 919 B
const RegisterType = require('../lib/node-installer'); const GlobalContextHelper = require('../lib/helpers/global-context-helper'); module.exports = function(RED) { const registerType = RegisterType(RED); const globalContextHelper = GlobalContextHelper(RED); function ChatBotPushMessage(config) { RED.nodes.createNode(this, config); const node = this; globalContextHelper.init(this.context().global); this.on('input', function(msg, send, done) { // send/done compatibility for node-red < 1.0 send = send || function() { node.send.apply(node, arguments) }; done = done || function(error) { node.error.call(node, error, msg) }; // get previous message from stash send({ ...msg, previous: { ...msg.payload } // store previous msg, use POP to retrieve }); done(); }); } registerType('chatbot-push-message', ChatBotPushMessage); };