[Question] Internal Server Error on sending messages to bot, after deployment to Azure?
Bot Info
- App ID: 7f4b8f38-34ce-4b13-9151-f88659b758d2
- SDK Platform: Node.js
- SDK Version: 3.11
Issue Description
After deploying the bot to Azure, using local git and azure cl, cannot connect to the bot or send messages on either the Bot Emulator, or the "Test" web panel at https://dev.botframework.com/
Everything works fine locally. Have tried out the steps in https://docs.microsoft.com/en-us/bot-framework/troubleshoot-authentication-problems#enable-security-localhost and can successfully do each till step 4.
This is my bot's endpoint: https://goliathalpha.azurewebsites.net/api/messages
Code
var restify = require('restify');
var builder = require('botbuilder');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: 'app id string' //replaced before deployment
appPassword: 'app password string' //replaced before deployment
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Receive messages from the user and respond by echoing each message back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, [
//Default dialog waterfall steps
function(session) {
session.send("Hi, Welcome to Goliath Bank!");
session.beginDialog("mainMenu");
}
]);
//.... further dialogs
Error from the Web Chat channel: There was an error sending this message to your bot: HTTP status code InternalServerError Error from the bot emulator: [17:37:19] -> POST Request to 'https://goliathalpha.azurewebsites.net/api/messages' failed: [500] Internal Server Error
Let me know if you need any other info.
Try to use the code blocks in git and reproduce steps, will make it easier for the MS guys :)
@jochem4207 : Good tip!
Also, upon checking out the application logs on Azure, here's what I get:
Application has thrown an uncaught exception and is terminated:
Error: Cannot find module 'domain'
at Function._resolveFilename (module.js:337:11)
at Function._load (module.js:279:25)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\restify\lib\server.js:5:14)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
@sajal2692 Something is wrong with your bot code. Your bot app crashed when it tried to run on the deployment server because it couldn't find a dependent module.
Try deploying one of the example bots here and report back if you run in to the same deployment issues.
@nwhitmont Thanks for the reply. Deploying one of the example bots worked fine.
I still don't understand why the bot app's working fine when deployed locally, and crashing on Azure. I haven't installed the dependent module 'domain' explicitly (it looks like Restify's using it?).
When I downgraded Restify, it gives me a different error on Azure deployment (but still works fine locally).
details:
TypeError: Cannot read property 'prototype' of undefined
at Object.inherits (util.js:511:43)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\csv-generate\lib\index.js:95:6)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Module.require (module.js:359:17)
at require (module.js:375:17)
at Object.<anonymous> (D:\home\site\wwwroot\node_modules\csv\lib\index.js:4:12)
at Module._compile (module.js:446:26)
again, the module that's throwing the error 'csv-generate', 'csv' is installed by npm itself.
Fixed the issue.
Had to specify the node version in package.json, or Azure deployed it on 0.10, hence the module problems.
Might make sense to add this info in the deployment documentation.
Glad you got this working.
my bots endpoint is https://hcmcertification.azurewebsites.net/api/messages. i get internal server error when i test in web chat .plz help me
I am facing the same issue. By bot code runs properly on local machine but once deployed on Azure it is giving internal server error while testing using webchat channel.
Need your expert advice to resolve this :(
@pankajdmishra I had the same issue, but as it turned out, I was not careful enough on the coding side when initializing the Connector:
var useEmulator = (process.env.NODE_ENV == 'development');
var connector = useEmulator ? new builder.ChatConnector() : new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
Make sure that builder refers the correct class and that it gets the correct settings passed into the constructor. Doubling checking my code and passing in the right fields solved it for me.
Another option is to change the messaging endpoint for the bot in Azure, and debug locally: https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/