Introduction:

The Bot Framework enables you to build bots that support different types of interactions with users. You can design conversations in your bot to be freeform. Your bot can also have more guided interactions where it provides the user choices or actions. The conversation can use simple text strings or more complex rich cards that contain text, images, and action buttons. And you can add natural language interactions, which let your users interact with your bots in a natural and expressive way.

Bot Builder SDK introduced Form Flow, it will automatically generate the dialogs conversation based on your property and type that a specified on a class. Before read this article, you can refer my previous article for basic understanding about Form Flow

In this article, will help you to customize the form process, change prompt text, field order and how to add condition field. We are going to edit bus booking bot and adding validation and form flow attribute.

Prerequisite:

I have explained about Bot framework Installation, deployment and implementation in the below article

Customize Form Flow Property Text:

Prompt Text:

The Form Flow provide default prompt text based on property name, for example Email Property default prompt text is “Please enter email “ but Bot Framework provided feature for customize text using prompt attribute like below

[Prompt("When you are satrting from")]
public DateTime? StartDate

The output look like below


Enum List Item with Prompt text:

The following code showing prompt text with list of data .You can add custom prompt text and add pattern language({&},{||} ) to dynamically populate list of data at runtime .{&} will replace the replace with description of the field.

{||} is replace with the list of choice in the enumeration
[Prompt("You can Select {&} {||}")]
public FromCity? FromAddress;
[Prompt("You can Select {&} {||}")]
public ToCity? ToAddress;

The output look like below


Form Flow User Input Validation:

Numeric field:

The Numeric attribute to specify to restrict the range of allowed values for a numeric field. The following code allow the number between 1 and 5.

[Numeric(1,5)]
public int? NumberofSeat;

If user provide value above 5 or below 1 , bot will show the validation message like below


Optional Field:

The Form Flow attribute by default every fields is required and must be filled in the form. If you specify the Optional attribute, it will default select as “No preference “.

[Optional]
public string Address;

The Optional Field type output look like below


Pattern field:

A regular expression is an object that describes a pattern of characters. Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text. You can add regular expressions into pattern attribute and validate the user input. The following code will validate user email id .

