-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jin
committed
Feb 27, 2024
1 parent
a3cf97c
commit 18b182b
Showing
3 changed files
with
157 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/* | ||
* This file is part of tiktokshop-client. | ||
* | ||
* Copyright (c) 2024 Jin <[email protected]> All rights reserved. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EcomPHP\TiktokShop\Resources; | ||
|
||
use EcomPHP\TiktokShop\Resource; | ||
use GuzzleHttp\RequestOptions; | ||
|
||
class CustomerService extends Resource | ||
{ | ||
protected $category = 'customer_service'; | ||
|
||
public function getConversationMessages($conversation_id, $params = []) | ||
{ | ||
$params = array_merge([ | ||
'page_size' => 20, | ||
], $params); | ||
|
||
return $this->call('GET', 'conversations/'.$conversation_id.'/messages', [ | ||
RequestOptions::QUERY => $params, | ||
]); | ||
} | ||
|
||
public function getConversations($params = []) | ||
{ | ||
$params = array_merge([ | ||
'page_size' => 20, | ||
], $params); | ||
|
||
return $this->call('GET', 'conversations', [ | ||
RequestOptions::QUERY => $params, | ||
]); | ||
} | ||
|
||
public function sendMessage($conversation_id, $type, $content) | ||
{ | ||
return $this->call('POST', 'conversations/'.$conversation_id.'/messages', [ | ||
RequestOptions::JSON => [ | ||
'type' => $type, | ||
'content' => is_array($content) ? json_encode($content) : $content, | ||
] | ||
]); | ||
} | ||
|
||
public function getAgentSettings() | ||
{ | ||
return $this->call('GET', 'agents/settings'); | ||
} | ||
|
||
public function updateAgentSettings($body = []) | ||
{ | ||
return $this->call('PUT', 'agents/settings', [ | ||
RequestOptions::JSON => $body, | ||
]); | ||
} | ||
|
||
public function uploadBuyerMessagesImage($image) | ||
{ | ||
return $this->call('POST', 'images/upload', [ | ||
RequestOptions::MULTIPART => [ | ||
[ | ||
'name' => 'data', | ||
'filename' => 'image', | ||
'contents' => static::dataTypeCast('image', $image), | ||
] | ||
] | ||
]); | ||
} | ||
|
||
public function readMessage($conversation_id) | ||
{ | ||
return $this->call('POST', 'conversations/'.$conversation_id.'/messages/read'); | ||
} | ||
|
||
public function createConversation($buyer_user_id) | ||
{ | ||
return $this->call('POST', 'conversations', [ | ||
RequestOptions::JSON => [ | ||
'buyer_user_id' => $buyer_user_id, | ||
] | ||
]); | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
/* | ||
* This file is part of tiktokshop-client. | ||
* | ||
* Copyright (c) 2024 Jin <[email protected]> All rights reserved. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace EcomPHP\TiktokShop\Tests\Resources; | ||
|
||
use EcomPHP\TiktokShop\Resources\CustomerService; | ||
use EcomPHP\TiktokShop\Tests\TestResource; | ||
|
||
class CustomerServiceTest extends TestResource | ||
{ | ||
public function testGetConversationMessages() | ||
{ | ||
$this->caller->getConversationMessages('conversation_id'); | ||
$this->assertPreviousRequest('GET', 'customer_service/'.TestResource::TEST_API_VERSION.'/conversations/conversation_id/messages'); | ||
} | ||
|
||
public function testGetConversations() | ||
{ | ||
$this->caller->getConversations(); | ||
$this->assertPreviousRequest('GET', 'customer_service/'.TestResource::TEST_API_VERSION.'/conversations'); | ||
} | ||
|
||
public function testSendMessage() | ||
{ | ||
$this->caller->sendMessage('conversation_id', 'type', 'content'); | ||
$this->assertPreviousRequest('POST', 'customer_service/'.TestResource::TEST_API_VERSION.'/conversations/conversation_id/messages'); | ||
} | ||
|
||
public function testGetAgentSettings() | ||
{ | ||
$this->caller->getAgentSettings(); | ||
$this->assertPreviousRequest('GET', 'customer_service/'.TestResource::TEST_API_VERSION.'/agents/settings'); | ||
} | ||
|
||
public function testUpdateAgentSettings() | ||
{ | ||
$this->caller->updateAgentSettings(); | ||
$this->assertPreviousRequest('PUT', 'customer_service/'.TestResource::TEST_API_VERSION.'/agents/settings'); | ||
} | ||
|
||
public function testUploadBuyerMessagesImage() | ||
{ | ||
$this->caller->uploadBuyerMessagesImage('php://memory'); | ||
$this->assertPreviousRequest('POST', 'customer_service/'.TestResource::TEST_API_VERSION.'/images/upload'); | ||
} | ||
|
||
public function testReadMessage() | ||
{ | ||
$this->caller->readMessage('conversation_id'); | ||
$this->assertPreviousRequest('POST', 'customer_service/'.TestResource::TEST_API_VERSION.'/conversations/conversation_id/messages/read'); | ||
} | ||
|
||
public function testCreateConversation() | ||
{ | ||
$this->caller->createConversation('buyer_id'); | ||
$this->assertPreviousRequest('POST', 'customer_service/'.TestResource::TEST_API_VERSION.'/conversations'); | ||
} | ||
} |