1

This is my second thread about this issue and I tried every suggestion provided in the last thread about this. The URL to the last thread is here: Bot works in Bot Framework Emulator on local computer, but not after it's deployed to Microsoft Azure - HTTP status code NotFound.

I followed the exact directions at https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli?view=azure-bot-service-4.0&tabs=newrg.

After following these instructions involving Azure CLI, I had three resource types that were created under my Azure subscription ID: Bot Channels Registration, App Service, and App Service Plan.

Unfortunately, when I enter a message in the “Test in Web Chat” window under “Bot Management” for the “Bot Channels Registration” resource, I received a message back saying “couldn’t send retry.”

When I go to channels under “Bot Management” for the “Bot Channels Registration” resource, click “Issues” under “Health”, I see this message: "There was an error sending this message to your bot: HTTP status code InternalServerError."

Here are some additional details that were highlighted in the last thread. I definitely took them into consideration as you’ll read below.

Before entering this code, a “.deployment” file was created in the bot’s directory and a zip file was subsequently created that contained the “.deployment” file in it: az webapp deployment source config-zip --resource-group "" --name "" --src "code.zip"

I went to this link, and I saw 21 .dll files listed on that page under the “WWWROOT” section: https:/.scm.azurewebsites.net/dev/wwwroot/

I went to this URL (https://.scm.azurewebsites.net/dev/wwwroot/:vs.output), pressed run and I did not see anything unusual on the right side of the screen under “Output”. It says “200.0 OK” at the last message under “Output” after “Click on http://.azurewebsites.net to open your site 2019-06-27T17:52:04 PID[32228] Information Sending response.” When I click on the “http://.azurewebsites.net” link, a new tab opens and I see this message at the top: " Bot Started."

I also tried publishing from Visual Studio.

When I tried publishing from Visual Studio, I followed the directions at this page: https://learn.microsoft.com/en-us/visualstudio/deployment/deploying-applications-services-and-components?view=vs-2019

I created a new Azure App Service, chose the correct subscription and resource group, turned off Application Insights since that’s not needed right now, and then pressed “Create.”

I then pressed “Publish.”

Next, I created a Bot Channels Registration and added the destination URL from the edit link at the top of “Publish” screen in Visual Studio. That bot did not work when testing in the web chat.

Creating a web app bot in Azure doesn’t help at this stage since a default echo or basic bot template seems required for the creation.

Just to elaborate again, the bot I’m attempting to test in Azure works perfectly in the bot emulator after running it in Visual Studio. Somewhere in the publishing/deployment stage to Azure lies an issue. What can we do to resolve this issue?


UPDATE:

I followed Matt Stannett's advice, who added a comment under this thread.

I went to Monitoring > App Service Logs and enabled Application Logging (Filesystem) as well as Detailed error messages and Failed request tracing.

Next, I went to Monitoring > Log stream tab. I kept this tab opened and loaded up Web Chat in another tab to see real-time logs.

I converted the html code to the pdf format and read the results.

Here is the top-level information regarding the error message:

HTTP Error 500.0 - Internal Server Error

The page cannot be displayed because an internal server error has occurred.

Most likely causes:

  • IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
  • IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
  • IIS was not able to process configuration for the Web site or application.
  • The authenticated user does not have permission to use this DLL.
  • The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:

  • Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
  • Check the event logs to see if any additional information was logged.
  • Verify the permissions for the DLL.
  • Install the .NET Extensibility feature if the request is mapped to a managed handler.
  • Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:

Error Code: 0x00000000

Module: AspNetCoreModule

Handler: aspNetCore

Notification: ExecuteRequestHandler

Logon Method: Anonymous

Logon User: Anonymous

More Information:

This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error. View more information »

  • I would recommend turning on Application Insights for your bot because it will help with finding the underlaying error. Alternatively on your App Service you could go to Monitoring > App Service Logs and enable Application Logging (Filesystem) as well as Detailed error messages and Failed request tracing. Then you can go to Monitoring > Log stream tab, once this tab has opened you should load up Web Chat in another tab and you will be able to see real-time logs. Once you get the error message out of there, you should update your question. – Matt Stannett Jun 27 '19 at 20:30
  • Thank you very much, Matt. I followed those steps and included the details from the error message in the log stream section at the bottom of my original thread. – DataExaminer555 Jun 28 '19 at 14:06
  • Hmmm, no more insight from that. You will have to remotely debug webchat to see what it going on. I have outlined this process in my answer [here](https://stackoverflow.com/a/56626814/5209435) under the "Debugging techniques" section - the area in yellow is mainly what you're interested in. – Matt Stannett Jun 28 '19 at 21:40
  • Hi, Matt. Thank you so much for directing me to those steps. i have a question about two of the steps. At the step, "In Visual Studio Copy the appId and appPassword key value pairs from the Production endpoint in the .bot file to the Development endpoint," I would enter the "MicrosoftAppId" and ""MicrosoftAppPassword" in the appsettings.json file and no where else? I'm just trying to make sure. Also at the "Ensure that the endpoint value for the Development endpoint is set to the localhost URL (http://localhost:3978/api/messages )," where exactly would I change the endpoint value? – DataExaminer555 Jul 01 '19 at 14:39
  • Additionally, as of today, when I run ANY bot in Visual Studio...this is what happens when I try to test the bot in the Bot Emulator using the settings I had before making your suggested configuration changes: A browser tab launches with "http://localhost:3978/" as the URL. I see a text at the top of this tab that says “QnA Prompting Bot Started.” That’s the bot template I deployed to Azure, but I see this message regardless of any bot I run in Visual Studio to test in the bot emulator. Every bot I try to test in the bot emulator is unresponsive—probably because of an endpoint setting. – DataExaminer555 Jul 01 '19 at 15:02
  • You are correct that the appId and appPassword map to the Microsoft App Id and Microsoft App Password. The instructions were written for debugging a .bot file which has since been replaced by the appsettings.json file. If the App Id and App Password are set in the appsetting then you will need to enter them when you are starting up your bot otherwise you will get authentication errors. With the endpoint that also used to live in the bot file but isn’t part of the new appsettings template so you can ignore it. If you wanted to change it through it would be on the debug tab under... – Matt Stannett Jul 01 '19 at 18:57
  • ... project properties (right click on the project in Visual Studio). It sounds like your emulator is having a problem so I would try uninstalling it then installing the latest version from the github releases page. – Matt Stannett Jul 01 '19 at 18:59

1 Answers1

1

Just a quick clarification here, since there appears to be two distinct issues:

  1. Your instance of the Bot Framework Emulator seems to have issues - I would recommend uninstalling it then getting the latest version from here.

  2. Your bot does not work in production - in order to debug the production channel locally you will need to ensure that the app id and app password in your app settings are populated with the values from Azure, then you should be able to follow the rest of the instructions below to chat in the production channel (Teams, WebChat, DirectLine etc NOT in the emulator) and have the production channel run against your local code so that you can set breakpoints and inspect variables to debug where the issue is.

Instructions based on guides here and here:

Debugging techniques

  • Ensure that the bot is working locally.
  • Check the Log stream or log files via Kudu under Development Tools > Advanced tools for your App Service. You can also turn on Application logs under Monitoring App Service logs for your App Service then view the log stream via the Log stream section of your App Service while you test your bot in Web Chat in another tab/window.
  • Check that the App Settings entries exist and are correct (password, app id etc).
  • Ensure that ngrok is installed.
  • Open the solution in Visual Studio.
  • Start debugging in Visual Studio.
  • Note down the port in the localhost address for the web page that is opened (this should be 3978).
  • Navigate into the directory where you extracted ngrok.
  • Type cmd into the address bar and press enter to open a new command prompt window.
  • Create a publicly accessible URL that tunnels all http traffic on a specified port to your machine:
  • ngrok http 3978 --host-header=localhost
  • Copy the https forwarding URL.
  • This should be in the form of https://(characters-here).ngrok.io.
  • Keep the command prompt window running ngrok open because once it is closed the URL will no longer be accessible.
  • Stop debugging.
  • In the Azure Portal open the Web App Bot resource.
  • Go to Bot management > Settings > Configuration and copy the URL into the description field so that it is saved somewhere.
  • Replace the everthing in the endpoint URL textbox before /api/messages with the ngrok URL.
  • The final URL should be in the form of https://(ngrok-url)/api/messages.
  • Click Save (you have click outside of the text box for the Save button to be enabled).
  • Go to App Service > Settings > Configuration and note down the value for MicrosoftAppId and MicrosoftAppPassword.
  • In The Azure portal, under the Configuration > Application settings tab of the App Service Visual copy the values for the MicrosoftAppId and MicrosoftAppPassword entries into the matching entries in your appsettings.json file (since you will be running a production endpoint against local code you need to have all of the relevant keys set).
  • Save your changes in Visual Studio.
  • Start debugging in Visual Studio.
  • Open Test in Web Chat in Azure.
  • Test the bot functionality.
  • You should hit any breakpoints that you've set in the code.

CLEAN UP STEPS - IMPORTANT!!!

  • Restore the Messaging endpoint URL for the Web App Bot in Azure to it's original value AND save the change.
  • Undo/revert any changes to the appsettings.json file.
  • Close the command prompt window running ngrok.
  • Close the Bot Framework Emulator
Matt Stannett
  • 2,700
  • 1
  • 15
  • 36
  • Thank you for the detailed and insightful advice. I tried all of the steps. Unfortunately, after doing all of that and testing my bot in Web Chat, the bot doesn't respond. I see this message in the command line window: "POST /api/messages 404 Not Found." Also, the Log Stream doesn't seem to detect my bot at all and continues saying "No new trace in the past ___ min(s)." In the Channels window for the bot, I continue seeing this error message: "There was an error sending this message to your bot: HTTP status code NotFound." – DataExaminer555 Jul 02 '19 at 16:12
  • I'm still in the process of setting up and utilizing Kudu, in case it would help to clarify why these issues are occurring and what can be done to correct them. – DataExaminer555 Jul 02 '19 at 16:19
  • It sounds like something is going wrong in the retrieve/zip step. Make sure that you are zipping from the correct directory as specified in the instructions.= [here](https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-deploy-az-cli?view=azure-bot-service-4.0&tabs=newrg#zip-up-the-code-directory-manually). If this still doesn't work then I would create an echo bot through the Azure Portal, then follow the steps [here](https://www.cloudguy.pro/setting-up-a-build-and-release-pipeline-for-azure-bot-service-using-azure-devops/). You want to do the following: – Matt Stannett Jul 03 '19 at 05:34
  • 1. Create an echo bot in the Azure Portal. 2. Test the echo bot using web chat. 3. Download the code from the Portal (overview > build/code will get your a zip). 4. Create an Azure DevOps account (it's free) 5. Create a project and repo for your bot. 6. Check out the empty repo. 7. Unzip the echo bot code into the repo. 8. Commit and push your changes. 9. Setup Build pipeline as per link above. 10. Setup Release pipeline as per above except deploy to your existing app service (created with your echo bot.) 11. Trigger a build manually (a release should be auto triggered too). – Matt Stannett Jul 03 '19 at 05:36
  • 12. Once the release has been deployed successfully test your echo bot in Web Chat again. 13. In the Release pipeline under the tasks/steps ensure that the remove additional files at destination option is [enabled](https://stackoverflow.com/a/52341194/5209435) 14. Delete all of the echobot files in the repo on your PC. 15. Copy the files from the bot you want to deploy into the repo. 16. Commit and push your changes. 17. A Build and release should be triggered automatically. 18. Test the bot functionality once the release is complete. – Matt Stannett Jul 03 '19 at 05:43
  • NOTE: You do not need to complete the Add Bot Registration Channel and Update the pipeline steps from the article above. – Matt Stannett Jul 03 '19 at 05:46