cancel
Showing results for 
Search instead for 
Did you mean: 

index.html in Fiori App doesn't import the SAP Conversational AI webchat script.

former_member610181
Participant
0 Kudos
226

I am trying to import my chatbot to my Fiori App. Docs say I need to put the following tag into the body tag of my index.html.

`<script src="https://cdn.cai.tools.sap/webchat/webchat.js" channelId="<Channel ID>" token="<token ID>" id="cai-webchat" ></script>`

I came across to this post, https://answers.sap.com/questions/143831/how-to-include-custom-ui5-library-in-fiori-app.html

but the OP doesn't need to provide any token IDs when importing the library. Also, the import is not from CDN unlike my case where I need to provide tokens and get the library from CDN. I tried putting the js code into a file and point to it in my manifest.json but without the token IDs it doesn't run. Any help is appreciated.

View Entire Topic
former_member610181
Participant

Okay, so I have been playing around with this and I got it working. If you want to use your webchat in a Fiori App, there is a distinction. For a Fiori App, the UI5 framework will inject views rendered from XML into index.html based on the controllers that those views are associated. This means one has to load the webchat script after the Fiori views are added otherwise the chatbot container will not appear in the app. This can be achieved by getting the webchat script in a deferred manner and modifying the index.html in the Fiori app like the following:

<head>
...
<!-- Application launch configuration -->
 <script>
 sap.ui.getCore().attachInit(function() {
 new sap.m.App ({
  pages : [
    new sap.m.Page({
      showHeader: false,
      enableScrolling : false,
      content : [
          new sap.ui.core.ComponentContainer({
          height : "100%", name : "myapp",
          settings : {
          id : "myapp"
          }
      })
    ]
  })
 ]
 }).placeAt("content");
 });
 </script>
</head>
<!-- UI Content --> 
<body class="sapUiBody" role="application">
 <!-- Application launch configuration -->
 <div id="content" >
 <script defer src="https://cdn.cai.tools.sap/webchat/webchat.js"
 channelId="xxxx"
 token="xxxx"
 id="cai-webchat"
 ></script>
 </div>
</body>

The keyword defer will load the webchat after the Fiori is done with rendering views.

Hope this helps.

Best,

Yigit