botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

How to format date within Confirm and Message methods of FormBuilder

Open dhirajgupta1 opened this issue 9 years ago • 3 comments

.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

dhirajgupta1 avatar Mar 21 '17 09:03 dhirajgupta1

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.

mgbennet avatar Mar 21 '17 17:03 mgbennet

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

dhirajgupta1 avatar Mar 22 '17 03:03 dhirajgupta1

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

djweddle avatar Mar 24 '17 21:03 djweddle