Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday, October 4, 2017

Getting Started Deploy a bot to Azure using Visual studio 2017



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 6: 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:
  1. Open Bot Emulator and Provide your bot's HTTPS endpoint with  api/messages .
  2. 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.

Getting Started with Building Bots using Visual Studio 2017


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 create a bot by using the Visual studio 2017 with Bot template and testing it with the Bot Emulator.
Install Visual Studio 2017:
Download Visual Studio 2017 from the following URL given below.  
  • Download Visual Studio 2017 from https://www.visualstudio.com/downloads/.
  • Refer Visual Studio 2017 system requirement from https://www.visualstudio.com/en-us/productinfo/vs2017-system-requirements-vs.
Note:
  • You can build bots for free with Visual Studio 2017 Community.
  • The Bot Builder SDK for .NET currently supports Only on Windows. Visual Studio for Mac is not supported.
Bot Application template:
Download the Bot Application template from the following url http://aka.ms/bf-bc-vstemplate and install the template by saving the .zip file to your Visual Studio 2017 project templates directory.
The Visual Studio 2017 project templates directory is typically located following url
%USERPROFILE%\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#\
C:\Users\DevEnvExe\AppData\Local\Microsoft\Windows\INetCache\Content.Word\template.png

Create New Project:
Let's start with creating a new Bot application in Visual Studio 2017.
Click on Windows Key > Select Visual Studio 2017.

Xamarin
Now, open VS and create new project with c# project, select the Bot applications template as per below
The Bot application was created with all of the components and installed all required Nuget reference
Update Bot Builder Nuget Package:
Verify your application Microsoft.Bot.Builder nuget package was installed under reference .if not , refer follow below steps
  • Right-click on the Bot project(DevEnvExeBot) and select Manage NuGet Packages.
  • In the Browse tab, type "Microsoft.Bot.Builder" and click on Search
  • Locate the Microsoft.Bot.Builder package in the list of search results, and click the Update button for that package or Uninstall and Install the package .
Update Code:
The Default application added simple conde snipper, no need to change anything. if you want to test your custom message, you can change like below.
You can find messagereceiveAsync method from Dialogs / RootDialog.cs file.
In this method activity.Text will return user text input so you can reply message based input text .
  1. private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
  2.        {
  3.            var activity = await result as Activity;

  4.            // calculate something for us to return
  5.            int length = (activity.Text ?? string.Empty).Length;

  6.            // return our reply to the user
  7.            
  8.            //test
  9.            if (activity.Text.Contains("technology"))
  10.            {
  11.                await context.PostAsync("Refer C# corner website for tecnology http://www.c-sharpcorner.com/");
  12.            }
  13.            else if (activity.Text.Contains("morning"))
  14.            {
  15.                await context.PostAsync("Hello !! Good Morning , Have a nice Day");
  16.            }
  17.            //test
  18.            else if (activity.Text.Contains("night"))
  19.            {
  20.                await context.PostAsync(" Good night and Sweetest Dreams with Bot Application ");
  21.            }
  22.            else if (activity.Text.Contains("date"))
  23.            {
  24.                await context.PostAsync(DateTime.Now.ToString());
  25.            }
  26.            else
  27.            {
  28.                await context.PostAsync($"You sent {activity.Text} which was {length} characters");
  29.            }

  30.            context.Wait(MessageReceivedAsync);
  31.        }
Install bot Emulator:
You will need to download and install the emulator for testing bot application .You can download bot emulator from https://docs.microsoft.com/en-us/bot-framework/debug-bots-emulator .

Run Bot Application:
The emulator is a desktop application that lets you test and debug your bot on localhost or remotely. Now, you can click on run the application in any browser
Test Application on Bot Emulator:
You can follow below steps for test bot application
  1. Open Bot Emulator
  2. Copy above localhost url and past it from emulator eg: http://localHost:3979
  3. You can append the /api/message from above localhost url eg: http://localHost:3979/api/messages.
  4. You won't need to specify Microsoft App ID and Microsoft App Password for localhost testing so click on Connect



Summary:
This article your learned about how to create Bot application using visual studio 2017.

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