0

Brand new to Twilio.

I've implemented the Build Voice Mail with SMS and Email Notifications Using Twilio Studio, Functions, and SendGrid tutorial. This tutorial relies on an Environment Variable named TO_EMAIL_ADDRESS to hold a static email address that is used in the sgMail.send(msg) command. I'd like to be able to variably set the value of TO_EMAIL_ADDRESS based on digits collected by a Gather Input On Call Widget.

I'm currently using the output of "user pressed keys" as two Variables. For one of them, I'm running a basic If/Else to convert the Digit to a String. This string is used in a Say\Play Widget in the next step.

{%- if flow.variables.department_id == '1' -%}
Dept1
{%- elsif flow.variables.department_id == '2' -%} 
Dept2 
{%- elsif flow.variables.department_id == '3' -%} 
Dept3
{%- endif -%}

I'd like to set the desired email address in the same manner.

That If/Else could just as easily end up as If department_id == 1 then 'dept1@domain.com'...

Do I need to use that Environment Variable in this case? Could I just compute the correct email address in Studio and pass that as part of the Event when calling the Function?

The tutorial is great, and fit the use case. I feel like I'm missing some foundational knowledge though.

Thanks in Advance!

flabbergasted
  • 341
  • 3
  • 6

1 Answers1

1

Twilio developer evangelist here.

You can absolutely control the email that the recording transcription is sent to.

You have set a Transcription Callback URL in the Record Coicemail widget in your Studio Flow. That causes Twilio to make a request to your Function when the transcription is complete. The request includes all of the parameters listed in the documentation.

In order to choose an email address as part of the Studio Flow and then pass it on to the Function you will need to:

  • Make the email address choice with the Gather widget before making the recording
  • Set the email address or identifier as a variable in the Flow, as you described
  • Pass the email address or identifier to the Function as a URL parameter.

So, if your Function URL is https://ilovetwiliofunctions-1985.twil.io/fowardVMViaEmail.

Then, using your variable, you can update it to: https://ilovetwiliofunctions-1985.twil.io/fowardVMViaEmail?email={{flow.variables.email}}.

You will then be able to read the email from the event object in the Function as event.email and use it in place of the environment variable.

philnash
  • 70,667
  • 10
  • 60
  • 88