Skip to content

Commit dad4352

Browse files
authored
Merge pull request #59954 from rushatgabhane/ab-test
A/B test various CTA for the Concierge Voice
2 parents 14c0bcb + 452382f commit dad4352

File tree

7 files changed

+42
-12
lines changed

7 files changed

+42
-12
lines changed

src/languages/en.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6112,7 +6112,9 @@ const translations = {
61126112
confirmText: 'Discard changes',
61136113
},
61146114
aiSales: {
6115-
talkWithSales: 'Talk with sales',
6115+
talkToSales: 'Talk to sales',
6116+
getHelp: 'Get help',
6117+
talkToConcierge: 'Talk to Concierge',
61166118
hangUp: 'Hang up',
61176119
},
61186120
};

src/languages/es.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6633,7 +6633,9 @@ const translations = {
66336633
confirmText: 'Descartar cambios',
66346634
},
66356635
aiSales: {
6636-
talkWithSales: 'Habla con ventas',
6636+
talkToSales: 'Habla con ventas',
6637+
getHelp: 'Obtener ayuda',
6638+
talkToConcierge: 'Habla con Concierge',
66376639
hangUp: 'Colgar',
66386640
},
66396641
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type GetEmphemeralTokenParams = {
2+
adminsChatReportID: number;
3+
ctaUsed: string;
4+
};
5+
6+
export default GetEmphemeralTokenParams;

src/libs/API/parameters/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,5 @@ export type {default as ChangeReportPolicyParams} from './ChangeReportPolicyPara
382382
export type {default as ResetBankAccountSetupParams} from './ResetBankAccountSetupParams';
383383
export type {default as SendRecapInAdminsRoomParams} from './SendRecapInAdminsRoomParams';
384384
export type {default as SetPolicyProhibitedExpensesParams} from './SetPolicyProhibitedExpensesParams';
385+
export type {default as GetEmphemeralTokenParams} from './GetEmphemeralTokenParams';
385386
export type {default as CreateAppleDigitalWalletParams} from './CreateAppleDigitalWalletParams';

src/libs/API/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,8 @@ type SideEffectRequestCommandParameters = {
11201120
[SIDE_EFFECT_REQUEST_COMMANDS.BANK_ACCOUNT_CREATE_CORPAY]: Parameters.BankAccountCreateCorpayParams;
11211121
[SIDE_EFFECT_REQUEST_COMMANDS.PAY_MONEY_REQUEST_ON_SEARCH]: Parameters.PayMoneyRequestOnSearchParams;
11221122
[SIDE_EFFECT_REQUEST_COMMANDS.LOG_OUT]: Parameters.LogOutParams;
1123+
[SIDE_EFFECT_REQUEST_COMMANDS.GET_EMPHEMERAL_TOKEN]: Parameters.GetEmphemeralTokenParams;
11231124
[SIDE_EFFECT_REQUEST_COMMANDS.CREATE_DIGITAL_WALLET]: Parameters.CreateAppleDigitalWalletParams;
1124-
[SIDE_EFFECT_REQUEST_COMMANDS.GET_EMPHEMERAL_TOKEN]: EmptyObject;
11251125
};
11261126

11271127
type ApiRequestCommandParameters = WriteCommandParameters & ReadCommandParameters & SideEffectRequestCommandParameters;

src/libs/actions/OpenAI/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Onyx from 'react-native-onyx';
22
import * as API from '@libs/API';
3-
import type {SendRecapInAdminsRoomParams} from '@libs/API/parameters';
3+
import type {GetEmphemeralTokenParams, SendRecapInAdminsRoomParams} from '@libs/API/parameters';
44
import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
55
import {playStreamSound} from '@libs/Sound';
66
import CONST from '@src/CONST';
@@ -51,7 +51,7 @@ function isExpiredToken(expiresAt: number): boolean {
5151
return currentUTCEpochTime >= expiresAt;
5252
}
5353

