0

I've made an IVR using Twilio Studio. In my API I have something like this

await validateForm(form);
await twilioIvrService(phone);
await saveData(form);

return res.json({message "Ok"})

Is there a way to wait for the twilioIvrService response? I mean, at the end of the IVR flow (on Twilio Studio) it should return a value (Boolean) depending on the user's choice, and saveData should store the form on a DB only if value is true. I want to get that value before calling saveData. The form parameter is almost 5KB.

This is how I run the Twilio flow using REST API Trigger

const twilioIvrService = async (phone) => {
  try {
    const { data } = await axios.post(
      url,
      new URLSearchParams({
        To: phone,
        From: TWILIO_PHONE,
      }),
      {
        auth: {
          username: twilioAccountSid,
          password: twilioAuthToken,
        },
      },
    );

    console.log(data);
  } catch (error) {
    console.log(error);
  }
};
Fernando
  • 15
  • 6

1 Answers1

0

No, the request that you make only triggers the Studio flow and return immedially.

I think it would be better if you provided a webhook that calls saveData(form); and add this webhook as the last step in your studio flow.

IObert
  • 2,118
  • 1
  • 10
  • 17
  • Do you mean using a "Make HTTP Request" widget at the end of the flow? The `form` parameter is almost 5KB, I think I can pass it via REST API Trigger and the widget can manage that. `saveData` should store the form on a DB only if the IVR response is successful – Fernando Apr 21 '23 at 17:51
  • Yes, that's what I meant. – IObert Apr 24 '23 at 06:19
  • Thanks, there's a problem with this. I want to send the same `body` the widget receives, so I've added `{{flow.data}}` on Request body, but when I want to `JSON.parse(data)` (on my API) it throws an error. The data I receive from the HTTP Request looks like this `{key=value, key=value}` (it's a string), the object doesn't have quotes in the key or in the value and can't be parsed (besides the equal sign instead of a colon). How can I send the full body ready to be parsed to an object? – Fernando Apr 24 '23 at 21:43
  • It sounds like the request is "form URL encoded" but you should be able to [change the type](https://www.twilio.com/docs/studio/widget-library/http-request#required-configuration-for-make-http-request) in the widget config. – IObert Apr 25 '23 at 08:07