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:
- 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:
Parameter | Description | Valid values |
---|---|---|
searchKey | (Required) Specifies the survey interaction field to search, such as the email or 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 |
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... | Key | Description |
---|---|---|
Number | numberResponseMax | The highest response across all number questions |
Number | numberResponseMin | The lowest response across all number questions |
Number | numberResponseAvg | The average response for all number questions |
Number | numberResponseCount | The number of responses to all number questions |
Number | numberResponseTotal | The sum of responses for all number questions |
NPS | npsResponseMax | The highest response across all NPS questions |
NPS | npsResponseMin | The lowest response across all NPS questions |
NPS | npsResponseAvg | The average response for all NPS questions |
NPS | npsResponseCount | The number of responses to all NPS questions |
NPS | npsResponseTotal | The sum of responses for all NPS questions |
Any | responseDate | The date of the survey interaction |
Any | daysSinceResponse | The number of days since the date of the survey interaction |
Any | interaction_id | The survey interaction ID |
Any | interaction_uuid | The survey interaction UUID |
Any | call_type | The value of the Call Type attribute for the survey interaction |
Any | agent_id | The value of the Mindful Feedback Agent ID attribute for the survey interaction |
Any, for each question | question_label |
|
Any, with custom data present | custom data attribute name |
|
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}}