【问题标题】:C# Microsoft Bot Schema Teams Image cropping off the top and bottomC# Microsoft Bot Schema Teams 图像从顶部和底部裁剪
【发布时间】:2022-01-08 07:35:08
【问题描述】:

我有一个关于 Teams Microsoft Bot 框架的问题。每当我的机器人发送自适应卡片时,照片的顶部和底部都会继续切断。自适应卡片里面是英雄卡片图像,我似乎无法调整它的大小以使其适合。我尝试让图像越来越小,看看是否能解决问题。以下是我遇到的问题的屏幕截图。

我希望有人遇到过同样的问题,以及这是否可以解决。谢谢。

正在使用的图像; https://imgur.com/a/hkcSkrJ

   public async Task<SendResult> SendAsync(NotificationTeamsAttempt attempt)
    {
        try
        {
            if (string.IsNullOrWhiteSpace(attempt.ConversationId))
                throw new Exception("Conversation Id is required.");
            if (string.IsNullOrWhiteSpace(attempt.ServiceUrl))
                throw new Exception("Service Url is required.");

            using (var connector = new ConnectorClient(new Uri(attempt.ServiceUrl), _clientId, _clientSecret))
            {
                var activity = MessageFactory.Text("");
                activity.Attachments.Add(attempt.Attachment());
                activity.Summary = attempt.Summary();
                var response = await connector.Conversations.SendToConversationAsync(attempt.ConversationId, activity);
                return new SendResult
                {
                    IsSuccess = true,
                    DispatchId = response.Id
                };
            }
        }
        catch (Exception exception)
        {
            return new SendResult
            {
                IsSuccess = false,
                Exception = exception
            };
        }
    }


   public override Attachment Attachment()
    {
        var card = new ThumbnailCard
        {
            Title = "Post submitted for review by " + DraftAuthor,
            Subtitle = DraftTitle,
            Text = DraftDescription,
            Images = new List<CardImage>(),
            Buttons = new List<CardAction>()
        };
        if (!string.IsNullOrWhiteSpace(TeamsUrl))
        {
            card.Buttons.Add(new CardAction
            {
                Type = "openUrl",
                Title = "Review in Teams",
                Value = TeamsUrl.Replace("null", $"%22post%7C{DraftId}%7C{DraftId}%22")
            });
        }
        if (!string.IsNullOrWhiteSpace(SPUrl))
        {
            card.Buttons.Add(new CardAction
            {
                Type = "openUrl",
                Title = "Review in SharePoint",
                Value = $"{SPUrl}?postId={DraftId}&sourceId={DraftId}"
            });
        }
        return card.ToAttachment();
    }

请忽略我添加的黑线。但在下面,您可以看到图像被裁剪的位置。 Image of the cropping.

【问题讨论】:

  • 您能分享一下自适应卡片 JSON 吗?
  • @Meghana-MSFT 我只是在使用开箱即用的 C# 默认自适应卡。如果有帮助的话,我很乐意发布我的 C# sn-ps。
  • 如果您能向我们指出您正在使用的样本(如果有),那将非常有帮助。这样我们就可以用相同的图像重现问题。
  • @Meghana-MSFT 再次感谢您的回复,我已经继续添加了一些代码 sn-ps。我希望这会有所帮助,如果您需要更多,请告诉我。这也是正在使用的图像; imgur.com/a/hkcSkrJ
  • 我们使用自适应卡片和缩略图卡片进行了尝试。我可以看到图像在这两种情况下都渲染得很好。缩略图卡:i.stack.imgur.com/AOBZR.png 自适应卡:i.stack.imgur.com/cllof.png

标签: botframework microsoft-teams adaptive-cards


【解决方案1】:

移动评论以回答 -

我们使用下面的 JSON,我们得到了完美的图像,没有裁剪 -- { "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "size": "Medium", "weight": "Bolder", "text": "card image test" }, { "type": "Container", "items": [ { "title": "Public test 1", "type": "Image", "url": "https://i.imgur.com/OiJNN03.jpeg" } ] } ], "$schema": "adaptivecards.io/schemas/adaptive-card.json", "version": "1.0" }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    相关资源
    最近更新 更多