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

Support: send initial info on chat start #471

Merged
merged 3 commits into from Mar 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions assets/wizards/support/views/chat/index.js
Expand Up @@ -27,9 +27,8 @@ class Chat extends Component {

closeHappychat = null;

componentDidMount() {
renderChat = () => {
const { WPCOM_ACCESS_TOKEN } = newspack_support_data;

if ( WPCOM_ACCESS_TOKEN ) {
this.closeHappychat = Happychat.open( {
nodeId: 'newspack-happychat',
Expand All @@ -43,6 +42,30 @@ class Chat extends Component {
defaultValues: {},
},
} );
}
};

componentDidMount() {
const { WPCOM_ACCESS_TOKEN } = newspack_support_data;
if ( WPCOM_ACCESS_TOKEN ) {
this.renderChat();

let didSendInitialInfo;
Happychat.on( 'availability', availability => {
if ( ! didSendInitialInfo && availability ) {
Happychat.sendUserInfo( {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Happychat.sendUserInfo( {
didSendInitialInfo = true;
Happychat.sendUserInfo( {

This change will prevent an infinite loop without otherwise affecting the behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed: f37bc85

site: {
ID: '0',
URL: `${ window.location.protocol }//${ window.location.hostname }`,
},
// just to bust the default 'gettingStarted'
howCanWeHelp: 'newspack',
} );

Happychat.sendEvent( __( '[ Newspack customer ]', 'newspack' ) );
didSendInitialInfo = true;
}
} );
} else {
this.setState( { hasToAuthenticate: true } );
}
Expand Down