Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Authoring] Adaptive Card Expression is not being evaluated with .NET SDK using AdaptiveCards.Templating 2.0.4 nuget #9085

Open
devanshuGit opened this issue Jan 14, 2025 · 0 comments

Comments

@devanshuGit
Copy link

Target Application

BotFramework WebChat

Application Operating System

Linux

Schema Version

1.5

Problem Description

We are using pre-built functions to round of time to next 15 mins Pre-built

The expression in JSON schema is

{
"type": "Input.Time",
"id": "fromDateTimeId",
"value": "${{if(empty(fromDateTime), convertFromUTC(formatTicks(mul(ceiling(div(int(ticks(addMinutes(utcNow(),15))),9000000000)),9000000000)), timeZone, 'HH:mm'), formatDateTime(fromDateTime, 'HH:mm'))}}"
}

Same JSON schema is working in Adaptive Card designer

Image

Expected Outcome

Expecting the expression is evaluated and time is set in the field as in the designer

Image

Actual Outcome

However the JSON schema is interpreted and parse as follows

{"type":"Input.Time","id":"fromDateTime","value":${${if(fromDateTime == null || fromDateTime == '', convertFromUTC(formatTicks(mul(ceiling(div(int(ticks(addMinutes(utcNow(),15))),9000000000)),9000000000)), timeZone, 'HH:mm'), formatDateTime(fromDateTime, 'HH:mm'))}}},{"type":"TextBlock","text":"End Time","wrap":true}

Card JSON

{"type":"AdaptiveCard","$schema":"http://adaptivecards.io/schemas/adaptive-card.json","version":"1.5","body":[{"type":"Container","id":"plaintextbox","items":[{"type":"TextBlock","text":"Sure, Please select the title, date \u0026 time for the meeting.","color":"Dark","wrap":true}]},{"type":"Container","id":"formfield","items":[{"type":"TextBlock","text":"Add Title"},{"type":"Input.Text","id":"meetingTitle","maxLength":50,"value":"Team Meeting Created By Bot"},{"type":"TextBlock","text":"Date"},{"type":"Input.Date","id":"date","value":"2025-01-10","placeholder":"Enter a date"},{"type":"TextBlock","text":"Start Time","wrap":true},{"type":"Input.Time","id":"fromDateTime","value":${${if(fromDateTime == null || fromDateTime == '', convertFromUTC(formatTicks(mul(ceiling(div(int(ticks(addMinutes(utcNow(),15))),9000000000)),9000000000)), timeZone, 'HH:mm'), formatDateTime(fromDateTime, 'HH:mm'))}}},{"type":"TextBlock","text":"End Time","wrap":true},{"type":"Input.Time","id":"toDateTime","value":${${if($root.toDateTime != null && $root.toDateTime != '', formatDateTime($root.toDateTime, 'HH:mm'), if($root.fromDateTime != null && $root.fromDateTime != '', formatDateTime(addMinutes($root.fromDateTime, defaultDurationMinute), 'HH:mm'), convertFromUTC(formatTicks(mul(ceiling(div(int(ticks(addMinutes(addMinutes(utcNow(),15),defaultDurationMinute))),9000000000)),9000000000)),$root.timeZone, 'HH:mm')))}}}]},{"type":"Container","id":"SpaceFeedbackContainer","items":[{"type":"ColumnSet","columns":[{"type":"Column","width":"auto","items":[{"type":"ActionSet","actions":[{"type":"Action.Submit","title":"Confirm","associatedInputs":"auto"}]}]},{"type":"Column","width":"auto","items":[{"type":"ActionSet","id":"whiteBtn","actions":[{"type":"Action.Submit","title":"Cancel","associatedInputs":"none"}]}]}]}]}]}

Repro Steps

