The bot is an app with a new user interface. It provides services such as web API that interact with the user in a conversational format. The intelligent bots interact with your users naturally wherever they are, from your website or app to text/SMS, Skype, Slack, Facebook Messenger, Office 365 mail, Teams, and other popular services. The Microsoft Bot Framework is a set of tools, services, products, and APIs to build and deploy software bots. The framework consists of the Bot Builder SDK, Bot Connector, Developer Portal, and Bot Directory. There's also an emulator that you can use to test your bot.
The Bot Builder SDK is an open source SDK available on the GitHub that allows developers to build intelligent apps without knowing or learning an additional skill, such as machine learning. It provides tools and services required to build bots. It can be build using .NET, Node.js, or REST API.
The Bot Framework Developer Portal lets you register and connect your bot to many different conversation experiences (Skype and Web are auto-configured), providing broad reach for your text/speech, image, button, card-capable and audio/video-capable bot. Make your bot available to your users through the Bot Framework.
The Bot Directory is a public directory of all reviewed bots registered through the Microsoft Developer Portal. Users will be able to discover, try, and add bots to their favorite conversation experiences from the Bot Directory.
The Microsoft Bot Connector is a communication service that helps you connect your Bot with many different communication channels (Skype, SMS, email, and others). If you write a conversational Bot or agent and expose a Microsoft Bot Framework-compatible API on the Internet, the Bot Framework Connector service will forward messages from your Bot to a user, and will send user messages back to your Bot.
The bot has many features which help to connect your customer from other conversational channels. These are as follows.
To understand a bot, let’s see a scenario. Suppose, you have a travel website which generates leads and you convert those leads. You share a static advertisement of travel package on the Facebook. Now, some customers are interested in this package and want to interact with you. Your customers have four options to follow.
In the fourth option, your customer leaves your static advertisement page and comes on your website or app, so there is the chance to lose some genuine leads. In the rest of the operations, you need to hook an agent so that he/she can deal with them and convert leads.
Now, what can a bot do here? You develop a bot and configure it with Facebook messenger. Your customer just sends a request for that holiday package and the bot sends back available booking options to that customer. The customer can see more details as per his/her request and books that package. So, there are fewer chances to lose a lead and customer doesn't need to leave that static advertisement.
There is some misconception about bots which are,
To set up the bot framework connector SDK .NET template in the Visual Studio 2015, this is a step-by-step guide.
This template is fully functional and inputs text as request and response.
We want to build a Microsoft bot application which shows facial attributes, such as Age, Gender and Smile, using the Cognitive Service Face API. We will create the application using the bot template as shown in figure 1. This bot application has the following features.
For the bot application with Cognitive Service, we need to create an account on Cognitive Service. After that, register the Face-Preview API and get a key which will be used in the bot application.
To implement the Face-Preview API, we install Microsoft.ProjectOxford.Face NuGet package in the bot application.
Now, create a class named Utility which has the Cognitive Service Face-Preview API integration, as per the following code snippet.
using
Microsoft.ProjectOxford.Face;
System;
System.Configuration;
System.IO;
System.Linq;
System.Net;
System.Threading.Tasks;
namespace
BotFaceApplication
{
public
static
class
Utility
private
readonly
IFaceServiceClient faceServiceClient =
new
FaceServiceClient(ConfigurationManager.AppSettings[
"FaceAPIKey"
]);
async Task<
string
> UploadAndDetectFaces(
imageFilePath)
try
var requiredFaceAttributes =
FaceAttributeType[] {
FaceAttributeType.Age,
FaceAttributeType.Gender,
FaceAttributeType.Smile
};
(WebClient webClient =
WebClient())
(Stream imageFileStream = webClient.OpenRead(imageFilePath))
var faces = await faceServiceClient.DetectAsync(imageFileStream, returnFaceLandmarks:
true
, returnFaceAttributes: requiredFaceAttributes);
var faceAttributes = faces.Select(face => face.FaceAttributes);
result =
.Empty;
faceAttributes.ToList().ForEach(f =>
result += $
"Age: {f.Age.ToString()} Years Gender: {f.Gender} Smile: {f.Smile.ToString()}{Environment.NewLine}{Environment.NewLine}"
);
return
result;
}
catch
(Exception ex)
The bot application which is created with the help of bot template has the pre-defined code. This code updates as per the following code snippet to handle the face image and send face attributes as an output.
Microsoft.Bot.Connector;
System.Net.Http;
System.Web.Http;
[BotAuthentication]
MessagesController : ApiController
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
async Task<HttpResponseMessage> Post([FromBody]Activity activity)
if
(activity.Type == ActivityTypes.Message && activity.Attachments.Count > 0)
ConnectorClient connector =
ConnectorClient(
Uri(activity.ServiceUrl));
imageUri = activity.Attachments[0].ContentUrl;
Activity reply = activity.CreateReply(await Utility.UploadAndDetectFaces(imageUri));
await connector.Conversations.ReplyToActivityAsync(reply);
else
HandleSystemMessage(activity);
var response = Request.CreateResponse(HttpStatusCode.OK);
response;
Activity HandleSystemMessage(Activity message)
(message.Type == ActivityTypes.DeleteUserData)
// Implement user deletion here
// If we handle user deletion, return a real message
(message.Type == ActivityTypes.ConversationUpdate)
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
(message.Type == ActivityTypes.ContactRelationUpdate)
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
(message.Type == ActivityTypes.Typing)
// Handle knowing that the user is typing
(message.Type == ActivityTypes.Ping)
null
;
The bot application is built successfully. Let's test it. To test the bot application, install the bot emulator.
Now, download the Microsoft Bot Framework Emulator from here. The bot emulator is an executable file named "botframework-emulator-Setup-3.5.21.exe". Just download and install it.
Now, run the application. Hit F5 or choose the Debug or Start Debugging menu command. The browser shows the following page. It is default.htm page in the bot application.
Now, run the Microsoft Bot Framework Emulator and use the same port in the emulator which is mentioned with localhost in the browser. You need to type the URL "http://localhost:xxxx/api/messages" in the Bot Framework Emulator to run the bot application.
Both, Microsoft App ID and Microsoft App Password, need to be left blank. Then, click on "Connect". Now, choose an image which has a face and gets results as in figure 6.
You can download the complete source code from MSDN sample. Click on download to Build First Bot Application With Bot Framework.
This article elaborated about how to build the Microsoft Bot application and integrate the Cognitive Services.