In Slack2Watson(1) and (2) I created a chatbot and integrated it into Slack Slash Commands. Now, let’s integrate the same chatbot into Facebook Messenger. To accomplish this I need to create a Facebook Application, add the Messenger Platform to my Facebook Application, create a Webhook, have admin access to a Facebook Page to generate a Page Access Token so I can send and receive messages send to the Facebook Page, and create the Node-RED flows to integrate the Facebook Messenger with the IBM Watson Conversation.
Create a Flow to Verify the Request for Webhook Edits in Node-RED,
Create an Endpoint for the Redirect URL of the Webhook in Node-RED,
Create a Facebook Application for the Messenger Platform,
Enable Webhooks Integration with Node-RED,
Create a Flow to Verify the Request for Webhook Edits in Node-RED
To prepare the setup and configuration of the Facebook Application, the Messenger platform and Webhooks to enable a chatbot in Facebook Messenger, I will first create the Node-RED flows to implement the required server workflow.
The first flow is to verify the endpoint for the setup of the Facebook Application, using the ‘hub.challenge’ token.
Go to your Node-RED application on Bluemix at http://<username>-nodered-slackapp.mybluemix.net/,
Click the ‘Go to your Node-RED flow editor’ button,
If you’re not logged in yet, log in now,
Add a new flow tab and rename the flow ‘Facebook Messenger’,
To verify your endpoint during setup of your Webhook, or when you update an existing topic subscription of your Webhook, Facebook sends a GET request. The request will include: hub.mode=subscribe
hub.challenge â€” a random string
Login to Bluemix, in a separate tab login to Github,
In Bluemix open Catalog->Boilerplates and create a ‘Node.js Cloudant DB Web Starter’ Boilerplate, named ‘<username>-nodejs-app1’, click CREATE
Go to ‘Overview’, scroll down to ‘Continuous delivery’ and click ‘Enable’
In the ‘Toolchain Settings’, change the name of the Toolchain to ‘<username>-nodejs-app1’, and click Create,
If the Github THINK or CODE icon displays a configuration error, from the block’s dropdown icon in the topright, click the ‘Configure’ link to correct the configuration of your Github account,
Go to your Github account and make sure that the repository for the new Bluemix app is created successfully,
Copy the Git URL, on localhost open a commandline terminal, change to your development directory and clone the new repository, cd ~/dev/src/bluemix
git clone https://github.com/remkohdev/remkohdev-nodejs-app1.git
Open the project directory in your favorite editor,
Open the ‘package.json’ file and change the ‘name’ property to ‘<username>-nodejs-app1’,
From the commandline, in your project directory, git status
git add .
commit -m "change package.json name property"
The objective of this tutorial is to create two applications: a Node.js application that functions as a web client, and a Node-RED application that functions as the server. You will create an input form in the client that lets a user send a registration request to a server. The server will save the registration in a database and send a spoken response back to the client using IBM Watson’s Text to Speech service.
You must have access to a Bluemix account.
1. Create a Client Application with SDK for Node.js
First, I will create a Node.js web application, which will function as our client and we will create web pages to ask for user input. Technically, this client application is also running on a server, so it is perhaps confusing to call it a client, but in our scenario and architecture, this client application functions as the user interface that initiates the request to a processing server.
In next parts, the idea is to add other possibly features: deploy the OAI definition file to Bluemix via API Connect, add Object Storage for Video support, create an Ionic/Apache Cordova based mobile client, add an automated build, deployment and test script, add a Content Delivery Network (CDN) to the backend, add event-driven OpenWhisk APIs, containerize the application, add chat, and possibly more.
Node, npm, and API Connect must be installed,
Check if the â€˜apicâ€™ tool is installed, by running â€˜apic -vâ€™ from the commandline. If not installed, follow the installation instructions, here.
Test if QAVideos (part 2) is running correctly by typing â€˜apic startâ€™ in the root directory, open a browser and go to â€˜http://0.0.0.0:4001â€™ in your browser.
Table of Content
The OAI Definition File
Create the Extended Data Model
Open API Initiative (OAI, based on Swagger)
The OAI is based on Swagger.io, an API Framework. The OAI is an open API definition standard. Frameworks like API Connect use the OAI definition file to generate the server, client, data model and documentation.
MQTT is a publish-subscribe messaging pattern with a light-weight footprint, ideal for IoT devices. This tutorial will create a basic workflow via an MQTT Broker from device client to application server and back. To avoid any hardware dependencies in this tutorial I will simulate the device client and implement it as a Node.js server. The application server will also be a Node.js server.
Setup an MQTT Broker
Register a Device on the MQTT Broker
Create an API Key on the MQTT Broker
Create the IoT Device Client
Create the IoT Application Server
Publish Data from Client to Application via Broker
Send Commands from Application to Client via Broker
Check if the ‘apic’ tool is installed, by running ‘apic -v’ from the commandline. If not installed, follow the installation instructions, here.
Get the source code for part 1 of this tutorial and follow the installation instructions for QAVideos Release v1.0.0. First clone the repository, then make sure you fetch all the remote tags to your local repository, and then checkout the v1.0.0 tag. git clone https://github.com/remkohdev/qavideos.git
git fetch --all --tags --prune
git checkout tags/v1.0.0
Table of Contents
Create Data Model
Add Video Functionality
Add Data Source
1. Create Data Model
First, test if QAVideos (part 1) is running correctly. Open a commandline, change your directory to the root directory of your QAVideos application, type ‘apic start’, and browse to ‘http://0.0.0.0:4001‘ in your browser.
Now, I want to add a custom model ‘Video’ so that users can manage their list of videos. To do this, I create a model for the Video with the ‘apic’ tool, and define the relationship between Video and User (a User can own many videos), and specify the access level of Users to Video objects using an Access Control List (ACL). Continue reading →
QAVideos (1) â€“ Adding User Management to Node.js. Part 1 creates the ‘StrongLoop’ application with built-in User and Role management with authentication, with an API layer based on Open API Initiative (OAI), formerly Swagger.io, and I add an Angular.js based web UI.
The initial design of the QAVideos application is very simple. A user can register, login and logout. An authenticated user can create, update and delete videos to the platform and see a list of their videos. Unauthenticated users can see all videos.
If you are not familiar with IBM API Connect (formerly StrongLoop), it is an API platform for Node.js and includes Loopback to quicly compose and manage APIs, and use graphical tools like the API Connect Designer to create, edit, manage and deploy your APIs. I will use the Loopback library that is part of API Connect to compose the model and the APIs.
Create a Node.js with Express.js AppCreate a Git repository and clone to localhostAdd Angular.jsAdd BootstrapAdd MongoDbAdd JadeAdd an API for GET /peopleConnect to MongoDbCreate a sortable table with Angular
Create a Node.js with Express.js App
I will be using Bluemix to host, build and deploy my Node.js application and the MongoDb service. I am developing on my localhost for unit testing before I upload my application to Bluemix, but you can also use the online editor and online Git instead.