Skip to content

Commit

Permalink
Use staging when proxied
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelini committed Oct 2, 2024
1 parent f89c0f5 commit c52a02b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/zendesk-client/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const SMOOCH_INTEGRATION_ID = '6453b7fc45cea5c267e60fed';
export const SMOOCH_INTEGRATION_ID_STAGING = '63d2ab28dc6b88010e60f38c';
export const ZENDESK_SOURCE_URL_TICKET_FIELD_ID = 23752099174548;
export const ZENDESK_SCRIPT_ID = 'ze-snippet';
export const ZENDESK_SUPPORT_CHAT_KEY = 'cec07bc9-4da6-4dd2-afa7-c7e01ae73584';
Expand Down
7 changes: 5 additions & 2 deletions packages/zendesk-client/src/use-smooch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { recordTracksEvent } from '@automattic/calypso-analytics';
import config from '@automattic/calypso-config';
import { useCallback, useState } from 'react';
import Smooch from 'smooch';
import { SMOOCH_INTEGRATION_ID } from './constants';
import { SMOOCH_INTEGRATION_ID, SMOOCH_INTEGRATION_ID_STAGING } from './constants';
import { UserFields } from './types';
import { useAuthenticateZendeskMessaging } from './use-authenticate-zendesk-messaging';
import { useUpdateZendeskUserFields } from './use-update-zendesk-user-fields';
Expand Down Expand Up @@ -51,6 +52,8 @@ const addUnreadCountListener = ( callback: ( unreadCount: number ) => void ) =>
};

export const useSmooch = () => {
const currentEnvironment = config( 'env_id' );
const isTestMode = currentEnvironment !== 'production';
const [ init, setInit ] = useState( typeof Smooch.getConversations === 'function' );
const { data: authData } = useAuthenticateZendeskMessaging( true, 'messenger' );
const { isPending: isSubmittingZendeskUserFields, mutateAsync: submitUserFields } =
Expand All @@ -60,7 +63,7 @@ export const useSmooch = () => {
( ref: HTMLDivElement ) => {
if ( authData?.jwt && authData?.externalId && ! init ) {
Smooch.init( {
integrationId: SMOOCH_INTEGRATION_ID,
integrationId: isTestMode ? SMOOCH_INTEGRATION_ID_STAGING : SMOOCH_INTEGRATION_ID,
embedded: true,
externalId: authData?.externalId,
jwt: authData?.jwt,
Expand Down

0 comments on commit c52a02b

Please sign in to comment.