54-
function getEmphemeralToken(): Promise<string> {
54+
function getEmphemeralToken(adminsChatReportID: number, ctaUsed: string): Promise<string> {
5555
if (clientSecret && !isExpiredToken(clientSecret.expiresAt)) {
5656
Onyx.merge(ONYXKEYS.TALK_TO_AI_SALES, {
5757
isLoading: true,
@@ -71,8 +71,13 @@ function getEmphemeralToken(): Promise<string> {
7171
],
7272
};
7373

74+
const parameters: GetEmphemeralTokenParams = {
75+
adminsChatReportID,
76+
ctaUsed,
77+
};
78+
7479
// eslint-disable-next-line rulesdir/no-api-side-effects-method
75-
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.GET_EMPHEMERAL_TOKEN, {}, onyxData)
80+
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.GET_EMPHEMERAL_TOKEN, parameters, onyxData)
7681
.then((response) => {
7782
Onyx.merge(ONYXKEYS.TALK_TO_AI_SALES, {
7883
clientSecret: {
@@ -101,7 +106,7 @@ function connectUsingSDP(ephemeralToken: string, rtcOffer: RTCSessionDescription
101106
});
102107
}
103108

104-
function connectToOpenAIRealtime(): Promise<ConnectionResult> {
109+
function connectToOpenAIRealtime(adminsChatReportID: number, ctaUsed: string): Promise<ConnectionResult> {
105110
let peerConnection: RTCPeerConnection;
106111
let rtcOffer: RTCSessionDescriptionInit;
107112
let dataChannel: RTCDataChannel;
@@ -165,7 +170,7 @@ function connectToOpenAIRealtime(): Promise<ConnectionResult> {
165170
rtcOffer = offer;
166171
})
167172
.then(() => {
168-
return getEmphemeralToken();
173+
return getEmphemeralToken(adminsChatReportID, ctaUsed);
169174
})
170175
.then((ephemeralToken: string) => {
171176
return connectUsingSDP(ephemeralToken, rtcOffer);
@@ -204,10 +209,14 @@ function handleOpenAIMessage(message: OpenAIRealtimeMessage) {
204209
}
205210
}
206211

207-
function initializeOpenAIRealtime(adminsReportID: number) {
212+
function initializeOpenAIRealtime(adminsReportID: number, ctaUsed: string) {
213+
if (adminsReportID === CONST.DEFAULT_NUMBER_ID || ctaUsed === '') {
214+
return;
215+
}
216+
208217
currentAdminsReportID = adminsReportID;
209218

210-
connectToOpenAIRealtime()
219+
connectToOpenAIRealtime(adminsReportID, ctaUsed)
211220
.then((connection: ConnectionResult) => {
212221
connections.openai = connection;
213222
Onyx.merge(ONYXKEYS.TALK_TO_AI_SALES, {isTalkingToAISales: true});

src/pages/home/TalkToSalesButton/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ function TalkToSalesButton({shouldUseNarrowLayout, reportID}: TalkToSalesButtonP
1818
const [talkToAISales] = useOnyx(ONYXKEYS.TALK_TO_AI_SALES);
1919
const styles = useThemeStyles();
2020

21+
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID});
22+
if (!reportID || !accountID) {
23+
return;
24+
}
25+
26+
const abTestCtaText = (): string => {
27+
const availableCTAs = [translate('aiSales.getHelp'), translate('aiSales.talkToSales'), translate('aiSales.talkToConcierge')];
28+
return availableCTAs.at(accountID % availableCTAs.length) ?? translate('aiSales.talkToSales');
29+
};
30+
2131
const talkToSalesIcon = () => {
2232
if (talkToAISales?.isLoading) {
2333
return undefined;
@@ -30,14 +40,14 @@ function TalkToSalesButton({shouldUseNarrowLayout, reportID}: TalkToSalesButtonP
3040

3141
return (
3242
<Button
33-
text={talkToAISales?.isTalkingToAISales ? translate('aiSales.hangUp') : translate('aiSales.talkWithSales')}
43+
text={talkToAISales?.isTalkingToAISales ? translate('aiSales.hangUp') : abTestCtaText()}
3444
onPress={() => {
3545
if (talkToAISales?.isTalkingToAISales) {
3646
stopConnection();
3747
return;
3848
}
3949

40-
initializeOpenAIRealtime(Number(reportID) ?? CONST.DEFAULT_NUMBER_ID);
50+
initializeOpenAIRealtime(Number(reportID) ?? CONST.DEFAULT_NUMBER_ID, abTestCtaText());
4151
}}
4252
style={shouldUseNarrowLayout && [styles.flex1]}
4353
icon={talkToSalesIcon()}

0 commit comments

Comments
 (0)