0

我用 C# AdaptiveCard SDK 创建了一张自适应卡。但是,一旦我部署到 Facebook Messenger,它就不会显示自适应卡片。代码的关键部分是这样的:(包括初始化IMessageActivity并设置它的属性

 var botActivity = (Microsoft.Bot.Connector.Activity)context.Activity;
 IMessageActivity reply = botActivity.CreateReply();
 reply.AttachmentLayout = AttachmentLayoutTypes.List;
 reply.Attachments = new List<Attachment>();

AdaptiveCard adaptiveCard = new AdaptiveCard()
{
    Body = new List<AdaptiveElement>
    {                    
        new AdaptiveColumnSet
        {
            Columns = new List<AdaptiveColumn>
            {                           
                new AdaptiveColumn
                {
                    Items = new List<AdaptiveElement>
                    {
                        new AdaptiveTextBlock
                        {
                            Size = AdaptiveTextSize.Large,
                            Text = "&#42;",
                            Color = AdaptiveTextColor.Warning
                        }
                    }
                },
                new AdaptiveColumn
                {
                    Size = "1px",
                    Items = new List<AdaptiveElement>
                    {
                        new AdaptiveTextBlock
                        {
                            Text = "indicates mandatory fields",
                            Size = AdaptiveTextSize.Medium,
                            Wrap = true
                        }
                    }
                }
            }
        },
        new AdaptiveTextBlock()
        {
            Text = " ",
            Spacing = AdaptiveSpacing.Medium,
        }
    },
    Actions = new List<AdaptiveAction>()
    {
        new AdaptiveSubmitAction()
        {
            Title = "Confirm",
            DataJson = "{\"Type\": \"RequestBody\"}"
        }
    }
};

RenderedAdaptiveCard renderedAdaptiveCard = renderer.RenderCard(adaptiveCard);
Attachment plAttachment = new Attachment()
{
    ContentType = AdaptiveCard.ContentType,
    Content = renderedAdaptiveCard.OriginatingCard
};

reply.Attachments.Add(plAttachment);
await context.PostAsync(reply);

我还将自适应卡片添加到 IMessageActivity 附件中,并使用 context.PostAsync 将带有附件的回复发回给用户。

有人知道为什么我在 Facebook Messenger 中看不到自适应卡片吗?

4

0 回答 0