From a0e0cb7a91c3d448ef4840217d00cd10a0f2da68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 25 Feb 2026 15:48:53 -0600 Subject: [PATCH 1/5] Send bespoke welcome message optimistically from frontend Instead of generating the bespoke welcome message server-side and injecting it into guidedSetupData (which caused INSERT collision risk with optimistic IDs), the frontend now generates the message, displays it optimistically via Onyx, and sends it to the backend as API params. The backend passes it to PAZR as a PREGENERATED_RESPONSE so the LLM appends followups. Old App versions that don not send the new params fall back to the WELCOME_EVENT path. Co-Authored-By: Claude Opus 4.6 --- .../parameters/CompleteGuidedSetupParams.ts | 2 + src/libs/ReportUtils.ts | 75 ++++++++++++++++++- src/libs/actions/Report/index.ts | 4 +- 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/libs/API/parameters/CompleteGuidedSetupParams.ts b/src/libs/API/parameters/CompleteGuidedSetupParams.ts index d31c0fe00afa..7878c75fb28e 100644 --- a/src/libs/API/parameters/CompleteGuidedSetupParams.ts +++ b/src/libs/API/parameters/CompleteGuidedSetupParams.ts @@ -14,6 +14,8 @@ type CompleteGuidedSetupParams = { policyID?: string; selfDMReportID?: string; selfDMCreatedReportActionID?: string; + bespokeWelcomeMessage?: string; + optimisticConciergeReportActionID?: string; }; export default CompleteGuidedSetupParams; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 72e5a2e44a91..766b9df6882b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11380,6 +11380,25 @@ type PrepareOnboardingOnyxDataParams = { isSelfTourViewed?: boolean; }; +function getBespokeWelcomeMessage(userReportedIntegration?: OnboardingAccounting): string { + let message = + "

Your free trial has started! Let's get you set up.

" + + '
' + + "👋 Hey there! I'm your Expensify setup specialist. " + + 'For a small team like yours, the fastest way to get value is to set up a few expense categories, ' + + 'invite your team members, and have them start snapping receipts right away. ' + + "I'm here to walk you through each step — just ask!"; + + if (userReportedIntegration && userReportedIntegration !== 'other') { + const friendlyName = CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration as keyof typeof CONST.ONBOARDING_ACCOUNTING_MAPPING]; + if (friendlyName) { + message += `

Since you use ${friendlyName}, I can help you connect it so your expenses sync automatically — just say the word!`; + } + } + + return message; +} + function prepareOnboardingOnyxData({ introSelected, engagementChoice, @@ -11481,6 +11500,18 @@ function prepareOnboardingOnyxData({ reportComment: textComment.commentText, }; + // When the user is MICRO and using followups, generate a bespoke welcome message from Concierge. + // The frontend displays it optimistically; the backend passes it to PAZR which appends followups. + let bespokeWelcomeMessage: string | undefined; + let optimisticConciergeReportActionID: string | undefined; + let bespokeAction: OptimisticReportAction | undefined; + + if (shouldUseFollowupsInsteadOfTasks && companySize === CONST.ONBOARDING_COMPANY_SIZE.MICRO) { + bespokeWelcomeMessage = getBespokeWelcomeMessage(userReportedIntegration); + optimisticConciergeReportActionID = rand64(); + bespokeAction = buildOptimisticAddCommentReportAction(bespokeWelcomeMessage, undefined, CONST.ACCOUNT_ID.CONCIERGE, 2, targetChatReportID, optimisticConciergeReportActionID); + } + let createWorkspaceTaskReportID; let addExpenseApprovalsTaskReportID; let setupTagsTaskReportID; @@ -11796,6 +11827,26 @@ function prepareOnboardingOnyxData({ }); } + if (bespokeAction && optimisticConciergeReportActionID) { + optimisticData.push( + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [optimisticConciergeReportActionID]: bespokeAction.reportAction as ReportAction, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${targetChatReportID}`, + value: { + lastVisibleActionCreated: bespokeAction.reportAction.created, + lastActorAccountID: CONST.ACCOUNT_ID.CONCIERGE, + }, + }, + ); + } + if (!wasInvited) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -11816,6 +11867,16 @@ function prepareOnboardingOnyxData({ }, }); + if (bespokeAction && optimisticConciergeReportActionID) { + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [optimisticConciergeReportActionID]: {pendingAction: null, isOptimisticAction: null}, + }, + }); + } + let failureReport: Partial = { lastMessageText: '', lastVisibleActionCreated: '', @@ -11869,6 +11930,18 @@ function prepareOnboardingOnyxData({ }, }); + if (bespokeAction && optimisticConciergeReportActionID) { + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, + value: { + [optimisticConciergeReportActionID]: { + errors: getMicroSecondOnyxErrorWithTranslationKey('report.genericAddCommentFailureMessage'), + } as ReportAction, + }, + }); + } + if (!wasInvited) { failureData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -12042,7 +12115,7 @@ function prepareOnboardingOnyxData({ }); } - return {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters}; + return {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters, bespokeWelcomeMessage, optimisticConciergeReportActionID}; } /** diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 8ae58991e6be..7abd665b34fc 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -4772,7 +4772,7 @@ async function completeOnboarding({ return; } - const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters} = onboardingData; + const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters, bespokeWelcomeMessage, optimisticConciergeReportActionID} = onboardingData; const parameters: CompleteGuidedSetupParams = { engagementChoice, @@ -4786,6 +4786,8 @@ async function completeOnboarding({ policyID: onboardingPolicyID, selfDMReportID: selfDMParameters.reportID, selfDMCreatedReportActionID: selfDMParameters.createdReportActionID, + bespokeWelcomeMessage, + optimisticConciergeReportActionID, }; // We should only set testDriveModalDismissed to false if it's not already true (i.e., if the modal hasn't been dismissed yet). From da6f08bf72259eaa537a28871b27bcabef5b58c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 25 Feb 2026 16:00:45 -0600 Subject: [PATCH 2/5] Fix spellcheck (PAZR -> agent) and update existing unit test for bespoke action Co-Authored-By: Claude Opus 4.6 --- src/libs/ReportUtils.ts | 2 +- tests/unit/ReportUtilsTest.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 766b9df6882b..5bec8387abaa 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11501,7 +11501,7 @@ function prepareOnboardingOnyxData({ }; // When the user is MICRO and using followups, generate a bespoke welcome message from Concierge. - // The frontend displays it optimistically; the backend passes it to PAZR which appends followups. + // The frontend displays it optimistically; the backend passes it to the agent which appends followups. let bespokeWelcomeMessage: string | undefined; let optimisticConciergeReportActionID: string | undefined; let bespokeAction: OptimisticReportAction | undefined; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 071e3c90a7c9..263ebc4520bc 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -551,7 +551,11 @@ describe('ReportUtils', () => { companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO, }); expect(result?.guidedSetupData).toHaveLength(0); - expect(result?.optimisticData.filter((i) => i.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`)).toHaveLength(0); + // MICRO company size with suggestedFollowups beta adds a bespoke Concierge welcome action optimistically + const reportActionsEntries = result?.optimisticData.filter((i) => i.key === `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`); + expect(reportActionsEntries).toHaveLength(1); + expect(result?.bespokeWelcomeMessage).toBeDefined(); + expect(result?.optimisticConciergeReportActionID).toBeDefined(); }); it('should add guidedSetupData when posting into admin room WITHOUT suggestedFollowups beta', async () => { From b99fa2f4df220c6e2da37b7b7b3dedd755451c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 25 Feb 2026 16:05:41 -0600 Subject: [PATCH 3/5] Update comment wording for clarity Co-Authored-By: Claude Opus 4.6 --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5bec8387abaa..e7d719ef66ca 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11501,7 +11501,7 @@ function prepareOnboardingOnyxData({ }; // When the user is MICRO and using followups, generate a bespoke welcome message from Concierge. - // The frontend displays it optimistically; the backend passes it to the agent which appends followups. + // The frontend displays it optimistically; the server uses it to generate suggested followups. let bespokeWelcomeMessage: string | undefined; let optimisticConciergeReportActionID: string | undefined; let bespokeAction: OptimisticReportAction | undefined; From d154372637603cfa74c448cd4edee5ad1e0a4a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 25 Feb 2026 16:10:36 -0600 Subject: [PATCH 4/5] Use markdown instead of HTML in bespoke message to avoid escaping getParsedComment escapes HTML entities before parsing, so raw HTML tags would render as literal text in the optimistic display. Markdown syntax is converted correctly by the parser. Co-Authored-By: Claude Opus 4.6 --- src/libs/ReportUtils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e7d719ef66ca..171b4e97cb52 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11381,10 +11381,11 @@ type PrepareOnboardingOnyxDataParams = { }; function getBespokeWelcomeMessage(userReportedIntegration?: OnboardingAccounting): string { + // Use markdown (not HTML) because buildOptimisticAddCommentReportAction -> getParsedComment + // escapes HTML entities before parsing, so raw HTML tags would render as literal text. let message = - "

Your free trial has started! Let's get you set up.

" + - '
' + - "👋 Hey there! I'm your Expensify setup specialist. " + + "# Your free trial has started! Let's get you set up.\n" + + "Hey there! I'm your Expensify setup specialist. " + 'For a small team like yours, the fastest way to get value is to set up a few expense categories, ' + 'invite your team members, and have them start snapping receipts right away. ' + "I'm here to walk you through each step — just ask!"; @@ -11392,7 +11393,7 @@ function getBespokeWelcomeMessage(userReportedIntegration?: OnboardingAccounting if (userReportedIntegration && userReportedIntegration !== 'other') { const friendlyName = CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration as keyof typeof CONST.ONBOARDING_ACCOUNTING_MAPPING]; if (friendlyName) { - message += `

Since you use ${friendlyName}, I can help you connect it so your expenses sync automatically — just say the word!`; + message += `\n\nSince you use ${friendlyName}, I can help you connect it so your expenses sync automatically — just say the word!`; } } From 62cf2f1a320ada971002f6192a5912de3f621d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Wed, 25 Feb 2026 16:12:08 -0600 Subject: [PATCH 5/5] Restore wave emoji in bespoke welcome message Co-Authored-By: Claude Opus 4.6 --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 171b4e97cb52..0c1621fa6ff6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -11385,7 +11385,7 @@ function getBespokeWelcomeMessage(userReportedIntegration?: OnboardingAccounting // escapes HTML entities before parsing, so raw HTML tags would render as literal text. let message = "# Your free trial has started! Let's get you set up.\n" + - "Hey there! I'm your Expensify setup specialist. " + + "👋 Hey there! I'm your Expensify setup specialist. " + 'For a small team like yours, the fastest way to get value is to set up a few expense categories, ' + 'invite your team members, and have them start snapping receipts right away. ' + "I'm here to walk you through each step — just ask!";