botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Adaptive Cards] Slack downrendering of AdaptiveCards not working

Open hrlourenco opened this issue 9 years ago • 12 comments

Version Bot: 3.8.1 Channels: Slack and Web

Issue Description

We are using AdaptiveCards. Until last week we have this working in both channels, even in slack the adptive card appear as an image while web mode appears in text (as it is supposed to be).

Since this week, slack adptive card is not working, whenever we make a request to show the card it appears the space of the image, the image exists but no content.

This is 2 image examples: https://bcattachmentsprod.blob.core.windows.net/at13023/BiQrsQYenEx-original https://slack-imgs.com/?c=1&url=https://bcattachmentsprod.blob.core.windows.net/at13023/JTJAU9ye6Q7-original

This works on web channel, the content is correct,

Code Example

//FactSet
string title = $"{TicketNumber} - {Title}";

List<AdaptiveCards.Fact> lstFacts = new List<AdaptiveCards.Fact>()
{
	new AdaptiveCards.Fact("Ticket Nr", TicketNumber),
	new AdaptiveCards.Fact("Team", ResponsibleTeam),
	new AdaptiveCards.Fact("Status", Status),
};


List<CardElement> listaCards = new List<CardElement>()
{
	UX.AdCards.ContainerFactSet.CreateFactSetWithTitle(ticket.Title, TextColor.Attention, lstFacts),
	UX.AdCards.ContainerDescription.CreateDescription("Description", InitialDescription),
};

List<ActionBase> listAction = new List<ActionBase>();
OpenUrlAction o = new OpenUrlAction()
{
	Title = "Show",
	Url = ticket.GetLink()
};
listAction.Add(o);

var card = new AdaptiveCard()
{
	Body = listaCards,
	Actions = listAction,
	Title = title
};

//Attachements
Attachment attachment = new Attachment()
{
	ContentType = AdaptiveCard.ContentType,
	Content = card
};

var reply = context.MakeMessage();
reply.Attachments.Add(attachment);

return reply;

public static Container CreateDescription(string title, string description, int maxDescriptionSize = 256000, bool removeHTMLImages = true)
{
	//remove images if some appears in text
	string descriptionAux = description;
	if (removeHTMLImages)
	{
		Regex regex = new Regex(@"<img(.*?)\/>");
		descriptionAux = regex.Replace(descriptionAux, "##Removed Image##");
	}

	int val = System.Text.ASCIIEncoding.Unicode.GetByteCount(descriptionAux);

	if (val > maxDescriptionSize)
	{
		descriptionAux = new string(descriptionAux.Take(100).ToArray()) + "... [Texto removido devido ao extenso tamanho]";
	}


	var converter = new ReverseMarkdown.Converter();
	description = converter.Convert(descriptionAux);

	Container container = new Container();
	if (!string.IsNullOrEmpty(description))
	{
		container.Items = new List<CardElement>()
		{
					new TextBlock()
					{
						Color = TextColor.Dark,
						Weight = TextWeight.Bolder,
						Text = title,
						Wrap = true
					},
					new TextBlock()
					{
						Color = TextColor.Default,
						Weight = TextWeight.Lighter,
						Text = description,
						Wrap = true
					}
		};
	}
	return container;
}

Reproduction Steps

1.Go to slack 2.Request to show a card

Expected Behavior

Appears the card. Slack: Show card (as an image for now, if possible should appear as text, but not full support yet by microsoft) Web: Show card

Actual Results

The image on Slack appears with no content, full transparent.

hrlourenco avatar Nov 24 '17 15:11 hrlourenco

Please try upgrading the bot builder version from 3.8.1 to 3.11.0

Does the Slack channel's Health column show any errors https://dev.botframework.com/bots/channels?id=YourBotId

Debugging locally might reveal more information: https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/

I created a bot with a modified version of the code from this issue.

Microsoft.AdaptiveCards version=0.5.1 Microsoft.Bot.Builder version=3.11.0

Tested it on slack. Other cards are also downrendering:

image

Slack windows client:

image

    [Serializable]
    public class FactSetDailog : IDialog<object>
    {
        public Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedAsync);

            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
        {
            var activity = await result as Activity;

            if (!string.IsNullOrEmpty(activity.Text) && activity.Text.ToUpper() != "FACTSET")
            {
                await context.Forward(new RootDialog(), null, activity.AsMessageActivity(), System.Threading.CancellationToken.None);
                return;
            }
            await context.PostAsync(GetMessage(context));
            context.Done(false);
        }

        public string TicketNumber { get { return "11"; } }
        public string Title { get { return "Title"; } }
        public string ResponsibleTeam { get { return "Team"; } }
        public string Status { get { return "Status"; } }

        public IMessageActivity GetMessage(IDialogContext context)
        {
            //FactSet
            string title = $"{TicketNumber} - {Title}";

            List<AdaptiveCards.Fact> lstFacts = new List<AdaptiveCards.Fact>()
            {
                new AdaptiveCards.Fact("Ticket Nr", TicketNumber),
                new AdaptiveCards.Fact("Team", ResponsibleTeam),
                new AdaptiveCards.Fact("Status", Status),
            };


            List<CardElement> listaCards = new List<CardElement>()
            {
                CreateFactSetWithTitle("ticket title", TextColor.Attention, lstFacts),
                CreateDescription("Description", "initial description"),
            };

            List<ActionBase> listAction = new List<ActionBase>();
            OpenUrlAction o = new OpenUrlAction()
            {
                Title = "Show",
                Url = "https://bing.com"
            };
            listAction.Add(o);

            var card = new AdaptiveCard()
            {
                Body = listaCards,
                Actions = listAction,
                Title = title
            };

            //Attachements
            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content = card
            };

            var reply = context.MakeMessage();
            reply.Attachments.Add(attachment);

            return reply;

        }
        public static FactSet CreateFactSetWithTitle(string title, TextColor textColor, List<AdaptiveCards.Fact> facts)
        {
            var factSet = new FactSet();

            foreach (var fact in facts)
            {
                factSet.Facts.Add(fact);
            }

            return factSet;
        }

        public static Container CreateDescription(string title, string description, int maxDescriptionSize = 256000, bool removeHTMLImages = true)
        {
            //remove images if some appears in text
            string descriptionAux = description;
            if (removeHTMLImages)
            {
                Regex regex = new Regex(@"<img(.*?)\/>");
                descriptionAux = regex.Replace(descriptionAux, "##Removed Image##");
            }

            int val = System.Text.ASCIIEncoding.Unicode.GetByteCount(descriptionAux);

            if (val > maxDescriptionSize)
            {
                descriptionAux = new string(descriptionAux.Take(100).ToArray()) + "... [Texto removido devido ao extenso tamanho]";
            }


            // var converter = new ReverseMarkdown.Converter();
            // description = converter.Convert(descriptionAux);

            Container container = new Container();
            if (!string.IsNullOrEmpty(description))
            {
                container.Items = new List<CardElement>()
                {
                    new TextBlock()
                    {
                        Color = TextColor.Dark,
                        Weight = TextWeight.Bolder,
                        Text = title,
                        Wrap = true
                    },
                    new TextBlock()
                    {
                        Color = TextColor.Default,
                        Weight = TextWeight.Lighter,
                        Text = description,
                        Wrap = true
                    }
                };
            }
            return container;
        }
    }

EricDahlvang avatar Nov 24 '17 22:11 EricDahlvang

Hi Eric, thanks for the quick reply. I'll try, Is there some reason to start not working? Until last week it works. We are using also authbot, that uses different version, some suggestion on this?

hrlourenco avatar Nov 25 '17 20:11 hrlourenco

It could be related to security protocol changes:

UPDATED 08/08/2017: We revised our security protocols on July 31, 2017. Update to Bot Builder 3.9+ or compatible security configuration to keep your bot working

from: https://blog.botframework.com/2017/05/07/bot-framework-auth-change/

EricDahlvang avatar Nov 25 '17 21:11 EricDahlvang

Hi Eric,

Already updated, now, it show on Health Slack this error: Error1: POST to xxxx failed: POST to the bot's endpoint failed with HTTP status 500 Error2: There was an error sending this message to your bot: HTTP status code InternalServerError

Could you please help on that?

hrlourenco avatar Nov 27 '17 11:11 hrlourenco

@hrlourenco Debugging locally will reveal more information: https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/

You can also add application insights, to receive more information on errors between the connector and your bot: https://docs.microsoft.com/en-us/bot-framework/resources-app-insights-keys

EricDahlvang avatar Nov 27 '17 20:11 EricDahlvang

Hi @EricDahlvang , i had use ngrok and the problem was authentication.

Related to AdaptiveCards, continues the same problem. This is how I'm printing the card

IMessageActivity activity = Helpers.ShowTicketDetail(lstTickets, ticketNumber, context);
if (activity == null)
{
   await context.PostAsync(AnswerNoData());
}
else
{
   await context.PostAsync(activity);
}

So, the card still remaining with no content. Is it possible to be caused by AuthBot that uses 3.8.1?

I use exactly the code you sent also, and it appears with no content. Already test on web channel, and works normally.

I have errors, this is the most common in AppInsigths: AppInsights Error

Thank you

hrlourenco avatar Nov 28 '17 12:11 hrlourenco

@EricDahlvang I already test on slack online, onpermisses, already get the old code when this was working, test your inputs, and still not render the image. What seem happens is: The text is sent to the server and it produces the image, however, is "transparent"! I'm telling this because, if I send lots of text, the image size is bigger and also has more height. If I send only a message "hello" it has oly a few bytes.

Do you have some input on that?

Thank you

hrlourenco avatar Nov 29 '17 16:11 hrlourenco

Hi @hrlourenco, what version of AdaptiveCards nuget package are you using? Please try using 1.0.0-beta09 and see if they helps.

matthidinger avatar Nov 29 '17 22:11 matthidinger

hi @matthidinger

Already update and still have the same issue.

I'm receiving the below error in appinsights, and it seems to be related to my issue:

POST to XXX_ASH failed: POST to the bot's endpoint failed with HTTP status 500POST to the bot's endpoint failed with HTTP status 500

Microsoft.Bot.Schema.BotException:
   at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__29.MoveNext (Microsoft.Bot.ChannelConnector, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null: d:\a\1\s\ChannelSDK\Microsoft.Bot.ChannelConnector\API\BotAPI.cs: 312)
Inner exception System.Exception handled at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__29.MoveNext:
   at Microsoft.Bot.ChannelConnector.BotAPI+<PostActivityToBotAsync>d__29.MoveNext (Microsoft.Bot.ChannelConnector, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null: d:\a\1\s\ChannelSDK\Microsoft.Bot.ChannelConnector\API\BotAPI.cs: 308)
assembly Microsoft.Bot.ChannelConnector, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null
  method Microsoft.Bot.ChannelConnector.BotAPI+d__29.MoveNext
  level 0
  line 312
  fileName d:\a\1\s\ChannelSDK\Microsoft.Bot.ChannelConnector\API\BotAPI.cs

Do you have some information about this issue?

hrlourenco avatar Nov 30 '17 16:11 hrlourenco

Hi @hrlourenco

  1. The App Insights error https://cld.pt/dl/download/39fcd440-071e-41e8-b882-04991cc667b4/boterror.png shows that your bot is timing out. Bots are expected to respond within 15 seconds.

  2. BotAuth https://github.com/richdizz/BotAuth (current nuget: https://www.nuget.org/packages/BotAuth ) will soon be replacing AuthBot.

  3. It is not clear to me why Adaptive Card downrendering in slack is not functioning properly for you. The only suggestion I can think of is to try creating a new bot, adding it to slack, and show an adaptive card there. If this new bot functions as expected, compare the two projects.

Which Slack client are you using? v2.9 on 64bit windows is my slack client.

EricDahlvang avatar Dec 01 '17 02:12 EricDahlvang

The error is back happening. I'm seeing a blank/transparent image now on my adaptive cards for Slack & Facebook

ejadib avatar Dec 01 '17 16:12 ejadib

I am also experiencing this now, with my bots on slack. The issue is being tracked here: https://github.com/Microsoft/AdaptiveCards/issues/985 That issue will be updated as the problem is resolved.

I'm going to close this one as a duplicate.

EricDahlvang avatar Dec 02 '17 00:12 EricDahlvang