Tuesday, 7 May 2019

How would I ask the user for a list of names?

I'm creating a custom Alexa skill and it need to collect a unknown number of names that the user says.

I have tried to store the names in a slot. I was able to get one name to work this way but not multiple. Right now, I am trying to ask the user for a number of people and then ask the user the names. But, I can not figure out how to get that solution to work. Also, I am trying to store the names in the session attributes.

Here is a what I have so far

    // Api call wrapped into a promise. Returns the person's email.
    return findEmployee(sessionAttributes.client, givenName)
        .then(attendee => {
            let prompt = ''
            if (attendee.value.length === 1) {
            sessionAttributes.attendees = [...sessionAttributes.attendees, attendee.value[0]]
            prompt = `${attendee.value.displayName} added to the meeting.`
            return handlerInput.responseBuilder
                .speak(prompt)
                .reprompt(prompt)
                .getResponse()
            }
         })
         .catch(err => console.log(err))

This snippet works fine with one person but how would I refactor it so Alexa will ask until a end condition is reached.



from How would I ask the user for a list of names?

No comments:

Post a Comment