0

I am using IBM Watson Assistant and try to validate user input against time frames / spans. What function should I use?

I was using @sys-date.before(now()) method to validate the time frame between past and present of a user input, but it does now work for me. If I input now or today Watson Assistant still thinks it is a past...

@sys-date.before(now()):

Looks "like you're trying to make a reservation in the past. Try again." true $day it is

I expect if user inputs now or today to make reservations work, and if user inputs time in the past to response as

"like you're trying to make a reservation in the past. Try again."

The code snippet in question looks like this:

{ "context": 
    { "day": "@sys-date" } }
{ "context": 
    { "time": "<? @sys-time.reformatDateTime('h:mm a') ?>" } }

2 Answers 2

1

I solved it! What I did is I put (today) for here @sys-date.before(today()) and now for here @sys-time.before(now())

Sign up to request clarification or add additional context in comments.

Comments

0

With IBM Watson Assistant you can use systen entities @sys-date and @sys-time to turn user input into data / time values. And you can use expression language functions for date and time to evaluate and transform those values. It seems that you are already using both. Now it is up to the logic...

There are functions before and after, but also sameMoment or sameOrAfter and more for comparisons. If the user inputs today, it is not before now because both would refer to the same day and date. Are you looking for the time value to be before the current timestamp or before the current date? You would need to compare time to time or date to date. You can reformat the values to snip off the time component and turn them into dates.

For more fancy validations you could even use java.util.Date functionality.

This should be true if it is a past moment:

now.after(yourInput)

10 Comments

Hi, data_henrik! The code does not compare or ignores if I input the date in the past. My chatbot does not recognize yesterday is the past already. So the code that IBM developers suggest for comparison Before(now()) in my case does not work. My chatbot perfectly recognizes dates and time but it does not understand if it is already past.
Add your code that you use for comparison and add sample values. What is the user input, what is the recognized data / time that is processed?
@sys-date.before(now()) and $day as a value. and "Looks like you're trying to make a reservation in the past. Try again." as a response. The input I test is a day before the current day but it makes a reservation anyways even if I use the code.
@sys-date.before(now()) You cannot make a reservation for a day in the past. Clear slot and prompt again , this is what IBM tutorial says but it does not properly work
I added a short code sample. Could you add to your question the JSON of the entire node?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.