How to format date within Confirm and Message methods of FormBuilder
.Confirm("Please Confirm, You are looking for flights flying out on {Date}"
How to format Date in a particular format. ("dddd dd MMMM")
Thanks, Dhiraj Gupta
This is a string formatting question that is outside of Bot Framework's scope. I suggest you look on Stack Overflow for date formatting questions.
This is related to scope of state object, while i am using string format i am not able to access Date property of my state object ( the object we are using in form builder). The question is how to access those properties while we need to apply formatting
Hello Dhiraj
It looks like you can format your date like Confirm("{?at {DateAndTime:dddd dd MMMM}}?")
As for getting at the date from the Form. I have been looking at this and it looks like you can get at the state in a few places.
A couple that I see are in OnCompletionAsyncDelegate and Confirm
public class TestDate
{
[Prompt("please give me a {&} would you like? {||}")]
public DateTime DateAndTime;
public static IForm<TestDate> BuildForm()
{
OnCompletionAsyncDelegate<TestDate> processOrder = async (context, state) =>
{
//if you place a break point on the await, youcan see in the state the DateAndTime value.
await context.PostAsync("We are currently processing your sandwich. We will message you the status.");
};
return new FormBuilder<TestDate>()
.Message("Welcome!")
.Field(nameof(TestDate.DateAndTime), "Please give me date and time? {||}")
.Confirm(async (state) =>
{
//if you place a break point on the await, youcan see in the state the DateAndTime value.
return new PromptAttribute($"your datetime is {state.DateAndTime} is that ok? {{||}}");
})
.Confirm("{?at {DateAndTime:dddd dd MMMM}}?")
.AddRemainingFields()
.Message("Thanks!")
.OnCompletion(processOrder)
.Build();
}
};
Also if you place a validate on the field you can see the entered value validate: async (state, value) => {}
If you look at the FormFlow reference you can see a few places that you can get at state.
Hope this helps Danny