Skip to content

CHI-4039: Voice post surveys record each answer, Lex idle TTL to 15 min (4/5) - #4858

Merged
gpaoloni merged 6 commits into
gian_CHI-4039-chatbotfrom
gian_CHI-4039-voice-flows
Nov 19, 2026
Merged

gpaoloni merged 6 commits into
gian_CHI-4039-chatbotfrom
gian_CHI-4039-voice-flows

Conversation

@gpaoloni

@gpaoloni gpaoloni commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Stacked PRs for CHI-4039 (save partial post-survey answers). Review and merge in order:

  1. CHI-4039: Extract post survey helpers (1/5) #4855 Refactor: extract the post survey helpers
  2. CHI-4039: Record post survey answers as they are given (2/5) #4856 Record post survey answers as they are given (lambda service + Studio route)
  3. CHI-4039: Chatbot post surveys record answers on every turn (3/5) #4857 Chatbot post surveys record answers on every turn
  4. CHI-4039: Voice post surveys record each answer, Lex idle TTL to 15 min (4/5) #4858 (this PR) twilio-iac: voice flows create their control task and record each answer, Lex idle TTL
  5. CHI-4039: Remove end-of-survey post survey save endpoints (5/5) #4859 Remove the end-of-survey save endpoints

Configuration for partial post-survey saving on voice IVR surveys, plus the Lex session TTL change. No application code.

  • Voice flows create their own control task first: a new first widget f_createControlTask (postSurvey/createControlTask, sending the contact's {{trigger.call.taskLanguage}} so it's stored on the control task) runs right after the trigger, before any prompt, and every later call reads {{widgets.f_createControlTask.parsed.controlTaskSid}}. Both success and failed continue to the survey: if the task can't be created the caller still hears the survey, but the answers aren't recorded. In USNC this runs before the opt-in question, so a caller who opts out leaves an empty control task that saves nothing and expires after 15 minutes.
  • Voice flows record each answer as it is given, through postSurvey/recordAnswers widgets (f_recordAnswers_*), instead of one hrm/savePostSurvey call at the end. The last call sends surveyComplete: true. Both success and failed continue the survey, so a failure never cuts it short.
    • USNC staging + production (usnc/templates/studio-flows/post-call-survey.tftpl): one widget after each answer (including the "unrecognized or no input" values it already recorded). Same question keys as before.
    • CA staging (ca/templates/studio-flows/khp-english-post-call-survey.tftpl): each valid answer is recorded right after its split. Same e_*_Main_v1 keys as on master. The "too many invalid answers" paths that used to jump to the save now send surveyComplete: true and play the thank-you message. Only valid answers are recorded now (before, the end save also sent invalid digits).
  • Lex post_survey bots: idle_session_ttl_in_seconds → 900 in all 12 bot configs, matching the new 15-minute control task, so a helpseeker who pauses isn't asked the questions again.
  • twilio-iac/AGENTS.md post-survey checklist updated for the new mechanism.

No service configuration change is needed: applying the new flows is what switches the behaviour.

as development: its post-call survey Studio flow isn't managed in this repo, so it has to be updated in the Twilio console the same way (f_createControlTask first, then f_recordAnswers_* widgets).

Checklist

  • Corresponding issue has been opened
  • New tests added
  • Feature flags added
  • Strings are localized
  • Tested for chat contacts
  • Tested for call contacts

Other Related Issues

Existing CA flow issues found while editing, not fixed here:

  • Every retry_counter_N checks flow.variables.retry_counter, which doesn't exist, so the counter is always 1 and the "repeated invalid answers" exits are never reached.
  • On every split the less_than condition comes before equal_to 0, so pressing 0 ("hear the options again") is probably taken as an answer.
  • split_2 uses * instead of 0 to repeat.

USNC: the split_end_interaction_response conditions' arguments reference gather_input_voice_beginning_interaction.Digits while the split's input is the end_interaction digits. Probably cosmetic (Studio evaluates input), not changed here.

Verification steps

Both edited flows were validated: interpolations stubbed and parsed as JSON, every widget body parses, all next targets exist, no unreachable widgets. All edited JSON parses.

Per environment, after applying (see order below): make a test call, answer only some questions and hang up, then check the answers in HRM and on the control task, and in Datadog that f_createControlTask and the f_recordAnswers_* widgets returned success.

AFTER YOU MERGE

Apply order, per environment (USNC staging, USNC production, CA staging, AS development):

  1. Lambdas from PRs 2–3 deployed, and HRM PATCH postSurveys/{taskId} deployed.
  2. configure apply (the Studio flows). Don't apply it before step 1: the new flows call postSurvey/createControlTask and postSurvey/recordAnswers.
  3. lex apply for every helpline with a post_survey bot (as, cl, clhs, nzba, ukmh, usch, usnc, usnm, and helplines using the shared configs/lex_v2/en). Independent of 1–2.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