[Pattern(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")]

public string Email;

The below output showing, user trying provide invalid email id, immediately bot will reply and ask valid email

Terms:

You can add the Terms attribute to match the user input. When we ask the user for gender they are presented with buttons for them to choose between Male or Female. However, they don’t have to use the buttons and can instead type their answer if they wish. By default, if the user types their answer they must enter the choice exactly, e.g. “Male” or “Female”, but in the context of a natural conversation the user might say something like “M” or “girl”.


/// <summary>
/// Gender
/// </summary>

public enum Gender
{
[Terms("M","boy")]
Male,
[Terms("F","girl")]
Female
}

The Form Flow like below and user can select or provider terms


Custom message for Enum :

The following code showing, how to show custom item list for enum . We have attribute for Describe for customize enum item using Describe

public enum Food
{
[Describe("Yes, I want South indian meal")]
SMeal = 1,
[Describe("Yes, I want South North Indain meal")]
NMeal = 2,
[Describe("Yes , I want Fruits")]
Fruts = 3 ,
[Describe("Thanks , I dont want any Food")]
No =4
}
The output look like below


Template Attribute:

The Template attribute enables you to replace the default templates that FormFlow uses to automatically generate prompts. The following code example uses the Template attribute to redefine how the form handles enumeration fields. The attribute indicates that the user may select only one item, sets the prompt text by using pattern language, and specifies that the form should display only one item per line.

[Template(TemplateUsage.EnumSelectOne, "What kind of {&} would you like ? {||}", ChoiceStyle = ChoiceStyleOptions.PerLine)]

public Food LunchFood;

Pattern language uses curly braces ({}) to identify elements that will be replaced at runtime with actual values. The output look like below


Custom template Error:

The following code redefines the TemplateUsage.NotUnderstood template to specify two different variations of message. When the bot needs to communicate that it does not understand a user's input, it will determine message contents by randomly selecting one of the two text strings.

[Template(TemplateUsage.NotUnderstood, "Sorry , \"{0}\" Not avilable .", "Try again, I don't get \"{0}\".")]
public Food LunchFood;

The output look like below


Welcome, Confirmation and Form Builder:

The following code example uses FormBuilder to define the steps of the form, validation, welcome message and dynamically define a field value and confirmation. By default, steps in the form will be executed in the sequence in which they are listed following

public static IForm<BusFormFlow> BuildForm()
{
return new FormBuilder<BusFormFlow>()
.Message("Welcome to the BotChat Bus Booking !")
.Field(nameof(ToAddress))
.Field(nameof(StartDate))
.Field(nameof(BusTypes))
.Field(nameof(NumberofSeat))
.Field(nameof(LunchFood))
.Message("Passenger Details")
.AddRemainingFields()
.Message("You will get confirmation email and SMS .Thanks for using Chat Bot Bus Booking")
.OnCompletion(async (context, profileForm) =>
{
string message = "Your Bus booking Successfully Completed , Welcome Again !!! :)";
await context.PostAsync(message);
})
.Build();
}

Run Bot Application:

The emulator is a desktop application that lets we test and debug our bot on localhost. Now, you can click on "Run the application" in Visual studio and execute in the browser.


  • Test Application on Bot Emulator
  • You can follow the below steps for test your bot application.
  • Open Bot Emulator.
  • Copy the above localhost url and paste it in emulator e.g. - http://localHost:3979
  • You can append the /api/messages in the above url; e.g. - http://localHost:3979/api/messages.
  • You won't need to specify Microsoft App ID and Microsoft App Password for localhost testing, so click on "Connect".

Download Source :


Summary:

In this article, you have learned about customize the form process, change prompt text, field order and how to add condition field. If you have any questions/ feedback/ issues, please write in the comment box.

Introduction:

The Bot Framework enables you to build bots that support different types of interactions with users. You can design conversations in your bot to be freeform. Your bot can also have more guided interactions where it provides the user choices or actions. The conversation can use simple text strings or more complex rich cards that contain text, images, and action buttons. And you can add natural language interactions, which let your users interact with your bots in a natural and expressive way.

Bot Builder SDK introduced prompt Dialogs that allow user to model conversations and manage conversation flow. The prompt is used whenever a bot needs input from the user. You can use prompts to ask a user for a series of inputs by chaining the prompts.

In this article will help you to understand how to use prompts and how you can use them to collect information from the users. We are creating sample Demo Bot for our c# corner Annual Conference 2018 registration process automation.

Prerequisite:

I have explained about Bot framework Installation, deployment and implementation the below article

Create New Bot Service:

Let’s create a new bot service application using Visual Studio 2017. Open Visual Studio > Select File > Create New Project (Ctrl + Shift +N) > Select Bot application 



The Bot application template was created with all the components and all required NuGet references installed in the solutions and add new annualplanDialog class to the project.



In this Solution, we have three main class MessagesController.cs , RootDialog.cs and AnnualPlanDialog class . Let us start discussing here.

RootDialog Class:

Step 1:

You can create / Edit the RootDialog class, create a class that is marked with the [Serializable] attribute (so the dialog can be serialized to state) and implement the IDialog interface.

using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
[Serializable]
public class RootDialog : IDialog<object>
{

}

Step 2:

IDialog interface has only StartAsync() methond. StartAsync() is called when the dialog becomes active. The method is passed the IDialogContext object, used to manage the conversation.

public async Task StartAsync(IDialogContext context)
{

}

Step 3: Design Title and Image for Welcome:

Create a method with hero card and return the attachment. The Hero card is a multipurpose card, it is having single title, subtitle, large image, button and a "tap action “. The following code added for C# Corner annual conference 2018 registration welcome message using Bot Hero card.

/// <summary>
/// Design Title with Image and About US link
/// </summary>
/// <returns></returns>

private static Attachment GetHeroCard()
{
var heroCard = new HeroCard
{
Title = "Annual Conference 2018 Registrtion ",
Subtitle = "DELHI, 13 - 15 APRIL 2018",

Text = "The C# Corner Annual Conference 2018 is a three-day annual event for software professionals and developers. First day is exclusive for C# Corner MVPs only. The second day is open to the public, and includes presentations from many top names in the industry. The third day events are, again, exclusively for C# Corner MVPs",

Images = new List<CardImage> { new CardImage("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE5XHanlTvde5T3qHspW4utJ4QoVrFopi21t6uTrhmGKRUfdiBGq_06WVp2YIxyvP2MA0v8_Up2J-3-7aLpF9cTZCHxyXqMDc5dQCpxslZNbOQkrIhZ2FEhuBWF3bfNmrhRtrs2eRrTvk/h120/annuvalevent.PNG") },

Buttons = new List<CardAction> { new CardAction(ActionTypes.OpenUrl, "About US", value: "http://conference.c-sharpcorner.com/") }
};
return heroCard.ToAttachment();
}
Welcome banner its look like below


Step 4: Custom Prompt Dialog:

The custom prompts a dialog for asking the user to select a registration plan, which he/she is interested. Like below Design .



Define the enum for different type pass. it’s a prompt list item

public enum AnnuvalConferencePass
{
EarlyBird,
Regular,
DelegatePass,
CareerandJobAdvice,
}

Create a method ShowAnnuvalConferenceTicket with Prompt Dialog choice like below

public virtual async Task ShowAnnuvalConferenceTicket(IDialogContext context, IAwaitable<IMessageActivity> activity)
{
var message = await activity;
PromptDialog.Choice(
context: context,
resume: ChoiceReceivedAsync,
options: (IEnumerable<AnnuvalConferencePass>)Enum.GetValues(typeof(AnnuvalConferencePass)),
prompt: "Hi. Please Select Annuval Conference 2018 Pass :",
retry: "Selected plan not avilabel . Please try again.",
promptStyle: PromptStyle.Auto
);
}

The PropmptDialog. choice method has different parameter, you can refer below for parameter and uses

Context - user context message
Resume - its Resume handler, what next process
Options - list of prompt item
Retry - What to show on retry.
Attempts -The number of times to retry.
PromptStyle - Style of the prompt Prompt Style
Descriptions - Descriptions to display for choices.
When the user selects an option, the ChoiceReceivedAsync method will be called.

public virtual async Task ChoiceReceivedAsync(IDialogContext context, IAwaitable<AnnuvalConferencePass> activity)
{
AnnuvalConferencePass response = await activity;
context.Call<object>(new AnnualPlanDialog(response.ToString()), ChildDialogComplete);
}

if its bot conversation is completed, the ChildDialogComplete method will execute for show thanks message

public virtual async Task ChildDialogComplete(IDialogContext context, IAwaitable<object> response)
{
await context.PostAsync("Thanks for select C# Corner bot for Annual Conference 2018 Registrion .");
context.Done(this);
}

Step 3:

You can wait for a message from the conversation, call context.Wait(<method name>) and pass it the method you called when the message is received. When ShowAnnuvalConferenceTicket () is called, it's passed the dialog context and an IAwaitable of type IMessageActivity. To get the message, await the result.

public async Task StartAsync(IDialogContext context)
{
//Show the title with background image and Details
var message = context.MakeMessage();
var attachment = GetHeroCard();
message.Attachments.Add(attachment);
await context.PostAsync(message);
// Show the list of plan
context.Wait(this.ShowAnnuvalConferenceTicket);
}

AnnualPlanDialog :

Create a new class file for registration prompt dialog and implement IDialog interface. In resume parameter, we can specify which dialog method to be called next after the user has responded. The response from the user is passed to the subsequent dialog methods and called to the following class.
In this class , Bot will collect all the user information one by one using prompt dialog like below

namespace BotPromptDialog.Dialogs
{
[Serializable]
public class AnnualPlanDialog : IDialog<object>
{
string name;
string email;
string phone;
string plandetails;

public AnnualPlanDialog(string plan)
{
plandetails = plan;
}

public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Thanks for Select "+ plandetails + " Plan , Can I Help for Registrtion ? ");
context.Wait(MessageReceivedAsync);
}

public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> activity)
{
var response = await activity;
if (response.Text.ToLower().Contains("yes"))
{
PromptDialog.Text(
context: context,
resume: ResumeGetName,
prompt: "Please share your good name",
retry: "Sorry, I didn't understand that. Please try again."
);
}
else
{
context.Done(this);
}
}

public virtual async Task ResumeGetName(IDialogContext context, IAwaitable<string> Username)
{
string response = await Username;
name = response; ;
PromptDialog.Text(
context: context,
resume: ResumeGetEmail,
prompt: "Please share your Email ID",
retry: "Sorry, I didn't understand that. Please try again."
);
}

public virtual async Task ResumeGetEmail(IDialogContext context, IAwaitable<string> UserEmail)
{
string response = await UserEmail;
email = response; ;
PromptDialog.Text(
context: context,
resume: ResumeGetPhone,
prompt: "Please share your Mobile Number",
retry: "Sorry, I didn't understand that. Please try again."
);
}

public virtual async Task ResumeGetPhone(IDialogContext context, IAwaitable<string> mobile)
{
string response = await mobile;
phone = response;

await context.PostAsync(String.Format("Hello {0} ,Congratulation :) Your C# Corner Annual Conference 2018 Registrion Successfullly completed with Name = {0} Email = {1} Mobile Number {2} . You will get Confirmation email and SMS", name, email, phone));
context.Done(this);
}
}
}

