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
‘Slack2Watson (1): Connect API Connect to Serverless OpenWhisk’ is part 1 of an application called Slack2Watson, which integrates a ChatBot into Slack and allows you to retrieve information about events via Slash Commands in Slack. In part 1, I will set up the ‘API Connect’ service and link the APIs in ‘API Connect’ to the OpenWhisk functions.
Integration is managed using API management in ‘API Connect,’ serverless or event-based APIs in OpenWhisk, and IBM Watson to create the Conversation bot. Some data is retrieved via Google Sheets API.
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"
Under ‘Boilerplates’, click the ‘Java Cloudant Web Starter’,
For ‘App name’ and ‘Host name’ enter ‘<username>-liberty-watson’,
Click the ‘Create’ button,
In ‘Application Details’ click the ‘Overview’ link,
Review the application configuration,
Click ‘Connections’ and click ‘Connect New’ to create the following services:
If no AlchemyAPI service already exists, create a new AlchemyAPI service by clicking the ‘Connect New’ button,
from the Catalog, filter by ‘Watson’, select the AlchemyAPI service, click the ‘Create’ button, and click ‘Restage’
Note: by default you can only create 1 instance of the AlchemyAPI service under your organization in a single space, creating a second instance or connecting an existing service in another space will cause an error. If an instance already exists, click the ‘Connect Existing’ instead, select the existing AlchemyAPI service and click the ‘Connect’ button, click ‘Restage’,
2. Add the Toolchain or Continuous Integration (CI)
The source code for the application can be viewed or cloned from Github.
1. Create a Starterapp
Go to Catalog > Boilerplates
Click the ‘Python Flask’ starterapp
For name enter <username>-newssentiment
Go to Overview
Under ‘Continuous Integration’ click ‘Add GIT Repo and Pipeline’ to add a DevOps platform, select ‘Populate the repo with the starterapp packageand enable Build & Deploy pipeline’ > Click Continue > Click ‘CLOSE’.
Click ‘EDIT CODE’.
The very first time you login to the ‘DevOps’ environment you will need to pick a username for the ‘DevOps’ environment.
In the left menu of icons, click the top folder icon, and click ‘Git URL’ to copy the Git repository url.
If you prefer to edit in the online editor in Bluemix, click ‘EDIT CODE’ button and then click the second pencil icon in the left menu of icons.
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.