Create your first Bot using Visual Studio 2017: Step by step guide

bot17

By looking at how fast the companies adopting the Bots, it is really the best time for you to start learning Bot framework and start adopting Bots for your business.

Some pain in the real world without the Bots:

  • You have to read the whole FAQ to find some specific information for any website or any company
  • You have to wait for next business day to start to get answers to your queries

bot15

  • You have to send emails to get some information to send some information
  • You have to do manual work to answer some repetitive questions
  • More manpower would require if the number of questions increases suddenly:

bot16

This would eventually affect your business. Time to try the Bots.

Let us see what the Bots are:

An Internet bot, also known as web robotWWW robot or simply bot, is a software application that runs automated tasks (scripts) over the Internet. Typically, bots perform tasks that are both simple and structurally repetitive, at a much higher rate than would be possible for a human alone.

In simple words, Bots are something that can be integrated with your website and they can answer the questions posted by the users without the need of the humans

Let us see how to create simple Bot application using Visual Studio 2017.

prerequisite:

Also if you want to have Bot Application as a template then as a workaround just download this  (download would start once you click on the link) project and put the extracted folder into below location:

C:\Users\YourName\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#

Once this is done, you can see Bot Application template as shown below:

bot2

Click on Bot Application and then it will create a sample project which has the structure as below:

bot3

Here MessagesController is created by default and it is the main entry point of the application.

If you open MessagesController, it will look blood red because it cannot find missing Nuget packages:

bot4

You just need to restore those missing Nuget packages by opening Nuget Manager:

bot5

You may encounter an error which would be as below:

CS0117 ‘Task’ does not contain a definition for ‘CompletedTask’ NeelBotDemo c:\users\NeelB\documents\visual studio 2017\Projects\NeelBotDemo\NeelBotDemo\Dialogs\RootDialog.cs 15 Active

This error comes because Task.CompletedTask is a static property added in .NET 4.6 and your application may have .NET 4.5

You need to change your application’s Target framework and make it 4.6.1 as below:

bot6

Your solution should build properly now.

Now we will make changes in the default code and will modify as per our need.

Open RootDialog.cs class which is in the Dialogs folder.

Replace the code of method with below code:

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
{
  var activity = await result as Activity;
  // calculate something for us to return 
  int length = (activity.Text ?? string.Empty).Length;
  // return our reply to the user 
  //test 
  if (activity.Text.Contains("morning"))
  {
     await context.PostAsync("Good Morning , Have a nice Day");
  }
  //test 
  else if (activity.Text.Contains("night"))
  {
     await context.PostAsync("Good night and Sweetest Dreams");
  }
  else if (activity.Text.Contains("who are you"))
  {
     await context.PostAsync("I am a Bot created by Neel");
  }
  else if (activity.Text.Contains("date"))
  {
     await context.PostAsync(DateTime.Now.ToString());
  }
  else
  {
     await context.PostAsync($"You sent {activity.Text} which was {length} characters");
  }
context.Wait(MessageReceivedAsync);
}

Here we are telling Bot, what it should answer when there are some specific keywords are there in the message.

Once you made the changes, just run your Bot application. It will have landing page as below:

bot9

At this point, your bot is ready to be used. We need an emulator to test our bot.

If we want to test our bots locally then Bot emulator is the best option.

The Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots on localhost or running remotely through a tunnel.

As we mentioned on top of the post, you can download the Bot emulator from here. Or you can click below, it will start the download automatically:

botframework-emulator-Setup-3.5.33.exe

Click on exe, it will start the installation:

bot10

