var directLineClient = new DirectLineClient("here is key that is got from Bot Channels Registration");
var conversation = await directLineClient.Conversations.StartConversationAsync();You can send a message to bot using the conversation id.
await directLineClient.Conversations.PostActivityAsync(conversation.ConversationId, new Activity { From = new ChannelAccount("User id"), Text = "a message send to bot", Type = ActivityTypes.Message, });And you can also get messages from the bot.
string watermark = null; while(true) { var activitySet = await directLineClient.Conversations.GetActivitiesAsync(conversation.ConversationId, watermark); watermark = activitySet.Watermark; var botMessages = activitySet.Activities.Where(x => x.From.Id == "bot id"); foreach (var message in botMessages) { // process a message that is from the bot } await Task.Delay(2000); }It's very simple and easy.
private IEnumerable<AdaptiveCard> ConvertAttachmentsToAdaptiveCard(IEnumerable<Attachment> attachments) { AdaptiveCard parseHeroCard(string json) { var heroCard = JsonConvert.DeserializeObject<HeroCard>(json); return new AdaptiveCard("1.0") { Body = new List<AdaptiveElement> { new AdaptiveTextBlock(heroCard.Title) { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder, }, new AdaptiveTextBlock(heroCard.Text), }, }; } return attachments?.Select(x => x.ContentType switch { "application/vnd.microsoft.card.hero" => parseHeroCard(x.Content.ToString()), "image/png" => new AdaptiveCard("1.0") { Body = new List<AdaptiveElement> { new AdaptiveImage(x.ContentUrl), } }, _ => null, }) ?.Where(x => x != null); }The rendering logic is like following code:
// The code for UWP var renderer = new AdaptiveCardRenderer(); var adaptiveCard = ... // Get an AdaptiveCards.AdaptiveCard instance var renderedCard = renderer.RenderAdaptiveCard(AdaptiveCard.FromJsonString(adaptiveCard.ToJson())); renderedCard.FrameworkElement; // get resultThe sample program
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.