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

    Energy Evolution 2025: Balancing Economic Growth and Carbon Reduction

    Now that the election is behind us, we have an opportunity to anticipate the possible effects on the energy industry under this new administration. What strategies will be impacted? What will remain the same? What opportunities can we take advantage of in 2025? This blog is meant to dig into these questions and provide some […]

  • Digital Products

    The Growing Importance of Digital Accessibility

    Embracing Digital Accessibility: A Moral and Business Imperative In today’s digital landscape, accessibility has become crucial for businesses and organizations. With increasing awareness and legal requirements, ensuring that digital products are accessible to all users, including those with disabilities, is not just a compliance issue but a moral imperative. At UDig, we champion ADA compliance […]

  • 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. […]