Embed a bot in an app

Although bots most commonly exist outside of apps, they can also be integrated with apps. For example, you could embed a knowledge bot within an app to help users find information that might otherwise be challenging to locate within complex app structures. You could embed a bot within a help desk app to act as the first responder to incoming user requests. The bot could independently resolve simple issues and hand off more complex issues to a human agent.

Integrating bot with app

The way to integrate a bot with an app varies depending on the type of app.

Native mobile app

An app that is created in native code can communicate with the Bot Framework by using the Direct Line API, either via REST or websockets.

Web-based mobile app

A mobile app that is built by using web language and frameworks such as Cordova may communicate with the Bot Framework by using the same components that a bot embedded within a website would use, just encapsulated within a native app's shell.

IoT app

An IoT app can communicate with the Bot Framework by using the Direct Line API. In some scenarios, it may also use Microsoft Cognitive Services to enable capabilities such as image recognition and speech.

Other types of apps and games

Other types of apps and games can communicate with the Bot Framework by using the Direct Line API.

Creating a cross-platform mobile app that runs a bot

This example of creating a mobile app that runs a bot uses Xamarin, a popular tool for building cross-platform mobile applications.

First, create a simple web view component and use it to host a web chat control. Then, using the Bot Framework Portal, connect the bot to the Web Chat channel.

Bot configuration settings

Next, specify the registered web chat URL as the source for the web view control in the Xamarin app:

public class WebPage : ContentPage
{
    public WebPage()
    {
        var browser = new WebView();
        browser.Source = "https://webchat.botframework.com/embed/<YOUR SECRET KEY HERE>";
        this.Content = browser;
    }
}

Using this process, you can create a cross-platform mobile application that renders the embedded web view with the web chat control.

Back-channel

Sample code

For a complete sample that shows how to create a cross-platform mobile app that runs a bot (as described in this article), see the Bot in Apps sample in GitHub.

Additional resources