@@ -26,13 +26,18 @@ const HELP_CENTER_STORE = HelpCenter.register();
2626
2727function getBotSlug (
2828 supportInteraction : SupportInteraction | undefined ,
29- newInteractionsBotSlug : string
29+ newInteractionsBotSlug : string ,
30+ currentUserId ?: number
3031) : string {
3132 if ( supportInteraction ) {
3233 // Legacy support interactions have their botSlug set to `''`. We need to use the legacy bot slug for them.
3334 return supportInteraction . bot_slug || ODIE_DEFAULT_BOT_SLUG_LEGACY ;
3435 }
3536
37+ if ( ! currentUserId ) {
38+ return 'wpcom-chat-loggedout' ;
39+ }
40+
3641 // When the interaction is undefined, it means we're sending the first message to Odie, which is done before the interaction is created.
3742 // In this case, we use the new interactions bot slug.
3843 return newInteractionsBotSlug ;
@@ -129,12 +134,13 @@ export const useSendOdieMessage = ( signal: AbortSignal ) => {
129134 ) ;
130135
131136 const updateLoggedOutSession = useCallback (
132- ( chatId : string , sessionId : string ) => {
137+ ( chatId : string , sessionId : string , botSlug : string ) => {
133138 const params = new URLSearchParams ( location . search ) ;
134139 params . set ( 'chatId' , chatId ) ;
135140 params . set ( 'sessionId' , sessionId ) ;
141+ params . set ( 'botSlug' , botSlug ) ;
136142 navigate ( `${ location . pathname } ?${ params . toString ( ) } ` , { replace : true } ) ;
137- setLoggedOutOdieChat ( { odieId : chatId , sessionId } ) ;
143+ setLoggedOutOdieChat ( { odieId : chatId , sessionId, botSlug } ) ;
138144 } ,
139145 [ location . pathname , location . search , navigate , setLoggedOutOdieChat ]
140146 ) ;
@@ -224,7 +230,11 @@ export const useSendOdieMessage = ( signal: AbortSignal ) => {
224230
225231 return useMutation < ReturnedChat , Error , Message > ( {
226232 mutationFn : async ( message : Message ) : Promise < ReturnedChat > => {
227- const botSlug = getBotSlug ( currentSupportInteraction , newInteractionsBotSlug ) ;
233+ const botSlug = getBotSlug (
234+ currentSupportInteraction ,
235+ newInteractionsBotSlug ,
236+ currentUser ?. ID
237+ ) ;
228238 const chatIdSegment = odieId ? `/${ odieId } ` : '' ;
229239 const session_id = sessionId ;
230240
@@ -308,8 +318,10 @@ export const useSendOdieMessage = ( signal: AbortSignal ) => {
308318 } ,
309319 } ) ;
310320 } else if ( ! isLoggedIn ) {
321+ const botSlug = getBotSlug ( currentSupportInteraction , newInteractionsBotSlug ) ;
322+
311323 // If the user is not logged in, we don't need to create a new support interaction.
312- updateLoggedOutSession ( chatId . toString ( ) , returnedChat . session_id ) ;
324+ updateLoggedOutSession ( chatId . toString ( ) , returnedChat . session_id , botSlug ) ;
313325 }
314326 } catch ( error ) {
315327 trackEvent ( 'error_updating_support_interaction' , {
0 commit comments