Twiml redirect widget not posting

aaron_cl
aaron_cl
edited May 24 in Studio

I'm Attempting to use the Twiml redirect widget as a mechanism to wait for a server-side process to complete, and then resume the flow.

I've configured the "Twiml redirect" widget with my ngrok url, which points to my local app.

However, when testing the flow by starting a new webchat, the POST request to the ngrok url is never fired. I've verified the address is configured correctly, and using postman to hit the ngrok url completes correctly. The studio widget never makes the request.

As a follow up question: once that's figured out, how is one to approach the issue of the waiting? Should I just hold the connection open on the server side, or is there a way to post to a webhook to notify the studio flow to proceed? If that's the case, what would the initial response from the twiml widget?

EDIT: including studio flow json:

{
  "description": "Bot flow for creating a Flex webchat task",
  "states": [
    {
      "name": "Trigger",
      "type": "trigger",
      "transitions": [
        {
          "next": "notify_hold_test",
          "event": "incomingMessage"
        },
        {
          "event": "incomingCall"
        },
        {
          "event": "incomingRequest"
        },
        {
          "event": "incomingParent"
        }
      ],
      "properties": {
        "offset": {
          "x": -1300,
          "y": -1660
        }
      }
    },
    {
      "name": "hold",
      "type": "add-twiml-redirect",
      "transitions": [
        {
          "next": "send_message_1",
          "event": "return"
        },
        {
          "next": "send_message_2",
          "event": "timeout"
        },
        {
          "next": "send_message_3",
          "event": "fail"
        }
      ],
      "properties": {
        "offset": {
          "x": -1290,
          "y": -1120
        },
        "method": "POST",
        "url": "https://redacted.ngrok.io/api/twiml",
        "timeout": "14400"
      }
    },
    {
      "name": "send_message_1",
      "type": "send-message",
      "transitions": [
        {
          "event": "sent"
        },
        {
          "event": "failed"
        }
      ],
      "properties": {
        "offset": {
          "x": -1750,
          "y": -760
        },
        "service": "{{trigger.message.InstanceSid}}",
        "channel": "{{trigger.message.ChannelSid}}",
        "from": "{{flow.channel.address}}",
        "to": "{{contact.channel.address}}",
        "body": "returned"
      }
    },
    {
      "name": "send_message_2",
      "type": "send-message",
      "transitions": [
        {
          "event": "sent"
        },
        {
          "event": "failed"
        }
      ],
      "properties": {
        "offset": {
          "x": -1440,
          "y": -740
        },
        "service": "{{trigger.message.InstanceSid}}",
        "channel": "{{trigger.message.ChannelSid}}",
        "from": "{{flow.channel.address}}",
        "to": "{{contact.channel.address}}",
        "body": "timeout"
      }
    },
    {
      "name": "send_message_3",
      "type": "send-message",
      "transitions": [
        {
          "event": "sent"
        },
        {
          "event": "failed"
        }
      ],
      "properties": {
        "offset": {
          "x": -1110,
          "y": -760
        },
        "service": "{{trigger.message.InstanceSid}}",
        "channel": "{{trigger.message.ChannelSid}}",
        "from": "{{flow.channel.address}}",
        "to": "{{contact.channel.address}}",
        "body": "fail"
      }
    },
    {
      "name": "notify_hold_test",
      "type": "send-message",
      "transitions": [
        {
          "next": "hold",
          "event": "sent"
        },
        {
          "event": "failed"
        }
      ],
      "properties": {
        "offset": {
          "x": -1300,
          "y": -1390
        },
        "service": "{{trigger.message.InstanceSid}}",
        "channel": "{{trigger.message.ChannelSid}}",
        "from": "{{flow.channel.address}}",
        "to": "{{contact.channel.address}}",
        "body": "starting hold test..."
      }
    }
  ],
  "initial_state": "Trigger",
  "flags": {
    "allow_concurrent_calls": true
  }
}

Best Answer

  • zpitts
    zpitts
    Accepted Answer

    Hello, sorry for the confusion. TwiML Redirect does not work with Flex-based messaging Flows. The HTTP Request widget would work if your server-side process returns in 10 seconds or less, but if you need more than that, you'd have to implement polling of some sort to check when the process is complete. This can be done with a combination of HTTP Request, Split and Set Variables widgets to create a loop. Hope that helps!

Sign In or Register to comment.