In Twilio Autopilot, I want to validate user input. In this case order_number
.
Assume order_number
can be anything between 8-12 characters. I have a webhook for validation.
I want to let the user know why the validation failed if they entered an order number that was lt 8 or gt 12 characters, or if the order_number
doesn't exists in our db.
My webhook returns { valid: true }
or { valid: false }
based on success or failure of validation.
My goal is to customize my failure message based on what validation failed. Is there a seamless way to achieve that ?
{
collect: {
name: 'collect_order_number',
questions: [
{
question: 'Can I have your order number ?',
name: 'order_number',
type: 'Twilio.ALPHANUMERIC',
validate: {
on_failure: {
messages: [ # How to customize this based on webhook validation ?
{ say: 'Order number too short' },
{ say: 'Order number too long' },
{ say: 'Could not find order number' },
],
repeat_question: true,
},
webhook: {
url: `https://<www.domain.com>/autopilot/validate_field`,
method: 'POST',
},
on_success: {
say: 'Great! got your order number',
}
}
},
{ ... more questions }
]
}
}