Fetching previous survey responses

The Mindful Feedback service provides the get-survey-response function to retrieve data about a specified survey interaction. A Twilio Studio Flow can use this function to access a previous survey interaction to make routing decisions or perform other actions based on a survey response.

To fetch previous survey responses, add a Run Function block into your Twilio Studio Flow, configured as shown below:Screen capture of Run Function page

  • Service: Select Mindful Feedback.
  • Environment: Select survey-dynamix-environment.
  • Function: Select /get-survey-response.
  • Function Parameters: Add as many search parameters as needed to filter survey responses. For more information on the available function parameters, see the Function Input (Parameters) section of this guide.

Function Input (Parameters)

The get-survey-response function accepts the following parameters:

ParameterDescriptionValid values
searchKey(Required) Specifies the survey interaction field to search, such as the email or Interaction ID
  • email
  • phone_number
  • external_ref
  • interaction_id
searchValue(Required) Sets a value for the searchKey (the value to search for within the specified field)Any valid value that corresponds to the searchKey being used
question_label(Optional) If specified, only the response to the specified question will be returned. If not specified, all question responses will be returned.Any question label for a survey interaction that might be returned by the search
survey_id(Optional) If specified, only the survey interactions with the specified survey ID will be returned.Any valid survey ID
Note:

The search will return the most recent survey interaction matching the search criteria, based on the survey's scheduled_at time. In addition to the search criteria provided by the function parameters, the search results will be limited to interactions that were completed, ended, and provided with responses (all three conditions must be met).

Function Output

The get-survey-response function returns data related to the most recent survey interaction matching the search criteria.

If a question_label parameter is provided in the search criteria, then the function will only return the response for that question (for example: "Resolution" : 3). Otherwise, the following keys will be returned, depending on the types of questions in the survey interaction:

When question type is...KeyDescription
NumbernumberResponseMaxThe highest response across all number questions
NumbernumberResponseMinThe lowest response across all number questions
NumbernumberResponseAvgThe average response for all number questions
NumbernumberResponseCountThe number of responses to all number questions
NumbernumberResponseTotalThe sum of responses for all number questions
NPSnpsResponseMaxThe highest response across all NPS questions
NPSnpsResponseMinThe lowest response across all NPS questions
NPSnpsResponseAvgThe average response for all NPS questions
NPSnpsResponseCountThe number of responses to all NPS questions
NPSnpsResponseTotalThe sum of responses for all NPS questions
AnyresponseDateThe date of the survey interaction
AnydaysSinceResponseThe number of days since the date of the survey interaction
Anyinteraction_idThe survey interaction ID
Anyinteraction_uuidThe survey interaction UUID
Anycall_typeThe value of the Call Type attribute for the survey interaction
Anyagent_idThe value of the Mindful Feedback Agent ID attribute for the survey interaction
Any, for each questionquestion_label
  • The response for each question in the survey interaction
  • For example, if there is a question with a label of "Knowledge" and a response of 4, then "Knowledge" : "4" will be returned.
Any, with custom data presentcustom data attribute name
  • Any custom attributes of the survey interaction will be returned in key-value pairs.
  • For example, if the survey interaction has an attribute named "CustomerName" with a value of "John", then "CustomerName" : "John" will be returned.

Using Function Output

You can use standard Twilio Studio notation to access the values returned by the function. For example, using an execution block named GetPrevSurveys, you could access the numberResponseAvg value with {{widgets.GetPrevSurveys.parsed.numberResponseAvg}}.

Example

The following example shows a Text to say value in a Play block referring to several returned values:

Hi {{widgets.GetPrevSurveys.parsed.CustomerName}}, you completed a survey {{widgets.GetPrevSurveys.parsed.daysSinceResponse}} days ago.
You gave us a score of {{widgets.GetPrevSurveys.parsed.NPS}} out of 10 for N. P. S.
You have us an average score of {{widgets.GetPrevSurveys.parsed.numberResponseAvg}} out of 5 for the Satisfaction and Helpfulness questions.
You gave us the following feedback: {{widgets.GetPrevSurveys.parsed.Feedback}}