Skip to content

CHI-3768, CHI-3773: Fix Aselo webchat participant names#4115

Open
stephenhand wants to merge 10 commits intoCHI-3641-channel_type_convo_attributefrom
CHI-3640-fix_aselo_webchat_participant_names
Open

CHI-3768, CHI-3773: Fix Aselo webchat participant names#4115
stephenhand wants to merge 10 commits intoCHI-3641-channel_type_convo_attributefrom
CHI-3640-fix_aselo_webchat_participant_names

Conversation

@stephenhand
Copy link
Copy Markdown
Collaborator

@stephenhand stephenhand commented Mar 27, 2026

Description

The logic for the names of message senders is that

Messages from the service user are labelled 'You' (translatable & overridable via helpline)
Messages from others with a conversation participant are labelled 'Counsellor' (translatable & overridable via helpline)
Messages from anywhere else (will be automated) use the message author

Unit tests for MessageBubble have been updated to reflect this new behaviour:

  • Mock state now includes translations and defaultLocale in the config so the localization selectors work correctly in tests
  • Test assertions updated to check for translated values ('You', 'Counsellor') rather than user friendly names
  • Also fixed a bug where the screen reader text was rendering raw i18n keys instead of translated values

createConversation in the Lambda layer has been made more robust:

  • The initial client.conversations.v1.conversations.create() call is now inside its own try/catch, ensuring that any failure at that stage is returned as a Result error (with no conversationSid) rather than causing an unhandled throw. A second try/catch continues to wrap all subsequent setup steps (returning the conversationSid in the error when it was created but setup failed).
  • Fixed typo in variable name: createConverationResultcreateConversationResult in customChannelToFlex.ts

