如何使用Java的Bot Framework SDK将卡片添加到Microsoft Team Bot?

时间:2019-06-10 04:44:08

标签: java botframework microsoft-teams

我正在使用Java botbuilder来构建一个Microsoft团队机器人。我想将Cards添加到我的漫游器中(例如嵌入链接,快速回复和图像)。

在上面的链接中说:Microsoft Teams不支持建议的操作:如果您希望按钮出现在Teams机器人消息中,请使用卡片。

但是,我找不到有关如何向Activity模式添加“卡”的文档。

我尝试过:

1。使用建议的操作

  

我尝试将List<CardAction>添加到SuggestedActions   Activity中的字段,但它们不是由Microsoft团队呈现的   (按预期,文档说不支持此功能。)

2。使用附件

  

我怀疑可以使用附件来完成,但是只能找到   C#/ JS版本的文档(例如   https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-rich-cards?view=azure-bot-service-3.0

所以我想知道如何在Activity模式中添加“卡片”,以便它可以由我的机器人呈现。

1 个答案:

答案 0 :(得分:1)

BotFramework Java SDK仍在预览中,因此我可以为您提供的文档很多。但是,这里有一个将HeroCard添加到回复中的示例。

Activity reply = new Activity()
        .withType(ActivityTypes.MESSAGE)
        .withRecipient(activity.from())
        .withFrom(activity.recipient())
        .withAttachments(Arrays.asList(
                new Attachment()
                        .withContentType("application/vnd.microsoft.card.hero")
                        .withContent(new HeroCard()
                                .withTitle("Hero Card")
                                .withSubtitle("BotFramework")
                                .withButtons(Arrays.asList(new CardAction()
                                    .withValue("https://docs.microsoft.com/en-us/azure/bot-service/")
                                    .withTitle("Get started")
                                    .withType(ActionTypes.OPEN_URL)
                                ))
                                .withImages(Collections.singletonList(new CardImage()
                                        .withUrl("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg"))))

        ));

您还可以查看SDK Attachment Tests,了解更多示例。

希望这会有所帮助!