Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@

The Intercom PHP library provides convenient access to the Intercom APIs from PHP.

## Table of Contents

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Exception Handling](#exception-handling)
- [Pagination](#pagination)
- [Legacy Sdk](#legacy-sdk)
- [Advanced](#advanced)
- [Custom Client](#custom-client)
- [Retries](#retries)
- [Timeouts](#timeouts)
- [Contributing](#contributing)

## Requirements

This SDK requires PHP ^8.1.
Expand All @@ -26,16 +40,14 @@ namespace Example;

use Intercom\IntercomClient;
use Intercom\AiContent\Requests\CreateContentImportSourceRequest;
use Intercom\AiContent\Types\CreateContentImportSourceRequestStatus;

$client = new IntercomClient(
token: '<token>',
);
$client->aiContent->createContentImportSource(
new CreateContentImportSourceRequest([
'syncBehavior' => 'api',
'status' => CreateContentImportSourceRequestStatus::Active->value,
'url' => 'url',
'url' => 'https://www.example.com',
]),
);

Expand Down Expand Up @@ -87,6 +99,7 @@ foreach ($items->getPages() as $page) {
}
```


## Legacy SDK

While the new SDK has a lot of improvements, we at Intercom understand that it takes time to upgrade when there are breaking changes.
Expand Down Expand Up @@ -156,7 +169,7 @@ A request is deemed retryable when any of the following HTTP status codes is ret
Use the `maxRetries` request option to configure this behavior.

```php
$response = $client->articles->create(
$response = $client->aiContent->createContentImportSource(
...,
options: [
'maxRetries' => 0 // Override maxRetries at the request level
Expand All @@ -169,7 +182,7 @@ $response = $client->articles->create(
The SDK defaults to a 30 second timeout. Use the `timeout` option to configure this behavior.

```php
$response = $client->articles->create(
$response = $client->aiContent->createContentImportSource(
...,
options: [
'timeout' => 3.0 // Override timeout to 3 seconds
Expand Down
21 changes: 15 additions & 6 deletions src/Admins/AdminsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public function __construct(
* queryParameters?: array<string, mixed>,
* bodyProperties?: array<string, mixed>,
* } $options
* @return AdminWithApp
* @return ?AdminWithApp
* @throws IntercomException
* @throws IntercomApiException
*/
public function identify(?array $options = null): AdminWithApp
public function identify(?array $options = null): ?AdminWithApp
{
$options = array_merge($this->options, $options ?? []);
try {
Expand All @@ -91,6 +91,9 @@ public function identify(?array $options = null): AdminWithApp
$statusCode = $response->getStatusCode();
if ($statusCode >= 200 && $statusCode < 400) {
$json = $response->getBody()->getContents();
if (empty($json)) {
return null;
}
return AdminWithApp::fromJson($json);
}
} catch (JsonException $e) {
Expand Down Expand Up @@ -127,11 +130,11 @@ public function identify(?array $options = null): AdminWithApp
* queryParameters?: array<string, mixed>,
* bodyProperties?: array<string, mixed>,
* } $options
* @return Admin
* @return ?Admin
* @throws IntercomException
* @throws IntercomApiException
*/
public function away(ConfigureAwayAdminRequest $request, ?array $options = null): Admin
public function away(ConfigureAwayAdminRequest $request, ?array $options = null): ?Admin
{
$options = array_merge($this->options, $options ?? []);
try {
Expand All @@ -147,6 +150,9 @@ public function away(ConfigureAwayAdminRequest $request, ?array $options = null)
$statusCode = $response->getStatusCode();
if ($statusCode >= 200 && $statusCode < 400) {
$json = $response->getBody()->getContents();
if (empty($json)) {
return null;
}
return Admin::fromJson($json);
}
} catch (JsonException $e) {
Expand Down Expand Up @@ -298,11 +304,11 @@ public function list(?array $options = null): AdminList
* queryParameters?: array<string, mixed>,
* bodyProperties?: array<string, mixed>,
* } $options
* @return Admin
* @return ?Admin
* @throws IntercomException
* @throws IntercomApiException
*/
public function find(FindAdminRequest $request, ?array $options = null): Admin
public function find(FindAdminRequest $request, ?array $options = null): ?Admin
{
$options = array_merge($this->options, $options ?? []);
try {
Expand All @@ -317,6 +323,9 @@ public function find(FindAdminRequest $request, ?array $options = null): Admin
$statusCode = $response->getStatusCode();
if ($statusCode >= 200 && $statusCode < 400) {
$json = $response->getBody()->getContents();
if (empty($json)) {
return null;
}
return Admin::fromJson($json);
}
} catch (JsonException $e) {
Expand Down
39 changes: 32 additions & 7 deletions src/Admins/Requests/ConfigureAwayAdminRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class ConfigureAwayAdminRequest extends JsonSerializableType
{
/**
* @var string $adminId The unique identifier of a given admin
* @var int $adminId The unique identifier of a given admin
*/
private string $adminId;
private int $adminId;

/**
* @var bool $awayModeEnabled Set to "true" to change the status of the admin to away.
Expand All @@ -24,11 +24,18 @@ class ConfigureAwayAdminRequest extends JsonSerializableType
#[JsonProperty('away_mode_reassign')]
private bool $awayModeReassign;

/**
* @var ?int $awayStatusReasonId The unique identifier of the away status reason
*/
#[JsonProperty('away_status_reason_id')]
private ?int $awayStatusReasonId;

/**
* @param array{
* adminId: string,
* adminId: int,
* awayModeEnabled: bool,
* awayModeReassign: bool,
* awayStatusReasonId?: ?int,
* } $values
*/
public function __construct(
Expand All @@ -37,20 +44,21 @@ public function __construct(
$this->adminId = $values['adminId'];
$this->awayModeEnabled = $values['awayModeEnabled'];
$this->awayModeReassign = $values['awayModeReassign'];
$this->awayStatusReasonId = $values['awayStatusReasonId'] ?? null;
}

/**
* @return string
* @return int
*/
public function getAdminId(): string
public function getAdminId(): int
{
return $this->adminId;
}

/**
* @param string $value
* @param int $value
*/
public function setAdminId(string $value): self
public function setAdminId(int $value): self
{
$this->adminId = $value;
return $this;
Expand Down Expand Up @@ -89,4 +97,21 @@ public function setAwayModeReassign(bool $value): self
$this->awayModeReassign = $value;
return $this;
}

/**
* @return ?int
*/
public function getAwayStatusReasonId(): ?int
{
return $this->awayStatusReasonId;
}

/**
* @param ?int $value
*/
public function setAwayStatusReasonId(?int $value = null): self
{
$this->awayStatusReasonId = $value;
return $this;
}
}
14 changes: 7 additions & 7 deletions src/Admins/Requests/FindAdminRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
class FindAdminRequest extends JsonSerializableType
{
/**
* @var string $adminId The unique identifier of a given admin
* @var int $adminId The unique identifier of a given admin
*/
private string $adminId;
private int $adminId;

/**
* @param array{
* adminId: string,
* adminId: int,
* } $values
*/
public function __construct(
Expand All @@ -23,17 +23,17 @@ public function __construct(
}

/**
* @return string
* @return int
*/
public function getAdminId(): string
public function getAdminId(): int
{
return $this->adminId;
}

/**
* @param string $value
* @param int $value
*/
public function setAdminId(string $value): self
public function setAdminId(int $value): self
{
$this->adminId = $value;
return $this;
Expand Down
47 changes: 36 additions & 11 deletions src/Admins/Types/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Admin extends JsonSerializableType
{
/**
* @var ?'admin' $type String representing the object's type. Always has the value `admin`.
* @var ?string $type String representing the object's type. Always has the value `admin`.
*/
#[JsonProperty('type')]
private ?string $type;
Expand Down Expand Up @@ -54,6 +54,12 @@ class Admin extends JsonSerializableType
#[JsonProperty('away_mode_reassign')]
private bool $awayModeReassign;

/**
* @var ?int $awayStatusReasonId The unique identifier of the away status reason
*/
#[JsonProperty('away_status_reason_id')]
private ?int $awayStatusReasonId;

/**
* @var bool $hasInboxSeat Identifies if this admin has a paid inbox seat to restrict/allow features that require them.
*/
Expand All @@ -67,10 +73,10 @@ class Admin extends JsonSerializableType
private array $teamIds;

/**
* @var ?AdminAvatar $avatar The avatar object associated with the admin
* @var ?string $avatar Image for the associated team or teammate
*/
#[JsonProperty('avatar')]
private ?AdminAvatar $avatar;
private ?string $avatar;

/**
* @var ?TeamPriorityLevel $teamPriorityLevel
Expand All @@ -87,9 +93,10 @@ class Admin extends JsonSerializableType
* awayModeReassign: bool,
* hasInboxSeat: bool,
* teamIds: array<int>,
* type?: ?'admin',
* type?: ?string,
* jobTitle?: ?string,
* avatar?: ?AdminAvatar,
* awayStatusReasonId?: ?int,
* avatar?: ?string,
* teamPriorityLevel?: ?TeamPriorityLevel,
* } $values
*/
Expand All @@ -103,22 +110,23 @@ public function __construct(
$this->jobTitle = $values['jobTitle'] ?? null;
$this->awayModeEnabled = $values['awayModeEnabled'];
$this->awayModeReassign = $values['awayModeReassign'];
$this->awayStatusReasonId = $values['awayStatusReasonId'] ?? null;
$this->hasInboxSeat = $values['hasInboxSeat'];
$this->teamIds = $values['teamIds'];
$this->avatar = $values['avatar'] ?? null;
$this->teamPriorityLevel = $values['teamPriorityLevel'] ?? null;
}

/**
* @return ?'admin'
* @return ?string
*/
public function getType(): ?string
{
return $this->type;
}

/**
* @param ?'admin' $value
* @param ?string $value
*/
public function setType(?string $value = null): self
{
Expand Down Expand Up @@ -228,6 +236,23 @@ public function setAwayModeReassign(bool $value): self
return $this;
}

/**
* @return ?int
*/
public function getAwayStatusReasonId(): ?int
{
return $this->awayStatusReasonId;
}

/**
* @param ?int $value
*/
public function setAwayStatusReasonId(?int $value = null): self
{
$this->awayStatusReasonId = $value;
return $this;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -263,17 +288,17 @@ public function setTeamIds(array $value): self
}

/**
* @return ?AdminAvatar
* @return ?string
*/
public function getAvatar(): ?AdminAvatar
public function getAvatar(): ?string
{
return $this->avatar;
}

/**
* @param ?AdminAvatar $value
* @param ?string $value
*/
public function setAvatar(?AdminAvatar $value = null): self
public function setAvatar(?string $value = null): self
{
$this->avatar = $value;
return $this;
Expand Down
Loading