Twilio Function: access variable from studio flow "set variable"

Viewed 108

I'm sure this is a silly question, but I don't claim to be a developer, just someone with a wide ranging job description

I am following this guide: https://www.twilio.com/blog/forward-voicemail-recordings-to-email

The transcription callback is firing correctly and sending me the email. That's great.

I'm looking to expand this to collect additional information fields through Gather widgets. I have the following being sent to my function:

{
  "flow": {
    "flow_sid": "FW07e11311d367...f8a0501c05e5108",
    "variables": {
      "CallerName": "Joe Bloggs"
    },
    "channel": {
      "address": "+441...147"
    },
    "sid": "FN866c64beb9...f5bf349fa19ad3"
  },
  "widgets": {
    "SetCallerNameVar": {
      "CallerName": "Joe Bloggs"
    },
    "GatherVoicemail": {
      "Called": "+4414....7",
      "Digits": "#",
      "RecordingUrl": "https://api.twilio.com/2010-04-01/Accounts/AC5fa2...12c7/Recordings/RE3a1d420de6db...2abb554c04f6",
      "CallerCountry": "GB",
      "Direction": "inbound",

[...]

I access the other (working) information through the ${event.variable} syntax. However, simply doing ${event.CallerName} results in "undefined". Can anyone advise how to access the CallerName variable that I have set in my flow?

If I was calling the function rather than using a transcription callback, it would be easy to pass the parameter, but doing so would result in duplicate emails per call.

I hope this makes sense and appreciate any advice.

Thank you

1 Answers

Twilio developer evangelist here.

The issue here is that your transcription callback does not have the same context as the Studio Flow, so does not come with all the other data. You can, however, add that context to the request by setting query parameters on the transcription callback URL.

Try setting your transcription callback URL to:

https://your-function-service.twil.io/?CallerName={{flow.variables.CallerName}}

You will then receive the CallerName in the event object.

enter image description here

Just to note, the Transcription Callback URL field does not highlight the liquid variable, but it does get interpolated. There is now an open issue to add the highlighting to this field.

Related