Exercise - Create a message extension

Completed

In this exercise, you create a message extension solution. You use Teams Toolkit in Visual Studio to create the required resources, then start a debug session and test in Microsoft Teams.

Screenshot of search results returned by a search based message extension in Microsoft Teams.

Create a message extension project

Start by creating a new Microsoft Teams app project configured with a message extension that contains a search command. While you could create a project using a Teams Toolkit for Visual Studio Code project template, there are changes required to be made to the scaffolded project to be able to complete this module. Instead, you use a custom project template that is available as an npm package. The benefit of using a custom template is that it creates a solution with the necessary files and dependencies, saving you time.

In a command line:

  1. Start creating a project by running npm create teams-msgext-search. Answer questions as follows:

    1. Internal name of the app: msgext-products. The project generator uses this name to create a new folder. It also uses it as the project name in the package.json file. This name is also used when provisioning resources.
    2. Display name of the app: Contoso Products. This name is displayed in the Microsoft Teams.
    3. Short description of the app: Product look up tool. This description helps Microsoft Teams users understand the purpose of your app.
    4. Full description of the app: Get real-time product information and share them in a conversation. This description helps Microsoft Teams users understand the purpose of your app.
    5. ID of the command: Search. This ID is the internal name of the search command in the app manifest.
    6. Description of the command: Find products by name. This description is shown in the message extension fly out.
    7. Title of the command: Products. This title is displayed in the message extension fly out.
    8. Name of the parameter: ProductName. This name is the internal name of the parameter in the app manifest.
    9. Title of the parameter: Product name. This title is displayed in the search command in Microsoft Teams.
    10. Description of the parameter: The name of the product as a keyword. This description is displayed as placeholder text in the message extension search box.
  2. Wait for the project generator to finish creating the project.

  3. Change the working directory to the newly created project folder.

  4. Open Visual Studio Code by running code ..

  5. Wait for Visual Studio Code to open and load the project.

  6. If prompted, select Install to install the recommended extensions.

Run and debug

The first time you launch the app using Teams Toolkit it installs project dependencies and create the required resources. This process requires you to sign in with your Microsoft 365 and Azure accounts. Once complete, a browser window opens and the app install dialog appears in the Microsoft Teams web client.

In Visual Studio Code:

  1. Start a debug session by pressing F5, or select Run and Debug from the sidebar, then select the green play button next to Run and Debug.
  2. If prompted, select Sign in and sign in with your Microsoft 365 account.
  3. If prompted, select Sign in and sign in with your Azure account.
  4. Select Allow for Teams Toolkit to sign in to Azure using your account.
  5. Select your Azure subscription from the list.
  6. Select an existing resource group or create a new one
    1. To create a new resource group, select Create new, enter a name, then press Enter.
    2. Select the location closest to you from the list.
  7. Select Provision to create the required resources.
  8. Wait for a browser window to open and the app install dialog to appear in the Microsoft Teams web client.
  9. In the app install dialog, select Add to install the app.

To test the message extension:

  1. Open a new, or existing Microsoft Teams chat
  2. In the message compose area, select + to open the app picker
  3. In the list of apps, select Contoso products to open the message extension
  4. In the text box, enter hello
  5. Wait for the search results to appear
  6. In the list of results, select hello to embed a card into the compose message box

Screenshot of search results returned by a search based message extension in Microsoft Teams.

To stop debugging, close the browser window.