Category Archives: api

Messenger2Watson(1): Connect Facebook to a Watson Chatbot

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.

Steps:

  1. Create a Flow to Verify the Request for Webhook Edits in Node-RED,
  2. Create an Endpoint for the Redirect URL of the Webhook in Node-RED,
  3. Create a Facebook Application for the Messenger Platform,
  4. 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
    hub.verify_toke
  • Continue reading

Slack2Watson (1): Connect API Connect to Serverless OpenWhisk

‘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.

  1. Create API Connect API v1.0.0
  2. Publish the API
  3. Create an OpenWhisk action
  4. Connect API Connect to OpenWhisk

Requirements

This tutorial uses the OpenWhisk service and the API Connect service on http://bluemix.net, the IBM Cloud. Create an account on IBM Bluemix to run this tutorial.

1. Create API Connect API v1.0.0

  • Go to the Bluemix Catalog,
  • In the left menu select the ‘APIs’ category, and click the ‘API Connect’ service,
  • Click the ‘CREATE’ button to create the ‘API Connect’ service,
  • Click the ‘Sandbox’ icon to go to the Sandbox view with a list of products, which currently says ‘There are no products available in the selected catalog.’,
  • Go to the ‘Navigate to’ icon next to the ‘Home’ icon, and click ‘Drafts’, which will take you by default to the ‘Drafts’ view in the ‘Designer’ perspective,
  • In the ‘Drafts’ view, you see a ‘Products’ tab and an ‘APIs’ tab, click the ‘APIs’ tab,
  • Click the ‘ADD’ button and add a ‘New API’ titled ‘<username>-slack2watson’
  • Title: ‘<username>-slack2watson’
  • Name: ‘<username>-slack2watson’
  • Base Path: /slack2watson
  • Version: 1.0.0

Continue reading

Creating a Nodejs App with Watson AlchemyAPI and CloudantDB

WIP

Requirements:

Overview:

  1. Setup
  2. Setup Details
  3. Add Watson AlchemyAPI
  4. Add Cloudant DB

Setup

  1. Login to Bluemix, in a separate tab login to Github,
  2. In Bluemix open Catalog->Boilerplates and create a ‘Node.js Cloudant DB Web Starter’ Boilerplate, named ‘<username>-nodejs-app1’, click CREATE
  3. Go to ‘Overview’, scroll down to ‘Continuous delivery’ and click ‘Enable’
  4. In the ‘Toolchain Settings’, change the name of the Toolchain to ‘<username>-nodejs-app1’, and click Create,
  5. 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,
  6. Go to your Github account and make sure that the repository for the new Bluemix app is created successfully,
  7. 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
    cd remkohdev-nodejs-app1
  8. Open the project directory in your favorite editor,
  9. Open the ‘package.json’ file and change the ‘name’ property to ‘<username>-nodejs-app1’,
  10. From the commandline, in your project directory,
    git status
    git add .
    commit -m "change package.json name property"

Continue reading

Getting Started: Creating a Java-Liberty App with Watson on Bluemix

An extended version of this tutorial, adding a Cloudant NoSQL Database and D3js data visualization, is available here.

Requirements:

  • Bluemix account
  • Github account

Steps:

  1. Create the StarterApp
  2. Add the Toolchain or Continuous Integration (CI)
  3. REST API Primer
  4. Authentication in REST API
  5. Getting the Bluemix Configuration
  6. Add the AlchemyData News API Client
  7. Add a Web Form
  8. Implement the AlchemyData News API Request
  9. Create Authorization Header for Basic Auth

1. Create the StarterApp

Continue reading

Creating Sentiment Line Chart for the News with Watson, Python, and D3js

Requirements:
You must have Python installed. Check to see if you have Python installed from the commandline:
python --version

Table of Contents:

  1. Create a Starterapp
  2. Git Clone and Setup
  3. Create Additional Folders and Files
  4. Commit and Push Changes to Repository, Build and Deploy
  5. Create an AlchemyAPI service
  6. Create a Cloudant NoSQL service
  7. Add the Basic Workflow for Request-Response
  8. Get News using AlchemyAPI
  9. Create Helper Functions
  10. Save Responses in Cloudant
  11. Parse Response for D3js
  12. Draw the Line Chart in D3js

You can import AlchemyAPI requests into Postman with this Postman collection.

The source code for the application can be viewed or cloned from Github.

1. Create a Starterapp

  1. Go to Catalog > Boilerplates
  2. Click the ‘Python Flask’ starterapp
  3. For name enter <username>-newssentiment
  4. Go to Overview
  5. 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’.
  6. Click ‘EDIT CODE’.
  7. The very first time you login to the ‘DevOps’ environment you will need to pick a username for the ‘DevOps’ environment.
  8. In the left menu of icons, click the top folder icon, and click ‘Git URL’ to copy the Git repository url.
  9. 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.
  10. I will continue to work on localhost instead.

Continue reading

QAVideos (3) – Extending the Data Model and Using Open API Initiative (OAI) in Node.js

(updated: 20170319) WIP
This is part 3 in a series to build a sample application called QAVideos using API Connect. QAVideos is a Question and Answer application that uses videos instead of text. Think of QAVideos as StackOverflow meets Youtube. QAVideos will use LoopBack, API Connect, Open API Initiative (OAI formerly Swagger.io), OpenWhisk, Object Storage.

  • In part 1 ‘QAVideos (Part 1), Adding User Management to Node.js’, I added User Management to a Node.js app using API Connect.
  • In part 2 ‘QAVideos (Part 2), Adding a Custom Model and ORM in Node.js‘, I added a custom data model, i.e. a Video model, and used ORM to persist the model to a PostgreSQL database.
  • In part 3 ‘QAVideos (Part 3), Extend Model and Using Open API Initiative (OAI) in Node.js‘, I extend the built-in User model with a Member, add a Question and Answer based on the Video model, and add a Sticker, while using the Open API Specification to define and manage the application and APIs.
  • 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.

Prerequisites

  • 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.
  • Get the source code from part 2 of this tutorial.
  • Install the ‘npm’ dependencies,
    npm install
  • Configure the file ‘~/server/datasources.json’,
  • 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

  1. The OAI Definition File
  2. 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.

Continue reading