198 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Deploying MicroProfile based Java Applications to Bluemix
Fri, Sep 22nd 2017 4
Deploying MicroProfile based Apps to IBM Cloud private
Thu, Sep 21st 2017 46
Watson Machine Learning Sample Walkthrough
Tue, Sep 19th 2017 43
Some Pictures from Hack.IAA
Tue, Sep 19th 2017 97
My Favorite Tech Talks for Developers
Mon, Sep 18th 2017 131
Running Cloud-Native Applications On-Premises
Mon, Sep 18th 2017 77
Node-RED Samples for IBM Watson IoT Hackathon
Mon, Sep 11th 2017 17
Top 10
My Favorite Tech Talks for Developers
Mon, Sep 18th 2017 131
Some Pictures from Hack.IAA
Tue, Sep 19th 2017 97
Running Cloud-Native Applications On-Premises
Mon, Sep 18th 2017 77
Deploying MicroProfile based Apps to IBM Cloud private
Thu, Sep 21st 2017 46
Watson Machine Learning Sample Walkthrough
Tue, Sep 19th 2017 43
Deploying Angular 2 Apps to Bluemix
Tue, Apr 11th 2017 25
Node-RED Samples for IBM Watson IoT Hackathon
Mon, Sep 11th 2017 17
Building Slack Bots with IBM Watson Conversation
Mon, Jun 26th 2017 13
Building Alexa Skills with IBM Watson and OpenWhisk
Thu, Jun 29th 2017 13
Simple Sample of the Watson Document Conversion Service
Wed, Jan 27th 2016 11


Building Slack Bots with IBM Watson Conversation
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Niklas Heidloff    

I’ve open sourced a simple sample that shows how to leverage IBM Watson Conversation in Slack bots via the open source project Botkit. With Botkit and a Watson middleware text messages defined in Conversation dialogs can easily be used in Slack bots. My sample shows additionally how to use Slack buttons in messages and how to invoke business logic at certain stages of the conversation.

Botkit is an open source framework to build bots that can be connected to popular messaging platforms like Slack and Facebook Messenger. IBM provides a middleware to easily leverage the conversation flows defined in Watson Conversation dialogs. The following code shows how to pass user input to Watson and how to return text messages to Slack.

var watsonMiddleware = require('botkit-middleware-watson')({
  username: YOUR_CONVERSATION_USERNAME,
  password: YOUR_CONVERSATION_PASSWORD,
  workspace_id: YOUR_WORKSPACE_ID,
  version_date: '2016-09-20',
  minimum_confidence: 0.50
});

slackController.middleware.receive.use(watsonMiddleware.receive);
slackBot.startRTM();

slackController.hears(['.*'], ['direct_message', 'direct_mention', 'mention'], function(bot, message) {
    bot.reply(message, message.watsonData.output.text.join('n'));
});

In order to provide the best possible user experience my sample shows how to use Slack buttons in messages so that users can, for example, easily pick one of the available options. Additionally the sample demonstrates how to invoke a REST API provided by Weather Company Data. Here is a simple sample conversation.

slack

Slack provides a Message Builder to define sophisticated JSON messages that include elements like buttons. Watson Conversation is a general purpose tool and doesn’t support messaging client specific functionality. In order to include the Slack message I’ve put the JSON into a context attribute in a dialog node.

workspace1

This is the complete JSON:

{
  "output": {
    "text": {
      "values": [
        "In which city? Berlin, Munich or Hamburg?"
      ]
    },
    "context": {
      "slack": {
        "attachments": [
          {
            "title": "Which location?",
            "actions": [
              {
                "name": "Berlin",
                "text": "Berlin",
                "type": "button",
                "value": "Berlin"
              },
              {
                "name": "Munich",
                "text": "Munich",
                "type": "button",
                "value": "Munich"
              },
              {
                "name": "Hamburg",
                "text": "Hamburg",
                "type": "button",
                "value": "Hamburg"
              }
            ],
            "callback_id": "123",
            "attachment_type": "default"
          }
        ]
      }
    }
  }
}

When the ‘slack’ attribute is part of the message, the content of this attribute is sent as message to Slack rather than the text message defined in the Conversation dialog.

Similarly I’m using another attribute ‘action’ to mark a node in the dialog as the stage where business logic is triggered, in this case a REST API to the weather service is invoked. Note that you can put the chosen location entity into the JSON.

{
  "output": {
    "text": {
      "values": [
        "looking up weather information for @location ..."
      ]
    },
    "context": {
      "action": {
        "name": "lookupWeather",
        "location": "@location"
      }
    },
    "selection_policy": "sequential"
  }
}

This is the JavaScript code for the action.

function lookupWeather(watsonDataOutput, bot, message) {
    let coordinates;
    let location = watsonDataOutput.context.action.location;

    switch (location) {
        case 'Munich':
            coordinates = '48.13/11.58';
            break;
        case 'Hamburg':
            coordinates = '53.55/9.99';
            break;
        default:
            coordinates = '52.52/13.38'; // Berlin
    }

    let weatherUsername = process.env.WEATHER_USERNAME;
    let weatherPassword = process.env.WEATHER_PASSWORD;
    let weatherUrl = 'https://' + weatherUsername + ':' + weatherPassword + '@twcservice.mybluemix.net:443/api/weather/v1/geocode/' + coordinates + '/observations.json?units=m&language=en-US';

    request(weatherUrl, function (error, response, body) {
        var info = JSON.parse(body);
        let answer = "The current temperature in " + info.observation.obs_name
            + " is " + info.observation.temp + " °C"
        bot.reply(message, answer);
    })
}

