CRM Chat Bot: Part 1 – Getting Started with Microsoft Bot Framework

Microsoft quite recently announced the Microsoft Bot Framework on Build Conference 2016. Below is the overview of the vision of Bot Framework from Microsoft:

The Microsoft Bot Framework provides everything you need to build and connect your bots to your users wherever they converse – from SMS to Office 365 mail to Slack and more… It’s your bot, wherever your users are talking. Learn how to use the Bot Framework to build a bot with your own existing code, use the Bot Builder to generate conversational dialogs from scratch, and more to give your bot skills with natural language processing and deep learning technology. Walk away with tools to build a great bot that can connect with users, wherever they are.

I’ve spent a few months reading and researching on the new Microsoft Bot Framework and I hope with this blog post series I could share and introduce how Microsoft Bot Framework to work together with Dynamics CRM.

Getting Started

Microsoft Bot Framework supports Node.js, .NET and REST Bot Builder SDK. In my posts, I will use .NET based bot, as this is the most common platform that CRM developers use to reduce the learning curve with the Bot Framework.

To start building the bot, we need to set the development environment. Below is my development environment setup:

  • Visual Studio 2015 Update 3 (latest update)
  • Bot Builder SDK (download links are here)
  • Visual Studio C# template (download here)
    • To install, extract the downloaded template and copy it to Visual Studio Project Template. Typically it is located on: “Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#”
  • Bot Framework Emulator (download here)
  • Microsoft Account
  • Microsoft Azure subscription (trial license should do)

Once the environment has been configured, you should be able to see the new project template to be available in Visual Studio:

VS-BotTemplate.png

Let the Journey Begins…

Now let’s create a new bot application. This will give you the following project structure:

ProjectStructure.png

Then we need to install these NuGet packages:

If your environment setup is successfully installed, you would be able to see a page similar to below on build:

ChatBotFirstBuild.png

Bot Emulator

We will use the Bot Emulator to simulate the conversation. Take note of the URL of the page before and enter it in Bot URL.

ChatBotEmulatorFirstBuild.png

You now will see that the bot is replying. Congratulations, you have your first reply from your bot 🙂 

Lesson Learned/Troubleshooting

  1. During the research, I encountered a few differences on the sample code. Some of them used “Message” and some have “Activity”. Apparently, it is part of the update on Bot Framework V3 (https://docs.botframework.com/en-us/support/upgrade-to-v3/) that Microsoft changed the usage of Message to Activity.
  2. Another difference in Bot Framework V3 is that you no longer need Microsoft.Bot.Connector package, Microsoft.Bot.Builder is now include the Microsoft.Bot.Connector assemblies.
  3. Use .Net Framework 4.6 and above to develop Bot. I used 4.5.2 (as this is the current supported framework for Dynamics CRM), this will resulting the installation of Microsoft.Bot.Builder package to fail:

Install-Package : Could not install package ‘Microsoft.Bot.Builder 3.2.0’. You are trying to install this package into

a project that targets ‘.NETFramework,Version=v4.5.2’, but the package does not contain any assembly references or

content files that are compatible with that framework. For more information, contact the package author.

At line:1 char:1

+ Install-Package Microsoft.Bot.Builder

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception

    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

 

Stay tuned for the Part 2: Microsoft Bot Framework Development Concept!

6 thoughts on “CRM Chat Bot: Part 1 – Getting Started with Microsoft Bot Framework

    • Hi Pierre,

      Thanks for your word.
      I’m planning to post this series on weekly basis. However, I might not be able to guarantee that I will post it on time, depends on my other commitments.

      Cheers

Leave a comment