This guide will showcase how to create a bot in LivePerson Conversational Builder that utilizes a Function-as-a-Service (FaaS) integration to retrieve and process data.
Prerequisites:
- A LivePerson Conversational Builder account with access to create bots and functions.
Navigate to the "Functions" section in LivePerson Conversational Builder.
Click Automate > Functions. The Functions page appears.
Click Confirm to agree to the Terms of Use and GDPR Agreement.
Click the icon to open the LivePerson Functions page.
Click Create a Function. The Create a new function wizard appears.
Ensure that the Access to external domains required toggle is set to off and click Continue. The next page appears.
Provide the function name and description in the fields.
Click Create function the function is added.
The second parameter of the callback is the response that the FaaS will provide to the Bot.
Click the 3 dot menu on the created function.
Click Deploy function. The Create a deployment page appears.
Click Approve & Deploy. The function is deployed.
Create a bot
Log in to your Conversational Cloud account and navigate to Automate > Conversation Builder.
The Conversation Builder appears.
Click New Bot. The Choose a Bot Template window appears.
Select Custom > Custom Bot. The Bot details page appears.
Provide the following information:
1. Name: Input the name for your bot into the field.
2. Description: Input information describing your bot.
3. Channel Type: Select the messaging option.
4. Small Talk: Select to turn on/off the small talk option.
Small Talk provides a human-like experience by providing chitchat, pleasantries, and other trivial conversation.
5. Bot Language: Select the language you require the bot to use from the dropdown menu.
6. Bot Group: Select a bot group if required, from the dropdown menu.
Bot Group is a collection of bots that can be grouped together for easier management and organization on the Bots dashboard.
Once done click Create Bot. The Bot Dialog page appears.
Click Integrations. The Integration page appears.
Provide the following information:
- Integration Name: Input the name to be used for your integration.
- Response Data Variable Name: Assign a variable name to store data from the API call for easy access to returned values.
- Integration Type: Select FaaS from the dropdown menu.
- Function: Select the created function from the dropdown menu.
- Function headers: Provide any HTTP headers required by the web service.
- Function Payload: Provides the payload from the function.
4. Transform Result Script: Leverage Conversation Builder to access non-LivePerson APIs and integrate JSON responses into your bot's dialogs using JavaScript.
You can store the API data into a Bot Variable. To do this you can use the following code on the Transform Result Script section.
Javascript:
var getContextData = botContext.getBotVariable("api_FaasTest");
var getContextJsonResponse = JSON.parse(getContextData.jsonData);
botContext.printDebugMessage("FaasTestData: " + JSON.stringify(getContextJsonResponse.api_FaasTest));
botContext.setBotVariable("FaasTestData", JSON.stringify(getContextJsonResponse.api_FaasTest), true, false);
When using the above code it is imperative that you replace "FaasTest" with the name you provided under Integration Name.
5. Custom Data Fields: These fields can hold integration results in key/value pairs for bot developers to reference and display in interactions.
Click Save. Add the integration to the dialog by clicking Integrations in the right panel.
Select the added API integration from the dropdown menu to add it to the dialog flow.
Click the custom code icon to add Pre-Process or Post-Process code as required.
With this, the bot can utilize and access the API data stored in the previously defined Bot Variable.
You can store Bot Variables with API Data to show them in the Bot responses. You can do this on the Pre-Process Code as seen in the screenshot below.
Once done, click Preview. The integration appears in the conversation window.
Congratulations! You have successfully integrated a FaaS function with your bot using Conversational Builder.
Your bot is now capable of executing custom functions seamlessly, enhancing its functionality and user experience.