如何使用 Java 的 Bot Framework SDK 将卡片添加到 Microsoft 团队机器人?
How to add Cards to microsoft teams bot using Bot Framework SDK for Java?
我在我的机器人中使用 Java botbuilder to build a microsoft teams bot. I want to add Cards(例如嵌入 links、快速回复和图像)。
在上面 link 中说:Microsoft Teams 不支持建议的操作:如果您希望按钮出现在 Teams 机器人消息上,请使用卡片。
但是,我找不到关于如何将 'card' 添加到 Activity
架构的文档。
我试过了:
1.使用建议的操作
I tried adding my List<CardAction>
to the SuggestedActions
field in Activity
but they were not rendered by microsoft teams
(as expected, the documentation says this is not supported).
2。使用附件
I suspect it could be done using attachments, but can only find
documentation for the C#/JS versions (e.g.
https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-rich-cards?view=azure-bot-service-3.0).
所以我想知道如何将 'a card' 添加到 Activity
架构,以便我的机器人可以呈现它。
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 以获取更多示例。
希望对您有所帮助!
我在我的机器人中使用 Java botbuilder to build a microsoft teams bot. I want to add Cards(例如嵌入 links、快速回复和图像)。
在上面 link 中说:Microsoft Teams 不支持建议的操作:如果您希望按钮出现在 Teams 机器人消息上,请使用卡片。
但是,我找不到关于如何将 'card' 添加到 Activity
架构的文档。
我试过了:
1.使用建议的操作
I tried adding my
List<CardAction>
to theSuggestedActions
field inActivity
but they were not rendered by microsoft teams (as expected, the documentation says this is not supported).
2。使用附件
I suspect it could be done using attachments, but can only find documentation for the C#/JS versions (e.g. https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-send-rich-cards?view=azure-bot-service-3.0).
所以我想知道如何将 'a card' 添加到 Activity
架构,以便我的机器人可以呈现它。
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 以获取更多示例。
希望对您有所帮助!