I hope you are well and healthy. I am trying to check the user input in a Twilio function for a specific "collect" from autopilot against multiple Field Types which some are custom.
For instance, I ask the user for their name first and then their phone number. The set types for these collect questions are Twilio.FIRST_NAME and Twilio.PHONE_NUMBER. However, the user might say "connect me to someone" on any of these 2 questions which will result in a failure because "connect me to someone" is not a name or a phone number. I want to be able to somehow handle a case like that which provides me control over the flow of the conversation but also be able to detect specific phrases and handle it properly. In this instance, connect them to someone.
Here is my Twilio function that executes after the initiation task:
exports.handler = function (context, event, callback) {
var responseObject;
responseObject ={
"actions": [
{
"collect": {
"name": "details",
"questions": [
{
"question": "May I get your first name?",
"name": "name",
"type": "Twilio.FIRST_NAME",
"validate": {
"on_failure": {
"messages": [
{
"say": "Sorry, that doesn't seem to be right, can you please try again?"
}
],
"repeat_question": true
},
"max_attempts": {
"redirect":{
"method": "POST",
"uri": "https://quartz-salamander-1024.twil.io/call-forwarding"
},
"num_attempts": 2
}
}
},
{
"question": "Can I get your contact number?",
"name": "phoneNumber",
"type": "Twilio.PHONE_NUMBER",
"validate": {
"on_failure": {
"messages": [
{
"say": "Sorry, that doesn't seem to be right, can you please try again?"
}
],
"repeat_question": true
},
"max_attempts": {
"redirect":{
"method": "POST",
"uri": "https://quartz-salamander-1024.twil.io/call-forwarding"
},
"num_attempts": 2
}
}
},
],
"on_complete": {
"redirect": {
"method": "POST",
"uri": "https://quartz-salamander-1024.twil.io/confirmation"
}
}
}
}
]
}
callback(null, responseObject);
}
I thought of creating multiple tasks for each question however I intend on adding more questions that I must collect their answers and validate in some fashion and by introducing multiple tasks I lose control over the flow of the conversation.
Thank you