1
votes

I have been working with Kyle H. in Azure Support Chat and he recommended that I post this here.

Please be understanding, as I have read every related Stack Overflow post relevant and have exercised due diligence.

I have completely deleted and restarted both my Azure resources AND source code multiple times. Using this guide: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-deploy-azure?view=azure-bot-service-4.0

The bot project is using the v4 template 'Echo'.

In Azure Portal, Test in Web Chat: "There was an error sending this message to your bot: HTTP status code Forbidden"

In Bot Emulator with ngrok configured: Cannot post activity. Unauthorized.

Following instructions here: https://docs.microsoft.com/en-us/azure/bot-service/bot-service-troubleshoot-authentication-problems?view=azure-bot-service-4.0#step-2

I ran: curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id=b7404e9f-0e74-4174-aa4f-447fdd96d7f0&client_secret=REMOVED&scope=https%3A%2F%2Fapi.botframework.com%2F.default" and I am returned a valid access token.

I have confirmed multiple times that my app registration is using https, as well as the /api/messages route, and that my app service has the two keys MicrosoftAppId and MicrosoftAppPassword and they are set appropriately. Including stopping and starting and the restart functionality. I have also ensured that during deployment(VS 2017 Publish), it removes existing files.

My last attempt was to upgrade the template 'Echo' bot to .net core 2.2 - which deployed successfully. I again verified app id and app password set as described above, and unfortunately both the Bot Emulator and Test in Web Chat failed with the same errors.

Edit 1: I used 'Create new resource' and picked the 'Web App Bot' template. I chose the 'Echo' bot. I chose 'Automatically Generate Application ID and Password' as well. This resulted in a bot deployment that did not have authorization errors. However, I noticed that instead of a 'Bot Channel Registration' resource - it instead created a 'Web App Bot'. When inspecting 'Application Settings', application ID and password aren't present, yet it functions just fine.

Edit 2: I researched deeper, and learned that the 'Web App Bot' created in azure uses the botFilePath and botFileSecret application settings and likely keeps the app id and app password there.

Edit 3: There is a huge difference between the v4 BotBuilder EchoBot template you use in visual studio when creating a new project and the EchoBot template used in Azure when creating a new resource. Narrowing it down now.

Edit 4: I was able to use the Azure created web bot and modify it to continue my work. Was not possible with the Vsix templates even with ensuring app config and .bot file config were correct.

Edit 5: I also learned that v4 doesn't support Microsoft Teams - and that was the entire purpose of my endeavor. v3 documentation is near nonexistent. So I think I'll be using an entirely different framework to integrate with Teams. I even attempted to implement: https://github.com/OfficeDev/BotBuilder-MicrosoftTeams-dotnet but my bot only responds with "Sorry, there was a problem encountered with your request" in Teams.

Edit 6: I managed to get my bot functioning with Microsoft Teams, during the process solving the unauthorized error.

I created the Echo bot in Azure - and used App Studio in Microsoft Teams to add a manifest and add the bot to our team.

After that, I imported the project located here: https://github.com/OfficeDev/BotBuilder-MicrosoftTeams-dotnet/tree/master/CSharp/Samples/Microsoft.Bot.Builder.Teams.TeamEchoBot

Then I modified setup.cs to work with the encrypted .bot file, based on the source code that created the Echo Bot in Azure.

2
Can you post the source of your startup.cs file please?Drew Marsh
For clarification, were you able to get your echo bot running locally? And regarding your Edits 1 and 2: You got the Azure-created Web App Bot working, but can't get your VS Template-created bot working; is that right?mdrichardson
If you are still struggling to create a bot in Visual Studios with the correct endpoints, you can follow this guide to create a bot on Azure and then download the source code to your machine.tdurnford
@mdrichardson Yes, in all cases I had success running locally with the bot emulator. Your second question, yes. Even though my VS Template-created bot was published to Azure with updated .bot file including production configuration. I've tried both encrypted and unencrypted.Matthew Blair
@tdurnford Thanks, this is the approach I took when I learned the Azure created bot. I then modified the bot and published to Azure - and it continues to function. I determined the variance in startup.cs was the culprit.Matthew Blair

2 Answers

0
votes

The VSIX templates are going to generate Startup code that uses the .bot file for appId/secret and, when deployed to Azure, is going to be looking for an endpoint named "production" which you would have had to add yourself to the default .bot file with the appid and secret from your provisioned bot.

For more details, check out this previous answer I gave on this topic .

0
votes

If you are struggling to deploy your bot, I would recommend looking at this guide. The steps will walk you through creating a bot on Azure, and then you can download the source code, develop your bot, and redeploy it.

Glad I could help!