Skip to content

Migrate post survey messages out of serverless assets#4000

Merged
stephenhand merged 7 commits intomasterfrom
copilot/migrate-post-survey-messages
Mar 6, 2026
Merged

Migrate post survey messages out of serverless assets#4000
stephenhand merged 7 commits intomasterfrom
copilot/migrate-post-survey-messages

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

Post survey trigger messages were fetched at runtime from the serverless repo via HTTP. This migrates all those translations into this repo and replaces the HTTP fetch with a local lookup chain.

Description

Translation file structure

  • lambdas/account-scoped/src/translations/en.json — global English default (from serverless en-US/postSurveyMessages.json)
  • lambdas/account-scoped/src/translations/es.json — global Spanish (from serverless es/postSurveyMessages.json)
  • form-definitions/{helpline}/v1/customStrings/postSurveyMessages.json — helpline-specific overrides migrated from serverless locale folders where the second part of the locale matches the helpline code:
    • en-JMjm/v1/customStrings/postSurveyMessages.json
    • en-NZnz/v1/customStrings/postSurveyMessages.json
    • en-USCHusch/v1/customStrings/postSurveyMessages.json (pre-existing, same content)
    • en-USCRuscr/v1/customStrings/postSurveyMessages.json
    • en-ZAza/v1/customStrings/postSurveyMessages.json
    • es-CLcl/v1/customStrings/postSurveyMessages.json
    • es-CLHSclhs/v1/customStrings/postSurveyMessages.json (pre-existing, same content)
    • es-COco/v1/customStrings/postSurveyMessages.json
    • pt-BRbr/v1/customStrings/postSurveyMessages.json

Lookup logic (translations/translationLookup.ts)

Priority chain for a given key + taskLanguage:

  1. customStrings.postSurveyMessages[key] from helpline's form definitions
  2. translations/{taskLanguage}.json (e.g. en-US.json)
  3. translations/{language}.json (e.g. en.json)
  4. translations/en.json (hardcoded global default)
  5. Throw configuration error

Locale chain deduplicates (e.g. taskLanguage=en → only tries en once).

Other changes

  • DefinitionVersion.customStrings gains postSurveyMessages: Record<string, string> field; loadDefinition fetches customStrings/postSurveyMessages.json with {} as default
  • postSurveyListener.ts drops serverlessBaseUrl / getServerlessBaseUrl entirely; calls getTranslation(accountSid, taskLanguage, 'triggerMessage') instead
  • Translation lookup module lives at src/translations/translationLookup.ts with generic exports (TranslationMessages, getTranslation) so it can be reused beyond post surveys
  • Full unit test coverage for lookup logic including deduplication and error cases (tests at tests/unit/translations/translationLookup.test.ts)

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

  1. Deploy to a helpline with enable_post_survey: true
  2. Complete a chat task — confirm post survey trigger message is sent
  3. For a helpline with customStrings/postSurveyMessages.json (e.g. usch, jm, nz), verify the helpline-specific message takes priority
  4. For a Spanish-language task (es-CO), verify the co customStrings entry is used
  5. For a task with a language that has no locale-specific or helpline-specific file, verify the en.json global default is used

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

Original prompt

This section details on the original issue you should resolve

<issue_title>Migrate post survey messages out of serverless assets</issue_title>
<issue_description>## Description

We want to move the post survey message json configuration files out of https://github.com/techmatters/serverless/tree/master/assets/translations into this repo where they are used.

The es.json file should be added to the account-scoped lambda source under a new translations directory. The en-US.json file should be added here as en.json.

The other files should be added to the customStrings folder for the form definition configuration where the first part of the definition code matches the last part of the locale used in the folder name in serverless assets

The lookup logic for these strings in the lambda code should be updated to follow this logic:

  • First look up the key in customStrings for the helpline's form definitions, if an entry is present, use this
  • Otherwise infer the taskLanguage the same as now
  • If there is a file matching the full name of the task languages (with a .json extension) in the account-scoped translations directory, look for the key in that file, if it exists, use the translation on that key
  • Otherwise if there is a file matching the language portion of the task language (with a .json extension) in the account-scoped translations directory, look for the key in that file, if it exists, use the translation on that key
  • Otherwise if there is a file matching the global default language, which should be hardcoded to 'en' (with a .json extension) in the account-scoped translations directory, look for the key in that file, if it exists, use the translation on that key
  • Otherwise throw a configuration error

Keep this lookup logic in a separate module and ensure it is fully unit tested
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate post survey messages out of serverless assets Migrate post survey messages out of serverless assets Mar 4, 2026
Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

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

You still need to migrate the postSurveyMessages.json files other than es.json and en-US.json files into the customStrings folder for the form definition where the second part of the containing folder in serverless assets is the same as the first part of the name for the folder for the form definition set

For example en-JM goes into the customStrings in jm-v1

…ition customStrings

Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 5, 2026

You still need to migrate the postSurveyMessages.json files other than es.json and en-US.json files into the customStrings folder for the form definition where the second part of the containing folder...

Done in commit 860984a. Migrated all remaining postSurveyMessages.json files from serverless assets into customStrings for their corresponding form definition sets:

  • en-JMjm/v1/customStrings/postSurveyMessages.json
  • en-NZnz/v1/customStrings/postSurveyMessages.json
  • en-USCRuscr/v1/customStrings/postSurveyMessages.json
  • en-ZAza/v1/customStrings/postSurveyMessages.json
  • es-CLcl/v1/customStrings/postSurveyMessages.json
  • es-COco/v1/customStrings/postSurveyMessages.json
  • pt-BRbr/v1/customStrings/postSurveyMessages.json

The en-USCH and es-CLHS files already existed with the same content. The cf and ch serverless folders were skipped as there are no corresponding form definition sets.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This translation lookup will be used in places other than post surveys, give it a more generic name and move it to the translations directory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit fb655bf. Renamed postSurveyTranslationLookup.tstranslationLookup.ts and moved it to src/translations/. Also renamed the exported types/functions to be generic (PostSurveyMessagesTranslationMessages, getPostSurveyTranslationgetTranslation). The test file was moved to tests/unit/translations/translationLookup.test.ts accordingly.

…slations/translationLookup

Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Copy link
Collaborator

@stephenhand stephenhand left a comment

Choose a reason for hiding this comment

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

fix linter issues

Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

fix linter issues

Fixed in commit 66bf19e. Collapsed multi-line getTranslation(...) calls to single lines to satisfy the prettier rule in postSurveyListener.ts and translationLookup.test.ts.

…ages' into copilot/migrate-post-survey-messages
@stephenhand stephenhand marked this pull request as ready for review March 6, 2026 20:19
@stephenhand stephenhand merged commit 67d7e16 into master Mar 6, 2026
75 of 76 checks passed
@stephenhand stephenhand deleted the copilot/migrate-post-survey-messages branch March 6, 2026 20:19
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.

Migrate post survey messages out of serverless assets

2 participants