Repository navigation
CHI-4039: Chatbot post surveys record answers on every turn (3/5) - #4857
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A rejected recordPostSurveyAnswers promise can reach the handler’s outer catch and return HTTP 500, interrupting survey progression or cleanup; local rejection handling and a rejection-path test are needed.
1 open issue
What changed in this PR
Part 3 of CHI-4039 connects Aselo’s chatbot surveys to per-turn answer recording, preserving partial responses for post-chat and post-call SMS surveys.
Changes:
- Records cumulative answers after each survey message, before end-of-dialog cleanup.
- Removes end-only saving and reduces control-task lifetime from one hour to 15 minutes.
- Adds tests for per-turn recording, returned-error handling, and control-task cancellation.
Deployment requires HRM’s PATCH postSurveys/{taskId} endpoint.
| File | Description |
|---|---|
lambdas/account-scoped/tests/unit/channelCapture/chatbotCallback.test.ts |
Tests recording, cleanup ordering, returned errors, and non-survey exclusion. |
lambdas/account-scoped/tests/unit/channelCapture/channelCaptureHandlers.test.ts |
Tests control-task cancellation when a survey completes. |
lambdas/account-scoped/src/postSurvey/postSurveyControlTask.ts |
Reduces control-task lifetime to 15 minutes. |
lambdas/account-scoped/src/channelCapture/chatbotCallbackCleanup.ts |
Stops passing survey memory to channel release. |
lambdas/account-scoped/src/channelCapture/chatbotCallback.ts |
Records survey answers on every turn and logs returned errors. |
lambdas/account-scoped/src/channelCapture/channelCaptureHandlers.ts |
Removes end-only saving while retaining task cancellation. |
Review effort: Balanced
| const recordResult = await recordPostSurveyAnswers({ | ||
| accountSid, | ||
| controlTaskSid: capturedChannelAttributes.controlTaskSid, | ||
| answers: LexClient.getBotMemory({ lexResponse }), | ||
| }); | ||
| if (isErr(recordResult)) { | ||
| console.error( | ||
| `Failed to record post survey answers for control task ${capturedChannelAttributes.controlTaskSid}`, | ||
| recordResult.message, | ||
| ); | ||
| } |
stephenhand
left a comment
There was a problem hiding this comment.
I do wonder if we should continue to maintain these sorts of post surveys long term, or migrate to all post surveys being post studio flows. Not for this PR but I think it would make sense in the future to have our post survey approach consistent
7f4c694 to
a9c1bd9
Compare
Post survey chatbots (post-chat and post-call SMS) now record the answers after every helpseeker message instead of only when the bot finishes, so a survey left halfway keeps the answers given. Finishing the survey now only cancels the control task. Lower the post survey control task TTL from 1 hour to 15 minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a9c1bd9 to
8f88df6
Compare

Description
Stacked PRs for CHI-4039 (save partial post-survey answers). Review and merge in order:
Post survey chatbots (post-chat surveys and USNM's post-call SMS survey, which reuses the same Lex mechanism) now record the answers after every helpseeker message, using
recordPostSurveyAnswersfrom the previous PR. Previously they were only saved when Lex closed the dialog, so a helpseeker who left halfway lost everything.chatbotCallback: on every turn of a post survey bot, recordgetBotMemory(lexResponse)on the control task before handling the end of the dialog. A recording failure is logged and doesn't affect the conversation.handleChannelRelease: when the survey finishes it now only cancels the control task (the answers are already recorded).SKIP→SKIPPEDin USNM's slot types) are recorded like any other answer.Deploy only after HRM has the
PATCH postSurveys/{taskId}endpoint (see PR 2). Otherwise answers reach the task and Insights but not HRM. This PR doesn't depend on any twilio-iac apply.Note: Lex post survey sessions expire after 5–10 minutes idle today; PR 4 raises that to 15 minutes to match the control task. Until then, a helpseeker who pauses longer may be asked the questions again, but answers already recorded are not lost.
Checklist
Other Related Issues
None
Verification steps
On a staging helpline with
enable_post_survey(and HRM PATCH deployed):postSurveyAnswers+ Insights attributes); after 15 min the control task is canceled and appears in Insights with that answer.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