如何解决在团队机器人中遇到多个404和405错误
我正在对我目前正在开发的Teams Bot进行一些调查。当我查看Application Insights时,看到很多404错误,在某些其他情况下,出现405错误-我试图了解是否错过了任何内容。
我将App Service设置为“ Always On”,因此我假设它每5分钟轮询一次该服务,以防止其空闲。但是,我看到很多404错误,特别是指向 GET / 端点,在其他情况下也指向405错误,这指向了 api / messages 端点。
我在环境变量中设置了应用程序ID和应用程序密码,我也使用Cosmos DB设置了存储,如下面的index.js文件所示。我还检查了Teams清单以确保它指向Bot ID,并且最近还添加了bot域,以查看是否有区别。
const restify = require('restify');
const path = require('path');
// Import required bot services.
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
const { BotFrameworkAdapter,ConversationState,UserState } = require('botbuilder');
// Import required services for bot telemetry
const { ApplicationInsightsTelemetryClient,TelemetryInitializerMiddleware } = require('botbuilder-applicationinsights');
const { TelemetryLoggerMiddleware,NullTelemetryClient } = require('botbuilder-core');
// Import our custom bot class that provides a turn handling function.
const { DialogBot } = require('./bots/dialogBot');
const { ProvisioningProfileDialog } = require('./dialogs/provisioningProfileDialog');
// Read environment variables from .env file
const ENV_FILE = path.join(__dirname,'.env');
require('dotenv').config({ path: ENV_FILE });
// Create the adapter. See https://aka.ms/about-bot-adapter to learn more about using information from
// the .bot file when configuring your adapter.
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,appPassword: process.env.MicrosoftAppPassword
});
// Define the state store for your bot.
const { CosmosDbPartitionedStorage } = require('botbuilder-azure');
const cosmosstorage = new CosmosDbPartitionedStorage({
cosmosDbEndpoint: process.env.CosmosDbEndpoint,authKey: process.env.CosmosDbAuthKey,databaseId: process.env.CosmosDbDatabaseId,containerId: process.env.CosmosDbContainerId,compatibilityMode: false
});
// Create conversation state with storage provider.
const conversationState = new ConversationState(cosmosstorage);
const userState = new UserState(cosmosstorage);
// Create the main dialog.
const dialog = new ProvisioningProfileDialog(userState);
const bot = new DialogBot(conversationState,userState,dialog);
dialog.telemetryClient = telemetryClient;
// Catch-all for errors.
const onTurnErrorHandler = async (context,error) => {
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment,you should consider logging this to Azure
// application insights.
console.error(`\n [onTurnError] unhandled error: ${ error }`);
// Send a trace activity,which will be displayed in Bot Framework Emulator
await context.sendTraceActivity(
'OnTurnError Trace',`${ error }`,'https://www.botframework.com/schemas/error','TurnError'
);
// Send a message to the user
await context.sendActivity('The bot encountered an error or bug.');
await context.sendActivity('To continue to run this bot,please fix the bot source code.');
// Clear out state
await conversationState.delete(context);
};
// Set the onTurnError for the singleton BotFrameworkAdapter.
adapter.onTurnError = onTurnErrorHandler;
// Add telemetry middleware to the adapter middleware pipeline
var telemetryClient = getTelemetryClient(process.env.InstrumentationKey);
var telemetryLoggerMiddleware = new TelemetryLoggerMiddleware(telemetryClient);
var initializerMiddleware = new TelemetryInitializerMiddleware(telemetryLoggerMiddleware);
adapter.use(initializerMiddleware);
// Creates a new TelemetryClient based on a instrumentation key
function getTelemetryClient(instrumentationKey) {
if (instrumentationKey) {
return new ApplicationInsightsTelemetryClient(instrumentationKey);
}
return new NullTelemetryClient();
}
// Create HTTP server.
const server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978,function() {
console.log(`\n${ server.name } listening to ${ server.url }.`);
console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
console.log('\nTo talk to your bot,open the emulator select "Open Bot"');
});
// Listen for incoming requests.
server.post('/api/messages',(req,res) => {
adapter.processActivity(req,res,async (context) => {
// Route the message to the bot's main handler.
await bot.run(context);
});
});
虽然Bot大部分情况下运行正常,但我是否错过了一些带有这些错误的内容,或者这是预期的行为,因为它正在轮询响应?
预先感谢
解决方法
- 您的漫游器还包含网页吗?节点样本不是.NET samples do。如果没有,那么当然会收到404。我倾向于同意您的看法,这可能是轮询的原因。
- 通常(特别是从模板或示例创建时),不处理bot到/ api / messages的GET端点。一切都通过POST处理。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。