2
votes

I am trying to display a card (or list of links ) to my Skype, Slack or Messenger users with some postBack actions.

Herocard works fine, they display the buttons with the text like in this example:

    IMessageActivity replyMessage = context.MakeMessage();
    replyMessage.Attachments.Add(
    new HeroCard
    {
        Subtitle = "Settings",
        Buttons = new List<CardAction> {
            new CardAction(ActionTypes.ImBack, $"Spell-check {spellcheckst}", value: $"Set Spell-check setting {spellcheckst}", text: $"Spell-check {spellcheckst}", displayText: $"Spell-check {spellcheckst}"),
            new CardAction(ActionTypes.ImBack, $"Small-talk {smalltalkst}", value: $"Set Small-talk setting {smalltalkst}", text: $"Small-talk {smalltalkst}", displayText: $"Small-talk {smalltalkst}")

        }
    }.ToAttachment()
    );
    await context.PostAsync(replyMessage);

But buttons take a lot of screen real estate and many times their captions are truncated.

Is there a way to trigger a postBack or imBack card action without displaying buttons. Here is an example scenario, when the User asks for Help, the Bot displays list of commands:

  1. Add a webpage Try Me
  2. delete a webpage Try Me
  3. Display help Try Me
  4. etc.

The "Try Me" links would postBack to the bot exactly as the buttons above do.

Is this possible to do?

Thanks

2

2 Answers

0
votes

Indeed, large button name will create a problem and it's look like alien to cards. In place of that you can do that using Carousel Cards. Put below code in your dialog and check. I am doing it and its working.

 public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            var reply = context.MakeMessage();

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments = GetCardsAttachments();

            await context.PostAsync(reply);

            context.Wait(this.MessageReceivedAsync);
        }

        private static IList<Attachment> GetCardsAttachments()
        {
            return new List<Attachment>()
            {
                GetHeroCard(
                    "Add a webpage",
                    "",
                    "",
                    new CardImage(url: "https://cdn.dribbble.com/users/22691/screenshots/1958250/attachments/340010/Button_800x600.gif?sz=328"),
                    new CardAction(ActionTypes.ImBack, "Add a webpage", value: "Add a webpage")),
                GetHeroCard(
                    "delete a webpage",
                    "",
                    "",
                    new CardImage(url: "https://cdn.dribbble.com/users/22691/screenshots/1958250/attachments/340010/Button_800x600.gif?sz=328"),
                    new CardAction(ActionTypes.ImBack, "delete a webpage", value: "delete a webpage")),
                GetHeroCard(
                    "Display help",
                    "",
                    "",
                    new CardImage(url: "https://cdn.dribbble.com/users/22691/screenshots/1958250/attachments/340010/Button_800x600.gif?sz=328"),
                    new CardAction(ActionTypes.ImBack, "Display help", value: "Display help")),
                GetHeroCard(
                    "etc",
                    "",
                    "",
                    new CardImage(url: "https://cdn.dribbble.com/users/22691/screenshots/1958250/attachments/340010/Button_800x600.gif?sz=328"),
                    new CardAction(ActionTypes.ImBack, "etc", value: "etc")),

            };
        }

        private static Attachment GetHeroCard(string title, string subtitle, string text, CardImage cardImage, CardAction cardAction)
        {
            var heroCard = new HeroCard
            {
                Title = title,
                Subtitle = subtitle,
                Text = text,
                Images = new List<CardImage>() { cardImage },
                Buttons = new List<CardAction>() { cardAction },
            };

            return heroCard.ToAttachment();
        }

I hope this will help you out to solve your concern.

Below is the scren shot for your reference. enter image description here

0
votes

Using the buttons, you can set the title to the display text, and set the value to what you need to post back. Then you could have a little piece of text above the buttons that says something along the lines, "click any of the buttons to try".

I use this approach within messenger, to make my button text short, but the "payload" (or value) of the button set to a richer description. Next thing is, the value is not displayed to the user, but it is received by the framework within the channel data portion of the message activity.