使用ngrok在Teams中测试机器人功能 [英] Test a bot functionality in Teams using ngrok

查看:42
本文介绍了使用ngrok在Teams中测试机器人功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Bot Framework和Azure for Microsoft Teams开发一个机器人,我将使用ngrok直接在MS Teams中开发和测试我的代码.在漫游器的设置中,我已将消息端点设置为从ngrok获取的URL,并添加了/api/messages .

I'm developing a bot using the Bot Framework and Azure for Microsoft Teams and I'll to develop and test my code directly in MS Teams using ngrok. In the settings of the bot I've set the message endpoint to the URL I get from ngrok and added /api/messages.

但是每次我想从Teams发送消息时,都会收到401未经授权的回复.

But every time I want to send a message from Teams, I get a 401 unauthorized response.

我如何授权ngrok发送消息?

How could I authorize ngrok to send messages?

更新:形成@Hilton Giesenow的答案,我已经检查了 appSettings.json 文件,那里的所有内容都是正确的.他还说,问题是在 HttpAdapter 中有一个小的变化.所以这是我的代码:

Update: Form an answer of @Hilton Giesenow I've checked the appSettings.json file and everything is correct there. He said also that there is a small change that the problem is in the HttpAdapter. So here is my code:

public class AdapterWithErrorHandler : BotFrameworkHttpAdapter
{
    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 方法中启动文件中的代码:

Code in startup file in the ConfigureServices method:

services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
services.AddTransient<ILogger<BotFrameworkHttpAdapter>, BotFrameworkHttpAdapterLogger>();

推荐答案

因此,如果您已经走了那么远,那么您已经迈出了正确的第一步.只是一个不相关的技巧,您甚至可以通过查看 http://localhost:4040 来查看流量.

So you've got the right first steps, if it's getting that far. Just an unrelated tip, you can even see the traffic by viewing http://localhost:4040.

除此之外,您的实际错误很可能是由机器人配置中错误或缺少的机器人应用ID和应用密码引起的(例如,对于C#项目,您的appSettings.json;对于节点项目,则是等效错误).这是C#项目的示例.

Aside from that, your actual error is most likely caused by the incorrect or missing bot App Id and App Password in your bot's configuration (e.g. your appSettings.json for a C# project, or equivalent for a node project). Here's an example for a C# project.

您可以在Azure门户中获取该信息.最简单的方法是自行运行漫游器,转到左侧菜单的设置"部分,然后选择"Microsoft App Id"部分上方的管理"链接(显示的App ID是您需要的,您可以从管理"链接获取应用密码).请参阅设置"屏幕的屏幕截图此处.

You get that info inside the Azure portal. The easiest way is to go your bot itself, go to the "Settings" section on the left menu, and then selecting the "Manage" link above the "Microsoft App Id" section (the App Id that appears is the one you need, the "manage" link is where you go to get the apppassword). See a screenshot of the Settings screen here.

如果仍然无法使用,则可能是配置设置本身.从本质上讲,默认情况下,HttpAdapter将尝试实例化

If it's still not working, then it's likely the configuration settings themselves. Essentially, under the covers and by default, the HttpAdapter will try to instantiate a ConfigurationCredentialProvider, which is looking very specifically for the configuration items named "MicrosoftAppId" and "MicrosoftAppPassword" (see here for more).

因此,您需要确保设置名称与配置文件中的名称正确匹配.如果您仍然遇到问题,则可以通过替换"AdapterWithErrorHandler"文件中的实例化基础行来至少确认这是配置问题.修改为:

So, you'd need to ensure that your setting names match that correctly in your config file. If you're still having issues, then you can at least verify it's a configuration issue by replacing the line to instantiate the base, in your "AdapterWithErrorHandler" file. Modify it to:

:基本(新的Bot.Connector.Authentication.SimpleCredentialProvider("[您的应用程序ID]","[您的添加密码"),记录器:记录器)

这篇关于使用ngrok在Teams中测试机器人功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