twiliotranslationivrtwilio-studio

Twilio IVR flow with translations


I am trying to add multiple languages to my studio flow. 1 - English, 2 - Spanish, 3 - French.

When the user selects the language I am saving the selected lang in {{flow.variables.lang}}. Based on the selected lang, I then load the respective translations.

I have multiple strings which use values set in the previous widget. I am not understanding how to set these values dynamically.

For Example:

String: "Welcome to Studio flow, we found your information in our system with zip code {{widgets.User_Information.parsed.zipCode}}"

In the translation file, I have this string set to key "User_Zip_Code".

In the widget "Gather Input on call" I added {{widgets.Translation_Function.parsed.User_Zip_Code}} in the text to say field. But when the voice reads it out, I expected Twilio would parse the and insert the dynamic value, but it just read it out as is. Is there a way to dynamically insert these flow variables in the string dynamically?

One way I could think of is to call a function and have that function return the string after replacing the values, but for some reason, there are a lot of gaps that I am seeing when the flow moves from one function to another, so I am trying to avoid function calls.

EDIT:

Adding the data shown in the Widget & Flow Properties

 "User_Information": {
      "status_code": 200,
      "content_type": "application/json",
      "parsed": {
        "zipCode": 201010
      },
}
    "Translation_Function": {
      "status_code": 200,
      "content_type": "application/json",
      "parsed": {
          "User_Zip_Code": "Welcome to Studio flow, we found your information in our system with zip code {{widgets.User_Information.parsed.zipCode}}. Press pound to continue.”
    },
}

Thanks in advance


Solution

  • It should work as you explained. Are you sure the reference in the liquid syntax is indeed correct, for example: {{widgets.User_Information.parsed.zipCode}} ?

    Try looking at the Studio Flow Execution Logs (under Logs) to see the path you must refer to in the liquid syntax is correct/

    enter image description here

    Update:

    It appears you are nesting Liquid Syntax expressions. What I mean by that is your Gather Input on Call Widget is referencing parsed JSON from an earlier Widget and that JSON has a liquid syntax expression in it.

    Example JSON:

    "FT_Fee_Information": "We found your account in our XX payment system. As a reminder, payments processed through this system are subject to a $x.xx convenience fee. Payments without a fee can be made through the My Account portal on our website at example.com. If you would like to use the stored payment information to make a payment on account ending in {{widgets.Validate_Number.parsed.accountNumber}}. Please enter the 5 digit zip code associated with this account. If you would like to pay on a different account press the pound key.

    I am pretty sure that is the reason for your issue, you can't nest these liquid syntax expression. Instead, can you pass in the Studio data to the Function calling the JSON so that Function can pre-populate this information (static data) into JSON (instead of using a liquid expression) before returning the JSON blob to Studio?