PeaceDealer
PeaceDealer

Reputation: 1017

Using Card Building Classes from Bot Framework for Webhooks

I was working on creating a Bot, when i found the classes that help you build the cards.

I've also been working on an incoming webhook, but on that front, it seems it has to be done via JSON?

I've tried to put the packages into my other project, but I can't find a way to actually send the attachment.

Is it even possible, to use the card building classes in Microsoft.Bot.Connector assembly, or does other alternative tools exist, that i am not aware off?

My goal is to create cards in the chat, using the incoming webhook.

In my application, I have added the Microsoft.Bot.Connector library.

Right now, I have a script that generates a JSON string, from various parameters, to create a card. This is then sent to an "Incoming Webhook"

When doing with in my bot, I can create classes like theHeroCard, or ThumbnailCard, and use the .ToAttachment() to send it as a reply from the bot, which I feel is much more versatile, and user friendly.

I wish to be able to use the library that I use in the bots, to also create the cards for the incoming webhook (or a similar tool).

Sample Code: https://pastebin.com/9fHS5DWZ

namespace Namespace
{
    public class Class()
    {
        public method()
        {
            List<CardImage> Images = new List<CardImage>();
            Images.Add(new CardImage(url: "http://dev.example.com/cat.png"));
            List<CardAction> Buttons = new List<CardAction>();
            Buttons.Add(new CardAction()
            {
                Value = $"http://google.com",
                    Type = "openUrl",
                    Title = "Google"
            });

            ThumbnailCard Card = new ThumbnailCard()
            {
                Title = "Another Card!",
                Subtitle = "Another test card",
                Text = "This is just like a hero card, but smaller picture.",
                Images = Images,
                Buttons = Buttons
            };

            try
            {
                PostJsonAsync(MSTeamsCards.Config.WebHook, card.ConvertToJsonSomehow())
                    .ContinueWith(x =>
                    {
                        try
                        {
                            Console.Write(x.Result);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    });
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

Upvotes: 1

Views: 406

Answers (1)

Bill Bliss - MSFT
Bill Bliss - MSFT

Reputation: 3581

@PeaceDealer, if I'm understanding you correctly, you know how to write a bot, and to create bot messages with cards. But you aren't doing that, you want to send the same type of cards over an incoming webhook?

The only format that's accepted over an incoming webhook is the Office 365 Connector card schema. You can find rich examples of that in the Message Card Playground site.

For the other card formats, you need to use a real Bot Framework bot or a Custom Bot.

Upvotes: 1

Related Questions