0
votes

This only relevent to IBM Watson Conversation users.

I am trying to set a context variable to the only "valid" date the user enters in the @sys-date property. A valid date here is after 01/01/1900 and before now. According to SpEL definition I should select the list with .?[value > expression]. Where value or #this is the current list item.

"context": {
    "date": "<? @sys-date and @sys-date.values ? @sys-date.values.?[value.after('1900-01-01') and value.before(now())] : null ?>",
    "thisWorks": "<? {0,1,2,3,4}.?[false] ?>",
    "thisDoesNot": "<? {0,1,2,3,4}.?[value > 1] ?>"
}

thisWorks = [] Everything else throws an error. I have tried using #this but watson translates to (intent == 'this') and escaping like \#this throws an error before even trying to save.

IBM says it supports SpEL and part of the definition is collection selection. Even in this blog post it says this type of feature is supported. However there are no examples of it and everything I have tried results in errors.

Has anyone else used collection selection in Watson Conversation and provide an example?

2

2 Answers

0
votes

Not sure about your question, but maybe this information can help you.

Try to save the date in one context variable, e.g:

{
  "context": {
    "date": <? @sys-date ?>;
  },
  "output": {
    "text": {
      "values": [
        "Are you sure about this $date?"
      ],
      "selection_policy": "sequential"
    }
  }
}

And after, make your conditions...

To see if the $date is in the future use:

if bot recognizes now().before($date) or @sys-date.before($date)
response "Ok, the date is before $date."

If the past:

now().after($date) or @sys-date.after($date)
response "Ok, the date is after $date, in this case is one invalid date"

Obs.: You can use this examples inside the conditions. In your case is to use the 'valids' dates in if bot recognizes.

0
votes

The only way I was able to filter a list is to make it a list of objects. For example:

<? {1:1, 2:2, 3:3 }.?[value < 3 ].![value] ?>

Hope this helps.