(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.
- Sequencesâ€Šâ€”â€ŠThe linking of Actions together such that the output of one Action goes to the input of the Next action.
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.
- A REST endpoint to register with my Watson Workspace App
- Verify that all incoming traffic is coming from Watson Workspace.
- Return a Verification response when requested during registration.
- 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:
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.
Boom! You can find my code (with examples) on Git.
This post was originally published in Scott’s blog at https://medium.com/@scottedchapman.