Andi® Chat Powers

Overview

When writing conversational skills, you can use the Andi® chat powers to identify and create the response that is returned to the user.

This article assumes familiarity with the information in Understanding Natural Language and Settings.

 

In this Article

 

How to call the chat powers

The chat powers will be called via the chat property of the Andi® power set.

skillcontext.powers.andi.chat.selectedChatPowerMethod?

 

What are the chat powers?

composeResponse

Returns a promise to compose a response that will display in the Andi® window when the user asks Andi® a question. This is most useful when seeking to heavily customize your chat responses.

It can consist the following parameters:

  • attachments - when defined, will be the results that display in the Andi® window. The attachment parameter consists of the following IChatResponseAttachment interface parameters:
IChatResponseAttachment {
    type?: string;
    definition?: string;
    articles?: IChatResponseArticle[
        {
            text: string, 
            url: string,
            type: string, 
            customIcon?: string
        }
    ];
    headerText?: string;
    footerText?: string;
    possibleActions?: IChatResponseAction[
        {
            text: string,
            action:string
        }
    ];
}

Not all attachment parameters are required. The parameters included will depend upon the goal of your response (see example code below). Once the attachment is defined, it is stored as an array in the AndiBotResponseModel.

  • possibleActions - when defined, is the action a user can take based on the response. The interface will be the same as defined above for possibleActions in attachments. Therefore, you could define your possibleActions in attachments or as its own separate parameter.

When composeResponse is used as part of the skill code, it will contain the following structure:

//returning a definition to a user
let attachmentA: andiSkills.IChatResponseAttachment = {
    type: 'definition',
    definition: "Maturity is the date on which the life of a transaction or financial instrument ends, after which it must either be renewed, or it will cease to exist."
};

return skillContext.powers.andi.chat.composeResponse([attachmentA])

//returning a custom resource to a user and utilizing the storage powers for article content
let attachmentB: andiSkills.IChatResponseAttachment = {
    type: 'customResource',
    articles: maturityArticle,
    headerText: "I'm sorry, I don't know how to do that yet, but I'll see if I can learn it. In the meantime, would you like someone to contact you?",
    possibleActions = [
        { text: "Yes", action: "andi-in-app-action contact-me-yes", decorations: ["Positive"] },
        { text: "No", action: "andi-in-app-action contact-me-learning-no", decorations: ["Negative"] }
    ];
};

return skillContext.powers.andi.chat.composeResponse([attachmentB])

 

sendResponse

Returns a promise to send a response that will display in the Andi® window when the user asks Andi® a question. This is most useful when seeking to heavily customize your chat responses.

It will consist of the following parameter:

  • message - this will generate the response defined as the attachment in the composeResponse

When used as part of the skill code, it will contain the following structure:

//returning a definition to a user
let attachmentA: andiSkills.IChatResponseAttachment = {
    type: 'definition',
    definition: "Maturity is the date on which the life of a transaction or financial instrument ends, after which it must either be renewed, or it will cease to exist."
};

return skillContext.powers.andi.chat.composeResponse([attachmentA])
    .then(response => skillContext.powers.andi.chat.sendResponse(response));

 

addArticle

This method allows you to add an article to the response that is returned to the user in the Andi® window. This is the preferred power to use to return simple chat responses rather than composeResponse and sendResponse, as this power targets the IChatResponseArticle array in the IChatResponseAttachment. The term 'article' is all encompassing for items that will either generate a text or hyperlinked response attachment. The method is composed of the following parameters:

  • text - the string that is displayed in the Andi® window 
  • url - the hyperlink for the article. This parameter isn't required and can link to any website, including your own intranet. However, adding a link allows you track whether or not users took action by selecting the hyperlink.
  • skillActivity - this is the skillActivity that results in the article being returned
  • location - this is where the article should appear in the list of articles that is returned.
return skillContext.powers.precisionLender.skills.getHelpContent
    .run()
    .then((response) => {
        let text = "Here is a link to Google's home page";
        let url = "http://google.com";

        // add an article to the message
        // response is the defined variable for the skillActivity
        skillContext.powers.andi.chat.addArticle(text, url, response, "First");
        return response
    });

 

getTopScoringIntent

Allows you to check for the top scoring intent, which will determine whether or not your skill will run or respond based on the logic you define.

For example, if you write a chat skill, defining an intent in the skillmanifest, and want the skill to run based on that intent, in the shouldIRun, you can use the getTopScoringIntent power to check for your intent, and if it is the top scoring intent, then your skill should run.

let topScoringIntent = skillContext.powers.andi.chat.getTopScoringIntent();
            
    if (topScoringIntent.intent === 'loan committee' && topScoringIntent.nluIntentSource === 'Andi-Bank-Intents')
        return skillContext.powers.andi.shouldIRun.shouldIRunTrue(topScoringIntent.intentScore);

    return skillContext.powers.andi.shouldIRun.shouldIRunFalse();     
}

  

addSimpleHeader

This method allows you to add a header text message to your response that will display in the Andi® window. 

It will consist of the following parameters:

  • headerText - the string of text that will display as the header.
  • skillActivity - this is the skillActivity as part of the skill context that results in the article header returned
skillContext.powers.andi.chat.addSimpleHeader ('your message', chatEvent)

 

sendSimpleHeader

Returns a promise to send a header text message in your response that will display in the Andi® window. 

It will consist of the following parameter:

  • headerText - the string of text that will display as the header.
skillContext.powers.andi.chat.sendSimpleHeader ('your message')

 

Was this article helpful?
0 out of 0 found this helpful