Compute Services

Serverless computing and Watson service chaining via OpenWhisk : Part 2 of 3 chaining the services

Share this post:

In Part 1 of this series, you learned the basics of Serverless computing and the building blocks behind OpenWhisk. In this post, you will create Watson Services  and add them to an OpenWhisk Sequence on IBM Bluemix.

As our post is all about chaining Watson Services using OpenWhisk, in this section you will create three Watson Services namely

  • Language Translator.
  • Speech to Text.
  • Text to Speech.

Creating Watson Services on Bluemix

  • Log into Bluemix account with your registered Email or IBMid.
  • Click on Catalog on the top bar. On the left pane click on Watson under Services

  • Select Language Translator and Click to create a new service.
  • Provide a unique Service name. If you are not sure what to mention leave the default name provided.
  • Leave the Credential name as it is.
  • (Optional) Read the Features and Pricing Plans.
  • Click on Create.

Note: Repeat the above steps to create Speech to Text and Text to Speech Watson Services.

Develop an OpenWhisk Sequence on a browser

In this section of the post, you will chain the Watson Services along with other actions to create a sequence that translates an input in en to fr.

  • Click on the hamburger menu   and select OpenWhisk.
  • You will see the landing page with two options – Develop in a Browser or Download OpenWhisk CLI.

  • Click on Develop in your Browser and you should see the Develop tab selected.
  • On the left pane, you will see tabs grouping your Actions, Sequences, Rules and Triggers.
  • Under My Actions, you should see two sample actions created for your reference namely Hello World and Hello World with Params. Both these actions are Node.JS 6 Actions.
  • Click on Create an Action. You are creating an OpenWhisk actionmyMessageSwiftAction. Choose SwiftV3 execution runtime, and, optionally, a sample from which to start, Choose Hello World in Swift. You can also choose to change the default quota settings, for this lab lets go with default Memory and Time Limit.

  •  Click on Create Action and you should see your action under MY ACTIONS tab. Select myMessageSwiftAction and replace the existing function code with the code below
func main(args: [String:Any]) -> [String:Any] {

if let message = args["message"] as? String {

return [ "payload" : "\(message)!" ]

} else {

return [ "payload" : "Hello stranger!" ]


Note: As output of one action is input to the next action, The JSON with payload will be an input to the next action you create in the sequence.

  •   Hit Make it Live to save your changes. Now Click Run the Action on the top and change the “message” JSON input. Run with this Value should invocate the action in a console and show the output with your input as a Payload output. Also, you can see the logs, Completed in and how many seconds are you Billed for.
  • Close the console and Click Link into a Sequence. You should see Configure a New Action Sequence with a variety of Packages to select from

Note: In IBM® Bluemix® OpenWhisk, you can use packages to bundle together a set of related actions, and share them with others.

  • Click on Watson Text to Speech tile and  Click on to create a new Package binding.

Note: Although you can use the entities in a package directly, you might find yourself passing the same parameters to the action every time. You can avoid this by binding to a package and specifying default parameters. These parameters are inherited by the actions in the package.

For example, in the /whisk.system/cloudant package, you can set default username, password, and dbname values in a package binding and these values are automatically passed to any actions in the package.

  • Let’s call this myWatsonTextToSpeech (Name for our configuration) and from the dropdown select the Text to Speech service which we created earlier.
  • (Optional) You can click on View Source to see the code.
  • Click on Add to Sequence to connect this to Swift Action which we created.
  • Click on This Looks Good to save your Watson Sequence and name it MyWatsonSequence. Also, run the sequence to see the output.
  • As you are not done with the chaining yet, Click on Extend and repeat the steps for adding Speech to Text package to the chain.
    • Name of the binding: myWatsonSpeechToText
    • In the dropdown, Choose the Speech to Text service which you created.
    • Click on Add to Sequence.
    • Click on This Looks Good to save your Watson Sequence.
  • Click on Actions and create a new action called myLanguageTranslator Which will convert the Speech to Text output to the JSON format of Watson Translator Package.
    • Execution Runtime – Node.JS 6
    • Start with a Blank State.
    • Create Action.
    • Replace the existing code with the code snippet below.
function main(params) {

return { payload: };


  • Click Make it Live to save your Action.
  • On the left pane under MY SEQUENCES, select MyWatsonSequence -> Extend -> My Actions Tile -> Select myLanguageTranslator and Click Add to Sequence
  • Click on Extend and Select Watson Translator
    • Select Translator as your Action.
    • Name of the Binding: myWatsonTranslator
    • Select the Language Translator Service which we created earlier.
    • Click on Add to Sequence.
  • Save your changes and Click on Run this Sequence to test your Watson Sequence.

Test: Json Input


"message": "hello"


Expected Output:

In this part, you completed the Watson service chaining via an OpenWhisk Sequence. You can chain other packages as well following the same steps.

Technical Offering Manager & Polyglot Programmer | IBM Cloud

More Compute Services stories
April 29, 2019

Transforming Customer Experiences with AI Services (Part 1)

This is an experience from a recent customer engagement on transcribing customer conversations using IBM Watson AI services.

Continue reading

April 26, 2019

Updated Tutorial: Database-Driven Chatbot

The tutorial on how to build a database-driven chatbot has been updated. It's now simpler to deploy and and offers more options—Slack, Facebook Messenger, Wordpress, and more.

Continue reading

April 24, 2019

How To Use IBM Cloud Object Storage with Veeam

As you may have heard, Veeam 9.5u4 now includes an integration with IBM Cloud Object Storage. This integration can result in up to 10x savings on long-term data retention and an overall reduction in IT and primary storage costs.

Continue reading