Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help Center: Connect to zendesk when user wants to contact support #95680

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useNavigate } from 'react-router-dom';
import { useOdieAssistantContext } from '../../context';
import { useCreateZendeskConversation } from '../../query/use-create-zendesk-conversation';

export const DirectEscalationLink = ( { messageId }: { messageId: number | undefined } ) => {
const { trackEvent, isUserEligibleForPaidSupport } = useOdieAssistantContext();
const newConversation = useCreateZendeskConversation();
const { shouldUseHelpCenterExperience, trackEvent, isUserEligibleForPaidSupport } =
useOdieAssistantContext();
const navigate = useNavigate();
const handleClick = useCallback( () => {
trackEvent( 'chat_message_direct_escalation_link_click', {
Expand All @@ -13,7 +16,11 @@ export const DirectEscalationLink = ( { messageId }: { messageId: number | undef
} );

if ( isUserEligibleForPaidSupport ) {
navigate( '/contact-options' );
if ( shouldUseHelpCenterExperience ) {
newConversation();
} else {
navigate( '/contact-options' );
}
} else {
navigate( '/contact-form?mode=FORUM' );
}
Expand Down
39 changes: 23 additions & 16 deletions packages/odie-client/src/components/message/user-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const UserMessage = ( {

const hasCannedResponse = message.context?.flags?.canned_response;
const isRequestingHumanSupport = message.context?.flags?.forward_to_human_support;
const isOnlyMessage = message.context?.flags?.only_message;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to understand the idea behind this boolean.
I would suggest us to rename this variable. Maybe we should call it “hide-disclaimer” or something similar. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus, I think we could extract this into another place, this is getting too conditional and difficult to read/follow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One refactoring example:

const renderExtraContactOptions = () => {
		return shouldUseHelpCenterExperience ? <GetSupport /> : extraContactOptions;
	};

	const renderDisclaimers = () => (
		<>
			<WasThisHelpfulButtons message={ message } isDisliked={ isDisliked } />
			<DirectEscalationLink messageId={ message.message_id } />
			<div className="disclaimer">
				{ __(
					"Generated by WordPress.com's Support AI. AI-generated responses may contain inaccurate information.",
					__i18n_text_domain__
				) }
				<ExternalLink href="https://automattic.com/ai-guidelines">
					{ __( 'Learn more.', __i18n_text_domain__ ) }
				</ExternalLink>
			</div>
		</>
	);

	return (
		<>
			<Markdown
				urlTransform={ uriTransformer }
				components={ {
					a: CustomALink,
				} }
			>
				{ isRequestingHumanSupport ? displayMessage : message.content }
			</Markdown>
			{ ! isOnlyMessage && (
				<>
					{ showExtraContactOptions ? renderExtraContactOptions() : isBot && renderDisclaimers() }
				</>
			) }
		</>
	);

const hasFeedback = !! message?.rating_value;
const isBot = message.role === 'bot';
const isPositiveFeedback =
Expand All @@ -46,23 +47,29 @@ export const UserMessage = ( {
>
{ isRequestingHumanSupport ? displayMessage : message.content }
</Markdown>
{ showExtraContactOptions &&
( shouldUseHelpCenterExperience ? <GetSupport /> : extraContactOptions ) }
{ ! showExtraContactOptions && isBot && (
<WasThisHelpfulButtons message={ message } isDisliked={ isDisliked } />
) }
{ isBot && (
{ ! isOnlyMessage && (
<>
{ ! showExtraContactOptions && <DirectEscalationLink messageId={ message.message_id } /> }
<div className="disclaimer">
{ __(
"Generated by WordPress.com's Support AI. AI-generated responses may contain inaccurate information.",
__i18n_text_domain__
) }
<ExternalLink href="https://automattic.com/ai-guidelines">
{ __( 'Learn more.', __i18n_text_domain__ ) }
</ExternalLink>
</div>
{ showExtraContactOptions &&
( shouldUseHelpCenterExperience ? <GetSupport /> : extraContactOptions ) }
{ ! showExtraContactOptions && isBot && (
<WasThisHelpfulButtons message={ message } isDisliked={ isDisliked } />
) }
{ isBot && (
<>
{ ! showExtraContactOptions && (
<DirectEscalationLink messageId={ message.message_id } />
) }
<div className="disclaimer">
{ __(
"Generated by WordPress.com's Support AI. AI-generated responses may contain inaccurate information.",
__i18n_text_domain__
) }
<ExternalLink href="https://automattic.com/ai-guidelines">
{ __( 'Learn more.', __i18n_text_domain__ ) }
</ExternalLink>
</div>
</>
) }
</>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const useCreateZendeskConversation = (): ( () => Promise< void > ) => {
content: "We're connecting you to our support team.",
role: 'bot',
type: 'message',
context: {
flags: {
only_message: true,
},
site_id: null,
},
} );

setChatStatus( 'sending' );
Expand Down
1 change: 1 addition & 0 deletions packages/odie-client/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type Context = {
flags?: {
forward_to_human_support?: boolean;
canned_response?: boolean;
only_message?: boolean;
};
};

Expand Down
Loading