Developing artificial intelligence using .NET

Developing artificial intelligence using .NET

Microsoft has recently released two important AI services:

  • Microsoft Cognitive Services  are APIs which lets you tap into an ever-growing collection of powerful AI algorithms developed by experts in the fields of computer vision, speech, natural language processing, knowledge extraction and web search;
  • Bot framework is a very useful framework to build and connect intelligent bots to interact with your users naturally wherever they are, from Telegram to Skype, Slack, Facebook and other popular services;

This article discovers this services and shows how developing artificial intelligence using .NET.


The demo shows how to build a Bot that can automatically caption photos sent by users.


  • Visual studio 2015 community edition , download here;
  • Bot conversation emulator, click here to download;
  • Microsoft cognitive services subscription, sign in here;
  • Visual studio Bot Framework .NET template, which can be downloaded here. To install, save the zip file to your Visual Studio 2015 templates directory which is traditionally in "%USERPROFILE%\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#\";

Setup the bot project

Create a new C# project using the new Bot Application template:

Developing artificial intelligence using .NET

Visual studio generates a new controller, by default, called MessageController, which is the main entry point of your bot:

Setup the bot emulator

The emulator gives the possibility to test your bots locally. You can download the emulator here.

Developing AI using .Net

The emulator requires 3 params:

  • The Url for your bot set the localhost:<port> pulled from the last step. You will need to add the path “/api/messages” to your URL when using the Bot Application template;
  • MicrosoftAppId field is NOT required to test bots locally;
  • MicrosoftAppPassword field is NOT required to test bots locally;

Important: you need to run your bot project in Visual Studio, to use the bot emulator.

Setup images recognition (Microsoft cognitive services: Vision)

Microsoft Cognitive Services APIs offer the possibility to implement AI inside our applications. There are different services:  Speech, Language, Knowledge, Vision and Search. This demo uses the Vision service to caption photos sent by users.

Class schema

Developing artificial intelligence using .Net


Firstly, add the IVisionConnector.cs interface and VisionConnector.cs class to your project:

The IVisionConnector interface is referenced by MessagesController and describes main methods which are used by VisionConnector. API Token is required by VisionServiceClient to consume APIs. You can get the APIs token here.

VisionConnector implements methods to communicate with Microsoft Cognitive API.

Next, go to MessagesController.cs class file and replace the following code:

MessageController class watches  all incoming images and returns the detected caption.

All together now!

Finally, run your Visual studio project and set the bot URL on Bot emulator:

Developing artificial intelligence using .NET

Final thoughts

It’s very easy developing artificial intelligence using .NET, Microsoft Cognitive Services  and Bot framework .

They let you build cross-platform apps with powerful algorithms using just a few lines of code.

Bot framework  is compatibile with the most famous chats: Facebook, Telegram, Skype and Whatsapp.

The example is available on GitHub.

Cheers 🙂