Thursday, November 3, 2016

IBM Watson Workspace -- Code Talks So Here's The First Samples

View Comments
Time for the next post on IBM Watson Workspace. In this post I wanted to share some code samples that could help you get going in your development of apps for IBM Watson Workspace using the IBM Watson Work Services and APIs.

I know many developers, including myself, learn a lot from code samples (probably more than using actual API documentation). So to build on my post from earlier this week, we have published the first 5 code samples into the Watson Work org in Github and there should be more posted this week and next. My samples are the Twitter and Weather apps. I built these as fully functioning apps that you can deploy to a server and get up and going in a few minutes. And once they are running, feel free to hack away!

To make things simpler, I've also included a one-click button to deploy the app to Bluemix (which I thought was freaking cool how they make this possible). This, however, is not a required step. If you want to use with another cloud provider, by all means. Back to Bluemix, when you click the button, Bluemix pulls down the code from Github and magically gets it up and running.

One cool thing is that even before the samples were available, I already picked up a few blogs of developers using the APIs:
even one creating an Eclipse plug-in that was able to get something going in < 1 hour ( I love hearing those stories):

So quick tour of the Weather app. It uses the Weather Underground APIs to get current conditions based on a US zipcode. I use the node module to convert the zip code to city and state:
const cityState = zipcode.lookup(zc);

With that info, I now call the Weather Underground APIs to get the current conditions:

client.conditions(opts, function(err, data) {

Now with the data that I get back, I build a message to post back to IBM Watson Workspace and put it in the appropriate JSON construct:

const messageData = {
type: "appMessage",
version: 1.0,
annotations: [
type: "generic",
version: 1.0,
color: "#D5212B",
title: "Current weather conditions",
text: message

and then call the API to post it back:

request(sendMessageOptions, (err, response, body) => {

So that should give you an idea on how to listen to a conversation, act on it, and then respond back. I followed a similar flow to build the Twitter app and my hope is you can take it and hack it to build your own.  And if you are in the mood to help improve these samples, pull requests are welcome!

Now definitely check out what Redbooth, Rocket, OpenTopic, Sapho and others have done... VERY COOL! (and just to make it more enticing.. Sapho for example has Marketo and Google Adword integration... )

blog comments powered by Disqus