sessionDataHandler.ts has been made more resilient for non-English locales:

  • The CustomerFriendlyName fallback now detects when localizeKey returns the raw i18n key unchanged (meaning the key is absent from the current locale's translations) and substitutes the hardcoded default 'Anonymous' instead of sending a raw key string as the conversation friendly name

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

See tickets

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@stephenhand stephenhand changed the base branch from master to CHI-3641-channel_type_convo_attribute March 27, 2026 16:56
@stephenhand
Copy link
Copy Markdown
Collaborator Author

@copilot Fix the unit tests that are failing due to the code changes in this PR

Copilot AI and others added 2 commits March 27, 2026 18:03
- Use localizeKey directly in MessageBubble.tsx instead of LocalizedTemplate component
  to get translated name for both visual text and screen reader text
- Fix screen reader text to use translated name (was showing raw i18n key)
- Fix null guard: use message.author || '' to prevent Mustache.render error
- Update MessageBubble.test.tsx: add translations/defaultLocale to mock state,
  update assertions to check for 'You'/'Counsellor' instead of user friendly names

Agent-Logs-Url: https://github.com/techmatters/flex-plugins/sessions/783c2c53-643e-4714-9a8b-bb1fe99abd53

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

Copilot AI commented Mar 27, 2026

@copilot Fix the unit tests that are failing due to the code changes in this PR

Fixed in commit 068b329. The tests were failing because MessageBubble.tsx was using LocalizedTemplate (which calls useSelector(selectCurrentTranslations)) but the test mock state had no translations in config.

Changes made:

  1. MessageBubble.tsx: Replaced LocalizedTemplate with direct localizeKey usage — selects currentTranslations via useSelector, computes translatedName, and uses it consistently for both the visible text and screen reader text (also fixing a bug where the screen reader was showing raw i18n keys instead of translated values). Added || '' fallback for message.author to guard against undefined.

  2. MessageBubble.test.tsx: Added translations and defaultLocale to the mock config state; updated the 'renders the message author' assertion to check for 'You' and the screenreader test for other users to check for 'Counsellor sent at'.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /opt/hostedtoolcache/node/20.20.1/x64/bin/node node dist/index.js --exec install (dns block)
  • tsock.us1.twilio.com
    • Triggering command: /opt/hostedtoolcache/node/20.20.1/x64/bin/node node node_modules/.bin/jest --watchAll=false (dns block)
    • Triggering command: /opt/hostedtoolcache/node/20.20.1/x64/bin/node node node_modules/.bin/jest --watchAll=false /home/REDACTED/work/flex-plugins/flex-plugins/aselo-webchat-react-app/src/store/actions/actionTypes.ts (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@stephenhand stephenhand requested review from Copilot and gpaoloni and removed request for gpaoloni March 31, 2026 15:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates how participant/sender names are determined and displayed in Aselo webchat (and related channel integrations), aiming to consistently label messages as “You”, “Counsellor”, or fall back to the author for automated/system messages.

Changes:

  • Adds localized sender-name behavior in MessageBubble (“You” / “Counsellor” / author fallback) and fixes screen-reader text to use translated values.
  • Updates conversation creation to return a Result type and sets Twilio Conversation User friendlyName to senderScreenName.
  • Extends AS webchat pre-engagement form to collect friendlyName, adds a localized default name (“Anonymous”), and improves local-dev form definitions loading.

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
lambdas/packages/hrm-form-definitions/form-definitions/as/v1/webchat/PreEngagementForm.json Adds required friendlyName input field to capture user nickname.
lambdas/account-scoped/src/conversation/createConversation.ts Returns Result, sets Twilio user friendlyName, and refactors error handling.
lambdas/account-scoped/src/webchatAuthentication/initWebchat.ts Adapts orchestration to Result-returning createConversation.
lambdas/account-scoped/src/customChannels/customChannelToFlex.ts Adapts to Result from createConversation and updates conversation removal call.
lambdas/account-scoped/src/customChannels/{modica,line,instagram}/*ToFlex.ts Adjusts senderScreenName to align with new naming expectations.
lambdas/account-scoped/tests/unit/webchatAuthentication/initWebchat.test.ts Updates mocks/assertions for Result-based createConversation behavior.
lambdas/account-scoped/tests/unit/customChannels/{telegram,line,modica}/*ToFlex.test.ts Extends Twilio client mocks for newly required users.get().update() call path.
aselo-webchat-react-app/src/components/MessageBubble.tsx Implements translated sender labels and screen-reader fix; changes sender selection logic.
aselo-webchat-react-app/src/components/tests/MessageBubble.test.tsx Updates tests to assert translated sender labels (“You” / “Counsellor”).
aselo-webchat-react-app/src/sessionDataHandler.ts Uses localized default customer name key instead of hardcoded string.
aselo-webchat-react-app/translationsSrc/en.json Adds new translation keys for sender labels and default customer name.
aselo-webchat-react-app/src/services/configService.ts Allows overriding form-definitions base URL via REACT_APP_FORM_DEFINITIONS_BASE_URL.
aselo-webchat-react-app/package.json Enhances local dev script to serve form definitions via a local server.
aselo-webchat-react-app/package-lock.json Updates lockfile to reflect dependency changes.
Files not reviewed (1)
  • aselo-webchat-react-app/package-lock.json: Language not supported

Comment on lines 70 to +78
try {
const conversationContext =
client.conversations.v1.conversations.get(conversationSid);
await conversationContext.participants.create({
identity: uniqueUserName,
});
await client.conversations.v1.users
.get(uniqueUserName)
.update({ friendlyName: senderScreenName });
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

The try/catch only wraps operations starting from conversationContext creation, but the initial client.conversations.v1.conversations.create(...) happens before the try. If that call fails, createConversation will still throw/reject even though its signature now returns a Result, and callers only checking isErr(...) will miss it.

Move the conversation creation into the try/catch (and return a newErr(...) with conversationSid omitted when it was never created).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Fixed in commit bd74e45. Split the single try/catch into two: the first wraps conversations.create() and returns newErr({ cause }) with no conversationSid (since none was created), and the second wraps all subsequent setup and returns newErr({ conversationSid, cause }) as before.

Comment on lines 128 to +133
if (!conversationSid) {
const { conversationSid: newConversationSid, error } = await createConversation(
client,
{
studioFlowSid,
channelType,
twilioNumber,
uniqueUserName,
senderScreenName,
onMessageAddedWebhookUrl,
conversationFriendlyName,
testSessionId,
},
);
const createConverationResult = await createConversation(client, {
studioFlowSid,
channelType,
twilioNumber,
uniqueUserName,
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

Typo in the new variable name: createConverationResult is missing an "s" (should be createConversationResult). This makes the code harder to read/search and can propagate to other call sites via copy/paste.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on #4115 (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.

Fixed in commit 9eda176. Renamed createConverationResultcreateConversationResult throughout customChannelToFlex.ts.

} else {
name = message.author || '';
}
const translatedName = localizeKey(currentTranslations)(name);
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

This introduces new i18n keys (MessagePhase-MessageBubble-OwnMessageSenderName / ...OtherParticipant...) and unconditionally runs them through localizeKey(currentTranslations). Only translationsSrc/en.json defines these keys right now; es.json, fr.json, mt.json, etc. don’t, so users on those locales will see the raw key strings rendered in the UI.

Add these keys to the other locale files (even if temporarily untranslated) or implement a fallback to defaultLocale/English when a key is missing from the current locale.

Suggested change
const translatedName = localizeKey(currentTranslations)(name);
const translated = localizeKey(currentTranslations)(name);
const translatedName = translated && translated !== name ? translated : message.author || '';

Copilot uses AI. Check for mistakes.
Comment on lines +193 to 199
const { config } = store.getState();
const payload: InitWebchatAPIPayload = {
DeploymentKey: this.getDeploymentKey(),
CustomerFriendlyName: (formData?.friendlyName as string) || CUSTOMER_DEFAULT_NAME,
CustomerFriendlyName:
(formData?.friendlyName as string) ||
localizeKey(config.translations[config.currentLocale ?? config.defaultLocale])(CUSTOMER_DEFAULT_NAME_KEY),
PreEngagementData: JSON.stringify(formData),
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

CustomerFriendlyName falls back to a localized key lookup, but Conversation-Participants-CustomerDefaultName is only present in translationsSrc/en.json right now. For other locales (or for configs/tests where translations is empty), localizeKey(...) will return the raw key string, which then becomes the conversation friendly name.

Either add this key to all locale translation files (even as an English placeholder), or add a safer fallback (e.g., if the lookup returns the key unchanged, use a hardcoded default like "Anonymous").

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Fixed in commit 9eda176. sessionDataHandler.ts now compares the localizeKey result against the raw key — if they're equal (key not found in translations), it falls back to the hardcoded 'Anonymous' string instead of passing the raw key as the friendly name.

stephenhand and others added 2 commits April 1, 2026 08:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… Result

The initial `client.conversations.v1.conversations.create()` call was outside the
try/catch, causing createConversation to throw instead of returning a newErr Result
when that call failed. Split into two try/catch blocks: the first wraps the initial
conversation creation (returning newErr without a conversationSid on failure), and
the second wraps all subsequent setup (returning newErr with the conversationSid).

Agent-Logs-Url: https://github.com/techmatters/flex-plugins/sessions/6db22729-5826-4470-9436-24b2a825ee89

Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
…ssionDataHandler.ts

- Fix typo: createConverationResult -> createConversationResult in customChannelToFlex.ts
- Add safe fallback in sessionDataHandler.ts: if localizeKey returns the raw key
  string unchanged (meaning the key is not in the current locale translations),
  fall back to the hardcoded 'Anonymous' default instead of using the raw key

Agent-Logs-Url: https://github.com/techmatters/flex-plugins/sessions/7bddef15-9291-4150-b998-7d199b6e58ae

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

Copilot AI commented Apr 1, 2026

@copilot Fix the unit tests that are failing due to the code changes in this PR

Unit tests are passing — all 321 tests in aselo-webchat-react-app pass and CI is green on the latest commits. The MessageBubble test failures were fixed previously in commit 068b329.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • tsock.us1.twilio.com
    • Triggering command: /opt/hostedtoolcache/node/20.20.1/x64/bin/node node /home/REDACTED/work/flex-plugins/flex-plugins/aselo-webchat-react-app/node_modules/.bin/jest (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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