Skip to content

Instantly share code, notes, and snippets.

@hhyyg
Created July 30, 2017 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhyyg/c397f9ce6d03497314f9a9027fe046c6 to your computer and use it in GitHub Desktop.
Save hhyyg/c397f9ce6d03497314f9a9027fe046c6 to your computer and use it in GitHub Desktop.
Adaptive Card Action Sample
/*
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;
}
/*
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>
/// 入力フォーム
/// </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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment