使用ngrok在团队中测试机器人功能

问题描述 投票:0回答:1

我正在使用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中直接开发和测试我的代码。在漫游器的设置中,我已经设置了消息...

c# botframework microsoft-teams ngrok
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.