Created
November 14, 2024 16:11
-
-
Save ivastly/fbe53e115fc1f0d05027e0342ab4af8d to your computer and use it in GitHub Desktop.
Extend Intercom API client
This file contains hidden or 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
| <?php | |
| declare(strict_types=1); | |
| use Intercom\IntercomClient; | |
| use Intercom\IntercomConversations; | |
| require_once __DIR__.'/../vendor/autoload.php'; | |
| final class ExtendedIntercomConversations extends IntercomConversations | |
| { | |
| public function __construct(IntercomClient $client) | |
| { | |
| parent::__construct($client); | |
| } | |
| public function closeConversation(int $conversationId): stdClass | |
| { | |
| $response = $this->client->get('/me'); | |
| return $this->client->post('/conversations/' . $conversationId . '/parts', [ | |
| 'type' => 'admin', | |
| 'admin_id' => $response->id, | |
| 'message_type' => 'close', | |
| 'body' => 'Conversation closed by admin', | |
| ]); | |
| } | |
| } | |
| $token = 'your token'; | |
| $client = new IntercomClient($token); | |
| $extendedIntercomConversations = new ExtendedIntercomConversations($client); | |
| $client->conversations = $extendedIntercomConversations; | |
| $result = $client->conversations->closeConversation(921); | |
| echo 'done'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment