0

I'm trying to set the height of an image in a bot framework adaptive card. It doesn't have to be exact, but it should be close.

For the following markup


{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"speak": "",
"type": "Container",


          "items": [
                {
                  "type": "TextBlock",
                  "text": "Acai Bowls, Juice Bars & Smoothies, Vegan"
                },
                {
                  "type": "TextBlock",
                  "text": "11:11 Health Bar",
                  "weight": "bolder",
                  "size": "Medium",
                  "spacing": "none"
                },
                {
                  "type": "Image",
                  "url": "https://sarestlocatoreastprem.blob.core.windows.net/images/small_4_half.png?st=2019-05-22T12%3A21%3A32Z&se=2029-05-23T12%3A21%3A00Z&sp=rl&sv=2018-03-28&sr=b&sig=XHqT5Fzdrc9idAYDM9slnMvC7W84d760qM6DC%2BHRZkE%3D",
                  "size": "auto",
                  "width": "82px",
                  "height": "14px"
                },
                {
                  "type": "TextBlock",
                  "text": "(29 reviews)",
                  "isSubtle": true,
                  "spacing": "none"
                },
                {
                  "type": "TextBlock",
                  "text": "",
                  "size": "small",
                  "wrap": true
                },
                {
                  "type": "TextBlock",
                  "text": "87 Union St\r\nNewton, MA 02459",
                  "size": "small",
                  "wrap": true
                },
                {
                  "type": "Image",
                  "url": "https://s3-media3.fl.yelpcdn.com/bphoto/-UK0ZIiw99QtnIqljweeXw/o.jpg",
                  "size": "auto",
                  "height": "200px"
                }
              ]
          }
      ],
      "actions": [
        {
          "type": "Action.OpenUrl",
          "title": "Directions",
          "url": "https://www.google.com/maps/@42.3297699,-71.1926317,18z?hl=en"
        },
        {
          "type": "Action.OpenUrl",
          "title": "More Info",
          "url": "https://www.yelp.com/biz/11-11-health-bar-newton"
        }
      ]
    }

the adaptive card visualizer

https://adaptivecards.io/visualizer/index.html?hostApp=Bot%20Framework%20WebChat

shows a 200px high image.

When I run the app the adaptive card displayed in the browser shows an 86px high image.

I know adaptive cards aren't meant to be pixel-perfect, but I should be able to control the image height with the specified properties.

What am I doing wrong here?

Here's a link to the bot running with the web chat client

http://adamsrestaurantbot.azurewebsites.net/

Thanks,

Adam

P.S. Versions

Adaptive Cards 1.1.2 Microsoft.Bot.Builder 4.2.2

MindModel
  • 822
  • 1
  • 10
  • 22

1 Answers1

2

The AdaptiveCard Image Schema shows that height isn't an option.

In the designer, this is in Preview, meaning that it isn't officially supported yet:

enter image description here

Edit: Width/Height is no longer in preview. However, it's still up to the channel/client to support it

This is because it's really up to the client displaying the card to adjust the size of the image.

If you resize the image yourself and specify "size": "auto", it will keep the image's true dimensions, but will still vary the overall size per the client renderer.

So unfortunately, you're not doing anything wrong.

Here's a couple of other things you can try:

  1. Hero or Thumbnail cards instead of adaptive cards. This will likely run into similar issues, but clients may render them differently. I recall running into this several months ago and Hero Cards working reasonably well.
  2. If the client will only be using WebChat, you can use custom styling. Adaptive Cards all use the class ac-image, so you could:
img.ac-image {
    height: 100px;
    width: 10px;
}

I did this on your page and got:

enter image description here

You'll have to play around with the CSS to get it how you want it.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • I'll look into HeroCards. I wasn't able to get the CSS rule you provided in your answer to work. I added it to the element of my page, but the Bot Framework sets the CSS for the img element on the element itself, so the style rule is ignored. Example If I set the Size value of the image element to stretch, the BF sets width=10)%. If I set Size to Automatic, it sets max-width. I hear that Size is not in the schema, but it is in Element Properties in designer. – MindModel May 24 '19 at 21:01
  • Changing the Size value in the designer https://adaptivecards.io/designer/ does change the size of the image on that page. If it's not supported, they should remove it from the designer. – MindModel May 24 '19 at 21:04
  • Using !important, adding an id to the parent iframe and writing a rule for that didn't help. The style attribute attached to the img element overrides these rules. Maybe the BF should style this element another way. – MindModel May 24 '19 at 21:05
  • 1) Sorry. I used the wrong CSS Selector (for some reason it worked in Chrome Element Inspector). Updated in Answer. 2) Updated answer. Designer says it's in Preview. Even once out of preview, it will be up to the clients to implement. I'm guessing Web Chat will be one of the first to use. – mdrichardson May 24 '19 at 22:02
  • Edit: OK. The original CSS selector was right for the iFrame, which you use. If you switch to [Web Chat](https://github.com/Microsoft/BotFramework-WebChat) from the iFrame, you can use the CSS in my answer. – mdrichardson May 24 '19 at 22:04
  • @MindModel Sorry. Forgot to @.mention you. – mdrichardson May 24 '19 at 22:50
  • The web chat control looks like a good approach, so I tried that but have not yet been successful. I downloaded the sample code from GitHub but couldn't get it to work. Tried BotFramework-WebChat-master\samples\01.a.getting-started-full-bundle index.html as-is, out of the box. Then I revised the index.html page for my bot, but also couldn't get it to work. I enabled DirectLine for my bot. Enabled enhanced authentiction options, Added my domain (https://adamsrestaurantbot.azurewebsites.net) to trusted sites. – MindModel May 27 '19 at 11:59
  • Revised the JS code on index.html to fetch('https://adamsrestaurantbot.azurewebsites.net/directline/token', { method: 'POST' }); Posted index.html to my site. Doesn't work. Ran Chrome Dev Tools. See that the request is returning 404. Very carefully checked spelling of trusted site. I left the broken page deployed, which I'd rather not do. Could you view source and let me know if you see something wrong? I can also post screen shot of trusted sites from Azure, without secret keys. – MindModel May 27 '19 at 12:02
  • Not sure if I have to @-mention you here so you see this update. Thanks! @mdrichardson – MindModel May 27 '19 at 13:01
  • @MindModel You do need to @.mention in order for me to get notified. The issue is that MockBot (WebChat's sample bot) gets token differently than you need to. [See here](https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication?view=azure-bot-service-4.0#generate-token). You need to make a POST request to `https://directline.botframework.com/v3/directline/tokens/generate` with `Authorization: Bearer ` in the header. Alternatively, you can use `const token = ` directly, instead. – mdrichardson May 27 '19 at 15:46
  • This is starting to veer off-topic quite a bit. If you have trouble with this, feel free to open another StackOverflow question. – mdrichardson May 27 '19 at 15:56
  • Thanks! I've done so here (for anyone else following along) https://stackoverflow.com/questions/56331507/what-is-the-correct-way-to-authenticate-from-javascript-in-an-html-file-to-the-m – MindModel May 27 '19 at 19:26
  • @MindModel It appears that width and height are no longer in preview. I'm not sure which channels/clients support it yet, though. – mdrichardson Jun 19 '19 at 16:27