Create a Node-RED Messenger writer

Your Node-RED application can see chats on Facebook Messenger. It now needs to write back. You’ll need to install a new node from the community Node-RED library.

    1. Go to the Node-RED Library page at http://flows.nodered.org. Search for Messenger.

      1. Select the node named node-red-contrib-facebook-messenger-writer. You will add this node to your Bluemix palette.

      1. Open your Bluemix dashboard.

      1. Select your application.

        1. Find the Continuous Delivery section and click Edit Code.

          1. Stop your application.

            1. Edit the package.json file.

              1. Add the following line. You can insert it anywhere. If you add it to the end, be sure to remove the final comma.
                "node-red-contrib-facebook-messenger-writer": "0.x",

              1. Save your changes and deploy your application. Wait for your application to start.
              2. Go to the Node-RED flow editor. Drag and drop the following nodes onto the canvas. You’ll wire them to the Messenger Chat Listener group.
                • A common function node
                • A function facebook messenger node
                • An output debug node
              1. Wire the nodes together by wiring the new function node to the facebook messenger node and then to the debug (msg.payload) node.

              1. Double-click the new function node, name it Set up response, and add the following code. Then, click Done.
                msg.facebookevent = msg.messagingEvent;

                msg.payload = 'Hello, this is all I say for now.';

                return msg;

              1. Double-click the facebook messenger node, name it Messenger Writer, and enter the Access Token that you previously copied. Then, click Doneand deploy your flow.

                1. Go back to Facebook Messenger and try out your bot.

                Your Facebook application can now listen to messages and respond