AS development routing prevents creation of the new survey control tasks and blocks answer recording, while non-cumulative payloads can permanently lose earlier answers after failed writes.

2 open issues
What changed in this PR

This fourth PR in CHI-4039 configures voice surveys to save answers incrementally using the preceding Lambda changes, preserving responses when callers leave early.

Changes:

  • Replace end-only saves with per-answer recording in USNC and CA voice flows.
  • Enable survey control-task creation for selected environments and update deployment guidance.
  • Set all 12 Lex post-survey idle timeouts to 15 minutes.
File Description
twilio-iac/​helplines/​usnm/​configs/​lex_v2/​es/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​usnm/​configs/​lex_v2/​en/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​usnc/​templates/​studio-flows/​post-call-survey.tftpl Record each answer and signal survey completion.
twilio-iac/​helplines/​usnc/​configs/​service-configuration/​staging.json Enable survey control-task creation.
twilio-iac/​helplines/​usnc/​configs/​service-configuration/​production.json Enable survey control-task creation.
twilio-iac/​helplines/​usnc/​configs/​lex_v2/​en_USNC/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​usch/​configs/​lex_v2/​en_USCH/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​usch/​configs/​lex_v2/​ch/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​usch/​configs/​lex_v2/​cf/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​ukmh/​configs/​lex_v2/​en_GB/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​nzba/​configs/​lex_v2/​en_NZBA/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​configs/​lex_v2/​en/​bots/​post_survey.json Update the shared bot's idle timeout.
twilio-iac/​helplines/​clhs/​configs/​lex_v2/​es_CLHS/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​cl/​configs/​lex_v2/​es_CL/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​helplines/​ca/​templates/​studio-flows/​khp-english-post-call-survey.tftpl Record accepted answers and complete normal or early exits.
twilio-iac/​helplines/​ca/​configs/​service-configuration/​staging.json Enable survey control-task creation.
twilio-iac/​helplines/​as/​configs/​service-configuration/​development.json Enable control tasks; disable Lambda conference ending.
twilio-iac/​helplines/​as/​configs/​lex_v2/​en_US/​bots/​post_survey.json Set idle timeout to 900 seconds.
twilio-iac/​AGENTS.md Document per-answer recording and deployment prerequisites.

Review effort: Balanced

"enforceZeroTranscriptRetention": false,
"postStudioFlows": {
"WQb4a3a7e8808c61d11d344e5b28fa53ef": {
"createSurveyControlTask": true,
"method": "POST",
"content_type": "application/json;charset=utf-8",
"add_twilio_auth": false,
"body": "{\n \"controlTaskSid\": \"{{trigger.call.controlTaskSid}}\",\n \"answers\": {\n \"beginning_interaction\": \"{{flow.variables.beginning_interaction}}\"\n },\n \"surveyComplete\": false\n}",
@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-voice-flows branch from d3eb8b4 to 13ff41f Compare November 17, 2026 15:25
@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-voice-flows branch from 13ff41f to e739df4 Compare November 18, 2026 16:37
@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-voice-flows branch from e739df4 to 0601ca0 Compare November 18, 2026 19:20
@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-voice-flows branch from 0601ca0 to 16723ba Compare November 18, 2026 19:44
gpaoloni and others added 6 commits November 19, 2026 12:37
Matches the 15 minute lifetime of the post survey control task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the final hrm/savePostSurvey call with a postSurvey/recordAnswers
call after each question, so answers survive a hang up mid-survey. The last
question also sends surveyComplete. Failures continue to the next question.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iven

Replace the final hrm/savePostSurvey call with a postSurvey/recordAnswers
call after each valid answer, keeping the same question keys. The last
question, and the paths that used to save after repeated invalid answers,
send surveyComplete. Failures continue the survey; the closing message is
the thank-you message, since earlier answers are already recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…recording

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
USNC and KHP English post-call survey flows call postSurvey/createControlTask
as their first widget and pass its controlTaskSid to every recordAnswers call,
instead of relying on the post studio flow listener to create the task behind
the createSurveyControlTask service configuration flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ontrol task

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-voice-flows branch from 16723ba to 0216dbd Compare November 19, 2026 15:37
@gpaoloni
gpaoloni merged commit 22703b2 into master Nov 19, 2026
48 of 49 checks passed
@gpaoloni
gpaoloni deleted the gian_CHI-4039-voice-flows branch November 19, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants