Using data output as Choices

#1

My use case is as follows:

  • make a all to an external service to get a list of options; list is of unknown length
  • using the “Ask a Question” service, and a Question Type of “Choice”, ask the user to pick one of the items from the list

Notes:

  • the “list” returned as an array of named items in JSON format
  • I’m referencing data_+_name of each item in the array as a potential “Choice” for the User

My question…
What value do I give for the Choices?

I’ve tried referencing the Magic Set, but that only provides everything as one choice.

Thanks!

(Aly Dabbous) #2

Hi @thomas How were you able to the list with unkown length?

I kind of want to do the same thing to do. I am building a bot to reserve restaurants and I want users to choose a restaurant from a group of restaurants. After the user chooses a restaurant an Email should be sent to the restaurant itself notifying them about the reservation. The problem with that is the Card-sets don’t come in the form of a questions but a message, so when I send an Email to the restaurant I can’t place an answer to a question as a data output in my Email. So the restaurant will never know which restaurant the User has Reserved.

(John Jackson) #3

@thomas The value really depends on what you want to do after the user has made a choice. If you leave the value blank, you’ll get back the choice itself - i.e. the button text that was chosen. This may be enough for you?

Otherwise, you could put an ID number in the value field, and then after the user has made the choice, use that ID to fetch details about the object the user has chosen?

#4

Thanks for the response @johnjackson, but my problem is a little ahead of what you’re suggesting.

E.g. if I get back a list like

[{"id":2144425,"name":"choice 1"},
 {"id":2253274,"name":"choice 2"},
 ...
 {"id":9999999,"name":"choice n"}] 

… and I want to use the name attribute of each item in the list as the “choice” that the user has available to them in the “Ask a Question” service, I may reference that list as service_name.data__name and use the collections syntax to get the entire list.

However, each “Choice” on the “Ask a Question” requires a single “choice” value and I can’t simply reference the Magic Set for the list above, e.g. {{service_name.data__name *}} and have the list show up as multiple choices.

So I’m kind of stuck trying to figure out how to take this list of unknown length and have it show up as a set of choices for the user.

You’re right though in that I’ll have a similar problem with the “value” half of the “choice” option because I’m going to want to show the name attribute value as the button text, but will want to make a follow-up API call referencing the id corresponding with the name that was chosen. So any suggestions there would be appreciated.

Thanks again for the quick reply.

(John Jackson) #5

OK I see now. Actually instead of using collections, it might be better to use the data outputs format.

In the case of data coming back as you described, to get the first choice, you’d use:

{{service_name.data__0__name}}

And for the second choice:

{{service_name.data__1__name}}

We can’t currently show choices for an unknown number of results, but you can add choices for 10 items, and you’ll only see the number of buttons for the number of items you have (i.e. if the choice is empty, no button is shown).

For each choice, set the value to:

{{service_name.data__0__id}}
{{service_name.data__1__id}}
etc..

Then your answer will be set to the chosen ID. From that, use another HTTP request to get the details of that ID, and present the info to the user.

Hope that gets you further along! Good luck with it :smiley:

#6

Thanks @johnjackson. I was afraid this would be the answer and I’d ask if, somehow, a solution can find its way on to the FlowXO roadmap as this is going to be a pretty significant blocker for what I’m trying to prototype on FlowXO.

To use a common example that I’ve seen on services like this, i.e. booking an appointment, and to which the base example is quite simple (almost too simple), I would suggest thinking about this kind of use case:

  1. User wants to book an appointment.
  2. Ask the user what type of appointment they would like to book (this list would come from an external service and could have 1…n types returned).
  3. User selects an appointment type.
  4. Ask the user what date they would like to book the appointment (this list would come from an external service, dates based on availability of the service provider and appointment type)
  5. User selects an available date.
  6. Ask the user what time they would like to book the appointment (this list would come from an external service, times based on availability of the service provider for that day and appointment type).
  7. User selects an available time.
  8. System books the appointment.

If I had to guess, I think the “easy” solution here would be just to put some intelligence into the “Ask a Question” service (and perhaps many other places that would benefit), to allow a collection to be passed to the “choice” field and have it split up the collection into multiple choices if it detects the input is a collection.

An alternative, if that’s too much heavy lifting, is to provide an alternate field that expects a collection as input.

Similarly, value fields would expect a collection of values.

The above would make my problem be a simple matter of referencing {{service_name.data__name *}} as the choices and {{service_name.data__id *}} as the values.

I’m not sure I can use the workaround you suggested as it implies a few “cons” on the UX side of things which is fundamental to what I’m trying to prove is better through a conversational bot approach than requiring a lot of back and forth with the user just to find a choice that is appealing to them. Further, I can’t simply “add choices for 10 items”, because if the user doesn’t like those 10 and wants to see 10 more, I need to solve that, which, btw, would be interesting to hear how that’s solved in FlowXO, assuming I might need to go that route in the short term.

Thanks again!

1 Like
(JI) #7

Great post! @thomas, I’d be happy to know if you got a temporary fix and how.

And @johnjackson, I’d be interested in knowing if there’s any movement on this topic at Flow Xo.

Cheers

(Karen Barker) #8

Hi @jerryiversen,

I have known users use the code service to return the first 9 results and then append a “More” option for the 10th choice. You’ll then need to filter a GoTo label for if the answer to the question is “More”. This then loops back to the code service action where you can get the next 9 options and so on until the user selects a specific answer. :thumbsup: