Azure App service code -
const restify = require('restify');
const { BotFrameworkAdapter } = require('botbuilder');
// Create HTTP server
const server = restify.createServer();
server.listen(3978, () => {
console.log('Bot listening on http://localhost:3978/api/messages');
});
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID || '',
appPassword: process.env.MICROSOFT_APP_PASSWORD || ''
});
// Error handling
adapter.onTurnError = async (context, error) => {
console.error('Unhandled error:', error);
await context.sendActivity('Oops! Something went wrong.');
};
// Listen for incoming requests at /api/messages
server.post('/api/messages', async (req, res) => {
adapter.processActivity(req, res, async (context) => {
// Respond directly using context.sendActivity()
const userMessage = context.activity.text || '<empty>';
await context.sendActivity(`You sent: "${userMessage}"`);
});
});
Error -
{
"statusCode": 401,
"details": {},
"name": "RestError",
"request": {
"url": "https://webchat.botframework.com/v3/conversations/16VXUFHtu2s7p0wxBKLEvz-in/activities/16VXUFHtu2s7p0wxBKLEvz-in%7C0000003",
"method": "POST",
"headers": {
"content-type": "application/json; charset=utf-8",
"x-ms-conversation-id": "REDACTED",
"accept-encoding": "gzip,deflate",
"user-agent": "botframework-connector/4.0.0 Microsoft-BotFramework/3.1 BotBuilder/4.23.3 (Node.js,Version=v22.20.0; Linux 6.6.104.2-1.azl3; x64) core-rest-pipeline/1.22.2 Node/22.20.0 (Linux 6.6.104.2-1.azl3; x64)",
"x-ms-client-request-id": "649cae8f-f8ee-4a3c-b4eb-bd30aefba3d0",
"accept": "*/*",
"authorization": "REDACTED",
"content-length": "504"
},
"timeout": 0,
"withCredentials": false,
"streamResponseStatusCodes": {},
"enableBrowserStreams": false,
"disableKeepAlive": false,
"requestId": "649cae8f-f8ee-4a3c-b4eb-bd30aefba3d0",
"allowInsecureConnection": false
}
}
Note -
The bot is working correctly in Bot framework Emulator, and able to receive messages on /api/messages, however when calling sendActivity() method it gives the error. The bot gives the error when ran in MS teams or test in web chat. The credentials and messaging endpoint are correct.
Webchat log - There was an error sending this message to your bot: HTTP status code InternalServerError