Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Error in user YAML: (<unknown>): mapping values are not allowed in this context at line 2 column 32
---
page_type: sample
description: Teams Catering Bot: Order food via Adaptive Cards in Microsoft Teams.
products:
- office-teams
- office
- office-365
languages:
- csharp
extensions:
 contentType: samples
 createdDate: "05/25/2021 13:38:26"
urlFragment: officedev-microsoft-teams-samples-bot-teams-catering-csharp
---

Teams Catering Bot

This Teams Catering Bot allows users to place food and drink orders seamlessly within Microsoft Teams. It leverages Universal Adaptive Cards for dynamic interactions and supports features like recent orders and order confirmation.

Document Manager

Summary

Teams Catering bot is a sample app that provides an experience of ordering food and drinks. This sample makes use of Teams platform capabilities like Universal Bots to bring a restaurant ordering feature to life.

Interaction with app

Prerequisites

  • .NET Core SDK version 6.0

    determine dotnet version

    dotnet --version
  • dev tunnel or Ngrok (For local environment testing) latest version (any other tunneling software can also be used)

  • Teams Microsoft Teams is installed and you have an account

Setup

  1. Register a new application in the Microsoft Entra ID – App Registrations portal.

    • Go to App registrations and create a new app registration in a different tab.

    • Register an application.

    • Fill out name and select third option for supported account type and click "Register".
    Register An Application

    NOTE: Copy and paste the App Id and Tenant ID somewhere safe. You will need it in a future step.

    • Create Client Secret.
      • Navigate to the "Certificates & secrets" blade and add a client secret by clicking "New Client Secret".

    NOTE: Copy and paste the secret somewhere safe. You will need it in a future step: Certificates And Secrets

  2. Setup for Bot

    • Register a bot with Azure Bot Service, following the instructions here.

      • Ensure that you've enabled the Teams Channel

      • While registering the bot, use https://<your_tunnel_domain>/api/messages as the messaging endpoint.

      • Register a bot with Azure Bot Service, following the instructions here.

      • Ensure that you've enabled the Teams Channel

      • While registering the bot, use https://<your_tunnel_domain>/api/messages as the messaging endpoint.

      Bot Channel Reg

      Go to the created resource, navigate to channels and add "Microsoft Teams" and “Web chat” channels:

      Bot Channels

      NOTE: When you create your bot you will create an App ID and App password - make sure you keep these for later.

  3. Create Azure Cosoms Database account**

    • Create an Azure Cosmos DB account
      • Choose an existing resource group or create a new one.
      • Choose an account name for your cosmos db account.
      • Select Azure Cosmos DB for NoSQL as API.

    Create an Azure Cosmos DB account:

    Cosmos Db account creation

    Azure Cosmos DB for NoSQL:

    Cosmos Db account creation
  4. Get Cosmos DB enpoint Uri and read write Primary Key

    • Open your newly created Cosmos DB account. Navigate to "Keys" section.
    • Copy paste your URI and read write Primary_Key for further use.
    Cosmos Db keys
  5. Setup NGROK

  • Run ngrok - point to port 3978

    ngrok http 3978 --host-header="localhost:3978"

    s Alternatively, you can also use the dev tunnels. Please follow Create and host a dev tunnel and host the tunnel with anonymous user access command as shown below:

    devtunnel host -p 3978 --allow-anonymous
  1. Setup for code
  • Clone the repository

    git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
  • Run the bot from a terminal or from Visual Studio:

    A) From a terminal, navigate to samples/bot-teams-catering/csharp

    # run the bot
    dotnet run

    B) Or from Visual Studio

    • Launch Visual Studio
    • File -> Open -> Project/Solution
    • Navigate to samples/bot-teams-catering/csharp folder
    • Select Catering.csproj file
    • Press F5 to run the project
  • Update the appsettings.json files.

    • "MicrosoftAppId: <<Your Microsoft Bot_Id>>

    • "MicrosoftAppPassword": <<Your Microsoft Bot_Secret>>

    • "CosmosEndpointUri": <<Your Cosmos DB enpoint uri>>

    • "CosmosKey": <<Your Cosmos DB read-write Primary_Key>>

    • "BotServiceUrl: <<YourBotServiceUrl>>/v3

NOTE: The App id to be installed into Teams meeting can be retrieved using the graph explorer. As this sample uses the same app to be added to the teams meeting, app needs to be installed into Teams (follow step 4 on how to package and install the app to teams) and use the app's ID generated by Teams (different from the external ID). For more information, see the List teamsApp refernce article

NOTE: The Bot Service Url needs to be dynamically fetched (and stored) from the Team. Recommendation is to capture the serviceUrl from the bot Payload and later re-use it to send proactive messages. eg: https://smba.trafficmanager.net/amer/v3

7. Setup Manifest for Teams

  • This step is specific to Teams.

    • Edit the manifest.json contained in the Manifest folder to replace your Microsoft App Id (that was created when you registered your bot earlier) everywhere you see the place holder string <<Your Microsoft App Id>> (depending on the scenario the Microsoft App Id may occur multiple times in the manifest.json)
    • Edit the manifest.json for websiteUrl,privacyUrl,termsOfUseUrl inside DeveloperTabs . Replace <<your_tunnel_domain>> with base Url domain. E.g. if you are using ngrok it would be https://1234.ngrok-free.app then your domain-name will be 1234.ngrok-free.app and if you are using dev tunnels then your domain will be like: 12345.devtunnels.ms.
    • Edit the manifest.json for validDomains with base Url domain. E.g. if you are using ngrok it would be https://1234.ngrok-free.app then your domain-name will be 1234.ngrok-free.app and if you are using dev tunnels then your domain will be like: 12345.devtunnels.ms.
    • Zip up the contents of the Manifest folder to create a manifest.zip (Make sure that zip file does not contains any subfolder otherwise you will get error while uploading your .zip package)
    • Upload the manifest.zip to Teams (In Teams Apps/Manage your apps click "Upload an app". Browse to and Open the .zip file. At the next dialog, click the Add button.)
    • Add the app to personal/team/groupChat scope (Supported scopes)

Note: If you are facing any issue in your app, please uncomment this line and put your debugger for local debug.

Running the sample

Install App:

Select your order UI:

Confirm selected item UI:

Order confirmed:

Select next order UI:

Recent order list UI:

Interaction with the Bot

  • Ping the bot in 1:1 or channel scope
  • Bot will send an Adaptive card to choose food.
  • Follow the sequential process of selecting food, drink and submit your choices.
  • Bot will keep on updating the adaptive card on each submission.
  • Submit your final order on confimation card.
  • Bot will update the card to order confirmed card.
  • You can click on "Recent Orders" button.
  • Bot will update the card to recent orders card.

Deploy the bot to Azure

To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.

Further reading