佈建雲端資源

重要

針對 Teams 代理程式和應用程式開發,已淘汰 Microsoft 365 Agents Toolkit,而針對所有案例,TeamsFx SDK 也已完全淘汰。

針對所有新的 Teams 代理程式和應用程式開發,請使用 Teams SDK 和 Teams 開發人員 CLI。

TeamsFx 與 Azure 和 Microsoft 365 雲端整合,讓您使用單一命令即可將應用程式放置在 Azure 中。 TeamsFx 與 Azure Resource Manager (ARM) 整合,可讓您佈建應用程式所需的 Azure 資源進行程式碼方法。

在 Visual Studio Code 中使用 Microsoft 365 Agents Toolkit 佈建

您可以在 Agents Toolkit (先前稱為 Teams Toolkit) 或 Microsoft 365 Agents Toolkit CLI (先前稱為 TeamsFx CLI) 中觸發 provision 命令,以建立或更新應用程式的資源。 provision 命令的步驟定義於檔案的 m365agents.yml 屬性下 provision 。 您可以檢視檔案以了解建立了哪些資源。

注意

Azure 服務會在您的訂閱中產生費用。 如需成本估算的詳細資訊,請參閱 定價計算機。

佈建動作

下列清單顯示專為佈建設計的動作。

teamsApp/create

這是什麼

如果儲存 Teams 應用程式識別碼的環境變數是空的,或者無法從 Teams 開發人員入口網站中找到應用程式識別碼,則此動作會建立新的 Teams 應用程式。

它運作什麼資源

Teams 開發人員入口網站中的 Teams 應用程式。

使用方式

  - uses: teamsApp/create
    with:
      # #required. Name of Teams app
      name: <your-preferred-app-name>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The id for Teams app
      teamsAppId: <your-preferred-env-var-name>

teamsApp/update

這是什麼

