简体   繁体   English

使用Microsoft Bot Framework将卡片附件添加到邮件中

[英]Add Card attachment to message using Microsoft Bot Framework

Problem: 问题:

  • Attaching a card to a response dialog, the following code is mostly taken from the bot samples, but does not display a card in the response dialog in the key pieces of display logic I pulled used. 将卡添加到响应对话框中,以下代码大部分来自bot示例,但在我拉动的显示逻辑的关键部分中,未在响应对话框中显示卡。

I am having trouble doing attachment within in a LUIS Intent task. 我在执行LUIS Intent任务时遇到麻烦。

Goal 目标

  • Have a user ask a question that LUIS does not recognize and then respond with a help card once the code jumps into the LUIS intent task responsible for handling the unrecognized. 让用户提出一个LUIS无法识别的问题,然后在代码跳入负责处理无法识别的LUIS意向任务后,用帮助卡进行响应。 Is there some other structure of a help window I could consider, that still utilizes cards? 我可以考虑使用帮助卡的其他一些帮助窗口结构吗?

Code

Where my card should be displayed from 我的卡应该从哪里显示

[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);
    }

Card Class of the View object I'ved created that I am trying to display. 我创建的要显示的View对象的Card Class。

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();
        }        
    }
}

A couple things. 几件事。 First, you are probably getting a null ref exception when you are trying to add the attachment as the attachments array hasn't been initialized yet. 首先,由于附件数组尚未初始化,当您尝试添加附件时,可能会收到null ref异常。

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

Also, you don't need to create the CardDialog. 另外,您无需创建CardDialog。 Here's an example that works: 这是一个有效的示例:

    [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 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://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png",
                    "https://azure.microsoft.com/en-us/pricing/")
            }
        };

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

        await context.PostAsync(message);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Microsoft Bot Framework上处理邮件附件 - Handling Message Attachment on Microsoft Bot Framework 在bot框架中翻译邮件附件 - Translate message attachment in bot framework 在 Microsoft Bot Framework 中的每条消息后添加“喜欢”和“不喜欢”按钮 - Add Like and Dislike button after every message in Microsoft Bot Framework 使用自定义API机器人无法使用Bot框架在Microsoft Teams频道中发布操作卡 - Using Custom API bot can't post action card in Microsoft Teams channel using Bot framework 如何在 Teams 中使用 Bot Framework 在自适应卡旁边添加提及 - How to add a mention in Teams alongside an adaptive card using Bot Framework 在Microsoft Bot框架中是否可以进行卡片操作来生成另一张卡片? - Is there a card action to generate another card in Microsoft Bot framework? 无法在MS bot框架中向邮件添加附件:对象引用未设置为对象的实例 - Cannot add attachment to message in MS bot framework: object reference not set to an instance of an object 如何使用Microsoft Bot Framework从我的Bot显示欢迎消息 - How to display a welcome message from my Bot using Microsoft Bot Framework 使用Microsoft Bot Framework V4主动向Microsoft Teams中的团队聊天发送消息 - Proactively send message to a Team chat in Microsoft Teams using Microsoft Bot Framework V4 Microsoft Bot Framework - 团队和Skype for Business不支持自适应卡版本 - Microsoft Bot Framework - Adaptive card version not supported in Teams and Skype for Business
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM