Skip to content

Instantly share code, notes, and snippets.

@ivastly
Created November 14, 2024 16:11
Show Gist options
  • Select an option

  • Save ivastly/fbe53e115fc1f0d05027e0342ab4af8d to your computer and use it in GitHub Desktop.

Select an option

Save ivastly/fbe53e115fc1f0d05027e0342ab4af8d to your computer and use it in GitHub Desktop.
Extend Intercom API client
<?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