-
Notifications
You must be signed in to change notification settings - Fork 2k
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 chat using Zendesk Messaging - attempt 2 #77024
Merged
klimeryk
merged 7 commits into
trunk
from
revert-77016-revert-76777-update/zendesk-chat-feature
May 18, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
16af2f3
Revert "Revert "Support chat using Zendesk Messaging (#76777)" (#77016)"
klimeryk b290b39
Use support activities instead of history
klimeryk ab00d76
Fix the Support Activity endpoint for ETK
klimeryk e5fa3ae
Safeguard against fetching support activity when we don't need it
klimeryk 3745095
Prevent unnecessary query when not in the JP presales context
klimeryk d96bb9d
Ensure we don't run into race conditions when loading scripts
klimeryk 93ac65a
Ensure Happy Chat is not loaded in production and staging
klimeryk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...toolkit/editing-toolkit-plugin/help-center/class-wp-rest-help-center-support-activity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* WP_REST_Help_Center_Support_Activity file. | ||
* | ||
* @package A8C\FSE | ||
*/ | ||
|
||
namespace A8C\FSE; | ||
|
||
use Automattic\Jetpack\Connection\Client; | ||
|
||
/** | ||
* Class WP_REST_Help_Center_Support_Activity. | ||
*/ | ||
class WP_REST_Help_Center_Support_Activity extends \WP_REST_Controller { | ||
/** | ||
* WP_REST_Help_Center_Support_Activity constructor. | ||
*/ | ||
public function __construct() { | ||
$this->namespace = 'help-center'; | ||
$this->rest_base = '/support-activity'; | ||
} | ||
|
||
/** | ||
* Register available routes. | ||
*/ | ||
public function register_rest_route() { | ||
register_rest_route( | ||
$this->namespace, | ||
$this->rest_base, | ||
array( | ||
'methods' => \WP_REST_Server::READABLE, | ||
'callback' => array( $this, 'get_support_activity' ), | ||
'permission_callback' => 'is_user_logged_in', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Get support activity through Jetpack. | ||
*/ | ||
public function get_support_activity() { | ||
$body = Client::wpcom_json_api_request_as_user( '/support-activity' ); | ||
|
||
if ( is_wp_error( $body ) ) { | ||
return $body; | ||
} | ||
|
||
$response = json_decode( wp_remote_retrieve_body( $body ) ); | ||
|
||
return rest_ensure_response( $response ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
...-toolkit/editing-toolkit-plugin/help-center/class-wp-rest-help-center-support-history.php
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...ting-toolkit/editing-toolkit-plugin/help-center/class-wp-rest-help-center-user-fields.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* WP_REST_Help_Center_User_Fields file. | ||
* | ||
* @package A8C\FSE | ||
*/ | ||
|
||
namespace A8C\FSE; | ||
|
||
use Automattic\Jetpack\Connection\Client; | ||
|
||
/** | ||
* Class WP_REST_Help_Center_User_Fields. | ||
*/ | ||
class WP_REST_Help_Center_User_Fields extends \WP_REST_Controller { | ||
/** | ||
* WP_REST_Help_Center_User_Fields constructor. | ||
*/ | ||
public function __construct() { | ||
$this->namespace = 'help-center'; | ||
$this->rest_base = '/zendesk/user-fields'; | ||
} | ||
|
||
/** | ||
* Register available routes. | ||
*/ | ||
public function register_rest_route() { | ||
register_rest_route( | ||
$this->namespace, | ||
$this->rest_base, | ||
array( | ||
'methods' => \WP_REST_Server::CREATABLE, | ||
'callback' => array( $this, 'update_user_fields' ), | ||
'permission_callback' => array( $this, 'permission_callback' ), | ||
'args' => array( | ||
'fields' => array( | ||
'type' => 'object', | ||
'required' => true, | ||
), | ||
), | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Callback to update user fields in Zendesk | ||
* | ||
* @param \WP_REST_Request $request The request sent to the API. | ||
* | ||
* @return WP_REST_Response | ||
*/ | ||
public function update_user_fields( \WP_REST_Request $request ) { | ||
$body = Client::wpcom_json_api_request_as_user( | ||
'help/zendesk/update-user-fields', | ||
'2', | ||
array( | ||
'method' => 'POST', | ||
), | ||
$request['fields'] | ||
); | ||
|
||
if ( is_wp_error( $body ) ) { | ||
return $body; | ||
} | ||
$response = json_decode( wp_remote_retrieve_body( $body ) ); | ||
return rest_ensure_response( $response ); | ||
} | ||
|
||
/** | ||
* Callback to determine whether the user has permission to access. | ||
*/ | ||
public function permission_callback() { | ||
return is_user_logged_in(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be wrong but I think you need the starting slash here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess not, I can see an instance of it without. Forgive me : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd assume so too, but looking at the other calls in this file and some others, it seems both versions work? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a slash:
wp-calypso/apps/editing-toolkit/editing-toolkit-plugin/help-center/class-wp-rest-help-center-ticket.php
Line 78 in 6f2928a
Without:
wp-calypso/apps/editing-toolkit/editing-toolkit-plugin/help-center/class-wp-rest-help-center-authenticate.php
Line 44 in 6f2928a
Those are existing calls that I assume are working. We could definitely update them to be consistent (probably the starting slash is the best way to go).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I appreciate the attention to detail! Those missing starting slashes in most cases are problematic. So probably good to fix this in a follow-up patch.