Template JSON
{ "type": "AdaptiveCard", "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.5", "body": [ { "type": "Container", "id": "plaintextbox", "items": [ { "type": "TextBlock", "text": "${summary}", "color": "Dark", "wrap": true } ] }, { "type": "Container", "id": "formfield", "items": [ { "type": "TextBlock", "text": "Add Title" }, { "type": "Input.Text", "id": "meetingTitle", "maxLength": 50, "value": "Team Meeting Created By Bot" }, { "type": "TextBlock", "text": "Date" }, { "type": "Input.Date", "id": "date", "value": "${if(fromDateTime == null || fromDateTime == '', convertFromUTC(utcNow(),timeZone,'yyyy-MM-dd'), formatDateTime(fromDateTime, 'yyyy-MM-dd'))}", "placeholder": "Enter a date" }, { "type": "TextBlock", "text": "Start Time", "wrap": true }, { "type": "Input.Time", "id": "fromDateTimeId", "value": "${{if(empty(fromDateTime), convertFromUTC(formatTicks(mul(ceiling(div(int(ticks(addMinutes(utcNow(),15))),9000000000)),9000000000)), timeZone, 'HH:mm'), formatDateTime(fromDateTime, 'HH:mm'))}}" }, { "type": "TextBlock", "text": "End Time", "wrap": true }, { "type": "Input.Time", "id": "toDateTime", "$data": "${data}", "value": "${if($root.toDateTime != null && $root.toDateTime != '', formatDateTime($root.toDateTime, 'HH:mm'), if($root.fromDateTime != null && $root.fromDateTime != '', formatDateTime(addMinutes($root.fromDateTime, defaultDurationMinute), 'HH:mm'), convertFromUTC(formatTicks(mul(ceiling(div(int(ticks(addMinutes(addMinutes(utcNow(),15),defaultDurationMinute))),9000000000)),9000000000)),$root.timeZone, 'HH:mm')))}" } ] }, { "type": "Container", "id": "SpaceFeedbackContainer", "items": [ { "type": "ColumnSet", "columns": [ { "type": "Column", "width": "auto", "items": [ { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Confirm", "associatedInputs": "auto" } ] } ] }, { "type": "Column", "width": "auto", "items": [ { "type": "ActionSet", "id": "whiteBtn", "actions": [ { "type": "Action.Submit", "title": "Cancel", "associatedInputs": "none" } ] } ] } ] } ] } ] }

Data JSON

{ "summary": "Sure, Please select the title, date & time for the meeting.", "fromDateTime": "", "toDateTime": "2025-01-08T04:45:00.000Z", "isAllDayEvent": true, "timeZone": "India Standard Time", "data": [ { "defaultDurationMinute": 15, "maxARP": 0, "maxBookingDuration": 0, "spaceTypeId": 2, "subSpaceTypeIds": [ 2 ], "earlyCheckinMinute": 15, "spaceCheckIn": true, "notificationTimes": [ { "subSpaceTypeId": 2, "time": 15 } ] } ] }

using following method in .NET solution

private AdaptiveCard GenerateAdaptiveCard(string contentPath, string cardData) { if (string.IsNullOrWhiteSpace(contentPath)) throw new ArgumentNullException(nameof(contentPath)); /*if (!string.IsNullOrWhiteSpace(cardData)) throw new ArgumentNullException(nameof(cardData));*/ var cardTemplate = File.ReadAllText(contentPath); var template = new AdaptiveCardTemplate(cardTemplate); var cardJson = template.Expand(cardData); //return cardJson; //// Parse the JSON AdaptiveCardParseResult result = AdaptiveCard.FromJson(cardJson); //// Get card from result AdaptiveCard card = result.Card; //card.Version = new AdaptiveSchemaVersion("1.3"); return card; ////var cardJson = new AdaptiveTransformer().Transform(cardTemplate, cardData); ////return AdaptiveCard.FromJson(cardJson).Card; }

public Activity GetActivityMessageForAdaptiveCard(string contentPath, string cardData) { if (string.IsNullOrWhiteSpace(contentPath)) throw new ArgumentNullException(nameof(contentPath)); /*if (!string.IsNullOrWhiteSpace(cardData)) throw new ArgumentNullException(nameof(cardData));*/ var adaptiveCard = this.GenerateAdaptiveCard(contentPath, cardData); var attachment = new Microsoft.Bot.Schema.Attachment { ContentType = AdaptiveCard.ContentType, Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(adaptiveCard)) //JsonConvert.DeserializeObject(adaptiveCard) }; var message = MessageFactory.Text(string.Empty); message.Attachments = new List<Attachment> { attachment }; message.InputHint = InputHints.IgnoringInput; ////message.Text = AdaptiveCardSpeakMessage.DefaultMessage; ////message.Speak = AdaptiveCardSpeakMessage.AdaptiveCardUserNotification; return message; }

var cardDataPath = "./Resources/MeetingDateTimeSelectionData.json"; var cardData = File.ReadAllText(cardDataPath);//JsonConvert.DeserializeObject(File.ReadAllText(cardDataPath)); //var cardTemplateData = JsonConvert.SerializeObject(cardData); var cardTemplatePath = "./Resources/MeetingDateTimeSelectionTemplate.json"; //await stepContext.Context.SendActivityAsync(GetActivityMessageForAdaptiveCard(cardTemplatePath, cardData), cancellationToken); await stepContext.Context.SendActivityAsync(GetActivityMessageForAdaptiveCard(cardTemplatePath, cardData), cancellationToken);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant