Build a Bot with FaaS Integration

Learn how to integrate a FaaS with your Bot.

  • Messaging

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. 

Screenshot 2024-02-19 at 1.42.04 PM.png

Click Automate > Functions. The Functions page appears.

Screenshot 2024-02-19 at 1.51.53 PM.png

Click Confirm to agree to the Terms of Use and GDPR Agreement.

Screenshot 2024-02-19 at 1.54.26 PM.png

Click the icon to open the LivePerson Functions page.

Screenshot 2024-02-19 at 1.57.45 PM.png

Click Create a Function. The Create a new function wizard appears.

Screenshot 2024-02-19 at 2.01.55 PM.png

Ensure that the Access to external domains required toggle is set to off and click Continue. The next page appears.

Screenshot 2024-02-19 at 2.08.41 PM.png

Provide the function name and description in the fields. 

Screenshot 2024-02-19 at 2.08.41 PM.png

Click Create function the function is added.

1.png

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.

Screenshot 2024-02-19 at 2.15.53 PM.png

Click Deploy function. The Create a deployment page appears.

Screenshot 2024-02-19 at 2.18.17 PM.png

Click Approve & Deploy. The function is deployed.

Screenshot 2024-02-19 at 2.20.18 PM.png

Create a bot

Log in to your Conversational Cloud account and navigate to Automate > Conversation Builder.

Screenshot 2024-02-15 at 2.57.08 PM.png

The Conversation Builder appears.

Screenshot 2024-02-15 at 3.05.13 PM.png

Click New Bot. The Choose a Bot Template window appears.

Screenshot 2024-02-15 at 3.10.42 PM.png

Select Custom > Custom Bot. The Bot details page appears.

Screenshot 2024-02-19 at 2.42.41 PM.png

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. For more information about Small Talk see, here.

    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. For more information on Bot Groups see, here.

Once done click Create Bot. The Bot Dialog page appears.

Screenshot 2024-02-15 at 9.22.08 PM.png

Click Integrations. The Integration page appears.

Screenshot 2024-02-19 at 2.50.38 PM.png

Provide the following information:

  1. Integration Name: Input the name to be used for your integration.
  2. Response Data Variable Name: Assign a variable name to store data from the API call for easy access to returned values.
  3. Integration Type: Select FaaS from the dropdown menu.
  4. Function: Select the created function from the dropdown menu.
  5. Function headers: Provide any HTTP headers required by the web service.
  6. 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 fllowing 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.

Screenshot 2024-02-19 at 12.07.48 PM.png

Click Save. Add the integration to the dialog by clicking Integrations in the right panel.

Screenshot 2024-02-19 at 5.12.30 PM.png

Select the added API integration from the dropdown menu to add it to the dialog flow. 

Screenshot 2024-02-19 at 5.19.20 PM.png

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.

Screenshot 2024-02-19 at 5.19.57 PM.png

Once done, click Preview. The integration appears in the conversation window.

ScreenRecording2024-02-19at5.22.09PM-ezgif.com-video-to-gif-converter.gif

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.

For further information and advanced techniques on API integrations see, here.