0
votes

I'm not a programmer so please forgive me. But I've spent hours and hours of research on the topic of collecting information with Twilio AutoPilot and posted that data to Airtable, which I will then have Zapier do some things with that data. I finally had a breakthrough today and am now able to post data from a call or text to Airtable. The only way I got the ending to work was to send the call or text to Studio to finish up the call. Everything seems to work from the end user standpoint, but I'm getting an error 90100 from Twilio. I'm sure I'm just missing one line of code for this to work, and I'm at the end of my rope.

    {
    "actions": [
        {
            "say": "Okay lets get you a new appointment. I just need you to answer a few questions."
        },
        {
            "collect": {
                "name": "member",
                "questions": [
                    {
                        "question": "Please tell me your first name.",
                        "name": "name",
                        "type": "Twilio.FIRST_NAME"
                    },
                    {
                        "question": "Thanks, and what is your email address?",
                        "name": "email",
                        "type": "Twilio.EMAIL"
                    }
                ],
                "on_complete": {
                    "redirect": "task://complete_booking"
                }
            }
        }
    ]
}

Then i have another task setup to redirect to the Twilio Function. This is probably overkill, but it's what I found in research.

    {
        "actions": [
            {
                "redirect": {
                    "method": "POST",
                    "uri": "https://TWILIO_FUNCTION_URL/atable_post"
                }
            }
        ]
    }

Then the function is as follows. Mind you, this is posting correctly to airtable.

exports.handler = function(context, event, callback) {

    let memory = JSON.parse(event.Memory);
    let name = memory.twilio.collected_data.member.answers.name.answer;
    let email = memory.twilio.collected_data.member.answers.email.answer;
    console.log(memory);
    let member = {
        name : memory.twilio.collected_data.member.answers.name.answer,
        email : memory.twilio.collected_data.member.answers.email.answer,
        date : Date.now()
    };

    var Airtable = require("airtable");
    var base = new Airtable({apikey: context.AIRTABLE_API_KEY}).base("AIRTABLE_ID");

    base("Members1").create(member, function(err, record) {
        if (err) { console.error(err); return; }
        console.log(record.getId());
        callback(null, member);
    });

};

The call hung up at this point, so I redirected it to a Studio Flow, which does work and the call finishes with the response I'm give it before ending the call. Again, everything is working fine, but I get the following error from twilio, and I have no idea how to resolve it.

Invalid Autopilot Actions JSON: Invalid Autopilot Action

Any help would be greatly appreciated. Thanks!

1

1 Answers

0
votes

Nice work James! It looks the the issue is the redirect to your Twilio Function is not returning the expected JSON Action response to execute.

Autopilot - Redirect https://www.twilio.com/docs/autopilot/actions/redirect

Redirecting to URLs When redirecting to a URL, Redirect will make an HTTP callback to your application and will expect an Autopilot Actions JSON as a response. The request will contain all the dialogue information. This is an example of a dynamic Action since the JSON is rendered dynamically with a URL or your own endpoint.

Can you modify the Twilio Function to return valid Action JSON to Autopilot which sets the returned data, if needed via the Remember action which you can access from Studio?