A sample bot showing how to go beyond by becoming embedded into larger applications.
The minimum prerequisites to run this sample are:
-
The latest update of Visual Studio 2015. You can download the community version here for free.
-
The Xamarin Platform. You can download it from here for free.
-
Register your bot with the Microsoft Bot Framework. Please refer to this for the instructions.
-
Enable the Web Chat channel, edit the settings
and add a new site to get the Web Chat Embed code.
Refer to this for more information on how to configure channels.
-
Update the
WebView
's source of the WebPage.cs file of theWorkingWithWebview
project with the Web chat embed code.public class WebPage : ContentPage { public WebPage() { var browser = new WebView(); browser.Source = "https://webchat.botframework.com/embed/<YOUR SECRET KEY HERE>"; this.Content = browser; } }
The Xamarin WebView
is a view for displaying web and HTML content in your app. It comes with support for the following types of content:
- HTML & CSS websites – WebView has full support for websites written using HTML & CSS, including JavaScript support.
- Documents – Because WebView is implemented using native components on each platform, WebView is capable of showing documents that are viewable on each platform. That means that PDF files work on iOS and Android, but not Windows Phone.
- HTML strings – WebView can show HTML strings from memory.
- Local Files – WebView can present any of the content types above embedded in the app.
WebView on Windows and Windows Phone does not support Silverlight, Flash or any ActiveX controls, even if they are supported by Internet Explorer on that platform.
The WorkingWithWebview
project is a Portable Class Library (PCL) project. Portable Class Libraries allow you to write code and produce libraries that can be shared across mulitple platforms including Xamarin.iOS, Xamarin.Android and Windows Phone
This project defines the app's layout and is being used by each of the platform projects in the solution.
Check out the App.cs
file of the WorkingWithWebview
project defining how the main page of the application will looks like.
public App()
{
this.MainPage = new WebPage { Title = "Web Page" };
}
Check out the MainActivity.cs of the Android project using an instance of the App class defined in the PCL project when loading the Android application.
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
this.LoadApplication(new App());
}
}
You will see the following result, depending the project you choose to run:
iOS | Universal App | Android | Windows Phone |
---|---|---|---|
To get more information about how to get started with the embeddable web chat control for the Microsoft Bot Framework and Xamarin's WebView please review the following resources: