我正在使用Bot Framework和Microsoft Teams的Azure开发一个机器人,我将使用ngrok在MS Teams中直接开发和测试我的代码。在漫游器的设置中,我已将消息端点设置为从ngrok获取并添加/api/messages
的URL。
但是每次我想从Teams发送消息时,都会收到401未经授权的回复。
我如何授权ngrok发送消息?
更新:
形成@Hilton Giesenow的答案,我已经检查了appSettings.json
文件,那里的所有内容都正确。他还说,问题出在HttpAdapter
上,但有很小的变化。所以这是我的代码:public class AdapterWithErrorHandler : BotFrameworkHttpAdapter { public AdapterWithErrorHandler() : this(default!, new BotFrameworkHttpAdapterLogger()) { } public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger) : base(configuration, logger) { OnTurnError = OnTurnErrorHandler; } private async Task OnTurnErrorHandler(ITurnContext turnContext, Exception exception) { string replyText = "An error occured while sending a message. If this error stays, please contact the service desk."; await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText)); } }
ConfigureServices
方法中启动文件中的代码:
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddTransient<ILogger<BotFrameworkHttpAdapter>, BotFrameworkHttpAdapterLogger>();
我正在使用Bot Framework和Microsoft Teams的Azure开发一个机器人,我将使用ngrok在MS Teams中直接开发和测试我的代码。在漫游器的设置中,我已经设置了消息...