CHI-3641: Add channel_type attribute to new aselo webchat conversations.#4087
CHI-3641: Add channel_type attribute to new aselo webchat conversations.#4087stephenhand wants to merge 18 commits intomasterfrom
Conversation
… redundant proxy session check from conversations path of the channel janitor
|
@copilot - add unit test coverage for the updated initWebchat.ts client.flexApi.v2.webChannels.create and patchConversationAttributes are calls with side effects, explicitly check they are invoked |
|
@stephenhand I've opened a new pull request, #4088, to work on those changes. Once the pull request is ready, I'll request review from you. |
…chConversationAttributes invocations Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com> Agent-Logs-Url: https://github.com/techmatters/flex-plugins/sessions/0c6cb863-13ab-44ab-91d9-a12ec2bf6070
Agent-Logs-Url: https://github.com/techmatters/flex-plugins/sessions/fbbe4f24-9cb2-48aa-9a23-babf6b3bd84e Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
CHI-3641: Add channel_type attribute to new aselo webchat conversations.
|
@copilot fix the failing unit tests to align with the updated conversation creation process, remove any redundant ones and add new ones to address gaps in coverage of the new workflow |
…flow Agent-Logs-Url: https://github.com/techmatters/flex-plugins/sessions/be435f5c-b653-4f28-a304-9149792dac99 Co-authored-by: stephenhand <1694716+stephenhand@users.noreply.github.com>
Done in Removed (no longer relevant):
Updated/added (covering the new workflow):
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:
|
There was a problem hiding this comment.
Pull request overview
This PR updates the webchat conversation initialization flow to use the shared Conversations creation helper (instead of the deprecated Flex WebChannels API), ensuring new webchat conversations include channel_type: 'web' in their attributes and use a Studio Flow SID retrieved from SSM. It also aligns several unit tests and custom-channel call sites with the updated conversation creation/webhook naming.
Changes:
- Replace deprecated webchat conversation creation with shared
createConversation(...), passingchannelType: 'web'and retrieving the Studio Flow SID viagetChannelStudioFlowSid(...). - Introduce shared conversation utilities (
createConversation,patchConversationAttributes) and refactor custom channels to useonMessageAddedWebhookUrlnaming. - Update/adjust unit tests to reflect new behavior (web conversations supported in HRM sanitization/profile-flag flows, janitor behavior changes, and rewritten webchat init tests).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lambdas/account-scoped/src/webchatAuthentication/initWebchat.ts | Webchat now creates conversations via shared helper and uses SSM Studio Flow SID. |
| lambdas/account-scoped/tests/unit/webchatAuthentication/initWebchat.test.ts | New unit tests for the updated init flow and parameter passing. |
| lambdas/account-scoped/src/conversation/createConversation.ts | New shared conversation creation helper that sets attributes and webhooks. |
| lambdas/account-scoped/src/conversation/patchConversationAttributes.ts | New helper to patch conversation attributes. |
| lambdas/account-scoped/src/customChannels/customChannelToFlex.ts | Refactor to import shared createConversation and rename webhook param. |
| lambdas/account-scoped/src/customChannels/*/*ToFlex.ts | Update call sites to pass onMessageAddedWebhookUrl (renames/aliases). |
| lambdas/account-scoped/src/customChannels/configuration.ts | Allow getChannelStudioFlowSid to accept 'web' as a channel name. |
| lambdas/account-scoped/src/hrm/sanitizeIdentifier.ts | Allow web conversation triggers to sanitize without error (behavior change). |
| lambdas/account-scoped/tests/unit/hrm/sanitizeIdentifier.test.ts | Update expectations for web conversation trigger behavior. |
| lambdas/account-scoped/tests/unit/hrm/getProfileFlagsForIdentifier.test.ts | Update expectations for web conversation channel behavior. |
| lambdas/account-scoped/src/conversation/chatChannelJanitor.ts | Stop deleting proxy sessions when deactivating conversations (behavior change). |
| lambdas/account-scoped/tests/unit/conversation/chatChannelJanitor.test.ts | Remove test coverage for proxy-session deletion on conversation deactivation. |
Comments suppressed due to low confidence (1)
lambdas/account-scoped/src/conversation/chatChannelJanitor.ts:106
chatChannelJanitor's file header says it will delete the associated proxy session, butdeactivateConversationno longer checks conversation attributes forproxySessionor deletes it (onlydeactivateChanneldoes). Either update the documentation to reflect the new behavior or restore proxy-session cleanup for conversation-based flows if conversations can still haveproxySessionattributes.
const deactivateConversation = async (
accountSid: AccountSID,
conversationSid: ConversationSID,
) => {
const client = await getTwilioClient(accountSid);
const conversation = await client.conversations.v1.conversations
.get(conversationSid)
.fetch();
if (conversation.state !== 'closed') {
console.info('Attempting to deactivate active conversation', conversationSid);
const updated = await conversation.update({
state: 'closed',
xTwilioWebhookEnabled: 'true',
});
lambdas/account-scoped/src/conversation/patchConversationAttributes.ts
Outdated
Show resolved
Hide resolved
lambdas/account-scoped/src/conversation/patchConversationAttributes.ts
Outdated
Show resolved
Hide resolved
| channelType: AseloCustomChannel | 'web'; // The chat channel being used | ||
| uniqueUserName: string; // Unique identifier for this user | ||
| senderScreenName: string; // Friendly info to show in the Flex UI (like Telegram handle) | ||
| onMessageAddedWebhookUrl?: string; // The url that must be used as the onMessageSent event webhook. |
There was a problem hiding this comment.
onMessageAddedWebhookUrl is documented as "onMessageSent" in the inline comment, which is misleading now that the webhook is subscribed to the onMessageAdded filter. Update the comment to match the actual behavior (and consider renaming any remaining references to onMessageSent if they exist).
| onMessageAddedWebhookUrl?: string; // The url that must be used as the onMessageSent event webhook. | |
| onMessageAddedWebhookUrl?: string; // The url that must be used as the onMessageAdded event webhook. |
| const client = await getTwilioClient(accountSid); | ||
| const orchestratorResponse = await client.flexApi.v2.webChannels.create({ | ||
| customerFriendlyName, | ||
| addressSid, | ||
| preEngagementData: JSON.stringify(formData), | ||
| uiVersion: process.env.WEBCHAT_VERSION || '1.0.0', | ||
| chatFriendlyName: 'Webchat widget', | ||
| const conversation = await createConversation(client, { | ||
| channelType: 'web', | ||
| conversationFriendlyName: customerFriendlyName, | ||
| senderScreenName: customerFriendlyName, | ||
| studioFlowSid, | ||
| testSessionId, | ||
| twilioNumber: `web:${accountSid}`, | ||
| uniqueUserName: senderId, | ||
| additionalConversationAttributes: { | ||
| pre_engagement_data: formData, | ||
| from: customerFriendlyName, | ||
| }, | ||
| }); | ||
| console.info('Webchat Orchestrator successfully called', orchestratorResponse); | ||
|
|
||
| const { conversationSid, identity } = orchestratorResponse; | ||
| const { conversationSid } = conversation; | ||
| console.info( | ||
| `Created new conversation ${conversationSid} via the API with sender ID: ${senderId}`, | ||
| ); | ||
|
|
||
| return newOk({ | ||
| conversationSid: conversationSid as ConversationSID, | ||
| identity, | ||
| identity: senderId, | ||
| }); |
There was a problem hiding this comment.
createConversation returns { conversationSid, error? } rather than throwing on post-create failures (participants/attributes/webhooks). Here the error field is ignored, so contactWebchatOrchestrator can return Ok even when conversation setup failed, and token creation will proceed for a broken conversation. Handle the returned error (and consider removing the partially created conversation, similar to customChannelToFlex) or change createConversation to throw on failure.
| const senderId = `web:${crypto.randomUUID()}`; | ||
| console.info(`Creating new conversation via the API with sender ID: ${senderId}`); |
There was a problem hiding this comment.
crypto.randomUUID() is used without importing crypto. In this codebase other usages import from crypto (e.g. import crypto from 'crypto'), and relying on a global may fail depending on TS libs/runtime. Import crypto explicitly (or use an existing UUID helper) to avoid build/runtime issues.
…butes.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…butes.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ibute' into CHI-3641-channel_type_convo_attribute
Description
Replace call to deprecated API with reusing the conversation creation logic we use for custom channels (
createConversation). Addschannel_type: 'web'to conversation attributes by passingchannelType: 'web'through the sharedcreateConversationflow, and usesgetChannelStudioFlowSidto retrieve the studio flow SID from SSM.Unit tests for
initWebchat.tshave been rewritten to align with the updated flow: mocks for the deprecatedwebChannels.createandpatchConversationAttributeshave been replaced with mocks forcreateConversationandgetChannelStudioFlowSid, with coverage for correct parameter passing, friendly name fallbacks, pre-engagement data attributes, error handling, and token generation.Checklist
Other Related Issues
None
Verification steps
Create a new webchat conversation and confirm the conversation attributes include
channel_type: 'web'. Verify studio flows that branch onchannel_typeroute correctly for webchat contacts.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
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.