Check out the GitHub project for more details and the setup instructions.

The post Building Slack Bots with IBM Watson Conversation appeared first on Niklas Heidloff.



---------------------
http://heidloff.net/article/slack-ibm-watson-conversation-botkit
Jun 26, 2017
14 hits



Recent Blog Posts
4
Deploying MicroProfile based Java Applications to Bluemix
Fri, Sep 22nd 2017 2:50p   Niklas Heidloff
Eclipse MicroProfile is an open source project to optimize Enterprise Java for microservices architectures. MicroProfile based applications can be deployed to Kubernetes. This article describes how to build microservices via the Microservice Builder and how to deploy them to Bluemix. The Microservice Builder provides functionality to easily create new Java based microservices. Below is a quick walkthrough how to create new microservices, how to run them locally and how to deploy them to Kubernet
46
Deploying MicroProfile based Apps to IBM Cloud private
Thu, Sep 21st 2017 2:30p   Niklas Heidloff
Eclipse MicroProfile is an open source project to optimize Enterprise Java for microservices architectures. MicroProfile based applications can be deployed to Kubernetes. This article describes how to deploy a sample application to IBM Cloud private. IBM Cloud private is a Kubernetes based platform to run cloud-native applications on-premises. It also comes with a Docker image registry. For developers there is a community edition available to run everything in one virtual machine. The example I&
43
Watson Machine Learning Sample Walkthrough
Tue, Sep 19th 2017 3:37p   Niklas Heidloff
Last month IBM announced the general availability of Watson Machine Learning which can be used by data scientists to create models and it can be used by developers to run predictions from their applications. Below is a simple sample walkthrough. As sample scenario I’ve chosen the Titanic dataset to predict whether people would have survived based on their age, ticket class, sex and number of siblings and spouses aboard the Titanic. I picked this dataset because it seems to be used a lot in
97
Some Pictures from Hack.IAA
Tue, Sep 19th 2017 7:34a   Niklas Heidloff
Last week I attended Hack.IAA, a hackathon with a focus on Artifical Intelligence and Car-2-X Communication organized by DigitalLife@Daimler. 60 students had 24 hours to come up with new business models and innovative solutions. IBM provided access to the IBM Cloud and Watson and helped participants with technical questions. I had great discussions with the students and enjoyed the event. The students used some of the Watson services like Visual Recognition and Conversation, technologies like No
131
My Favorite Tech Talks for Developers
Mon, Sep 18th 2017 3:21p   Niklas Heidloff
During my workouts I enjoy watching tech talks to learn about new technologies and trends. I’ve created a YouTube playlist with some of my favorite tech talks. The videos in the playlist are awesome sessions from great speakers like Martin Fowler, Brian Will, Erik Dörnenburg, Kevlin Henney and Jonas Bonér. The sessions cover topics like cloud-native, microservices, functional programming, reactive programming, engineering culture, coding best practises and more. The post My Favorite Tec
77
Running Cloud-Native Applications On-Premises
Mon, Sep 18th 2017 2:30p   Niklas Heidloff
Cloud-native applications have a lot of advantages compared to monolithic architectures such as scalability and elasticity. Cloud-native platforms typically also provide services that developers can use without having to worry about infrastructure. These advantages are available in public clouds and now also in some private clouds which is important for companies with high data security and privacy requirements. Recently IBM announced IBM Cloud private. The wiki describes the key features: IBM C
17
Node-RED Samples for IBM Watson IoT Hackathon
Mon, Sep 11th 2017 11:49a   Niklas Heidloff
Recently I gave an one hour webinar to help developers to prepare for a hackathon related to IBM Watson IoT. I demonstrated Node-RED and coded live some sample flows. Get the sample flows from GitHub. Functionality: Getting started with the Watson IoT Quickstart Using the IoT Starter Building simple web user interfaces via the Node-RED Dashboard Invoking REST APIs and implementing REST APIs Leveraging Watson services: Conversation, Translation, Tone Analyzer, Text to Speech Here is a screensho
5
Securing Kubernetes Applications with Vulnerability Advisor
Tue, Sep 5th 2017 7:58a   Niklas Heidloff
The Bluemix Vulnerability Advisor checks the security status of container images before deployments as well as the status of running containers. For example it can detect weak passwords, whether SSH is installed or whether images have known vulnerabilities. The Vulnerability Advisor leverages various sources like the CentOS announce archives and Red Hat RHSA announce archives to know about vulnerabilities and it calculates risk based on the IBM X-Force Exchange technology. While this functional
6
Tool to manage all Bluemix CLIs
Fri, Sep 1st 2017 7:33a   Niklas Heidloff
As a Bluemix developer you typically need to use several CLIs (command line interfaces). There is a specific CLI for Bluemix with multiple plugins to manage Bluemix applications and services. Additionally you can use third party CLIs like Docker, Kubernetes and Cloud Foundry against Bluemix. Recently a new tool has been published for macOS ‘IBM Cloud Application Tools 2‘ (beta). I find this tool pretty useful since you can install and update all CLIs with a few clicks. In the past I
4
Introducing the Conversation Optimizer for IBM Watson
Tue, Aug 29th 2017 8:18a   Niklas Heidloff
In order to develop conversational experiences it’s important to understand how users are actually using bots. Based on this data conversational experiences can continuously be improved. Watson Conversation comes with an improve component which helps analyzing and improving bots. Dependent on the service plan all conversations from the last 7, 30 or 90 days are stored. Via the Watson Conversation web interface you can get an overview of the interactions between users and bots, for example




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition