Create OpenWhisk Action

  1. Click the edit icon at the bottom right of the screen to bring up the create a New OpenWhisk Action page.
Figure 1. Figure 428  Create OpenWhisk Action Page
  1. Fill the Action Name and Code fields.
  2. Click the Submit button to save and create the action in IBM Cloud OpenWhisk space associated with your BigFix AEX Instance.
  1. Guidelines for writing the OpenWhisk functions:

    It is recommended to structure your code as shown below as it follows the coding best practices:

    /*
     OPENWHISK SKELETON
     */
     //########################## DECLARE REQUIRED MODULES ##############################
     var MODULE_NAME = require('MODULE_NAME');
     var request = require('request');
     //########################## DECLARE REQUIRED MODULES ##############################
     //########################## DECLARE GLOBAL VARIABLES ##############################
     var URL = 'http://www.google.com';
     //########################## DECLARE GLOBAL VARIABLES ##############################
     //########################## DECLARE CONSTANTS #####################################
     const METHOD_TYPE = 'GET';
     //########################## DECLARE CONSTANTS #####################################
     //########################## MAIN FUNCTION HAVING THE INTENDED CODE ################
     function main(params){
     //########################## DECLARE REQUIRED VARIABLES ###########################
     var RESULT;
     //########################## DECLARE REQUIRED VARIABLES ###########################
     //########################## CODE HAVING PARAM DECLARATION AND REQUEST DETAILS #####
     var options = {
     method: METHOD_TYPE,
     url: URL
     }
     //########################## CODE HAVING PARAM DECLARATION AND REQUEST DETAILS #####
     //########################## PROMISE DECLARATION ##################################
     return new Promise(function(resolve, reject){
     request(options, function(error, response, body){
     //########################## RESPONSE MANIPULATION AND STATUS CHECK CODE #########
     if(error){
     RESULT = 'ERROR: '+error;
     }else{
     RESULT = body;
     }
     //########################## RESPONSE MANIPULATION AND STATUS CHECK CODE #########
     });
     resolve({"message": RESULT});
     });
     //########################## PROMISE DECLARATION ##################################
     }
     //########################## MAIN FUNCTION HAVING THE INTENDED CODE ################
    The console only facilitates the creation of function that can be used for Integration and will not validate the functionality or the correctness of the function.

    The OpenWhisk function should not allocate more than 256MB of RAM/MEMORY for its variables and constants. If it does, its execution will be aborted.

    The OpenWhisk function should finish execution and return within maximum of 60 seconds, otherwise it will be timed out.

    Since node.js code is asynchronous, use the PROMISE construct to write a synchronous block of code. It is not necessary to use Promise in case the function is not going to wait on a request or the IO operation. But, to avoid any confusion it is best to use the Promise. Failing to use promise might result in execution completion of the action before the request or IO operation is completed.

    For advanced debugging needs, it is recommended to first write the function in your local machine and debug/test it thoroughly. Then the code can be pasted here.

    The OpenWhisk function’s output must be a JSON object. For majority of the scenarios, the output JSON object must contain the key, “message” and its corresponding value. This value is the one that is shown to the user as BigFix AEX’s response or sent to Watson Assistant for further interpretation. If the output JSON does not contain the key, “message”, then the message to be displayed to the user must be constructed from the other keys of the JSON output. This needs to be done in the configuration of the “Integration” that invoked the OpenWhisk function.

    1. The OpenWhisk function must make use the params input variable (a JSON object) that contains the key/value pairs passed to it from the invoker.
  2. The OpenWhisk function can modify the flow of messaging back to the user chatting with BigFix AEX or send information to the Watson Assistant, by using “Integration Application Parameters”, “Session Parameters”, and “Profile/Context Variables” of the Integration Configuration.