在facebook消息,bot框架中显示自适应卡

时间:2018-01-09 01:37:39

标签: c# botframework facebook-messenger adaptive-cards

我用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中看不到自适应卡?

0 个答案:

没有答案