2

我想创建一个带有电子邮件和通话功能按钮的自适应卡片。我在自适应卡片中找不到电话和电子邮件的格式。有没有办法将自适应卡与英雄卡结合起来,因为英雄卡具有 cardAction 对象功能?

4

2 回答 2

0

有没有办法将自适应卡与英雄卡结合起来,因为英雄卡具有 cardAction 对象功能?

不,但其中的按钮AdaptiveCard不是使用CardAction对象创建的,您可以改用AdaptiveCard 中定义的模式。

共有三种动作OpenUrlSubmitShowCard。这Submit是我们需要的。

如果您想AdaptiveCard在 C# 中创建,例如可以创建它并发送如下消息:

AdaptiveCard card = new AdaptiveCard()
{
    Body = new List<CardElement>()
    {
        new Container()
        {
            Speak = "<s>Hello!</s><s>Send Email!</s>",
            Items = new List<CardElement>()
            {
                new TextBlock()
                {
                     Text = "Hello!",
                     Weight = TextWeight.Bolder,
                     IsSubtle = true
                },
                new TextBlock()
                {
                     Text = "Send Email!",
                     Wrap = true
                },
                new TextInput()
                {
                    Id = "EmailAddTo",
                    Placeholder = "To:"
                },
                new TextInput()
                {
                    Id = "EmailAddFrom",
                    Placeholder = "From:"
                },
                new TextInput()
                {
                    Id = "Subject",
                    Placeholder = "Subject:"
                },
                new TextInput()
                {
                    Id = "Content",
                    Placeholder = "Content:",
                    IsMultiline = true,                          
                }
            }
        }
    },
    Actions = new List<ActionBase>()
    {
        new SubmitAction()
        {
            Title = "Send Email",
            DataJson = "{\"Type\": \"EmailSend\"}"
        }
    }
};

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

var reply = context.MakeMessage();
reply.Attachments.Add(attachment);

await context.PostAsync(reply,CancellationToken.None);

使用Submitaction 时,Bot Framework 将处理提交,您的 bot 将收到一个IMessageActivity带有它的新的Value,然后您可以在代码中处理它,例如:

private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
    var message = await result;

    if (message.Value != null)
    {
        // Got an Action Submit
        dynamic value = message.Value;
        string submitType = value.Type.ToString();
        switch (submitType)
        {
            case "EmailSend":
                /* */
                return;
        }
    }
}

更多信息,可以参考官方Adaptive Cards Bot Sample

于 2017-12-08T06:03:00.400 回答
0

自适应卡片具有可以设置的动作元素和选择动作。您将根据输入要求创建一张卡片,然后使用提交操作来处理输入。注意文本输入元素,格式已设置为电子邮件或电话

{"type":"AdaptiveCard","version":"1.0","id":"c2de1dd7-c916-4196-a914-0694957aff77","minVersion":"1.0","fallbackText":"","speak":"","body":[{"type":"TextBlock","id":"23af4d94-cf3b-480e-8c28-5a7988b8a26b","text":"Email Address","maxLines":1},{"type":"Input.Text","id":"4a47c737-dbf0-42d0-aa9f-10f4f38bd20f","placeholder":"enter your email here","value":"","style":"email","maxLength":250,"isRequired":false},{"type":"TextBlock","id":"b4f3bce9-2464-473f-9129-48a3740aec8b","size":"large","text":"OR","horizontalAlignment":"center","maxLines":1},{"type":"TextBlock","id":"fe2d84aa-79e7-4fdf-91a0-79a9eb264dc1","text":"Call me","maxLines":1},{"type":"Input.Text","id":"d03d538f-7ead-4959-8a8e-7703dbaf1899","placeholder":"What's your number?","value":"","style":"tel","maxLength":250,"isRequired":false}],"actions":[{"type":"Action.Submit","id":"8421a872-2c4f-4fa2-8254-b1d88503cc8a","data":"","title":"Email Me"},{"type":"Action.Submit","id":"2ccf2819-ad38-492a-80f9-7cd5152fea09","data":"","title":"Call Me"}]}

在此处输入图像描述

于 2017-12-07T19:33:35.293 回答