After execute above code, the output look like below 


MessagesController Class :

The RootDialog class is added to the conversation in the MessageController class via the Post() method. In the Post() method, the call to Conversation.SendAsync() creates an instance of the RootDialog, adds it to the dialog stack to make it the active dialog, calling the RootDialog.StartAsync() from Post method

[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}

private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (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
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (message.Type == ActivityTypes.Ping)
{
}
return null;
}
}

Run Bot Application:

The emulator is a desktop application that lets we test and debug our bot on localhost. Now, you can click on "Run the application" in Visual studio and execute in the browser.


  • Test Application on Bot Emulator
  • You can follow the below steps for test your bot application.
  • Open Bot Emulator.
  • Copy the above localhost url and paste it in emulator e.g. - http://localHost:3979
  • You can append the /api/messages in the above url; e.g. - http://localHost:3979/api/messages.
  • You won't need to specify Microsoft App ID and Microsoft App Password for localhost testing, so click on "Connect".

Summary:

In this article, how to use prompts and how you can use them to collect information from the users. If you have any questions/ feedback/ issues, please write in the comment box.

The Bot Framework enables you to build bots that support different types of interactions with users. You can design conversations in your bot to be freeform. Your bot can also have more guided interactions where it provides the user choices or actions. The conversation can use simple text strings or more complex rich cards that contain text, images, and action buttons. And you can add natural language interactions, which let your users interact with your bots in a natural and expressive way.

Bot Builder SDK introduced Dialogs, Users allow to model conversations and manage conversation flow. Dialogs can contain waterfall steps and prompts(Options). As the user interacts with the bot, the bot will start, stop, and switch between various dialogs in response based on user messages. 



In this article, we will learn about the condition inside waterfall Bot Framework.

Prerequisite:

I have explained about Bot framework Installation, deployment and implementation the below article

Create New Bot Service:

Let start create new bot service application using Visual Studio 2017. Open Visual Studio > Select File > Create New Project (Ctrl + Shift +N) > Select Bot application



The Bot application template was created with all the components and all required NuGet references installed in the solutions .



In this Solution, we have two main class MessagesController.cs and RootDialog.cs , Let we start discuss about here .

RootDialog Class:

Step 1:

You can create / Edit the RootDialog class, create a class that is marked with the [Serializable] attribute (so the dialog can be serialized to state) and implement the IDialog interface.

using System;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
[Serializable]

public class RootDialog : IDialog<object>
{

}

Step 2:

IDialog interface have only StartAsync() methond. StartAsync() is called when the dialog becomes active. The method is passed the IDialogContext object, used to manage the conversation.

public async Task StartAsync(IDialogContext context)
{

}

Step 3:

You can wait for a message from the conversation, call context.Wait(<method name>) and pass it the method you called when the message is received. When MessageReceivedAsync() is called, it's passed the dialog context and an IAwaitable of type IMessageActivity. To get the message, await the result.

[Serializable]

public class RootDialog : IDialog<object>
{
public Task StartAsync(IDialogContext context)
{
context.Wait(MessageReceivedAsync);
return Task.CompletedTask;
}

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{

}
}

Step 4:

Let start edit MessageReceivedAsync method as per your requirement or create new async method. The following code is welcome message conversation dialog.
[Serializable]
public class RootDialog : IDialog<object>
{
static string username;
int count = 0;
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Hello, I am Microsoft Bot");
context.Wait(MessageReceivedAsync);
}
private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
var message = await result as Activity;
if(count >0)
username = message.Text;
if (string.IsNullOrEmpty(username))
{
await context.PostAsync("what is your good name");
count++;
}
else
{
await context.PostAsync($"Hello {username} , How may help You");
}
context.Wait(MessageReceivedAsync);
}
}

IDialogContext have following Public Member Functions
Context.Call< R > (IDialog< R > child, ResumeAfter< R > resume)
Call a child dialog and add it to the top of the stack.
Context.Done< R > (R value)
Complete the current dialog and return a result to the parent dialog.
Context .Fail (Exception error)
Fail the current dialog and return an exception to the parent dialog.
Context .Forward< R, T > (IDialog< R > child, ResumeAfter< R > resume, T item, CancellationToken token)
Call a child dialog, add it to the top of the stack and post the item to the child dialog.
Context .Post< E > (E @event, ResumeAfter< E > resume)
Post an internal event to the queue.
Context .Reset ()
Resets the stack
Context .Wait< R > (ResumeAfter< R > resume)
Suspend the current dialog until an external event has been sent to the bot.

