SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Let Your Web App Interact with Your Chatbot

Use the Web Client APIs to send messages, intercept messages, change the memory and other chatbot actions from within your SAPUI5 app.

Overview

🎓 beginner 20 min. SAP Conversational AiBeginnerSapui5JavascriptMachine LearningArtificial Intelligence

You will learn

  • โœ”How to use the Web Client APIs
  • โœ”How to use the Web Client Bridge APIs
Unknown U Unknown November 4, 2022
Created by March 20, 2022
Contributors

Prerequisites

Prerequisites

  • Any SAPUI5 app (feel free to build the simple SAPUI5 app described in the 2 Minutes of SAPUI5 playlist)
  • An SAP Conversational AI chatbot to deploy in your SAPUI5 app (you can simply use a new one with the Greetings skill)
  • Knowledge on how to deploy a chatbot to a web page with the Web Client. The tutorial Deploy an SAP Conversational AI Chatbot on a Web Site describes a similar process for the Web Chat client.

Steps

Intro

The Web Client APIs let you control your chatbot from within your web application, including:

  • Open and close the chatbot
  • Send a message to the chatbot (as if it came from your user)
  • Change the theme of the chatbot

The Web Client Bridge APIs let you:

  • Capture the messages sent by the user and the chatbot
  • Set the client info for the conversation
  • Set the style and default texts
  • Set up speech to text for your chatbot (this is explained in the tutorial Add Speech-to-Text to Your Chatbot)

The Web Client APIs and Bridge APIs are documented in the SAPConversationalAI / WebClientDevGuide GitHub repo.


Step 1 Add Web Client script
โ€”

In your SAPUI5 view controller, in the onAfterRendering method, add the script tag for adding your Web Client to a web page. The script is available in the Connect tab when developing your chatbot.

javascript[4-11]
onAfterRendering: function () {
  // Set up chatbot
  // this.renderCAIChatBot()
        var s = document.createElement("script");
        s.setAttribute("src", "https://cdn.cai.tools.sap/webclient/bootstrap.js");
        s.setAttribute("id", "cai-webclient-custom");
        s.setAttribute("data-expander-preferences",data_expander_preferences);
        s.setAttribute("data-channel-id",data_channel_id);
        s.setAttribute("data-token",data_token);
        s.setAttribute("data-expander-type","CAI");
        document.body.appendChild(s);
     },

For the specific IDs and tokens for your chatbot, place a new file webclient.js inside the controller folder (since you may want to change the chatbot from time to time) and add just the following few lines. Make sure to enter values for your chatbot.

JavaScript[1-3]
const data_expander_preferences = "<my preferences>";
const data_channel_id = "<my channel ID>";
const data_token = "<my token>";

To load the file with your details, add a dependency at the start of the controller file.

JavaScript[14,18]
sap.ui.define([
    "profilePic/controller/BaseController",
    "sap/m/MessageToast",
    "sap/m/MessageBox",
    "sap/ui/core/Core",
    "sap/ui/model/json/JSONModel",
    "sap/ui/Device",
    "sap/suite/ui/commons/library",
    "sap/m/Dialog",
    "sap/m/DialogType",
    "sap/m/Button",
    "sap/m/ButtonType",
    "sap/m/TextArea",
    "./webclient"
],
    function (BaseController, MessageToast, MessageBox, oCore, JSONModel, Device, SuiteLibrary,
        Dialog, DialogType, Button, ButtonType, TextArea,
        webclient) {

At this point you should already be able to use the chatbot in your app – just without speech to text.

Run the SAPUI5 app and use your chatbot.

Step 2 Add footer toolbar
+
Step 3 Add data model for themes
+
Step 4 Add event handlers
+
Step 5 Try the web client APIs
+
Step 6 Set up Web Client bridge
+
Step 7 Change memory
+
Step 8 Capture messages
+
Step 9 Capture data messages
+
Step 10 Set client info and preferences
+
Step 11 2 use cases
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 11
1. Add Web Client script 2. Add footer toolbar 3. Add data model for themes 4. Add event handlers 5. Try the web client APIs 6. Set up Web Client bridge 7. Change memory 8. Capture messages 9. Capture data messages 10. Set client info and preferences 11. 2 use cases

Learn more →