编程语言
首页 > 编程语言> > c# – Microsoft Bot Framework自适应卡无法正常呈现

c# – Microsoft Bot Framework自适应卡无法正常呈现

作者:互联网

我正在尝试使用自适应卡片将其添加到我的路易斯响应中,并遵循指南:https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-add-rich-card-attachments.

为什么我的按钮没有显示在我的机器人模拟器上?我错过了什么吗?看图:
enter image description here

我的代码:

 [LuisIntent("Test")]
    public async Task Test(IDialogContext context, LuisResult result)
    {

        Activity replyToConversation = (Activity)context.MakeMessage();
        //Activity replyToConversation = message.CreateReply("Should go to conversation");
        replyToConversation.Attachments = new List<Attachment>();
        AdaptiveCard card = new AdaptiveCard();

       // Add text to the card.
        card.Body.Add(new TextBlock()
        {
            Text = "Adaptive Card design session",
            Size = TextSize.Large,
            Weight = TextWeight.Bolder
        });

        // Add text to the card.
        card.Body.Add(new TextBlock()
        {
            Text = "Conf Room 112/3377 (10)"
        });

        // Add text to the card.
        card.Body.Add(new TextBlock()
        {
            Text = "12:30 PM - 1:30 PM"
        });

        // Add list of choices to the card.
        card.Body.Add(new ChoiceSet()
        {
            Id = "snooze",
            Style = ChoiceInputStyle.Compact,
            Choices = new List<Choice>()
            {
                new Choice() { Title = "5 minutes", Value = "5", IsSelected = true },
                new Choice() { Title = "15 minutes", Value = "15" },
                new Choice() { Title = "30 minutes", Value = "30" }
            }
        });

        // Add buttons to the card.
        card.Actions.Add(new HttpAction()
        {
            Url = "http://foo.com",
            Title = "Snooze"
        });

        card.Actions.Add(new HttpAction()
        {
            Url = "http://foo.com",
            Title = "I'll be late"
        });

        card.Actions.Add(new HttpAction()
        {
            Url = "http://foo.com",
            Title = "Dismiss"
        });

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

        replyToConversation.Attachments.Add(attachment);

        // var reply = await connector.Conversations.SendToConversationAsync(replyToConversation);
        await context.PostAsync(replyToConversation);
        context.Done(true);
    }

解决方法:

将您的HttpAction更改为OpenUrlAction(或SubmitAction,具体取决于您的需要),您将获得按钮:

demo

查看文档时,Actions的可能性如下:

> Action.OpenUrl
> Action.Submit
> Action.ShowCard

它们在C#对象中的等价物是OpenUrlAction,SubmitAction和ShowCardAction

标签:c,botframework,adaptive-cards,web-chat
来源: https://codeday.me/bug/20190608/1195942.html