admin

Nov 102017
 

 

 

 

 

You can say that the bot framework can be classified in to the following concepts.

keyconcepts

 

Connector: The bot framework is basically a REST full API that is used to communicate between the Bot and the channel. Now here the channel could be anything like skype, slack kik etc. Basically the connector library is used to perform an interaction between the Bot and the user.

Activity: The means to facilitate communication between the bot and the user is called activity. This is used by the connector. Now an Activity is an object which could be a message or any other type.

Dialog: Dialog in bot framework is used to model a conversation and conversation flow. You can have a dialog within a dialog to model a meaning full conversation. The main purpose of having a nested is model like is because of the re usability. The Dialog in the Dialog Context is maintained in dialog stack that are in a conversation.

FormFlow: Sometime the input from a user is more complex than just a message in those cases a form flow is used. For example if you want to take multiple input from the user like customer review or some general information regarding a complex question. The formflow can automatically generate dialog to maintain a guided conversation.

State: As obvious by its name the state is associated with a user. The bot frame maintain the state of the user that is communication with the bot at any given time, If the user leaves you can always reload the state of the user and see where he left and continue the conversation from there.

 Posted by at 4:29 am
Nov 062017
 

Whenever i talk Bot i always think of those Sifi movies where you can have those super complex and intelligent digital beings. When I heard that the bot framework is out I wanted to try it and it wasn’t that easy to learn and develop. I know I am a bit late in this blog so the words might be new but the technology is not that recent. So lets start coding then.

So first off you need to follow this post to set up the environment and the template for the bot. So when you create a new bot project you will given some template files on which you can work directly and that is what we are going to do as well. I will directly use those templates and change them to more meaningful and understandable code.

If you see the template generate files you will observe that the code is divided into two main parts, Controller and Dialog. The Controller will send the message that will come from the user via the bot interface and it will send it to the dialog. The dialog will process the message and will reply accordingly. We can have multiple dialogs you can consider them as routes in a website.

How will we work

MessageController: No change here so we will use the same file as the template generate it.

RootDialog: Here we will instrust the dialog to get user profile information. Do remember that this class needs to be serializable.

EnsureProfileDialog: This dialog will get the user profile from the user. You can also notice that this class is serializable

UserProfile: This serializable datastrcuture will hold the actual profile information

This is how the bot will look like

bot hello world

 Posted by at 10:35 am
Jul 242017
 

I wanted to create a self hosting console application without going to the hassle  of creating a new web application project. So all i had to do was to create a console application and then do the nuget and OWIN do the rest.

Create a new console project and paste this code in the main procedure.

 

So the first thing that you will see if that you will get error as it is unable to identify the WebApp class. So the first thing that you need to do is to include the nuget package. Include the nuget package called ‘Microsoft.AspNet.WebApi.OwinSelfHost’ to the project and then try to compile and run the project. After that you will still get more error that Startup class is missing. So include this class.

Now compile the project and you will be able to compile. Lets see the code now

The WebApp.Start is taking a class called Statup as configuration. The configuration defines multiple configuartion paramatere  but here we are only defining the route though which the we will access the REST full API. Now when you run the application you will see a 404 as its still unable to find the values controller. So lets include that.

Snippet

Now run the app and you will see an output. Wohoo a successful self hosting app.

 Posted by at 10:22 am
Jul 132017
 

To create your first c# Bot you need to setup your environment you the Bot project template and the Bot framework channel emulator. They are not included in the standard VS installation package (at least not yet) so we have to fix it ourselves. Lets fix the project template first. You can download the project template from this link. After you download the template unzip the template and open this path “C:\Users\usernmae\Documents\Visual Studio 2017\Templates\ProjectTemplates\Visual C#” and paste you unzipped folder here. Once you have that you will be able to see the new Bot project template in your ‘Create New Project’ dialog.

bot new project

 

Once you have that you can just hit F5 to run but you will notice that it will only open your selected browser nothing else will happen. You need to communicate with your bot and for that you need an emulator. You can download the emulator from here. Once you have that you can run it and along with the hosted application. We will see the emulator in more detail in the next slide.

Bot Framework Channel Emulator

bot emulator empty

 

 Posted by at 2:59 pm
Jul 122017
 

Though the concept is really simple but there is always an edge confusion between the two. Lets discuss them one by one using example. To understand the concept of Abstract lets consider one of this easy case domain problem. Lets discuss the characteristics of an animal. An animal can have 4 legs if its a horse and two legs if its a Kangaroo (ok you can argue that the arms are legs as well but lets assume that its only two legs and two arms). When i define a object of such characteristics i cant really say directly that an animal has 4 legs. I mean in real life it could have 4 but not when its a Kangaroo. Let me define the two processes separately

If we have a domain case where we say that we cannot haven’t an object of Animal class because we don’t know if it would have 4 or 6 legs. but we could have Horse or Kangaroo objects. Then we define the animal class abstract. What it will do it one it could restrict the type animal to be instantiated and secondly it would force all the child classes to implement the base class abstract method.

If we have a domain case where we have a Passenger class which could travel with ticket. But if its European passenger then we need to check the passport only and if its Non European passenger then we need to check the Passport and visa. To implement that check the example below where the base class(Passenger) method is overridden by the child class based on their nature

 

 

 

 

 

 Posted by at 4:38 pm
Jul 112017
 

Structs are value types so their memory allocation is stored in Stack in the memory on your computer and the class is stored on heap which is a different location the logical memory. The reason behind that is structs are value types and classes are reference type. So if you pass a struct to a method and change the value of that the object you will see that the value is changed within that scope of the method. On the other hand if you do the same with a class and pass it to a method. In that method if you update the value of the object. You will see that the value of the actual object is also changed. see the example below

 

The output from that code is

values before passing Asad Mirza
values updated Ali Mirza
values after passing Asad Mirza
Class Object
values before passing Asad Mirza
values updated Ali Mirza
values after passing Ali Mirza

So you see for the class object the actual value is updated

 Posted by at 11:29 am
Jul 102017
 

In this example i will printing out the list of movies that we get in the form of Json and print them out.

Step1: Create a console project

Step2: Add newtonsoft nuget package

Step3: I will be using a open source api that i will call to pint the title of the movie along with the release year. In this example i will print the movies which have the keyword beast in the title. So here is the code.

Snippet

In the above code the variable text have the resulting json text. which looks like this

[ { “id”: “5628302”, “title”: “Beast (III)”, “year”: “2017”, “poster”: “N/A”, “type”: “movie” }, { “id”: “6414796”, “title”: “Beast (V)”, “year”: “2017”, “poster”: “N/A”, “type”: “movie” }, { “id”: “4261746”, “title”: “Beast (VIII)”, “year”: “2017”, “poster”: “N/A”, “type”: “movie” }, { “id”: “1365050”, “title”: “Beasts of No Nation”, “year”: “2015”, “poster”: “N/A”, “type”: “movie” }, { “id”: “1152398”, “title”: “Beastly”, “year”: “2011”, “poster”: “N/A”, “type”: “movie” } ]

To deserialize it I will cal the newtonsoft deserializer that will map the json values to my object MovieInfo and provide me with the converted list.

 Posted by at 10:38 am
Jul 072017
 

You may ask what is the purpose of this post. The title seems really confusing indicating that i may have used the same word twice and trying to explain the difference between it. The thing is these are two different things. One if the native class string and the other is the class object provided by the framework called String. Basically there is no difference in them as  far as the functionality is concerned but when it comes to coding convention then if you want to declare any string value you should use the class ‘string’ to declare it but if you want to use any functionality from the string class the you should use the class ‘String’ which is also the class the object the static class through which you class access method like concat or Parse.

 Posted by at 10:44 pm
Jul 062017
 

In this post i am going to explain two different ways to parse XML file. I am directly going to start with the code but before that here is my sample XML. In the code there are two ways of parsing the XML one is the simple way of doing it through which it is done using the XMLReader way and the other is to deserialize it to a class. Both are explained below

 

The code to parse it is

In the above code the first method called from main is ParseXML. In this method we are using the simplest way to parse the XML by using the XMLReader. So first we need to create the XMLReader by providing the content of the XML and once we have that then its really easy to go though the XML. The first method used is ‘ReadToFollowing’ this method will take you to the first requested node and each call will traverse to the next occurrence. It returns a bool type based on the result of the search. MoveToFirstAttrubute read the first attribute of the node.

The other way to parse the XML file is to serialize it in object. But you have to have an class object in which you can map the XML file and for complex object its a bit hard to make it. Luckily VS provides a really easy way to do it. All you have to do is select the XML and do the following process

xmltoclass

You will get the following file

In method serializeXML i am using the deserializer to deserialize the XML to catalog object and then i just loop around the list to display

 

 

 

 

 Posted by at 2:45 pm
Jul 052017
 

I was always getting confused in what to use until i came to know when should we use IEuqatable and IComparable. So lets say you have an object and you want to use it in a dictionary. Sometime we implement the ‘contains’ method from the dictionary on the list. Now this method wont work if the object is not implementing IEquatable. When you implement that method than the purpose of this method is to compare the object with another object. So indirectly we helped our ‘contains’ method which will use this to compare the object.

 

Now lets say there is another requirement in which you want to sort the dictionary then then object used in that dictionary should implement IComparable. By using this interface you will have to implement the compareTo method where you will mention the position of the two objects under observation.

 Posted by at 11:30 am