You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure部署的Node.js TypeScript版Echo Bot无法运行,请求技术排查协助

Troubleshooting Your Node.js TypeScript Echo Bot (User Assigned MSI) with NotFound Error

Let's break down the most common issues that could be causing your bot to return a NotFound error, and walk through actionable checks to resolve them:

1. Verify Web App Deployment & Endpoint Reachability

First, confirm your bot code is running correctly on the Web App:

  • Check the Deployment Center in your Web App resource: Look for build/deployment errors (critical for TypeScript—ensure the build step compiles .ts files to .js and outputs them to the correct directory).
  • Test the /api/messages endpoint directly: Send a POST request to https://<your-webapp-name>.azurewebsites.net/api/messages (use tools like Postman or curl). If this returns 404 immediately, your bot's route isn't properly registered. Double-check your Express setup—you should have code like this to map the endpoint:
    server.post('/api/messages', async (req, res) => {
      await adapter.processActivity(req, res, async (context) => {
        await bot.run(context);
      });
    });
    

2. Validate User Assigned MSI Permissions & Configuration

Misconfigured MSI is a frequent culprit here:

  • Assign the correct role: Ensure your Web App's User Assigned MSI has the Bot Channel Registration Contributor (or Bot Service Contributor) role assigned to your Azure Bot resource. Without this, the Web App can't authenticate with the Bot Service.
  • Check .env values carefully:
    • MicrosoftAppType must be set to UserAssignedMSI
    • MicrosoftAppId should be the Client ID of your User Assigned MSI (not the Azure Bot's App ID—this is a common mix-up!)
    • MicrosoftAppTenantId is your Azure tenant ID
    • Leave MicrosoftAppPassword blank/undefined—you don't need it for MSI

3. Check Bot Framework Adapter Initialization

Make sure your adapter is set up to use MSI correctly in code:

import { BotFrameworkAdapter } from 'botbuilder';

const adapter = new BotFrameworkAdapter({
  appId: process.env.MicrosoftAppId,
  appPassword: undefined, // No password needed for User Assigned MSI
  appType: 'UserAssignedMSI',
  tenantId: process.env.MicrosoftAppTenantId
});

// Add error handling to catch internal issues
adapter.onTurnError = async (context, error) => {
  console.error(`[onTurnError] Unhandled error: ${error}`);
  await context.sendActivity('Oops, something went wrong!');
};

Without proper error handling, internal failures (like MSI token retrieval errors) might not surface, making it look like a NotFound issue.

4. Confirm Azure Bot Messaging Endpoint & Identity Settings

  • Double-check the Messaging endpoint in your Azure Bot resource: It must exactly match https://<your-webapp-name>.azurewebsites.net/api/messages (HTTPS is mandatory, path must be correct).
  • In the Azure Bot's Configuration tab, ensure Managed identity is set to User assigned and you've selected the correct MSI resource.

5. Dig Into Logs for Detailed Errors

Logs will reveal the root cause behind the NotFound error:

  • Use the Log Stream in your Web App to see real-time server logs—look for errors related to route registration, MSI token acquisition, or bot initialization.
  • Check Application Insights (if enabled) for traces and exceptions from your bot.
  • In the Azure Bot's Channels tab, view error logs for Web Chat/Direct Line—sometimes a 401 (unauthorized) error gets translated to a NotFound response at the channel level.

6. Test Locally to Isolate Code vs. Deployment Issues

Run your bot locally with the Bot Framework Emulator. If it works as expected (sends welcome messages and echoes input), the problem is in your Azure deployment/configuration. If it fails locally, debug your code first—check if the welcome message is properly registered (e.g., using a ConversationUpdate handler) and that the echo logic is correctly implemented.


内容的提问来源于stack exchange,提问作者userbin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 15:57:43