Skip to content

CHI-4039: Chatbot post surveys record answers on every turn (3/5) - #4857

Merged
gpaoloni merged 1 commit into
gian_CHI-4039-record-answersfrom
gian_CHI-4039-chatbot
Nov 19, 2026
Merged

gpaoloni merged 1 commit into
gian_CHI-4039-record-answersfrom
gian_CHI-4039-chatbot

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 (this PR) 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 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

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 recordPostSurveyAnswers from 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, record getBotMemory(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).
  • Control task TTL lowered from 1 hour to 15 minutes. An abandoned survey keeps its answers; the task just expires sooner.
  • Skipped questions (e.g. SKIP → SKIPPED in 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

  • 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

None

Verification steps

On a staging helpline with enable_post_survey (and HRM PATCH deployed):

  1. Webchat contact → counsellor wraps up → answer only the first post survey question, then close the chat.
  2. The answer is in HRM for the contact's post survey, and on the survey control task attributes (postSurveyAnswers + Insights attributes); after 15 min the control task is canceled and appears in Insights with that answer.
  3. Repeat answering every question: same result, the control task is canceled right after the last answer.
  4. Repeat without answering anything: no post survey in HRM, no survey attributes on the control task.
  5. USNM post-call SMS survey: answer some questions and stop; the answers are saved.

AFTER YOU MERGE

  1. Cut a release tag using the Github workflow. Wait for it to complete and notify in the #aselo-deploys Slack channel.
  2. Comment on the ticket with the release tag version AND any additional instructions required to configure an environment to test the changes.
  3. Only then move the ticket into the QA column in JIRA

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

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

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

Comment on lines +156 to +166
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 stephenhand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-chatbot branch 4 times, most recently from 7f4c694 to a9c1bd9 Compare November 18, 2026 19:41
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>
@gpaoloni
gpaoloni force-pushed the gian_CHI-4039-chatbot branch from a9c1bd9 to 8f88df6 Compare November 19, 2026 15:37
@gpaoloni
gpaoloni merged commit 22703b2 into master Nov 19, 2026
26 checks passed
@gpaoloni
gpaoloni deleted the gian_CHI-4039-chatbot 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