0
votes

I'm working on a Teams bot and I'm trying various ways to send rich messages to users (we need clickable buttons) from my bot. I have tried adaptive cards, which are almost perfect, but noticed that on the toast popup for the message it just says "Testbot sent a card". This isn't ideal as we'd like an overview of the message to appear instead.

I noticed that when you use the weather app to send a card to another user, it has the desired effect- a short summary of the weather appears in the toast popup. Looking inside the JSON that represents that message shows that the "card" is actually an HTML attachment.

Am I able to replicate this by sending an HTML attachment? I have (naively) tried the following but it causes an exception:

            Activity reply = new Activity();
            reply.Type = ActivityTypes.Message;
            reply.Text = "Test the toast";

            reply.Conversation = new ConversationAccount()
            {
                Id = conversationResponse.Id
            };
            reply.Attachments.Add(new Attachment()
            {
                ContentType = "text/html",
                Content = "<div>Some generated html</div>"
            });

Am I just barking up the wrong tree completely?

Thanks.

Edit:

The exception I'm getting is "Operation returned an invalid status code 'BadRequest'" from within mscorlib.dll.

For an adaptive card, I can do the following, and it works fine:

                reply.Attachments.Add(new Attachment()
                {
                    ContentType = "application/vnd.microsoft.card.adaptive",
                    Content = JsonConvert.DeserializeObject("{Some generated JSON}")
                });

When trying to send the attachment as HTML, I assume I need to do more than simply send a string as Content. I tried rendering an adaptive card to HTML and attaching the resultant RenderedAdaptiveCard object, but still got the same exception.

--

Edit 2:

When a colleague sends me a card using the weather app: https://i.imgur.com/BlBk557.png

I get the following toast: https://i.imgur.com/EoO8COj.png

When using that tool to send a message to the bot, I can see a message with an attachment of type text/html.

I was attempting to replicate this by sending a message from the bot to a user with an attachment of type text/html and some HTML in the content field. I now see that when I do this there is a 400 response from the serviceUrl which says

{"error":{"code":"BadArgument","message":"Unknown attachment type"}}

I think maybe the assumption I made was based on a misunderstanding. I take it that we can't have informative text on the toast for a card in the same manner as the weather app?

1
Welcome to Stack Overflow :) Could you please include the exception in the question, this will help us identify the problemsedders123
@rugt0r Please try rendering adaptive card to html to send your card as a Html attachment.Gousia Begum
Thanks for the suggestions, I've updated the original post. Still no joy.rugt0r
@rugt0r Could you please share a screenshot of what you are expecting? Currently when a bot sends a card we receive a toast like: i.stack.imgur.com/wHyQx.pngGousia Begum
Thanks. I will edit the original post with my updated information.rugt0r

1 Answers

0
votes

It seems like this is impossible. See comment on OP:

"Bots does not support an Html Attachment" - Gousia-MSFT