MessagesController Class :

The RootDialog class is added to the conversation in the MessageController class via the Post() method. In the Post() method, the call to Conversation.SendAsync() creates an instance of the RootDialog, adds it to the dialog stack to make it the active dialog, calling the RootDialog.StartAsync() from Post method

[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}

Run Bot Application:

The emulator is a desktop application that lets we test and debug our bot on localhost. Now, you can click on "Run the application" in Visual studio and execute in the browser.


  • Test Application on Bot Emulator
  • You can follow the below steps to test your bot application.
  • Open Bot Emulator.
  • Copy the above localhost url and paste it in emulator e.g. - http://localHost:3979
  • You can append the /api/messages in the above url; e.g. - http://localHost:3979/api/messages.
  • You won't need to specify Microsoft App ID and Microsoft App Password for localhost testing, so click on "Connect".

Summary:

In this article, your learned how to create a Bot application using Visual Studio 2017 with Bot dialog API. If you have any questions/ feedback/ issues, please write in the comment box.

Introduction:

Microsoft Cognitive Services awesome APIs and services for developers to create more intelligent applications. You can add a more interesting feature like people emotion and video detection, facial, speech and vision recognition and speech and language understanding into our all the application. The following sample image showing for emotion and face detection using cognitive service.



In this article, you will get understand how to Create a Cognitive Services APIs account in the Azure Portal.

Prerequisites:

Create a free trial Azure subscription from Azure portal.
If you are looking paid version, Click here for detail


Create a Cognitive Services Account in Azure:

You can follow below steps for Create a Cognitive Services APIs account in the Azure Portal.

Step 1: 

 Sign in to the Azure portal.

Step 2: 

Click + NEW and Select AI + Cognitive Services


Step 3: 

You can see the entire list of Cognitive Services APIs. Click on the API of your choice to proceed.


Step 4:

 Select on required API and read about the API and Click on Create


Step 5: 

after click on create button, provide the following information for create cognitive service and click on create.

Name: Name of the account, Microsoft recommend a descriptive name. for example, <common name><APIName>Account.
Subscription: Select the available Azure subscriptions.
Location: Select the service locations.
Pricing tier: you can choose your pricing tier. F0 is free service and S0 paid service. based on your usage you can choose the pricing tier

Select the Resource group > confirm the Microsoft notice and Click on create for create the account

Step 6: 

wait for few second and you will get notification after complete. If Cognitive Services account is successfully deployed, click the notification to view the account information.

You can see and copy the Endpoint URL in the Overview section.



You can also copy keys in the Keys section to start making API calls in our Xamarin or other applications.


Summary:

In this article, you learned about how to Create a Cognitive Services APIs account in the Azure Portal.

We can use these keys and endpoint URL to the next article with an app to communicate intelligent feature in Xamarin application. 

If you have any questions/ feedback/ issues, please write in the comment box.








The Azure Bot Service is powered by the Microsoft Bot Framework and bot service allows developers to build conversational applications that plug into many popular chat applications including Facebook Messenger, Skype and Office 365, etc. In this article, we can be creating and testing a bot by using the Azure Bot Service.

Create new Bot Service:

Logon to the Azure portal with your registered Azure Microsoft account. If you don’t have azure subscription, you can Create a free trial Azure subscription from Azure portal.
In Azure Portal > click on + Add > Select on Data Analytics



Step 1: Select on new Bot service from data analytics menu



Step 2: 

  • You can provide following information for create new bot service
  • unique App name to your bot’s name. The name is used as the subdomain in azure website (eg DevEnvExeBot.azurewebsites.net).
  • Select the Azure subscription.
  • Select the resource group or create new user group.
  • Select the location. And click on Create button

Step 3: 

After clicking on Create button, wait a few minutes for the Bot Service to be deployed successfully before proceeding. You will get confirmation notification for after success.


Register Bot Application:

You can click on confirmation notification. then, you will get the following screen where you need to create App ID. This is a prerequisite to authenticating your bot with the bot framework.

Step 1: 

Click on Create Microsoft App ID and Password



Step 2: 

