OfficeDev / TeamsFx

Developer tools for building Teams apps
Other
427 stars 165 forks source link

Bug report: Why doesn't the bot program run locally? #7184

Closed tuxxon closed 1 year ago

tuxxon commented 1 year ago

Describe the bug My bot program was running locally until last week (2022-12-09 Friday, KST). But, Today the same bot program is not running even locally. I want to know why.

Could you please let me know why?

To Reproduce Steps to reproduce the behavior:

  1. click F5 (in WSL-ubuntu22 on windows 10)

Expected behavior Working normally.

Screenshots If applicable, add screenshots to help explain your problem. image

VS Code Extension Information (please complete the following information):

CLI Information (please complete the following information):

Additional context

(Totally 5 steps) Teams Toolkit is setting up bot for debugging.

(1/5) Registering the AAD app which is required to create the bot ...
(2/5) Registering the bot in Bot Framework Portal ...

Summary:

√ Skip registering AAD app but use the existing AAD app from args: 1b874558-27b9-49e4-b818-39c85c3b9c3f

× AlreadyCreatedBotNotExist: Could not get bot with id 1b874558-27b9-49e4-b818-39c85c3b9c3f which was created before. 
This could happen if the bot was created by another account. Visit https://aka.ms/teamsfx-switch-account-or-subscription-help to learn more.

Visit https://aka.ms/teamsfx-debug-set-up-bot-task to learn more about 'Set up bot' task.

[2022-12-11T10:13:50.875Z] [Error] - code:Ext.SetUpBotError, message: Set up bot task failed. Please check the output panel to see the details.
ghost commented 1 year ago

Thank you for contacting us! Any issue or feedback from you is quite important to us. We will do our best to fully respond to your issue as soon as possible. Sometimes additional investigations may be needed, we will usually get back to you within 2 days by adding comments to this issue. Please stay tuned.

quinndumala commented 1 year ago

I'm getting this same error on my Teams Toolkit bot app as well. It was running completely fine last week but it now fails with that message when I try to debug.

mikepepping commented 1 year ago

Posting to help gain traction, same problem occurring for my team as well, was working Friday 9th Dec, this morning, no bueno. Mac Ventura, node 16 lts and teams code toolkit.

lucianchen commented 1 year ago

Seems a P1 issue. Getting this same error from Friday afternoon, affecting local testing now, in teams dev portal cannot retrieve correct bot info, tried add bot from there also no luck. Provisioning directly against Azure seems working though.

image

AChaoZJU commented 1 year ago

Hi @lucianchen How can we provision directly against Azure? Is there any difference between provisioning directly against Azure and the normal workflow? Thanks in advance.

IvanJobs commented 1 year ago

Hi All, After some investigations and verifications, It seems there's some live-site issues related to the underlying API of creating bot registration on bot framework portal. We're actively connecting with the corresponding team to handle this issue, please stay tunned, thanks.

To workaround this issue, you can apply the existing bot flow.

  1. Use this link https://dev.botframework.com/bots/new to create bot registration for local debug manually
  2. Update the corresponding BOT_ID, BOT_PASSWORD in project file by following this guide https://github.com/OfficeDev/TeamsFx/blob/dev/docs/fx-core/bot-help.md#how-to-reuse-existing-aad-in-toolkit-v2.
  3. Hit local debug's F5 again, TTK will respect the existing bot.
xlb233 commented 1 year ago

Hi All, After some investigations and verifications, It seems there's some live-site issues related to the underlying API of creating bot registration on bot framework portal. We're actively connecting with the corresponding team to handle this issue, please stay tunned, thanks.

To workaround this issue, you can apply the existing bot flow.

  1. Use this link https://dev.botframework.com/bots/new to create bot registration for local debug manually
  2. Update the corresponding BOT_ID, BOT_PASSWORD in project file by following this guide https://github.com/OfficeDev/TeamsFx/blob/dev/docs/fx-core/bot-help.md#how-to-reuse-existing-aad-in-toolkit-v2.
  3. Hit local debug's F5 again, TTK will respect the existing bot.

There seem to be some issues within the bot registration workflow. This workaround doesn't work for me. image

