【问题标题】:Microsoft Teams allow user to share a card from a bot to another channelMicrosoft Teams 允许用户将卡片从机器人共享到另一个频道
【发布时间】:2020-06-11 22:07:11
【问题描述】:

我们构建了一个microsoft teams app,它使用bot,在用户安装应用程序后,我们希望显示一个“分享到频道”按钮,用户可以点击该按钮,然后选择他们想要的频道也想送卡。

我该怎么做?这是通过连接器或 webhook 实现的,还是我需要其他方法?

我已连接一个连接器并将该连接器 ID 添加到应用程序包中的 manifest.json 文件中,但我不知道从那里去哪里。 我已阅读以下文档: https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook

当用户安装应用时,我们可以获取该用户的信息,但我们无法获取该用户连接的其他团队或频道的信息。

我也尝试创建一个message extension https://docs.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/how-to/create-messaging-extension

我也看了Graph API

【问题讨论】:

  • 嘿,我是 msftsofbot,我们正在调查您的问题。

标签: microsoft-teams


【解决方案1】:

使用机器人向频道发送卡片

 public static async Task<ConversationResourceResponse> SendCardToChannel(ITurnContext turnContext, Attachment cardToSend, CancellationToken cancellationToken, IConfiguration configuration)
    {
        var id = configuration["MicrosoftAppId"];
        var pass = configuration["MicrosoftAppPassword"];
        var channelid = configuration["ChannelId"];
        var credentials = new MicrosoftAppCredentials(id, pass);
        var conversationParameters = new ConversationParameters
        {
            Activity = (Activity)MessageFactory.Attachment(cardToSend),
            ChannelData = new TeamsChannelData { Channel = new ChannelInfo(channelid) },
        };

        var tcs = new TaskCompletionSource<ConversationResourceResponse>();
        try
        {
            await ((BotFrameworkAdapter)turnContext.Adapter).CreateConversationAsync(
                    null,       // If we set channel = "msteams", there is an error as preinstalled middleware expects ChannelData to be present
                    turnContext.Activity.ServiceUrl,
                    credentials,
                    conversationParameters,
                    (newTurnContext, newCancellationToken) =>
                    {
                        var activity = newTurnContext.Activity;
                        tcs.SetResult(new ConversationResourceResponse
                        {
                            Id = activity.Conversation.Id,
                            ActivityId = activity.Id,
                            ServiceUrl = activity.ServiceUrl,
                        });
                        return Task.CompletedTask;
                    },
                    cancellationToken);
        }
        catch (Exception e)
        {

            Console.WriteLine(e);
        }

        return await tcs.Task;
    }

试试这段代码,如果你能在频道中发送卡片,请告诉我。

【讨论】:

    【解决方案2】:

    出于安全原因,您的代码无法向团队(1-1 聊天、群聊或频道)中的任何东西发送消息,除非您有已安装的东西 到那个位置(机器人、连接器、webhook)。在这种情况下,您已经有一个机器人,所以这可能是最好的选择,并且根据 Trinetra 的回答,您需要将您的卡作为"proactive message" 发送。为此,您需要某些值(例如,conversationid、serviceurl 等),并且要获得这些值,您还需要将您的应用安装到最终目的地。

    因此,从本质上讲,您需要将机器人安装到目的地,但对于频道,有几种方法可以做到这一点。最简单的方法是让用户安装您的机器人,并立即从 conversationUpdate 事件中获取您需要的信息(conversationid 等)。作为替代方案,您可以install your app programmatically using the Graph。

    【讨论】:

      【解决方案3】:

      只需使用传入的 webhook。您可以将自适应卡直接发送到频道。 https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#send-adaptive-cards-using-an-incoming-webhook

      要获取用户所属的频道,请在 Ms Graph API 上使用 OData 查询 https://docs.microsoft.com/en-us/graph/api/channel-list?view=graph-rest-1.0&tabs=http

      但要获取频道列表,您需要先获取用户的 Teams。一个频道属于一个团队。然后获取每个团队的所有可发布频道。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-26
        • 1970-01-01
        • 1970-01-01
        • 2023-02-15
        • 1970-01-01
        • 2018-06-15
        • 2020-03-02
        • 2021-11-08
        相关资源
        最近更新 更多