在 Teams 開發人員入口網站中,將先前稱為 Teams 應用程式資訊清單) 的應用程式資訊清單 (套用至現有的 Teams 應用程式。 它會使用檔案中的 manifest.json 應用程式識別碼來判斷要更新的 Teams 應用程式。

它運作什麼資源

Teams 開發人員入口網站中的 Teams 應用程式。

使用方式

- uses: teamsApp/update
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/validateManifest

這是什麼

此動作會使用環境變數呈現應用程式資訊清單範本,並使用其結構描述驗證應用程式資訊清單檔案。

它運作什麼資源

不適用

使用方式

  - uses: teamsApp/validate
    with:
      # Required. Relative path to the yaml file. Path to app manifest file
      manifestPath: <path-to-manifest-file>

teamsApp/validateAppPackage

這是什麼

此動作會使用驗證規則驗證 Teams 應用程式套件。

它運作什麼資源

不適用

使用方式

  - uses: teamsApp/validateAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package-file>

teamsApp/zipAppPackage

這是什麼

此動作會使用環境變數呈現應用程式資訊清單範本,並將含有兩個圖示的應用程式資訊清單檔案壓縮成 zip 檔案。

它運作什麼資源

不適用

使用方式

- uses: teamsApp/zipAppPackage
    with:
      # Required. Relative path to the yaml file. This is the path for app manifest file. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml file. This is the path for built zip file.
      outputZipPath: <path-to-generated-zip-file>
      # Required. Relative path to the yaml file. This is the path for built manifest json file.
      outputJsonPath: <path-to-generated-json-file>

teamsApp/publishAppPackage

這是什麼

此動作會將組建的 Teams 應用程式 zip 檔案發佈到租用戶應用程式目錄。

它運作什麼資源

Microsoft 365 租用戶應用程式目錄中的 Teams 應用程式。

使用方式

- uses: teamsApp/publishAppPackage
    with:
      # Required. Relative path to this file. This is the path for built zip file.
      appPackagePath: <path-to-teams-app-package>
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # The Teams app id in tenant app catalog.
      publishedAppId: <your-preferred-env-var-name>

aadApp/create

這是什麼

此動作會建立新的 Microsoft Entra 應用程式,在儲存 clientId 的環境變數為空時驗證使用者。

它運作什麼資源

您 Microsoft 365 租用戶中的 Microsoft Entra ID。

使用方式

- uses: aadApp/create
    with:
      # Required. The Microsoft Entra app's display name. When you run aadApp/update, the Microsoft Entra app name will be updated based on the definition in manifest. If you don't want to change the name, make sure the name in Microsoft Entra app manifest is the same with the name defined here.
      name: <your-application-name>
      # Required. If the value is false, the action will not generate client secret for you
      generateClientSecret: true
      # Required. Specifies what Microsoft accounts are supported for the current application. Supported values are: `AzureADMyOrg`, `AzureADMultipleOrgs`, `AzureADandPersonalMicrosoftAccount`, `PersonalMicrosoftAccount`.
      signInAudience: "AzureADMyOrg"
    # Write the information of created resources into environment file for the specified environment variable(s).
    writeToEnvironmentFile:
      # Required. The client (application) ID of Microsoft Entra application. The action will refer the environment variable defined here to determine whether to create a new Microsoft Entra app.
      clientId: <your-preferred-env-var-name>
      # Required when `generateClientSecret` is `true`. The action will refer the environment variable defined here to determine whether to create a new client secret. It's recommended to add `SECRET_` prefix to the environment variable name so it will be stored to the .env.{envName}.user environment file.
      clientSecret: <your-preferred-env-var-name>
      # Required. The object ID of Microsoft Entra application
      objectId: <your-preferred-env-var-name>
      # Optional. The tenant ID of Microsoft Entra tenant
      tenantId: <your-preferred-env-var-name>
      # Optional. The Microsoft Entra authority
      authority: <your-preferred-env-var-name>
      # Optional. The host name of Microsoft Entra authority
      authorityHost: <your-preferred-env-var-name>

aadApp/update

這是什麼

此動作會根據指定的 Microsoft Entra 應用程式資訊清單更新您的 Microsoft Entra 應用程式。 它會參照 Microsoft Entra 應用程式資訊清單中的識別碼屬性,以判斷要更新的 Microsoft Entra 應用程式。

它運作什麼資源

您 Microsoft 365 租用戶中的 Microsoft Entra ID。

使用方式

- uses: aadApp/update
    with:
      # Required. Relative path to the yaml file. Path to the Microsoft Entra app manifest. Environment variables in manifest will be replaced before apply to Microsoft Entra app.
      manifestPath: <path-to-manifest-file>
      # Required. Relative path to the yaml folder. This action will output the final Microsoft Entra app manifest used to update Microsoft Entra app to this path.
      outputFilePath : <path-to-output-file>

botAadApp/create

這是什麼

此動作會為 Bot 建立新的或重複使用現有的 Microsoft Entra 應用程式。

它運作什麼資源

您 Microsoft 365 租用戶中的 Microsoft Entra ID。

使用方式

- uses: botAadApp/create
    with:
      # Required. The Microsoft Entra app's display name
      name: <your-app-name>
    writeToEnvironmentFile:
      # The Microsoft Entra app's client id created for bot.
      botId: <your-preferred-env-var-name>
      # The Microsoft Entra app's client secret created for bot. 
      botPassword: <your-preferred-env-var-name>

ARM/部署

這是什麼

此動作會平行部署指定的 ARM 範本。

它運作什麼資源

Azure 訂用帳戶。

使用方式

- uses: arm/deploy
    with:
      # Required. You can use built-in environment variable `AZURE_SUBSCRIPTION_ID` here. TeamsFx will ask you select one subscription if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select subscription if it's empty in this case.
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      # Required. You can use built-in environment variable `AZURE_RESOURCE_GROUP_NAME` here. TeamsFx will ask you to select or create one resource group if its value is empty. You're free to reference other environment variable here, but TeamsFx will not ask you to select or create resource group if it's empty in this case.
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      # Required. The ARM templates to be deployed.
      templates:
        # Required. Relative path to the yaml file.
      - path: <path-to-arm-template>
        # Optional. Relative path to the yaml file. TeamsFx will replace the environment variable reference with real value before deploy ARM template.
        parameters: <path-to-arm-template-parameter>
        # Required. Name of the ARM template deployment.
        deploymentName: <arm-deployment-name>
      # Optional. Agents Toolkit will download this bicep CLI version from github for you, will use bicep CLI in PATH if you remove this config.
      bicepCliVersion: v0.9.1

azureStorage/enableStaticWebsite

這是什麼

此動作會在 Azure 儲存體中啟用靜態網站設定。

它運作什麼資源

Azure 儲存體。

使用方式

- uses: azureStorage/enableStaticWebsite
    with:
      # Required. The resource id of Azure Storage
      storageResourceId: ${{<env-name-of-azure-storage-resource-id>}}
      # Required. The path to index page.
      indexPage: <path-to-index-page>
      # Required. The path to error page.
      errorPage: <path-to-error-page>

azureStaticWebApps/getDeploymentToken

這是什麼

此動作會從 Azure 靜態 Web 應用程式擷取部署權杖。

版本資訊

v1.4

它運作什麼資源

Azure 靜態 Web 應用程式。

使用方式

- uses: azureStaticWebApps/getDeploymentToken
    with:
      resourceId: ${{AZURE_STATIC_WEB_APPS_RESOURCE_ID}}
    writeToEnvironmentFile:
      deploymentToken: SECRET_TAB_SWA_DEPLOYMENT_TOKEN

script

這是什麼

此動作會執行使用者定義的指令碼。

它運作什麼資源

不適用

使用方式

- uses: script
    with:
     # Required. Command to run or path to the script. Succeeds if exit code is 0. '::set-teamsfx-env key=value' is a special command to generate output variables into .env file, in this case, "mykey=abc" will be added the output in the corresponding .env file.
     run: $my_key="abc"; echo "::set-teamsfx-env mykey=${my_key}"
     # Optional. Available values are: bash, sh, powershell(Powershell Desktop), pwsh(powershell core), cmd. If omitted, it defaults to bash on Linux/MacOS, defaults to pwsh on windows.
     shell: <shell-name>
     # Optional. Current working directory. Defaults to the directory of this file.
     workingDirectory: <working-directory>
     # Optional. Timeout in ms.
     timeout: <timeout-in-ms>
     # Optional. Redirect stdout and stderr to a file.
     redirectTo: <path-to-output-file>

自訂資源佈建

佈建步驟定義於檔案中的 m365agents.yml 屬性下 provision 。 您可以新增、移除或更新屬性的 provision 動作,以定義您在佈建期間要執行的預期動作。

參數檔案中的參考環境變數

Agents Toolkit 支援參考環境中的 m365agents.yml值,例如在 、應用程式資訊清單、Microsoft Entra 應用程式資訊清單和 Azure 參數檔案。 您可以使用語法 ${{ENV_VARIABLE_NAME}} 來參考環境變數。

下列範例會將環境變數 MY_AZURE_SUBSCRIPTION_ID 的值設定為 subscriptionId:

subscriptionId: ${{MY_AZURE_SUBSCRIPTION_ID}}

自訂 ARM 範本檔案

如果預先定義的範本不符合您的應用程式需求,您可以建立自己的 ARM 範本或更新現有的 ARM 範本,並提供動作路徑 arm/deploy ,如下列範本所示:

- uses: arm/deploy
    with:
      subscriptionId: ${{AZURE_SUBSCRIPTION_ID}}
      resourceGroupName: ${{AZURE_RESOURCE_GROUP_NAME}}
      templates:
      - path: <path-to-your-arm-template>
        parameters: <path-to-your-parameter-file>
        deploymentName: <arm-deployment-name>
      bicepCliVersion: <bicep-cli-version>

動作支援 arm/deploy 以 bicep 和 json 格式撰寫的 ARM 範本。 如果您使用 json 格式,可以省略參數 bicepCliVersion 。 您必須具備 Azure Resource Manager 的基本知識。 您可以在 Azure Resource Manager 文件中開始使用 Azure Resource Manager。

自訂 Teams 應用程式

您可以新增環境變數來自訂 Bot 或 Teams 應用程式,以使用您建立的 Microsoft Entra 應用程式。 自訂 Teams 應用程式的方式如下:

針對 Teams 應用程式使用現有的 Microsoft Entra 應用程式

您可以遵循下列步驟將環境變數新增至 .env 檔案,以使用針對您的 Teams 應用程式建立的 Microsoft Entra 應用程式。 如果您還沒有 Microsoft Entra 應用程式,或已經有但不知道在哪裡可以找到正確的值,請參閱 如何在 TeamsFx 專案中使用現有的 Microsoft Entra 應用程式。

  1. 開啟 m365agents.yml 並尋找 aadApp/create 動作。

  2. 尋找在屬性中 writeToEnvironmentFile 儲存 Microsoft Entra 應用程式資訊的環境變數名稱。 如果您使用 Agents Toolkit 建立專案,則預設 writeToenvironmentFile 定義如下:

     writeToEnvironmentFile:
      clientId: AAD_APP_CLIENT_ID
      clientSecret: SECRET_AAD_APP_CLIENT_SECRET
      objectId: AAD_APP_OBJECT_ID
      tenantId: AAD_APP_TENANT_ID
      authority: AAD_APP_OAUTH_AUTHORITY
      authorityHost: AAD_APP_OAUTH_AUTHORITY_HOST
    
  3. 新增步驟 2 中的每個環境變數的值。

    1. 將下列環境變數及其值 env\.env.{env} 新增至檔案。

       AAD_APP_CLIENT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OBJECT_ID=<value of Microsoft Entra application's object id> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_TENANT_ID=<value of Microsoft Entra's tenant id>> # example: 00000000-0000-0000-0000-000000000000
       AAD_APP_OAUTH_AUTHORITY=<value of Microsoft Entra's authority> # example: https://login.microsoftonline.com/<Directory (tenant) ID>
       AAD_APP_OAUTH_AUTHORITY_HOST=<host of Microsoft Entra's authority> # example: https://login.microsoftonline.com
       AAD_APP_ACCESS_AS_USER_PERMISSION_ID=<id of access_as_user permission> # example: 00000000-0000-0000-0000-000000000000
      
    2. 如果您的應用程式需要 Microsoft Entra 應用程式用戶端密碼,請將下列環境變數及其值 env\.env.{env}.user 新增至檔案。

      SECRET_AAD_APP_CLIENT_SECRET=<value of Microsoft Entra application's client secret>
      

注意

  • 如果您在 中使用不同的名稱 writeToEnvironmentFile,請記得更新範例中的環境變數名稱。
  • 如果您不使用動作來 aadApp/create 建立 Microsoft Entra 應用程式,您可以使用慣用的名稱新增必要的環境變數,而不需要遵循上述步驟。
  • 請確定不要在多個環境中共用相同的 Microsoft Entra 應用程式。

針對您的 Bot 使用現有的 Microsoft Entra 應用程式

您可以遵循下列步驟將環境變數新增至 .env 檔案,以使用針對您的 Teams 應用程式建立的 Microsoft Entra 應用程式。 如果您還沒有適用於 Bot 的 Microsoft Entra 應用程式,或您已經有一個但不知道在哪裡可以找到正確的值,請參閱在 TeamsFx 專案中使用現有的 Microsoft Entra 應用程式。

  1. 開啟 m365agents.yml 並尋找 botAadApp/create 動作。

  2. 尋找在屬性中 writeToEnvironmentFile 儲存 Microsoft Entra 應用程式資訊的環境變數名稱。 如果您使用 Agents Toolkit 建立專案,則預設 writeToEnvironmentFile 定義如下:

     writeToEnvironmentFile:
       botId: BOT_ID
       botPassword: SECRET_BOT_PASSWORD
    
  3. 新增步驟 2 中的每個環境變數的值。

    1. 將下列環境變數及其值 env\.env.{env} 新增至檔案。

      BOT_ID=<value of Microsoft Entra application's client id (application id)> # example: 00000000-0000-0000-0000-000000000000    
      
    2. 將下列環境變數及其值 env\.env.{env}.user 新增至檔案。

      SECRET_BOT_PASSWORD=<value of Microsoft Entra application's client secret>
      

注意

  • 如果您在 中使用不同的名稱 writeToEnvironmentFile,請記得更新範例中的環境變數名稱。
  • 如果您不使用動作來 botAadApp/create 建立 Microsoft Entra 應用程式,您可以使用慣用的名稱新增必要的環境變數,而不需要遵循上述步驟。
  • 請確定不要在多個環境中共用相同的 Microsoft Entra 應用程式。

另請參閱

將 Teams 應用程式部署到雲端