App ID and password will generate following screen and click on button for go back to Bot framework


Step 3: 

Select the Programming language and template for developing bot application


Step 4:

 Now bot application successfully created and running in the cloud, you can edit code from Azure Develop code editor and also you can manage channels, analytics and setting.


Test Bot Application:

You can click on Test button and provide sample input text.


Summary

In this article, your learned about create and test a bot by using the Azure Bot Service. If you have any questions/ feedback/ issues, please write in the comment box.

Introduction:

The Bot Framework enables you to build bots that support different types of interactions with users. You can design conversations in your bot to be freeform. Your bot can also have more guided interactions where it provides the user choices or actions. The conversation can use simple text strings or more complex rich cards that contain text, images, and action buttons. And you can add natural language interactions, which let your users interact with your bots in a natural and expressive way.

In this article, we can deploy a bot to azure using visual studio 2017, register app with bot portal and testing it with the Bot Framework Emulator.

Setup and Create New Bot Application.

You can read my previous article for Getting Started with Bots Using Visual Studio 2017 from following URL http://www.c-sharpcorner.com/article/getting-started-with-bots-using-visual-studio-2017/



You need azure account for deploy bot application to azure so If you do not have an Azure account, you can click following url for a free trial azure subscription. https://azure.microsoft.com/en-us/free/

Register Bot Application:

Step 1: Navigate to Bot Framework Portal from https://dev.botframework.com/

Step 2: Click on Sign in button and login with credential

Step 3: Click on Create a Bot or Skill

Step 4: Click on Create a Bot and click on Register

Step 5: Upload relevant app png icon and max size should be 30k

Step 6: Provide your bot's Display Name.

Step 7: Provide a Description of your bot.



Step 7: Provide your bots Https endpoint in configuration section.

We are not yet deployed our bot to the cloud so leave the endpoint blank for now. we will return to the Bot Framework Portal later and specify the endpoint after we have deployed our bot.

Step 8: On the next page, click Generate an app password to continue.

Step 9: Copy and securely store the password that is shown, and then click Ok.

Step 10: Click Finish and go back to Bot Framework.

Step 11: Back in the Bot Framework Portal, the App ID field is now populated.

Click 12: Click on Register to complete the registration process.

Update Web Configuration file:

Open your project in Visual Studio and update the Microsoft App Id and Microsoft App Password values in your web configuration settings to specify the app ID and password values that were generated for your bot during the above registration process.



<appSettings>
<!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="DevEnvExeBot" />
<add key="MicrosoftAppId" value="2f3edda3-d36d-4d88-8acf-e448d870348e" />
<add key="MicrosoftAppPassword" value="L6KOPcc3jqZB6hKPe06yxsH" />
</appSettings>

Azure publishing wizard:

Step 1: Right click on Project > Select on Publish and start publish bot application into azure



Step 2: Select on Microsoft Azure App Service > select on Create New and click on Publish button


Step 3: Login with Microsoft azure account and click on create app service

Step 4: Copy the Destination URL value to the clipboard (you'll need this value later to test the connection to the bot)


Update Site Url from Bot Portal:

Step 1: Sign in to the Bot framework Portal - https://dev.botframework.com/

Step 2: Click My Bots.

Step 3: Select the bot that you want to configure and click Settings.

Step 4: Provide your bot's HTTPS endpoint. This is the endpoint where your bot will receive HTTP POST messages from Bot Connector. If you built your bot by using the Bot Builder SDK, the endpoint should end with /api/messages.
Step 5: Click on Save Changes.

Test Bot Application on Portal:

After publish Bot application into azure, you can test bot application from portal and emulator .

Step 1: Sign in to the Bot framework Portal - https://dev.botframework.com/

Step 2: Click on Test and provide input text


Test Bot Application on Emulator:

Open Bot Emulator and Provide your bot's HTTPS endpoint with api/messages .

Provide Microsoft App ID and Password and click on Connect



If you are getting following error, Click on Edit Tunneling (ngrok) setting.



download Tunneling (ngrok.exe) from https://ngrok.com/download and click on browse and associate ngrok.exe path



Click on refresh from Bot emulator and provide your input for test application 


Summary

In this article, your learned how to Deploy a bot to Azure using Visual studio 2017. If you have any questions/ feedback/ issues, please write in the comment box.

Featured Post

Improving C# Performance by Using AsSpan and Avoiding Substring

During development and everyday use, Substring is often the go-to choice for string manipulation. However, there are cases where Substring c...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts