What are NodeJS providers?

What are NodeJS providers?

With providers you can create customized conversational flows with the end-user.

Note: Contact your Customer Success Manager for more information about what providers can do.

A Node JS provider is one of the most versatile providers. Its Node JS code runs on lambda for certain events of the knowledge base to provide custom information for the bot to use. Node JS runs on two AWS Lambda instances: one for the getEntity logic and one for the detect logic. They have a default maximum of three seconds per each call and have a lifespan of about 20-30 minutes from its first call. This means you can cache items on a lambda, but only up to 20-30 minutes.

Creating a Node JS Provider

To create or update a provider, in Bold360 AI, go to Admin Center > KB Setup > Providers and choose Add Provider.

To call the providers that you create, add the entity that the provider represents to the article as [[ENTITY_NAME]] and call that article in your bot.

NodeJS workflow

Details to expand on

  • Runs on a Lambda AWS instance
  • Supported Entities
    • Defines which entities this provider should handle
  • Dependencies
    • Defines which entities an entity depends on in order to be used
  • getEntities
    • Used to get entities based on the information collected and to define if there are any missing entities needed
    • This should always return something with the nano.sendGetEntitiesResult()
    • When you return a missing entity, make sure the name and missingVarText are filled out. Else it will not work, and you'll never figure out why.
  • detect
    • Used to detect intents in a set of tokenized words and create entities based on those words
    • If it doesn't capture anything in the tokens, it should let the function end and not try to return anything or run any callbacks

Response format

getEntity
this.sendLambdaResult(callback, {
    "resultEntities": [],
    "missingEntities": []
});
detect
this.sendLambdaResult(callback, [resultEntity1, resultEntity2])

URL Button

var storeExistsEntity = nano.createEntity({
    "name": "STORE_CITY_EXISTS",
    "kind": "STORE_CITY_EXISTS",
    "type": "quickOption",
    "_public": "true",
    "lifecycle": "statement",
    "value": "Store Locator",
    "properties": [{
        "kind": "url",
        "value": "www.google.com",
        "type": "text",
        "name": "Display Text"
    }]
});
 
//  nano.addProperty(storeEntity,"ADDRESS1","text",store[5],"ADDRESS1");
console.log("this is the entity" + JSON.stringify(storeExistsEntity));
 
//var entities = [storeEntity];
return nano.sendGetEntityResult(callback, [storeExistsEntity]);

Quick Option

To return a quick option with text above it, return the following entities. In the article body, add ONLY [[OPEN_MESSAGE]] and NOT [[OPEN_INCIDENTS]]. The system adds the options that return a statement.

incidents.push({
            "name": "Incident Name:",
            "kind": "statement",
            "value": "What is the status of " + result[i].number,
            "type": "text"
          });
  
var entityOpenIncidents = nano.createEntity = {
            "name": "OPEN_INCIDENTS",
            "kind": "OPEN_INCIDENTS",
            "type": "quickOption",
            "_public": "true",
            "lifecycle": "statement",
            "value": "I see that you have " + count + " " + ticketText + " open. Which one woulyou like me to assist you with?",
            "properties": incidents
};
if (!arr) var arr = [];
arr.push(entityOpenIncidents);
 
var entityOpenMessage = nano.createEntity = {
            "name": "OPEN_MESSAGE",
            "kind": "OPEN_MESSAGE",
            "type": "text",
            "_public": "true",
            "lifecycle": "statement",
            "value": "I see that you have " + count + " " + ticketText + " open. Which one woulyou like me to assist you with?",
};
     return nano.sendGetEntityResult(callback, [entityOpenIncidents, entityOpenMessage]);

Multiple Choice Buttons

This allows you to add a button for your users to click on. You must return an error entity as well as the missing entity that you want the result to refer to.

Adding a button
let sizes = result.map((e) => e[2]);
var multichoice = {
    "kind": "text",
    "type": "error",
    "value": "Please choose one of the sizes below::",
    "_public": true,
    "properties": []
};
nano.addProperty(multichoice, "type", "text", "multichoice");
nano.addProperty(multichoice, "header", "text", "Please choose one of the sizes below:");
  
let numOfOptions = 0;
for (let size of sizes) {
    ++numOfOptions;
    let option = nano.addProperty(multichoice, "" + numOfOptions, "text", size);
    nano.addProperty(option, "text", "text", size);
    nano.addProperty(option, "statement", "text", size);
    nano.addProperty(option, "quickOption", "text", size);
}
nano.addProperty(multichoice, "count", "number", numOfOptions);
 
return nano.sendGetEntityResult(callback, [multichoice], "PRODUCT_SIZE_US");

Then send that back as an entity in the result:

MultiChoice properties
Property Description
count The number of options
quickOptionStyle

'statement'

'numbers'

'disabled'

header Header to add before the options list
footer Footer to add after the options list
MultiChoice option properties
Property Description
text Text to display in the response message when the button is clicked
statement The STATEMENT to execute when selecting the option
quickOption The text displayed in the button
quickOptionType inlineOption
type (Optional) - There is only one, called share_location

Carousel

To add a carousel to the screen, you should first create an entity with the following object. You cannot use custom HTML in the text property because that is escaped.

let carouselObject = {
    "type": "carousel",
    "items": [{
        "title": "Apple iPhone",
        "subtitle": "Say hello to the future",
        "imageUrl": "https://cdn-customers.nanorep.com/customers/product_demo/assets/apple-iphone.jpg",
        "options": [{
            "isDefault": true,
            "type": "url",
            "text": "Product Page",
            "value": "https://www.apple.com/iphone/"
        }, {
            "type": "url",
            "text": "Models",
            "value": "https://www.apple.com/iphone/compare/"
        }]
    }, {
        "title": "Apple iPad",
        "subtitle": "Anything you can do, you can do better",
        "imageUrl": "https://cdn-customers.nanorep.com/customers/product_demo/assets/apple-ipad.jpg",
        "options": [{
            "isDefault": true,
            "type": "url",
            "text": "Product Page",
            "value": "https://www.apple.com/ipad/"
        }, {
            "type": "url",
            "text": "Models",
            "value": "https://www.apple.com/ipad/compare/"
        }]
    }, {
        "title": "Apple Macbook",
        "subtitle": "Light. Years ahead",
        "imageUrl": "https://cdn-customers.nanorep.com/customers/product_demo/assets/apple-macbook.jpg",
        "options": [{
            "isDefault": true,
            "type": "url",
            "text": "Product Page",
            "value": "https://www.apple.com/macbook/"
        }, {
            "type": "url",
            "text": "Models",
            "value": "https://www.apple.com/mac/compare/"
        }]
    }, {
        "title": "Apple TV",
        "subtitle": "The 4K HDR era. Now playing",
        "imageUrl": "https://cdn-customers.nanorep.com/customers/product_demo/assets/apple-tv.jpg",
        "options": [{
            "isDefault": true,
            "type": "url",
            "text": "Product Page",
            "value": "https://www.apple.com/tv/"
        }, {
            "type": "url",
            "text": "Models",
            "value": "https://www.apple.com/tv/compare/"
        }]
    }, {
        "title": "Apple Watch",
        "subtitle": "Make calls and send texts with just your watch",
        "imageUrl": "https://cdn-customers.nanorep.com/customers/product_demo/assets/apple-watch.jpg",
        "options": [{
            "isDefault": true,
            "type": "url",
            "text": "Product Page",
            "value": "https://www.apple.com/watch/"
        }, {
            "type": "url",
            "text": "Models",
            "value": "https://www.apple.com/macbook/specs/"
        }]
    }]
};

Finally, save the article in Source mode.