无法通过ConnectorClient机器人连接器向团队发送消息

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

我正在尝试从驻留在我的Teams Bot中的主动第3方WebHook回调中向Teams Channel发送消息,该回调在我的机器人对话结束后的某个时间从外部触发。

我的config.ServiceURL为'https://smba.trafficmanager.net/amer/',是我在会话中进行会话时从机器人中获得的。

我的config.MicrosoftAppId值是分配给我在Azure中的机器人应用程序注册的ApplicationID。

我的config.MicrosoftAppPassword是我为注册的机器人应用程序创建的客户端密码。

我的ChannelInfo值是我通过枚举另一个应用程序中所有目标团队的渠道而发现的值。我用“ f”代替了实际值。

在Azure中,我向注册的应用程序添加了以下权限:委托-Group.ReadWrite.All

[当我尝试创建对话时,我收到禁止响应。如果将下面的ChannelInfo更改为虚假值,则会收到预期的Not Found响应,因此至少ChannelInfo似乎是有效值。

我需要添加其他权限吗?我错过了一步吗?我做错了什么吗?

这里是代码:

        AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");

        var credentials = new MicrosoftAppCredentials(config.MicrosoftAppId, config.MicrosoftAppPassword);

        if (!MicrosoftAppCredentials.IsTrustedServiceUrl(config.ServiceURL))
        {
            MicrosoftAppCredentials.TrustServiceUrl(config.ServiceURL);
        }

        var serviceUri = new Uri(config.ServiceURL);
        var botConnector = new ConnectorClient(serviceUri, credentials);


        Activity message = (Activity)Activity.CreateMessageActivity();
        message.Text = "Hello World";

        var conversationParameters = new ConversationParameters
        {
            Bot = message.From,
            IsGroup = true,
            ChannelData = new TeamsChannelData
            {
                Channel = new ChannelInfo("19:[email protected]")
            },
            Activity = (Activity)message
        };


        var conversationResponse = await botConnector.Conversations.CreateConversationAsync(conversationParameters);

        await botConnector
           .Conversations
           .SendToConversationAsync(message);
botframework microsoft-teams
1个回答
0
投票

您的代码对我来说很好。您可以尝试以下操作:

  1. 确保您通过App Studio或清单上传将bot加载到Teams中,并且不只是通过appId与bot对话
  2. 确保您的机器人已安装到您要发送消息的团队中
  3. 将您的漫游器托管的域添加到漫游器清单的Valid Domains部分
  4. 通过将.SendToConversationAsync(message);更改为.SendToConversationAsync(conversationResponse.Id, message);,确保将消息发送到正确的对话中>

  5. [还请注意,由于BotTeams功能已直接集成到Bot Framework SDK中,因此Microsoft.Bot.Builder.Teams软件包已被弃用。我强烈建议您远离它。

您可能想发送主动消息,如Microsoft.Bot.Builder.Teams所示。其他this sample是数字50-60。


让我知道您是否要坚持使用该软件包,我可以继续尝试提供支持。

© www.soinside.com 2019 - 2024. All rights reserved.