article by Frank Nimphius, June 2019

 

The Oracle Bots Node.js SDK  includes a command line utility that you can install globally on your local computer and that lets you easily create new custom component and custom component projects.

The custom components created by the Oracle Bots Node.js SDK contain a "hello world" content that contains examples fo the two main function calls: metadata() and invoke(). In addition, the invoke() function implementation shows example code for how to access input parameters ("human" in the example), how to print responses to the bot ("conversation.replay(…)) and how to pass control back to the bot ("done()").

Unless "hello world" is all you need to build, or if this is the first time you use the Oracle Bots Node.js SDK to create custom components, you may be interested to learn how to customize the template to contain e.g. the author name, a use license and more. Especially when working in teams you may want to enforce consistency across custom components that are integrated, which includes a common set of input parameters (e.g. always use "variable" as an input parameter for the reference to the dialog flow variable to update (like system components do).

This article explains how to modify the component template in a global Oracle Bots Node.js SDK installation. 

Finding the Oracle Bots Node.js SDK Component Template

ON A MAC, the custom component template (custom.js) is located in the grayed out usr folder. 

<hard drive>/usr/local/lib/node_modules/@oracle/bots-node-sdk/bin/templates/component/custom.js

ON WINDOWS, you find the same file in the following directory

<user account name>/roaming/npm/node_modules/@oracle/bots-node-sdk/bin/templates/component/custom.js

In the screenshot below, the @oracle folder contains two entries: bots-node-sdk and ojet-cli. If you don't see "ojet-cli" then this means that you don't use Oracle JET for your single page application development. You don't need Oracle JET for building custom components, so only the bots-node-sdk folder is what matters.

To customize the component template, open the custom.js file in a text editor.

Customizing The Component Template

The default content of the custom.js file is the "hello world" template you see by default. As mentioned, it is a good starting point and contains all you need to deploy and run the custom component. 

The screenshot below shows a modified version. Note that the license text needs to be fully surrounded by a pair of /* … */ (the  "/*" is missing in the screen shot below). Notice the other changes in the sample below

  • Author name
  • input parameter name changed to "name"
  • No "hello world" content

Once you changed the content and create a new custom component project (see image below), the initial file that gets created has the new content

"BuyFlowers.js" is the file created by Oracle Bots Node.js SDK and …

… contains the modified content. 

Extra Tip

Using the command below, you can create  a custom component in an existing custom component project and save it in a sub-folder of the "components" folder.

bots-node-sdk init component –name <the_component_name> components/<your_subfolder>

 

e.g. 

 

bots-node-sdk init component –name TrackDelivery  components/delivery

 

 

 

 

This command created the following folder structure:

 

 

Related Content

TechExchange – Tutorial: Building Custom Component Services for Oracle Digital Assistant in Under 5 Minutes with Oracle Bots Node.js SDK

TechExchange – Tutorial: How-to Debug Custom Component Services Deployed to Oracle Digital Assistant Skill Bot Local Component Container

 

Author