1
votes

I'm using the Java botbuilder to build a microsoft teams bot. I want to add Cards to my bot (e.g. to embed links, quick replies, and images).

In the above link it says: suggested actions are not supported in Microsoft Teams: if you want buttons to appear on a Teams bot message, use a card.

However, I can find no documentation on how to add a 'card' to the Activity schema.

I tried:

1. Using suggested actions

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. Using Attachments

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).

So I want to know how to add 'a card' to Activity schema so it can be rendered by my bot.

1

1 Answers

1
votes

The BotFramework Java SDK is still in preview, so there isn't a lot of documentation I can point you towards. However, here is an example of adding a HeroCard to a reply.

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"))))

        ));

You can also take a look at the SDK Attachment Tests for more examples.

Hope this helps!