Unable to create the bot through `teamsapp provision`
tbhaxor opened this issue · 6 comments
Describe the bug
I have configured the teams app and entra id application from the azure portal and using teamsapp cli to create the bot from the information.
To Reproduce
Steps to reproduce the behavior:
-
Scaffold the application
teamsapp new -c bot -n bot-app -i false
-
Configure the
env/.env.local
# This file includes environment variables that can be committed to git. It's gitignored by default because it represents your local development environment. # Built-in environment variables TEAMSFX_ENV=local APP_NAME_SUFFIX=local # Generated during provision, you can also add your own variables. TEAMS_APP_ID=<REDACTED> BOT_DOMAIN=127.0.0.1:3978 BOT_ENDPOINT=https://127.0.0.1:3978 MS_ENTRA_ID_CLIENT_ID=<REDACTED> MS_ENTRA_ID_CLIENT_SECRET=<REDACTED>
Note — Our project demands ignoring env file, so putting secrets directory here would work.
-
Update the
teamsapp.local.yaml
version: v1.5
provision:
- uses: devTool/install
with:
devCert:
trust: true
writeToEnvironmentFile:
sslCertFile: SSL_CRT_FILE
sslKeyFile: SSL_KEY_FILE
# Create or update the bot registration on dev.botframework.com
- uses: botFramework/create
with:
botId: ${{MS_ENTRA_ID_CLIENT_ID}}
name: ms-bot
messagingEndpoint: ${{BOT_ENDPOINT}}/api/messages
description: ""
channels:
- name: msteams
deploy:
# Build Teams app package with latest env value
- uses: teamsApp/zipAppPackage
with:
# Path to manifest template
manifestPath: ./appPackage/manifest.json
outputZipPath: ./appPackage/build/appPackage.${{TEAMSFX_ENV}}.zip
outputJsonPath: ./appPackage/build/manifest.${{TEAMSFX_ENV}}.json
# Validate using manifest schema
- uses: teamsApp/validateManifest
with:
# Path to manifest template
manifestPath: ./appPackage/manifest.json
# Validate app package using validation rules
- uses: teamsApp/validateAppPackage
with:
# Relative path to this file. This is the path for built zip file.
appPackagePath: ./appPackage/build/appPackage.${{TEAMSFX_ENV}}.zip
# Apply the Teams app manifest to an existing Teams app in
# Teams Developer Portal.
# Will use the app id in manifest file to determine which Teams app to update.
- uses: teamsApp/update
with:
# Relative path to this file. This is the path for built zip file.
appPackagePath: ./appPackage/build/appPackage.${{TEAMSFX_ENV}}.zip
# Generate runtime environment variables
- uses: file/createOrUpdateEnvironmentFile
with:
target: ./.localConfigs
envs:
BOT_ID: ${{MS_ENTRA_ID_CLIENT_ID}}
BOT_PASSWORD: ${{MS_ENTRA_ID_CLIENT_SECRET}}
SSL_CRT_FILE: ${{SSL_CRT_FILE}}
SSL_KEY_FILE: ${{SSL_KEY_FILE}}
- Run the provision command
teamsapp provision --env local
Error
Executing provision
Lifecycle stage: provision(2 step(s) in total). The following actions will be executed:
(1/2) Action devTool/install: installing dependencies
(2/2) Action botFramework/create: creates or updates the bot registration on dev.botframework.com
Executing lifecycle provision
Skip trusting development certificate for localhost.
(✖) Error: Unable to execute action botFramework/create. Error message: Unable to make API call to Developer Portal. Check [Output panel](command:fx-extension.showOutputChannel) for details.
(✖) Error: Failed to Execute lifecycle provision due to failed action: botFramework/create. DeveloperPortalAPIFailedError:Unable to make API call to Developer Portal: AxiosError, Request failed with status code 400, API name: create-bot, X-Correlation-ID: bf9b2565-3558-46f1-9143-0fee82b1fcd5. This may be due to a temporary service error. Try again after a few minutes. data: "The bot name is already registered to another bot application.". Env output: {"SSL_CRT_FILE":"/home/tbhaxor/.fx/certificate/localhost.crt","SSL_KEY_FILE":"/home/tbhaxor/.fx/certificate/localhost.key"}
Execution summary:
Summary:
(×) Error: Lifecycle stage provision failed.
(√) Done: devTool/install was executed successfully.
(√) Done: Skip trusting development certificate for localhost.
(×) Error: botFramework/create failed.
(×) Error: Unable to make API call to Developer Portal: AxiosError, Request failed with status code 400, API name: create-bot, X-Correlation-ID: bf9b2565-3558-46f1-9143-0fee82b1fcd5. This may be due to a temporary service error. Try again after a few minutes. data: "The bot name is already registered to another bot application."
███████████████████▒ 96% | [2/2] Provision: Creating or updating bot registration. (✖) Failed.
(✖) Error: AppStudioPlugin.DeveloperPortalAPIFailedError: Unable to make API call to Developer Portal: AxiosError, Request failed with status code 400, API name: create-bot, X-Correlation-ID: bf9b2565-3558-46f1-9143-0fee82b1fcd5. This may be due to a temporary service error. Try again after a few minutes. data: "The bot name is already registered to another bot application."
Note: AFAIK, This is the first time I am creating bot with the registered entra id application. Please help me debug it.
Expected behavior
It should not partially fails. It is creating bot but then failing later.
VS Code Extension Information (please complete the following information):
- OS: [e.g. iOS]: Windows
- Version [e.g. 22]: 11
CLI Information (please complete the following information):
- OS: [e.g. iOS8.1]: Windows
- Version [e.g. 22]: 3.0.2
Additional context
I have tried the following
- Delete the bot from the dev.botframework.com and then retry
- Delete all the resources (entra id app, teams app, bot from dev.botframework.com), ask the admin to re-issue me entra id app (id + secret) and teams app id. Then re-config and run the command.
In all these case I am getting same error.
Hi, based on the error message, you need to use another bot name, or you have to delete the existing bot with the same name from https://dev.botframework.com/, to avoid duplicate. (Not all bots will be shown in here, and it requires manually deletion by calling graph API)
The bot name is already registered to another bot application.
To use another bot name, you can find botFramework/create action from teamsapp.local.yml, update the name and try local debug again. Thanks!
Does the name need to be globally unique, because I was getting error even from the fresh start (deleting all bots).
I will try again with different account to validate it.
I have found a similar issue that may help you: #9928.
Normally, the name does not need to be unique. It may be related to the bot ID or another reason. If you still encounter this issue, you can try changing the log level of the Teams Toolkit and share more information with us. Thanks.
Now I only have one step in the provision lifecycle
- uses: botFramework/create
with:
botId: ${{MS_ENTRA_ID_CLIENT_ID}}
name: ms-teams-bot
messagingEndpoint: http://localhost:3978/api/messages
description: ""
channels:
- name: msteams
This MS_ENTRA_ID_CLIENT_ID
is coming from the following snippet, which is same as provisioning from aadApp/create
step.
$Application = New-AzADApplication -DisplayName "MS Bot Tutorial"
$Credentials = New-AzADAppCredential -ApplicationId $Application.AppId
Add-Content -Path .\env\.env.local -Value "MS_ENTRA_ID_CLIENT_ID=$($Application.AppId)"
Now I have the following .env.local
file content.
TEAMSFX_ENV=local
APP_NAME_SUFFIX=local
# Generated during provision, you can also add your own variables.
MS_ENTRA_ID_CLIENT_ID=<REDACTED>
TEAMS_APP_ID=<REDACTED>
BOT_DOMAIN=localhost:3978
TEAMS_APP_TENANT_ID=<REDACTED>
The new error message is
(✖) Error: AppStudioPlugin.DeveloperPortalAPIFailedError: Unable to make API call to Developer Portal: AxiosError, Request failed with status code 400, API name: create-bot, X-Correlation-ID: dcd11bc4-389d-485c-a558-cad3983e1881. This may be due to a temporary service error. Try again after a few minutes. data: "The endpoint property was not recognized as valid HTTPS URL"
Call stack: DeveloperPortalAPIFailedError: Unable to make API call to Developer Portal: AxiosError, Request failed with status code 400, API name: create-bot, X-Correlation-ID: 8f45690c-f522-407b-a2e3-e953945fc7ec. This may be due to a temporary service error. Try again after a few minutes. data: "The endpoint property was not recognized as valid HTTPS URL"
at Object.wrapException (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2578506)
at handleBotFrameworkError (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2926717)
at AppStudioClient.createBotRegistration (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2928972)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async AppStudioClient.<anonymous> (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:3085931)
at async Object.createOrUpdateBotRegistration (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2933324)
at async CreateOrUpdateBotFrameworkBotDriver.handler (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2440974)
at async /usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2439955
at async Object.wrapRun (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2966169)
at async CreateOrUpdateBotFrameworkBotDriver.execute (/usr/lib/node_modules/@microsoft/teamsapp-cli/lib/index.js:2:2439908)
I checked, it is because we can't use localhost in the botframework step. Do you have any way to suggest that create dev tunnel before botFramework/create
.
@tbhaxor In tasks.json, you can add a task called "Start local tunnel". This task will start the dev tunnel and output the tunnel endpoint to the env file. You can see more details here. You can also use placeholders in the local yml to use this tunnel URL in the env file.
dev tunnel task
{
// Start the local tunnel service to forward public URL to local port and inspect traffic.
// See https://aka.ms/teamsfx-tasks/local-tunnel for the detailed args definitions.
"label": "Start local tunnel",
"type": "teamsfx",
"command": "debug-start-local-tunnel",
"args": {
"type": "dev-tunnel",
"ports": [
{
"portNumber": 3978,
"protocol": "http",
"access": "public",
"writeToEnvironmentFile": {
"endpoint": "BOT_ENDPOINT", // output tunnel endpoint as BOT_ENDPOINT
"domain": "BOT_DOMAIN" // output tunnel domain as BOT_DOMAIN
}
}
],
"env": "local"
},
"isBackground": true,
"problemMatcher": "$teamsfx-local-tunnel-watch"
},
local yml
- uses: botFramework/create
with:
botId: ${{MS_ENTRA_ID_CLIENT_ID}}
name: ms-teams-bot
messagingEndpoint: ${{BOT_ENDPOINT}}/api/messages
description: ""
channels:
- name: msteams