(by Scott Chapman)

Well, sort of. I am really talking about using Serverless technology to build Watson Workspace Apps. For those that are unfamiliar Serverless architectures are essentially ones where you focus on your code, and leave the running of it to the experts. In this particular case I am talking about IBM Cloud Functions (based on Apache Openwhisk) for my Serverless technology. I mean what could be cooler right?

Truth be told, I work on Watson Workspace. In Watson Workspace, users collaborate in a space, a virtual workspace. They can converse, share files, work with other tools and more. There are cognitive capabilities such as moments and action fulfillment built in. As an app developer, there is a lot you can do to enhance that experience.

Who doesn’t like to write apps? But, no one wants to do all the DevOps associated with it. IBM Cloud Functions (built on Apache OpenWhisk) is a great way to focus on the fun (code writing) and let a company like IBM manage everything else. The basic fundamental building blocks of applications in IBM Cloud Functions are:

  • Actions — Actions are basically functions; they take an input and produce some output
  • Triggers — Triggers are input sources. There is no code associated with them, and are generally used for eventing.
  • Rules — The association of Triggers with Actions. Basically the events from the trigger become input to the Action specified in the Rule.
    Rule trigger action flow diagram
  • Sequences — The linking of Actions together such that the output of one Action goes to the input of the Next action.
    Action sequence diagram

With that I’ve created a basic Watson Workspace application that simply listens for a specific message pattern (in this case a message that starts with “can you echo…”) and will provide a canned response (in this case “You bet I can!”). Nice and simple, and a good starting place for any Watson Workspace application. You can find my code and detailed instructions here on Github, but let me walk you through what I did, because I found it really satisfying…

To start you need to log into your IBM Cloud Account. IBM Cloud Functions maintains namespaces based on your Organization and Space names (e.g. <org>_<space>), so personally I like to create a new space when I start something new.

With the new space I start off by creating a package for my functions. The purpose of the package is to not only keep my related functions together, but because I can leverage a mechanism called “Package Parameters”. Package Parameters are like default values that are included in the input of every Action contained within the Package making it perfectly suited for things like configuration parameters and other static data. If you want Environment Variables, Parameters are the closest analog. So I create a package for my functions called “WatsonWorkspace” and create Watson Workspace App parameters (e.g. AppId and secrets).

With that in place I create my first Action. The action needs to perform a number of things. You can see code for this in my repo.

  1. A REST endpoint to register with my Watson Workspace App
  2. Verify that all incoming traffic is coming from Watson Workspace.
  3. Return a Verification response when requested during registration.
  4. Publish all incoming events to a Trigger.

I will also need an action to generate and manage my Watson Workspace App token, along with an action to send a message back to Watson Workspace.

Now my building blocks are in place. I have a Trigger where events generated by Watson Workspace will come in, and I have an Action that can generate a message. These can be used by any application you want to write.

Remember what I wanted to write? Something that checks to see if a specific message came in, and if so generate a specific response? Well, here it is:

Application code

That’s it, simply checking to see if there is any content, if it begins with “can you echo” and responds with “Why yes I can!”.

To put it all together I simply create a sequence linking my Echo function to the Send Message function. Then create Rule linking the Trigger with my Sequence.

Echo sequence diagram

Boom! You can find my code (with examples) on Git.

This post was originally published in Scott’s blog at https://medium.com/@scottedchapman.

Join The Discussion

Your email address will not be published. Required fields are marked *