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

Run the app (Using Teams Toolkit for Visual Studio)

The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio.

  1. Install Visual Studio 2022 Version 17.10 Preview 4 or higher Visual Studio
  2. Install Teams Toolkit for Visual Studio Teams Toolkit extension
  3. In the debug dropdown menu of Visual Studio, select Dev Tunnels > Create A Tunnel (set authentication type to Public) or select an existing public dev tunnel.
  4. In the debug dropdown menu of Visual Studio, select default startup project > Microsoft Teams (browser)
  5. In Visual Studio, right-click your TeamsApp project and Select Teams Toolkit > Prepare Teams App Dependencies
  6. Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps.
  7. Select Debug > Start Debugging or F5 to run the menu in Visual Studio.
  8. In the browser that launches, select the Add button to install the app to Teams.

If you do not have permission to upload custom apps (sideloading), Teams Toolkit will recommend creating and using a Microsoft 365 Developer Program account - a free program to get your own dev environment sandbox that includes Teams.

Setup

  1. 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
  2. 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
  3. 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.sln file
    • Press F5 to run the project
  • Update the appsettings.json files.

    • "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

  1. Upload the manifest.zip to Teams (in the Apps view click "Upload a custom app")
    • Go to Microsoft Teams. From the lower left corner, select Apps
    • From the lower left corner, choose Upload a custom App
    • Go to your project directory, the ./appPackage/build folder, select the zip folder, and choose Open.
    • Select Add in the pop-up dialog box. Your app is uploaded to Teams.

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