Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
Digital assistants play a crucial role in the UX of every application. They are everywhere! Is not that all applications should have one, just make sure they add its value to the whole. Their massive adoption is a clear sign of their importance in terms of UX. We are quite far from achieving a KITT, like in Knight Rider, but people are adopting them more and more.

KITT: “Michael are you sure you want to do that?”


Personally, I use Alexa at home quite a lot, Google assistant sometimes, and the voice assistant in my car too, although rarely.


I’m sure you already know SAP Conversational AI, SAP’s offering to develop your own chatbots. It offers many standard channels to choose from, like the webchat, the SAP web client, Amazon Alexa, Facebook Messenger and Telegram, among others. A lot of options that can suite your needs. You can even, of course, implement one of your own. In this blog post I want to show you how you can integrate the web chat client into an MDK app. It’s clear that this functionality wont work offline, as an MDK app can, but is understandable and useful despite of that. Many popular assistants have that limitation too.


In this blog post I’m not going to go over the process of creating a chatbot and the basics of MDK. I intend this to be a short reading with the specific goal to integrate the two parts.

If you want to understand these topics better before you go on, you can go through these resources:

SAP Conversational AI Blogs

SAP Mobile Services, Mobile Development Kit


Specially this tutorial is key as I was based on it to write this post.



  • You need a chatbot with the web chat channel implemented

  • A BTP (trial) account with mobile services and an MDK app created

  • The MDK SDK correctly installed



The idea is to create a custom control for the MDK app, using the metadata approach. This control will implement an embedded browser that will display a webpage with the web chat client in it. I have only did it for Android, using the WebView control, but it’s similarly achievable in iOS with the WKWebView. Hopefully I can soon update the post and include these devices too.

So, first of all, you need to build a web page and place the script that will include the web chat client. For example, this is the way I did it, just because I was reusing something I did previously. You can let go your imagination and make it the way you like it.
<!DOCTYPE html>

body {
background-image: url(./assets/Athenas.jpeg);
background-repeat: no-repeat;
background-size: cover;

<body background-image="./assets/Athenas.jpeg">
<!-- // Pericles -->
<script src="" channelId="<channelId>" token="<token>" id="<id>"> </script>
<meta name="viewport" content="width=device-width">


And it looks like this:

Simple webpage

Now you need to make your webpage accessible from the MDK app and I found 2 ways to do it. One alternative is to host it publicly and access it with the url. Or else you can include it and ship it as a resource in your app. For this, I couldn’t make it work using the metadata. Apparently, there is a folder in the metadata definitions to store resources, but not html files. If I’m wrong, I appreciate you let me know so I can fix it in here. But there is other way by building your own MDK client and placing your web page inside. So we are going to do that.


Steps to implement the metadata

  1. Open the Business Application Studio, create the Dev Space and a new project using the MDK template.

  2. Upload the image that will represent your custom control. In my case I’m using this one.

  3. Now register the extension control

  4. Select template New and Register Metadata Extension Control

  5. For the schema use this json
    "type": "object",
    "BindType": "",
    "properties": {
    "url": {
    "type": "string",
    "BindType": ""

  6. Now edit the to place your new custom control. Drag and drop it in the available area
    Set the Height to something like 580In the extension properties you can set the location of your webpage in the network

    url: https://etc.

  7. Fill the code in Extensions/chatClientModule/controls/chatClientExtension.ts
    import * as app from 'tns-core-modules/application';
    import { IControl } from 'mdk-core/controls/IControl';
    import { BaseObservable } from 'mdk-core/observables/BaseObservable';

    export class chatClientClass extends IControl {
    private _observable: BaseObservable;
    private _webView: any;
    private _url: string;

    public initialize(props: any): any {

    if (this.definition().data.ExtensionProperties.url) {
    this._url = this.definition().data.ExtensionProperties.url;
    } else {
    this._url = "file:///android_asset/webchat.html";

    if ( {
    this._webView = new android.webkit.WebView(this.androidContext());
    this._webView.loadUrl(this._url);, this.onActivityPaused, this);, this.onActivityResumed, this);, this.onActivitySaveInstanceState, this);, this.onActivityDestroyed, this);
    var that = this;

    private onActivityPaused(args) {
    if (!this._webView || this != args.activity) return;

    private onActivityResumed(args) {
    if (!this._webView || this != args.activity) return;

    private onActivitySaveInstanceState(args) {
    if (!this._webView || this != args.activity) return;

    private onActivityDestroyed(args) {
    if (!this._webView || this != args.activity) return;

    public view() {

    if ( {
    return this._webView;

    public viewIsNative() {
    return true;

    public observable() {
    if (!this._observable) {
    this._observable = new BaseObservable(this, this.definition(),;
    return this._observable;

    public setContainer(container: IControl) {
    // do nothing

    public setValue(value: any, notify: boolean, isTextValue?: boolean): Promise<any> {
    // do nothing
    return Promise.resolve();

    In your import function, if you see errors related to tns-core-modules or mdk-core, you can ignore them. There is currently no reference of such libraries in the MDK editor.

    The way it’s implemented, the web view is going to take the url from the extension properties if it’s set. If not it will use the one bundled with the client.

  8. Finally, deploy it to your app in mobile services.

Steps to build the MDK client

  1. I assume you already have your SDK installed, so look for the project template and paste your web page files in the respective resources folder.

  2. Set the respective values in the branding settings and build the client. If everything worked fine you will see your nice web page display in the phone.


I thought it was a nice trick and I hope you enjoy trying it on your own. So easily, you can extend the reach of the web chat client making it available to MDK apps.

Your feedback is highly appreciated!