Repository navigation
CHI-4039: Record post survey answers as they are given (2/5) - #4856
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Overlapping requests can overwrite newer HRM answers with stale snapshots, while completion-only requests can finalize tasks without syncing previously stored answers to HRM.
2 open issues
What changed in this PR
Adds the Lambda-side foundation for saving partial post-survey answers in Aselo. This second PR in the CHI-4039 series prepares the service and Studio route; later PRs enable chatbot and voice callers, and HRM needs the new upsert endpoint.
Changes:
- Merge answers into control-task attributes, rebuild Insights data, and send accumulated answers to HRM.
- Add the Studio recording route and opt-in control-task creation without changing existing flow behavior by default.
- Add unit tests and route documentation.
| File | Description |
|---|---|
lambdas/account-scoped/tests/unit/studioFlow/postStudioFlowTaskRouterListener.test.ts |
Tests optional control-task creation and SID propagation. |
lambdas/account-scoped/tests/unit/postSurvey/recordPostSurveyAnswers.test.ts |
Tests recording, completion, and failure handling. |
lambdas/account-scoped/tests/unit/postSurvey/postSurveyAnswers.test.ts |
Tests answer merging and Insights rebuilding. |
lambdas/account-scoped/STUDIO_ROUTES.md |
Documents the new recording route. |
lambdas/account-scoped/src/studioFlow/postStudioFlowTaskRouterListener.ts |
Creates optional control tasks before starting flows. |
lambdas/account-scoped/src/router.ts |
Registers the recording endpoint. |
lambdas/account-scoped/src/postSurvey/recordPostSurveyAnswers.ts |
Implements incremental persistence and completion handling. |
lambdas/account-scoped/src/postSurvey/postSurveyControlTask.ts |
Adds control-task creation and cancellation helpers. |
lambdas/account-scoped/src/postSurvey/postSurveyAnswers.ts |
Adds answer filtering, merging, and Insights helpers. |
lambdas/account-scoped/src/configuration/aseloConfiguration.ts |
Adds the optional createSurveyControlTask setting. |
Review effort: Balanced
| const hrmResult = await patchOnInternalHrmEndpoint( | ||
| accountSid, | ||
| hrmApiVersion, | ||
| `postSurveys/${controlTaskSid}`, | ||
| hrmPatch, |
| if (!Object.keys(answeredQuestions(answers)).length) { | ||
| console.debug(`${logPrefix} No answered questions, nothing to record.`); | ||
| return newOk({ recorded: false }); |
stephenhand
left a comment
There was a problem hiding this comment.
Does the copilot have a point about overlapping answers? Probably an unlikely scenario right, the studio flow effectively serialises the requests?
| if (targetParticipants.length === 1) { | ||
| const [participant] = targetParticipants; | ||
| try { | ||
| const controlTaskSid = await createSurveyControlTaskIfConfigured({ |
There was a problem hiding this comment.
Any reason why this has to be created now, instead of as a HTTP call in the first step in the studio flow?
There was a problem hiding this comment.
No not real reason other than just looking for consistency in the behavior and taking out complexity for the studio flow.
There was a problem hiding this comment.
I think we should consider the current chat based studio flows as legacy in the long term, it makes no sense that we keep the hardcoded ones long term if we can also implement them in studio flows. For that reason I'd consider keeping hardcoded studio flow behaviour out of the system to be more of a priority
There was a problem hiding this comment.
Also, I think you already explained this, but could you speak to why we can't create the task just in time when we record the first answer? We wouldn't need to bake studio flow specific stuff into task routers and the post studio flow system OR have an extra step in the studio flow then
4b6bbcc to
5cfabdc
Compare
Add recordPostSurveyAnswers, which stores the answered questions on the post survey control task (raw answers plus their Insights attributes) and upserts the post survey in HRM with all the answers so far. Blank surveys record nothing. Expose it to Studio as postSurvey/recordAnswers, and create the control task before triggering a post studio flow whose configuration sets createSurveyControlTask, passing its SID to the flow. Flows without the flag keep working as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the post studio flow TaskRouter listener unaware of what the flow it triggers does: instead of creating the control task there (behind the createSurveyControlTask flag), expose postSurvey/createControlTask so a post survey flow creates it as its first step and passes the returned controlTaskSid to postSurvey/recordAnswers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The post studio flow listener now sends the task language (or the helpline language, or en-US) to the flow it triggers: as taskLanguage on the inProgressCall redirect, and as the taskLanguage execution parameter for rest flows, which used to get an empty string when the task had none. postSurvey/createControlTask accepts it as an optional language, stored on the control task like the chatbot post survey does. getTaskLanguage moves to task/taskLanguage.ts so both listeners share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5cfabdc to
2cd0acf
Compare


Description
Stacked PRs for CHI-4039 (save partial post-survey answers). Review and merge in order:
Adds the mechanism to save post survey answers as they are given, instead of only when the survey ends, so a helpseeker who answers only some questions (or hangs up / leaves) still has those answers saved.
recordPostSurveyAnswers(newpostSurvey/recordPostSurveyAnswers.ts) runs after every answer:postSurveyAnswersattribute). Empty answers never overwrite a recorded one.patchTaskAttributes(ETag retries).PATCH postSurveys/{controlTaskSid}), so a failed patch is repaired by the next answer.When the survey finishes the control task is canceled; if it's abandoned, the task expires. Either way the answers are already persisted, so no end-of-survey save is needed.
Voice (Studio) support:
postSurvey/recordAnswers({ controlTaskSid, answers, surveyComplete? }), documented inSTUDIO_ROUTES.md.surveyComplete: truecancels the control task.postSurvey/createControlTask({ contactTaskSid, contactId, language? }→{ controlTaskSid }), also inSTUDIO_ROUTES.md. A post survey flow calls it as its first widget, before any question, and sends the returnedcontrolTaskSidto everypostSurvey/recordAnswerscall.postStudioFlowTaskRouterListener.ts) does not create the control task: it only triggers the configured flow and stays unaware of what that flow does (post surveys are one of its uses). The flow owns its control task.language, else the helpline'shelplineLanguage, elseen-US(same rule as the chat post survey;getTaskLanguagemoved totask/taskLanguage.tsand is shared). It arrives as{{trigger.call.taskLanguage}}(inProgressCall) or{{flow.data.taskLanguage}}(rest). Forrestflows this replaces the previous empty string when the task had no language; USNM's only use (startPostSurveyChatbot) already fell back to the same languages.Deploying this doesn't affect current flows: nothing calls the new routes until the flows in PR 4 are applied.
This PR is not used by anything yet: chatbots switch in PR 3, voice flows in PR 4.
taskIdis the post survey control task SID;(accountId, taskId)identifies one post survey.data(we always send every answer recorded so far) and bumpsupdatedAt.200with the saved post survey;400ifcontactTaskIdis missing when creating; other failures non-2xx (the lambda retries 3 times).POST postSurveysmust stay until PR 5 ships.Checklist
Other Related Issues
HRM: needs the
PATCH postSurveys/{taskId}upsert described above.Verification steps
npm run test:unitinlambdas/.hrm/savePostSurvey) until PR 4's flows are applied.AFTER YOU MERGE
You are responsible for ensuring the above steps are completed. If you move a ticket into QA without advising what version to test, the QA team will assume the latest tag has the changes. If it does not, the following confusion is on you! :-P
🤖 Generated with Claude Code