简体   繁体   English

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

[英]Test a bot functionality in Teams using ngrok

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.我正在使用 Bot Framework 和 Azure 为 Microsoft Teams 开发一个机器人,我将使用 ngrok 在 MS Teams 中直接开发和测试我的代码。 In the settings of the bot I've set the message endpoint to the URL I get from ngrok and added /api/messages .在机器人的设置中,我将消息端点设置为从 ngrok 获得的 URL 并添加了/api/messages

But every time I want to send a message from Teams, I get a 401 unauthorized response.但每次我想从 Teams 发送消息时,都会收到 401 未经授权的响应。

How could I authorize ngrok to send messages?我如何授权 ngrok 发送消息?

Update: Form an answer of @Hilton Giesenow I've checked the appSettings.json file and everything is correct there.更新:形成@Hilton Giesenow 的答案我已经检查了appSettings.json文件,那里的一切都是正确的。 He said also that there is a small change that the problem is in the HttpAdapter .他还说问题出在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));
    }
}

Code in startup file in the ConfigureServices method: ConfigureServices方法中启动文件中的代码:

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

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 .只是一个无关的提示,您甚至可以通过查看http://localhost:4040来查看流量。

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 (eg your appSettings.json for a C# project, or equivalent for a node project).除此之外,您的实际错误很可能是由您的机器人配置中不正确或缺少机器人应用程序 ID 和应用程序密码引起的(例如,您的 appSettings.json 用于 C# 项目,或等效于节点项目)。 Here's an example for a C# project. 这是 C# 项目的示例

You get that info inside the Azure portal.您可以在 Azure 门户中获得该信息。 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).最简单的方法是 go 您的机器人本身,go 到左侧菜单的“设置”部分,然后选择“Microsoft App Id”部分上方的“管理”链接(出现的 App Id 是您需要的, “管理”链接是 go 获取 apppassword 的地方)。 See a screenshot of the Settings screen here . 在此处查看“设置”屏幕的屏幕截图。

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).本质上,在默认情况下,HttpAdapter 将尝试实例化一个ConfigurationCredentialProvider ,它非常专门用于名为“MicrosoftAppId”和“MicrosoftAppPassword”的配置项(有关更多信息,请参见此处)。

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.如果您仍然遇到问题,那么您至少可以通过在“AdapterWithErrorHandler”文件中替换用于实例化基础的行来验证这是一个配置问题。 Modify it to:将其修改为:

: base(new Bot.Connector.Authentication.SimpleCredentialProvider("[your app id]", "[your add password"), logger: logger)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用ngrok在本地测试我的Telegram Bot - Couldn't test locally my Telegram Bot with ngrok 如何使用 Bot Framework V4 C# SDK 在 Teams 中迁移 1:1 主动消息功能 - How to migrate 1:1 proactive messages functionality in Teams with Bot Framework V4 C# SDK 使用团队中的机器人框架向群聊发送消息 - Sending message to a group chat using bot framework from teams 使用Microsoft Bot Framework自动对Microsoft团队中的用户进行身份验证 - Auto authenticate users in Microsoft teams using Microsoft Bot Framework 如何在 Teams 中使用 Bot Framework 在自适应卡旁边添加提及 - How to add a mention in Teams alongside an adaptive card using Bot Framework 使用自定义API机器人无法使用Bot框架在Microsoft Teams频道中发布操作卡 - Using Custom API bot can't post action card in Microsoft Teams channel using Bot framework Bot Framework(.Net)-在Microsoft Teams中的特定时间使用bot检索特定用户的用户名 - Bot Framework (.Net) - Retrieving Username of a specific user using the bot at a specific time in Microsoft Teams Microsoft Teams Bot 在 Teams 中没有响应,但在 Bot Emulator 中工作 - Microsoft Teams Bot is not responding in Teams, but works in the Bot Emulator Bot框架虚拟助手作为MS Teams Bot - Bot Framework Virtual Assistant as MS Teams Bot 团队机器人在 Controller 中创建对话 - Teams Bot Create Conversation In Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM