Watson assistant putting the day of the week in a variable based on user input of @sys-date

Viewed 874

I'm making a bot that can take dinner reservations. When it asks for the users reservation time, I'd like the bot to populate my variable $dayoftheweek with the day of the week based on the date the user inputs. How would I be able to do that?

slot

here is my slot "If Found".

value Basically I'd like to know what "value" I could put in to get the day of the week populated.

3 Answers

The easiest would be to use the new system entities (currently in beta). Enable the beta in your skills options. Then, in your dialog node, assign the following:

Check for: @sys-data.day_of_week
save as: mydayofweek

Note that the day names are lower case.

You can use the method reformatDateTime of the expession language to get the day from @sys-date.

For example setting $dayofweek to

<? @sys-date.reformatDateTime('u') ?> 

will set $dayofweek to a value between "1" (Monday) and "7" (Sunday)

or setting $dayofweek to

<? @sys-date.reformatDateTime('E') ?> 

will set $dayofweek to a value between "Mo" and "Su"

The value of @sys-date is stored as a string format "yyyy-MM-dd" e.g. "2016-11-21".

If you want to know what day of the week that date is, you can use the method reformatDateTime:

"<? @sys-date.reformatDateTime('EEEE') ?>"

Here all the posibles values of the method

So your node would look something like this.

Or in JSON format:

{
  "context": {
    "dayoftheweek": "<? @sys-date.reformatDateTime('EEEE') ?>"
  }
}

And here a small test of what would be stored in $dayoftheweek:

Watson: Hello. How can I help you?

User: Day of the week test

Watson: Tell me a date

User: September 13, 2019

Watson: Friday

Here is the JSON Skill for the test.

Related