CHI-3768, CHI-3773: Fix Aselo webchat participant names#4115
CHI-3768, CHI-3773: Fix Aselo webchat participant names#4115stephenhand wants to merge 10 commits intoCHI-3641-channel_type_convo_attributefrom
Conversation
…x_aselo_webchat_participant_names
…x_aselo_webchat_participant_names
|
@copilot Fix the unit tests that are failing due to the code changes in this PR |
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>
- 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>
Fixed in commit 068b329. The tests were failing because Changes made:
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:
If you need me to access, download, or install something from one of these locations, you can either:
|
…x_aselo_webchat_participant_names
…. createConversation now uses Result type
There was a problem hiding this comment.
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
Resulttype and sets Twilio Conversation UserfriendlyNametosenderScreenName. - 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
| 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 }); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
@copilot apply changes based on #4115 (comment)
There was a problem hiding this comment.
Fixed in commit 9eda176. Renamed createConverationResult → createConversationResult throughout customChannelToFlex.ts.
| } else { | ||
| name = message.author || ''; | ||
| } | ||
| const translatedName = localizeKey(currentTranslations)(name); |
There was a problem hiding this comment.
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.
| const translatedName = localizeKey(currentTranslations)(name); | |
| const translated = localizeKey(currentTranslations)(name); | |
| const translatedName = translated && translated !== name ? translated : message.author || ''; |
| 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), |
There was a problem hiding this comment.
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").
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
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.
lambdas/account-scoped/tests/unit/webchatAuthentication/initWebchat.test.ts
Show resolved
Hide resolved
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>
Unit tests are passing — all 321 tests in 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:
If you need me to access, download, or install something from one of these locations, you can either:
|
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
MessageBubblehave been updated to reflect this new behaviour:translationsanddefaultLocalein the config so the localization selectors work correctly in testscreateConversationin the Lambda layer has been made more robust:client.conversations.v1.conversations.create()call is now inside its owntry/catch, ensuring that any failure at that stage is returned as aResulterror (with noconversationSid) rather than causing an unhandled throw. A secondtry/catchcontinues to wrap all subsequent setup steps (returning theconversationSidin the error when it was created but setup failed).createConverationResult→createConversationResultincustomChannelToFlex.tssessionDataHandler.tshas been made more resilient for non-English locales:CustomerFriendlyNamefallback now detects whenlocalizeKeyreturns 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 nameChecklist
Other Related Issues
None
Verification steps
See tickets
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
🔒 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.