csharp 自适应卡片动作样本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 自适应卡片动作样本相关的知识,希望对你有一定的参考价值。

/*
using AdaptiveCards;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System.Collections.Generic;
*/

/// <summary>
/// 入力フォーム
/// </summary>
/// <returns></returns>
public static AdaptiveCard CreateFormCard()
{
	var card = new AdaptiveCard();

	var columnsBlock = new ColumnSet()
	{
		Separation = SeparationStyle.None,
		Columns = new List<Column>
		{
			new Column
			{
				Size = "2",
				Items = new List<CardElement>
				{
					new TextBlock
					{
						Text = "Tell us about yourself...",
						Weight = TextWeight.Bolder,
						Size = TextSize.Large,
					},
					new TextBlock
					{
						Text = "We just need a few more details to get you booked for the trip of a lifetime!",
						IsSubtle = true,
						Wrap = true,
					},
					new TextBlock
					{
						Text = "Your name",
						Wrap = true,
					},
					new TextInput
					{
						Id = "myName",
						Placeholder = "Last, First",
					},
					new TextBlock
					{
						Text = "Your email",
						Wrap = true,
					},
					new TextInput
					{
						Id = "myEmail",
						Placeholder = "youremail@example.com",
						Style = TextInputStyle.Email,
					},
					new TextBlock
					{
						Text = "Phone Number",
						Wrap = true,
					},
					new TextInput
					{
						Id = "myTel",
						Placeholder = "xxx-xxxx-xxxx",
						Style = TextInputStyle.Tel,
					},
				}
			},
			new Column
			{
				Size = "1",
				Items = new List<CardElement>
				{
					new Image
					{
						Url = "https://upload.wikimedia.org/wikipedia/commons/b/b2/Diver_Silhouette%2C_Great_Barrier_Reef.jpg",
						Size = ImageSize.Auto,
					}
				}
			}
		}
	};
	card.Body.Add(columnsBlock);

	card.Actions = new List<ActionBase>()
	{
		new SubmitAction
		{
			Title = "Submit",
			DataJson = "{ \"Type\": \"CreateFormCard\" }",
		}
	};
	return card;
}
/*
using AdaptiveCards;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System.Collections.Generic;
*/

/// <summary>
/// Action ShowCard のサンプル
/// </summary>
/// <returns></returns>
public static AdaptiveCard CreateShowCard()
{
  var card = new AdaptiveCard();

  var container = new Container
  {
    Items = new List<CardElement>
    {
      new TextBlock
      {
        Text = "サンプル文章です",
      }
    }
  };
  card.Body.Add(container);

  //選択すると表示するカードの作成
  var subCard = new AdaptiveCard();
  subCard.Body.Add(new TextInput
  {
    Id = "Comment",
    IsMultiline = true,
    Placeholder = "コメントを入力してください",
  });
  subCard.Actions = new List<ActionBase>()
  {
    new SubmitAction
    {
      Title = "Submit",
      DataJson = "{ \"Type\": \"PostComment\" }",
    }
  };

  card.Actions = new List<ActionBase>()
  {
    new ShowCardAction
    {
      Title = "コメント",
      Card = subCard,
    }
  };

  return card;
}
/*
using AdaptiveCards;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using System.Collections.Generic;
*/

/// <summary>
/// URLを開くカード
/// </summary>
/// <returns></returns>
public static AdaptiveCard CreateOpenUrlCard()
{
  var card = new AdaptiveCard();

  var columnsBlock = new ColumnSet()
  {
    Separation = SeparationStyle.Default,
    Columns = new List<Column>
    {
      new Column
      {
        Size = "1",
        Items = new List<CardElement>
        {
          new TextBlock
          {
            Text = "miso_soup3 blog",
            Weight = TextWeight.Bolder,
            Size = TextSize.ExtraLarge,
            Wrap = true,
          },
          new TextBlock
          {
            Text = "主に ASP.NET について書いています",
            IsSubtle = true,
            Wrap = true,
          },
        }
      },
      new Column
      {
        Size = "1",
        Items = new List<CardElement>
        {
          new Image
          {
            Url = "https://cdn1.www.st-hatena.com/users/mi/miso_soup3/profile.gif",
            Size = ImageSize.Medium,
          }
        }
      },
    },
  };

  card.Body.Add(columnsBlock);

  card.Actions = new List<ActionBase>()
  {
    new OpenUrlAction
    {
      Title = "開く",
      Url = "http://miso-soup3.hateblo.jp/",
    }
  };

  return card;
}

以上是关于csharp 自适应卡片动作样本的主要内容,如果未能解决你的问题,请参考以下文章

适用于常见问题的自适应卡内的自适应卡

自适应卡片 js 渲染 - 不支持卡片

BotFramework-WebChat - 自适应卡片

如何将自定义 json 转换为自适应卡片 json 格式

自适应卡片:Action.Show Card 上的动态数据绑定

如何将背景图像添加到自适应卡片机器人框架