Facebook Watson Chat Bot
Hickmat 100000QA3T Comments (5) Visits (12851)
So hot on the heels of creating my "Chat Handler" I've created a Facebook Chat bot which uses it to call Watson The process to create a bot in Facebook was fairly straight forward and is well documented here but I did have to jump through some hoops to get my NodeRED flow registered as a Webhook and hence I thought it would be good to create this blog entry.
The first thing I did was to create a simple flow to act as the backend for the Facebook app I created which was going to support the "bot". I did this by setting up a very simple web listener which looked like:
The next step I needed to do was to create a flow in NodeRED which would act as the end point for the bots Webhook. This needed to support both GET and POST. The GET is there to support the registration handshake where as the POST is there to receive data from the Webhook. The flow I created looked like this:
To get the Webhook registered I needed to validate a passed token and return it back to Facebook... Easy enough... Well not as easy as I thought The JSON payload which Facebook passes has key names which imbed '.' so accessing them directly in NodeRED was a pain. In the end the "Handle Token Validation" function I created was:
With this in place I fired up Facebook and started chatting to the bot and it all worked In addition I checked I could run a chat via Telegram and Facebook at the same time and yep that all worked I've got some more testing to do and I need to tidy up some things but the basic concept I wanted to test worked. Now I need to look at what else I could hook in.... May be Slack will be my next target.