使用Microsoft Bot Framework

时间:2016-12-07 19:43:49

标签: c# bots botframework luis

问题:

  • 将卡附加到响应对话框,以下代码主要取自机器人样本,但在我使用的显示逻辑关键部分的响应对话框中不显示卡片。

我无法在LUIS Intent任务中进行附件。

目标

  • 让用户提出LUIS无法识别的问题,然后在代码跳转到负责处理无法识别的LUIS意图任务后,使用帮助卡进行回复。是否还有其他一些我可以考虑的帮助窗口结构,仍然使用卡片?

代码

我的卡片应该从

显示
[LuisIntent("None")]    
public async Task NoneHandler(IDialogContext context, LuisResult result) {
        string worriedFace = "\U0001F61F";
        string smilingFace = "\U0001F642";

        await context.PostAsync("I'm sorry, I didn't get that " + worriedFace + '.');
        await context.PostAsync("Here are some things I know how to talk about!" + smilingFace);

        var message = context.MakeMessage();

        var attachment = new CardDialog().ReceiptCard();
        message.Attachments.Add(attachment);

        await context.PostAsync(message);
    }

我创建的View对象的Card类正在尝试显示。

namespace LUISBankingBot.Views
{
    using System.Collections.Generic;
    using Microsoft.Bot.Connector;
    using Microsoft.Bot.Builder.Dialogs;
    using System;
    using System.Threading.Tasks;

    public class CardDialog : IDialog<object>
    {
        public Task StartAsync(IDialogContext context)
        {
            throw new NotImplementedException();
        }

        public Attachment ReceiptCard()
        {
            var receiptCard = new ReceiptCard
            {
                Title = "John Doe",
                Facts = new List<Fact> { new Fact("Order Number", "1234"), new Fact("Payment Method", "VISA 5555-****") },
                Items = new List<ReceiptItem>
                {
                    new ReceiptItem("Data Transfer", price: "$ 38.45", quantity: "368", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png")),
                    new ReceiptItem("App Service", price: "$ 45.00", quantity: "720", image: new CardImage(url: "https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png")),
                },
                Tax = "$ 7.50",
                Total = "$ 90.95",
                Buttons = new List<CardAction>
                {
                    new CardAction(
                        ActionTypes.OpenUrl,
                        "More information",
                        "https://account.windowsazure.com/content/6.10.1.38-.8225.160809-1618/aux-pre/images/offer-icon-freetrial.png",
                        "https://azure.microsoft.com/en-us/pricing/")
                }
            };

            return receiptCard.ToAttachment();
        }        
    }
}

1 个答案:

答案 0 :(得分:4)

一些事情。首先,当您尝试添加附件时,您可能会收到空引用异常,因为附件数组尚未初始化。

<?php
$response = array("a" => "test");
echo (json_encode($response);
?>

此外,您无需创建CardDialog。这是一个有效的例子:

message.Attachments = new List<Attachment>();