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 Answers2

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())

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)
data_henrik
  • 16,724
  • 2
  • 28
  • 49
  • 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. – Egor Petrov May 29 '19 at 15:09
  • 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? – data_henrik May 29 '19 at 15:39
  • ```@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. – Egor Petrov May 29 '19 at 15:57
  • ```@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 – Egor Petrov May 29 '19 at 16:03
  • I added a short code sample. Could you add to your question the JSON of the entire node? – data_henrik May 29 '19 at 16:15
  • ```now.after(yourInput)``` is what here? Instead of yourInput something else? Because I tried this one and it did not change anything. probably something else does not let this code to run properly that I have not noticed yet. – Egor Petrov May 30 '19 at 05:03
  • Thank you btw. I can actually add the entire code of the node.```{ "context": { "day": "@sys-date" } } { "context": { "time": " @sys-time.reformatDateTime('h:mm a') ?>" } }``` These are two main codes handling the time inputs for booking but it does not say much – Egor Petrov May 30 '19 at 05:12
  • just tried this ```@sys-date.before($day)``` and no luck :What day would you like to schedule a call?? 24-5-2017 Irrelevant @sys-number:24 @sys-date:2017-05-24 @sys-number:-5 @sys-number:-2017 2017-05-24 it is What time on 2017-05-24 do you want to schedule a call? as you can see here it makes reservation even if the date is a past. – Egor Petrov May 30 '19 at 05:38
  • You are not sharing the entire code and it is hard to judge what is wrong with it. – data_henrik May 30 '19 at 05:44
  • So I added, shared the entire dialogue nodes tree. Any ideas? – Egor Petrov May 31 '19 at 04:07