3
votes

I have created an outgoing webhook in MS Teams. At mentioning the name specified in the outgoing webhook, it will successfully cause an API call in my app - all fine and good.

According to the documentation, my app is required to respond to that request with a response message. But I absolutely can't find any documentation of the format that is accepted in this response.

The only reference, I can find is this one: https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-outgoing-webhook

Unfortunately, it does not go into detail of what such a message can look like. It only gives an example that this would be acceptable:

{
    "type": "message",
    "text": "This is a reply!"
}

I would however not like to respond with a simple message, but much rather with something more rich formatted like a card or - in some cases a reaction instead of a message.

Is that possible? Is there any documentation, what other responses are acceptable? Are there other types than just "message" that can be returned?

2
Please see this sample. Let us know if you still have doubts. - Manish-MSFT
@Manish-MSFT I have the same issue as the OP. I don't find in your sample projet where the different response types are presented. Thank you - NicoSalvadore
@NicoSalvador : Here you can find different response types. - Manish-MSFT
Hey, there wouldn't be something like a json example? Not coming from .net and not really knowing how the json serialization and the framework around it works makes it very hard to understand the code samples. @Manish-MSFT - Matthias Huttar
There aren't any samples for Json as example at the moment. @MatthiasHuttar - Manish-MSFT

2 Answers

1
votes

Alright, here's a quick and dirty way to handle things for teams. For some reason this is not documented very clearly, but what teams requires is for the "Card" to be created as an attachment, instead of just getting the response directly.

What I've done is capture the boilerplate required to house the card first:

string TeamsAdaptiveCardBoilerplate =
@"
{
    ""type"":""message"",
    ""attachments"":[
        {
            ""contentType"":""application/vnd.microsoft.card.adaptive"",
            ""contentUrl"":null,
            ""content"":{
                ""$schema"":""http://adaptivecards.io/schemas/adaptive-card.json"",
                ""type"":""AdaptiveCard"",
                ""version"":""1.2"",
                ""body"":[
                    @@BODY@@
                ]
            }
        }
    ]
}
";

Then, I build the body (usually, this would not be static text, but it serves well as an example)

string AdaptiveCardBody =
@"
        {
            ""type"": ""TextBlock"",
            ""text"": ""Here is a ninja cat""
        },
        {
            ""type"": ""Image"",
            ""url"": ""http://adaptivecards.io/content/cats/1.png""
        }
";

Next I simple swap out the placeholder with the real body:

var jsonPayload1 = TeamsAdaptiveCardBoilerplate.Replace("@@BODY@@", AdaptiveCardBody); 

And finally, return the assembled payload (converted back into an object so the correct response headers get set):

var payload1 = JsonConvert.DeserializeObject(jsonPayload1);
return (ActionResult)new OkObjectResult(payload1);

From there, you should be good to go.

Note:

For convenience, the entirety of the "content" (and not "body") block is what you'd copy/paste into the adaptivecards.io designer. You might refactor the above to reflect that reality if it was important to you.

0
votes

Could you please try this sample json { "$schema": "adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.2", "body": [ { "type": "Image", "url": "c.s-microsoft.com/en-us/CMSImages/…" }, { "type": "TextBlock", "text": "Sample image for Adaptive Card..", "wrap": true } ] }