March 6, 2025

Step-by-Step Guide: Building, Integrating, and Deploying a Microsoft Teams Bot Using Visual Studio, OpenAI, and Azure - Part 1


In today's fast-paced business environment, effective communication and automation are crucial for productivity. Microsoft Teams bots powered by AI can significantly enhance your team's collaboration and efficiency. By integrating OpenAI with a Microsoft Teams bot, you can automate responses, streamline workflows, and offer instant support. This guide will walk you through the process of setting up and deploying a bot that leverages OpenAI’s capabilities to bring intelligent, natural interactions to your Microsoft Teams environment.

Why Need a Teams Bot?
A Microsoft Teams bot integrated with OpenAI enhances team collaboration by automating repetitive tasks, providing instant responses to queries, and streamlining workflows. It improves productivity and ensures round-the-clock support, offering human-like interactions within the team's environment. 

Key Advantages: 
  • Automated Assistance: Reduces repetitive work and answers common questions instantly.
  • Natural Conversations: Uses AI to understand and respond naturally in multiple languages.
  • Integration and Personalization: Customizable to meet specific business needs and integrate with other tools

This blog is divided into two parts to help you easily navigate and follow the steps for creating and deploying a bot:

Part 1: Azure Configuration for Your Bot
  1. Setting up a new resource group for your bot.
  2. Set up the Azure Bot and Key Vault resources.
  3. Setting up the web application along with its service plan.
  4. Configuring the bot credentials and channels 

Part 2: Bot Configuration and Deployment here
  1. Add the Bot Framework v4 SDK Templates to Visual Studio.
  2. Create an Echo Bot Solution in Visual Studio.
  3. Configure the OpenAI API in the Echo Bot Solution.
  4. Test the Bot Locally in BotFramework-Emulator.
  5. Deploy the Bot to Azure App Service.
  6. Create a manifest.json for Microsoft Teams.
  7. Add the App to Microsoft Teams.

This blog covers the points of Part 1: Azure Configuration for Your Bot.

  1. Setting up a new resource group for your bot.
  2. We'll begin by setting up a new resource group in our subscription to host the resources needed for our bot deployment. 

    1. Launch the Azure Portal in your browser.
    2. Navigate to Resource Groups from the menu on the left, and click Create. 
    3. Choose the subscription you want to use. 
    4. Enter a name for the resource group, following your organization's naming standards.
    5. Pick a region close to your users (for example, the US if your users are in Europe



  3. Set up the Azure Bot and Key Vault resources.
  4. Once the resource group is set up, go to the resource group and follow these steps to create the Azure Bot and Key Vault resources. The Key Vault is automatically created when setting up the bot resource. The Azure Bot resource is essential for managing communication between the bot code hosted on Azure and the client application (such as Microsoft Teams). The Key Vault stores the client secret necessary for authentication. 

    1. Within the newly created resource group, click the 'Create Resource' button. This will take you to the Marketplace.
    2. In the search bar, type Azure Bot and select it from the results.


    3. Click Create to start setting up your bot.


    4. Enter a unique name for the bot as its identifier (e.g., projectname-bot). This will serve as the bot’s "handle." You can set a separate display name, but the handle is just a unique identifier. 
    5. Verify that the correct subscription and resource group are preselected. 
    6. The default pricing tier is Standard, but you can downgrade it to Free by selecting Change plan if premium channels aren't needed.
    7. Choose 'Multi-Tenant' as the app type. 
    8. Keep the creation type set to its default option, which is 'Create a new Microsoft App ID'.
    9. Finally, navigate to the 'Review + Create' tab and click on 'Create.'
    10. Once the bot resource is created, click on 'Go to the resource.'


  5. Setting up the web application along with its service plan.
  6. The Azure Bot we previously set up manages communication between the bot's logic and the client application (in this case, Microsoft Teams). However, we still need to host the bot’s core code somewhere. To do this, we will create a Web App resource in Azure.Web apps require an App Service Plan, which lets us choose the hardware and computational resources for our bot. The plan you select will directly impact both the bot's performance and the associated running costs.

    1. After the bot resource is created, click on 'Go to the resource.'
    2. In the search bar, type Web App and select it


    3. Click on Create.


    4. Subscription: Select your Azure subscription.
    5. Resource Group: Choose an existing resource group or create a new one.
    6. Name: Enter a unique name for your web app.
    7. Publish: Choose Code if you are deploying code directly, or Docker Container if you are using a container.
    8. Runtime Stack: Select the runtime stack (e.g., .NET, Node.js, Python, etc.).
    9. Region: Choose the region closest to your users.
    10. App Service Plan: Select an existing plan or create a new one.
    11. Review all the configurations and click on Create. Azure will deploy your web app, which might take a few minutes.


  7. Configuring the bot credentials and channels .
  8. With the bot resource created, we can now proceed with the configurations. Start by recording the bot app ID and secret for future reference.

    1. Navigate to the Configuration section in the bot resource settings.
    2. Go to your Azure Bot > Configuration > Messaging endpoint: set to the URL that your App Service gave you + “api/messages”


    3. Copy the Microsoft App ID to a place like Notepad, as you'll need to use it later in your bot code project.


    4. Click on the 'Manage' link just above the field containing the GUID you copied. This will take you to the Azure AD app registration created alongside your bot resource.
    5. You will land on the 'Certificates and Secrets' section. Generate a new client secret (valid for 24 months) and save its value in Notepad for future use.
    6. Now that we have the authentication details, let's enable the bot to communicate with our client application. Although I am setting up a bot for Teams here, you can choose another platform as the bot channel in a similar manner.

      • Return to the bot resource and navigate to the Channels section.
      • Open the Channels section.
      • Select Microsoft Teams (or another platform)

      • Accept the terms of service if required.
      • Use the default settings (Teams Commercial, calling off) or adjust them for your bot’s needs (e.g., GCC environment, calling enabled)
      • Click Apply and Close.


Thank you for reading! We hope this guide helped with Azure configuration for your bot. Click here to read Part 2 and complete your bot setup!


If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment