jeudi 20 août 2020

How to loop on a `hold` in CSML?

I am writing a program in CSML and I want the chatbot to perform some data validation, so basically if an email or a phone number is not valid, it'd ask the question again but since we can't place a hold in a loop and break our of it when the data is valid, I don't quite understand how to go about that, here is the piece of code below:

start:
    say "Hi, let sign you up!"
    goto form
    
form:
    say "What's your name?"
    hold
    remember name = event
    say "What's your email address?"
    hold
    if (!event.contains_regex("^.+@.+\..+$")) {
         say "Please enter a real email address"
         // How do I get into a loop here  to ask the question again?
    }
    remember email = event
    say "What's your phone number?"
    hold
    if (!event.contains_regex("^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$")) {
         say "Please enter a real phone number (+(123) - 456-78-90)"
         // Same problem here?
    }
    remember name = event
    // the program continues

Aucun commentaire:

Enregistrer un commentaire