And once the installation is done, it will have a landing page as below, here you need to give the URL of your bot application(http://localhost:3979/api/messages):

bot13

It will ask you for Microsoft App Id and password, but for now, do not give anything there and click on CONNECT.

Now your bot is ready to be tested.

Give something that you have added to your code and the bot will respond as per your input in code:

bot14

As you can see it answered all of those which we have given in above code and for rest of the things, it will answer as: “You sent {input} which was {length} character”

Congratulations, you just created your first Bot 🙂

You can integrate Microsoft Cognitive APIs into your Bot application, I have written a post on the same which you can find here.

In my upcoming posts, I will share my experiments with the Bots.

Important Note – Microsoft team has created Bot Builder SDK for .NET so that it is easy for us to develop the bots. But if you want to know what is happening behind the curtain then you can have a look here: https://github.com/Microsoft/BotBuilder/tree/65d4e985b68e4fce5a5e0ac81de198c0a95ac7bb/CSharp/Library, all the libraries are here.

For example, you may have seen I used BotAuthentication attribute above the action, you can find the code for the same attribute here: https://github.com/Microsoft/BotBuilder/blob/65d4e985b68e4fce5a5e0ac81de198c0a95ac7bb/CSharp/Library/Microsoft.Bot.Connector.AspNetCore/BotAuthentication.cs

Hope it helps.

 

Advertisements

AI-Driven Stack Overflow Bot from Microsoft: First look

 

bot7I guess there would be very few developers who do not use StackOverflow in their day to day life. StackOverflow is part of a developer’s life.

Whenever we have some issues or doubts we go to the browser -> opens StackOverflow or search for the question on the browser -> StackOverflow link opens and then we can clear our doubts or issues.

Now imagine you have an active bot in your Visual Studio Code and as soon as you have any issues, just ask that to the bot without leaving Visual Studio Code.

Sounds interesting right?

It is possible with AI driven StackOverflow bots as Microsoft has teamed up with Stack Overflow to create a bot that will answer your programming questions from inside the Visual Studio code editor.

Let us see what are the things required to run the bot.

Requirement:

  • Node 8.1.4 or more
  • StackBot directory

Steps to run:

  • Run npm install in StackBot directory
  • Run npm start in StackBot directory
  • Navigate to http://localhost:portNumber/ to interact with bot

Please note that as this bot uses a number of services(including Bing Custom Search, LUIS, QnA Maker, and Text Analytics), you will need to create applications and generate keys for each one. Microsoft has created a GitHub page with the necessary details which can help you to guide on how to do this.

For this article, we will concentrate more on Visual Studio Code capability to run StackOverflow bot.

Configuration of the bot in Visual Studio Code

As I explained earlier, Visual Studio Code allows developers to quickly call the bot using some simple commands.

Steps:

bot8

  • From the Bot dashboard, add ‘Direct Line’ channel which will communicate with your bot’s backend service

bot9

  • Add site with appropriate name which will then redirect to the page where you can generate the tokens

bot10

Once you add a site:

bot11

  • Click on Show to view the keys:

bot12

  • Copy the tokens and go back to Visual Studio Code
  • Open user settings and add the new field named StackCode.directLineToken, assign the token you copied earlier into this field
  • If everything is done correctly, a pan would be opened which is the interactive window, nothing but the bot

Microsoft has given the bot demo in Ignite conference last month where they showed how powerful the bot is.

Let us see some examples of the bot:

Whenever you want to get help from StackOverflow, just start the StackOverflow bot:

bot1

Which will open the StackOverflow bot:

bot2

Now you can just write down your question in the text and bot will give the answers:

bot3

It can even help you if you need the code.

For example, you are in a need to convert Name+Surname into Surname, First Initial of your name.

Just ask this to the bot:

bot4

And the bot will reply the code for you with the code:

bot5

It can even read the image you uploaded into the bot.

For example, you have an exception, you take the screenshot of the exception and just upload that image into the bot:

bot6

It is really mind-blowing.

 

 

Basic information for Ready API (SoapUI): API Testing

API-Testing_The-Accountability-of-Testers-or-Developers

What is SoapUI?

SoapUI is an open-source web service testing application for service-oriented architectures (SOA) and representational state transfers (REST). Its functionality covers web service inspection, invoking, development, simulation and mocking, functional testing, load and compliance testing.

Basic kick off with SoapUI:

Once you get SoapUI installed, it will have the dashboard as shown below:

RA10

To add sample test, we need to select between SOAP or REST:

RA1

We will select URL as we want to test REST API. Once URL is selected, we need to provide the URL we need to test. For example I am using StackOverflow public API to get the users:

RA2

Once we click on Next, it will create one new project and in that project it will create a TestSuite where all your test will reside:

RA3

Once we run the test, it will show green or Red color whether the test is passed or failed:

RA4

If the test is passed, it will show the response in JSON which we have got with REST GET request:

RA5

Now as it is mentioned in very first image, if we perform some security tests then it will ask about the things we need to add in security test as shown below:

RA7

Once we click on Finish, it will show the result as below:

RA8

We can get detailed report as well:

RA9

I created one sample Web API on my machine which returns 2 values and I published the API project. When I gave localhost URL in ReadyAPI, It created one new project in ReadyApi and it gave the result as shown below:

RA11

So if the API would be installed on IIS then also APIs can be tested using Ready Api.

As it works with GET, it can work with POST\PUT\DELETE as well:

RA12

Virtual service:

SoapUI provides a feature called Virt in which we can create a virtual service, so if testers want to mock the service without calling the actual REST API, it is possible with SoapUI. We need to create a new Virt as below:

RA15

This Virt can behave as GET\POST etc as per your need and Once the Virt is created, we can even host that Virt on localhost by applying some settings.

To conclude this, if we want to test the scenario of a user account creation, we will create one project and in that there would be a test suite named “Test account creation” and in that suite we can add different test cases as shown below:

RA14

Try it out.

 

Create a free website or blog at WordPress.com.

Up ↑