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.
-
- Go to the Node-RED Library page at http://flows.nodered.org. Search for
Messenger
.
- Go to the Node-RED Library page at http://flows.nodered.org. Search for
-
- Select the node named node-red-contrib-facebook-messenger-writer. You will add this node to your Bluemix palette.
-
- Open your Bluemix dashboard.
-
- Select your application.
-
- Find the Continuous Delivery section and click Edit Code.
-
- Stop your application.
-
- Edit the package.json file.
-
- 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",
- Add the following line. You can insert it anywhere. If you add it to the end, be sure to remove the final comma.
-
- Save your changes and deploy your application. Wait for your application to start.
- 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
-
- Wire the nodes together by wiring the new function node to the facebook messenger node and then to the debug (msg.payload) node.
-
- 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
;
- Double-click the new function node, name it Set up response, and add the following code. Then, click Done.
-
- 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.
-
- Go back to Facebook Messenger and try out your bot.
Your Facebook application can now listen to messages and respond