IvanJobs commented 1 year ago

Hi All, After some investigations and verifications, It seems there's some live-site issues related to the underlying API of creating bot registration on bot framework portal. We're actively connecting with the corresponding team to handle this issue, please stay tunned, thanks. To workaround this issue, you can apply the existing bot flow.

  1. Use this link https://dev.botframework.com/bots/new to create bot registration for local debug manually
  2. Update the corresponding BOT_ID, BOT_PASSWORD in project file by following this guide https://github.com/OfficeDev/TeamsFx/blob/dev/docs/fx-core/bot-help.md#how-to-reuse-existing-aad-in-toolkit-v2.
  3. Hit local debug's F5 again, TTK will respect the existing bot.

There seem to be some issues within the bot registration workflow. This workaround doesn't work for me. image

Hi @xlb233, Thanks for the quick feedback. It seems you used the Developer Portal for Teams to create a new bot. Unfortunately, Developer Portal for Teams may have the same issue. Can you try using BotFramework Portal (https://dev.botframework.com/bots/new) instead as I mentioned in the previous comment? Thanks.

wangrenhang commented 1 year ago

Hi @IvanJobs, I just follow your workaround but still cannot proceed debugging locally

Screen Shot 2022-12-12 at 15 06 55
IvanJobs commented 1 year ago

Hi @IvanJobs, I just follow your workaround but still cannot proceed debugging locally Screen Shot 2022-12-12 at 15 06 55

It looks like there's another underlying API of Getting Bot Registation was also impacted which makes the reusing existing bot flow not working anymore. Thanks for your feedback. Stay tunned - I will give updates as long as the server side API issue was fixed. @wangrenhang

sohamzycus commented 1 year ago

Team, when are we expecting a resolution on this issue. Workaround doesn't work and our development process is totally stuck. Looking for fast resolution and/or any working work around, please.

hidn commented 1 year ago

Hi @IvanJobs ,

Tried the workaround to manually create the app registration and Bot. Unfortunately while it appears that the task did pickup the app id, it still returned ProvisionError.

Was provisioning the bot in local environment for this first time. Not sure if this is the same issue as others, or a different one.

Is there a way to complete the provisioning manually? Or have to wait for the fix (ETA)? - As it blocks a demo session to key stakeholders

Summary:

√ Forwarding ngrok URL https://3f01-115-199-179-165.ngrok.io to http://localhost:3978

Visit https://aka.ms/teamsfx-local-tunnel-task to learn more about 'Start local tunnel' task.

[2022-12-12T09:10:31.467Z] [Info] - Started local tunnel service in 1.61 seconds.
[2022-12-12T09:10:31.508Z] [Info] - Running 'Set up bot' Visual Studio Code task.

(Totally 5 steps) Teams Toolkit is setting up bot for debugging.

(1/5) Registering the AAD app which is required to create the bot ...
(2/5) Registering the bot in Bot Framework Portal ...

Summary:

√ Skip registering AAD app but use the existing AAD app from args: ef37b9d4-c1e2-4ab0-b6d1-484f64b73a93

× ProvisionError: Failed to provision Developer Portal bot registration.

Visit https://aka.ms/teamsfx-debug-set-up-bot-task to learn more about 'Set up bot' task.

[2022-12-12T09:13:22.309Z] [Error] - code:Ext.SetUpBotError, message: Set up bot task failed. Please check the output panel to see the details.
lucianchen commented 1 year ago

Hi @lucianchen How can we provision directly against Azure? Is there any difference between provisioning directly against Azure and the normal workflow? Thanks in advance.

First click provision in the cloud, then use provisioned debugging option

image

@IvanJobs Is there a way to check the console logs from somewhere in Azure console since the local debugging is not working yet? Many thanks!

Ericvf commented 1 year ago

Any progress on this? We are trying to develop an application but its impossible at the moment.

Our team is using Visual Studio and we cannot Debug the application with that using the workaround. When trying Project > Teams Toolkit > Prepare Teams App Dependencies the task always fails with this error:


[core] success to acquire lock for task provisionResourcesV3  on: C:\git\TeamsBotApp\MyTeamsApp3\.fx
execute [TeamsfxCore.provision] start!
execute [AppManifest.provision] start!
execute [AppManifest.provision] success!
Running teams-tab concurrently
execute [TeamsTab.provision] start!
Running aad-app concurrently
[AAD App Registration] Start to provision
Running bot-service concurrently
execute [BotService.provision] start!
execute [TeamsTab.provision] success!
Provisioning bot registration.
[AAD App Registration] Successfully get Azure AD app.
[AAD App Registration] Successfully provision
execute [BotService.provision] failed!
[Teams Toolkit] Execute Task summary----------------------------
teams-tab:provision......................................... [ok]
aad-app:provision........................................... [ok]
bot-service:provision....................................... [failed]
[Teams Toolkit] Task overall result.........................[failed]
execute [TeamsfxCore.provision] failed!
[core] persist env state: C:\git\TeamsBotApp\MyTeamsApp3\.fx\states\state.local.json
[core] persist project setting file: C:\git\TeamsBotApp\MyTeamsApp3\.fx\configs\projectSettings.json
[core] lock released on C:\git\TeamsBotApp\MyTeamsApp3\.fx
{
  "errorType": "UserError",
  "source": "BT",
  "name": "ProvisionError",
  "message": "Failed to provision Developer Portal bot registration. Suggestions: Please check log in output channel and try to fix this issue. Please retry the current step.",
  "stack": "ProvisionError: Failed to provision Developer Portal bot registration. Suggestions: Please check log in output channel and try to fix this issue. Please retry the current step.\n    at Function.UserError (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at Object.wrapError (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at Object.errorHandler (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at BotService.<anonymous> (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\n    at async Promise.all (index 2)\n    at async Object.executeConcurrently (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at async TeamsfxCore.provision (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at async TeamsfxCore.<anonymous> (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)",
  "innerError": {
    "message": "Request failed with status code 500",
    "name": "Error",
    "stack": "Error: Request failed with status code 500\n    at createError (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at settle (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at IncomingMessage.handleStreamEnd (C:\\snapshot\\TeamsFx\\packages\\server\\lib\\index.js)\n    at IncomingMessage.emit (events.js:412:35)\n    at endReadableNT (internal/streams/readable.js:1334:12)\n    at processTicksAndRejections (internal/process/task_queues.js:82:21)",
    "config": {
      "url": "https://dev.teams.microsoft.com/api/botframework",
      "method": "post",
      "data": "{\"botId\":\"32849009-0c84-40e4-89f2-8694f5488db5\",\"name\":\"myteamsapp3-local-debug\",\"description\":\"\",\"iconUrl\":\"\",\"messagingEndpoint\":\"\",\"callingEndpoint\":\"\"}",
      "headers": {
        "Accept": "application/json, text/plain, */*",
        "Content-Type": "application/json",
        "Authorization": "Bearer <redacted>",
        "Client-Source": "teamstoolkit",
        "User-Agent": "axios/0.21.4",
        "Content-Length": 155
      },
      "transformRequest": [
        null
      ],
      "transformResponse": [
        null
      ],
      "timeout": 0,
      "xsrfCookieName": "XSRF-TOKEN",
      "xsrfHeaderName": "X-XSRF-TOKEN",
      "maxContentLength": -1,
      "maxBodyLength": -1,
      "transitional": {
        "silentJSONParsing": true,
        "forcedJSONParsing": true,
        "clarifyTimeoutError": false
      },
      "params": {
        "teamstoolkit": true
      }
    }
  },
  "userData": null,
  "timestamp": "2022-12-12T14:30:32.326Z",
  "displayMessage": "Failed to provision Developer Portal bot registration. Suggestions: Please check log in output channel and try to fix this issue. Please retry the current step.",
  "helpLink": "https://aka.ms/teamsfx-bot-help",
  "issueLink": null
}
[core] finish task:provisionResourcesV3 , time: 102273 ms```
YutongTie-MSFT commented 1 year ago

Hello @IvanJobs

I have seen two more threads about this issue for your reference - https://learn.microsoft.com/en-us/answers/questions/1124839/error-occurs-when-fetching-bot.html?childToView=1125743#answer-1125743 https://learn.microsoft.com/en-us/answers/questions/1125281/teams-developer-portal-can39t-fetch-bot-error.html?childToView=1125771#answer-1125771

I posted your solution in both threads, please let us know once this issue has been fixed. Thank you.

Ericvf commented 1 year ago

@YutongTie-MSFT

Thanks! These steps do work for me now:

  1. Clean solution
  2. Restart VS
  3. Update the Messaging endpoint in the Botframework portal to my local ngrok url
  4. Remove <ProjectCapability Include="TeamsFx" /> from the .csproj
  5. Add the following section to my config.local.json
"bot": {
    "appId": "<bot-id>",
    "appPassword": "<bot-secret>"
  }

Now when I press F5 the web app is running and debuggable.

Ericvf commented 1 year ago

NOTE

The solution above does not correctly provision a new TeamApp package (manifest) to Teams. That means that your ngrok.io urls will not be updated in the manifest.json. For our Teams task modules we require the ngrok url to be present as validDomains in the manifest.

If you also need to upload a new TeamsApp manifest:

  1. Add <ProjectCapability Include="TeamsFx" /> back to the project
  2. Use Project > Teams Toolkit > Zip App Package > For Local
  3. Upload the ~/build/appPackage/appPackage.local.zip file to the Teams Admin portal
  4. Install the app within Teams
  5. Remove <ProjectCapability Include="TeamsFx" />

Now when I press F5 the tabs and task modules are working correctly

IvanJobs commented 1 year ago

Hi @lucianchen How can we provision directly against Azure? Is there any difference between provisioning directly against Azure and the normal workflow? Thanks in advance.

First click provision in the cloud, then use provisioned debugging option image

@IvanJobs Is there a way to check the console logs from somewhere in Azure console since the local debugging is not working yet? Many thanks!

@lucianchen You can check Azure App Service's application log stream on Azure portal instead. Check https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs.

lucianchen commented 1 year ago

Hi @lucianchen How can we provision directly against Azure? Is there any difference between provisioning directly against Azure and the normal workflow? Thanks in advance.

First click provision in the cloud, then use provisioned debugging option image @IvanJobs Is there a way to check the console logs from somewhere in Azure console since the local debugging is not working yet? Many thanks!

@lucianchen You can check Azure App Service's application log stream on Azure portal instead. Check https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs.

Thanks, figured it out later🙏 Btw tried disabling the Set up bot task to bypass this error in tasks.json , then specified Messaging endpoint in Azure console to be ngrok host url, bots got launched locally and can do local debugging with Bot Framework Simulator now. image

Just after launching Teams and install the app, then interact with the bot app, local bot side still didn't get any messages... Guess still missing some config somewhere in the workflow, @IvanJobs any workaround tips would be appreciated.

image

IvanJobs commented 1 year ago

@kuojianlu will give a working workaround for this server-side api issue soon. The basic logic is to remove steps of calling those APIs from local debug, and provide guide to do those steps manually. Sorry for the inconvenience, and please stay tunned. @lucianchen @Ericvf @YutongTie-MSFT @hidn @sohamzycus @wangrenhang @xlb233 @quinndumala @tuxxon

kuojianlu commented 1 year ago

Hi all, here is a workaround for VS Code:

  1. In .vscode/tasks.json, remove "Set up bot" from the "dependsOn" field of "Start Teams App Locally" task.
  2. From command palette, run "Tasks: Run Task" and select "Start local tunnel". Then open "Start local tunnel" terminal, you can see the forwarding url like "https://f633-2404-f801-9000-18-6fec-00-26d.ngrok.io".
  3. Create an AAD app with your M365 account. Create a client secret and copy the secret value which will be used later.
  4. Create a bot in https://dev.botframework.com/bots/new with your M365 account. Set the messaging endpoint using the above forwarding url like "https://f633-2404-f801-9000-18-6fec-00-26d.ngrok.io/api/messages". After the bot is created, configure Microsoft Teams channel.
  5. In templates/appPackage/manifest.template.json, update botId to the AAD app client id; update validDomains to the domain of the above forwarding url like "f633-2404-f801-9000-18-6fec-00-26d.ngrok.io".
  6. In bot/.env.teamsfx.local, update "BOT_ID" to the AAD app client id; update BOT_PASSWORD to the AAD app client secret.
  7. F5.
quinndumala commented 1 year ago

Hi all, here is a workaround for VS Code:

  1. In .vscode/tasks.json, remove "Set up bot" from the "dependsOn" field of "Start Teams App Locally" task.
  2. From command palette, run "Tasks: Run Task" and select "Start local tunnel". Then open "Start local tunnel" terminal, you can see the forwarding url like "https://f633-2404-f801-9000-18-6fec-00-26d.ngrok.io".
  3. Create an AAD app with your M365 account. Create a client secret and copy the secret value which will be used later.
  4. Create a bot in https://dev.botframework.com/bots/new with your M365 account. Set the messaging endpoint using the above forwarding url like "https://f633-2404-f801-9000-18-6fec-00-26d.ngrok.io/api/messages". After the bot is created, configure Microsoft Teams channel.
  5. In templates/appPackage/manifest.template.json, update botId to the AAD app client id; update validDomains to the domain of the above forwarding url like "f633-2404-f801-9000-18-6fec-00-26d.ngrok.io".
  6. In bot/.env.teamsfx.local, update "BOT_ID" to the AAD app client id; update BOT_PASSWORD to the AAD app client secret.
  7. F5.

Didn't work for me, unfortunately. I'm getting the following error: × GetLocalDebugConfigFailed: Missing configuration data for manifest. You may need to run 'debug' first. Data required: state.teams-bot.botId,state.teams-bot.domain.

kuojianlu commented 1 year ago

@quinndumala Have you done the step 5?

  1. In templates/appPackage/manifest.template.json, update botId to the AAD app client id; update validDomains to the domain of the above forwarding url like "f633-2404-f801-9000-18-6fec-00-26d.ngrok.io".

For example:

{
    ...
    "bots": [
        {
            "botId": "5800acec-8e11-4407-8430-04d7610e0236",
            ...
        }
    ]
    ...
    "validDomains": [
        "911f-2404-f801-9000-1a-6fea-00-26d.ngrok.io"
    ]
    ...
}
quinndumala commented 1 year ago

@quinndumala Have you done the step 5?

  1. In templates/appPackage/manifest.template.json, update botId to the AAD app client id; update validDomains to the domain of the above forwarding url like "f633-2404-f801-9000-18-6fec-00-26d.ngrok.io". For example:
{
    ...
    "bots": [
        {
            "botId": "5800acec-8e11-4407-8430-04d7610e0236",
            ...
        }
    ]
    ...
    "validDomains": [
        "911f-2404-f801-9000-1a-6fea-00-26d.ngrok.io"
    ]
    ...
}

Okay, it now works after replacing the variables in manifest.template.json with the literal string values. I initially just added them to the state.env.json file. Many thanks!

Priyanka-Diligent commented 1 year ago

3. Create an AAD app with your M365 account.

Create an AAD app with your M365 account. How to create an AAD app with your M365 account? Can somebody please help me.

kuojianlu commented 1 year ago

@Priyanka-Diligent

  1. Open https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/Overview, login with your M365 account.
  2. Click "App registrations" from left side bar, then click "New registration".
IvanJobs commented 1 year ago

Hi All,

The server side API issue was resolved around two hours ago.

I did a quick check, and the local debug experience of TTK was working good now. Can you help verify this in your convenience and give some feedbacks here? Thanks. @lucianchen @Ericvf @YutongTie-MSFT @hidn @sohamzycus @wangrenhang @xlb233 @quinndumala @tuxxon

YutongTie-MSFT commented 1 year ago

Thanks for posting the fix confirmation! @IvanJobs Working for me now.

quinndumala commented 1 year ago

It's working for me now too. Thank you @IvanJobs!

Ericvf commented 1 year ago

Thanks all, problems here resolved as well

tuxxon commented 1 year ago

Thanks all for posting the fix. It's working for me.