Your Privacy

This site uses cookies to enhance your browsing experience and deliver personalized content. By continuing to use this site, you consent to our use of cookies.
COOKIE POLICY

Microsoft Bot Framework – Creating a Bot Application | Part 1

Microsoft Bot Framework – Creating a Bot Application | Part 1
Back to insights

Part 1 – Your First Bot Application

A big focus of the Microsoft BUILD Conference this year was Artificial Intelligence. Branded as Microsoft Cognitive Services, Microsoft’s AI offerings include 29 different services, ranging from custom search to computer vision to natural language processing to bots. In this series of blog posts, we will focus on the Microsoft Bot Framework.

To start developing with the Microsoft Bot Framework, you need to have Visual Studio 2017 installed. If you do not already have Visual Studio 2017, you can download the free Visual Studio 2017 Community Edition. You will also need to download the Bot Application project template. Do not unzip the package, just move the zip file to your Visual Studio 2017 project templates directory:

You will also want to download and install the Bot Emulator. The emulator allows you to run and test your bot application without deploying it anywhere.

Start Visual Studio 2017 and create a new project. In the New Project dialog box, select Visual C# Templates, and select Bot Application. Name your project and select OK.

Microsoft Bot: New Project

When the project is created, notice the files that are created in Solution Explorer. Open web.config and find the settings for BotId, MicrosoftAppId, and MicrosoftAppPassword. To develop and debug locally, you leave BotId, MicrosoftAppId, and MicrosoftAppPassword blank. When you are ready to deploy your bot app, you will need to register it to get real values. We will cover that process in a future post.

Microsoft Bot: Solution ExplorerMicrosoft Bot: Web Config

Next we will take a look at the MessagesController, in the Controllers folder. It contains two methods:

Bot Message Controller

The Post method receives an activity from the user. If the activity type is “Message” it is processed in the Post method. If it is another activity type, it is passed to the HandleSystemMessage method for processing. The boilerplate code in the Post method creates a new Dialog, which simply returns the message the user typed and the length of the message.

To see this simple bot example run, start the bot emulator. Notice the field to enter your endpoint URL. We will get this when we start debugging in Visual Studio.

start running the microsoft bot framework emulator

In Visual Studio, press F5 or select Debug->Start Debugging. When the browser window opens, it opens to the default.htm page. Note the url and the message that tells you what to set the endpoint to. In this case, we will set the endpoint to http://localhost:3979/api/messages. (Note that the message uses https, but we do not use SSL locally.)

Put that value in the bot emulator and press Connect. You do not need to enter values for Microsoft App ID or Microsoft App Password when debugging locally.

Once you connect, enter a message and either press Enter or click the send button.

Your bot app will reply with the message content and message length.

microsoft bot framework channel emulator

Congratulations! You have created your first bot application. In the next blog post in this series, we will extend the bot application to connect to a real-time API and customize our bot messaging.

If you would like to download the source code for this blog post, it is available on UDig’s GitHub.

Digging In

  • Digital Products

    Unlocking Business Potential: The Power of Custom Application Development

    Like any savvy business leader, you’re likely always on the lookout for tools to give your company a competitive edge. And in doing so, you’ve undoubtedly considered investing in custom application development. But the question is, how do you ensure that such a major investment in a custom web application development provides a strong return on […]

  • Digital Products

    Mastering Legacy Application Modernization: Strategies for Success

    The ironic truth of the business world is that change is the only constant. But this means that failing to keep pace with the competition and its technologies will only end with you falling behind. That’s where legacy application modernization enters the fold. When you modernize legacy applications, your team gains access to new features […]

  • Digital Products

    CTO Confessions Podcast

    In this episode of CTO Confessions, Rob Phillips, the Vice President of Software Engineering at UDig, digs into his journey from a passionate technologist in his youth to a seasoned leader in the tech industry. He shares valuable lessons on transitioning to senior leadership, the importance of understanding and articulating company problems, and the art of empowering teams for high performance.

  • Digital Products

    Navigating the Challenges of On Premise to Cloud Migration

    In today’s rapidly evolving technological landscape, the shift from on premise solutions to cloud-based infrastructure has become a pivotal transformation for organizations seeking to modernize their IT operations. This transition holds the promise of increased agility, cost savings, and enhanced scalability. However, it is not without its set of formidable challenges that organizations must navigate. […]

  • Digital Products

    The Power of Transferrable Skills in Tech Projects

    Every project has its own unique elements that require flexibility to be effective and achieve success. This often requires picking up new pieces of a tech stack, learning a new programming language, or a new project methodology. Fortunately, there are also many transferrable skills that carry over from one project to the next. In my […]

  • Digital Products

    The Four Pillars of Effective Digital Product Development

    In 2020 alone, approximately two billion consumers purchased at least one digital product. From software licenses to mobile apps and tech tools, consumers are becoming increasingly active in the digital product market, a trend that has naturally spurred brands across a wide range of industries to reevaluate their digital product design and development process workflows. […]