diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index bc38754a..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,38 +0,0 @@ -version: 2 -jobs: - test-7.4: &test-template - docker: - - image: circleci/php:7.4 - - working_directory: ~/intercom-php - - steps: - - checkout - - run: composer validate --strict - - run: composer install --no-interaction --no-suggest --prefer-dist - - run: vendor/bin/phpunit - - run: vendor/bin/phpcs --standard=PSR2 src tests - - test-7.3: - <<: *test-template - docker: - - image: circleci/php:7.3 - - test-7.2: - <<: *test-template - docker: - - image: circleci/php:7.2 - - test-7.1: - <<: *test-template - docker: - - image: circleci/php:7.1 - -workflows: - version: 2 - test_on_supported_php_versions: - jobs: - - test-7.4 - - test-7.3 - - test-7.2 - - test-7.1 diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 6b910f17..00000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,2 +0,0 @@ -exclude_paths: - - tests/* diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 4517a938..00000000 --- a/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_size = 4 -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -[*.md] -trim_trailing_whitespace = false - -[*.yml] -indent_size = 2 diff --git a/.fernignore b/.fernignore new file mode 100644 index 00000000..084a8ebb --- /dev/null +++ b/.fernignore @@ -0,0 +1 @@ +# Specify files that shouldn't be modified by Fern diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index f5cd687b..00000000 --- a/.gitattributes +++ /dev/null @@ -1,10 +0,0 @@ -* text=auto - -/.circleci export-ignore -/.github export-ignore -/tests export-ignore -.codeclimate.yml export-ignore -.editorconfig export-ignore -.gitattributes export-ignore -.gitignore export-ignore -phpunit.xml.dist export-ignore diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index ee7d44bc..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,20 +0,0 @@ -Please use the following template to submit your issue. Following this template will allow us to quickly investigate and help you with your issue. Please be aware that issues which do not conform to this template may be closed. - -For feature requests please contact us at team@intercom.io - - -## Version info - - intercom-php version: - - Intercom API version: - - PHP version: - -## Expected behavior - -## Actual behavior - -## Steps to reproduce (as granular as possible, including screenshots where appropriate) - 1. - 2. - 3. - -## Logs diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 7c94e728..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,5 +0,0 @@ -#### Why? -Why are you making this change? - -#### How? -Technical details on your change diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index ffa55689..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "composer" - directory: "/" - schedule: - interval: "weekly" - open-pull-requests-limit: 5 - commit-message: - prefix: "chore" - - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..258bf33a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: ci + +on: [push] + +jobs: + compile: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.1" + + - name: Install tools + run: | + composer install + + - name: Build + run: | + composer build + + - name: Analyze + run: | + composer analyze + + unit-tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.1" + + - name: Install tools + run: | + composer install + + - name: Run Tests + run: | + composer test \ No newline at end of file diff --git a/.github/workflows/label-ai-generated-prs.yml b/.github/workflows/label-ai-generated-prs.yml deleted file mode 100644 index 547cbfec..00000000 --- a/.github/workflows/label-ai-generated-prs.yml +++ /dev/null @@ -1,11 +0,0 @@ -# .github/workflows/label-ai-generated-prs.yml -name: Label AI-generated PRs - -on: - pull_request: - types: [opened, edited, synchronize] # run when the body changes too - -jobs: - call-label-ai-prs: - uses: intercom/github-action-workflows/.github/workflows/label-ai-prs.yml@main - secrets: inherit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6466b0cf..31a1aeb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -/vendor -composer.lock - -# PHPUnit -phpunit.phar -phpunit.xml +.idea +.php-cs-fixer.cache .phpunit.result.cache +composer.lock +vendor/ \ No newline at end of file diff --git a/CHANGES.txt b/CHANGES.txt deleted file mode 100644 index a28d7278..00000000 --- a/CHANGES.txt +++ /dev/null @@ -1,110 +0,0 @@ -Changes -========= -2.0.0 - -- Major rewrite using Guzzle 6 - -1.5.0 - -- Adds `created_since` when listing users - -1.4.0 - -- Adds `order` when listing users - -1.3.2 - -- Adds bulk support for both users and events. -- Adds support for viewing bulk job info. - -1.3.1 - -- Fixes paging - -1.3.0 - -- Adds support for the Bulk API (Users) - -1.2.3 - -- Fixes Contacts iterator - -1.2.2 - -- Adding Contacts iterator - -1.2.1 - -- Metadata fix - -1.2.0 - -- Support opening, closing, and assigning conversations - -1.1.1 - -- Fix encoding for empty event metadata -- Fix error response when receiving ELB error - -1.1.0 - -- Acquire support - -1.0.0 - -- Releasing version 1.0.0 - -1.0.0-b12 - -- Remove Id requirement on userUpdate, thanks @rb-cohen - -1.0.0-b11 - -- Add support for `signed_up_at` - -1.0.0-b10 - -- Add support for Admin replies to conversations - -1.0.0-b9 - -- Add support for the update_last_request_at parameter on creating users -- Add support for the new_session parameter on updating users - -1.0.0-b8 - -- Added support for the new_session parameter when creating users, thanks @FallDi - -1.0.0-b7 - -- Removed requirement for admin_id on note creation - -1.0.0-b6 - -- Added rate limit details to response, thanks @ziemkowski -- Improve conversation fetching for admins/users, thanks @ziemkowski - -1.0.0-b5 - -- Packagist -- Licence & Readme updates - -1.0.0-b4 - -- Fix /events response being parsed as JSON - -1.0.0-b3 - -- Add remote_created_at to user update and create. - -1.0.0-b2 - - - Add a user-agent string to the default headers - - Set the accept header to be application/json - - Make user the default type for a conversations query (fix for https://github.com/intercom/intercom-php/issues/41) - - Populate exceptions with errors from the response (fix for https://github.com/intercom/intercom-php/issues/37) - - Fix directory names on Linux for composer (fix for https://github.com/intercom/intercom-php/issues/38) - -1.0.0-b1 - - - initial beta release diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 9defd179..00000000 --- a/LICENSE +++ /dev/null @@ -1,12 +0,0 @@ -Copyright 2014 Intercom, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy of the -License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed -under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR -CONDITIONS OF ANY KIND, either express or implied. See the License for the -specific language governing permissions and limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 3fd8ad38..608ce53f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ -# intercom-php +# Intercom PHP Library -[![Circle CI](https://circleci.com/gh/intercom/intercom-php.png?style=shield)](https://circleci.com/gh/intercom/intercom-php) -[![packagist](https://img.shields.io/packagist/v/intercom/intercom-php.svg)](https://packagist.org/packages/intercom/intercom-php) -![Intercom API Version](https://img.shields.io/badge/Intercom%20API%20Version-1.3-blue) +[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fintercom%2Fintercom-php) +[![php shield](https://img.shields.io/badge/php-packagist-pink)](https://packagist.org/packages/intercom/intercom-php) -> Official PHP bindings to the [Intercom API](https://api.intercom.io/docs) +The Intercom PHP library provides convenient access to the Intercom API from PHP. ## Project Updates @@ -18,14 +17,8 @@ We'll communicate all relevant updates as we build this new team and support str ## Installation -This library supports PHP 7.1 and later - -This library uses [HTTPlug](https://github.com/php-http/httplug) as HTTP client. HTTPlug is an abstraction that allows this library to support many different HTTP Clients. Therefore, you need to provide it with an adapter for the HTTP library you prefer. You can find all the available adapters [in Packagist](https://packagist.org/providers/php-http/client-implementation). This documentation assumes you use the Guzzle6 Client, but you can replace it with any adapter that you prefer. - -The recommended way to install intercom-php is through [Composer](https://getcomposer.org): - ```sh -composer require intercom/intercom-php php-http/guzzle6-adapter +composer require intercom/intercom-php ``` ## Clients @@ -569,28 +562,33 @@ For more info on rate limits and these headers please see the [API reference doc ## Pagination -When listing, the Intercom API may return a pagination object: +List endpoints return a `Pager` which lets you loop over all items and the SDK will automatically make multiple HTTP requests for you. -```json -{ - "pages": { - "next": "..." - } -} -``` +```php +use Intercom\IntercomClient; -You can grab the next page of results using the client: +$client = new IntercomClient( + '', + ['baseUrl' => 'https://api.example.com'], +); -```php -$client->nextPage($response->pages); -``` +$items = $client->articles->list(['limit' => 10]); -In API versions 2.0 and above subsequent pages for listing contacts can be retreived with: +foreach ($items as $item) { + var_dump($item); +} +``` +You can also iterate page-by-page: ```php -$client->nextCursor($response->pages); +foreach ($items->getPages() as $page) { + foreach ($page->getItems() as $pageItem) { + var_dump($pageItem); + } +} ``` + ## Scroll The first time you use the scroll API you can just send a simple GET request. @@ -653,3 +651,131 @@ try { - **Send coherent history**. Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before sending them to us. + +## Requirements + +This SDK requires PHP ^8.1. + +## Usage + +Instantiate and use the client with the following: + +```php +', +); +$client->articles->create( + new CreateArticleRequest([ + 'title' => 'Thanks for everything', + 'description' => 'Description of the Article', + 'body' => 'Body of the Article', + 'authorId' => 1295, + 'state' => CreateArticleRequestState::Published->value, + ]), +); + +``` + +## Exception Handling + +When the API returns a non-success status code (4xx or 5xx response), an exception will be thrown. + +```php +use Intercom\Exceptions\IntercomApiException; +use Intercom\Exceptions\IntercomException; + +try { + $response = $client->articles->create(...); +} catch (IntercomApiException $e) { + echo 'API Exception occurred: ' . $e->getMessage() . "\n"; + echo 'Status Code: ' . $e->getCode() . "\n"; + echo 'Response Body: ' . $e->getBody() . "\n"; + // Optionally, rethrow the exception or handle accordingly. +} +``` + +## Advanced + +### Custom Client + +This SDK is built to work with any HTTP client that implements Guzzle's `ClientInterface`. +By default, if no client is provided, the SDK will use Guzzle's default HTTP client. +However, you can pass your own client that adheres to `ClientInterface`: + +```php +use Intercom\IntercomClient; + +// Create a custom Guzzle client with specific configuration. +$customClient = new \GuzzleHttp\Client([ + 'timeout' => 5.0, +]); + +// Pass the custom client when creating an instance of the class. +$client = new IntercomClient(options: [ + 'client' => $customClient +]); + +// You can also utilize the same technique to leverage advanced customizations to the client such as adding middleware +$handlerStack = \GuzzleHttp\HandlerStack::create(); +$handlerStack->push(MyCustomMiddleware::create()); +$customClient = new \GuzzleHttp\Client(['handler' => $handlerStack]); + +// Pass the custom client when creating an instance of the class. +$client = new IntercomClient(options: [ + 'client' => $customClient +]); +``` + +### Retries + +The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long +as the request is deemed retryable and the number of retry attempts has not grown larger than the configured +retry limit (default: 2). + +A request is deemed retryable when any of the following HTTP status codes is returned: + +- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout) +- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests) +- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors) + +Use the `maxRetries` request option to configure this behavior. + +```php +$response = $client->articles->create( + ..., + options: [ + 'maxRetries' => 0 // Override maxRetries at the request level + ] +); +``` + +### Timeouts + +The SDK defaults to a 30 second timeout. Use the `timeout` option to configure this behavior. + +```php +$response = $client->articles->create( + ..., + options: [ + 'timeout' => 3.0 // Override timeout to 3 seconds + ] +); +``` + +## Contributing + +While we value open-source contributions to this SDK, this library is generated programmatically. +Additions made directly to this library would have to be moved over to our generation code, +otherwise they would be overwritten upon the next generated release. Feel free to open a PR as +a proof of concept, but know that we will not be able to merge it as-is. We suggest opening +an issue first to discuss with us! + +On the other hand, contributions to the README are always very welcome! \ No newline at end of file diff --git a/composer.json b/composer.json index 8fe5ee93..66963bdc 100644 --- a/composer.json +++ b/composer.json @@ -1,57 +1,44 @@ { - "name": "intercom/intercom-php", - "description": "Intercom API client built on top of HTTPlug", - "keywords": [ - "api", - "guzzle", - "intercom", - "intercom.io" - ], - "license": "Apache-2.0", - "authors": [ - { - "name": "Intercom Platform Team", - "homepage": "https://www.intercom.com" - } - ], - "support": { - "issues": "https://github.com/intercom/intercom-php/issues", - "source": "https://github.com/intercom/intercom-php" - }, - "autoload": { - "psr-4": { - "Intercom\\": [ - "src" - ] - } - }, - "autoload-dev": { - "psr-4": { - "Intercom\\Test\\": [ - "tests" - ] - } - }, - "require": { - "php": ">= 7.1", - "ext-json": "*", - "php-http/client-common": "^1.9 || ^2.0", - "php-http/client-implementation": "^1.0", - "php-http/discovery": "^1.4", - "php-http/httplug": "^1.0 || ^2.0", - "php-http/message": "^1.7", - "psr/http-message": "^1.0 || ^2.0" - }, - "require-dev": { - "nyholm/psr7": "^1.6.1", - "php-http/mock-client": "^1.4", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", - "squizlabs/php_codesniffer": "^3.1" - }, - "config": { - "sort-packages": true, - "allow-plugins": { - "php-http/discovery": false - } + "name": "intercom/intercom-php", + "version": "0.0.325", + "description": "Intercom API client.", + "keywords": [ + "intercom", + "api", + "sdk" + ], + "license": [], + "require": { + "php": "^8.1", + "ext-json": "*", + "guzzlehttp/guzzle": "^7.4" + }, + "require-dev": { + "phpunit/phpunit": "^9.0", + "friendsofphp/php-cs-fixer": "3.5.0", + "phpstan/phpstan": "^1.12" + }, + "autoload": { + "psr-4": { + "Intercom\\": "src/" } -} + }, + "autoload-dev": { + "psr-4": { + "Intercom\\Tests\\": "tests/" + } + }, + "scripts": { + "build": [ + "@php -l src", + "@php -l tests" + ], + "test": "phpunit", + "analyze": "phpstan analyze src tests --memory-limit=1G" + }, + "author": { + "name": "Intercom Platform Team", + "url": "https://www.intercom.com" + }, + "homepage": "https://developers.intercom.com/docs" +} \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..780706b8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: max + reportUnmatchedIgnoredErrors: false + paths: + - src + - tests \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..54630a51 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,7 @@ + + + + tests + + + \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 19cad74e..00000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,17 +0,0 @@ - - - - - ./tests/ - - - diff --git a/src/Admins/AdminsClient.php b/src/Admins/AdminsClient.php new file mode 100644 index 00000000..82600c0c --- /dev/null +++ b/src/Admins/AdminsClient.php @@ -0,0 +1,343 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * + * You can view the currently authorised admin along with the embedded app object (a "workspace" in legacy terminology). + * + * > 🚧 Single Sign On + * > + * > If you are building a custom "Log in with Intercom" flow for your site, and you call the `/me` endpoint to identify the logged-in user, you should not accept any sign-ins from users with unverified email addresses as it poses a potential impersonation security risk. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return AdminWithApp + * @throws IntercomException + * @throws IntercomApiException + */ + public function identify(?array $options = null): AdminWithApp + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "me", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return AdminWithApp::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can set an Admin as away for the Inbox. + * + * @param ConfigureAwayAdminRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Admin + * @throws IntercomException + * @throws IntercomApiException + */ + public function away(ConfigureAwayAdminRequest $request, ?array $options = null): Admin + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins/{$request->getAdminId()}/away", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Admin::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can get a log of activities by all admins in an app. + * + * @param ListAllActivityLogsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ActivityLogList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAllActivityLogs(ListAllActivityLogsRequest $request, ?array $options = null): ActivityLogList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['created_at_after'] = $request->getCreatedAtAfter(); + if ($request->getCreatedAtBefore() != null) { + $query['created_at_before'] = $request->getCreatedAtBefore(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins/activity_logs", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ActivityLogList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of admins for a given workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return AdminList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): AdminList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return AdminList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can retrieve the details of a single admin. + * + * @param FindAdminRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Admin + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindAdminRequest $request, ?array $options = null): Admin + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins/{$request->getAdminId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Admin::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Admins/Requests/ConfigureAwayAdminRequest.php b/src/Admins/Requests/ConfigureAwayAdminRequest.php new file mode 100644 index 00000000..37cee6de --- /dev/null +++ b/src/Admins/Requests/ConfigureAwayAdminRequest.php @@ -0,0 +1,92 @@ +adminId = $values['adminId']; + $this->awayModeEnabled = $values['awayModeEnabled']; + $this->awayModeReassign = $values['awayModeReassign']; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeEnabled(): bool + { + return $this->awayModeEnabled; + } + + /** + * @param bool $value + */ + public function setAwayModeEnabled(bool $value): self + { + $this->awayModeEnabled = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeReassign(): bool + { + return $this->awayModeReassign; + } + + /** + * @param bool $value + */ + public function setAwayModeReassign(bool $value): self + { + $this->awayModeReassign = $value; + return $this; + } +} diff --git a/src/Admins/Requests/FindAdminRequest.php b/src/Admins/Requests/FindAdminRequest.php new file mode 100644 index 00000000..3145be73 --- /dev/null +++ b/src/Admins/Requests/FindAdminRequest.php @@ -0,0 +1,41 @@ +adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Admins/Requests/ListAllActivityLogsRequest.php b/src/Admins/Requests/ListAllActivityLogsRequest.php new file mode 100644 index 00000000..969c2882 --- /dev/null +++ b/src/Admins/Requests/ListAllActivityLogsRequest.php @@ -0,0 +1,65 @@ +createdAtAfter = $values['createdAtAfter']; + $this->createdAtBefore = $values['createdAtBefore'] ?? null; + } + + /** + * @return string + */ + public function getCreatedAtAfter(): string + { + return $this->createdAtAfter; + } + + /** + * @param string $value + */ + public function setCreatedAtAfter(string $value): self + { + $this->createdAtAfter = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCreatedAtBefore(): ?string + { + return $this->createdAtBefore; + } + + /** + * @param ?string $value + */ + public function setCreatedAtBefore(?string $value = null): self + { + $this->createdAtBefore = $value; + return $this; + } +} diff --git a/src/Admins/Types/Admin.php b/src/Admins/Types/Admin.php new file mode 100644 index 00000000..6a012346 --- /dev/null +++ b/src/Admins/Types/Admin.php @@ -0,0 +1,306 @@ + $teamIds This object represents the avatar associated with the admin. + */ + #[JsonProperty('team_ids'), ArrayType(['integer'])] + private array $teamIds; + + /** + * @var ?AdminAvatar $avatar The avatar object associated with the admin + */ + #[JsonProperty('avatar')] + private ?AdminAvatar $avatar; + + /** + * @var ?TeamPriorityLevel $teamPriorityLevel + */ + #[JsonProperty('team_priority_level')] + private ?TeamPriorityLevel $teamPriorityLevel; + + /** + * @param array{ + * id: string, + * name: string, + * email: string, + * awayModeEnabled: bool, + * awayModeReassign: bool, + * hasInboxSeat: bool, + * teamIds: array, + * type?: ?'admin', + * jobTitle?: ?string, + * avatar?: ?AdminAvatar, + * teamPriorityLevel?: ?TeamPriorityLevel, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id']; + $this->name = $values['name']; + $this->email = $values['email']; + $this->jobTitle = $values['jobTitle'] ?? null; + $this->awayModeEnabled = $values['awayModeEnabled']; + $this->awayModeReassign = $values['awayModeReassign']; + $this->hasInboxSeat = $values['hasInboxSeat']; + $this->teamIds = $values['teamIds']; + $this->avatar = $values['avatar'] ?? null; + $this->teamPriorityLevel = $values['teamPriorityLevel'] ?? null; + } + + /** + * @return ?'admin' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'admin' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getJobTitle(): ?string + { + return $this->jobTitle; + } + + /** + * @param ?string $value + */ + public function setJobTitle(?string $value = null): self + { + $this->jobTitle = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeEnabled(): bool + { + return $this->awayModeEnabled; + } + + /** + * @param bool $value + */ + public function setAwayModeEnabled(bool $value): self + { + $this->awayModeEnabled = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeReassign(): bool + { + return $this->awayModeReassign; + } + + /** + * @param bool $value + */ + public function setAwayModeReassign(bool $value): self + { + $this->awayModeReassign = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasInboxSeat(): bool + { + return $this->hasInboxSeat; + } + + /** + * @param bool $value + */ + public function setHasInboxSeat(bool $value): self + { + $this->hasInboxSeat = $value; + return $this; + } + + /** + * @return array + */ + public function getTeamIds(): array + { + return $this->teamIds; + } + + /** + * @param array $value + */ + public function setTeamIds(array $value): self + { + $this->teamIds = $value; + return $this; + } + + /** + * @return ?AdminAvatar + */ + public function getAvatar(): ?AdminAvatar + { + return $this->avatar; + } + + /** + * @param ?AdminAvatar $value + */ + public function setAvatar(?AdminAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?TeamPriorityLevel + */ + public function getTeamPriorityLevel(): ?TeamPriorityLevel + { + return $this->teamPriorityLevel; + } + + /** + * @param ?TeamPriorityLevel $value + */ + public function setTeamPriorityLevel(?TeamPriorityLevel $value = null): self + { + $this->teamPriorityLevel = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Admins/Types/AdminAvatar.php b/src/Admins/Types/AdminAvatar.php new file mode 100644 index 00000000..b0a255c0 --- /dev/null +++ b/src/Admins/Types/AdminAvatar.php @@ -0,0 +1,54 @@ +imageUrl = $values['imageUrl']; + } + + /** + * @return string + */ + public function getImageUrl(): string + { + return $this->imageUrl; + } + + /** + * @param string $value + */ + public function setImageUrl(string $value): self + { + $this->imageUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/AiAgent/Types/AiAgent.php b/src/AiAgent/Types/AiAgent.php new file mode 100644 index 00000000..76dc4b71 --- /dev/null +++ b/src/AiAgent/Types/AiAgent.php @@ -0,0 +1,205 @@ + $sourceType The type of the source that triggered AI Agent involvement in the conversation. + */ + #[JsonProperty('source_type')] + private string $sourceType; + + /** + * @var ?string $sourceTitle The title of the source that triggered AI Agent involvement in the conversation. If this is `essentials_plan_setup` then it will return `null`. + */ + #[JsonProperty('source_title')] + private ?string $sourceTitle; + + /** + * @var ?string $lastAnswerType The type of the last answer delivered by AI Agent. If no answer was delivered then this will return `null` + */ + #[JsonProperty('last_answer_type')] + private ?string $lastAnswerType; + + /** + * @var ?string $resolutionState The resolution state of AI Agent. If no AI or custom answer has been delivered then this will return `null`. + */ + #[JsonProperty('resolution_state')] + private ?string $resolutionState; + + /** + * @var ?int $rating The customer satisfaction rating given to AI Agent, from 1-5. + */ + #[JsonProperty('rating')] + private ?int $rating; + + /** + * @var ?string $ratingRemark The customer satisfaction rating remark given to AI Agent. + */ + #[JsonProperty('rating_remark')] + private ?string $ratingRemark; + + /** + * @var ?ContentSourcesList $contentSources + */ + #[JsonProperty('content_sources')] + private ?ContentSourcesList $contentSources; + + /** + * @param array{ + * sourceType: value-of, + * sourceTitle?: ?string, + * lastAnswerType?: ?string, + * resolutionState?: ?string, + * rating?: ?int, + * ratingRemark?: ?string, + * contentSources?: ?ContentSourcesList, + * } $values + */ + public function __construct( + array $values, + ) { + $this->sourceType = $values['sourceType']; + $this->sourceTitle = $values['sourceTitle'] ?? null; + $this->lastAnswerType = $values['lastAnswerType'] ?? null; + $this->resolutionState = $values['resolutionState'] ?? null; + $this->rating = $values['rating'] ?? null; + $this->ratingRemark = $values['ratingRemark'] ?? null; + $this->contentSources = $values['contentSources'] ?? null; + } + + /** + * @return value-of + */ + public function getSourceType(): string + { + return $this->sourceType; + } + + /** + * @param value-of $value + */ + public function setSourceType(string $value): self + { + $this->sourceType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSourceTitle(): ?string + { + return $this->sourceTitle; + } + + /** + * @param ?string $value + */ + public function setSourceTitle(?string $value = null): self + { + $this->sourceTitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLastAnswerType(): ?string + { + return $this->lastAnswerType; + } + + /** + * @param ?string $value + */ + public function setLastAnswerType(?string $value = null): self + { + $this->lastAnswerType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getResolutionState(): ?string + { + return $this->resolutionState; + } + + /** + * @param ?string $value + */ + public function setResolutionState(?string $value = null): self + { + $this->resolutionState = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRating(): ?int + { + return $this->rating; + } + + /** + * @param ?int $value + */ + public function setRating(?int $value = null): self + { + $this->rating = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRatingRemark(): ?string + { + return $this->ratingRemark; + } + + /** + * @param ?string $value + */ + public function setRatingRemark(?string $value = null): self + { + $this->ratingRemark = $value; + return $this; + } + + /** + * @return ?ContentSourcesList + */ + public function getContentSources(): ?ContentSourcesList + { + return $this->contentSources; + } + + /** + * @param ?ContentSourcesList $value + */ + public function setContentSources(?ContentSourcesList $value = null): self + { + $this->contentSources = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/AiAgent/Types/AiAgentSourceType.php b/src/AiAgent/Types/AiAgentSourceType.php new file mode 100644 index 00000000..a8a2108a --- /dev/null +++ b/src/AiAgent/Types/AiAgentSourceType.php @@ -0,0 +1,12 @@ +contentType = $values['contentType']; + $this->url = $values['url']; + $this->title = $values['title']; + $this->locale = $values['locale']; + } + + /** + * @return 'custom_answer' + */ + public function getContentType(): string + { + return $this->contentType; + } + + /** + * @param 'custom_answer' $value + */ + public function setContentType(string $value): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return string + */ + public function getLocale(): string + { + return $this->locale; + } + + /** + * @param string $value + */ + public function setLocale(string $value): self + { + $this->locale = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/ArticlesClient.php b/src/Articles/ArticlesClient.php new file mode 100644 index 00000000..cc81580c --- /dev/null +++ b/src/Articles/ArticlesClient.php @@ -0,0 +1,458 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all articles by making a GET request to `https://api.intercom.io/articles`. + * + * > 📘 How are the articles sorted and ordered? + * > + * > Articles will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated articles first. + * + * @param ListArticlesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListArticlesRequest $request = new ListArticlesRequest(), ?array $options = null): Pager + { + return new OffsetPager( + request: $request, + getNextPage: fn (ListArticlesRequest $request) => $this->_list($request, $options), + /* @phpstan-ignore-next-line */ + getOffset: fn (ListArticlesRequest $request) => $request?->getPage() ?? 0, + setOffset: function (ListArticlesRequest $request, int $offset) { + $request->setPage($offset); + }, + getStep: null, + /* @phpstan-ignore-next-line */ + getItems: fn (ArticleList $response) => $response?->getData() ?? [], + /* @phpstan-ignore-next-line */ + hasNextPage: null, + ); + } + + /** + * You can create a new article by making a POST request to `https://api.intercom.io/articles`. + * + * @param CreateArticleRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Article + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateArticleRequest $request, ?array $options = null): Article + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Article::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single article by making a GET request to `https://api.intercom.io/articles/`. + * + * @param FindArticleRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Article + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindArticleRequest $request, ?array $options = null): Article + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/{$request->getArticleId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Article::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update the details of a single article by making a PUT request to `https://api.intercom.io/articles/`. + * + * @param UpdateArticleRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Article + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateArticleRequest $request, ?array $options = null): Article + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/{$request->getArticleId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Article::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single article by making a DELETE request to `https://api.intercom.io/articles/`. + * + * @param DeleteArticleRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedArticleObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function delete(DeleteArticleRequest $request, ?array $options = null): DeletedArticleObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/{$request->getArticleId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedArticleObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for articles by making a GET request to `https://api.intercom.io/articles/search`. + * + * @param SearchArticlesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SearchArticlesResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function search(SearchArticlesRequest $request = new SearchArticlesRequest(), ?array $options = null): SearchArticlesResponse + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPhrase() != null) { + $query['phrase'] = $request->getPhrase(); + } + if ($request->getState() != null) { + $query['state'] = $request->getState(); + } + if ($request->getHelpCenterId() != null) { + $query['help_center_id'] = $request->getHelpCenterId(); + } + if ($request->getHighlight() != null) { + $query['highlight'] = $request->getHighlight(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/search", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SearchArticlesResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all articles by making a GET request to `https://api.intercom.io/articles`. + * + * > 📘 How are the articles sorted and ordered? + * > + * > Articles will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated articles first. + * + * @param ListArticlesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ArticleList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListArticlesRequest $request = new ListArticlesRequest(), ?array $options = null): ArticleList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ArticleList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Articles/Requests/CreateArticleRequest.php b/src/Articles/Requests/CreateArticleRequest.php new file mode 100644 index 00000000..c38aee4b --- /dev/null +++ b/src/Articles/Requests/CreateArticleRequest.php @@ -0,0 +1,221 @@ + $state Whether the article will be `published` or will be a `draft`. Defaults to draft. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?int $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?int $parentId; + + /** + * @var ?value-of $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @param array{ + * title: string, + * authorId: int, + * description?: ?string, + * body?: ?string, + * state?: ?value-of, + * parentId?: ?int, + * parentType?: ?value-of, + * translatedContent?: ?ArticleTranslatedContent, + * } $values + */ + public function __construct( + array $values, + ) { + $this->title = $values['title']; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId']; + $this->state = $values['state'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getAuthorId(): int + { + return $this->authorId; + } + + /** + * @param int $value + */ + public function setAuthorId(int $value): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getParentId(): ?int + { + return $this->parentId; + } + + /** + * @param ?int $value + */ + public function setParentId(?int $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?value-of $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } +} diff --git a/src/Articles/Requests/DeleteArticleRequest.php b/src/Articles/Requests/DeleteArticleRequest.php new file mode 100644 index 00000000..ecc8079f --- /dev/null +++ b/src/Articles/Requests/DeleteArticleRequest.php @@ -0,0 +1,41 @@ +articleId = $values['articleId']; + } + + /** + * @return string + */ + public function getArticleId(): string + { + return $this->articleId; + } + + /** + * @param string $value + */ + public function setArticleId(string $value): self + { + $this->articleId = $value; + return $this; + } +} diff --git a/src/Articles/Requests/FindArticleRequest.php b/src/Articles/Requests/FindArticleRequest.php new file mode 100644 index 00000000..ff372e28 --- /dev/null +++ b/src/Articles/Requests/FindArticleRequest.php @@ -0,0 +1,41 @@ +articleId = $values['articleId']; + } + + /** + * @return string + */ + public function getArticleId(): string + { + return $this->articleId; + } + + /** + * @param string $value + */ + public function setArticleId(string $value): self + { + $this->articleId = $value; + return $this; + } +} diff --git a/src/Articles/Requests/ListArticlesRequest.php b/src/Articles/Requests/ListArticlesRequest.php new file mode 100644 index 00000000..3feab27e --- /dev/null +++ b/src/Articles/Requests/ListArticlesRequest.php @@ -0,0 +1,65 @@ +page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Articles/Requests/SearchArticlesRequest.php b/src/Articles/Requests/SearchArticlesRequest.php new file mode 100644 index 00000000..f563cd11 --- /dev/null +++ b/src/Articles/Requests/SearchArticlesRequest.php @@ -0,0 +1,113 @@ +phrase = $values['phrase'] ?? null; + $this->state = $values['state'] ?? null; + $this->helpCenterId = $values['helpCenterId'] ?? null; + $this->highlight = $values['highlight'] ?? null; + } + + /** + * @return ?string + */ + public function getPhrase(): ?string + { + return $this->phrase; + } + + /** + * @param ?string $value + */ + public function setPhrase(?string $value = null): self + { + $this->phrase = $value; + return $this; + } + + /** + * @return ?string + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?string $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHelpCenterId(): ?int + { + return $this->helpCenterId; + } + + /** + * @param ?int $value + */ + public function setHelpCenterId(?int $value = null): self + { + $this->helpCenterId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHighlight(): ?bool + { + return $this->highlight; + } + + /** + * @param ?bool $value + */ + public function setHighlight(?bool $value = null): self + { + $this->highlight = $value; + return $this; + } +} diff --git a/src/Articles/Requests/UpdateArticleRequest.php b/src/Articles/Requests/UpdateArticleRequest.php new file mode 100644 index 00000000..fdafae37 --- /dev/null +++ b/src/Articles/Requests/UpdateArticleRequest.php @@ -0,0 +1,245 @@ + $state Whether the article will be `published` or will be a `draft`. Defaults to draft. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?string $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?string $parentId; + + /** + * @var ?value-of $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @param array{ + * articleId: string, + * title?: ?string, + * description?: ?string, + * body?: ?string, + * authorId?: ?int, + * state?: ?value-of, + * parentId?: ?string, + * parentType?: ?value-of, + * translatedContent?: ?ArticleTranslatedContent, + * } $values + */ + public function __construct( + array $values, + ) { + $this->articleId = $values['articleId']; + $this->title = $values['title'] ?? null; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId'] ?? null; + $this->state = $values['state'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + } + + /** + * @return string + */ + public function getArticleId(): string + { + return $this->articleId; + } + + /** + * @param string $value + */ + public function setArticleId(string $value): self + { + $this->articleId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAuthorId(): ?int + { + return $this->authorId; + } + + /** + * @param ?int $value + */ + public function setAuthorId(?int $value = null): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?value-of $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } +} diff --git a/src/Articles/Traits/ArticleListItem.php b/src/Articles/Traits/ArticleListItem.php new file mode 100644 index 00000000..d1747509 --- /dev/null +++ b/src/Articles/Traits/ArticleListItem.php @@ -0,0 +1,399 @@ + $state + * @property int $createdAt + * @property int $updatedAt + * @property ?string $url + * @property ?int $parentId + * @property ?array $parentIds + * @property ?string $parentType + * @property ?string $defaultLocale + * @property ?ArticleTranslatedContent $translatedContent + */ +trait ArticleListItem +{ + /** + * @var ?'article' $type The type of object - `article`. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var string $id The unique identifier for the article which is given by Intercom. + */ + #[JsonProperty('id')] + private string $id; + + /** + * @var string $workspaceId The id of the workspace which the article belongs to. + */ + #[JsonProperty('workspace_id')] + private string $workspaceId; + + /** + * @var string $title The title of the article. For multilingual articles, this will be the title of the default language's content. + */ + #[JsonProperty('title')] + private string $title; + + /** + * @var ?string $description The description of the article. For multilingual articles, this will be the description of the default language's content. + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var ?string $body The body of the article in HTML. For multilingual articles, this will be the body of the default language's content. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var int $authorId The id of the author of the article. For multilingual articles, this will be the id of the author of the default language's content. Must be a teammate on the help center's workspace. + */ + #[JsonProperty('author_id')] + private int $authorId; + + /** + * @var value-of $state Whether the article is `published` or is a `draft`. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private string $state; + + /** + * @var int $createdAt The time when the article was created. For multilingual articles, this will be the timestamp of creation of the default language's content in seconds. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var int $updatedAt The time when the article was last updated. For multilingual articles, this will be the timestamp of last update of the default language's content in seconds. + */ + #[JsonProperty('updated_at')] + private int $updatedAt; + + /** + * @var ?string $url The URL of the article. For multilingual articles, this will be the URL of the default language's content. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?int $parentId; + + /** + * @var ?array $parentIds The ids of the article's parent collections or sections. An article without this field stands alone. + */ + #[JsonProperty('parent_ids'), ArrayType(['integer'])] + private ?array $parentIds; + + /** + * @var ?string $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?string $defaultLocale The default locale of the help center. This field is only returned for multilingual help centers. + */ + #[JsonProperty('default_locale')] + private ?string $defaultLocale; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @return ?'article' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'article' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getAuthorId(): int + { + return $this->authorId; + } + + /** + * @param int $value + */ + public function setAuthorId(int $value): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return value-of + */ + public function getState(): string + { + return $this->state; + } + + /** + * @param value-of $value + */ + public function setState(string $value): self + { + $this->state = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getParentId(): ?int + { + return $this->parentId; + } + + /** + * @param ?int $value + */ + public function setParentId(?int $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getParentIds(): ?array + { + return $this->parentIds; + } + + /** + * @param ?array $value + */ + public function setParentIds(?array $value = null): self + { + $this->parentIds = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?string $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultLocale(): ?string + { + return $this->defaultLocale; + } + + /** + * @param ?string $value + */ + public function setDefaultLocale(?string $value = null): self + { + $this->defaultLocale = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } +} diff --git a/src/Articles/Types/Article.php b/src/Articles/Types/Article.php new file mode 100644 index 00000000..09b9a006 --- /dev/null +++ b/src/Articles/Types/Article.php @@ -0,0 +1,91 @@ +, + * createdAt: int, + * updatedAt: int, + * type?: ?'article', + * description?: ?string, + * body?: ?string, + * url?: ?string, + * parentId?: ?int, + * parentIds?: ?array, + * parentType?: ?string, + * defaultLocale?: ?string, + * translatedContent?: ?ArticleTranslatedContent, + * statistics?: ?ArticleStatistics, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id']; + $this->workspaceId = $values['workspaceId']; + $this->title = $values['title']; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId']; + $this->state = $values['state']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->url = $values['url'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentIds = $values['parentIds'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->defaultLocale = $values['defaultLocale'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->statistics = $values['statistics'] ?? null; + } + + /** + * @return ?ArticleStatistics + */ + public function getStatistics(): ?ArticleStatistics + { + return $this->statistics; + } + + /** + * @param ?ArticleStatistics $value + */ + public function setStatistics(?ArticleStatistics $value = null): self + { + $this->statistics = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/ArticleListItem.php b/src/Articles/Types/ArticleListItem.php new file mode 100644 index 00000000..77521c87 --- /dev/null +++ b/src/Articles/Types/ArticleListItem.php @@ -0,0 +1,431 @@ + $state Whether the article is `published` or is a `draft`. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private string $state; + + /** + * @var int $createdAt The time when the article was created. For multilingual articles, this will be the timestamp of creation of the default language's content in seconds. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var int $updatedAt The time when the article was last updated. For multilingual articles, this will be the timestamp of last update of the default language's content in seconds. + */ + #[JsonProperty('updated_at')] + private int $updatedAt; + + /** + * @var ?string $url The URL of the article. For multilingual articles, this will be the URL of the default language's content. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?int $parentId; + + /** + * @var ?array $parentIds The ids of the article's parent collections or sections. An article without this field stands alone. + */ + #[JsonProperty('parent_ids'), ArrayType(['integer'])] + private ?array $parentIds; + + /** + * @var ?string $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?string $defaultLocale The default locale of the help center. This field is only returned for multilingual help centers. + */ + #[JsonProperty('default_locale')] + private ?string $defaultLocale; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @param array{ + * id: string, + * workspaceId: string, + * title: string, + * authorId: int, + * state: value-of, + * createdAt: int, + * updatedAt: int, + * type?: ?'article', + * description?: ?string, + * body?: ?string, + * url?: ?string, + * parentId?: ?int, + * parentIds?: ?array, + * parentType?: ?string, + * defaultLocale?: ?string, + * translatedContent?: ?ArticleTranslatedContent, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id']; + $this->workspaceId = $values['workspaceId']; + $this->title = $values['title']; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId']; + $this->state = $values['state']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->url = $values['url'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentIds = $values['parentIds'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->defaultLocale = $values['defaultLocale'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + } + + /** + * @return ?'article' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'article' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getAuthorId(): int + { + return $this->authorId; + } + + /** + * @param int $value + */ + public function setAuthorId(int $value): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return value-of + */ + public function getState(): string + { + return $this->state; + } + + /** + * @param value-of $value + */ + public function setState(string $value): self + { + $this->state = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getParentId(): ?int + { + return $this->parentId; + } + + /** + * @param ?int $value + */ + public function setParentId(?int $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getParentIds(): ?array + { + return $this->parentIds; + } + + /** + * @param ?array $value + */ + public function setParentIds(?array $value = null): self + { + $this->parentIds = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?string $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultLocale(): ?string + { + return $this->defaultLocale; + } + + /** + * @param ?string $value + */ + public function setDefaultLocale(?string $value = null): self + { + $this->defaultLocale = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/ArticleListItemState.php b/src/Articles/Types/ArticleListItemState.php new file mode 100644 index 00000000..57275a9b --- /dev/null +++ b/src/Articles/Types/ArticleListItemState.php @@ -0,0 +1,9 @@ + $highlightedTitle An Article title highlighted. + */ + #[JsonProperty('highlighted_title'), ArrayType([ArticleSearchHighlightsHighlightedTitleItem::class])] + private array $highlightedTitle; + + /** + * @var array> $highlightedSummary An Article description and body text highlighted. + */ + #[JsonProperty('highlighted_summary'), ArrayType([[ArticleSearchHighlightsHighlightedSummaryItemItem::class]])] + private array $highlightedSummary; + + /** + * @param array{ + * articleId: string, + * highlightedTitle: array, + * highlightedSummary: array>, + * } $values + */ + public function __construct( + array $values, + ) { + $this->articleId = $values['articleId']; + $this->highlightedTitle = $values['highlightedTitle']; + $this->highlightedSummary = $values['highlightedSummary']; + } + + /** + * @return string + */ + public function getArticleId(): string + { + return $this->articleId; + } + + /** + * @param string $value + */ + public function setArticleId(string $value): self + { + $this->articleId = $value; + return $this; + } + + /** + * @return array + */ + public function getHighlightedTitle(): array + { + return $this->highlightedTitle; + } + + /** + * @param array $value + */ + public function setHighlightedTitle(array $value): self + { + $this->highlightedTitle = $value; + return $this; + } + + /** + * @return array> + */ + public function getHighlightedSummary(): array + { + return $this->highlightedSummary; + } + + /** + * @param array> $value + */ + public function setHighlightedSummary(array $value): self + { + $this->highlightedSummary = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItem.php b/src/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItem.php new file mode 100644 index 00000000..5b0aadeb --- /dev/null +++ b/src/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItem.php @@ -0,0 +1,79 @@ + $type The type of text - `highlight` or `plain`. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $text The text of the title. + */ + #[JsonProperty('text')] + private ?string $text; + + /** + * @param array{ + * type?: ?value-of, + * text?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->text = $values['text'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getText(): ?string + { + return $this->text; + } + + /** + * @param ?string $value + */ + public function setText(?string $value = null): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItemType.php b/src/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItemType.php new file mode 100644 index 00000000..2f9665ad --- /dev/null +++ b/src/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItemType.php @@ -0,0 +1,9 @@ + $type The type of text - `highlight` or `plain`. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $text The text of the title. + */ + #[JsonProperty('text')] + private ?string $text; + + /** + * @param array{ + * type?: ?value-of, + * text?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->text = $values['text'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getText(): ?string + { + return $this->text; + } + + /** + * @param ?string $value + */ + public function setText(?string $value = null): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/ArticleSearchHighlightsHighlightedTitleItemType.php b/src/Articles/Types/ArticleSearchHighlightsHighlightedTitleItemType.php new file mode 100644 index 00000000..9ec868f2 --- /dev/null +++ b/src/Articles/Types/ArticleSearchHighlightsHighlightedTitleItemType.php @@ -0,0 +1,9 @@ +type = $values['type']; + $this->totalCount = $values['totalCount']; + $this->data = $values['data']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return SearchArticlesResponseData + */ + public function getData(): SearchArticlesResponseData + { + return $this->data; + } + + /** + * @param SearchArticlesResponseData $value + */ + public function setData(SearchArticlesResponseData $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/SearchArticlesResponseData.php b/src/Articles/Types/SearchArticlesResponseData.php new file mode 100644 index 00000000..f1634af3 --- /dev/null +++ b/src/Articles/Types/SearchArticlesResponseData.php @@ -0,0 +1,80 @@ + $articles An array of Article objects + */ + #[JsonProperty('articles'), ArrayType([Article::class])] + private ?array $articles; + + /** + * @var ?array $highlights A corresponding array of highlighted Article content + */ + #[JsonProperty('highlights'), ArrayType([ArticleSearchHighlights::class])] + private ?array $highlights; + + /** + * @param array{ + * articles?: ?array
, + * highlights?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->articles = $values['articles'] ?? null; + $this->highlights = $values['highlights'] ?? null; + } + + /** + * @return ?array
+ */ + public function getArticles(): ?array + { + return $this->articles; + } + + /** + * @param ?array
$value + */ + public function setArticles(?array $value = null): self + { + $this->articles = $value; + return $this; + } + + /** + * @return ?array + */ + public function getHighlights(): ?array + { + return $this->highlights; + } + + /** + * @param ?array $value + */ + public function setHighlights(?array $value = null): self + { + $this->highlights = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Articles/Types/UpdateArticleRequestBodyParentType.php b/src/Articles/Types/UpdateArticleRequestBodyParentType.php new file mode 100644 index 00000000..374f62b9 --- /dev/null +++ b/src/Articles/Types/UpdateArticleRequestBodyParentType.php @@ -0,0 +1,9 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a single company by passing in `company_id` or `name`. + * + * `https://api.intercom.io/companies?name={name}` + * + * `https://api.intercom.io/companies?company_id={company_id}` + * + * You can fetch all companies and filter by `segment_id` or `tag_id` as a query parameter. + * + * `https://api.intercom.io/companies?tag_id={tag_id}` + * + * `https://api.intercom.io/companies?segment_id={segment_id}` + * + * @param RetrieveCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompaniesRetrieveResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieve(RetrieveCompanyRequest $request = new RetrieveCompanyRequest(), ?array $options = null): CompaniesRetrieveResponse + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getName() != null) { + $query['name'] = $request->getName(); + } + if ($request->getCompanyId() != null) { + $query['company_id'] = $request->getCompanyId(); + } + if ($request->getTagId() != null) { + $query['tag_id'] = $request->getTagId(); + } + if ($request->getSegmentId() != null) { + $query['segment_id'] = $request->getSegmentId(); + } + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompaniesRetrieveResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create or update a company. + * + * Companies will be only visible in Intercom when there is at least one associated user. + * + * Companies are looked up via `company_id` in a `POST` request, if not found via `company_id`, the new company will be created, if found, that company will be updated. + * + * {% admonition type="warning" name="Using `company_id`" %} + * You can set a unique `company_id` value when creating a company. However, it is not possible to update `company_id`. Be sure to set a unique value once upon creation of the company. + * {% /admonition %} + * + * @param CreateOrUpdateCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function createOrUpdate(CreateOrUpdateCompanyRequest $request = new CreateOrUpdateCompanyRequest(), ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a single company. + * + * @param FindCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindCompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getCompanyId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update a single company using the Intercom provisioned `id`. + * + * {% admonition type="warning" name="Using `company_id`" %} + * When updating a company it is not possible to update `company_id`. This can only be set once upon creation of the company. + * {% /admonition %} + * + * @param UpdateCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateCompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getCompanyId()}", + method: HttpMethod::PUT, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single company. + * + * @param DeleteCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedCompanyObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function delete(DeleteCompanyRequest $request, ?array $options = null): DeletedCompanyObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getCompanyId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedCompanyObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all contacts that belong to a company. + * + * @param ListAttachedContactsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyAttachedContacts + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedContacts(ListAttachedContactsRequest $request, ?array $options = null): CompanyAttachedContacts + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getCompanyId()}/contacts", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyAttachedContacts::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all segments that belong to a company. + * + * @param ListSegmentsAttachedToCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyAttachedSegments + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedSegments(ListSegmentsAttachedToCompanyRequest $request, ?array $options = null): CompanyAttachedSegments + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getCompanyId()}/segments", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyAttachedSegments::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can list companies. The company list is sorted by the `last_request_at` field and by default is ordered descending, most recently requested first. + * + * Note that the API does not include companies who have no associated users in list responses. + * + * When using the Companies endpoint and the pages object to iterate through the returned companies, there is a limit of 10,000 Companies that can be returned. If you need to list or iterate on more than 10,000 Companies, please use the [Scroll API](https://developers.intercom.com/reference#iterating-over-all-companies). + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListCompaniesRequest $request = new ListCompaniesRequest(), ?array $options = null): Pager + { + return new OffsetPager( + request: $request, + getNextPage: fn (ListCompaniesRequest $request) => $this->_list($request, $options), + /* @phpstan-ignore-next-line */ + getOffset: fn (ListCompaniesRequest $request) => $request?->getPage() ?? 0, + setOffset: function (ListCompaniesRequest $request, int $offset) { + $request->setPage($offset); + }, + getStep: null, + /* @phpstan-ignore-next-line */ + getItems: fn (CompanyList $response) => $response?->getData() ?? [], + /* @phpstan-ignore-next-line */ + hasNextPage: null, + ); + } + + /** + * The `list all companies` functionality does not work well for huge datasets, and can result in errors and performance problems when paging deeply. The Scroll API provides an efficient mechanism for iterating over all companies in a dataset. + * + * - Each app can only have 1 scroll open at a time. You'll get an error message if you try to have more than one open per app. + * - If the scroll isn't used for 1 minute, it expires and calls with that scroll param will fail + * - If the end of the scroll is reached, "companies" will be empty and the scroll parameter will expire + * + * {% admonition type="info" name="Scroll Parameter" %} + * You can get the first page of companies by simply sending a GET request to the scroll endpoint. + * For subsequent requests you will need to use the scroll parameter from the response. + * {% /admonition %} + * {% admonition type="danger" name="Scroll network timeouts" %} + * Since scroll is often used on large datasets network errors such as timeouts can be encountered. When this occurs you will see a HTTP 500 error with the following message: + * "Request failed due to an internal network error. Please restart the scroll operation." + * If this happens, you will need to restart your scroll query: It is not possible to continue from a specific point when using scroll. + * {% /admonition %} + * + * @param ScrollCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function scroll(ScrollCompaniesRequest $request = new ScrollCompaniesRequest(), ?array $options = null): Pager + { + return new CursorPager( + request: $request, + getNextPage: fn (ScrollCompaniesRequest $request) => $this->_scroll($request, $options), + setCursor: function (ScrollCompaniesRequest $request, ?string $cursor) { + $request->setScrollParam($cursor); + }, + /* @phpstan-ignore-next-line */ + getNextCursor: fn (CompanyScroll $response) => $response?->getScrollParam() ?? null, + /* @phpstan-ignore-next-line */ + getItems: fn (CompanyScroll $response) => $response?->getData() ?? [], + ); + } + + /** + * You can attach a company to a single contact. + * + * @param AttachContactToCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachContact(AttachContactToCompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/companies", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can detach a company from a single contact. + * + * @param DetachContactFromCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachContact(DetachContactFromCompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/companies/{$request->getCompanyId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can list companies. The company list is sorted by the `last_request_at` field and by default is ordered descending, most recently requested first. + * + * Note that the API does not include companies who have no associated users in list responses. + * + * When using the Companies endpoint and the pages object to iterate through the returned companies, there is a limit of 10,000 Companies that can be returned. If you need to list or iterate on more than 10,000 Companies, please use the [Scroll API](https://developers.intercom.com/reference#iterating-over-all-companies). + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListCompaniesRequest $request = new ListCompaniesRequest(), ?array $options = null): CompanyList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getOrder() != null) { + $query['order'] = $request->getOrder(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/list", + method: HttpMethod::POST, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * The `list all companies` functionality does not work well for huge datasets, and can result in errors and performance problems when paging deeply. The Scroll API provides an efficient mechanism for iterating over all companies in a dataset. + * + * - Each app can only have 1 scroll open at a time. You'll get an error message if you try to have more than one open per app. + * - If the scroll isn't used for 1 minute, it expires and calls with that scroll param will fail + * - If the end of the scroll is reached, "companies" will be empty and the scroll parameter will expire + * + * {% admonition type="info" name="Scroll Parameter" %} + * You can get the first page of companies by simply sending a GET request to the scroll endpoint. + * For subsequent requests you will need to use the scroll parameter from the response. + * {% /admonition %} + * {% admonition type="danger" name="Scroll network timeouts" %} + * Since scroll is often used on large datasets network errors such as timeouts can be encountered. When this occurs you will see a HTTP 500 error with the following message: + * "Request failed due to an internal network error. Please restart the scroll operation." + * If this happens, you will need to restart your scroll query: It is not possible to continue from a specific point when using scroll. + * {% /admonition %} + * + * @param ScrollCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyScroll + * @throws IntercomException + * @throws IntercomApiException + */ + private function _scroll(ScrollCompaniesRequest $request = new ScrollCompaniesRequest(), ?array $options = null): CompanyScroll + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getScrollParam() != null) { + $query['scroll_param'] = $request->getScrollParam(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/scroll", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyScroll::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Companies/Requests/AttachContactToCompanyRequest.php b/src/Companies/Requests/AttachContactToCompanyRequest.php new file mode 100644 index 00000000..974fb138 --- /dev/null +++ b/src/Companies/Requests/AttachContactToCompanyRequest.php @@ -0,0 +1,67 @@ +contactId = $values['contactId']; + $this->companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Companies/Requests/CreateOrUpdateCompanyRequest.php b/src/Companies/Requests/CreateOrUpdateCompanyRequest.php new file mode 100644 index 00000000..ad18998a --- /dev/null +++ b/src/Companies/Requests/CreateOrUpdateCompanyRequest.php @@ -0,0 +1,244 @@ + $customAttributes A hash of key/value pairs containing any other data about the company you want Intercom to store. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @var ?int $remoteCreatedAt The time the company was created by you. + */ + #[JsonProperty('remote_created_at')] + private ?int $remoteCreatedAt; + + /** + * @var ?int $monthlySpend How much revenue the company generates for your business. Note that this will truncate floats. i.e. it only allow for whole integers, 155.98 will be truncated to 155. Note that this has an upper limit of 2**31-1 or 2147483647.. + */ + #[JsonProperty('monthly_spend')] + private ?int $monthlySpend; + + /** + * @param array{ + * name?: ?string, + * companyId?: ?string, + * plan?: ?string, + * size?: ?int, + * website?: ?string, + * industry?: ?string, + * customAttributes?: ?array, + * remoteCreatedAt?: ?int, + * monthlySpend?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->name = $values['name'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->plan = $values['plan'] ?? null; + $this->size = $values['size'] ?? null; + $this->website = $values['website'] ?? null; + $this->industry = $values['industry'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->remoteCreatedAt = $values['remoteCreatedAt'] ?? null; + $this->monthlySpend = $values['monthlySpend'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPlan(): ?string + { + return $this->plan; + } + + /** + * @param ?string $value + */ + public function setPlan(?string $value = null): self + { + $this->plan = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSize(): ?int + { + return $this->size; + } + + /** + * @param ?int $value + */ + public function setSize(?int $value = null): self + { + $this->size = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWebsite(): ?string + { + return $this->website; + } + + /** + * @param ?string $value + */ + public function setWebsite(?string $value = null): self + { + $this->website = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIndustry(): ?string + { + return $this->industry; + } + + /** + * @param ?string $value + */ + public function setIndustry(?string $value = null): self + { + $this->industry = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRemoteCreatedAt(): ?int + { + return $this->remoteCreatedAt; + } + + /** + * @param ?int $value + */ + public function setRemoteCreatedAt(?int $value = null): self + { + $this->remoteCreatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getMonthlySpend(): ?int + { + return $this->monthlySpend; + } + + /** + * @param ?int $value + */ + public function setMonthlySpend(?int $value = null): self + { + $this->monthlySpend = $value; + return $this; + } +} diff --git a/src/Companies/Requests/DeleteCompanyRequest.php b/src/Companies/Requests/DeleteCompanyRequest.php new file mode 100644 index 00000000..0d5ffc29 --- /dev/null +++ b/src/Companies/Requests/DeleteCompanyRequest.php @@ -0,0 +1,41 @@ +companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Companies/Requests/DetachContactFromCompanyRequest.php b/src/Companies/Requests/DetachContactFromCompanyRequest.php new file mode 100644 index 00000000..540af626 --- /dev/null +++ b/src/Companies/Requests/DetachContactFromCompanyRequest.php @@ -0,0 +1,65 @@ +contactId = $values['contactId']; + $this->companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Companies/Requests/FindCompanyRequest.php b/src/Companies/Requests/FindCompanyRequest.php new file mode 100644 index 00000000..6789872c --- /dev/null +++ b/src/Companies/Requests/FindCompanyRequest.php @@ -0,0 +1,41 @@ +companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Companies/Requests/ListAttachedContactsRequest.php b/src/Companies/Requests/ListAttachedContactsRequest.php new file mode 100644 index 00000000..edcc04fa --- /dev/null +++ b/src/Companies/Requests/ListAttachedContactsRequest.php @@ -0,0 +1,89 @@ +companyId = $values['companyId']; + $this->page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Companies/Requests/ListCompaniesRequest.php b/src/Companies/Requests/ListCompaniesRequest.php new file mode 100644 index 00000000..15149bd6 --- /dev/null +++ b/src/Companies/Requests/ListCompaniesRequest.php @@ -0,0 +1,89 @@ +page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->order = $values['order'] ?? null; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOrder(): ?string + { + return $this->order; + } + + /** + * @param ?string $value + */ + public function setOrder(?string $value = null): self + { + $this->order = $value; + return $this; + } +} diff --git a/src/Companies/Requests/ListSegmentsAttachedToCompanyRequest.php b/src/Companies/Requests/ListSegmentsAttachedToCompanyRequest.php new file mode 100644 index 00000000..2b0332c3 --- /dev/null +++ b/src/Companies/Requests/ListSegmentsAttachedToCompanyRequest.php @@ -0,0 +1,41 @@ +companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Companies/Requests/RetrieveCompanyRequest.php b/src/Companies/Requests/RetrieveCompanyRequest.php new file mode 100644 index 00000000..5d7c5363 --- /dev/null +++ b/src/Companies/Requests/RetrieveCompanyRequest.php @@ -0,0 +1,161 @@ +name = $values['name'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->tagId = $values['tagId'] ?? null; + $this->segmentId = $values['segmentId'] ?? null; + $this->page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTagId(): ?string + { + return $this->tagId; + } + + /** + * @param ?string $value + */ + public function setTagId(?string $value = null): self + { + $this->tagId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSegmentId(): ?string + { + return $this->segmentId; + } + + /** + * @param ?string $value + */ + public function setSegmentId(?string $value = null): self + { + $this->segmentId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Companies/Requests/ScrollCompaniesRequest.php b/src/Companies/Requests/ScrollCompaniesRequest.php new file mode 100644 index 00000000..5191117a --- /dev/null +++ b/src/Companies/Requests/ScrollCompaniesRequest.php @@ -0,0 +1,41 @@ +scrollParam = $values['scrollParam'] ?? null; + } + + /** + * @return ?string + */ + public function getScrollParam(): ?string + { + return $this->scrollParam; + } + + /** + * @param ?string $value + */ + public function setScrollParam(?string $value = null): self + { + $this->scrollParam = $value; + return $this; + } +} diff --git a/src/Companies/Requests/UpdateCompanyRequest.php b/src/Companies/Requests/UpdateCompanyRequest.php new file mode 100644 index 00000000..02646681 --- /dev/null +++ b/src/Companies/Requests/UpdateCompanyRequest.php @@ -0,0 +1,41 @@ +companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Companies/Types/CompaniesRetrieveResponse.php b/src/Companies/Types/CompaniesRetrieveResponse.php new file mode 100644 index 00000000..06d081ad --- /dev/null +++ b/src/Companies/Types/CompaniesRetrieveResponse.php @@ -0,0 +1,234 @@ +type = $values['type']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'company' + * |'list' + * |'_unknown' + * ) + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return ( + * Company + * |CompanyList + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param Company $company + * @return CompaniesRetrieveResponse + */ + public static function company(Company $company): CompaniesRetrieveResponse + { + return new CompaniesRetrieveResponse([ + 'type' => 'company', + 'value' => $company, + ]); + } + + /** + * @param CompanyList $list + * @return CompaniesRetrieveResponse + */ + public static function list(CompanyList $list): CompaniesRetrieveResponse + { + return new CompaniesRetrieveResponse([ + 'type' => 'list', + 'value' => $list, + ]); + } + + /** + * @return bool + */ + public function isCompany(): bool + { + return $this->value instanceof Company && $this->type === 'company'; + } + + /** + * @return Company + */ + public function asCompany(): Company + { + if (!($this->value instanceof Company && $this->type === 'company')) { + throw new Exception( + "Expected company; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isList_(): bool + { + return $this->value instanceof CompanyList && $this->type === 'list'; + } + + /** + * @return CompanyList + */ + public function asList_(): CompanyList + { + if (!($this->value instanceof CompanyList && $this->type === 'list')) { + throw new Exception( + "Expected list; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['type'] = $this->type; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->type) { + case 'company': + $value = $this->asCompany()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'list': + $value = $this->asList_()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('type', $data)) { + throw new Exception( + "JSON data is missing property 'type'", + ); + } + $type = $data['type']; + if (!(is_string($type))) { + throw new Exception( + "Expected property 'type' in JSON data to be string, instead received " . get_debug_type($data['type']), + ); + } + + $args['type'] = $type; + switch ($type) { + case 'company': + $args['value'] = Company::jsonDeserialize($data); + break; + case 'list': + $args['value'] = CompanyList::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['type'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Companies/Types/Company.php b/src/Companies/Types/Company.php new file mode 100644 index 00000000..8c648d6a --- /dev/null +++ b/src/Companies/Types/Company.php @@ -0,0 +1,480 @@ + $customAttributes The custom attributes you have set on the company. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @var ?CompanyTags $tags The list of tags associated with the company + */ + #[JsonProperty('tags')] + private ?CompanyTags $tags; + + /** + * @var ?CompanySegments $segments The list of segments associated with the company + */ + #[JsonProperty('segments')] + private ?CompanySegments $segments; + + /** + * @param array{ + * id: string, + * name: string, + * appId: string, + * companyId: string, + * createdAt: int, + * updatedAt: int, + * monthlySpend: int, + * sessionCount: int, + * userCount: int, + * plan?: ?CompanyPlan, + * remoteCreatedAt?: ?int, + * lastRequestAt?: ?int, + * size?: ?int, + * website?: ?string, + * industry?: ?string, + * customAttributes?: ?array, + * tags?: ?CompanyTags, + * segments?: ?CompanySegments, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->name = $values['name']; + $this->appId = $values['appId']; + $this->plan = $values['plan'] ?? null; + $this->companyId = $values['companyId']; + $this->remoteCreatedAt = $values['remoteCreatedAt'] ?? null; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->lastRequestAt = $values['lastRequestAt'] ?? null; + $this->size = $values['size'] ?? null; + $this->website = $values['website'] ?? null; + $this->industry = $values['industry'] ?? null; + $this->monthlySpend = $values['monthlySpend']; + $this->sessionCount = $values['sessionCount']; + $this->userCount = $values['userCount']; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->segments = $values['segments'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getAppId(): string + { + return $this->appId; + } + + /** + * @param string $value + */ + public function setAppId(string $value): self + { + $this->appId = $value; + return $this; + } + + /** + * @return ?CompanyPlan + */ + public function getPlan(): ?CompanyPlan + { + return $this->plan; + } + + /** + * @param ?CompanyPlan $value + */ + public function setPlan(?CompanyPlan $value = null): self + { + $this->plan = $value; + return $this; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRemoteCreatedAt(): ?int + { + return $this->remoteCreatedAt; + } + + /** + * @param ?int $value + */ + public function setRemoteCreatedAt(?int $value = null): self + { + $this->remoteCreatedAt = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastRequestAt(): ?int + { + return $this->lastRequestAt; + } + + /** + * @param ?int $value + */ + public function setLastRequestAt(?int $value = null): self + { + $this->lastRequestAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSize(): ?int + { + return $this->size; + } + + /** + * @param ?int $value + */ + public function setSize(?int $value = null): self + { + $this->size = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWebsite(): ?string + { + return $this->website; + } + + /** + * @param ?string $value + */ + public function setWebsite(?string $value = null): self + { + $this->website = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIndustry(): ?string + { + return $this->industry; + } + + /** + * @param ?string $value + */ + public function setIndustry(?string $value = null): self + { + $this->industry = $value; + return $this; + } + + /** + * @return int + */ + public function getMonthlySpend(): int + { + return $this->monthlySpend; + } + + /** + * @param int $value + */ + public function setMonthlySpend(int $value): self + { + $this->monthlySpend = $value; + return $this; + } + + /** + * @return int + */ + public function getSessionCount(): int + { + return $this->sessionCount; + } + + /** + * @param int $value + */ + public function setSessionCount(int $value): self + { + $this->sessionCount = $value; + return $this; + } + + /** + * @return int + */ + public function getUserCount(): int + { + return $this->userCount; + } + + /** + * @param int $value + */ + public function setUserCount(int $value): self + { + $this->userCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?CompanyTags + */ + public function getTags(): ?CompanyTags + { + return $this->tags; + } + + /** + * @param ?CompanyTags $value + */ + public function setTags(?CompanyTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?CompanySegments + */ + public function getSegments(): ?CompanySegments + { + return $this->segments; + } + + /** + * @param ?CompanySegments $value + */ + public function setSegments(?CompanySegments $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Companies/Types/CompanyPlan.php b/src/Companies/Types/CompanyPlan.php new file mode 100644 index 00000000..5e4a0a80 --- /dev/null +++ b/src/Companies/Types/CompanyPlan.php @@ -0,0 +1,101 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?'plan' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'plan' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Companies/Types/CompanySegments.php b/src/Companies/Types/CompanySegments.php new file mode 100644 index 00000000..21df7441 --- /dev/null +++ b/src/Companies/Types/CompanySegments.php @@ -0,0 +1,81 @@ + $segments + */ + #[JsonProperty('segments'), ArrayType([Segment::class])] + private ?array $segments; + + /** + * @param array{ + * type?: ?'segment.list', + * segments?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->segments = $values['segments'] ?? null; + } + + /** + * @return ?'segment.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'segment.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSegments(): ?array + { + return $this->segments; + } + + /** + * @param ?array $value + */ + public function setSegments(?array $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Companies/Types/CompanyTags.php b/src/Companies/Types/CompanyTags.php new file mode 100644 index 00000000..dccdaaf2 --- /dev/null +++ b/src/Companies/Types/CompanyTags.php @@ -0,0 +1,80 @@ + $tags + */ + #[JsonProperty('tags'), ArrayType(['mixed'])] + private ?array $tags; + + /** + * @param array{ + * type?: ?'tag.list', + * tags?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->tags = $values['tags'] ?? null; + } + + /** + * @return ?'tag.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTags(): ?array + { + return $this->tags; + } + + /** + * @param ?array $value + */ + public function setTags(?array $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Contacts/ContactsClient.php b/src/Contacts/ContactsClient.php new file mode 100644 index 00000000..b3896518 --- /dev/null +++ b/src/Contacts/ContactsClient.php @@ -0,0 +1,1244 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of companies that are associated to a contact. + * + * @param ListAttachedCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function listAttachedCompanies(ListAttachedCompaniesRequest $request, ?array $options = null): Pager + { + return new OffsetPager( + request: $request, + getNextPage: fn (ListAttachedCompaniesRequest $request) => $this->_listAttachedCompanies($request, $options), + /* @phpstan-ignore-next-line */ + getOffset: fn (ListAttachedCompaniesRequest $request) => $request?->getPage() ?? 0, + setOffset: function (ListAttachedCompaniesRequest $request, int $offset) { + $request->setPage($offset); + }, + getStep: null, + /* @phpstan-ignore-next-line */ + getItems: fn (ContactAttachedCompanies $response) => $response?->getCompanies() ?? [], + /* @phpstan-ignore-next-line */ + hasNextPage: null, + ); + } + + /** + * You can fetch a list of segments that are associated to a contact. + * + * @param ListSegmentsAttachedToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactSegments + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedSegments(ListSegmentsAttachedToContactRequest $request, ?array $options = null): ContactSegments + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/segments", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactSegments::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of subscription types that are attached to a contact. These can be subscriptions that a user has 'opted-in' to or has 'opted-out' from, depending on the subscription type. + * This will return a list of Subscription Type objects that the contact is associated with. + * + * The data property will show a combined list of: + * + * 1.Opt-out subscription types that the user has opted-out from. + * 2.Opt-in subscription types that the user has opted-in to receiving. + * + * @param ListAttachedSubscriptionsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionTypeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedSubscriptions(ListAttachedSubscriptionsRequest $request, ?array $options = null): SubscriptionTypeList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/subscriptions", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionTypeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can add a specific subscription to a contact. In Intercom, we have two different subscription types based on user consent - opt-out and opt-in: + * + * 1.Attaching a contact to an opt-out subscription type will opt that user out from receiving messages related to that subscription type. + * + * 2.Attaching a contact to an opt-in subscription type will opt that user in to receiving messages related to that subscription type. + * + * This will return a subscription type model for the subscription type that was added to the contact. + * + * @param AttachSubscriptionToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionType + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachSubscription(AttachSubscriptionToContactRequest $request, ?array $options = null): SubscriptionType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/subscriptions", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove a specific subscription from a contact. This will return a subscription type model for the subscription type that was removed from the contact. + * + * @param DetachSubscriptionFromContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionType + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachSubscription(DetachSubscriptionFromContactRequest $request, ?array $options = null): SubscriptionType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/subscriptions/{$request->getSubscriptionId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all tags that are attached to a specific contact. + * + * @param ListTagsAttachedToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TagList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedTags(ListTagsAttachedToContactRequest $request, ?array $options = null): TagList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/tags", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TagList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single contact. + * + * @param FindContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Contact + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindContactRequest $request, ?array $options = null): Contact + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Contact::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update an existing contact (ie. user or lead). + * + * @param UpdateContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Contact + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateContactRequest $request, ?array $options = null): Contact + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Contact::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single contact. + * + * @param DeleteContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactDeleted + * @throws IntercomException + * @throws IntercomApiException + */ + public function delete(DeleteContactRequest $request, ?array $options = null): ContactDeleted + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactDeleted::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can merge a contact with a `role` of `lead` into a contact with a `role` of `user`. + * + * @param MergeContactsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Contact + * @throws IntercomException + * @throws IntercomApiException + */ + public function mergeLeadInUser(MergeContactsRequest $request, ?array $options = null): Contact + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/merge", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Contact::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple contacts by the value of their attributes in order to fetch exactly who you want. + * + * To search for contacts, you need to send a `POST` request to `https://api.intercom.io/contacts/search`. + * + * This will accept a query object in the body which will define your filters in order to search for contacts. + * + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `50` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * ### Contact Creation Delay + * + * If a contact has recently been created, there is a possibility that it will not yet be available when searching. This means that it may not appear in the response. This delay can take a few minutes. If you need to be instantly notified it is recommended to use webhooks and iterate to see if they match your search filters. + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiple's there can be: + * * There's a limit of max 2 nested filters + * * There's a limit of max 15 filters for each AND or OR group + * + * ### Searching for Timestamp Fields + * + * All timestamp fields (created_at, updated_at etc.) are indexed as Dates for Contact Search queries; Datetime queries are not currently supported. This means you can only query for timestamp fields by day - not hour, minute or second. + * For example, if you search for all Contacts with a created_at value greater (>) than 1577869200 (the UNIX timestamp for January 1st, 2020 9:00 AM), that will be interpreted as 1577836800 (January 1st, 2020 12:00 AM). The search results will then include Contacts created from January 2nd, 2020 12:00 AM onwards. + * If you'd like to get contacts created on January 1st, 2020 you should search with a created_at value equal (=) to 1577836800 (January 1st, 2020 12:00 AM). + * This behaviour applies only to timestamps used in search queries. The search results will still contain the full UNIX timestamp and be sorted accordingly. + * + * ### Accepted Fields + * + * Most key listed as part of the Contacts Model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`). + * + * | Field | Type | + * | ---------------------------------- | ------------------------------ | + * | id | String | + * | role | String
Accepts user or lead | + * | name | String | + * | avatar | String | + * | owner_id | Integer | + * | email | String | + * | email_domain | String | + * | phone | String | + * | external_id | String | + * | created_at | Date (UNIX Timestamp) | + * | signed_up_at | Date (UNIX Timestamp) | + * | updated_at | Date (UNIX Timestamp) | + * | last_seen_at | Date (UNIX Timestamp) | + * | last_contacted_at | Date (UNIX Timestamp) | + * | last_replied_at | Date (UNIX Timestamp) | + * | last_email_opened_at | Date (UNIX Timestamp) | + * | last_email_clicked_at | Date (UNIX Timestamp) | + * | language_override | String | + * | browser | String | + * | browser_language | String | + * | os | String | + * | location.country | String | + * | location.region | String | + * | location.city | String | + * | unsubscribed_from_emails | Boolean | + * | marked_email_as_spam | Boolean | + * | has_hard_bounced | Boolean | + * | ios_last_seen_at | Date (UNIX Timestamp) | + * | ios_app_version | String | + * | ios_device | String | + * | ios_app_device | String | + * | ios_os_version | String | + * | ios_app_name | String | + * | ios_sdk_version | String | + * | android_last_seen_at | Date (UNIX Timestamp) | + * | android_app_version | String | + * | android_device | String | + * | android_app_name | String | + * | andoid_sdk_version | String | + * | segment_id | String | + * | tag_id | String | + * | custom_attributes.{attribute_name} | String | + * + * ### Accepted Operators + * + * {% admonition type="warning" name="Searching based on `created_at`" %} + * You cannot use the `<=` or `>=` operators to search by `created_at`. + * {% /admonition %} + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :------------------------------- | :--------------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In
Shortcut for `OR` queries
Values must be in Array | + * | NIN | All | Not In
Shortcut for `OR !` queries
Values must be in Array | + * | > | Integer
Date (UNIX Timestamp) | Greater than | + * | < | Integer
Date (UNIX Timestamp) | Lower than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function search(SearchRequest $request, ?array $options = null): Pager + { + return new CursorPager( + request: $request, + getNextPage: fn (SearchRequest $request) => $this->_search($request, $options), + setCursor: function (SearchRequest $request, ?string $cursor) { + PaginationHelper::setDeep($request, ["pagination", "startingAfter"], $cursor); + }, + /* @phpstan-ignore-next-line */ + getNextCursor: fn (ContactList $response) => $response?->getPages()?->getNext()?->getStartingAfter() ?? null, + /* @phpstan-ignore-next-line */ + getItems: fn (ContactList $response) => $response?->getData() ?? [], + ); + } + + /** + * You can fetch a list of all contacts (ie. users or leads) in your workspace. + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `50` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListContactsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListContactsRequest $request = new ListContactsRequest(), ?array $options = null): Pager + { + return new CursorPager( + request: $request, + getNextPage: fn (ListContactsRequest $request) => $this->_list($request, $options), + setCursor: function (ListContactsRequest $request, ?string $cursor) { + $request->setStartingAfter($cursor); + }, + /* @phpstan-ignore-next-line */ + getNextCursor: fn (ContactList $response) => $response?->getPages()?->getNext()?->getStartingAfter() ?? null, + /* @phpstan-ignore-next-line */ + getItems: fn (ContactList $response) => $response?->getData() ?? [], + ); + } + + /** + * You can create a new contact (ie. user or lead). + * + * @param ( + * CreateContactRequestWithEmail + * |CreateContactRequestWithExternalId + * |CreateContactRequestWithRole + * ) $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Contact + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateContactRequestWithEmail|CreateContactRequestWithExternalId|CreateContactRequestWithRole $request, ?array $options = null): Contact + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts", + method: HttpMethod::POST, + body: JsonSerializer::serializeUnion($request, new Union(CreateContactRequestWithEmail::class, CreateContactRequestWithExternalId::class, CreateContactRequestWithRole::class)), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Contact::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can archive a single contact. + * + * @param ArchiveContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactArchived + * @throws IntercomException + * @throws IntercomApiException + */ + public function archive(ArchiveContactRequest $request, ?array $options = null): ContactArchived + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/archive", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactArchived::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can unarchive a single contact. + * + * @param UnarchiveContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactUnarchived + * @throws IntercomException + * @throws IntercomApiException + */ + public function unarchive(UnarchiveContactRequest $request, ?array $options = null): ContactUnarchived + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/unarchive", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactUnarchived::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of companies that are associated to a contact. + * + * @param ListAttachedCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactAttachedCompanies + * @throws IntercomException + * @throws IntercomApiException + */ + private function _listAttachedCompanies(ListAttachedCompaniesRequest $request, ?array $options = null): ContactAttachedCompanies + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/companies", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactAttachedCompanies::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple contacts by the value of their attributes in order to fetch exactly who you want. + * + * To search for contacts, you need to send a `POST` request to `https://api.intercom.io/contacts/search`. + * + * This will accept a query object in the body which will define your filters in order to search for contacts. + * + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `50` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * ### Contact Creation Delay + * + * If a contact has recently been created, there is a possibility that it will not yet be available when searching. This means that it may not appear in the response. This delay can take a few minutes. If you need to be instantly notified it is recommended to use webhooks and iterate to see if they match your search filters. + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiple's there can be: + * * There's a limit of max 2 nested filters + * * There's a limit of max 15 filters for each AND or OR group + * + * ### Searching for Timestamp Fields + * + * All timestamp fields (created_at, updated_at etc.) are indexed as Dates for Contact Search queries; Datetime queries are not currently supported. This means you can only query for timestamp fields by day - not hour, minute or second. + * For example, if you search for all Contacts with a created_at value greater (>) than 1577869200 (the UNIX timestamp for January 1st, 2020 9:00 AM), that will be interpreted as 1577836800 (January 1st, 2020 12:00 AM). The search results will then include Contacts created from January 2nd, 2020 12:00 AM onwards. + * If you'd like to get contacts created on January 1st, 2020 you should search with a created_at value equal (=) to 1577836800 (January 1st, 2020 12:00 AM). + * This behaviour applies only to timestamps used in search queries. The search results will still contain the full UNIX timestamp and be sorted accordingly. + * + * ### Accepted Fields + * + * Most key listed as part of the Contacts Model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`). + * + * | Field | Type | + * | ---------------------------------- | ------------------------------ | + * | id | String | + * | role | String
Accepts user or lead | + * | name | String | + * | avatar | String | + * | owner_id | Integer | + * | email | String | + * | email_domain | String | + * | phone | String | + * | external_id | String | + * | created_at | Date (UNIX Timestamp) | + * | signed_up_at | Date (UNIX Timestamp) | + * | updated_at | Date (UNIX Timestamp) | + * | last_seen_at | Date (UNIX Timestamp) | + * | last_contacted_at | Date (UNIX Timestamp) | + * | last_replied_at | Date (UNIX Timestamp) | + * | last_email_opened_at | Date (UNIX Timestamp) | + * | last_email_clicked_at | Date (UNIX Timestamp) | + * | language_override | String | + * | browser | String | + * | browser_language | String | + * | os | String | + * | location.country | String | + * | location.region | String | + * | location.city | String | + * | unsubscribed_from_emails | Boolean | + * | marked_email_as_spam | Boolean | + * | has_hard_bounced | Boolean | + * | ios_last_seen_at | Date (UNIX Timestamp) | + * | ios_app_version | String | + * | ios_device | String | + * | ios_app_device | String | + * | ios_os_version | String | + * | ios_app_name | String | + * | ios_sdk_version | String | + * | android_last_seen_at | Date (UNIX Timestamp) | + * | android_app_version | String | + * | android_device | String | + * | android_app_name | String | + * | andoid_sdk_version | String | + * | segment_id | String | + * | tag_id | String | + * | custom_attributes.{attribute_name} | String | + * + * ### Accepted Operators + * + * {% admonition type="warning" name="Searching based on `created_at`" %} + * You cannot use the `<=` or `>=` operators to search by `created_at`. + * {% /admonition %} + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :------------------------------- | :--------------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In
Shortcut for `OR` queries
Values must be in Array | + * | NIN | All | Not In
Shortcut for `OR !` queries
Values must be in Array | + * | > | Integer
Date (UNIX Timestamp) | Greater than | + * | < | Integer
Date (UNIX Timestamp) | Lower than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _search(SearchRequest $request, ?array $options = null): ContactList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/search", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all contacts (ie. users or leads) in your workspace. + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `50` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListContactsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListContactsRequest $request = new ListContactsRequest(), ?array $options = null): ContactList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getStartingAfter() != null) { + $query['starting_after'] = $request->getStartingAfter(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Contacts/Requests/ArchiveContactRequest.php b/src/Contacts/Requests/ArchiveContactRequest.php new file mode 100644 index 00000000..ba17d66c --- /dev/null +++ b/src/Contacts/Requests/ArchiveContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/AttachSubscriptionToContactRequest.php b/src/Contacts/Requests/AttachSubscriptionToContactRequest.php new file mode 100644 index 00000000..0198cca9 --- /dev/null +++ b/src/Contacts/Requests/AttachSubscriptionToContactRequest.php @@ -0,0 +1,92 @@ +contactId = $values['contactId']; + $this->subscriptionId = $values['subscriptionId']; + $this->consentType = $values['consentType']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getSubscriptionId(): string + { + return $this->subscriptionId; + } + + /** + * @param string $value + */ + public function setSubscriptionId(string $value): self + { + $this->subscriptionId = $value; + return $this; + } + + /** + * @return string + */ + public function getConsentType(): string + { + return $this->consentType; + } + + /** + * @param string $value + */ + public function setConsentType(string $value): self + { + $this->consentType = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/DeleteContactRequest.php b/src/Contacts/Requests/DeleteContactRequest.php new file mode 100644 index 00000000..d8e5171e --- /dev/null +++ b/src/Contacts/Requests/DeleteContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/DetachSubscriptionFromContactRequest.php b/src/Contacts/Requests/DetachSubscriptionFromContactRequest.php new file mode 100644 index 00000000..7eff9b9a --- /dev/null +++ b/src/Contacts/Requests/DetachSubscriptionFromContactRequest.php @@ -0,0 +1,65 @@ +contactId = $values['contactId']; + $this->subscriptionId = $values['subscriptionId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getSubscriptionId(): string + { + return $this->subscriptionId; + } + + /** + * @param string $value + */ + public function setSubscriptionId(string $value): self + { + $this->subscriptionId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/FindContactRequest.php b/src/Contacts/Requests/FindContactRequest.php new file mode 100644 index 00000000..33839197 --- /dev/null +++ b/src/Contacts/Requests/FindContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/ListAttachedCompaniesRequest.php b/src/Contacts/Requests/ListAttachedCompaniesRequest.php new file mode 100644 index 00000000..2be08c95 --- /dev/null +++ b/src/Contacts/Requests/ListAttachedCompaniesRequest.php @@ -0,0 +1,89 @@ +contactId = $values['contactId']; + $this->page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/ListAttachedSubscriptionsRequest.php b/src/Contacts/Requests/ListAttachedSubscriptionsRequest.php new file mode 100644 index 00000000..fff1e4e8 --- /dev/null +++ b/src/Contacts/Requests/ListAttachedSubscriptionsRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/ListContactsRequest.php b/src/Contacts/Requests/ListContactsRequest.php new file mode 100644 index 00000000..121eb476 --- /dev/null +++ b/src/Contacts/Requests/ListContactsRequest.php @@ -0,0 +1,89 @@ +page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/ListSegmentsAttachedToContactRequest.php b/src/Contacts/Requests/ListSegmentsAttachedToContactRequest.php new file mode 100644 index 00000000..436a987f --- /dev/null +++ b/src/Contacts/Requests/ListSegmentsAttachedToContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/ListTagsAttachedToContactRequest.php b/src/Contacts/Requests/ListTagsAttachedToContactRequest.php new file mode 100644 index 00000000..a2238e32 --- /dev/null +++ b/src/Contacts/Requests/ListTagsAttachedToContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/MergeContactsRequest.php b/src/Contacts/Requests/MergeContactsRequest.php new file mode 100644 index 00000000..cb586774 --- /dev/null +++ b/src/Contacts/Requests/MergeContactsRequest.php @@ -0,0 +1,68 @@ +leadId = $values['leadId']; + $this->contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getLeadId(): string + { + return $this->leadId; + } + + /** + * @param string $value + */ + public function setLeadId(string $value): self + { + $this->leadId = $value; + return $this; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/UnarchiveContactRequest.php b/src/Contacts/Requests/UnarchiveContactRequest.php new file mode 100644 index 00000000..4e5da9c8 --- /dev/null +++ b/src/Contacts/Requests/UnarchiveContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Contacts/Requests/UpdateContactRequest.php b/src/Contacts/Requests/UpdateContactRequest.php new file mode 100644 index 00000000..2f6dc656 --- /dev/null +++ b/src/Contacts/Requests/UpdateContactRequest.php @@ -0,0 +1,318 @@ + $customAttributes The custom attributes which are set for the contact + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * contactId: string, + * role?: ?string, + * externalId?: ?string, + * email?: ?string, + * phone?: ?string, + * name?: ?string, + * avatar?: ?string, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * ownerId?: ?int, + * unsubscribedFromEmails?: ?bool, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->contactId = $values['contactId']; + $this->role = $values['role'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->email = $values['email'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRole(): ?string + { + return $this->role; + } + + /** + * @param ?string $value + */ + public function setRole(?string $value = null): self + { + $this->role = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } +} diff --git a/src/Contacts/Types/Contact.php b/src/Contacts/Types/Contact.php new file mode 100644 index 00000000..22d2496f --- /dev/null +++ b/src/Contacts/Types/Contact.php @@ -0,0 +1,1185 @@ + $customAttributes The custom attributes which are set for the contact. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @var ?string $avatar An image URL containing the avatar of a contact. + */ + #[JsonProperty('avatar')] + private ?string $avatar; + + /** + * @var ?ContactTags $tags + */ + #[JsonProperty('tags')] + private ?ContactTags $tags; + + /** + * @var ?ContactNotes $notes + */ + #[JsonProperty('notes')] + private ?ContactNotes $notes; + + /** + * @var ?ContactCompanies $companies + */ + #[JsonProperty('companies')] + private ?ContactCompanies $companies; + + /** + * @var ContactLocation $location + */ + #[JsonProperty('location')] + private ContactLocation $location; + + /** + * @var ContactSocialProfiles $socialProfiles + */ + #[JsonProperty('social_profiles')] + private ContactSocialProfiles $socialProfiles; + + /** + * @param array{ + * id: string, + * workspaceId: string, + * role: string, + * hasHardBounced: bool, + * markedEmailAsSpam: bool, + * unsubscribedFromEmails: bool, + * createdAt: int, + * updatedAt: int, + * location: ContactLocation, + * socialProfiles: ContactSocialProfiles, + * type?: ?'contact', + * externalId?: ?string, + * email?: ?string, + * emailDomain?: ?string, + * phone?: ?string, + * formattedPhone?: ?string, + * name?: ?string, + * ownerId?: ?int, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * lastRepliedAt?: ?int, + * lastContactedAt?: ?int, + * lastEmailOpenedAt?: ?int, + * lastEmailClickedAt?: ?int, + * languageOverride?: ?string, + * browser?: ?string, + * browserVersion?: ?string, + * browserLanguage?: ?string, + * os?: ?string, + * androidAppName?: ?string, + * androidAppVersion?: ?string, + * androidDevice?: ?string, + * androidOsVersion?: ?string, + * androidSdkVersion?: ?string, + * androidLastSeenAt?: ?int, + * iosAppName?: ?string, + * iosAppVersion?: ?string, + * iosDevice?: ?string, + * iosOsVersion?: ?string, + * iosSdkVersion?: ?string, + * iosLastSeenAt?: ?int, + * customAttributes?: ?array, + * avatar?: ?string, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id']; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId']; + $this->role = $values['role']; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced']; + $this->markedEmailAsSpam = $values['markedEmailAsSpam']; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location']; + $this->socialProfiles = $values['socialProfiles']; + } + + /** + * @return ?'contact' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'contact' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getRole(): string + { + return $this->role; + } + + /** + * @param string $value + */ + public function setRole(string $value): self + { + $this->role = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmailDomain(): ?string + { + return $this->emailDomain; + } + + /** + * @param ?string $value + */ + public function setEmailDomain(?string $value = null): self + { + $this->emailDomain = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getFormattedPhone(): ?string + { + return $this->formattedPhone; + } + + /** + * @param ?string $value + */ + public function setFormattedPhone(?string $value = null): self + { + $this->formattedPhone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasHardBounced(): bool + { + return $this->hasHardBounced; + } + + /** + * @param bool $value + */ + public function setHasHardBounced(bool $value): self + { + $this->hasHardBounced = $value; + return $this; + } + + /** + * @return bool + */ + public function getMarkedEmailAsSpam(): bool + { + return $this->markedEmailAsSpam; + } + + /** + * @param bool $value + */ + public function setMarkedEmailAsSpam(bool $value): self + { + $this->markedEmailAsSpam = $value; + return $this; + } + + /** + * @return bool + */ + public function getUnsubscribedFromEmails(): bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param bool $value + */ + public function setUnsubscribedFromEmails(bool $value): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastRepliedAt(): ?int + { + return $this->lastRepliedAt; + } + + /** + * @param ?int $value + */ + public function setLastRepliedAt(?int $value = null): self + { + $this->lastRepliedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastContactedAt(): ?int + { + return $this->lastContactedAt; + } + + /** + * @param ?int $value + */ + public function setLastContactedAt(?int $value = null): self + { + $this->lastContactedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastEmailOpenedAt(): ?int + { + return $this->lastEmailOpenedAt; + } + + /** + * @param ?int $value + */ + public function setLastEmailOpenedAt(?int $value = null): self + { + $this->lastEmailOpenedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastEmailClickedAt(): ?int + { + return $this->lastEmailClickedAt; + } + + /** + * @param ?int $value + */ + public function setLastEmailClickedAt(?int $value = null): self + { + $this->lastEmailClickedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLanguageOverride(): ?string + { + return $this->languageOverride; + } + + /** + * @param ?string $value + */ + public function setLanguageOverride(?string $value = null): self + { + $this->languageOverride = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowser(): ?string + { + return $this->browser; + } + + /** + * @param ?string $value + */ + public function setBrowser(?string $value = null): self + { + $this->browser = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowserVersion(): ?string + { + return $this->browserVersion; + } + + /** + * @param ?string $value + */ + public function setBrowserVersion(?string $value = null): self + { + $this->browserVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowserLanguage(): ?string + { + return $this->browserLanguage; + } + + /** + * @param ?string $value + */ + public function setBrowserLanguage(?string $value = null): self + { + $this->browserLanguage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOs(): ?string + { + return $this->os; + } + + /** + * @param ?string $value + */ + public function setOs(?string $value = null): self + { + $this->os = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidAppName(): ?string + { + return $this->androidAppName; + } + + /** + * @param ?string $value + */ + public function setAndroidAppName(?string $value = null): self + { + $this->androidAppName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidAppVersion(): ?string + { + return $this->androidAppVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidAppVersion(?string $value = null): self + { + $this->androidAppVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidDevice(): ?string + { + return $this->androidDevice; + } + + /** + * @param ?string $value + */ + public function setAndroidDevice(?string $value = null): self + { + $this->androidDevice = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidOsVersion(): ?string + { + return $this->androidOsVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidOsVersion(?string $value = null): self + { + $this->androidOsVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidSdkVersion(): ?string + { + return $this->androidSdkVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidSdkVersion(?string $value = null): self + { + $this->androidSdkVersion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAndroidLastSeenAt(): ?int + { + return $this->androidLastSeenAt; + } + + /** + * @param ?int $value + */ + public function setAndroidLastSeenAt(?int $value = null): self + { + $this->androidLastSeenAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosAppName(): ?string + { + return $this->iosAppName; + } + + /** + * @param ?string $value + */ + public function setIosAppName(?string $value = null): self + { + $this->iosAppName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosAppVersion(): ?string + { + return $this->iosAppVersion; + } + + /** + * @param ?string $value + */ + public function setIosAppVersion(?string $value = null): self + { + $this->iosAppVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosDevice(): ?string + { + return $this->iosDevice; + } + + /** + * @param ?string $value + */ + public function setIosDevice(?string $value = null): self + { + $this->iosDevice = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosOsVersion(): ?string + { + return $this->iosOsVersion; + } + + /** + * @param ?string $value + */ + public function setIosOsVersion(?string $value = null): self + { + $this->iosOsVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosSdkVersion(): ?string + { + return $this->iosSdkVersion; + } + + /** + * @param ?string $value + */ + public function setIosSdkVersion(?string $value = null): self + { + $this->iosSdkVersion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getIosLastSeenAt(): ?int + { + return $this->iosLastSeenAt; + } + + /** + * @param ?int $value + */ + public function setIosLastSeenAt(?int $value = null): self + { + $this->iosLastSeenAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?ContactTags + */ + public function getTags(): ?ContactTags + { + return $this->tags; + } + + /** + * @param ?ContactTags $value + */ + public function setTags(?ContactTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?ContactNotes + */ + public function getNotes(): ?ContactNotes + { + return $this->notes; + } + + /** + * @param ?ContactNotes $value + */ + public function setNotes(?ContactNotes $value = null): self + { + $this->notes = $value; + return $this; + } + + /** + * @return ?ContactCompanies + */ + public function getCompanies(): ?ContactCompanies + { + return $this->companies; + } + + /** + * @param ?ContactCompanies $value + */ + public function setCompanies(?ContactCompanies $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return ContactLocation + */ + public function getLocation(): ContactLocation + { + return $this->location; + } + + /** + * @param ContactLocation $value + */ + public function setLocation(ContactLocation $value): self + { + $this->location = $value; + return $this; + } + + /** + * @return ContactSocialProfiles + */ + public function getSocialProfiles(): ContactSocialProfiles + { + return $this->socialProfiles; + } + + /** + * @param ContactSocialProfiles $value + */ + public function setSocialProfiles(ContactSocialProfiles $value): self + { + $this->socialProfiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Conversations/ConversationsClient.php b/src/Conversations/ConversationsClient.php new file mode 100644 index 00000000..159776c3 --- /dev/null +++ b/src/Conversations/ConversationsClient.php @@ -0,0 +1,1067 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all conversations. + * + * You can optionally request the result page size and the cursor to start after to fetch the result. + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListConversationsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListConversationsRequest $request = new ListConversationsRequest(), ?array $options = null): Pager + { + return new CursorPager( + request: $request, + getNextPage: fn (ListConversationsRequest $request) => $this->_list($request, $options), + setCursor: function (ListConversationsRequest $request, ?string $cursor) { + $request->setStartingAfter($cursor); + }, + /* @phpstan-ignore-next-line */ + getNextCursor: fn (PaginatedConversationResponse $response) => $response?->getPages()?->getNext()?->getStartingAfter() ?? null, + /* @phpstan-ignore-next-line */ + getItems: fn (PaginatedConversationResponse $response) => $response?->getConversations() ?? [], + ); + } + + /** + * You can create a conversation that has been initiated by a contact (ie. user or lead). + * The conversation can be an in-app message only. + * + * {% admonition type="info" name="Sending for visitors" %} + * You can also send a message from a visitor by specifying their `user_id` or `id` value in the `from` field, along with a `type` field value of `contact`. + * This visitor will be automatically converted to a contact with a lead role once the conversation is created. + * {% /admonition %} + * + * This will return the Message model that has been created. + * + * @param CreateConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Message + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateConversationRequest $request, ?array $options = null): Message + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Message::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can fetch the details of a single conversation. + * + * This will return a single Conversation model with all its conversation parts. + * + * {% admonition type="warning" name="Hard limit of 500 parts" %} + * The maximum number of conversation parts that can be returned via the API is 500. If you have more than that we will return the 500 most recent conversation parts. + * {% /admonition %} + * + * For AI agent conversation metadata, please note that you need to have the agent enabled in your workspace, which is a [paid feature](https://www.intercom.com/help/en/articles/8205718-fin-resolutions#h_97f8c2e671). + * + * @param FindConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getDisplayAs() != null) { + $query['display_as'] = $request->getDisplayAs(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can update an existing conversation. + * + * {% admonition type="info" name="Replying and other actions" %} + * If you want to reply to a coveration or take an action such as assign, unassign, open, close or snooze, take a look at the reply and manage endpoints. + * {% /admonition %} + * + * @param UpdateConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getDisplayAs() != null) { + $query['display_as'] = $request->getDisplayAs(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}", + method: HttpMethod::PUT, + query: $query, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple conversations by the value of their attributes in order to fetch exactly which ones you want. + * + * To search for conversations, you need to send a `POST` request to `https://api.intercom.io/conversations/search`. + * + * This will accept a query object in the body which will define your filters in order to search for conversations. + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `20` results per page and maximum is `150`. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiple's there can be: + * - There's a limit of max 2 nested filters + * - There's a limit of max 15 filters for each AND or OR group + * + * ### Accepted Fields + * + * Most keys listed as part of the The conversation model is searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`). + * The `source.body` field is unique as the search will not be performed against the entire value, but instead against every element of the value separately. For example, when searching for a conversation with a `"I need support"` body - the query should contain a `=` operator with the value `"support"` for such conversation to be returned. A query with a `=` operator and a `"need support"` value will not yield a result. + * + * | Field | Type | + * | :---------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | + * | id | String | + * | created_at | Date (UNIX timestamp) | + * | updated_at | Date (UNIX timestamp) | + * | source.type | String
Accepted fields are `conversation`, `email`, `facebook`, `instagram`, `phone_call`, `phone_switch`, `push`, `sms`, `twitter` and `whatsapp`. | + * | source.id | String | + * | source.delivered_as | String | + * | source.subject | String | + * | source.body | String | + * | source.author.id | String | + * | source.author.type | String | + * | source.author.name | String | + * | source.author.email | String | + * | source.url | String | + * | contact_ids | String | + * | teammate_ids | String | + * | admin_assignee_id | String | + * | team_assignee_id | String | + * | channel_initiated | String | + * | open | Boolean | + * | read | Boolean | + * | state | String | + * | waiting_since | Date (UNIX timestamp) | + * | snoozed_until | Date (UNIX timestamp) | + * | tag_ids | String | + * | priority | String | + * | statistics.time_to_assignment | Integer | + * | statistics.time_to_admin_reply | Integer | + * | statistics.time_to_first_close | Integer | + * | statistics.time_to_last_close | Integer | + * | statistics.median_time_to_reply | Integer | + * | statistics.first_contact_reply_at | Date (UNIX timestamp) | + * | statistics.first_assignment_at | Date (UNIX timestamp) | + * | statistics.first_admin_reply_at | Date (UNIX timestamp) | + * | statistics.first_close_at | Date (UNIX timestamp) | + * | statistics.last_assignment_at | Date (UNIX timestamp) | + * | statistics.last_assignment_admin_reply_at | Date (UNIX timestamp) | + * | statistics.last_contact_reply_at | Date (UNIX timestamp) | + * | statistics.last_admin_reply_at | Date (UNIX timestamp) | + * | statistics.last_close_at | Date (UNIX timestamp) | + * | statistics.last_closed_by_id | String | + * | statistics.count_reopens | Integer | + * | statistics.count_assignments | Integer | + * | statistics.count_conversation_parts | Integer | + * | conversation_rating.requested_at | Date (UNIX timestamp) | + * | conversation_rating.replied_at | Date (UNIX timestamp) | + * | conversation_rating.score | Integer | + * | conversation_rating.remark | String | + * | conversation_rating.contact_id | String | + * | conversation_rating.admin_d | String | + * | ai_agent_participated | Boolean | + * | ai_agent.resolution_state | String | + * | ai_agent.last_answer_type | String | + * | ai_agent.rating | Integer | + * | ai_agent.rating_remark | String | + * | ai_agent.source_type | String | + * | ai_agent.source_title | String | + * + * ### Accepted Operators + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :----------------------------- | :----------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In Shortcut for `OR` queries Values most be in Array | + * | NIN | All | Not In Shortcut for `OR !` queries Values must be in Array | + * | > | Integer Date (UNIX Timestamp) | Greater (or equal) than | + * | < | Integer Date (UNIX Timestamp) | Lower (or equal) than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function search(SearchRequest $request, ?array $options = null): Pager + { + return new CursorPager( + request: $request, + getNextPage: fn (SearchRequest $request) => $this->_search($request, $options), + setCursor: function (SearchRequest $request, ?string $cursor) { + PaginationHelper::setDeep($request, ["pagination", "startingAfter"], $cursor); + }, + /* @phpstan-ignore-next-line */ + getNextCursor: fn (PaginatedConversationResponse $response) => $response?->getPages()?->getNext()?->getStartingAfter() ?? null, + /* @phpstan-ignore-next-line */ + getItems: fn (PaginatedConversationResponse $response) => $response?->getConversations() ?? [], + ); + } + + /** + * You can reply to a conversation with a message from an admin or on behalf of a contact, or with a note for admins. + * + * @param ReplyToConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function reply(ReplyToConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/reply", + method: HttpMethod::POST, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * For managing conversations you can: + * - Close a conversation + * - Snooze a conversation to reopen on a future date + * - Open a conversation which is `snoozed` or `closed` + * - Assign a conversation to an admin and/or team. + * + * @param ManageConversationPartsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function manage(ManageConversationPartsRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/parts", + method: HttpMethod::POST, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * {% admonition type="danger" name="Deprecation of Run Assignment Rules" %} + * Run assignment rules is now deprecated in version 2.12 and future versions and will be permanently removed on December 31, 2026. After this date, any requests made to this endpoint will fail. + * {% /admonition %} + * You can let a conversation be automatically assigned following assignment rules. + * {% admonition type="warning" name="When using workflows" %} + * It is not possible to use this endpoint with Workflows. + * {% /admonition %} + * + * @param AutoAssignConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function runAssignmentRules(AutoAssignConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/run_assignment_rules", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can add participants who are contacts to a conversation, on behalf of either another contact or an admin. + * + * {% admonition type="warning" name="Contacts without an email" %} + * If you add a contact via the email parameter and there is no user/lead found on that workspace with he given email, then we will create a new contact with `role` set to `lead`. + * {% /admonition %} + * + * @param AttachContactToConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachContactAsAdmin(AttachContactToConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/customers", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can add participants who are contacts to a conversation, on behalf of either another contact or an admin. + * + * {% admonition type="warning" name="Contacts without an email" %} + * If you add a contact via the email parameter and there is no user/lead found on that workspace with he given email, then we will create a new contact with `role` set to `lead`. + * {% /admonition %} + * + * @param DetachContactFromConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachContactAsAdmin(DetachContactFromConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/customers/{$request->getContactId()}", + method: HttpMethod::DELETE, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can redact a conversation part or the source message of a conversation (as seen in the source object). + * + * {% admonition type="info" name="Redacting parts and messages" %} + * If you are redacting a conversation part, it must have a `body`. If you are redacting a source message, it must have been created by a contact. We will return a `conversation_part_not_redactable` error if these criteria are not met. + * {% /admonition %} + * + * @param RedactConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function redactConversationPart(RedactConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/redact", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can convert a conversation to a ticket. + * + * @param ConvertConversationToTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function convertToTicket(ConvertConversationToTicketRequest $request, ?array $options = null): Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/convert", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all conversations. + * + * You can optionally request the result page size and the cursor to start after to fetch the result. + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListConversationsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedConversationResponse + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListConversationsRequest $request = new ListConversationsRequest(), ?array $options = null): PaginatedConversationResponse + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getStartingAfter() != null) { + $query['starting_after'] = $request->getStartingAfter(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedConversationResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple conversations by the value of their attributes in order to fetch exactly which ones you want. + * + * To search for conversations, you need to send a `POST` request to `https://api.intercom.io/conversations/search`. + * + * This will accept a query object in the body which will define your filters in order to search for conversations. + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `20` results per page and maximum is `150`. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiple's there can be: + * - There's a limit of max 2 nested filters + * - There's a limit of max 15 filters for each AND or OR group + * + * ### Accepted Fields + * + * Most keys listed as part of the The conversation model is searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`). + * The `source.body` field is unique as the search will not be performed against the entire value, but instead against every element of the value separately. For example, when searching for a conversation with a `"I need support"` body - the query should contain a `=` operator with the value `"support"` for such conversation to be returned. A query with a `=` operator and a `"need support"` value will not yield a result. + * + * | Field | Type | + * | :---------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | + * | id | String | + * | created_at | Date (UNIX timestamp) | + * | updated_at | Date (UNIX timestamp) | + * | source.type | String
Accepted fields are `conversation`, `email`, `facebook`, `instagram`, `phone_call`, `phone_switch`, `push`, `sms`, `twitter` and `whatsapp`. | + * | source.id | String | + * | source.delivered_as | String | + * | source.subject | String | + * | source.body | String | + * | source.author.id | String | + * | source.author.type | String | + * | source.author.name | String | + * | source.author.email | String | + * | source.url | String | + * | contact_ids | String | + * | teammate_ids | String | + * | admin_assignee_id | String | + * | team_assignee_id | String | + * | channel_initiated | String | + * | open | Boolean | + * | read | Boolean | + * | state | String | + * | waiting_since | Date (UNIX timestamp) | + * | snoozed_until | Date (UNIX timestamp) | + * | tag_ids | String | + * | priority | String | + * | statistics.time_to_assignment | Integer | + * | statistics.time_to_admin_reply | Integer | + * | statistics.time_to_first_close | Integer | + * | statistics.time_to_last_close | Integer | + * | statistics.median_time_to_reply | Integer | + * | statistics.first_contact_reply_at | Date (UNIX timestamp) | + * | statistics.first_assignment_at | Date (UNIX timestamp) | + * | statistics.first_admin_reply_at | Date (UNIX timestamp) | + * | statistics.first_close_at | Date (UNIX timestamp) | + * | statistics.last_assignment_at | Date (UNIX timestamp) | + * | statistics.last_assignment_admin_reply_at | Date (UNIX timestamp) | + * | statistics.last_contact_reply_at | Date (UNIX timestamp) | + * | statistics.last_admin_reply_at | Date (UNIX timestamp) | + * | statistics.last_close_at | Date (UNIX timestamp) | + * | statistics.last_closed_by_id | String | + * | statistics.count_reopens | Integer | + * | statistics.count_assignments | Integer | + * | statistics.count_conversation_parts | Integer | + * | conversation_rating.requested_at | Date (UNIX timestamp) | + * | conversation_rating.replied_at | Date (UNIX timestamp) | + * | conversation_rating.score | Integer | + * | conversation_rating.remark | String | + * | conversation_rating.contact_id | String | + * | conversation_rating.admin_d | String | + * | ai_agent_participated | Boolean | + * | ai_agent.resolution_state | String | + * | ai_agent.last_answer_type | String | + * | ai_agent.rating | Integer | + * | ai_agent.rating_remark | String | + * | ai_agent.source_type | String | + * | ai_agent.source_title | String | + * + * ### Accepted Operators + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :----------------------------- | :----------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In Shortcut for `OR` queries Values most be in Array | + * | NIN | All | Not In Shortcut for `OR !` queries Values must be in Array | + * | > | Integer Date (UNIX Timestamp) | Greater (or equal) than | + * | < | Integer Date (UNIX Timestamp) | Lower (or equal) than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedConversationResponse + * @throws IntercomException + * @throws IntercomApiException + */ + private function _search(SearchRequest $request, ?array $options = null): PaginatedConversationResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/search", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedConversationResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Conversations/Requests/AttachContactToConversationRequest.php b/src/Conversations/Requests/AttachContactToConversationRequest.php new file mode 100644 index 00000000..668b7930 --- /dev/null +++ b/src/Conversations/Requests/AttachContactToConversationRequest.php @@ -0,0 +1,112 @@ +conversationId = $values['conversationId']; + $this->adminId = $values['adminId'] ?? null; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ( + * AttachContactToConversationRequestCustomerIntercomUserId + * |AttachContactToConversationRequestCustomerUserId + * |AttachContactToConversationRequestCustomerCustomer + * )|null + */ + public function getCustomer(): AttachContactToConversationRequestCustomerIntercomUserId|AttachContactToConversationRequestCustomerUserId|AttachContactToConversationRequestCustomerCustomer|null + { + return $this->customer; + } + + /** + * @param ( + * AttachContactToConversationRequestCustomerIntercomUserId + * |AttachContactToConversationRequestCustomerUserId + * |AttachContactToConversationRequestCustomerCustomer + * )|null $value + */ + public function setCustomer(AttachContactToConversationRequestCustomerIntercomUserId|AttachContactToConversationRequestCustomerUserId|AttachContactToConversationRequestCustomerCustomer|null $value = null): self + { + $this->customer = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/AutoAssignConversationRequest.php b/src/Conversations/Requests/AutoAssignConversationRequest.php new file mode 100644 index 00000000..0309f145 --- /dev/null +++ b/src/Conversations/Requests/AutoAssignConversationRequest.php @@ -0,0 +1,41 @@ +conversationId = $values['conversationId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/ConvertConversationToTicketRequest.php b/src/Conversations/Requests/ConvertConversationToTicketRequest.php new file mode 100644 index 00000000..71ed79e9 --- /dev/null +++ b/src/Conversations/Requests/ConvertConversationToTicketRequest.php @@ -0,0 +1,93 @@ + $attributes + */ + #[JsonProperty('attributes'), ArrayType(['string' => 'mixed'])] + private ?array $attributes; + + /** + * @param array{ + * conversationId: string, + * ticketTypeId: string, + * attributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->conversationId = $values['conversationId']; + $this->ticketTypeId = $values['ticketTypeId']; + $this->attributes = $values['attributes'] ?? null; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttributes(): ?array + { + return $this->attributes; + } + + /** + * @param ?array $value + */ + public function setAttributes(?array $value = null): self + { + $this->attributes = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/CreateConversationRequest.php b/src/Conversations/Requests/CreateConversationRequest.php new file mode 100644 index 00000000..35ed68e1 --- /dev/null +++ b/src/Conversations/Requests/CreateConversationRequest.php @@ -0,0 +1,94 @@ +from = $values['from']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + } + + /** + * @return CreateConversationRequestFrom + */ + public function getFrom(): CreateConversationRequestFrom + { + return $this->from; + } + + /** + * @param CreateConversationRequestFrom $value + */ + public function setFrom(CreateConversationRequestFrom $value): self + { + $this->from = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/DetachContactFromConversationRequest.php b/src/Conversations/Requests/DetachContactFromConversationRequest.php new file mode 100644 index 00000000..200678e7 --- /dev/null +++ b/src/Conversations/Requests/DetachContactFromConversationRequest.php @@ -0,0 +1,91 @@ +conversationId = $values['conversationId']; + $this->contactId = $values['contactId']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/FindConversationRequest.php b/src/Conversations/Requests/FindConversationRequest.php new file mode 100644 index 00000000..72b9922c --- /dev/null +++ b/src/Conversations/Requests/FindConversationRequest.php @@ -0,0 +1,65 @@ +conversationId = $values['conversationId']; + $this->displayAs = $values['displayAs'] ?? null; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDisplayAs(): ?string + { + return $this->displayAs; + } + + /** + * @param ?string $value + */ + public function setDisplayAs(?string $value = null): self + { + $this->displayAs = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/ListConversationsRequest.php b/src/Conversations/Requests/ListConversationsRequest.php new file mode 100644 index 00000000..b43587d2 --- /dev/null +++ b/src/Conversations/Requests/ListConversationsRequest.php @@ -0,0 +1,65 @@ +perPage = $values['perPage'] ?? null; + $this->startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/ManageConversationPartsRequest.php b/src/Conversations/Requests/ManageConversationPartsRequest.php new file mode 100644 index 00000000..633d16d4 --- /dev/null +++ b/src/Conversations/Requests/ManageConversationPartsRequest.php @@ -0,0 +1,66 @@ +conversationId = $values['conversationId']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return ConversationsManageRequestBody + */ + public function getBody(): ConversationsManageRequestBody + { + return $this->body; + } + + /** + * @param ConversationsManageRequestBody $value + */ + public function setBody(ConversationsManageRequestBody $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/ReplyToConversationRequest.php b/src/Conversations/Requests/ReplyToConversationRequest.php new file mode 100644 index 00000000..fb978428 --- /dev/null +++ b/src/Conversations/Requests/ReplyToConversationRequest.php @@ -0,0 +1,89 @@ +conversationId = $values['conversationId']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return ( + * ContactReplyIntercomUserIdRequest + * |ContactReplyEmailRequest + * |ContactReplyUserIdRequest + * |AdminReplyConversationRequest + * ) + */ + public function getBody(): ContactReplyIntercomUserIdRequest|ContactReplyEmailRequest|ContactReplyUserIdRequest|AdminReplyConversationRequest + { + return $this->body; + } + + /** + * @param ( + * ContactReplyIntercomUserIdRequest + * |ContactReplyEmailRequest + * |ContactReplyUserIdRequest + * |AdminReplyConversationRequest + * ) $value + */ + public function setBody(ContactReplyIntercomUserIdRequest|ContactReplyEmailRequest|ContactReplyUserIdRequest|AdminReplyConversationRequest $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Conversations/Requests/UpdateConversationRequest.php b/src/Conversations/Requests/UpdateConversationRequest.php new file mode 100644 index 00000000..e4dda34f --- /dev/null +++ b/src/Conversations/Requests/UpdateConversationRequest.php @@ -0,0 +1,117 @@ + $customAttributes + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * conversationId: string, + * displayAs?: ?string, + * read?: ?bool, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->conversationId = $values['conversationId']; + $this->displayAs = $values['displayAs'] ?? null; + $this->read = $values['read'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDisplayAs(): ?string + { + return $this->displayAs; + } + + /** + * @param ?string $value + */ + public function setDisplayAs(?string $value = null): self + { + $this->displayAs = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRead(): ?bool + { + return $this->read; + } + + /** + * @param ?bool $value + */ + public function setRead(?bool $value = null): self + { + $this->read = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } +} diff --git a/src/Conversations/Types/AttachContactToConversationRequestCustomerCustomer.php b/src/Conversations/Types/AttachContactToConversationRequestCustomerCustomer.php new file mode 100644 index 00000000..eb351497 --- /dev/null +++ b/src/Conversations/Types/AttachContactToConversationRequestCustomerCustomer.php @@ -0,0 +1,96 @@ +email = $values['email']; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null + */ + public function getCustomer(): CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null + { + return $this->customer; + } + + /** + * @param ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null $value + */ + public function setCustomer(CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null $value = null): self + { + $this->customer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Conversations/Types/AttachContactToConversationRequestCustomerIntercomUserId.php b/src/Conversations/Types/AttachContactToConversationRequestCustomerIntercomUserId.php new file mode 100644 index 00000000..08544b80 --- /dev/null +++ b/src/Conversations/Types/AttachContactToConversationRequestCustomerIntercomUserId.php @@ -0,0 +1,96 @@ +intercomUserId = $values['intercomUserId']; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null + */ + public function getCustomer(): CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null + { + return $this->customer; + } + + /** + * @param ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null $value + */ + public function setCustomer(CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null $value = null): self + { + $this->customer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Conversations/Types/AttachContactToConversationRequestCustomerUserId.php b/src/Conversations/Types/AttachContactToConversationRequestCustomerUserId.php new file mode 100644 index 00000000..50fefe17 --- /dev/null +++ b/src/Conversations/Types/AttachContactToConversationRequestCustomerUserId.php @@ -0,0 +1,96 @@ +userId = $values['userId']; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null + */ + public function getCustomer(): CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null + { + return $this->customer; + } + + /** + * @param ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null $value + */ + public function setCustomer(CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null $value = null): self + { + $this->customer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Conversations/Types/Conversation.php b/src/Conversations/Types/Conversation.php new file mode 100644 index 00000000..1e693fb3 --- /dev/null +++ b/src/Conversations/Types/Conversation.php @@ -0,0 +1,691 @@ + $state Can be set to "open", "closed" or "snoozed". + */ + #[JsonProperty('state')] + private string $state; + + /** + * @var bool $read Indicates whether a conversation has been read. + */ + #[JsonProperty('read')] + private bool $read; + + /** + * @var ?value-of $priority If marked as priority, it will return priority or else not_priority. + */ + #[JsonProperty('priority')] + private ?string $priority; + + /** + * @var ?int $adminAssigneeId The id of the admin assigned to the conversation. If it's not assigned to an admin it will return null. + */ + #[JsonProperty('admin_assignee_id')] + private ?int $adminAssigneeId; + + /** + * @var ?string $teamAssigneeId The id of the team assigned to the conversation. If it's not assigned to a team it will return null. + */ + #[JsonProperty('team_assignee_id')] + private ?string $teamAssigneeId; + + /** + * @var ?Tags $tags + */ + #[JsonProperty('tags')] + private ?Tags $tags; + + /** + * @var ?ConversationRating $conversationRating + */ + #[JsonProperty('conversation_rating')] + private ?ConversationRating $conversationRating; + + /** + * @var ConversationSource $source + */ + #[JsonProperty('source')] + private ConversationSource $source; + + /** + * @var ConversationContacts $contacts + */ + #[JsonProperty('contacts')] + private ConversationContacts $contacts; + + /** + * @var ConversationTeammates $teammates + */ + #[JsonProperty('teammates')] + private ConversationTeammates $teammates; + + /** + * @var array $customAttributes + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private array $customAttributes; + + /** + * @var ?ConversationFirstContactReply $firstContactReply + */ + #[JsonProperty('first_contact_reply')] + private ?ConversationFirstContactReply $firstContactReply; + + /** + * @var ?SlaApplied $slaApplied + */ + #[JsonProperty('sla_applied')] + private ?SlaApplied $slaApplied; + + /** + * @var ?ConversationStatistics $statistics + */ + #[JsonProperty('statistics')] + private ?ConversationStatistics $statistics; + + /** + * @var ?ConversationParts $conversationParts + */ + #[JsonProperty('conversation_parts')] + private ?ConversationParts $conversationParts; + + /** + * @var ?LinkedObjectList $linkedObjects + */ + #[JsonProperty('linked_objects')] + private ?LinkedObjectList $linkedObjects; + + /** + * @var ?bool $aiAgentParticipated Indicates whether the AI Agent participated in the conversation. + */ + #[JsonProperty('ai_agent_participated')] + private ?bool $aiAgentParticipated; + + /** + * @var ?AiAgent $aiAgent + */ + #[JsonProperty('ai_agent')] + private ?AiAgent $aiAgent; + + /** + * @param array{ + * id: string, + * createdAt: int, + * updatedAt: int, + * open: bool, + * state: value-of, + * read: bool, + * source: ConversationSource, + * contacts: ConversationContacts, + * teammates: ConversationTeammates, + * customAttributes: array, + * type?: ?'conversation', + * title?: ?string, + * waitingSince?: ?int, + * snoozedUntil?: ?int, + * priority?: ?value-of, + * adminAssigneeId?: ?int, + * teamAssigneeId?: ?string, + * tags?: ?Tags, + * conversationRating?: ?ConversationRating, + * firstContactReply?: ?ConversationFirstContactReply, + * slaApplied?: ?SlaApplied, + * statistics?: ?ConversationStatistics, + * conversationParts?: ?ConversationParts, + * linkedObjects?: ?LinkedObjectList, + * aiAgentParticipated?: ?bool, + * aiAgent?: ?AiAgent, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id']; + $this->title = $values['title'] ?? null; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->waitingSince = $values['waitingSince'] ?? null; + $this->snoozedUntil = $values['snoozedUntil'] ?? null; + $this->open = $values['open']; + $this->state = $values['state']; + $this->read = $values['read']; + $this->priority = $values['priority'] ?? null; + $this->adminAssigneeId = $values['adminAssigneeId'] ?? null; + $this->teamAssigneeId = $values['teamAssigneeId'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->conversationRating = $values['conversationRating'] ?? null; + $this->source = $values['source']; + $this->contacts = $values['contacts']; + $this->teammates = $values['teammates']; + $this->customAttributes = $values['customAttributes']; + $this->firstContactReply = $values['firstContactReply'] ?? null; + $this->slaApplied = $values['slaApplied'] ?? null; + $this->statistics = $values['statistics'] ?? null; + $this->conversationParts = $values['conversationParts'] ?? null; + $this->linkedObjects = $values['linkedObjects'] ?? null; + $this->aiAgentParticipated = $values['aiAgentParticipated'] ?? null; + $this->aiAgent = $values['aiAgent'] ?? null; + } + + /** + * @return ?'conversation' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'conversation' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getWaitingSince(): ?int + { + return $this->waitingSince; + } + + /** + * @param ?int $value + */ + public function setWaitingSince(?int $value = null): self + { + $this->waitingSince = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSnoozedUntil(): ?int + { + return $this->snoozedUntil; + } + + /** + * @param ?int $value + */ + public function setSnoozedUntil(?int $value = null): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return bool + */ + public function getOpen(): bool + { + return $this->open; + } + + /** + * @param bool $value + */ + public function setOpen(bool $value): self + { + $this->open = $value; + return $this; + } + + /** + * @return value-of + */ + public function getState(): string + { + return $this->state; + } + + /** + * @param value-of $value + */ + public function setState(string $value): self + { + $this->state = $value; + return $this; + } + + /** + * @return bool + */ + public function getRead(): bool + { + return $this->read; + } + + /** + * @param bool $value + */ + public function setRead(bool $value): self + { + $this->read = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getPriority(): ?string + { + return $this->priority; + } + + /** + * @param ?value-of $value + */ + public function setPriority(?string $value = null): self + { + $this->priority = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAdminAssigneeId(): ?int + { + return $this->adminAssigneeId; + } + + /** + * @param ?int $value + */ + public function setAdminAssigneeId(?int $value = null): self + { + $this->adminAssigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTeamAssigneeId(): ?string + { + return $this->teamAssigneeId; + } + + /** + * @param ?string $value + */ + public function setTeamAssigneeId(?string $value = null): self + { + $this->teamAssigneeId = $value; + return $this; + } + + /** + * @return ?Tags + */ + public function getTags(): ?Tags + { + return $this->tags; + } + + /** + * @param ?Tags $value + */ + public function setTags(?Tags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?ConversationRating + */ + public function getConversationRating(): ?ConversationRating + { + return $this->conversationRating; + } + + /** + * @param ?ConversationRating $value + */ + public function setConversationRating(?ConversationRating $value = null): self + { + $this->conversationRating = $value; + return $this; + } + + /** + * @return ConversationSource + */ + public function getSource(): ConversationSource + { + return $this->source; + } + + /** + * @param ConversationSource $value + */ + public function setSource(ConversationSource $value): self + { + $this->source = $value; + return $this; + } + + /** + * @return ConversationContacts + */ + public function getContacts(): ConversationContacts + { + return $this->contacts; + } + + /** + * @param ConversationContacts $value + */ + public function setContacts(ConversationContacts $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ConversationTeammates + */ + public function getTeammates(): ConversationTeammates + { + return $this->teammates; + } + + /** + * @param ConversationTeammates $value + */ + public function setTeammates(ConversationTeammates $value): self + { + $this->teammates = $value; + return $this; + } + + /** + * @return array + */ + public function getCustomAttributes(): array + { + return $this->customAttributes; + } + + /** + * @param array $value + */ + public function setCustomAttributes(array $value): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?ConversationFirstContactReply + */ + public function getFirstContactReply(): ?ConversationFirstContactReply + { + return $this->firstContactReply; + } + + /** + * @param ?ConversationFirstContactReply $value + */ + public function setFirstContactReply(?ConversationFirstContactReply $value = null): self + { + $this->firstContactReply = $value; + return $this; + } + + /** + * @return ?SlaApplied + */ + public function getSlaApplied(): ?SlaApplied + { + return $this->slaApplied; + } + + /** + * @param ?SlaApplied $value + */ + public function setSlaApplied(?SlaApplied $value = null): self + { + $this->slaApplied = $value; + return $this; + } + + /** + * @return ?ConversationStatistics + */ + public function getStatistics(): ?ConversationStatistics + { + return $this->statistics; + } + + /** + * @param ?ConversationStatistics $value + */ + public function setStatistics(?ConversationStatistics $value = null): self + { + $this->statistics = $value; + return $this; + } + + /** + * @return ?ConversationParts + */ + public function getConversationParts(): ?ConversationParts + { + return $this->conversationParts; + } + + /** + * @param ?ConversationParts $value + */ + public function setConversationParts(?ConversationParts $value = null): self + { + $this->conversationParts = $value; + return $this; + } + + /** + * @return ?LinkedObjectList + */ + public function getLinkedObjects(): ?LinkedObjectList + { + return $this->linkedObjects; + } + + /** + * @param ?LinkedObjectList $value + */ + public function setLinkedObjects(?LinkedObjectList $value = null): self + { + $this->linkedObjects = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAiAgentParticipated(): ?bool + { + return $this->aiAgentParticipated; + } + + /** + * @param ?bool $value + */ + public function setAiAgentParticipated(?bool $value = null): self + { + $this->aiAgentParticipated = $value; + return $this; + } + + /** + * @return ?AiAgent + */ + public function getAiAgent(): ?AiAgent + { + return $this->aiAgent; + } + + /** + * @param ?AiAgent $value + */ + public function setAiAgent(?AiAgent $value = null): self + { + $this->aiAgent = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Conversations/Types/ConversationPriority.php b/src/Conversations/Types/ConversationPriority.php new file mode 100644 index 00000000..5a5ffc54 --- /dev/null +++ b/src/Conversations/Types/ConversationPriority.php @@ -0,0 +1,9 @@ +messageType = $values['messageType']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'close' + * |'snoozed' + * |'open' + * |'assignment' + * |'_unknown' + * ) + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @return ( + * CloseConversationRequest + * |SnoozeConversationRequest + * |OpenConversationRequest + * |AssignConversationRequest + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param CloseConversationRequest $close + * @return ConversationsManageRequestBody + */ + public static function close(CloseConversationRequest $close): ConversationsManageRequestBody + { + return new ConversationsManageRequestBody([ + 'messageType' => 'close', + 'value' => $close, + ]); + } + + /** + * @param SnoozeConversationRequest $snoozed + * @return ConversationsManageRequestBody + */ + public static function snoozed(SnoozeConversationRequest $snoozed): ConversationsManageRequestBody + { + return new ConversationsManageRequestBody([ + 'messageType' => 'snoozed', + 'value' => $snoozed, + ]); + } + + /** + * @param OpenConversationRequest $open + * @return ConversationsManageRequestBody + */ + public static function open(OpenConversationRequest $open): ConversationsManageRequestBody + { + return new ConversationsManageRequestBody([ + 'messageType' => 'open', + 'value' => $open, + ]); + } + + /** + * @param AssignConversationRequest $assignment + * @return ConversationsManageRequestBody + */ + public static function assignment(AssignConversationRequest $assignment): ConversationsManageRequestBody + { + return new ConversationsManageRequestBody([ + 'messageType' => 'assignment', + 'value' => $assignment, + ]); + } + + /** + * @return bool + */ + public function isClose(): bool + { + return $this->value instanceof CloseConversationRequest && $this->messageType === 'close'; + } + + /** + * @return CloseConversationRequest + */ + public function asClose(): CloseConversationRequest + { + if (!($this->value instanceof CloseConversationRequest && $this->messageType === 'close')) { + throw new Exception( + "Expected close; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSnoozed(): bool + { + return $this->value instanceof SnoozeConversationRequest && $this->messageType === 'snoozed'; + } + + /** + * @return SnoozeConversationRequest + */ + public function asSnoozed(): SnoozeConversationRequest + { + if (!($this->value instanceof SnoozeConversationRequest && $this->messageType === 'snoozed')) { + throw new Exception( + "Expected snoozed; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isOpen(): bool + { + return $this->value instanceof OpenConversationRequest && $this->messageType === 'open'; + } + + /** + * @return OpenConversationRequest + */ + public function asOpen(): OpenConversationRequest + { + if (!($this->value instanceof OpenConversationRequest && $this->messageType === 'open')) { + throw new Exception( + "Expected open; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isAssignment(): bool + { + return $this->value instanceof AssignConversationRequest && $this->messageType === 'assignment'; + } + + /** + * @return AssignConversationRequest + */ + public function asAssignment(): AssignConversationRequest + { + if (!($this->value instanceof AssignConversationRequest && $this->messageType === 'assignment')) { + throw new Exception( + "Expected assignment; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['message_type'] = $this->messageType; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->messageType) { + case 'close': + $value = $this->asClose()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'snoozed': + $value = $this->asSnoozed()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'open': + $value = $this->asOpen()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'assignment': + $value = $this->asAssignment()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('message_type', $data)) { + throw new Exception( + "JSON data is missing property 'message_type'", + ); + } + $messageType = $data['message_type']; + if (!(is_string($messageType))) { + throw new Exception( + "Expected property 'messageType' in JSON data to be string, instead received " . get_debug_type($data['message_type']), + ); + } + + $args['messageType'] = $messageType; + switch ($messageType) { + case 'close': + $args['value'] = CloseConversationRequest::jsonDeserialize($data); + break; + case 'snoozed': + $args['value'] = SnoozeConversationRequest::jsonDeserialize($data); + break; + case 'open': + $args['value'] = OpenConversationRequest::jsonDeserialize($data); + break; + case 'assignment': + $args['value'] = AssignConversationRequest::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['messageType'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Conversations/Types/CreateConversationRequestFrom.php b/src/Conversations/Types/CreateConversationRequestFrom.php new file mode 100644 index 00000000..b2b7f369 --- /dev/null +++ b/src/Conversations/Types/CreateConversationRequestFrom.php @@ -0,0 +1,76 @@ + $type The role associated to the contact - user or lead. + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The identifier for the contact which is given by Intercom. + */ + #[JsonProperty('id')] + private string $id; + + /** + * @param array{ + * type: value-of, + * id: string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Conversations/Types/CreateConversationRequestFromType.php b/src/Conversations/Types/CreateConversationRequestFromType.php new file mode 100644 index 00000000..dd3baa34 --- /dev/null +++ b/src/Conversations/Types/CreateConversationRequestFromType.php @@ -0,0 +1,10 @@ + $headers Additional headers for the request (optional) + * @param array $query Query parameters for the request (optional) + */ + public function __construct( + public readonly string $baseUrl, + public readonly string $path, + public readonly HttpMethod $method, + public readonly array $headers = [], + public readonly array $query = [], + ) { + } +} diff --git a/src/Core/Client/HttpMethod.php b/src/Core/Client/HttpMethod.php new file mode 100644 index 00000000..ce906fce --- /dev/null +++ b/src/Core/Client/HttpMethod.php @@ -0,0 +1,12 @@ + $headers + */ + private array $headers; + + /** + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * headers?: array, + * } $options + */ + public function __construct( + public readonly ?array $options = null, + ) { + $this->client = $this->options['client'] + ?? $this->createDefaultClient(); + $this->headers = $this->options['headers'] ?? []; + } + + /** + * @return Client + */ + private function createDefaultClient(): Client + { + $handler = HandlerStack::create(); + $handler->push(RetryMiddleware::create()); + return new Client(['handler' => $handler]); + } + + /** + * @param BaseApiRequest $request + * @param ?array{ + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ResponseInterface + * @throws ClientExceptionInterface + */ + public function sendRequest( + BaseApiRequest $request, + ?array $options = null, + ): ResponseInterface { + $opts = $options ?? []; + $httpRequest = $this->buildRequest($request, $opts); + return $this->client->send($httpRequest, $this->toGuzzleOptions($opts)); + } + + /** + * @param array{ + * maxRetries?: int, + * timeout?: float, + * } $options + * @return array + */ + private function toGuzzleOptions(array $options): array + { + $guzzleOptions = []; + if (isset($options['maxRetries'])) { + $guzzleOptions['maxRetries'] = $options['maxRetries']; + } + if (isset($options['timeout'])) { + $guzzleOptions['timeout'] = $options['timeout']; + } + return $guzzleOptions; + } + + /** + * @param BaseApiRequest $request + * @param array{ + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Request + */ + private function buildRequest( + BaseApiRequest $request, + array $options + ): Request { + $url = $this->buildUrl($request, $options); + $headers = $this->encodeHeaders($request, $options); + $body = $this->encodeRequestBody($request, $options); + return new Request( + $request->method->name, + $url, + $headers, + $body, + ); + } + + /** + * @param BaseApiRequest $request + * @param array{ + * headers?: array, + * } $options + * @return array + */ + private function encodeHeaders( + BaseApiRequest $request, + array $options, + ): array { + return match (get_class($request)) { + JsonApiRequest::class => array_merge( + [ + "Content-Type" => "application/json", + "Accept" => "*/*", + ], + $this->headers, + $request->headers, + $options['headers'] ?? [], + ), + MultipartApiRequest::class => array_merge( + $this->headers, + $request->headers, + $options['headers'] ?? [], + ), + default => throw new InvalidArgumentException('Unsupported request type: ' . get_class($request)), + }; + } + + /** + * @param BaseApiRequest $request + * @param array{ + * bodyProperties?: array, + * } $options + * @return ?StreamInterface + */ + private function encodeRequestBody( + BaseApiRequest $request, + array $options, + ): ?StreamInterface { + return match (get_class($request)) { + JsonApiRequest::class => $request->body === null ? null : Utils::streamFor( + json_encode( + $this->buildJsonBody( + $request->body, + $options, + ), + ) + ), + MultipartApiRequest::class => $request->body != null ? new MultipartStream($request->body->toArray()) : null, + default => throw new InvalidArgumentException('Unsupported request type: ' . get_class($request)), + }; + } + + /** + * @param mixed $body + * @param array{ + * bodyProperties?: array, + * } $options + * @return mixed + */ + private function buildJsonBody( + mixed $body, + array $options, + ): mixed { + $overrideProperties = $options['bodyProperties'] ?? []; + if (is_array($body) && (empty($body) || self::isSequential($body))) { + return array_merge($body, $overrideProperties); + } + + if ($body instanceof JsonSerializable) { + $result = $body->jsonSerialize(); + } else { + $result = $body; + } + if (is_array($result)) { + $result = array_merge($result, $overrideProperties); + if (empty($result)) { + // force to be serialized as {} instead of [] + return (object)($result); + } + } + + return $result; + } + + /** + * @param BaseApiRequest $request + * @param array{ + * queryParameters?: array, + * } $options + * @return string + */ + private function buildUrl( + BaseApiRequest $request, + array $options, + ): string { + $baseUrl = $request->baseUrl; + $trimmedBaseUrl = rtrim($baseUrl, '/'); + $trimmedBasePath = ltrim($request->path, '/'); + $url = "{$trimmedBaseUrl}/{$trimmedBasePath}"; + $query = array_merge( + $request->query, + $options['queryParameters'] ?? [], + ); + if (!empty($query)) { + $url .= '?' . $this->encodeQuery($query); + } + return $url; + } + + /** + * @param array $query + * @return string + */ + private function encodeQuery(array $query): string + { + $parts = []; + foreach ($query as $key => $value) { + if (is_array($value)) { + foreach ($value as $item) { + $parts[] = urlencode($key) . '=' . $this->encodeQueryValue($item); + } + } else { + $parts[] = urlencode($key) . '=' . $this->encodeQueryValue($value); + } + } + return implode('&', $parts); + } + + private function encodeQueryValue(mixed $value): string + { + if (is_string($value)) { + return urlencode($value); + } + if (is_scalar($value)) { + return urlencode((string)$value); + } + if (is_null($value)) { + return 'null'; + } + // Unreachable, but included for a best effort. + return urlencode(strval(json_encode($value))); + } + + /** + * Check if an array is sequential, not associative. + * @param mixed[] $arr + * @return bool + */ + private static function isSequential(array $arr): bool + { + if (empty($arr)) { + return false; + } + $length = count($arr); + $keys = array_keys($arr); + for ($i = 0; $i < $length; $i++) { + if ($keys[$i] !== $i) { + return false; + } + } + return true; + } +} diff --git a/src/Core/Client/RetryMiddleware.php b/src/Core/Client/RetryMiddleware.php new file mode 100644 index 00000000..e8219f51 --- /dev/null +++ b/src/Core/Client/RetryMiddleware.php @@ -0,0 +1,191 @@ + 2, + 'baseDelay' => 1000 + ]; + private const RETRY_STATUS_CODES = [408, 429]; + + /** + * @var callable(RequestInterface, array): PromiseInterface + * @phpstan-ignore missingType.iterableValue + */ + private $nextHandler; + + /** + * @var array{ + * maxRetries: int, + * baseDelay: int, + * } + */ + private array $options; + + /** + * @param callable $nextHandler + * @param ?array{ + * maxRetries?: int, + * } $options + */ + public function __construct( + callable $nextHandler, + ?array $options = null, + ) { + $this->nextHandler = $nextHandler; + $this->options = array_merge(self::DEFAULT_RETRY_OPTIONS, $options ?? []); + } + + /** + * @param ?array{ + * maxRetries?: int, + * baseDelay?: int, + * } $options + * @return callable + */ + public static function create(?array $options = null): callable + { + return static function (callable $handler) use ($options): RetryMiddleware { + return new RetryMiddleware($handler, $options); + }; + } + + /** + * @param RequestInterface $request + * @param array{ + * retryAttempt?: int, + * delay: int, + * maxRetries?: int, + * } $options + * @return PromiseInterface + */ + public function __invoke(RequestInterface $request, array $options): PromiseInterface + { + $options = array_merge($this->options, $options); + if (!isset($options['retryAttempt'])) { + $options['retryAttempt'] = 0; + } + + $fn = $this->nextHandler; + + return $fn($request, $options) + ->then( + $this->onFulfilled($request, $options), + $this->onRejected($request, $options) + ); + } + + /** + * @param int $retryAttempt + * @param int $maxRetries + * @param ?ResponseInterface $response + * @param ?Throwable $exception + * @return bool + */ + private function shouldRetry( + int $retryAttempt, + int $maxRetries, + ?ResponseInterface $response = null, + ?Throwable $exception = null + ): bool { + if ($retryAttempt >= $maxRetries) { + return false; + } + + if ($exception instanceof ConnectException) { + return true; + } + + if ($response) { + return $response->getStatusCode() >= 500 || + in_array($response->getStatusCode(), self::RETRY_STATUS_CODES); + } + return false; + } + + /** + * Execute fulfilled closure + * @param array{ + * retryAttempt: int, + * delay: int, + * maxRetries: int, + * } $options + */ + private function onFulfilled(RequestInterface $request, array $options): callable + { + $retryAttempt = $options['retryAttempt']; + $maxRetries = $options['maxRetries']; + return function ($value) use ($request, $options, $retryAttempt, $maxRetries) { + if (!$this->shouldRetry( + $retryAttempt, + $maxRetries, + $value + )) { + return $value; + } + + return $this->doRetry($request, $options); + }; + } + + /** + * Execute rejected closure + * @param RequestInterface $req + * @param array{ + * retryAttempt: int, + * delay: int, + * maxRetries: int, + * } $options + * @return callable + */ + private function onRejected(RequestInterface $req, array $options): callable + { + $retryAttempt = $options['retryAttempt']; + $maxRetries = $options['maxRetries']; + return function ($reason) use ($req, $options, $retryAttempt, $maxRetries) { + if (!$this->shouldRetry( + $retryAttempt, + $maxRetries, + null, + $reason + )) { + return P\Create::rejectionFor($reason); + } + + return $this->doRetry($req, $options); + }; + } + + /** + * @param RequestInterface $request + * @param array{ + * delay: int, + * retryAttempt: int, + * } $options + * @return PromiseInterface + */ + private function doRetry(RequestInterface $request, array $options): PromiseInterface + { + $options['delay'] = $this->exponentialDelay(++$options['retryAttempt']); + return $this($request, $options); + } + + /** + * Default exponential backoff delay function. + * + * @return int milliseconds. + */ + private function exponentialDelay(int $retryAttempt): int + { + return 2 ** ($retryAttempt - 1) * $this->options['baseDelay']; + } +} diff --git a/src/Core/Json/JsonApiRequest.php b/src/Core/Json/JsonApiRequest.php new file mode 100644 index 00000000..d31c0f0f --- /dev/null +++ b/src/Core/Json/JsonApiRequest.php @@ -0,0 +1,28 @@ + $headers Additional headers for the request (optional) + * @param array $query Query parameters for the request (optional) + * @param mixed|null $body The JSON request body (optional) + */ + public function __construct( + string $baseUrl, + string $path, + HttpMethod $method, + array $headers = [], + array $query = [], + public readonly mixed $body = null + ) { + parent::__construct($baseUrl, $path, $method, $headers, $query); + } +} diff --git a/src/Core/Json/JsonDecoder.php b/src/Core/Json/JsonDecoder.php new file mode 100644 index 00000000..c2b51fc3 --- /dev/null +++ b/src/Core/Json/JsonDecoder.php @@ -0,0 +1,161 @@ + $type The type definition for deserialization. + * @return mixed[]|array The deserialized array. + * @throws JsonException If the decoded value is not an array. + */ + public static function decodeArray(string $json, array $type): array + { + $decoded = self::decode($json); + if (!is_array($decoded)) { + throw new JsonException("Unexpected non-array json value: " . $json); + } + return JsonDeserializer::deserializeArray($decoded, $type); + } + + /** + * Decodes a JSON string and deserializes it based on the provided union type definition. + * + * @param string $json The JSON string to decode. + * @param Union $union The union type definition for deserialization. + * @return mixed The deserialized value. + * @throws JsonException If the deserialization for all types in the union fails. + */ + public static function decodeUnion(string $json, Union $union): mixed + { + $decoded = self::decode($json); + return JsonDeserializer::deserializeUnion($decoded, $union); + } + /** + * Decodes a JSON string and returns a mixed. + * + * @param string $json The JSON string to decode. + * @return mixed The decoded mixed. + * @throws JsonException If the decoded value is not an mixed. + */ + public static function decodeMixed(string $json): mixed + { + return self::decode($json); + } + + /** + * Decodes a JSON string into a PHP value. + * + * @param string $json The JSON string to decode. + * @return mixed The decoded value. + * @throws JsonException If an error occurs during JSON decoding. + */ + public static function decode(string $json): mixed + { + return json_decode($json, associative: true, flags: JSON_THROW_ON_ERROR); + } +} diff --git a/src/Core/Json/JsonDeserializer.php b/src/Core/Json/JsonDeserializer.php new file mode 100644 index 00000000..825d08e5 --- /dev/null +++ b/src/Core/Json/JsonDeserializer.php @@ -0,0 +1,204 @@ + $data The array to be deserialized. + * @param mixed[]|array $type The type definition from the annotation. + * @return mixed[]|array The deserialized array. + * @throws JsonException If deserialization fails. + */ + public static function deserializeArray(array $data, array $type): array + { + return Utils::isMapType($type) + ? self::deserializeMap($data, $type) + : self::deserializeList($data, $type); + } + + /** + * Deserializes a value based on its type definition. + * + * @param mixed $data The data to deserialize. + * @param mixed $type The type definition. + * @return mixed The deserialized value. + * @throws JsonException If deserialization fails. + */ + private static function deserializeValue(mixed $data, mixed $type): mixed + { + if ($type instanceof Union) { + return self::deserializeUnion($data, $type); + } + + if (is_array($type)) { + return self::deserializeArray((array)$data, $type); + } + + if (gettype($type) != "string") { + throw new JsonException("Unexpected non-string type."); + } + + return self::deserializeSingleValue($data, $type); + } + + /** + * Deserializes a value based on the possible types in a union type definition. + * + * @param mixed $data The data to deserialize. + * @param Union $type The union type definition. + * @return mixed The deserialized value. + * @throws JsonException If none of the union types can successfully deserialize the value. + */ + public static function deserializeUnion(mixed $data, Union $type): mixed + { + foreach ($type->types as $unionType) { + try { + return self::deserializeValue($data, $unionType); + } catch (Exception) { + continue; + } + } + $readableType = Utils::getReadableType($data); + throw new JsonException( + "Cannot deserialize value of type $readableType with any of the union types: " . $type + ); + } + + /** + * Deserializes a single value based on its expected type. + * + * @param mixed $data The data to deserialize. + * @param string $type The expected type. + * @return mixed The deserialized value. + * @throws JsonException If deserialization fails. + */ + private static function deserializeSingleValue(mixed $data, string $type): mixed + { + if ($type === 'null' && $data === null) { + return null; + } + + if ($type === 'date' && is_string($data)) { + return self::deserializeDate($data); + } + + if ($type === 'datetime' && is_string($data)) { + return self::deserializeDateTime($data); + } + + if ($type === 'mixed') { + return $data; + } + + if (class_exists($type) && is_array($data)) { + return self::deserializeObject($data, $type); + } + + // Handle floats as a special case since gettype($data) returns "double" for float values in PHP, and because + // floats make come through from json_decoded as integers + if ($type === 'float' && (is_numeric($data))) { + return (float) $data; + } + + if (gettype($data) === $type) { + return $data; + } + + throw new JsonException("Unable to deserialize value of type '" . gettype($data) . "' as '$type'."); + } + + /** + * Deserializes an array into an object of the given type. + * + * @param array $data The data to deserialize. + * @param string $type The class name of the object to deserialize into. + * + * @return object The deserialized object. + * + * @throws JsonException If the type does not implement JsonSerializableType. + */ + public static function deserializeObject(array $data, string $type): object + { + if (!is_subclass_of($type, JsonSerializableType::class)) { + throw new JsonException("$type is not a subclass of JsonSerializableType."); + } + return $type::jsonDeserialize($data); + } + + /** + * Deserializes a map (associative array) with defined key and value types. + * + * @param array $data The associative array to deserialize. + * @param array $type The type definition for the map. + * @return array The deserialized map. + * @throws JsonException If deserialization fails. + */ + private static function deserializeMap(array $data, array $type): array + { + $keyType = array_key_first($type); + $valueType = $type[$keyType]; + $result = []; + + foreach ($data as $key => $item) { + $key = Utils::castKey($key, (string)$keyType); + $result[$key] = self::deserializeValue($item, $valueType); + } + + return $result; + } + + /** + * Deserializes a list (indexed array) with a defined value type. + * + * @param array $data The list to deserialize. + * @param array $type The type definition for the list. + * @return array The deserialized list. + * @throws JsonException If deserialization fails. + */ + private static function deserializeList(array $data, array $type): array + { + $valueType = $type[0]; + return array_map(fn ($item) => self::deserializeValue($item, $valueType), $data); + } +} diff --git a/src/Core/Json/JsonEncoder.php b/src/Core/Json/JsonEncoder.php new file mode 100644 index 00000000..d6637421 --- /dev/null +++ b/src/Core/Json/JsonEncoder.php @@ -0,0 +1,20 @@ + Extra properties from JSON that don't map to class properties */ + private array $__additionalProperties = []; + + /** + * Serializes the object to a JSON string. + * + * @return string JSON-encoded string representation of the object. + * @throws Exception If encoding fails. + */ + public function toJson(): string + { + $serializedObject = $this->jsonSerialize(); + $encoded = JsonEncoder::encode($serializedObject); + if (!$encoded) { + throw new Exception("Could not encode type"); + } + return $encoded; + } + + /** + * Serializes the object to an array. + * + * @return mixed[] Array representation of the object. + * @throws JsonException If serialization fails. + */ + public function jsonSerialize(): array + { + $result = []; + $reflectionClass = new \ReflectionClass($this); + foreach ($reflectionClass->getProperties() as $property) { + $jsonKey = self::getJsonKey($property); + if ($jsonKey == null) { + continue; + } + $value = $property->getValue($this); + + // Handle DateTime properties + $dateTypeAttr = $property->getAttributes(Date::class)[0] ?? null; + if ($dateTypeAttr && $value instanceof DateTime) { + $dateType = $dateTypeAttr->newInstance()->type; + $value = ($dateType === Date::TYPE_DATE) + ? JsonSerializer::serializeDate($value) + : JsonSerializer::serializeDateTime($value); + } + + // Handle Union annotations + $unionTypeAttr = $property->getAttributes(Union::class)[0] ?? null; + if ($unionTypeAttr) { + $unionType = $unionTypeAttr->newInstance(); + $value = JsonSerializer::serializeUnion($value, $unionType); + } + + // Handle arrays with type annotations + $arrayTypeAttr = $property->getAttributes(ArrayType::class)[0] ?? null; + if ($arrayTypeAttr && is_array($value)) { + $arrayType = $arrayTypeAttr->newInstance()->type; + $value = JsonSerializer::serializeArray($value, $arrayType); + } + + // Handle object + if (is_object($value)) { + $value = JsonSerializer::serializeObject($value); + } + + if ($value !== null) { + $result[$jsonKey] = $value; + } + } + return $result; + } + + /** + * Deserializes a JSON string into an instance of the calling class. + * + * @param string $json JSON string to deserialize. + * @return static Deserialized object. + * @throws JsonException If decoding fails or the result is not an array. + * @throws Exception If deserialization fails. + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new JsonException("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * Deserializes an array into an instance of the calling class. + * + * @param array $data Array data to deserialize. + * @return static Deserialized object. + * @throws JsonException If deserialization fails. + */ + public static function jsonDeserialize(array $data): static + { + $reflectionClass = new \ReflectionClass(static::class); + $constructor = $reflectionClass->getConstructor(); + if ($constructor === null) { + throw new JsonException("No constructor found."); + } + + $args = []; + $properties = []; + $additionalProperties = []; + foreach ($reflectionClass->getProperties() as $property) { + $jsonKey = self::getJsonKey($property) ?? $property->getName(); + $properties[$jsonKey] = $property; + } + + foreach ($data as $jsonKey => $value) { + if (!isset($properties[$jsonKey])) { + // This JSON key doesn't map to any class property - add it to additionalProperties + $additionalProperties[$jsonKey] = $value; + continue; + } + + $property = $properties[$jsonKey]; + + // Handle Date annotation + $dateTypeAttr = $property->getAttributes(Date::class)[0] ?? null; + if ($dateTypeAttr) { + $dateType = $dateTypeAttr->newInstance()->type; + if (!is_string($value)) { + throw new JsonException("Unexpected non-string type for date."); + } + $value = ($dateType === Date::TYPE_DATE) + ? JsonDeserializer::deserializeDate($value) + : JsonDeserializer::deserializeDateTime($value); + } + + // Handle Array annotation + $arrayTypeAttr = $property->getAttributes(ArrayType::class)[0] ?? null; + if (is_array($value) && $arrayTypeAttr) { + $arrayType = $arrayTypeAttr->newInstance()->type; + $value = JsonDeserializer::deserializeArray($value, $arrayType); + } + + // Handle Union annotations + $unionTypeAttr = $property->getAttributes(Union::class)[0] ?? null; + if ($unionTypeAttr) { + $unionType = $unionTypeAttr->newInstance(); + $value = JsonDeserializer::deserializeUnion($value, $unionType); + } + + // Handle object + $type = $property->getType(); + if (is_array($value) && $type instanceof ReflectionNamedType && !$type->isBuiltin()) { + $value = JsonDeserializer::deserializeObject($value, $type->getName()); + } + + $args[$property->getName()] = $value; + } + + // Fill in any missing properties with defaults + foreach ($properties as $property) { + if (!isset($args[$property->getName()])) { + $args[$property->getName()] = $property->getDefaultValue() ?? null; + } + } + + // @phpstan-ignore-next-line + $result = new static($args); + $result->__additionalProperties = $additionalProperties; + return $result; + } + + /** + * Get properties from JSON that weren't mapped to class fields + * @return array + */ + public function getAdditionalProperties(): array + { + return $this->__additionalProperties; + } + + /** + * Retrieves the JSON key associated with a property. + * + * @param ReflectionProperty $property The reflection property. + * @return ?string The JSON key, or null if not available. + */ + private static function getJsonKey(ReflectionProperty $property): ?string + { + $jsonPropertyAttr = $property->getAttributes(JsonProperty::class)[0] ?? null; + return $jsonPropertyAttr?->newInstance()?->name; + } +} diff --git a/src/Core/Json/JsonSerializer.php b/src/Core/Json/JsonSerializer.php new file mode 100644 index 00000000..d1279231 --- /dev/null +++ b/src/Core/Json/JsonSerializer.php @@ -0,0 +1,192 @@ +format(Constant::DateFormat); + } + + /** + * Serializes a DateTime object into a string using the date-time format. + * + * @param DateTime $date The DateTime object to serialize. + * @return string The serialized date-time string. + */ + public static function serializeDateTime(DateTime $date): string + { + return $date->format(Constant::DateTimeFormat); + } + + /** + * Serializes an array based on type annotations (either a list or map). + * + * @param mixed[]|array $data The array to be serialized. + * @param mixed[]|array $type The type definition from the annotation. + * @return mixed[]|array The serialized array. + * @throws JsonException If serialization fails. + */ + public static function serializeArray(array $data, array $type): array + { + return Utils::isMapType($type) + ? self::serializeMap($data, $type) + : self::serializeList($data, $type); + } + + /** + * Serializes a value based on its type definition. + * + * @param mixed $data The value to serialize. + * @param mixed $type The type definition. + * @return mixed The serialized value. + * @throws JsonException If serialization fails. + */ + private static function serializeValue(mixed $data, mixed $type): mixed + { + if ($type instanceof Union) { + return self::serializeUnion($data, $type); + } + + if (is_array($type)) { + return self::serializeArray((array)$data, $type); + } + + if (gettype($type) != "string") { + throw new JsonException("Unexpected non-string type."); + } + + return self::serializeSingleValue($data, $type); + } + + /** + * Serializes a value for a union type definition. + * + * @param mixed $data The value to serialize. + * @param Union $unionType The union type definition. + * @return mixed The serialized value. + * @throws JsonException If serialization fails for all union types. + */ + public static function serializeUnion(mixed $data, Union $unionType): mixed + { + foreach ($unionType->types as $type) { + try { + return self::serializeValue($data, $type); + } catch (Exception) { + // Try the next type in the union + continue; + } + } + $readableType = Utils::getReadableType($data); + throw new JsonException( + "Cannot serialize value of type $readableType with any of the union types: " . $unionType + ); + } + + /** + * Serializes a single value based on its type. + * + * @param mixed $data The value to serialize. + * @param string $type The expected type. + * @return mixed The serialized value. + * @throws JsonException If serialization fails. + */ + private static function serializeSingleValue(mixed $data, string $type): mixed + { + if ($type === 'null' && $data === null) { + return null; + } + + if (($type === 'date' || $type === 'datetime') && $data instanceof DateTime) { + return $type === 'date' ? self::serializeDate($data) : self::serializeDateTime($data); + } + + if ($type === 'mixed') { + return $data; + } + + if (class_exists($type) && $data instanceof $type) { + return self::serializeObject($data); + } + + // Handle floats as a special case since gettype($data) returns "double" for float values in PHP. + if ($type === 'float' && is_float($data)) { + return $data; + } + + if (gettype($data) === $type) { + return $data; + } + + throw new JsonException("Unable to serialize value of type '" . gettype($data) . "' as '$type'."); + } + + /** + * Serializes an object to a JSON-serializable format. + * + * @param object $data The object to serialize. + * @return mixed The serialized data. + * @throws JsonException If the object does not implement JsonSerializable. + */ + public static function serializeObject(object $data): mixed + { + if (!is_subclass_of($data, JsonSerializable::class)) { + $type = get_class($data); + throw new JsonException("Class $type must implement JsonSerializable."); + } + return $data->jsonSerialize(); + } + + /** + * Serializes a map (associative array) with defined key and value types. + * + * @param array $data The associative array to serialize. + * @param array $type The type definition for the map. + * @return array The serialized map. + * @throws JsonException If serialization fails. + */ + private static function serializeMap(array $data, array $type): array + { + $keyType = array_key_first($type); + if ($keyType === null) { + throw new JsonException("Unexpected no key in ArrayType."); + } + $valueType = $type[$keyType]; + $result = []; + + foreach ($data as $key => $item) { + $key = Utils::castKey($key, $keyType); + $result[$key] = self::serializeValue($item, $valueType); + } + + return $result; + } + + /** + * Serializes a list (indexed array) where only the value type is defined. + * + * @param array $data The list to serialize. + * @param array $type The type definition for the list. + * @return array The serialized list. + * @throws JsonException If serialization fails. + */ + private static function serializeList(array $data, array $type): array + { + $valueType = $type[0]; + return array_map(fn ($item) => self::serializeValue($item, $valueType), $data); + } +} diff --git a/src/Core/Json/Utils.php b/src/Core/Json/Utils.php new file mode 100644 index 00000000..515c1942 --- /dev/null +++ b/src/Core/Json/Utils.php @@ -0,0 +1,61 @@ + $type The type definition from the annotation. + * @return bool True if the type is a map, false if it's a list. + */ + public static function isMapType(array $type): bool + { + return count($type) === 1 && !array_is_list($type); + } + + /** + * Casts the key to the appropriate type based on the key type. + * + * @param mixed $key The key to be cast. + * @param string $keyType The type to cast the key to ('string', 'integer', 'float'). + * @return mixed The casted key. + * @throws JsonException + */ + public static function castKey(mixed $key, string $keyType): mixed + { + if (!is_scalar($key)) { + throw new JsonException("Key must be a scalar type."); + } + return match ($keyType) { + 'integer' => (int)$key, + 'float' => (float)$key, + 'string' => (string)$key, + default => $key, + }; + } + + /** + * Returns a human-readable representation of the input's type. + * + * @param mixed $input The input value to determine the type of. + * @return string A readable description of the input type. + */ + public static function getReadableType(mixed $input): string + { + if (is_object($input)) { + return get_class($input); + } elseif (is_array($input)) { + return 'array(' . count($input) . ' items)'; + } elseif (is_null($input)) { + return 'null'; + } else { + return gettype($input); + } + } +} diff --git a/src/Core/Multipart/MultipartApiRequest.php b/src/Core/Multipart/MultipartApiRequest.php new file mode 100644 index 00000000..f6140b74 --- /dev/null +++ b/src/Core/Multipart/MultipartApiRequest.php @@ -0,0 +1,28 @@ + $headers Additional headers for the request (optional) + * @param array $query Query parameters for the request (optional) + * @param ?MultipartFormData $body The multipart form data for the request (optional) + */ + public function __construct( + string $baseUrl, + string $path, + HttpMethod $method, + array $headers = [], + array $query = [], + public readonly ?MultipartFormData $body = null + ) { + parent::__construct($baseUrl, $path, $method, $headers, $query); + } +} diff --git a/src/Core/Multipart/MultipartFormData.php b/src/Core/Multipart/MultipartFormData.php new file mode 100644 index 00000000..12165f9f --- /dev/null +++ b/src/Core/Multipart/MultipartFormData.php @@ -0,0 +1,61 @@ + + */ + private array $parts = []; + + /** + * Adds a new part to the multipart form data. + * + * @param string $name + * @param string|int|bool|float|StreamInterface $value + * @param ?string $contentType + */ + public function add( + string $name, + string|int|bool|float|StreamInterface $value, + ?string $contentType = null, + ): void { + $headers = $contentType != null ? ['Content-Type' => $contentType] : null; + self::addPart( + new MultipartFormDataPart( + name: $name, + value: $value, + headers: $headers, + ) + ); + } + + /** + * Adds a new part to the multipart form data. + * + * @param MultipartFormDataPart $part + */ + public function addPart(MultipartFormDataPart $part): void + { + $this->parts[] = $part; + } + + /** + * Converts the multipart form data into an array suitable + * for Guzzle's multipart form data. + * + * @return array + * }> + */ + public function toArray(): array + { + return array_map(fn ($part) => $part->toArray(), $this->parts); + } +} diff --git a/src/Core/Multipart/MultipartFormDataPart.php b/src/Core/Multipart/MultipartFormDataPart.php new file mode 100644 index 00000000..5e88f267 --- /dev/null +++ b/src/Core/Multipart/MultipartFormDataPart.php @@ -0,0 +1,76 @@ + + */ + private ?array $headers; + + /** + * @param string $name + * @param string|bool|float|int|StreamInterface $value + * @param ?string $filename + * @param ?array $headers + */ + public function __construct( + string $name, + string|bool|float|int|StreamInterface $value, + ?string $filename = null, + ?array $headers = null + ) { + $this->name = $name; + $this->contents = Utils::streamFor($value); + $this->filename = $filename; + $this->headers = $headers; + } + + /** + * Converts the multipart form data part into an array suitable + * for Guzzle's multipart form data. + * + * @return array{ + * name: string, + * contents: StreamInterface, + * filename?: string, + * headers?: array + * } + */ + public function toArray(): array + { + $formData = [ + 'name' => $this->name, + 'contents' => $this->contents, + ]; + + if ($this->filename != null) { + $formData['filename'] = $this->filename; + } + + if ($this->headers != null) { + $formData['headers'] = $this->headers; + } + + return $formData; + } +} diff --git a/src/Core/Pagination/CursorPager.php b/src/Core/Pagination/CursorPager.php new file mode 100644 index 00000000..3b9b340d --- /dev/null +++ b/src/Core/Pagination/CursorPager.php @@ -0,0 +1,73 @@ + + * @internal Use the Pager class + */ +class CursorPager extends Pager +{ + /** @var TRequest */ + private $request; + + /** @var callable(TRequest): TResponse */ + private $getNextPage; + + /** @var callable(TRequest, TCursor): void */ + private $setCursor; + + /** @var callable(TResponse): ?TCursor */ + private $getNextCursor; + + /** @var callable(TResponse): ?array */ + private $getItems; + + /** + * @param TRequest $request + * @param callable(TRequest): TResponse $getNextPage + * @param callable(TRequest, TCursor): void $setCursor + * @param callable(TResponse): ?TCursor $getNextCursor + * @param callable(TResponse): ?array $getItems + */ + public function __construct( + $request, + callable $getNextPage, + callable $setCursor, + callable $getNextCursor, + callable $getItems + ) { + $this->request = clone $request; + $this->getNextPage = $getNextPage; + $this->setCursor = $setCursor; + $this->getNextCursor = $getNextCursor; + $this->getItems = $getItems; + } + + /** + * @return Generator> + */ + public function getPages(): Generator + { + do { + $response = ($this->getNextPage)($this->request); + $items = ($this->getItems)($response); + $nextCursor = ($this->getNextCursor)($response); + if ($items !== null) { + yield new Page($items); + } + + if ($nextCursor === null || $nextCursor === '') { + break; + } + + ($this->setCursor)($this->request, $nextCursor); + } while (true); + } +} diff --git a/src/Core/Pagination/OffsetPager.php b/src/Core/Pagination/OffsetPager.php new file mode 100644 index 00000000..e47d5b29 --- /dev/null +++ b/src/Core/Pagination/OffsetPager.php @@ -0,0 +1,89 @@ + + * @internal Use the Pager class + */ +class OffsetPager extends Pager +{ + /** @var TRequest */ + private $request; + + /** @var callable(TRequest): TResponse */ + private $getNextPage; + + /** @var callable(TRequest): int */ + private $getOffset; + + /** @var callable(TRequest, int): void */ + private $setOffset; + + /** @var ?callable(TRequest): ?int */ + private $getStep; + + /** @var callable(TResponse): ?array */ + private $getItems; + + /** @var ?callable(TResponse): ?bool */ + private $hasNextPage; + + /** + * @param TRequest $request + * @param callable(TRequest): TResponse $getNextPage + * @param callable(TRequest): int $getOffset + * @param callable(TRequest, int): void $setOffset + * @param ?callable(TRequest): ?int $getStep + * @param callable(TResponse): ?array $getItems + * @param ?callable(TResponse): ?bool $hasNextPage + */ + public function __construct( + $request, + callable $getNextPage, + callable $getOffset, + callable $setOffset, + ?callable $getStep, + callable $getItems, + ?callable $hasNextPage + ) { + $this->request = clone $request; + $this->getNextPage = $getNextPage; + $this->getOffset = $getOffset; + $this->setOffset = $setOffset; + $this->getStep = $getStep; + $this->getItems = $getItems; + $this->hasNextPage = $hasNextPage; + } + + /** + * @return Generator> + */ + public function getPages(): Generator + { + $hasStep = $this->getStep !== null && ($this->getStep)($this->request) !== null; + $offset = ($this->getOffset)($this->request); + do { + $response = ($this->getNextPage)($this->request); + $items = ($this->getItems)($response); + $itemCount = $items !== null ? count($items) : 0; + $hasNextPage = $this->hasNextPage !== null ? ($this->hasNextPage)($response) : $itemCount > 0; + if ($items !== null) { + yield new Page($items); + } + + if ($hasStep) { + $offset += $items !== null ? count($items) : 1; + } else { + $offset++; + } + + ($this->setOffset)($this->request, $offset); + } while ($hasNextPage); + } +} diff --git a/src/Core/Pagination/Page.php b/src/Core/Pagination/Page.php new file mode 100644 index 00000000..3f1c7911 --- /dev/null +++ b/src/Core/Pagination/Page.php @@ -0,0 +1,49 @@ + + */ +class Page implements IteratorAggregate +{ + /** + * @var array + */ + private array $items; + + /** + * @param array $items + */ + public function __construct(array $items) + { + $this->items = $items; + } + + /** + * Gets the items in this Page. + * + * @return array + */ + public function getItems(): array + { + return $this->items; + } + + /** + * Get items in this Page as an iterator. + * + * @return Generator + */ + public function getIterator(): Generator + { + return yield from $this->getItems(); + } +} diff --git a/src/Core/Pagination/Pager.php b/src/Core/Pagination/Pager.php new file mode 100644 index 00000000..59331525 --- /dev/null +++ b/src/Core/Pagination/Pager.php @@ -0,0 +1,36 @@ + + */ +abstract class Pager implements IteratorAggregate +{ + /** + * Enumerate the values a Page at a time. This may + * make multiple service requests. + * + * @return Generator> + */ + abstract public function getPages(): Generator; + + /** + * Enumerate the values one at a time. This may make multiple service requests. + * + * @return Generator + */ + public function getIterator(): Generator + { + foreach ($this->getPages() as $page) { + yield from $page->getItems(); + } + } +} diff --git a/src/Core/Pagination/PaginationHelper.php b/src/Core/Pagination/PaginationHelper.php new file mode 100644 index 00000000..6e59a920 --- /dev/null +++ b/src/Core/Pagination/PaginationHelper.php @@ -0,0 +1,167 @@ + $className + * @return T + */ + public static function createRequestWithDefaults(string $className) + { + return self::createInstanceWithDefaults($className); + } + + /** + * Sets a nested property on an object, creating intermediate objects as needed. + * + * @template TObject of object + * @template TValue + * @param TObject $object The object to set the property on. + * @param string[] $propertyPath The path to the property, as an array of strings. + * @param TValue $value The value to set. + * @return void + * @internal + */ + public static function setDeep(mixed $object, array $propertyPath, mixed $value): void + { + try { + /** @var object $current */ + $current = $object; + + foreach ($propertyPath as $i => $part) { + /* @phpstan-ignore-next-line */ + $reflectionClass = new ReflectionClass($current); + + $reflectionProperty = $reflectionClass->getProperty($part); + $reflectionProperty->setAccessible(true); + if ($i === count($propertyPath) - 1) { + /* @phpstan-ignore-next-line */ + $reflectionProperty->setValue($current, $value); + return; + } + + /* @phpstan-ignore-next-line */ + $next = $reflectionProperty->getValue($current); + + if ($next === null) { + $propertyType = $reflectionProperty->getType(); + if ($propertyType === null) { + throw new RuntimeException("Property type is null for property '$part' in class '" . $reflectionClass->getName() . "'"); + } + + /** @var class-string $nextTypeName */ + /* @phpstan-ignore-next-line */ + $nextTypeName = $propertyType->getName(); + /** @var object $next */ + $next = self::createInstanceWithDefaults($nextTypeName); + /* @phpstan-ignore-next-line */ + $reflectionProperty->setValue($current, $next); + } + + $current = $next; + } + } catch (ReflectionException $ex) { + $path = implode('->', $propertyPath); + throw new RuntimeException("Failed to set deep property at $path", 0, $ex); + } + } + + /** + * @template T of object + * @param class-string $className + * @return T + */ + private static function createInstanceWithDefaults(string $className) + { + try { + $reflectionClass = new ReflectionClass($className); + $args = []; + $values = []; + + $properties = $reflectionClass->getProperties(); + foreach ($properties as $property) { + if ($property->isStatic()) { + continue; + } + /** @var ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null $type */ + $type = $property->getType(); + $value = self::getDefaultValueForType($type); + // if something is nullable, don't explicitly pass the null value as a parameter + if ($value === null) { + continue; + } + + $values[$property->getName()] = $value; + } + $args = [$values]; + + /** @var T|null $instance */ + $instance = $reflectionClass->newInstanceArgs($args); + if ($instance === null) { + return new $className(); + } + return $instance; + } catch (ReflectionException $ex) { + throw new RuntimeException("Failed create instance of $className", 0, $ex); + } + } + + private static function getDefaultValueForType( + null|ReflectionIntersectionType|ReflectionNamedType|ReflectionUnionType $type + ): mixed { + if ($type === null) { + return null; + } + + if ($type instanceof ReflectionUnionType) { + foreach ($type->getTypes() as $t) { + if ($t instanceof ReflectionNamedType) { + return self::getDefaultValueForType($t); + } + } + } + + if ($type instanceof ReflectionIntersectionType) { + foreach ($type->getTypes() as $t) { + if ($t instanceof ReflectionNamedType) { + return self::getDefaultValueForType($t); + } + } + } + + if ($type->allowsNull()) { + return null; + } + + if ($type instanceof ReflectionNamedType) { + if ($type->isBuiltin()) { + return match ($type->getName()) { + 'int' => 0, + 'string' => '', + 'bool' => false, + 'array' => [], + default => null, + }; + } + + /** @var class-string $typeName */ + $typeName = $type->getName(); + return self::createInstanceWithDefaults($typeName); + } + + return null; + } +} diff --git a/src/Core/Types/ArrayType.php b/src/Core/Types/ArrayType.php new file mode 100644 index 00000000..30a54705 --- /dev/null +++ b/src/Core/Types/ArrayType.php @@ -0,0 +1,16 @@ + 'valueType'] for maps, or ['valueType'] for lists + */ + public function __construct(public array $type) + { + } +} diff --git a/src/Core/Types/Constant.php b/src/Core/Types/Constant.php new file mode 100644 index 00000000..78e03ac6 --- /dev/null +++ b/src/Core/Types/Constant.php @@ -0,0 +1,12 @@ +> The types allowed for this property, which can be strings, arrays, or nested Union types. + */ + public array $types; + + /** + * Constructor for the Union attribute. + * + * @param string|Union|array ...$types The list of types that the property can accept. + * This can include primitive types (e.g., 'string', 'int'), arrays, or other Union instances. + * + * Example: + * ```php + * #[Union('string', 'null', 'date', new Union('boolean', 'int'))] + * ``` + */ + public function __construct(string|Union|array ...$types) + { + $this->types = $types; + } + + /** + * Converts the Union type to a string representation. + * + * @return string A string representation of the union types. + */ + public function __toString(): string + { + return implode(' | ', array_map(function ($type) { + if (is_string($type)) { + return $type; + } elseif ($type instanceof Union) { + return (string) $type; // Recursively handle nested unions + } elseif (is_array($type)) { + return 'array'; // Handle arrays + } + }, $this->types)); + } +} diff --git a/src/DataAttributes/DataAttributesClient.php b/src/DataAttributes/DataAttributesClient.php new file mode 100644 index 00000000..067b71ac --- /dev/null +++ b/src/DataAttributes/DataAttributesClient.php @@ -0,0 +1,236 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all data attributes belonging to a workspace for contacts, companies or conversations. + * + * @param ListDataAttributesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataAttributeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(ListDataAttributesRequest $request = new ListDataAttributesRequest(), ?array $options = null): DataAttributeList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getModel() != null) { + $query['model'] = $request->getModel(); + } + if ($request->getIncludeArchived() != null) { + $query['include_archived'] = $request->getIncludeArchived(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "data_attributes", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataAttributeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a data attributes for a `contact` or a `company`. + * + * @param CreateDataAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateDataAttributeRequest $request, ?array $options = null): DataAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "data_attributes", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can update a data attribute. + * + * > 🚧 Updating the data type is not possible + * > + * > It is currently a dangerous action to execute changing a data attribute's type via the API. You will need to update the type via the UI instead. + * + * @param UpdateDataAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateDataAttributeRequest $request, ?array $options = null): DataAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "data_attributes/{$request->getDataAttributeId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/DataAttributes/Requests/CreateDataAttributeRequest.php b/src/DataAttributes/Requests/CreateDataAttributeRequest.php new file mode 100644 index 00000000..cc9a533e --- /dev/null +++ b/src/DataAttributes/Requests/CreateDataAttributeRequest.php @@ -0,0 +1,171 @@ + $model The model that the data attribute belongs to. + */ + #[JsonProperty('model')] + private string $model; + + /** + * @var value-of $dataType The type of data stored for this attribute. + */ + #[JsonProperty('data_type')] + private string $dataType; + + /** + * @var ?string $description The readable description you see in the UI for the attribute. + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var ?array $options To create list attributes. Provide a set of hashes with `value` as the key of the options you want to make. `data_type` must be `string`. + */ + #[JsonProperty('options'), ArrayType(['string'])] + private ?array $options; + + /** + * @var ?bool $messengerWritable Can this attribute be updated by the Messenger + */ + #[JsonProperty('messenger_writable')] + private ?bool $messengerWritable; + + /** + * @param array{ + * name: string, + * model: value-of, + * dataType: value-of, + * description?: ?string, + * options?: ?array, + * messengerWritable?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->model = $values['model']; + $this->dataType = $values['dataType']; + $this->description = $values['description'] ?? null; + $this->options = $values['options'] ?? null; + $this->messengerWritable = $values['messengerWritable'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return value-of + */ + public function getModel(): string + { + return $this->model; + } + + /** + * @param value-of $value + */ + public function setModel(string $value): self + { + $this->model = $value; + return $this; + } + + /** + * @return value-of + */ + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param value-of $value + */ + public function setDataType(string $value): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?array + */ + public function getOptions(): ?array + { + return $this->options; + } + + /** + * @param ?array $value + */ + public function setOptions(?array $value = null): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMessengerWritable(): ?bool + { + return $this->messengerWritable; + } + + /** + * @param ?bool $value + */ + public function setMessengerWritable(?bool $value = null): self + { + $this->messengerWritable = $value; + return $this; + } +} diff --git a/src/DataAttributes/Requests/ListDataAttributesRequest.php b/src/DataAttributes/Requests/ListDataAttributesRequest.php new file mode 100644 index 00000000..5562a636 --- /dev/null +++ b/src/DataAttributes/Requests/ListDataAttributesRequest.php @@ -0,0 +1,66 @@ + $model Specify the data attribute model to return. + */ + private ?string $model; + + /** + * @var ?bool $includeArchived Include archived attributes in the list. By default we return only non archived data attributes. + */ + private ?bool $includeArchived; + + /** + * @param array{ + * model?: ?value-of, + * includeArchived?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->model = $values['model'] ?? null; + $this->includeArchived = $values['includeArchived'] ?? null; + } + + /** + * @return ?value-of + */ + public function getModel(): ?string + { + return $this->model; + } + + /** + * @param ?value-of $value + */ + public function setModel(?string $value = null): self + { + $this->model = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIncludeArchived(): ?bool + { + return $this->includeArchived; + } + + /** + * @param ?bool $value + */ + public function setIncludeArchived(?bool $value = null): self + { + $this->includeArchived = $value; + return $this; + } +} diff --git a/src/DataAttributes/Requests/UpdateDataAttributeRequest.php b/src/DataAttributes/Requests/UpdateDataAttributeRequest.php new file mode 100644 index 00000000..89d79867 --- /dev/null +++ b/src/DataAttributes/Requests/UpdateDataAttributeRequest.php @@ -0,0 +1,144 @@ + $options To create list attributes. Provide a set of hashes with `value` as the key of the options you want to make. `data_type` must be `string`. + */ + #[JsonProperty('options'), ArrayType([UpdateDataAttributeRequestOptionsItem::class])] + private ?array $options; + + /** + * @var ?bool $messengerWritable Can this attribute be updated by the Messenger + */ + #[JsonProperty('messenger_writable')] + private ?bool $messengerWritable; + + /** + * @param array{ + * dataAttributeId: string, + * archived?: ?bool, + * description?: ?string, + * options?: ?array, + * messengerWritable?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->dataAttributeId = $values['dataAttributeId']; + $this->archived = $values['archived'] ?? null; + $this->description = $values['description'] ?? null; + $this->options = $values['options'] ?? null; + $this->messengerWritable = $values['messengerWritable'] ?? null; + } + + /** + * @return string + */ + public function getDataAttributeId(): string + { + return $this->dataAttributeId; + } + + /** + * @param string $value + */ + public function setDataAttributeId(string $value): self + { + $this->dataAttributeId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?array + */ + public function getOptions(): ?array + { + return $this->options; + } + + /** + * @param ?array $value + */ + public function setOptions(?array $value = null): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMessengerWritable(): ?bool + { + return $this->messengerWritable; + } + + /** + * @param ?bool $value + */ + public function setMessengerWritable(?bool $value = null): self + { + $this->messengerWritable = $value; + return $this; + } +} diff --git a/src/DataAttributes/Types/CreateDataAttributeRequestDataType.php b/src/DataAttributes/Types/CreateDataAttributeRequestDataType.php new file mode 100644 index 00000000..ed7177cb --- /dev/null +++ b/src/DataAttributes/Types/CreateDataAttributeRequestDataType.php @@ -0,0 +1,13 @@ + $model Value is `contact` for user/lead attributes and `company` for company attributes. + */ + #[JsonProperty('model')] + private ?string $model; + + /** + * @var string $name Name of the attribute. + */ + #[JsonProperty('name')] + private string $name; + + /** + * @var string $fullName Full name of the attribute. Should match the name unless it's a nested attribute. We can split full_name on `.` to access nested user object values. + */ + #[JsonProperty('full_name')] + private string $fullName; + + /** + * @var string $label Readable name of the attribute (i.e. name you see in the UI) + */ + #[JsonProperty('label')] + private string $label; + + /** + * @var ?string $description Readable description of the attribute. + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var value-of $dataType The data type of the attribute. + */ + #[JsonProperty('data_type')] + private string $dataType; + + /** + * @var ?array $options List of predefined options for attribute value. + */ + #[JsonProperty('options'), ArrayType(['string'])] + private ?array $options; + + /** + * @var ?bool $apiWritable Can this attribute be updated through API + */ + #[JsonProperty('api_writable')] + private ?bool $apiWritable; + + /** + * @var ?bool $messengerWritable Can this attribute be updated by the Messenger + */ + #[JsonProperty('messenger_writable')] + private ?bool $messengerWritable; + + /** + * @var ?bool $uiWritable Can this attribute be updated in the UI + */ + #[JsonProperty('ui_writable')] + private ?bool $uiWritable; + + /** + * @var ?bool $custom Set to true if this is a CDA + */ + #[JsonProperty('custom')] + private ?bool $custom; + + /** + * @var ?bool $archived Is this attribute archived. (Only applicable to CDAs) + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?int $createdAt The time the attribute was created as a UTC Unix timestamp + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The time the attribute was last updated as a UTC Unix timestamp + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?string $adminId Teammate who created the attribute. Only applicable to CDAs + */ + #[JsonProperty('admin_id')] + private ?string $adminId; + + /** + * @param array{ + * type: 'data_attribute', + * name: string, + * fullName: string, + * label: string, + * dataType: value-of, + * id?: ?int, + * model?: ?value-of, + * description?: ?string, + * options?: ?array, + * apiWritable?: ?bool, + * messengerWritable?: ?bool, + * uiWritable?: ?bool, + * custom?: ?bool, + * archived?: ?bool, + * createdAt?: ?int, + * updatedAt?: ?int, + * adminId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id'] ?? null; + $this->model = $values['model'] ?? null; + $this->name = $values['name']; + $this->fullName = $values['fullName']; + $this->label = $values['label']; + $this->description = $values['description'] ?? null; + $this->dataType = $values['dataType']; + $this->options = $values['options'] ?? null; + $this->apiWritable = $values['apiWritable'] ?? null; + $this->messengerWritable = $values['messengerWritable'] ?? null; + $this->uiWritable = $values['uiWritable'] ?? null; + $this->custom = $values['custom'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->adminId = $values['adminId'] ?? null; + } + + /** + * @return 'data_attribute' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'data_attribute' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getId(): ?int + { + return $this->id; + } + + /** + * @param ?int $value + */ + public function setId(?int $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getModel(): ?string + { + return $this->model; + } + + /** + * @param ?value-of $value + */ + public function setModel(?string $value = null): self + { + $this->model = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getFullName(): string + { + return $this->fullName; + } + + /** + * @param string $value + */ + public function setFullName(string $value): self + { + $this->fullName = $value; + return $this; + } + + /** + * @return string + */ + public function getLabel(): string + { + return $this->label; + } + + /** + * @param string $value + */ + public function setLabel(string $value): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return value-of + */ + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param value-of $value + */ + public function setDataType(string $value): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?array + */ + public function getOptions(): ?array + { + return $this->options; + } + + /** + * @param ?array $value + */ + public function setOptions(?array $value = null): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getApiWritable(): ?bool + { + return $this->apiWritable; + } + + /** + * @param ?bool $value + */ + public function setApiWritable(?bool $value = null): self + { + $this->apiWritable = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMessengerWritable(): ?bool + { + return $this->messengerWritable; + } + + /** + * @param ?bool $value + */ + public function setMessengerWritable(?bool $value = null): self + { + $this->messengerWritable = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUiWritable(): ?bool + { + return $this->uiWritable; + } + + /** + * @param ?bool $value + */ + public function setUiWritable(?bool $value = null): self + { + $this->uiWritable = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getCustom(): ?bool + { + return $this->custom; + } + + /** + * @param ?bool $value + */ + public function setCustom(?bool $value = null): self + { + $this->custom = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/DataAttributes/Types/DataAttributeDataType.php b/src/DataAttributes/Types/DataAttributeDataType.php new file mode 100644 index 00000000..af97abed --- /dev/null +++ b/src/DataAttributes/Types/DataAttributeDataType.php @@ -0,0 +1,12 @@ +value = $values['value']; + } + + /** + * @return string + */ + public function getValue(): string + { + return $this->value; + } + + /** + * @param string $value + */ + public function setValue(string $value): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/DataEvents/Types/DataEvent.php b/src/DataEvents/Types/DataEvent.php new file mode 100644 index 00000000..394b2db3 --- /dev/null +++ b/src/DataEvents/Types/DataEvent.php @@ -0,0 +1,230 @@ + $metadata Optional metadata about the event. + */ + #[JsonProperty('metadata'), ArrayType(['string' => 'string'])] + private ?array $metadata; + + /** + * @param array{ + * eventName: string, + * createdAt: int, + * type?: ?'event', + * userId?: ?string, + * id?: ?string, + * intercomUserId?: ?string, + * email?: ?string, + * metadata?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->eventName = $values['eventName']; + $this->createdAt = $values['createdAt']; + $this->userId = $values['userId'] ?? null; + $this->id = $values['id'] ?? null; + $this->intercomUserId = $values['intercomUserId'] ?? null; + $this->email = $values['email'] ?? null; + $this->metadata = $values['metadata'] ?? null; + } + + /** + * @return ?'event' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'event' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getEventName(): string + { + return $this->eventName; + } + + /** + * @param string $value + */ + public function setEventName(string $value): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIntercomUserId(): ?string + { + return $this->intercomUserId; + } + + /** + * @param ?string $value + */ + public function setIntercomUserId(?string $value = null): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?array + */ + public function getMetadata(): ?array + { + return $this->metadata; + } + + /** + * @param ?array $value + */ + public function setMetadata(?array $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/DataExport/DataExportClient.php b/src/DataExport/DataExportClient.php new file mode 100644 index 00000000..8756d264 --- /dev/null +++ b/src/DataExport/DataExportClient.php @@ -0,0 +1,297 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * To create your export job, you need to send a `POST` request to the export endpoint `https://api.intercom.io/export/content/data`. + * + * The only parameters you need to provide are the range of dates that you want exported. + * + * >🚧 Limit of one active job + * > + * > You can only have one active job per workspace. You will receive a HTTP status code of 429 with the message Exceeded rate limit of 1 pending message data export jobs if you attempt to create a second concurrent job. + * + * >❗️ Updated_at not included + * > + * > It should be noted that the timeframe only includes messages sent during the time period and not messages that were only updated during this period. For example, if a message was updated yesterday but sent two days ago, you would need to set the created_at_after date before the message was sent to include that in your retrieval job. + * + * >📘 Date ranges are inclusive + * > + * > Requesting data for 2018-06-01 until 2018-06-30 will get all data for those days including those specified - e.g. 2018-06-01 00:00:00 until 2018-06-30 23:59:99. + * + * @param CreateDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataExport + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateDataExportRequest $request, ?array $options = null): DataExport + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/content/data", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataExport::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can view the status of your job by sending a `GET` request to the URL + * `https://api.intercom.io/export/content/data/{job_identifier}` - the `{job_identifier}` is the value returned in the response when you first created the export job. More on it can be seen in the Export Job Model. + * + * > 🚧 Jobs expire after two days + * > All jobs that have completed processing (and are thus available to download from the provided URL) will have an expiry limit of two days from when the export ob completed. After this, the data will no longer be available. + * + * @param FindDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataExport + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindDataExportRequest $request, ?array $options = null): DataExport + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/content/data/{$request->getJobIdentifier()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataExport::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can cancel your job + * + * @param CancelDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataExport + * @throws IntercomException + * @throws IntercomApiException + */ + public function cancel(CancelDataExportRequest $request, ?array $options = null): DataExport + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/cancel/{$request->getJobIdentifier()}", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataExport::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * When a job has a status of complete, and thus a filled download_url, you can download your data by hitting that provided URL, formatted like so: https://api.intercom.io/download/content/data/xyz1234. + * + * Your exported message data will be streamed continuously back down to you in a gzipped CSV format. + * + * > 📘 Octet header required + * > + * > You will have to specify the header Accept: `application/octet-stream` when hitting this endpoint. + * + * @param DownloadDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function download(DownloadDataExportRequest $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "download/content/data/{$request->getJobIdentifier()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/DataExport/Requests/CancelDataExportRequest.php b/src/DataExport/Requests/CancelDataExportRequest.php new file mode 100644 index 00000000..f030c5ae --- /dev/null +++ b/src/DataExport/Requests/CancelDataExportRequest.php @@ -0,0 +1,41 @@ +jobIdentifier = $values['jobIdentifier']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } +} diff --git a/src/DataExport/Requests/CreateDataExportRequest.php b/src/DataExport/Requests/CreateDataExportRequest.php new file mode 100644 index 00000000..f8ac8eff --- /dev/null +++ b/src/DataExport/Requests/CreateDataExportRequest.php @@ -0,0 +1,68 @@ +createdAtAfter = $values['createdAtAfter']; + $this->createdAtBefore = $values['createdAtBefore']; + } + + /** + * @return int + */ + public function getCreatedAtAfter(): int + { + return $this->createdAtAfter; + } + + /** + * @param int $value + */ + public function setCreatedAtAfter(int $value): self + { + $this->createdAtAfter = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAtBefore(): int + { + return $this->createdAtBefore; + } + + /** + * @param int $value + */ + public function setCreatedAtBefore(int $value): self + { + $this->createdAtBefore = $value; + return $this; + } +} diff --git a/src/DataExport/Requests/DownloadDataExportRequest.php b/src/DataExport/Requests/DownloadDataExportRequest.php new file mode 100644 index 00000000..d2718ff3 --- /dev/null +++ b/src/DataExport/Requests/DownloadDataExportRequest.php @@ -0,0 +1,41 @@ +jobIdentifier = $values['jobIdentifier']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } +} diff --git a/src/DataExport/Requests/FindDataExportRequest.php b/src/DataExport/Requests/FindDataExportRequest.php new file mode 100644 index 00000000..ad016697 --- /dev/null +++ b/src/DataExport/Requests/FindDataExportRequest.php @@ -0,0 +1,41 @@ +jobIdentifier = $values['jobIdentifier']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } +} diff --git a/src/DataExport/Types/DataExport.php b/src/DataExport/Types/DataExport.php new file mode 100644 index 00000000..9b675025 --- /dev/null +++ b/src/DataExport/Types/DataExport.php @@ -0,0 +1,129 @@ + $status The current state of your job. + */ + #[JsonProperty('status')] + private string $status; + + /** + * @var string $downloadExpiresAt The time after which you will not be able to access the data. + */ + #[JsonProperty('download_expires_at')] + private string $downloadExpiresAt; + + /** + * @var string $downloadUrl The location where you can download your data. + */ + #[JsonProperty('download_url')] + private string $downloadUrl; + + /** + * @param array{ + * jobIdentifier: string, + * status: value-of, + * downloadExpiresAt: string, + * downloadUrl: string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->jobIdentifier = $values['jobIdentifier']; + $this->status = $values['status']; + $this->downloadExpiresAt = $values['downloadExpiresAt']; + $this->downloadUrl = $values['downloadUrl']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } + + /** + * @return value-of + */ + public function getStatus(): string + { + return $this->status; + } + + /** + * @param value-of $value + */ + public function setStatus(string $value): self + { + $this->status = $value; + return $this; + } + + /** + * @return string + */ + public function getDownloadExpiresAt(): string + { + return $this->downloadExpiresAt; + } + + /** + * @param string $value + */ + public function setDownloadExpiresAt(string $value): self + { + $this->downloadExpiresAt = $value; + return $this; + } + + /** + * @return string + */ + public function getDownloadUrl(): string + { + return $this->downloadUrl; + } + + /** + * @param string $value + */ + public function setDownloadUrl(string $value): self + { + $this->downloadUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/DataExport/Types/DataExportStatus.php b/src/DataExport/Types/DataExportStatus.php new file mode 100644 index 00000000..8c3d6be0 --- /dev/null +++ b/src/DataExport/Types/DataExportStatus.php @@ -0,0 +1,13 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * + * > 🚧 + * > + * > Please note that you can only 'list' events that are less than 90 days old. Event counts and summaries will still include your events older than 90 days but you cannot 'list' these events individually if they are older than 90 days + * + * The events belonging to a customer can be listed by sending a GET request to `https://api.intercom.io/events` with a user or lead identifier along with a `type` parameter. The identifier parameter can be one of `user_id`, `email` or `intercom_user_id`. The `type` parameter value must be `user`. + * + * - `https://api.intercom.io/events?type=user&user_id={user_id}` + * - `https://api.intercom.io/events?type=user&email={email}` + * - `https://api.intercom.io/events?type=user&intercom_user_id={id}` (this call can be used to list leads) + * + * The `email` parameter value should be [url encoded](http://en.wikipedia.org/wiki/Percent-encoding) when sending. + * + * You can optionally define the result page size as well with the `per_page` parameter. + * + * @param ListEventsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataEventSummary + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(ListEventsRequest $request, ?array $options = null): DataEventSummary + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['type'] = $request->getType(); + if ($request->getUserId() != null) { + $query['user_id'] = $request->getUserId(); + } + if ($request->getIntercomUserId() != null) { + $query['intercom_user_id'] = $request->getIntercomUserId(); + } + if ($request->getEmail() != null) { + $query['email'] = $request->getEmail(); + } + if ($request->getSummary() != null) { + $query['summary'] = $request->getSummary(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "events", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataEventSummary::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You will need an Access Token that has write permissions to send Events. Once you have a key you can submit events via POST to the Events resource, which is located at https://api.intercom.io/events, or you can send events using one of the client libraries. When working with the HTTP API directly a client should send the event with a `Content-Type` of `application/json`. + * + * When using the JavaScript API, [adding the code to your app](http://docs.intercom.io/configuring-Intercom/tracking-user-events-in-your-app) makes the Events API available. Once added, you can submit an event using the `trackEvent` method. This will associate the event with the Lead or currently logged-in user or logged-out visitor/lead and send it to Intercom. The final parameter is a map that can be used to send optional metadata about the event. + * + * With the Ruby client you pass a hash describing the event to `Intercom::Event.create`, or call the `track_user` method directly on the current user object (e.g. `user.track_event`). + * + * **NB: For the JSON object types, please note that we do not currently support nested JSON structure.** + * + * | Type | Description | Example | + * | :-------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- | + * | String | The value is a JSON String | `"source":"desktop"` | + * | Number | The value is a JSON Number | `"load": 3.67` | + * | Date | The key ends with the String `_date` and the value is a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time), assumed to be in the [UTC](http://en.wikipedia.org/wiki/Coordinated_Universal_Time) timezone. | `"contact_date": 1392036272` | + * | Link | The value is a HTTP or HTTPS URI. | `"article": "https://example.org/ab1de.html"` | + * | Rich Link | The value is a JSON object that contains `url` and `value` keys. | `"article": {"url": "https://example.org/ab1de.html", "value":"the dude abides"}` | + * | Monetary Amount | The value is a JSON object that contains `amount` and `currency` keys. The `amount` key is a positive integer representing the amount in cents. The price in the example to the right denotes €349.99. | `"price": {"amount": 34999, "currency": "eur"}` | + * + * **Lead Events** + * + * When submitting events for Leads, you will need to specify the Lead's `id`. + * + * **Metadata behaviour** + * + * - We currently limit the number of tracked metadata keys to 10 per event. Once the quota is reached, we ignore any further keys we receive. The first 10 metadata keys are determined by the order in which they are sent in with the event. + * - It is not possible to change the metadata keys once the event has been sent. A new event will need to be created with the new keys and you can archive the old one. + * - There might be up to 24 hrs delay when you send a new metadata for an existing event. + * + * **Event de-duplication** + * + * The API may detect and ignore duplicate events. Each event is uniquely identified as a combination of the following data - the Workspace identifier, the Contact external identifier, the Data Event name and the Data Event created time. As a result, it is **strongly recommended** to send a second granularity Unix timestamp in the `created_at` field. + * + * Duplicated events are responded to using the normal `202 Accepted` code - an error is not thrown, however repeat requests will be counted against any rate limit that is in place. + * + * ### HTTP API Responses + * + * - Successful responses to submitted events return `202 Accepted` with an empty body. + * - Unauthorised access will be rejected with a `401 Unauthorized` or `403 Forbidden` response code. + * - Events sent about users that cannot be found will return a `404 Not Found`. + * - Event lists containing duplicate events will have those duplicates ignored. + * - Server errors will return a `500` response code and may contain an error message in the body. + * + * @param ( + * CreateDataEventRequestWithId + * |CreateDataEventRequestWithUserId + * |CreateDataEventRequestWithEmail + * ) $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateDataEventRequestWithId|CreateDataEventRequestWithUserId|CreateDataEventRequestWithEmail $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "events", + method: HttpMethod::POST, + body: JsonSerializer::serializeUnion($request, new Union(CreateDataEventRequestWithId::class, CreateDataEventRequestWithUserId::class, CreateDataEventRequestWithEmail::class)), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Create event summaries for a user. Event summaries are used to track the number of times an event has occurred, the first time it occurred and the last time it occurred. + * + * @param ListEventSummariesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function summaries(ListEventSummariesRequest $request = new ListEventSummariesRequest(), ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "events/summaries", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Events/Requests/ListEventSummariesRequest.php b/src/Events/Requests/ListEventSummariesRequest.php new file mode 100644 index 00000000..5c3999fb --- /dev/null +++ b/src/Events/Requests/ListEventSummariesRequest.php @@ -0,0 +1,69 @@ +userId = $values['userId'] ?? null; + $this->eventSummaries = $values['eventSummaries'] ?? null; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?CreateDataEventSummariesRequestEventSummaries + */ + public function getEventSummaries(): ?CreateDataEventSummariesRequestEventSummaries + { + return $this->eventSummaries; + } + + /** + * @param ?CreateDataEventSummariesRequestEventSummaries $value + */ + public function setEventSummaries(?CreateDataEventSummariesRequestEventSummaries $value = null): self + { + $this->eventSummaries = $value; + return $this; + } +} diff --git a/src/Events/Requests/ListEventsRequest.php b/src/Events/Requests/ListEventsRequest.php new file mode 100644 index 00000000..514efdd1 --- /dev/null +++ b/src/Events/Requests/ListEventsRequest.php @@ -0,0 +1,161 @@ +userId = $values['userId'] ?? null; + $this->intercomUserId = $values['intercomUserId'] ?? null; + $this->email = $values['email'] ?? null; + $this->type = $values['type']; + $this->summary = $values['summary'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIntercomUserId(): ?string + { + return $this->intercomUserId; + } + + /** + * @param ?string $value + */ + public function setIntercomUserId(?string $value = null): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getSummary(): ?bool + { + return $this->summary; + } + + /** + * @param ?bool $value + */ + public function setSummary(?bool $value = null): self + { + $this->summary = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Events/Types/CreateDataEventSummariesRequestEventSummaries.php b/src/Events/Types/CreateDataEventSummariesRequestEventSummaries.php new file mode 100644 index 00000000..dc4cdb05 --- /dev/null +++ b/src/Events/Types/CreateDataEventSummariesRequestEventSummaries.php @@ -0,0 +1,129 @@ +eventName = $values['eventName'] ?? null; + $this->count = $values['count'] ?? null; + $this->first = $values['first'] ?? null; + $this->last = $values['last'] ?? null; + } + + /** + * @return ?string + */ + public function getEventName(): ?string + { + return $this->eventName; + } + + /** + * @param ?string $value + */ + public function setEventName(?string $value = null): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCount(): ?int + { + return $this->count; + } + + /** + * @param ?int $value + */ + public function setCount(?int $value = null): self + { + $this->count = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirst(): ?int + { + return $this->first; + } + + /** + * @param ?int $value + */ + public function setFirst(?int $value = null): self + { + $this->first = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLast(): ?int + { + return $this->last; + } + + /** + * @param ?int $value + */ + public function setLast(?int $value = null): self + { + $this->last = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Exceptions/IntercomApiException.php b/src/Exceptions/IntercomApiException.php new file mode 100644 index 00000000..703bece9 --- /dev/null +++ b/src/Exceptions/IntercomApiException.php @@ -0,0 +1,53 @@ +body = $body; + parent::__construct($message, $statusCode, $previous); + } + + /** + * Returns the body of the response that triggered the exception. + * + * @return mixed + */ + public function getBody(): mixed + { + return $this->body; + } + + /** + * @return string + */ + public function __toString(): string + { + if (empty($this->body)) { + return "$this->message; Status Code: $this->code\n"; + } + return "$this->message; Status Code: $this->code; Body: " . $this->body . "\n"; + } +} diff --git a/src/Exceptions/IntercomException.php b/src/Exceptions/IntercomException.php new file mode 100644 index 00000000..0197232d --- /dev/null +++ b/src/Exceptions/IntercomException.php @@ -0,0 +1,12 @@ +id = $values['id']; + $this->workspaceId = $values['workspaceId']; + $this->name = $values['name']; + $this->description = $values['description'] ?? null; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->url = $values['url'] ?? null; + $this->icon = $values['icon'] ?? null; + $this->order = $values['order']; + $this->defaultLocale = $values['defaultLocale'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->helpCenterId = $values['helpCenterId'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param ?string $value + */ + public function setIcon(?string $value = null): self + { + $this->icon = $value; + return $this; + } + + /** + * @return int + */ + public function getOrder(): int + { + return $this->order; + } + + /** + * @param int $value + */ + public function setOrder(int $value): self + { + $this->order = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultLocale(): ?string + { + return $this->defaultLocale; + } + + /** + * @param ?string $value + */ + public function setDefaultLocale(?string $value = null): self + { + $this->defaultLocale = $value; + return $this; + } + + /** + * @return ?GroupTranslatedContent + */ + public function getTranslatedContent(): ?GroupTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?GroupTranslatedContent $value + */ + public function setTranslatedContent(?GroupTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHelpCenterId(): ?int + { + return $this->helpCenterId; + } + + /** + * @param ?int $value + */ + public function setHelpCenterId(?int $value = null): self + { + $this->helpCenterId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/HelpCenter/Types/HelpCenter.php b/src/HelpCenter/Types/HelpCenter.php new file mode 100644 index 00000000..2cf0b607 --- /dev/null +++ b/src/HelpCenter/Types/HelpCenter.php @@ -0,0 +1,204 @@ +id = $values['id']; + $this->workspaceId = $values['workspaceId']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->identifier = $values['identifier']; + $this->websiteTurnedOn = $values['websiteTurnedOn']; + $this->displayName = $values['displayName']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function getIdentifier(): string + { + return $this->identifier; + } + + /** + * @param string $value + */ + public function setIdentifier(string $value): self + { + $this->identifier = $value; + return $this; + } + + /** + * @return bool + */ + public function getWebsiteTurnedOn(): bool + { + return $this->websiteTurnedOn; + } + + /** + * @param bool $value + */ + public function setWebsiteTurnedOn(bool $value): self + { + $this->websiteTurnedOn = $value; + return $this; + } + + /** + * @return string + */ + public function getDisplayName(): string + { + return $this->displayName; + } + + /** + * @param string $value + */ + public function setDisplayName(string $value): self + { + $this->displayName = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/HelpCenter/Types/HelpCenterList.php b/src/HelpCenter/Types/HelpCenterList.php new file mode 100644 index 00000000..6165aa10 --- /dev/null +++ b/src/HelpCenter/Types/HelpCenterList.php @@ -0,0 +1,80 @@ + $data An array of Help Center objects + */ + #[JsonProperty('data'), ArrayType([HelpCenter::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/HelpCenters/Collections/CollectionsClient.php b/src/HelpCenters/Collections/CollectionsClient.php new file mode 100644 index 00000000..0a1f0f89 --- /dev/null +++ b/src/HelpCenters/Collections/CollectionsClient.php @@ -0,0 +1,382 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all collections by making a GET request to `https://api.intercom.io/help_center/collections`. + * + * Collections will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated collections first. + * + * @param ListCollectionsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListCollectionsRequest $request = new ListCollectionsRequest(), ?array $options = null): Pager + { + return new OffsetPager( + request: $request, + getNextPage: fn (ListCollectionsRequest $request) => $this->_list($request, $options), + /* @phpstan-ignore-next-line */ + getOffset: fn (ListCollectionsRequest $request) => $request?->getPage() ?? 0, + setOffset: function (ListCollectionsRequest $request, int $offset) { + $request->setPage($offset); + }, + getStep: null, + /* @phpstan-ignore-next-line */ + getItems: fn (CollectionList $response) => $response?->getData() ?? [], + /* @phpstan-ignore-next-line */ + hasNextPage: null, + ); + } + + /** + * You can create a new collection by making a POST request to `https://api.intercom.io/help_center/collections.` + * + * @param CreateCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Collection + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateCollectionRequest $request, ?array $options = null): Collection + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Collection::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single collection by making a GET request to `https://api.intercom.io/help_center/collections/`. + * + * @param FindCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Collection + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindCollectionRequest $request, ?array $options = null): Collection + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections/{$request->getCollectionId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Collection::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update the details of a single collection by making a PUT request to `https://api.intercom.io/collections/`. + * + * @param UpdateCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Collection + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateCollectionRequest $request, ?array $options = null): Collection + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections/{$request->getCollectionId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Collection::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single collection by making a DELETE request to `https://api.intercom.io/collections/`. + * + * @param DeleteCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedCollectionObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function delete(DeleteCollectionRequest $request, ?array $options = null): DeletedCollectionObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections/{$request->getCollectionId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedCollectionObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all collections by making a GET request to `https://api.intercom.io/help_center/collections`. + * + * Collections will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated collections first. + * + * @param ListCollectionsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CollectionList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListCollectionsRequest $request = new ListCollectionsRequest(), ?array $options = null): CollectionList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CollectionList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/HelpCenters/Collections/Requests/CreateCollectionRequest.php b/src/HelpCenters/Collections/Requests/CreateCollectionRequest.php new file mode 100644 index 00000000..2421a01e --- /dev/null +++ b/src/HelpCenters/Collections/Requests/CreateCollectionRequest.php @@ -0,0 +1,144 @@ +name = $values['name']; + $this->description = $values['description'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->helpCenterId = $values['helpCenterId'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?GroupTranslatedContent + */ + public function getTranslatedContent(): ?GroupTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?GroupTranslatedContent $value + */ + public function setTranslatedContent(?GroupTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHelpCenterId(): ?int + { + return $this->helpCenterId; + } + + /** + * @param ?int $value + */ + public function setHelpCenterId(?int $value = null): self + { + $this->helpCenterId = $value; + return $this; + } +} diff --git a/src/HelpCenters/Collections/Requests/DeleteCollectionRequest.php b/src/HelpCenters/Collections/Requests/DeleteCollectionRequest.php new file mode 100644 index 00000000..0e91e4bf --- /dev/null +++ b/src/HelpCenters/Collections/Requests/DeleteCollectionRequest.php @@ -0,0 +1,41 @@ +collectionId = $values['collectionId']; + } + + /** + * @return string + */ + public function getCollectionId(): string + { + return $this->collectionId; + } + + /** + * @param string $value + */ + public function setCollectionId(string $value): self + { + $this->collectionId = $value; + return $this; + } +} diff --git a/src/HelpCenters/Collections/Requests/FindCollectionRequest.php b/src/HelpCenters/Collections/Requests/FindCollectionRequest.php new file mode 100644 index 00000000..d09948ec --- /dev/null +++ b/src/HelpCenters/Collections/Requests/FindCollectionRequest.php @@ -0,0 +1,41 @@ +collectionId = $values['collectionId']; + } + + /** + * @return string + */ + public function getCollectionId(): string + { + return $this->collectionId; + } + + /** + * @param string $value + */ + public function setCollectionId(string $value): self + { + $this->collectionId = $value; + return $this; + } +} diff --git a/src/HelpCenters/Collections/Requests/ListCollectionsRequest.php b/src/HelpCenters/Collections/Requests/ListCollectionsRequest.php new file mode 100644 index 00000000..83a55182 --- /dev/null +++ b/src/HelpCenters/Collections/Requests/ListCollectionsRequest.php @@ -0,0 +1,65 @@ +page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/HelpCenters/Collections/Requests/UpdateCollectionRequest.php b/src/HelpCenters/Collections/Requests/UpdateCollectionRequest.php new file mode 100644 index 00000000..dfe8d959 --- /dev/null +++ b/src/HelpCenters/Collections/Requests/UpdateCollectionRequest.php @@ -0,0 +1,143 @@ +collectionId = $values['collectionId']; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->parentId = $values['parentId'] ?? null; + } + + /** + * @return string + */ + public function getCollectionId(): string + { + return $this->collectionId; + } + + /** + * @param string $value + */ + public function setCollectionId(string $value): self + { + $this->collectionId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?GroupTranslatedContent + */ + public function getTranslatedContent(): ?GroupTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?GroupTranslatedContent $value + */ + public function setTranslatedContent(?GroupTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } +} diff --git a/src/HelpCenters/HelpCentersClient.php b/src/HelpCenters/HelpCentersClient.php new file mode 100644 index 00000000..647a8cb3 --- /dev/null +++ b/src/HelpCenters/HelpCentersClient.php @@ -0,0 +1,214 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + $this->collections = new CollectionsClient($this->client, $this->options); + } + + /** + * You can fetch the details of a single Help Center by making a GET request to `https://api.intercom.io/help_center/help_center/`. + * + * @param FindHelpCenterRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return HelpCenter + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindHelpCenterRequest $request, ?array $options = null): HelpCenter + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/help_centers/{$request->getHelpCenterId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return HelpCenter::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can list all Help Centers by making a GET request to `https://api.intercom.io/help_center/help_centers`. + * + * @param ListHelpCentersRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListHelpCentersRequest $request = new ListHelpCentersRequest(), ?array $options = null): Pager + { + return new OffsetPager( + request: $request, + getNextPage: fn (ListHelpCentersRequest $request) => $this->_list($request, $options), + /* @phpstan-ignore-next-line */ + getOffset: fn (ListHelpCentersRequest $request) => $request?->getPage() ?? 0, + setOffset: function (ListHelpCentersRequest $request, int $offset) { + $request->setPage($offset); + }, + getStep: null, + /* @phpstan-ignore-next-line */ + getItems: fn (HelpCenterList $response) => $response?->getData() ?? [], + /* @phpstan-ignore-next-line */ + hasNextPage: null, + ); + } + + /** + * You can list all Help Centers by making a GET request to `https://api.intercom.io/help_center/help_centers`. + * + * @param ListHelpCentersRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return HelpCenterList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListHelpCentersRequest $request = new ListHelpCentersRequest(), ?array $options = null): HelpCenterList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/help_centers", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return HelpCenterList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/HelpCenters/Requests/FindHelpCenterRequest.php b/src/HelpCenters/Requests/FindHelpCenterRequest.php new file mode 100644 index 00000000..72f71916 --- /dev/null +++ b/src/HelpCenters/Requests/FindHelpCenterRequest.php @@ -0,0 +1,41 @@ +helpCenterId = $values['helpCenterId']; + } + + /** + * @return string + */ + public function getHelpCenterId(): string + { + return $this->helpCenterId; + } + + /** + * @param string $value + */ + public function setHelpCenterId(string $value): self + { + $this->helpCenterId = $value; + return $this; + } +} diff --git a/src/HelpCenters/Requests/ListHelpCentersRequest.php b/src/HelpCenters/Requests/ListHelpCentersRequest.php new file mode 100644 index 00000000..7241adec --- /dev/null +++ b/src/HelpCenters/Requests/ListHelpCentersRequest.php @@ -0,0 +1,65 @@ +page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/IntercomAdmins.php b/src/IntercomAdmins.php deleted file mode 100644 index 75ed901c..00000000 --- a/src/IntercomAdmins.php +++ /dev/null @@ -1,48 +0,0 @@ -client->get("admins", $options); - } - - /** - * Gets a single Admin based on the Intercom ID. - * - * @see https://developers.intercom.com/v2.0/reference#view-an-admin - * @param integer $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getAdmin($id, $options = []) - { - $path = $this->adminPath($id); - return $this->client->get($path, $options); - } - - /** - * Returns endpoint path to Admin with given ID. - * - * @param string $id - * @return string - */ - public function adminPath($id) - { - return 'admins/' . $id; - } -} diff --git a/src/IntercomBulk.php b/src/IntercomBulk.php deleted file mode 100644 index 7c92a921..00000000 --- a/src/IntercomBulk.php +++ /dev/null @@ -1,33 +0,0 @@ -client->post("bulk/users", $options); - } - - /** - * Creates Events in bulk. - * - * @param array $options - * @return stdClass - * @throws Exception - */ - public function events($options) - { - return $this->client->post("bulk/events", $options); - } -} diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 6fb053b7..b9c8a5ef 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -2,440 +2,219 @@ namespace Intercom; -use Http\Client\Common\Plugin\ErrorPlugin; -use Http\Client\Common\PluginClient; -use Http\Discovery\Psr17FactoryDiscovery; -use Http\Discovery\Psr18ClientDiscovery; -use Http\Message\Authentication; -use Http\Message\Authentication\BasicAuth; -use Http\Message\Authentication\Bearer; -use Psr\Http\Client\ClientExceptionInterface; -use Psr\Http\Client\ClientInterface; -use Psr\Http\Message\RequestFactoryInterface; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamFactoryInterface; -use Psr\Http\Message\UriFactoryInterface; -use Psr\Http\Message\UriInterface; -use stdClass; +use Intercom\Admins\AdminsClient; +use Intercom\Articles\ArticlesClient; +use Intercom\HelpCenters\HelpCentersClient; +use Intercom\Companies\CompaniesClient; +use Intercom\Contacts\ContactsClient; +use Intercom\Notes\NotesClient; +use Intercom\Tags\TagsClient; +use Intercom\Conversations\ConversationsClient; +use Intercom\DataAttributes\DataAttributesClient; +use Intercom\Events\EventsClient; +use Intercom\DataExport\DataExportClient; +use Intercom\Messages\MessagesClient; +use Intercom\Segments\SegmentsClient; +use Intercom\SubscriptionTypes\SubscriptionTypesClient; +use Intercom\PhoneCallRedirects\PhoneCallRedirectsClient; +use Intercom\Teams\TeamsClient; +use Intercom\TicketTypes\TicketTypesClient; +use Intercom\Tickets\TicketsClient; +use Intercom\Visitors\VisitorsClient; +use Intercom\News\NewsClient; +use Intercom\Unstable\UnstableClient; +use GuzzleHttp\ClientInterface; +use Intercom\Core\Client\RawClient; +use Exception; class IntercomClient { - const SDK_VERSION = '4.4.0'; - - /** - * @var ClientInterface $httpClient - */ - private $httpClient; - - /** - * @var RequestFactoryInterface $requestFactory - */ - private $requestFactory; - /** - * @var UriFactoryInterface $uriFactory + * @var AdminsClient $admins */ - private $uriFactory; + public AdminsClient $admins; /** - * @var StreamFactoryInterface $streamFactory + * @var ArticlesClient $articles */ - private $streamFactory; + public ArticlesClient $articles; /** - * @var string API user authentication + * @var HelpCentersClient $helpCenters */ - private $appIdOrToken; + public HelpCentersClient $helpCenters; /** - * @var string API password authentication + * @var CompaniesClient $companies */ - private $passwordPart; + public CompaniesClient $companies; /** - * @var array $extraRequestHeaders + * @var ContactsClient $contacts */ - private $extraRequestHeaders; + public ContactsClient $contacts; /** - * @var IntercomUsers $users + * @var NotesClient $notes */ - public $users; + public NotesClient $notes; /** - * @var IntercomEvents $events + * @var TagsClient $tags */ - public $events; + public TagsClient $tags; /** - * @var IntercomCompanies $companies + * @var ConversationsClient $conversations */ - public $companies; + public ConversationsClient $conversations; /** - * @var IntercomContacts $contacts + * @var DataAttributesClient $dataAttributes */ - public $contacts; + public DataAttributesClient $dataAttributes; /** - * @var IntercomMessages $messages + * @var EventsClient $events */ - public $messages; + public EventsClient $events; /** - * @var IntercomConversations $conversations + * @var DataExportClient $dataExport */ - public $conversations; + public DataExportClient $dataExport; /** - * @var IntercomLeads $leads + * @var MessagesClient $messages */ - public $leads; + public MessagesClient $messages; /** - * @var IntercomVisitors $visitors + * @var SegmentsClient $segments */ - public $visitors; + public SegmentsClient $segments; /** - * @var IntercomAdmins $admins + * @var SubscriptionTypesClient $subscriptionTypes */ - public $admins; + public SubscriptionTypesClient $subscriptionTypes; /** - * @var IntercomTags $tags + * @var PhoneCallRedirectsClient $phoneCallRedirects */ - public $tags; + public PhoneCallRedirectsClient $phoneCallRedirects; /** - * @var IntercomSegments $segments + * @var TeamsClient $teams */ - public $segments; + public TeamsClient $teams; /** - * @var IntercomCounts $counts + * @var TicketTypesClient $ticketTypes */ - public $counts; + public TicketTypesClient $ticketTypes; /** - * @var IntercomBulk $bulk + * @var TicketsClient $tickets */ - public $bulk; + public TicketsClient $tickets; /** - * @var IntercomNotes $notes + * @var VisitorsClient $visitors */ - public $notes; + public VisitorsClient $visitors; /** - * @var IntercomTeams $teams + * @var NewsClient $news */ - public $teams; + public NewsClient $news; /** - * @var array $rateLimitDetails + * @var UnstableClient $unstable */ - protected $rateLimitDetails = []; + public UnstableClient $unstable; /** - * IntercomClient constructor. - * - * @param string $appIdOrToken App ID. - * @param string|null $password Api Key. - * @param array $extraRequestHeaders Extra request headers to be sent in every api request + * @var array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options */ - public function __construct(string $appIdOrToken, ?string $password = null, array $extraRequestHeaders = []) - { - $this->users = new IntercomUsers($this); - $this->contacts = new IntercomContacts($this); - $this->events = new IntercomEvents($this); - $this->companies = new IntercomCompanies($this); - $this->messages = new IntercomMessages($this); - $this->conversations = new IntercomConversations($this); - $this->leads = new IntercomLeads($this); - $this->visitors = new IntercomVisitors($this); - $this->admins = new IntercomAdmins($this); - $this->tags = new IntercomTags($this); - $this->segments = new IntercomSegments($this); - $this->counts = new IntercomCounts($this); - $this->bulk = new IntercomBulk($this); - $this->notes = new IntercomNotes($this); - $this->teams = new IntercomTeams($this); - - $this->appIdOrToken = $appIdOrToken; - $this->passwordPart = $password; - $this->extraRequestHeaders = $extraRequestHeaders; - - $this->httpClient = $this->getDefaultHttpClient(); - $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); - $this->uriFactory = Psr17FactoryDiscovery::findUriFactory(); - $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); - } + private array $options; /** - * Sets the HTTP client. - * - * @param ClientInterface $httpClient + * @var RawClient $client */ - public function setHttpClient(ClientInterface $httpClient) - { - $this->httpClient = $httpClient; - } + private RawClient $client; /** - * Sets the request factory. - * - * @param RequestFactoryInterface $requestFactory + * @param ?string $token The token to use for authentication. + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options */ - public function setRequestFactory(RequestFactoryInterface $requestFactory) - { - $this->requestFactory = $requestFactory; - } - - /** - * Sets the URI factory. - * - * @param UriFactoryInterface $uriFactory - */ - public function setUriFactory(UriFactoryInterface $uriFactory) - { - $this->uriFactory = $uriFactory; - } - - /** - * Sets the stream factory. - * - * @param StreamFactoryInterface $streamFactory - */ - public function setStreamFactory(StreamFactoryInterface $streamFactory) - { - $this->streamFactory = $streamFactory; - } - - /** - * Sends POST request to Intercom API. - * - * @param string $endpoint - * @param array $json - * @return stdClass - */ - public function post($endpoint, $json) - { - $response = $this->sendRequest('POST', "https://api.intercom.io/$endpoint", $json); - return $this->handleResponse($response); - } - - /** - * Sends PUT request to Intercom API. - * - * @param string $endpoint - * @param array $json - * @return stdClass - */ - public function put($endpoint, $json) - { - $response = $this->sendRequest('PUT', "https://api.intercom.io/$endpoint", $json); - return $this->handleResponse($response); - } - - /** - * Sends DELETE request to Intercom API. - * - * @param string $endpoint - * @param array $json - * @return stdClass - */ - public function delete($endpoint, $json) - { - $response = $this->sendRequest('DELETE', "https://api.intercom.io/$endpoint", $json); - return $this->handleResponse($response); - } - - /** - * Sends GET request to Intercom API. - * - * @param string $endpoint - * @param array $queryParams - * @return stdClass - */ - public function get($endpoint, $queryParams = []) - { - $uri = $this->uriFactory->createUri("https://api.intercom.io/$endpoint"); - if (!empty($queryParams)) { - $uri = $uri->withQuery(http_build_query($queryParams)); - } - - $response = $this->sendRequest('GET', $uri); - - return $this->handleResponse($response); - } - - /** - * Returns the next page of the result. - * - * @param stdClass $pages - * @return stdClass - */ - public function nextPage($pages) - { - $response = $this->sendRequest('GET', $pages->next); - return $this->handleResponse($response); - } - - /** - * Returns the next page of the result for a search query. - * - * @param string $path - * @param array $query - * @param stdClass $pages - * @return stdClass - */ - public function nextSearchPage(string $path, array $query, $pages) - { - $options = [ - "query" => $query, - "pagination" => [ - "per_page" => $pages->per_page, - "starting_after" => $pages->next->starting_after, - ] + public function __construct( + ?string $token = null, + ?array $options = null, + ) { + $token ??= $this->getFromEnvOrThrow('INTERCOM_API_KEY', 'Please pass in token or set the environment variable INTERCOM_API_KEY.'); + $defaultHeaders = [ + 'Authorization' => "Bearer $token", + 'X-Fern-Language' => 'PHP', + 'X-Fern-SDK-Name' => 'Intercom', + 'X-Fern-SDK-Version' => '0.0.325', + 'User-Agent' => 'intercom/intercom-php/0.0.325', + 'Intercom-Version' => '2.11', ]; - return $this->post($path, $options); - } - - /** - * Returns the next page of the result for a cursor based search. - * - * @param string $path - * @param string $startingAfter - * @return stdClass - */ - public function nextCursorPage(string $path, string $startingAfter) - { - return $this->get($path . "?starting_after=" . $startingAfter); - } - - /** - * Gets the rate limit details. - * - * @return array - */ - public function getRateLimitDetails() - { - return $this->rateLimitDetails; - } - /** - * @return ClientInterface - */ - private function getDefaultHttpClient() - { - return new PluginClient( - Psr18ClientDiscovery::find(), - [new ErrorPlugin()] + $this->options = $options ?? []; + $this->options['headers'] = array_merge( + $defaultHeaders, + $this->options['headers'] ?? [], ); - } - /** - * @return array - */ - private function getRequestHeaders() - { - return array_merge( - [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json', - 'User-Agent' => 'Intercom-PHP/' . self::SDK_VERSION, - ], - $this->extraRequestHeaders + $this->client = new RawClient( + options: $this->options, ); - } - - /** - * Returns authentication parameters - * - * @return Authentication - */ - private function getAuth() - { - if (!empty($this->appIdOrToken) && !empty($this->passwordPart)) { - return new BasicAuth($this->appIdOrToken, $this->passwordPart); - } elseif (!empty($this->appIdOrToken)) { - return new Bearer($this->appIdOrToken); - } - return null; - } - - /** - * Authenticates a request object - * @param RequestInterface $request - * - * @return RequestInterface - */ - private function authenticateRequest(RequestInterface $request) - { - $auth = $this->getAuth(); - return $auth ? $auth->authenticate($request) : $request; - } - - /** - * @param string $method - * @param string|UriInterface $uri - * @param array|string|null $body - * - * @return ResponseInterface - * @throws ClientExceptionInterface - */ - private function sendRequest($method, $uri, $body = null) - { - $body = is_array($body) ? json_encode($body) : $body; - $request = $this->requestFactory - ->createRequest($method, $uri); - - if ($body !== null) { - $request = $request - ->withBody($this->streamFactory->createStream($body)); - } - - foreach ($this->getRequestHeaders() as $name => $value) { - $request = $request - ->withHeader($name, $value); - } - - $request = $this->authenticateRequest($request); - return $this->httpClient->sendRequest($request); - } - - /** - * @param ResponseInterface $response - * - * @return stdClass - */ - private function handleResponse(ResponseInterface $response) - { - $this->setRateLimitDetails($response); - - $stream = $response->getBody()->getContents(); - - return json_decode($stream); - } - - /** - * @param ResponseInterface $response - */ - private function setRateLimitDetails(ResponseInterface $response) - { - $this->rateLimitDetails = [ - 'limit' => $response->hasHeader('X-RateLimit-Limit') - ? (int)$response->getHeader('X-RateLimit-Limit')[0] - : null, - 'remaining' => $response->hasHeader('X-RateLimit-Remaining') - ? (int)$response->getHeader('X-RateLimit-Remaining')[0] - : null, - 'reset_at' => $response->hasHeader('X-RateLimit-Reset') - ? (new \DateTimeImmutable())->setTimestamp((int)$response->getHeader('X-RateLimit-Reset')[0]) - : null, - ]; + $this->admins = new AdminsClient($this->client, $this->options); + $this->articles = new ArticlesClient($this->client, $this->options); + $this->helpCenters = new HelpCentersClient($this->client, $this->options); + $this->companies = new CompaniesClient($this->client, $this->options); + $this->contacts = new ContactsClient($this->client, $this->options); + $this->notes = new NotesClient($this->client, $this->options); + $this->tags = new TagsClient($this->client, $this->options); + $this->conversations = new ConversationsClient($this->client, $this->options); + $this->dataAttributes = new DataAttributesClient($this->client, $this->options); + $this->events = new EventsClient($this->client, $this->options); + $this->dataExport = new DataExportClient($this->client, $this->options); + $this->messages = new MessagesClient($this->client, $this->options); + $this->segments = new SegmentsClient($this->client, $this->options); + $this->subscriptionTypes = new SubscriptionTypesClient($this->client, $this->options); + $this->phoneCallRedirects = new PhoneCallRedirectsClient($this->client, $this->options); + $this->teams = new TeamsClient($this->client, $this->options); + $this->ticketTypes = new TicketTypesClient($this->client, $this->options); + $this->tickets = new TicketsClient($this->client, $this->options); + $this->visitors = new VisitorsClient($this->client, $this->options); + $this->news = new NewsClient($this->client, $this->options); + $this->unstable = new UnstableClient($this->client, $this->options); + } + + /** + * @param string $env + * @param string $message + * @return string + */ + private function getFromEnvOrThrow(string $env, string $message): string + { + $value = getenv($env); + return $value ? (string) $value : throw new Exception($message); } } diff --git a/src/IntercomCompanies.php b/src/IntercomCompanies.php deleted file mode 100644 index e3256ad9..00000000 --- a/src/IntercomCompanies.php +++ /dev/null @@ -1,149 +0,0 @@ -client->post("companies", $options); - } - - /** - * Updates a Company. - * - * @see https://developers.intercom.io/reference#create-or-update-company - * @param array $options - * @return stdClass - * @throws Exception - */ - public function update($options) - { - return $this->create($options); - } - - /** - * Attaches a Contact to a Company. - * - * @see https://developers.intercom.io/reference#attach-contact-to-company - * @param string $contactId - * @param string $companyId - * @param array $options - * @return stdClass - * @throws Exception - */ - public function attachContact(string $contactId, string $companyId, array $options = []) - { - $path = $this->companyAttachPath($contactId); - $options = array_merge($options, ["id" => $companyId]); - return $this->client->post($path, $options); - } - - /** - * Detaches a Contact from a Company. - * - * @see https://developers.intercom.io/reference#detach-contact-from-company - * @param string $contactId - * @param string $companyId - * @param array $options - * @return stdClass - * @throws Exception - */ - public function detachContact(string $contactId, string $companyId, array $options = []) - { - $path = $this->companyDetachPath($contactId, $companyId); - return $this->client->delete($path, $options); - } - - /** - * Returns list of Companies. - * - * @see https://developers.intercom.io/reference#list-companies - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getCompanies($options) - { - return $this->client->get("companies", $options); - } - - /** - * Gets a single Company based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#view-a-company - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getCompany($id, $options = []) - { - $path = $this->companyPath($id); - return $this->client->get($path, $options); - } - - - /** - * Returns a list of Users belonging to a single Company based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#list-company-users - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getCompanyUsers($id, $options = []) - { - $path = $this->companyUsersPath($id); - return $this->client->get($path, $options); - } - - /** - * @param string $id - * @return string - */ - public function companyPath($id) - { - return 'companies/' . $id; - } - - /** - * @param string $id - * @return string - */ - public function companyUsersPath($id) - { - return 'companies/' . $id . '/users'; - } - - /** - * @param string $contactId - * @return string - */ - public function companyAttachPath(string $contactId) - { - return 'contacts/' . $contactId . '/companies'; - } - - /** - * @param string $contactId - * @param string $companyId - * @return string - */ - public function companyDetachPath(string $contactId, string $companyId) - { - return 'contacts/' . $contactId . '/companies/' . $companyId; - } -} diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php deleted file mode 100644 index 7cfc0739..00000000 --- a/src/IntercomContacts.php +++ /dev/null @@ -1,133 +0,0 @@ -client->post("contacts", $options); - } - - /** - * Updates a Contact. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function update(string $id, array $options) - { - $path = $this->contactPath($id); - return $this->client->put($path, $options); - } - - /** - * Lists Contacts. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#list-contacts - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getContacts(array $options = []) - { - return $this->client->get('contacts', $options); - } - - /** - * Gets a single Contact based on the Intercom ID. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getContact(string $id, array $options = []) - { - $path = $this->contactPath($id); - return $this->client->get($path, $options); - } - - /** - * Permenently Deletes a single Contact based on the Intercom ID. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function deleteContact(string $id, array $options = []) - { - $path = $this->contactPath($id); - return $this->client->delete($path, $options); - } - - /** - * Returns list of Contacts that match search query. - * - * @see https://developers.intercom.com/reference#search-for-contacts - * @param array $options - * @return stdClass - * @throws Exception - */ - public function search(array $options) - { - $path = 'contacts/search'; - return $this->client->post($path, $options); - } - - /** - * Returns next page of Contacts that match search query. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#pagination-search - * @param array $query - * @param stdClass $pages - * @return stdClass - * @throws Exception - */ - public function nextSearch(array $query, $pages) - { - $path = 'contacts/search'; - return $this->client->nextSearchPage($path, $query, $pages); - } - - /** - * Returns next page of a Contacts list. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#pagination - * @param stdClass $pages - * @return stdClass - * @throws Exception - */ - public function nextCursor($pages) - { - $path = 'contacts'; - $starting_after = $pages->next->starting_after; - return $this->client->nextCursorPage($path, $starting_after); - } - - /** - * @param string $id - * @return string - */ - public function contactPath(string $id) - { - return 'contacts/' . $id; - } -} diff --git a/src/IntercomConversations.php b/src/IntercomConversations.php deleted file mode 100644 index b38f387b..00000000 --- a/src/IntercomConversations.php +++ /dev/null @@ -1,145 +0,0 @@ -client->post('conversations', $options); - } - - /** - * Returns list of Conversations. - * - * @see https://developers.intercom.io/reference#list-conversations - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getConversations($options) - { - return $this->client->get('conversations', $options); - } - - /** - * Returns single Conversation. - * - * @see https://developers.intercom.io/reference#get-a-single-conversation - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getConversation($id, $options = []) - { - $path = $this->conversationPath($id); - return $this->client->get($path, $options); - } - - /** - * Returns list of Conversations that match search query. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#search-for-conversations - * @param array $options - * @return stdClass - * @throws Exception - */ - public function search(array $options) - { - $path = 'conversations/search'; - return $this->client->post($path, $options); - } - - /** - * Returns next page of Conversations that match search query. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#pagination-search - * @param array $query - * @param stdClass $pages - * @return stdClass - * @throws Exception - */ - public function nextSearch(array $query, $pages) - { - $path = 'conversations/search'; - return $this->client->nextSearchPage($path, $query, $pages); - } - - /** - * Creates Conversation Reply to Conversation with given ID. - * - * @see https://developers.intercom.io/reference#replying-to-a-conversation - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function replyToConversation($id, $options) - { - $path = $this->conversationReplyPath($id); - return $this->client->post($path, $options); - } - - /** - * Creates Conversation Reply to last conversation. (no need to specify Conversation ID.) - * - * @see https://developers.intercom.io/reference#replying-to-users-last-conversation - * @param array $options - * @return stdClass - * @throws Exception - */ - public function replyToLastConversation($options) - { - $path = 'conversations/last/reply'; - return $this->client->post($path, $options); - } - - /** - * Marks a Conversation as read based on the given Conversation ID. - * - * @see https://developers.intercom.io/reference#marking-a-conversation-as-read - * @param string $id - * @return stdClass - * @throws Exception - */ - public function markConversationAsRead($id) - { - $path = $this->conversationPath($id); - $data = ['read' => true]; - return $this->client->put($path, $data); - } - - /** - * Returns endpoint path to Conversation with given ID. - * - * @param string $id - * @return string - */ - public function conversationPath($id) - { - return 'conversations/' . $id; - } - - /** - * Returns endpoint path to Conversation Reply for Conversation with given ID. - * - * @param string $id - * @return string - */ - public function conversationReplyPath($id) - { - return 'conversations/' . $id . '/reply'; - } -} diff --git a/src/IntercomCounts.php b/src/IntercomCounts.php deleted file mode 100644 index b968cc54..00000000 --- a/src/IntercomCounts.php +++ /dev/null @@ -1,22 +0,0 @@ -client->get("counts", $options); - } -} diff --git a/src/IntercomEvents.php b/src/IntercomEvents.php deleted file mode 100644 index 60629af8..00000000 --- a/src/IntercomEvents.php +++ /dev/null @@ -1,35 +0,0 @@ -client->post("events", $options); - } - - /** - * Lists User Events. - * - * @see https://developers.intercom.io/reference#list-user-events - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getEvents($options) - { - return $this->client->get("events", array_merge(["type" => "user"], $options)); - } -} diff --git a/src/IntercomLeads.php b/src/IntercomLeads.php deleted file mode 100644 index 6ef1132d..00000000 --- a/src/IntercomLeads.php +++ /dev/null @@ -1,115 +0,0 @@ -client->post("contacts", $options); - } - - /** - * Creates Lead. - * - * @see https://developers.intercom.io/reference#create-lead - * @param array $options - * @return stdClass - * @throws Exception - */ - public function update($options) - { - return $this->create($options); - } - - /** - * Lists Leads. - * - * @see https://developers.intercom.io/reference#list-leads - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getLeads($options) - { - return $this->client->get("contacts", $options); - } - - /** - * Returns single Lead. - * - * @see https://developers.intercom.io/reference#view-a-lead - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getLead($id, $options = []) - { - $path = $this->leadPath($id); - return $this->client->get($path, $options); - } - - /** - * Deletes Lead. - * - * @see https://developers.intercom.io/reference#delete-a-lead - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function deleteLead($id, $options = []) - { - $path = $this->leadPath($id); - return $this->client->delete($path, $options); - } - - /** - * Converts Lead. - * - * @see https://developers.intercom.io/reference#convert-a-lead - * @param $options - * @return stdClass - * @throws Exception - */ - public function convertLead($options) - { - return $this->client->post("contacts/convert", $options); - } - - /** - * Returns endpoint path to Lead with given ID. - * - * @param string $id - * @return string - */ - public function leadPath($id) - { - return "contacts/" . $id; - } - - /** - * Gets a list of Leads through the contacts scroll API. - * - * @see https://developers.intercom.com/v2.0/reference#iterating-over-all-leads - * @param array $options - * @return stdClass - * @throws Exception - */ - public function scrollLeads($options = []) - { - return $this->client->get('contacts/scroll', $options); - } -} diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php deleted file mode 100644 index d4d96657..00000000 --- a/src/IntercomMessages.php +++ /dev/null @@ -1,22 +0,0 @@ -client->post("messages", $options); - } -} diff --git a/src/IntercomNotes.php b/src/IntercomNotes.php deleted file mode 100644 index 43a02d60..00000000 --- a/src/IntercomNotes.php +++ /dev/null @@ -1,48 +0,0 @@ -client->post("notes", $options); - } - - /** - * Lists Notes. - * - * @see https://developers.intercom.io/reference#list-notes-for-a-user - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getNotes($options) - { - return $this->client->get("notes", $options); - } - - /** - * Returns single Note. - * - * @see https://developers.intercom.io/reference#view-a-note - * @param string $id - * @return stdClass - * @throws Exception - */ - public function getNote($id) - { - return $this->client->get("notes/" . $id, []); - } -} diff --git a/src/IntercomResource.php b/src/IntercomResource.php deleted file mode 100644 index 98c12b52..00000000 --- a/src/IntercomResource.php +++ /dev/null @@ -1,21 +0,0 @@ -client = $client; - } -} diff --git a/src/IntercomSegments.php b/src/IntercomSegments.php deleted file mode 100644 index a40feb1b..00000000 --- a/src/IntercomSegments.php +++ /dev/null @@ -1,36 +0,0 @@ -client->get('segments/' . $id, $options); - } - - /** - * Lists Segments. - * - * @see https://developers.intercom.com/reference#list-segments - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getSegments($options = []) - { - return $this->client->get("segments", $options); - } -} diff --git a/src/IntercomTags.php b/src/IntercomTags.php deleted file mode 100644 index e7952e50..00000000 --- a/src/IntercomTags.php +++ /dev/null @@ -1,35 +0,0 @@ -client->post("tags", $options); - } - - /** - * Lists Tags. - * - * @see https://developers.intercom.io/reference#list-tags-for-an-app - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getTags($options = []) - { - return $this->client->get("tags", $options); - } -} diff --git a/src/IntercomTeams.php b/src/IntercomTeams.php deleted file mode 100644 index b2a344b6..00000000 --- a/src/IntercomTeams.php +++ /dev/null @@ -1,48 +0,0 @@ -client->get("teams", $options); - } - - /** - * Gets a single Team based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#view-a-team - * @param integer $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getTeam($id, $options = []) - { - $path = $this->teamPath($id); - return $this->client->get($path, $options); - } - - /** - * Returns endpoint path to Team with given ID. - * - * @param string $id - * @return string - */ - public function teamPath($id) - { - return 'teams/' . $id; - } -} diff --git a/src/IntercomUsers.php b/src/IntercomUsers.php deleted file mode 100644 index 04b78757..00000000 --- a/src/IntercomUsers.php +++ /dev/null @@ -1,129 +0,0 @@ -client->post("users", $options); - } - - /** - * Creates a User. - * - * @see https://developers.intercom.io/reference#create-or-update-user - * @param array $options - * @return stdClass - * @throws Exception - */ - public function update(array $options) - { - return $this->create($options); - } - - /** - * Lists Users. - * - * @see https://developers.intercom.io/reference#list-users - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getUsers(array $options) - { - return $this->client->get('users', $options); - } - - /** - * Gets a single User based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#view-a-user - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getUser($id, $options = []) - { - $path = $this->userPath($id); - return $this->client->get($path, $options); - } - - /** - * Gets a list of Users through the user scroll API. - * - * @see https://developers.intercom.com/reference#iterating-over-all-users - * @param array $options - * @return stdClass - * @throws Exception - */ - public function scrollUsers(array $options = []) - { - return $this->client->get('users/scroll', $options); - } - - /** - * Deletes a single User based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#archive-a-user - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function archiveUser(string $id, array $options = []) - { - $path = $this->userPath($id); - return $this->client->delete($path, $options); - } - - /** - * Deletes a single User based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#archive-a-user - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function deleteUser(string $id, array $options = []) - { - return $this->archiveUser($id, $options); - } - - /** - * Permanently deletes a single User based on the Intercom ID. - * - * @see https://developers.intercom.com/reference#delete-users - * @param string $id - * @return stdClass - * @throws Exception - */ - public function permanentlyDeleteUser(string $id) - { - return $this->client->post('user_delete_requests', [ - 'intercom_user_id' => $id - ]); - } - - /** - * @param string $id - * @return string - */ - public function userPath(string $id) - { - return 'users/' . $id; - } -} diff --git a/src/IntercomVisitors.php b/src/IntercomVisitors.php deleted file mode 100644 index c840a889..00000000 --- a/src/IntercomVisitors.php +++ /dev/null @@ -1,77 +0,0 @@ -client->put("visitors", $options); - } - - - /** - * Returns single Visitor. - * - * @see https://developers.intercom.com/reference#view-a-visitor - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getVisitor($id, $options = []) - { - $path = $this->visitorPath($id); - return $this->client->get($path, $options); - } - - /** - * Deletes Visitor. - * - * @see https://developers.intercom.com/reference#delete-a-visitor - * @param string $id - * @param array $options - * @return stdClass - * @throws Exception - */ - public function deleteVisitor($id, $options = []) - { - $path = $this->visitorPath($id); - return $this->client->delete($path, $options); - } - - /** - * Converts Visitor. - * - * @see https://developers.intercom.io/reference#convert-a-lead - * @param $options - * @return stdClass - * @throws Exception - */ - public function convertVisitor($options) - { - return $this->client->post("visitors/convert", $options); - } - - /** - * Returns endpoint path to Visitor with given ID. - * - * @param string $id - * @return string - */ - public function visitorPath($id) - { - return "visitors/" . $id; - } -} diff --git a/src/Messages/MessagesClient.php b/src/Messages/MessagesClient.php new file mode 100644 index 00000000..48850bc7 --- /dev/null +++ b/src/Messages/MessagesClient.php @@ -0,0 +1,119 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can create a message that has been initiated by an admin. The conversation can be either an in-app message or an email. + * + * > 🚧 Sending for visitors + * > + * > There can be a short delay between when a contact is created and when a contact becomes available to be messaged through the API. A 404 Not Found error will be returned in this case. + * + * This will return the Message model that has been created. + * + * > 🚧 Retrieving Associated Conversations + * > + * > As this is a message, there will be no conversation present until the contact responds. Once they do, you will have to search for a contact's conversations with the id of the message. + * + * @param CreateMessageRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Message + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateMessageRequest $request, ?array $options = null): Message + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "messages", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Message::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Messages/Types/Message.php b/src/Messages/Types/Message.php new file mode 100644 index 00000000..9572fd34 --- /dev/null +++ b/src/Messages/Types/Message.php @@ -0,0 +1,204 @@ + $messageType The type of message that was sent. Can be email, inapp, facebook or twitter. + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var string $conversationId The associated conversation_id + */ + #[JsonProperty('conversation_id')] + private string $conversationId; + + /** + * @param array{ + * type: string, + * id: string, + * createdAt: int, + * subject: string, + * body: string, + * messageType: value-of, + * conversationId: string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->createdAt = $values['createdAt']; + $this->subject = $values['subject']; + $this->body = $values['body']; + $this->messageType = $values['messageType']; + $this->conversationId = $values['conversationId']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return string + */ + public function getSubject(): string + { + return $this->subject; + } + + /** + * @param string $value + */ + public function setSubject(string $value): self + { + $this->subject = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return value-of + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param value-of $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Messages/Types/MessageMessageType.php b/src/Messages/Types/MessageMessageType.php new file mode 100644 index 00000000..7a60d687 --- /dev/null +++ b/src/Messages/Types/MessageMessageType.php @@ -0,0 +1,11 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all news items that are live on a given newsfeed + * + * @param ListNewsFeedItemsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedNewsItemResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function listItems(ListNewsFeedItemsRequest $request, ?array $options = null): PaginatedNewsItemResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/newsfeeds/{$request->getNewsfeedId()}/items", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedNewsItemResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all newsfeeds + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedNewsfeedResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): PaginatedNewsfeedResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/newsfeeds", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedNewsfeedResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single newsfeed + * + * @param FindNewsFeedRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Newsfeed + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindNewsFeedRequest $request, ?array $options = null): Newsfeed + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/newsfeeds/{$request->getNewsfeedId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Newsfeed::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/News/Feeds/Requests/FindNewsFeedRequest.php b/src/News/Feeds/Requests/FindNewsFeedRequest.php new file mode 100644 index 00000000..2f38b123 --- /dev/null +++ b/src/News/Feeds/Requests/FindNewsFeedRequest.php @@ -0,0 +1,41 @@ +newsfeedId = $values['newsfeedId']; + } + + /** + * @return string + */ + public function getNewsfeedId(): string + { + return $this->newsfeedId; + } + + /** + * @param string $value + */ + public function setNewsfeedId(string $value): self + { + $this->newsfeedId = $value; + return $this; + } +} diff --git a/src/News/Feeds/Requests/ListNewsFeedItemsRequest.php b/src/News/Feeds/Requests/ListNewsFeedItemsRequest.php new file mode 100644 index 00000000..16234900 --- /dev/null +++ b/src/News/Feeds/Requests/ListNewsFeedItemsRequest.php @@ -0,0 +1,41 @@ +newsfeedId = $values['newsfeedId']; + } + + /** + * @return string + */ + public function getNewsfeedId(): string + { + return $this->newsfeedId; + } + + /** + * @param string $value + */ + public function setNewsfeedId(string $value): self + { + $this->newsfeedId = $value; + return $this; + } +} diff --git a/src/News/Items/ItemsClient.php b/src/News/Items/ItemsClient.php new file mode 100644 index 00000000..d6a5a64e --- /dev/null +++ b/src/News/Items/ItemsClient.php @@ -0,0 +1,332 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all news items + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedNewsItemResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): PaginatedNewsItemResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedNewsItemResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a news item + * + * @param NewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NewsItem + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(NewsItemRequest $request, ?array $options = null): NewsItem + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NewsItem::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single news item. + * + * @param FindNewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NewsItem + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindNewsItemRequest $request, ?array $options = null): NewsItem + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items/{$request->getNewsItemId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NewsItem::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * @param UpdateNewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NewsItem + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateNewsItemRequest $request, ?array $options = null): NewsItem + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items/{$request->getNewsItemId()}", + method: HttpMethod::PUT, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NewsItem::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single news item. + * + * @param DeleteNewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function delete(DeleteNewsItemRequest $request, ?array $options = null): DeletedObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items/{$request->getNewsItemId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/News/Items/Requests/DeleteNewsItemRequest.php b/src/News/Items/Requests/DeleteNewsItemRequest.php new file mode 100644 index 00000000..395f60f9 --- /dev/null +++ b/src/News/Items/Requests/DeleteNewsItemRequest.php @@ -0,0 +1,41 @@ +newsItemId = $values['newsItemId']; + } + + /** + * @return string + */ + public function getNewsItemId(): string + { + return $this->newsItemId; + } + + /** + * @param string $value + */ + public function setNewsItemId(string $value): self + { + $this->newsItemId = $value; + return $this; + } +} diff --git a/src/News/Items/Requests/FindNewsItemRequest.php b/src/News/Items/Requests/FindNewsItemRequest.php new file mode 100644 index 00000000..c4ab230c --- /dev/null +++ b/src/News/Items/Requests/FindNewsItemRequest.php @@ -0,0 +1,41 @@ +newsItemId = $values['newsItemId']; + } + + /** + * @return string + */ + public function getNewsItemId(): string + { + return $this->newsItemId; + } + + /** + * @param string $value + */ + public function setNewsItemId(string $value): self + { + $this->newsItemId = $value; + return $this; + } +} diff --git a/src/News/Items/Requests/UpdateNewsItemRequest.php b/src/News/Items/Requests/UpdateNewsItemRequest.php new file mode 100644 index 00000000..ee861626 --- /dev/null +++ b/src/News/Items/Requests/UpdateNewsItemRequest.php @@ -0,0 +1,66 @@ +newsItemId = $values['newsItemId']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getNewsItemId(): string + { + return $this->newsItemId; + } + + /** + * @param string $value + */ + public function setNewsItemId(string $value): self + { + $this->newsItemId = $value; + return $this; + } + + /** + * @return NewsItemRequest + */ + public function getBody(): NewsItemRequest + { + return $this->body; + } + + /** + * @param NewsItemRequest $value + */ + public function setBody(NewsItemRequest $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/News/NewsClient.php b/src/News/NewsClient.php new file mode 100644 index 00000000..0c6d7a06 --- /dev/null +++ b/src/News/NewsClient.php @@ -0,0 +1,57 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + $this->items = new ItemsClient($this->client, $this->options); + $this->feeds = new FeedsClient($this->client, $this->options); + } +} diff --git a/src/News/Types/NewsItem.php b/src/News/Types/NewsItem.php new file mode 100644 index 00000000..9666a61f --- /dev/null +++ b/src/News/Types/NewsItem.php @@ -0,0 +1,381 @@ + $state News items will not be visible to your users in the assigned newsfeeds until they are set live. + */ + #[JsonProperty('state')] + private string $state; + + /** + * @var ?array $newsfeedAssignments A list of newsfeed_assignments to assign to the specified newsfeed. + */ + #[JsonProperty('newsfeed_assignments'), ArrayType([NewsfeedAssignment::class])] + private ?array $newsfeedAssignments; + + /** + * @var ?array $labels Label names displayed to users to categorize the news item. + */ + #[JsonProperty('labels'), ArrayType([new Union('string', 'null')])] + private ?array $labels; + + /** + * @var ?string $coverImageUrl URL of the image used as cover. Must have .jpg or .png extension. + */ + #[JsonProperty('cover_image_url')] + private ?string $coverImageUrl; + + /** + * @var ?array $reactions Ordered list of emoji reactions to the news item. When empty, reactions are disabled. + */ + #[JsonProperty('reactions'), ArrayType([new Union('string', 'null')])] + private ?array $reactions; + + /** + * @var ?bool $deliverSilently When set to true, the news item will appear in the messenger newsfeed without showing a notification badge. + */ + #[JsonProperty('deliver_silently')] + private ?bool $deliverSilently; + + /** + * @var int $createdAt Timestamp for when the news item was created. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var ?int $updatedAt Timestamp for when the news item was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @param array{ + * type: 'news-item', + * id: string, + * workspaceId: string, + * title: string, + * body: string, + * senderId: int, + * state: value-of, + * createdAt: int, + * newsfeedAssignments?: ?array, + * labels?: ?array, + * coverImageUrl?: ?string, + * reactions?: ?array, + * deliverSilently?: ?bool, + * updatedAt?: ?int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->workspaceId = $values['workspaceId']; + $this->title = $values['title']; + $this->body = $values['body']; + $this->senderId = $values['senderId']; + $this->state = $values['state']; + $this->newsfeedAssignments = $values['newsfeedAssignments'] ?? null; + $this->labels = $values['labels'] ?? null; + $this->coverImageUrl = $values['coverImageUrl'] ?? null; + $this->reactions = $values['reactions'] ?? null; + $this->deliverSilently = $values['deliverSilently'] ?? null; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return 'news-item' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'news-item' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getSenderId(): int + { + return $this->senderId; + } + + /** + * @param int $value + */ + public function setSenderId(int $value): self + { + $this->senderId = $value; + return $this; + } + + /** + * @return value-of + */ + public function getState(): string + { + return $this->state; + } + + /** + * @param value-of $value + */ + public function setState(string $value): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?array + */ + public function getNewsfeedAssignments(): ?array + { + return $this->newsfeedAssignments; + } + + /** + * @param ?array $value + */ + public function setNewsfeedAssignments(?array $value = null): self + { + $this->newsfeedAssignments = $value; + return $this; + } + + /** + * @return ?array + */ + public function getLabels(): ?array + { + return $this->labels; + } + + /** + * @param ?array $value + */ + public function setLabels(?array $value = null): self + { + $this->labels = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCoverImageUrl(): ?string + { + return $this->coverImageUrl; + } + + /** + * @param ?string $value + */ + public function setCoverImageUrl(?string $value = null): self + { + $this->coverImageUrl = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReactions(): ?array + { + return $this->reactions; + } + + /** + * @param ?array $value + */ + public function setReactions(?array $value = null): self + { + $this->reactions = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeliverSilently(): ?bool + { + return $this->deliverSilently; + } + + /** + * @param ?bool $value + */ + public function setDeliverSilently(?bool $value = null): self + { + $this->deliverSilently = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/News/Types/NewsItemState.php b/src/News/Types/NewsItemState.php new file mode 100644 index 00000000..35a65c21 --- /dev/null +++ b/src/News/Types/NewsItemState.php @@ -0,0 +1,9 @@ +id = $values['id']; + $this->type = $values['type']; + $this->name = $values['name']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'newsfeed' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'newsfeed' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/News/Types/NewsfeedAssignment.php b/src/News/Types/NewsfeedAssignment.php new file mode 100644 index 00000000..eff051f8 --- /dev/null +++ b/src/News/Types/NewsfeedAssignment.php @@ -0,0 +1,79 @@ +newsfeedId = $values['newsfeedId']; + $this->publishedAt = $values['publishedAt']; + } + + /** + * @return int + */ + public function getNewsfeedId(): int + { + return $this->newsfeedId; + } + + /** + * @param int $value + */ + public function setNewsfeedId(int $value): self + { + $this->newsfeedId = $value; + return $this; + } + + /** + * @return int + */ + public function getPublishedAt(): int + { + return $this->publishedAt; + } + + /** + * @param int $value + */ + public function setPublishedAt(int $value): self + { + $this->publishedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Notes/NotesClient.php b/src/Notes/NotesClient.php new file mode 100644 index 00000000..eb0f5f95 --- /dev/null +++ b/src/Notes/NotesClient.php @@ -0,0 +1,264 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of notes that are associated to a contact. + * + * @param ListContactNotesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function list(ListContactNotesRequest $request, ?array $options = null): Pager + { + return new OffsetPager( + request: $request, + getNextPage: fn (ListContactNotesRequest $request) => $this->_list($request, $options), + /* @phpstan-ignore-next-line */ + getOffset: fn (ListContactNotesRequest $request) => $request?->getPage() ?? 0, + setOffset: function (ListContactNotesRequest $request, int $offset) { + $request->setPage($offset); + }, + getStep: null, + /* @phpstan-ignore-next-line */ + getItems: fn (NoteList $response) => $response?->getData() ?? [], + /* @phpstan-ignore-next-line */ + hasNextPage: null, + ); + } + + /** + * You can add a note to a single contact. + * + * @param CreateContactNoteRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Note + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateContactNoteRequest $request, ?array $options = null): Note + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/notes", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Note::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single note. + * + * @param FindNoteRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Note + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindNoteRequest $request, ?array $options = null): Note + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "notes/{$request->getNoteId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Note::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of notes that are associated to a contact. + * + * @param ListContactNotesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NoteList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _list(ListContactNotesRequest $request, ?array $options = null): NoteList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/notes", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NoteList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Notes/Requests/CreateContactNoteRequest.php b/src/Notes/Requests/CreateContactNoteRequest.php new file mode 100644 index 00000000..7d3ab6e0 --- /dev/null +++ b/src/Notes/Requests/CreateContactNoteRequest.php @@ -0,0 +1,92 @@ +contactId = $values['contactId']; + $this->body = $values['body']; + $this->adminId = $values['adminId'] ?? null; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Notes/Requests/FindNoteRequest.php b/src/Notes/Requests/FindNoteRequest.php new file mode 100644 index 00000000..1e3cede9 --- /dev/null +++ b/src/Notes/Requests/FindNoteRequest.php @@ -0,0 +1,41 @@ +noteId = $values['noteId']; + } + + /** + * @return string + */ + public function getNoteId(): string + { + return $this->noteId; + } + + /** + * @param string $value + */ + public function setNoteId(string $value): self + { + $this->noteId = $value; + return $this; + } +} diff --git a/src/Notes/Requests/ListContactNotesRequest.php b/src/Notes/Requests/ListContactNotesRequest.php new file mode 100644 index 00000000..76f7ecdb --- /dev/null +++ b/src/Notes/Requests/ListContactNotesRequest.php @@ -0,0 +1,89 @@ +contactId = $values['contactId']; + $this->page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Notes/Types/Note.php b/src/Notes/Types/Note.php new file mode 100644 index 00000000..f1cf5025 --- /dev/null +++ b/src/Notes/Types/Note.php @@ -0,0 +1,180 @@ +type = $values['type']; + $this->id = $values['id']; + $this->createdAt = $values['createdAt']; + $this->contact = $values['contact'] ?? null; + $this->author = $values['author']; + $this->body = $values['body']; + } + + /** + * @return 'note' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'note' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?NoteContact + */ + public function getContact(): ?NoteContact + { + return $this->contact; + } + + /** + * @param ?NoteContact $value + */ + public function setContact(?NoteContact $value = null): self + { + $this->contact = $value; + return $this; + } + + /** + * @return Admin + */ + public function getAuthor(): Admin + { + return $this->author; + } + + /** + * @param Admin $value + */ + public function setAuthor(Admin $value): self + { + $this->author = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Notes/Types/NoteContact.php b/src/Notes/Types/NoteContact.php new file mode 100644 index 00000000..fc3623bb --- /dev/null +++ b/src/Notes/Types/NoteContact.php @@ -0,0 +1,79 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + } + + /** + * @return ?'contact' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'contact' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/PhoneCallRedirects/PhoneCallRedirectsClient.php b/src/PhoneCallRedirects/PhoneCallRedirectsClient.php new file mode 100644 index 00000000..bc05457c --- /dev/null +++ b/src/PhoneCallRedirects/PhoneCallRedirectsClient.php @@ -0,0 +1,112 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can use the API to deflect phone calls to the Intercom Messenger. + * Calling this endpoint will send an SMS with a link to the Messenger to the phone number specified. + * + * If custom attributes are specified, they will be added to the user or lead's custom data attributes. + * + * @param CreatePhoneCallRedirectRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PhoneSwitch + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreatePhoneCallRedirectRequest $request, ?array $options = null): PhoneSwitch + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "phone_call_redirects", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PhoneSwitch::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/PhoneCallRedirects/Requests/CreatePhoneCallRedirectRequest.php b/src/PhoneCallRedirects/Requests/CreatePhoneCallRedirectRequest.php new file mode 100644 index 00000000..22252828 --- /dev/null +++ b/src/PhoneCallRedirects/Requests/CreatePhoneCallRedirectRequest.php @@ -0,0 +1,69 @@ + $customAttributes + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * phone: string, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->phone = $values['phone']; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getPhone(): string + { + return $this->phone; + } + + /** + * @param string $value + */ + public function setPhone(string $value): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } +} diff --git a/src/Segments/Requests/FindSegmentRequest.php b/src/Segments/Requests/FindSegmentRequest.php new file mode 100644 index 00000000..ceade37a --- /dev/null +++ b/src/Segments/Requests/FindSegmentRequest.php @@ -0,0 +1,41 @@ +segmentId = $values['segmentId']; + } + + /** + * @return string + */ + public function getSegmentId(): string + { + return $this->segmentId; + } + + /** + * @param string $value + */ + public function setSegmentId(string $value): self + { + $this->segmentId = $value; + return $this; + } +} diff --git a/src/Segments/Requests/ListSegmentsRequest.php b/src/Segments/Requests/ListSegmentsRequest.php new file mode 100644 index 00000000..98fb040d --- /dev/null +++ b/src/Segments/Requests/ListSegmentsRequest.php @@ -0,0 +1,41 @@ +includeCount = $values['includeCount'] ?? null; + } + + /** + * @return ?bool + */ + public function getIncludeCount(): ?bool + { + return $this->includeCount; + } + + /** + * @param ?bool $value + */ + public function setIncludeCount(?bool $value = null): self + { + $this->includeCount = $value; + return $this; + } +} diff --git a/src/Segments/SegmentsClient.php b/src/Segments/SegmentsClient.php new file mode 100644 index 00000000..9d96d436 --- /dev/null +++ b/src/Segments/SegmentsClient.php @@ -0,0 +1,170 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all segments. + * + * @param ListSegmentsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SegmentList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(ListSegmentsRequest $request = new ListSegmentsRequest(), ?array $options = null): SegmentList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getIncludeCount() != null) { + $query['include_count'] = $request->getIncludeCount(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "segments", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SegmentList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single segment. + * + * @param FindSegmentRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Segment + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindSegmentRequest $request, ?array $options = null): Segment + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "segments/{$request->getSegmentId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Segment::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Segments/Types/Segment.php b/src/Segments/Types/Segment.php new file mode 100644 index 00000000..77799c94 --- /dev/null +++ b/src/Segments/Types/Segment.php @@ -0,0 +1,204 @@ + $personType Type of the contact: contact (lead) or user. + */ + #[JsonProperty('person_type')] + private string $personType; + + /** + * @var ?int $count The number of items in the user segment. It's returned when `include_count=true` is included in the request. + */ + #[JsonProperty('count')] + private ?int $count; + + /** + * @param array{ + * type: 'segment', + * id: string, + * name: string, + * createdAt: int, + * personType: value-of, + * updatedAt?: ?int, + * count?: ?int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->name = $values['name']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->personType = $values['personType']; + $this->count = $values['count'] ?? null; + } + + /** + * @return 'segment' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'segment' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return value-of + */ + public function getPersonType(): string + { + return $this->personType; + } + + /** + * @param value-of $value + */ + public function setPersonType(string $value): self + { + $this->personType = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCount(): ?int + { + return $this->count; + } + + /** + * @param ?int $value + */ + public function setCount(?int $value = null): self + { + $this->count = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Segments/Types/SegmentPersonType.php b/src/Segments/Types/SegmentPersonType.php new file mode 100644 index 00000000..07e33f5c --- /dev/null +++ b/src/Segments/Types/SegmentPersonType.php @@ -0,0 +1,9 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can list all subscription types. A list of subscription type objects will be returned. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionTypeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): SubscriptionTypeList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "subscription_types", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionTypeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/SubscriptionTypes/Types/SubscriptionType.php b/src/SubscriptionTypes/Types/SubscriptionType.php new file mode 100644 index 00000000..f2f03cb5 --- /dev/null +++ b/src/SubscriptionTypes/Types/SubscriptionType.php @@ -0,0 +1,206 @@ + $state The state of the subscription type. + */ + #[JsonProperty('state')] + private string $state; + + /** + * @var Translation $defaultTranslation + */ + #[JsonProperty('default_translation')] + private Translation $defaultTranslation; + + /** + * @var array $translations An array of translations objects with the localised version of the subscription type in each available locale within your translation settings. + */ + #[JsonProperty('translations'), ArrayType([Translation::class])] + private array $translations; + + /** + * @var value-of $consentType Describes the type of consent. + */ + #[JsonProperty('consent_type')] + private string $consentType; + + /** + * @var array> $contentTypes The message types that this subscription supports - can contain `email` or `sms_message`. + */ + #[JsonProperty('content_types'), ArrayType(['string'])] + private array $contentTypes; + + /** + * @param array{ + * type: 'subscription', + * id: string, + * state: value-of, + * defaultTranslation: Translation, + * translations: array, + * consentType: value-of, + * contentTypes: array>, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->state = $values['state']; + $this->defaultTranslation = $values['defaultTranslation']; + $this->translations = $values['translations']; + $this->consentType = $values['consentType']; + $this->contentTypes = $values['contentTypes']; + } + + /** + * @return 'subscription' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'subscription' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return value-of + */ + public function getState(): string + { + return $this->state; + } + + /** + * @param value-of $value + */ + public function setState(string $value): self + { + $this->state = $value; + return $this; + } + + /** + * @return Translation + */ + public function getDefaultTranslation(): Translation + { + return $this->defaultTranslation; + } + + /** + * @param Translation $value + */ + public function setDefaultTranslation(Translation $value): self + { + $this->defaultTranslation = $value; + return $this; + } + + /** + * @return array + */ + public function getTranslations(): array + { + return $this->translations; + } + + /** + * @param array $value + */ + public function setTranslations(array $value): self + { + $this->translations = $value; + return $this; + } + + /** + * @return value-of + */ + public function getConsentType(): string + { + return $this->consentType; + } + + /** + * @param value-of $value + */ + public function setConsentType(string $value): self + { + $this->consentType = $value; + return $this; + } + + /** + * @return array> + */ + public function getContentTypes(): array + { + return $this->contentTypes; + } + + /** + * @param array> $value + */ + public function setContentTypes(array $value): self + { + $this->contentTypes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/SubscriptionTypes/Types/SubscriptionTypeConsentType.php b/src/SubscriptionTypes/Types/SubscriptionTypeConsentType.php new file mode 100644 index 00000000..32d530fd --- /dev/null +++ b/src/SubscriptionTypes/Types/SubscriptionTypeConsentType.php @@ -0,0 +1,9 @@ +tagId = $values['tagId']; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/FindTagRequest.php b/src/Tags/Requests/FindTagRequest.php new file mode 100644 index 00000000..af911b84 --- /dev/null +++ b/src/Tags/Requests/FindTagRequest.php @@ -0,0 +1,41 @@ +tagId = $values['tagId']; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/TagContactRequest.php b/src/Tags/Requests/TagContactRequest.php new file mode 100644 index 00000000..bb695ce8 --- /dev/null +++ b/src/Tags/Requests/TagContactRequest.php @@ -0,0 +1,67 @@ +contactId = $values['contactId']; + $this->tagId = $values['tagId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/TagConversationRequest.php b/src/Tags/Requests/TagConversationRequest.php new file mode 100644 index 00000000..6165c2f5 --- /dev/null +++ b/src/Tags/Requests/TagConversationRequest.php @@ -0,0 +1,92 @@ +conversationId = $values['conversationId']; + $this->tagId = $values['tagId']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/TagTicketRequest.php b/src/Tags/Requests/TagTicketRequest.php new file mode 100644 index 00000000..c0615820 --- /dev/null +++ b/src/Tags/Requests/TagTicketRequest.php @@ -0,0 +1,92 @@ +ticketId = $values['ticketId']; + $this->tagId = $values['tagId']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/UntagContactRequest.php b/src/Tags/Requests/UntagContactRequest.php new file mode 100644 index 00000000..6b8f9e5f --- /dev/null +++ b/src/Tags/Requests/UntagContactRequest.php @@ -0,0 +1,65 @@ +contactId = $values['contactId']; + $this->tagId = $values['tagId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/UntagConversationRequest.php b/src/Tags/Requests/UntagConversationRequest.php new file mode 100644 index 00000000..04f641e4 --- /dev/null +++ b/src/Tags/Requests/UntagConversationRequest.php @@ -0,0 +1,91 @@ +conversationId = $values['conversationId']; + $this->tagId = $values['tagId']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Tags/Requests/UntagTicketRequest.php b/src/Tags/Requests/UntagTicketRequest.php new file mode 100644 index 00000000..c408b89b --- /dev/null +++ b/src/Tags/Requests/UntagTicketRequest.php @@ -0,0 +1,91 @@ +ticketId = $values['ticketId']; + $this->tagId = $values['tagId']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return string + */ + public function getTagId(): string + { + return $this->tagId; + } + + /** + * @param string $value + */ + public function setTagId(string $value): self + { + $this->tagId = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Tags/TagsClient.php b/src/Tags/TagsClient.php new file mode 100644 index 00000000..befceb3b --- /dev/null +++ b/src/Tags/TagsClient.php @@ -0,0 +1,636 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can tag a specific contact. This will return a tag object for the tag that was added to the contact. + * + * @param TagContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function tagContact(TagContactRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/tags", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove tag from a specific contact. This will return a tag object for the tag that was removed from the contact. + * + * @param UntagContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function untagContact(UntagContactRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/tags/{$request->getTagId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can tag a specific conversation. This will return a tag object for the tag that was added to the conversation. + * + * @param TagConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function tagConversation(TagConversationRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/tags", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove tag from a specific conversation. This will return a tag object for the tag that was removed from the conversation. + * + * @param UntagConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function untagConversation(UntagConversationRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/tags/{$request->getTagId()}", + method: HttpMethod::DELETE, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all tags for a given workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TagList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): TagList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TagList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can use this endpoint to perform the following operations: + * + * **1. Create a new tag:** You can create a new tag by passing in the tag name as specified in "Create or Update Tag Request Payload" described below. + * + * **2. Update an existing tag:** You can update an existing tag by passing the id of the tag as specified in "Create or Update Tag Request Payload" described below. + * + * **3. Tag Companies:** You can tag single company or a list of companies. You can tag a company by passing in the tag name and the company details as specified in "Tag Company Request Payload" described below. Also, if the tag doesn't exist then a new one will be created automatically. + * + * **4. Untag Companies:** You can untag a single company or a list of companies. You can untag a company by passing in the tag id and the company details as specified in "Untag Company Request Payload" described below. + * + * **5. Tag Multiple Users:** You can tag a list of users. You can tag the users by passing in the tag name and the user details as specified in "Tag Users Request Payload" described below. + * + * Each operation will return a tag object. + * + * @param ( + * CreateOrUpdateTagRequest + * |TagCompanyRequest + * |UntagCompanyRequest + * |TagMultipleUsersRequest + * ) $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateOrUpdateTagRequest|TagCompanyRequest|UntagCompanyRequest|TagMultipleUsersRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags", + method: HttpMethod::POST, + body: JsonSerializer::serializeUnion($request, new Union(CreateOrUpdateTagRequest::class, TagCompanyRequest::class, UntagCompanyRequest::class, TagMultipleUsersRequest::class)), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of tags that are on the workspace by their id. + * This will return a tag object. + * + * @param FindTagRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindTagRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags/{$request->getTagId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete the details of tags that are on the workspace by passing in the id. + * + * @param DeleteTagRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function delete(DeleteTagRequest $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags/{$request->getTagId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can tag a specific ticket. This will return a tag object for the tag that was added to the ticket. + * + * @param TagTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function tagTicket(TagTicketRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}/tags", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove tag from a specific ticket. This will return a tag object for the tag that was removed from the ticket. + * + * @param UntagTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function untagTicket(UntagTicketRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}/tags/{$request->getTagId()}", + method: HttpMethod::DELETE, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Tags/Types/Tag.php b/src/Tags/Types/Tag.php new file mode 100644 index 00000000..f85996a0 --- /dev/null +++ b/src/Tags/Types/Tag.php @@ -0,0 +1,155 @@ +type = $values['type']; + $this->id = $values['id']; + $this->name = $values['name']; + $this->appliedAt = $values['appliedAt'] ?? null; + $this->appliedBy = $values['appliedBy'] ?? null; + } + + /** + * @return 'tag' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'tag' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAppliedAt(): ?int + { + return $this->appliedAt; + } + + /** + * @param ?int $value + */ + public function setAppliedAt(?int $value = null): self + { + $this->appliedAt = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getAppliedBy(): ?Reference + { + return $this->appliedBy; + } + + /** + * @param ?Reference $value + */ + public function setAppliedBy(?Reference $value = null): self + { + $this->appliedBy = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Teams/Requests/FindTeamRequest.php b/src/Teams/Requests/FindTeamRequest.php new file mode 100644 index 00000000..98e8e142 --- /dev/null +++ b/src/Teams/Requests/FindTeamRequest.php @@ -0,0 +1,41 @@ +teamId = $values['teamId']; + } + + /** + * @return string + */ + public function getTeamId(): string + { + return $this->teamId; + } + + /** + * @param string $value + */ + public function setTeamId(string $value): self + { + $this->teamId = $value; + return $this; + } +} diff --git a/src/Teams/TeamsClient.php b/src/Teams/TeamsClient.php new file mode 100644 index 00000000..29e949dd --- /dev/null +++ b/src/Teams/TeamsClient.php @@ -0,0 +1,163 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * This will return a list of team objects for the App. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TeamList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): TeamList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "teams", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TeamList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single team, containing an array of admins that belong to this team. + * + * @param FindTeamRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Team + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindTeamRequest $request, ?array $options = null): Team + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "teams/{$request->getTeamId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Team::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Teams/Types/Team.php b/src/Teams/Types/Team.php new file mode 100644 index 00000000..7c4dd314 --- /dev/null +++ b/src/Teams/Types/Team.php @@ -0,0 +1,156 @@ + $adminIds The list of admin IDs that are a part of the team. + */ + #[JsonProperty('admin_ids'), ArrayType(['integer'])] + private array $adminIds; + + /** + * @var ?AdminPriorityLevel $adminPriorityLevel + */ + #[JsonProperty('admin_priority_level')] + private ?AdminPriorityLevel $adminPriorityLevel; + + /** + * @param array{ + * type: 'team', + * id: string, + * name: string, + * adminIds: array, + * adminPriorityLevel?: ?AdminPriorityLevel, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->name = $values['name']; + $this->adminIds = $values['adminIds']; + $this->adminPriorityLevel = $values['adminPriorityLevel'] ?? null; + } + + /** + * @return 'team' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'team' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getAdminIds(): array + { + return $this->adminIds; + } + + /** + * @param array $value + */ + public function setAdminIds(array $value): self + { + $this->adminIds = $value; + return $this; + } + + /** + * @return ?AdminPriorityLevel + */ + public function getAdminPriorityLevel(): ?AdminPriorityLevel + { + return $this->adminPriorityLevel; + } + + /** + * @param ?AdminPriorityLevel $value + */ + public function setAdminPriorityLevel(?AdminPriorityLevel $value = null): self + { + $this->adminPriorityLevel = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/TicketTypes/Attributes/AttributesClient.php b/src/TicketTypes/Attributes/AttributesClient.php new file mode 100644 index 00000000..4ce51555 --- /dev/null +++ b/src/TicketTypes/Attributes/AttributesClient.php @@ -0,0 +1,166 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can create a new attribute for a ticket type. + * + * @param CreateTicketTypeAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketTypeAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateTicketTypeAttributeRequest $request, ?array $options = null): TicketTypeAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getTicketTypeId()}/attributes", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketTypeAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update an existing attribute for a ticket type. + * + * @param UpdateTicketTypeAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketTypeAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateTicketTypeAttributeRequest $request, ?array $options = null): TicketTypeAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getTicketTypeId()}/attributes/{$request->getAttributeId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketTypeAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/TicketTypes/Attributes/Requests/CreateTicketTypeAttributeRequest.php b/src/TicketTypes/Attributes/Requests/CreateTicketTypeAttributeRequest.php new file mode 100644 index 00000000..fb99a5d4 --- /dev/null +++ b/src/TicketTypes/Attributes/Requests/CreateTicketTypeAttributeRequest.php @@ -0,0 +1,293 @@ + $dataType The data type of the attribute + */ + #[JsonProperty('data_type')] + private string $dataType; + + /** + * @var ?bool $requiredToCreate Whether the attribute is required to be filled in when teammates are creating the ticket in Inbox. + */ + #[JsonProperty('required_to_create')] + private ?bool $requiredToCreate; + + /** + * @var ?bool $requiredToCreateForContacts Whether the attribute is required to be filled in when contacts are creating the ticket in Messenger. + */ + #[JsonProperty('required_to_create_for_contacts')] + private ?bool $requiredToCreateForContacts; + + /** + * @var ?bool $visibleOnCreate Whether the attribute is visible to teammates when creating a ticket in Inbox. + */ + #[JsonProperty('visible_on_create')] + private ?bool $visibleOnCreate; + + /** + * @var ?bool $visibleToContacts Whether the attribute is visible to contacts when creating a ticket in Messenger. + */ + #[JsonProperty('visible_to_contacts')] + private ?bool $visibleToContacts; + + /** + * @var ?bool $multiline Whether the attribute allows multiple lines of text (only applicable to string attributes) + */ + #[JsonProperty('multiline')] + private ?bool $multiline; + + /** + * @var ?string $listItems A comma delimited list of items for the attribute value (only applicable to list attributes) + */ + #[JsonProperty('list_items')] + private ?string $listItems; + + /** + * @var ?bool $allowMultipleValues Whether the attribute allows multiple files to be attached to it (only applicable to file attributes) + */ + #[JsonProperty('allow_multiple_values')] + private ?bool $allowMultipleValues; + + /** + * @param array{ + * ticketTypeId: string, + * name: string, + * description: string, + * dataType: value-of, + * requiredToCreate?: ?bool, + * requiredToCreateForContacts?: ?bool, + * visibleOnCreate?: ?bool, + * visibleToContacts?: ?bool, + * multiline?: ?bool, + * listItems?: ?string, + * allowMultipleValues?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->ticketTypeId = $values['ticketTypeId']; + $this->name = $values['name']; + $this->description = $values['description']; + $this->dataType = $values['dataType']; + $this->requiredToCreate = $values['requiredToCreate'] ?? null; + $this->requiredToCreateForContacts = $values['requiredToCreateForContacts'] ?? null; + $this->visibleOnCreate = $values['visibleOnCreate'] ?? null; + $this->visibleToContacts = $values['visibleToContacts'] ?? null; + $this->multiline = $values['multiline'] ?? null; + $this->listItems = $values['listItems'] ?? null; + $this->allowMultipleValues = $values['allowMultipleValues'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return value-of + */ + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param value-of $value + */ + public function setDataType(string $value): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreate(): ?bool + { + return $this->requiredToCreate; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreate(?bool $value = null): self + { + $this->requiredToCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreateForContacts(): ?bool + { + return $this->requiredToCreateForContacts; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreateForContacts(?bool $value = null): self + { + $this->requiredToCreateForContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleOnCreate(): ?bool + { + return $this->visibleOnCreate; + } + + /** + * @param ?bool $value + */ + public function setVisibleOnCreate(?bool $value = null): self + { + $this->visibleOnCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleToContacts(): ?bool + { + return $this->visibleToContacts; + } + + /** + * @param ?bool $value + */ + public function setVisibleToContacts(?bool $value = null): self + { + $this->visibleToContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMultiline(): ?bool + { + return $this->multiline; + } + + /** + * @param ?bool $value + */ + public function setMultiline(?bool $value = null): self + { + $this->multiline = $value; + return $this; + } + + /** + * @return ?string + */ + public function getListItems(): ?string + { + return $this->listItems; + } + + /** + * @param ?string $value + */ + public function setListItems(?string $value = null): self + { + $this->listItems = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAllowMultipleValues(): ?bool + { + return $this->allowMultipleValues; + } + + /** + * @param ?bool $value + */ + public function setAllowMultipleValues(?bool $value = null): self + { + $this->allowMultipleValues = $value; + return $this; + } +} diff --git a/src/TicketTypes/Attributes/Requests/UpdateTicketTypeAttributeRequest.php b/src/TicketTypes/Attributes/Requests/UpdateTicketTypeAttributeRequest.php new file mode 100644 index 00000000..d4741e5a --- /dev/null +++ b/src/TicketTypes/Attributes/Requests/UpdateTicketTypeAttributeRequest.php @@ -0,0 +1,316 @@ +ticketTypeId = $values['ticketTypeId']; + $this->attributeId = $values['attributeId']; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->requiredToCreate = $values['requiredToCreate'] ?? null; + $this->requiredToCreateForContacts = $values['requiredToCreateForContacts'] ?? null; + $this->visibleOnCreate = $values['visibleOnCreate'] ?? null; + $this->visibleToContacts = $values['visibleToContacts'] ?? null; + $this->multiline = $values['multiline'] ?? null; + $this->listItems = $values['listItems'] ?? null; + $this->allowMultipleValues = $values['allowMultipleValues'] ?? null; + $this->archived = $values['archived'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return string + */ + public function getAttributeId(): string + { + return $this->attributeId; + } + + /** + * @param string $value + */ + public function setAttributeId(string $value): self + { + $this->attributeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreate(): ?bool + { + return $this->requiredToCreate; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreate(?bool $value = null): self + { + $this->requiredToCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreateForContacts(): ?bool + { + return $this->requiredToCreateForContacts; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreateForContacts(?bool $value = null): self + { + $this->requiredToCreateForContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleOnCreate(): ?bool + { + return $this->visibleOnCreate; + } + + /** + * @param ?bool $value + */ + public function setVisibleOnCreate(?bool $value = null): self + { + $this->visibleOnCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleToContacts(): ?bool + { + return $this->visibleToContacts; + } + + /** + * @param ?bool $value + */ + public function setVisibleToContacts(?bool $value = null): self + { + $this->visibleToContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMultiline(): ?bool + { + return $this->multiline; + } + + /** + * @param ?bool $value + */ + public function setMultiline(?bool $value = null): self + { + $this->multiline = $value; + return $this; + } + + /** + * @return ?string + */ + public function getListItems(): ?string + { + return $this->listItems; + } + + /** + * @param ?string $value + */ + public function setListItems(?string $value = null): self + { + $this->listItems = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAllowMultipleValues(): ?bool + { + return $this->allowMultipleValues; + } + + /** + * @param ?bool $value + */ + public function setAllowMultipleValues(?bool $value = null): self + { + $this->allowMultipleValues = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } +} diff --git a/src/TicketTypes/Attributes/Types/CreateTicketTypeAttributeRequestDataType.php b/src/TicketTypes/Attributes/Types/CreateTicketTypeAttributeRequestDataType.php new file mode 100644 index 00000000..bb55331b --- /dev/null +++ b/src/TicketTypes/Attributes/Types/CreateTicketTypeAttributeRequestDataType.php @@ -0,0 +1,14 @@ + $category Category of the Ticket Type. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?string $icon The icon of the ticket type. + */ + #[JsonProperty('icon')] + private ?string $icon; + + /** + * @var ?bool $isInternal Whether the tickets associated with this ticket type are intended for internal use only or will be shared with customers. This is currently a limited attribute. + */ + #[JsonProperty('is_internal')] + private ?bool $isInternal; + + /** + * @param array{ + * name: string, + * description?: ?string, + * category?: ?value-of, + * icon?: ?string, + * isInternal?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->description = $values['description'] ?? null; + $this->category = $values['category'] ?? null; + $this->icon = $values['icon'] ?? null; + $this->isInternal = $values['isInternal'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param ?string $value + */ + public function setIcon(?string $value = null): self + { + $this->icon = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsInternal(): ?bool + { + return $this->isInternal; + } + + /** + * @param ?bool $value + */ + public function setIsInternal(?bool $value = null): self + { + $this->isInternal = $value; + return $this; + } +} diff --git a/src/TicketTypes/Requests/FindTicketTypeRequest.php b/src/TicketTypes/Requests/FindTicketTypeRequest.php new file mode 100644 index 00000000..003ab1d0 --- /dev/null +++ b/src/TicketTypes/Requests/FindTicketTypeRequest.php @@ -0,0 +1,41 @@ +ticketTypeId = $values['ticketTypeId']; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } +} diff --git a/src/TicketTypes/Requests/UpdateTicketTypeRequest.php b/src/TicketTypes/Requests/UpdateTicketTypeRequest.php new file mode 100644 index 00000000..d6d02f2d --- /dev/null +++ b/src/TicketTypes/Requests/UpdateTicketTypeRequest.php @@ -0,0 +1,193 @@ + $category Category of the Ticket Type. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?string $icon The icon of the ticket type. + */ + #[JsonProperty('icon')] + private ?string $icon; + + /** + * @var ?bool $archived The archived status of the ticket type. + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?bool $isInternal Whether the tickets associated with this ticket type are intended for internal use only or will be shared with customers. This is currently a limited attribute. + */ + #[JsonProperty('is_internal')] + private ?bool $isInternal; + + /** + * @param array{ + * ticketTypeId: string, + * name?: ?string, + * description?: ?string, + * category?: ?value-of, + * icon?: ?string, + * archived?: ?bool, + * isInternal?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->ticketTypeId = $values['ticketTypeId']; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->category = $values['category'] ?? null; + $this->icon = $values['icon'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->isInternal = $values['isInternal'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param ?string $value + */ + public function setIcon(?string $value = null): self + { + $this->icon = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsInternal(): ?bool + { + return $this->isInternal; + } + + /** + * @param ?bool $value + */ + public function setIsInternal(?bool $value = null): self + { + $this->isInternal = $value; + return $this; + } +} diff --git a/src/TicketTypes/TicketTypesClient.php b/src/TicketTypes/TicketTypesClient.php new file mode 100644 index 00000000..8b179fa1 --- /dev/null +++ b/src/TicketTypes/TicketTypesClient.php @@ -0,0 +1,293 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + $this->attributes = new AttributesClient($this->client, $this->options); + } + + /** + * You can get a list of all ticket types for a workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketTypeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function list(?array $options = null): TicketTypeList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketTypeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new ticket type. + * > 📘 Creating ticket types. + * > + * > Every ticket type will be created with two default attributes: _default_title_ and _default_description_. + * > For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/) + * + * @param CreateTicketTypeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketType + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateTicketTypeRequest $request, ?array $options = null): TicketType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single ticket type. + * + * @param FindTicketTypeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketType + * @throws IntercomException + * @throws IntercomApiException + */ + public function get(FindTicketTypeRequest $request, ?array $options = null): TicketType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getTicketTypeId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can update a ticket type. + * + * > 📘 Updating a ticket type. + * > + * > For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/) + * + * @param UpdateTicketTypeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketType + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateTicketTypeRequest $request, ?array $options = null): TicketType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getTicketTypeId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/TicketTypes/Types/CreateTicketTypeRequestCategory.php b/src/TicketTypes/Types/CreateTicketTypeRequestCategory.php new file mode 100644 index 00000000..d5c81599 --- /dev/null +++ b/src/TicketTypes/Types/CreateTicketTypeRequestCategory.php @@ -0,0 +1,10 @@ +ticketId = $values['ticketId']; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } +} diff --git a/src/Tickets/Requests/ReplyToTicketRequest.php b/src/Tickets/Requests/ReplyToTicketRequest.php new file mode 100644 index 00000000..c001a6ef --- /dev/null +++ b/src/Tickets/Requests/ReplyToTicketRequest.php @@ -0,0 +1,89 @@ +ticketId = $values['ticketId']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return ( + * ContactReplyTicketIntercomUserIdRequest + * |ContactReplyTicketUserIdRequest + * |ContactReplyTicketEmailRequest + * |AdminReplyTicketRequest + * ) + */ + public function getBody(): ContactReplyTicketIntercomUserIdRequest|ContactReplyTicketUserIdRequest|ContactReplyTicketEmailRequest|AdminReplyTicketRequest + { + return $this->body; + } + + /** + * @param ( + * ContactReplyTicketIntercomUserIdRequest + * |ContactReplyTicketUserIdRequest + * |ContactReplyTicketEmailRequest + * |AdminReplyTicketRequest + * ) $value + */ + public function setBody(ContactReplyTicketIntercomUserIdRequest|ContactReplyTicketUserIdRequest|ContactReplyTicketEmailRequest|AdminReplyTicketRequest $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Tickets/Requests/UpdateTicketRequest.php b/src/Tickets/Requests/UpdateTicketRequest.php new file mode 100644 index 00000000..ee986eea --- /dev/null +++ b/src/Tickets/Requests/UpdateTicketRequest.php @@ -0,0 +1,195 @@ + $ticketAttributes The attributes set on the ticket. + */ + #[JsonProperty('ticket_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $ticketAttributes; + + /** + * @var ?value-of $state The state of the ticket. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?bool $open Specify if a ticket is open. Set to false to close a ticket. Closing a ticket will also unsnooze it. + */ + #[JsonProperty('open')] + private ?bool $open; + + /** + * @var ?bool $isShared Specify whether the ticket is visible to users. + */ + #[JsonProperty('is_shared')] + private ?bool $isShared; + + /** + * @var ?int $snoozedUntil The time you want the ticket to reopen. + */ + #[JsonProperty('snoozed_until')] + private ?int $snoozedUntil; + + /** + * @var ?UpdateTicketRequestAssignment $assignment + */ + #[JsonProperty('assignment')] + private ?UpdateTicketRequestAssignment $assignment; + + /** + * @param array{ + * ticketId: string, + * ticketAttributes?: ?array, + * state?: ?value-of, + * open?: ?bool, + * isShared?: ?bool, + * snoozedUntil?: ?int, + * assignment?: ?UpdateTicketRequestAssignment, + * } $values + */ + public function __construct( + array $values, + ) { + $this->ticketId = $values['ticketId']; + $this->ticketAttributes = $values['ticketAttributes'] ?? null; + $this->state = $values['state'] ?? null; + $this->open = $values['open'] ?? null; + $this->isShared = $values['isShared'] ?? null; + $this->snoozedUntil = $values['snoozedUntil'] ?? null; + $this->assignment = $values['assignment'] ?? null; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTicketAttributes(): ?array + { + return $this->ticketAttributes; + } + + /** + * @param ?array $value + */ + public function setTicketAttributes(?array $value = null): self + { + $this->ticketAttributes = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getOpen(): ?bool + { + return $this->open; + } + + /** + * @param ?bool $value + */ + public function setOpen(?bool $value = null): self + { + $this->open = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsShared(): ?bool + { + return $this->isShared; + } + + /** + * @param ?bool $value + */ + public function setIsShared(?bool $value = null): self + { + $this->isShared = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSnoozedUntil(): ?int + { + return $this->snoozedUntil; + } + + /** + * @param ?int $value + */ + public function setSnoozedUntil(?int $value = null): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return ?UpdateTicketRequestAssignment + */ + public function getAssignment(): ?UpdateTicketRequestAssignment + { + return $this->assignment; + } + + /** + * @param ?UpdateTicketRequestAssignment $value + */ + public function setAssignment(?UpdateTicketRequestAssignment $value = null): self + { + $this->assignment = $value; + return $this; + } +} diff --git a/src/Tickets/TicketsClient.php b/src/Tickets/TicketsClient.php new file mode 100644 index 00000000..7b740ead --- /dev/null +++ b/src/Tickets/TicketsClient.php @@ -0,0 +1,490 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can reply to a ticket with a message from an admin or on behalf of a contact, or with a note for admins. + * + * @param ReplyToTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketReply + * @throws IntercomException + * @throws IntercomApiException + */ + public function reply(ReplyToTicketRequest $request, ?array $options = null): TicketReply + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}/reply", + method: HttpMethod::POST, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketReply::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new ticket. + * + * @param CreateTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function create(CreateTicketRequest $request, ?array $options = null): Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single ticket. + * + * @param FindTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function get(FindTicketRequest $request, ?array $options = null): Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update a ticket. + * + * @param UpdateTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateTicketRequest $request, ?array $options = null): Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple tickets by the value of their attributes in order to fetch exactly which ones you want. + * + * To search for tickets, you send a `POST` request to `https://api.intercom.io/tickets/search`. + * + * This will accept a query object in the body which will define your filters. + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiples there can be: + * - There's a limit of max 2 nested filters + * - There's a limit of max 15 filters for each AND or OR group + * + * ### Accepted Fields + * + * Most keys listed as part of the Ticket model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foobar"`). + * + * | Field | Type | + * | :---------------------------------------- | :--------------------------------------------------------------------------------------- | + * | id | String | + * | created_at | Date (UNIX timestamp) | + * | updated_at | Date (UNIX timestamp) | + * | _default_title_ | String | + * | _default_description_ | String | + * | category | String | + * | ticket_type_id | String | + * | contact_ids | String | + * | teammate_ids | String | + * | admin_assignee_id | String | + * | team_assignee_id | String | + * | open | Boolean | + * | state | String | + * | snoozed_until | Date (UNIX timestamp) | + * | ticket_attribute.{id} | String or Boolean or Date (UNIX timestamp) or Float or Integer | + * + * ### Accepted Operators + * + * {% admonition type="info" name="Searching based on `created_at`" %} + * You may use the `<=` or `>=` operators to search by `created_at`. + * {% /admonition %} + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :----------------------------- | :----------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In Shortcut for `OR` queries Values most be in Array | + * | NIN | All | Not In Shortcut for `OR !` queries Values must be in Array | + * | > | Integer Date (UNIX Timestamp) | Greater (or equal) than | + * | < | Integer Date (UNIX Timestamp) | Lower (or equal) than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Pager + */ + public function search(SearchRequest $request, ?array $options = null): Pager + { + return new CursorPager( + request: $request, + getNextPage: fn (SearchRequest $request) => $this->_search($request, $options), + setCursor: function (SearchRequest $request, ?string $cursor) { + PaginationHelper::setDeep($request, ["pagination", "startingAfter"], $cursor); + }, + /* @phpstan-ignore-next-line */ + getNextCursor: fn (TicketList $response) => $response?->getPages()?->getNext()?->getStartingAfter() ?? null, + /* @phpstan-ignore-next-line */ + getItems: fn (TicketList $response) => $response?->getTickets() ?? [], + ); + } + + /** + * You can search for multiple tickets by the value of their attributes in order to fetch exactly which ones you want. + * + * To search for tickets, you send a `POST` request to `https://api.intercom.io/tickets/search`. + * + * This will accept a query object in the body which will define your filters. + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiples there can be: + * - There's a limit of max 2 nested filters + * - There's a limit of max 15 filters for each AND or OR group + * + * ### Accepted Fields + * + * Most keys listed as part of the Ticket model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foobar"`). + * + * | Field | Type | + * | :---------------------------------------- | :--------------------------------------------------------------------------------------- | + * | id | String | + * | created_at | Date (UNIX timestamp) | + * | updated_at | Date (UNIX timestamp) | + * | _default_title_ | String | + * | _default_description_ | String | + * | category | String | + * | ticket_type_id | String | + * | contact_ids | String | + * | teammate_ids | String | + * | admin_assignee_id | String | + * | team_assignee_id | String | + * | open | Boolean | + * | state | String | + * | snoozed_until | Date (UNIX timestamp) | + * | ticket_attribute.{id} | String or Boolean or Date (UNIX timestamp) or Float or Integer | + * + * ### Accepted Operators + * + * {% admonition type="info" name="Searching based on `created_at`" %} + * You may use the `<=` or `>=` operators to search by `created_at`. + * {% /admonition %} + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :----------------------------- | :----------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In Shortcut for `OR` queries Values most be in Array | + * | NIN | All | Not In Shortcut for `OR !` queries Values must be in Array | + * | > | Integer Date (UNIX Timestamp) | Greater (or equal) than | + * | < | Integer Date (UNIX Timestamp) | Lower (or equal) than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketList + * @throws IntercomException + * @throws IntercomApiException + */ + private function _search(SearchRequest $request, ?array $options = null): TicketList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/search", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Tickets/Types/Ticket.php b/src/Tickets/Types/Ticket.php new file mode 100644 index 00000000..4e3cdf89 --- /dev/null +++ b/src/Tickets/Types/Ticket.php @@ -0,0 +1,507 @@ + $category Category of the Ticket. + */ + #[JsonProperty('category')] + private string $category; + + /** + * @var array $ticketAttributes + */ + #[JsonProperty('ticket_attributes'), ArrayType(['string' => 'mixed'])] + private array $ticketAttributes; + + /** + * @var value-of $ticketState The state the ticket is currently in + */ + #[JsonProperty('ticket_state')] + private string $ticketState; + + /** + * @var TicketType $ticketType + */ + #[JsonProperty('ticket_type')] + private TicketType $ticketType; + + /** + * @var TicketContacts $contacts + */ + #[JsonProperty('contacts')] + private TicketContacts $contacts; + + /** + * @var ?string $adminAssigneeId The id representing the admin assigned to the ticket. + */ + #[JsonProperty('admin_assignee_id')] + private ?string $adminAssigneeId; + + /** + * @var ?string $teamAssigneeId The id representing the team assigned to the ticket. + */ + #[JsonProperty('team_assignee_id')] + private ?string $teamAssigneeId; + + /** + * @var ?int $createdAt The time the ticket was created as a UTC Unix timestamp. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The last time the ticket was updated as a UTC Unix timestamp. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?bool $open Whether or not the ticket is open. If false, the ticket is closed. + */ + #[JsonProperty('open')] + private ?bool $open; + + /** + * @var ?int $snoozedUntil The time the ticket will be snoozed until as a UTC Unix timestamp. If null, the ticket is not currently snoozed. + */ + #[JsonProperty('snoozed_until')] + private ?int $snoozedUntil; + + /** + * @var ?LinkedObjectList $linkedObjects + */ + #[JsonProperty('linked_objects')] + private ?LinkedObjectList $linkedObjects; + + /** + * @var ?TicketParts $ticketParts + */ + #[JsonProperty('ticket_parts')] + private ?TicketParts $ticketParts; + + /** + * @var ?bool $isShared Whether or not the ticket is shared with the customer. + */ + #[JsonProperty('is_shared')] + private ?bool $isShared; + + /** + * @var ?string $ticketStateInternalLabel The state the ticket is currently in, in a human readable form - visible in Intercom + */ + #[JsonProperty('ticket_state_internal_label')] + private ?string $ticketStateInternalLabel; + + /** + * @var ?string $ticketStateExternalLabel The state the ticket is currently in, in a human readable form - visible to customers, in the messenger, email and tickets portal. + */ + #[JsonProperty('ticket_state_external_label')] + private ?string $ticketStateExternalLabel; + + /** + * @param array{ + * type: 'ticket', + * id: string, + * ticketId: string, + * category: value-of, + * ticketAttributes: array, + * ticketState: value-of, + * ticketType: TicketType, + * contacts: TicketContacts, + * adminAssigneeId?: ?string, + * teamAssigneeId?: ?string, + * createdAt?: ?int, + * updatedAt?: ?int, + * open?: ?bool, + * snoozedUntil?: ?int, + * linkedObjects?: ?LinkedObjectList, + * ticketParts?: ?TicketParts, + * isShared?: ?bool, + * ticketStateInternalLabel?: ?string, + * ticketStateExternalLabel?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->ticketId = $values['ticketId']; + $this->category = $values['category']; + $this->ticketAttributes = $values['ticketAttributes']; + $this->ticketState = $values['ticketState']; + $this->ticketType = $values['ticketType']; + $this->contacts = $values['contacts']; + $this->adminAssigneeId = $values['adminAssigneeId'] ?? null; + $this->teamAssigneeId = $values['teamAssigneeId'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->open = $values['open'] ?? null; + $this->snoozedUntil = $values['snoozedUntil'] ?? null; + $this->linkedObjects = $values['linkedObjects'] ?? null; + $this->ticketParts = $values['ticketParts'] ?? null; + $this->isShared = $values['isShared'] ?? null; + $this->ticketStateInternalLabel = $values['ticketStateInternalLabel'] ?? null; + $this->ticketStateExternalLabel = $values['ticketStateExternalLabel'] ?? null; + } + + /** + * @return 'ticket' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return value-of + */ + public function getCategory(): string + { + return $this->category; + } + + /** + * @param value-of $value + */ + public function setCategory(string $value): self + { + $this->category = $value; + return $this; + } + + /** + * @return array + */ + public function getTicketAttributes(): array + { + return $this->ticketAttributes; + } + + /** + * @param array $value + */ + public function setTicketAttributes(array $value): self + { + $this->ticketAttributes = $value; + return $this; + } + + /** + * @return value-of + */ + public function getTicketState(): string + { + return $this->ticketState; + } + + /** + * @param value-of $value + */ + public function setTicketState(string $value): self + { + $this->ticketState = $value; + return $this; + } + + /** + * @return TicketType + */ + public function getTicketType(): TicketType + { + return $this->ticketType; + } + + /** + * @param TicketType $value + */ + public function setTicketType(TicketType $value): self + { + $this->ticketType = $value; + return $this; + } + + /** + * @return TicketContacts + */ + public function getContacts(): TicketContacts + { + return $this->contacts; + } + + /** + * @param TicketContacts $value + */ + public function setContacts(TicketContacts $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminAssigneeId(): ?string + { + return $this->adminAssigneeId; + } + + /** + * @param ?string $value + */ + public function setAdminAssigneeId(?string $value = null): self + { + $this->adminAssigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTeamAssigneeId(): ?string + { + return $this->teamAssigneeId; + } + + /** + * @param ?string $value + */ + public function setTeamAssigneeId(?string $value = null): self + { + $this->teamAssigneeId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getOpen(): ?bool + { + return $this->open; + } + + /** + * @param ?bool $value + */ + public function setOpen(?bool $value = null): self + { + $this->open = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSnoozedUntil(): ?int + { + return $this->snoozedUntil; + } + + /** + * @param ?int $value + */ + public function setSnoozedUntil(?int $value = null): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return ?LinkedObjectList + */ + public function getLinkedObjects(): ?LinkedObjectList + { + return $this->linkedObjects; + } + + /** + * @param ?LinkedObjectList $value + */ + public function setLinkedObjects(?LinkedObjectList $value = null): self + { + $this->linkedObjects = $value; + return $this; + } + + /** + * @return ?TicketParts + */ + public function getTicketParts(): ?TicketParts + { + return $this->ticketParts; + } + + /** + * @param ?TicketParts $value + */ + public function setTicketParts(?TicketParts $value = null): self + { + $this->ticketParts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsShared(): ?bool + { + return $this->isShared; + } + + /** + * @param ?bool $value + */ + public function setIsShared(?bool $value = null): self + { + $this->isShared = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTicketStateInternalLabel(): ?string + { + return $this->ticketStateInternalLabel; + } + + /** + * @param ?string $value + */ + public function setTicketStateInternalLabel(?string $value = null): self + { + $this->ticketStateInternalLabel = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTicketStateExternalLabel(): ?string + { + return $this->ticketStateExternalLabel; + } + + /** + * @param ?string $value + */ + public function setTicketStateExternalLabel(?string $value = null): self + { + $this->ticketStateExternalLabel = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Tickets/Types/TicketCategory.php b/src/Tickets/Types/TicketCategory.php new file mode 100644 index 00000000..ceb58afe --- /dev/null +++ b/src/Tickets/Types/TicketCategory.php @@ -0,0 +1,10 @@ + $contacts The list of contacts affected by this ticket. + */ + #[JsonProperty('contacts'), ArrayType([ContactReference::class])] + private array $contacts; + + /** + * @param array{ + * type: 'contact.list', + * contacts: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->contacts = $values['contacts']; + } + + /** + * @return 'contact.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'contact.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getContacts(): array + { + return $this->contacts; + } + + /** + * @param array $value + */ + public function setContacts(array $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Tickets/Types/TicketPart.php b/src/Tickets/Types/TicketPart.php new file mode 100644 index 00000000..cdccddd5 --- /dev/null +++ b/src/Tickets/Types/TicketPart.php @@ -0,0 +1,358 @@ + $previousTicketState The previous state of the ticket. + */ + #[JsonProperty('previous_ticket_state')] + private ?string $previousTicketState; + + /** + * @var value-of $ticketState The state of the ticket. + */ + #[JsonProperty('ticket_state')] + private string $ticketState; + + /** + * @var int $createdAt The time the ticket part was created. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var ?int $updatedAt The last time the ticket part was updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?Reference $assignedTo The id of the admin that was assigned the ticket by this ticket_part (null if there has been no change in assignment.) + */ + #[JsonProperty('assigned_to')] + private ?Reference $assignedTo; + + /** + * @var ?TicketPartAuthor $author + */ + #[JsonProperty('author')] + private ?TicketPartAuthor $author; + + /** + * @var ?array $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?string $externalId The external id of the ticket part + */ + #[JsonProperty('external_id')] + private ?string $externalId; + + /** + * @var ?bool $redacted Whether or not the ticket part has been redacted. + */ + #[JsonProperty('redacted')] + private ?bool $redacted; + + /** + * @param array{ + * type: 'ticket_part', + * id: string, + * partType: string, + * ticketState: value-of, + * createdAt: int, + * body?: ?string, + * previousTicketState?: ?value-of, + * updatedAt?: ?int, + * assignedTo?: ?Reference, + * author?: ?TicketPartAuthor, + * attachments?: ?array, + * externalId?: ?string, + * redacted?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->partType = $values['partType']; + $this->body = $values['body'] ?? null; + $this->previousTicketState = $values['previousTicketState'] ?? null; + $this->ticketState = $values['ticketState']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->assignedTo = $values['assignedTo'] ?? null; + $this->author = $values['author'] ?? null; + $this->attachments = $values['attachments'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->redacted = $values['redacted'] ?? null; + } + + /** + * @return 'ticket_part' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_part' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getPartType(): string + { + return $this->partType; + } + + /** + * @param string $value + */ + public function setPartType(string $value): self + { + $this->partType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getPreviousTicketState(): ?string + { + return $this->previousTicketState; + } + + /** + * @param ?value-of $value + */ + public function setPreviousTicketState(?string $value = null): self + { + $this->previousTicketState = $value; + return $this; + } + + /** + * @return value-of + */ + public function getTicketState(): string + { + return $this->ticketState; + } + + /** + * @param value-of $value + */ + public function setTicketState(string $value): self + { + $this->ticketState = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getAssignedTo(): ?Reference + { + return $this->assignedTo; + } + + /** + * @param ?Reference $value + */ + public function setAssignedTo(?Reference $value = null): self + { + $this->assignedTo = $value; + return $this; + } + + /** + * @return ?TicketPartAuthor + */ + public function getAuthor(): ?TicketPartAuthor + { + return $this->author; + } + + /** + * @param ?TicketPartAuthor $value + */ + public function setAuthor(?TicketPartAuthor $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRedacted(): ?bool + { + return $this->redacted; + } + + /** + * @param ?bool $value + */ + public function setRedacted(?bool $value = null): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Tickets/Types/TicketPartPreviousTicketState.php b/src/Tickets/Types/TicketPartPreviousTicketState.php new file mode 100644 index 00000000..7772652b --- /dev/null +++ b/src/Tickets/Types/TicketPartPreviousTicketState.php @@ -0,0 +1,11 @@ + $category Category of the Ticket Type. + */ + #[JsonProperty('category')] + private string $category; + + /** + * @var string $name The name of the ticket type + */ + #[JsonProperty('name')] + private string $name; + + /** + * @var string $description The description of the ticket type + */ + #[JsonProperty('description')] + private string $description; + + /** + * @var string $icon The icon of the ticket type + */ + #[JsonProperty('icon')] + private string $icon; + + /** + * @var string $workspaceId The id of the workspace that the ticket type belongs to. + */ + #[JsonProperty('workspace_id')] + private string $workspaceId; + + /** + * @var TicketTypeAttributeList $ticketTypeAttributes + */ + #[JsonProperty('ticket_type_attributes')] + private TicketTypeAttributeList $ticketTypeAttributes; + + /** + * @var bool $archived Whether the ticket type is archived or not. + */ + #[JsonProperty('archived')] + private bool $archived; + + /** + * @var int $createdAt The date and time the ticket type was created. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var ?int $updatedAt The date and time the ticket type was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @param array{ + * type: 'ticket_type', + * id: string, + * category: value-of, + * name: string, + * description: string, + * icon: string, + * workspaceId: string, + * ticketTypeAttributes: TicketTypeAttributeList, + * archived: bool, + * createdAt: int, + * updatedAt?: ?int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->category = $values['category']; + $this->name = $values['name']; + $this->description = $values['description']; + $this->icon = $values['icon']; + $this->workspaceId = $values['workspaceId']; + $this->ticketTypeAttributes = $values['ticketTypeAttributes']; + $this->archived = $values['archived']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return 'ticket_type' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_type' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return value-of + */ + public function getCategory(): string + { + return $this->category; + } + + /** + * @param value-of $value + */ + public function setCategory(string $value): self + { + $this->category = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function getIcon(): string + { + return $this->icon; + } + + /** + * @param string $value + */ + public function setIcon(string $value): self + { + $this->icon = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return TicketTypeAttributeList + */ + public function getTicketTypeAttributes(): TicketTypeAttributeList + { + return $this->ticketTypeAttributes; + } + + /** + * @param TicketTypeAttributeList $value + */ + public function setTicketTypeAttributes(TicketTypeAttributeList $value): self + { + $this->ticketTypeAttributes = $value; + return $this; + } + + /** + * @return bool + */ + public function getArchived(): bool + { + return $this->archived; + } + + /** + * @param bool $value + */ + public function setArchived(bool $value): self + { + $this->archived = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Tickets/Types/TicketTypeCategory.php b/src/Tickets/Types/TicketTypeCategory.php new file mode 100644 index 00000000..54216c7a --- /dev/null +++ b/src/Tickets/Types/TicketTypeCategory.php @@ -0,0 +1,10 @@ +adminId = $values['adminId'] ?? null; + $this->assigneeId = $values['assigneeId'] ?? null; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAssigneeId(): ?string + { + return $this->assigneeId; + } + + /** + * @param ?string $value + */ + public function setAssigneeId(?string $value = null): self + { + $this->assigneeId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Tickets/Types/UpdateTicketRequestState.php b/src/Tickets/Types/UpdateTicketRequestState.php new file mode 100644 index 00000000..89728a6b --- /dev/null +++ b/src/Tickets/Types/UpdateTicketRequestState.php @@ -0,0 +1,10 @@ + $attachmentUrls + */ +trait ContactReplyBaseRequest +{ + /** + * @var 'comment' $messageType + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var 'user' $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $body The text body of the comment. + */ + #[JsonProperty('body')] + private string $body; + + /** + * @var ?int $createdAt The time the reply was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @return 'comment' + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param 'comment' $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'user' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'user' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } +} diff --git a/src/Traits/ListItem.php b/src/Traits/ListItem.php new file mode 100644 index 00000000..ecf6ecbb --- /dev/null +++ b/src/Traits/ListItem.php @@ -0,0 +1,205 @@ +type; + } + + /** + * @param 'item' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSubtitle(): ?string + { + return $this->subtitle; + } + + /** + * @param ?string $value + */ + public function setSubtitle(?string $value = null): self + { + $this->subtitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTertiaryText(): ?string + { + return $this->tertiaryText; + } + + /** + * @param ?string $value + */ + public function setTertiaryText(?string $value = null): self + { + $this->tertiaryText = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRoundedImage(): ?bool + { + return $this->roundedImage; + } + + /** + * @param ?bool $value + */ + public function setRoundedImage(?bool $value = null): self + { + $this->roundedImage = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return ?ActionComponent + */ + public function getAction(): ?ActionComponent + { + return $this->action; + } + + /** + * @param ?ActionComponent $value + */ + public function setAction(?ActionComponent $value = null): self + { + $this->action = $value; + return $this; + } +} diff --git a/src/Types/ActionComponent.php b/src/Types/ActionComponent.php new file mode 100644 index 00000000..9a587df1 --- /dev/null +++ b/src/Types/ActionComponent.php @@ -0,0 +1,280 @@ +type = $values['type']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'sheet' + * |'url' + * |'submit' + * |'_unknown' + * ) + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return ( + * SheetActionComponent + * |UrlActionComponent + * |SubmitActionComponent + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param SheetActionComponent $sheet + * @return ActionComponent + */ + public static function sheet(SheetActionComponent $sheet): ActionComponent + { + return new ActionComponent([ + 'type' => 'sheet', + 'value' => $sheet, + ]); + } + + /** + * @param UrlActionComponent $url + * @return ActionComponent + */ + public static function url(UrlActionComponent $url): ActionComponent + { + return new ActionComponent([ + 'type' => 'url', + 'value' => $url, + ]); + } + + /** + * @param SubmitActionComponent $submit + * @return ActionComponent + */ + public static function submit(SubmitActionComponent $submit): ActionComponent + { + return new ActionComponent([ + 'type' => 'submit', + 'value' => $submit, + ]); + } + + /** + * @return bool + */ + public function isSheet(): bool + { + return $this->value instanceof SheetActionComponent && $this->type === 'sheet'; + } + + /** + * @return SheetActionComponent + */ + public function asSheet(): SheetActionComponent + { + if (!($this->value instanceof SheetActionComponent && $this->type === 'sheet')) { + throw new Exception( + "Expected sheet; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isUrl(): bool + { + return $this->value instanceof UrlActionComponent && $this->type === 'url'; + } + + /** + * @return UrlActionComponent + */ + public function asUrl(): UrlActionComponent + { + if (!($this->value instanceof UrlActionComponent && $this->type === 'url')) { + throw new Exception( + "Expected url; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSubmit(): bool + { + return $this->value instanceof SubmitActionComponent && $this->type === 'submit'; + } + + /** + * @return SubmitActionComponent + */ + public function asSubmit(): SubmitActionComponent + { + if (!($this->value instanceof SubmitActionComponent && $this->type === 'submit')) { + throw new Exception( + "Expected submit; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['type'] = $this->type; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->type) { + case 'sheet': + $value = $this->asSheet()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'url': + $value = $this->asUrl()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'submit': + $value = $this->asSubmit()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('type', $data)) { + throw new Exception( + "JSON data is missing property 'type'", + ); + } + $type = $data['type']; + if (!(is_string($type))) { + throw new Exception( + "Expected property 'type' in JSON data to be string, instead received " . get_debug_type($data['type']), + ); + } + + $args['type'] = $type; + switch ($type) { + case 'sheet': + $args['value'] = SheetActionComponent::jsonDeserialize($data); + break; + case 'url': + $args['value'] = UrlActionComponent::jsonDeserialize($data); + break; + case 'submit': + $args['value'] = SubmitActionComponent::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['type'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Types/ActivityLog.php b/src/Types/ActivityLog.php new file mode 100644 index 00000000..d5d56872 --- /dev/null +++ b/src/Types/ActivityLog.php @@ -0,0 +1,179 @@ + $activityType + */ + #[JsonProperty('activity_type')] + private string $activityType; + + /** + * @var ?string $activityDescription A sentence or two describing the activity. + */ + #[JsonProperty('activity_description')] + private ?string $activityDescription; + + /** + * @param array{ + * id: string, + * performedBy: ActivityLogPerformedBy, + * activityType: value-of, + * metadata?: ?ActivityLogMetadata, + * createdAt?: ?int, + * activityDescription?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->performedBy = $values['performedBy']; + $this->metadata = $values['metadata'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->activityType = $values['activityType']; + $this->activityDescription = $values['activityDescription'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ActivityLogPerformedBy + */ + public function getPerformedBy(): ActivityLogPerformedBy + { + return $this->performedBy; + } + + /** + * @param ActivityLogPerformedBy $value + */ + public function setPerformedBy(ActivityLogPerformedBy $value): self + { + $this->performedBy = $value; + return $this; + } + + /** + * @return ?ActivityLogMetadata + */ + public function getMetadata(): ?ActivityLogMetadata + { + return $this->metadata; + } + + /** + * @param ?ActivityLogMetadata $value + */ + public function setMetadata(?ActivityLogMetadata $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return value-of + */ + public function getActivityType(): string + { + return $this->activityType; + } + + /** + * @param value-of $value + */ + public function setActivityType(string $value): self + { + $this->activityType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getActivityDescription(): ?string + { + return $this->activityDescription; + } + + /** + * @param ?string $value + */ + public function setActivityDescription(?string $value = null): self + { + $this->activityDescription = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ActivityLogActivityType.php b/src/Types/ActivityLogActivityType.php new file mode 100644 index 00000000..82eb0da0 --- /dev/null +++ b/src/Types/ActivityLogActivityType.php @@ -0,0 +1,74 @@ + $activityLogs An array of activity logs + */ + #[JsonProperty('activity_logs'), ArrayType([ActivityLog::class])] + private array $activityLogs; + + /** + * @param array{ + * type: 'activity_log.list', + * activityLogs: array, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->pages = $values['pages'] ?? null; + $this->activityLogs = $values['activityLogs']; + } + + /** + * @return 'activity_log.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'activity_log.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return array + */ + public function getActivityLogs(): array + { + return $this->activityLogs; + } + + /** + * @param array $value + */ + public function setActivityLogs(array $value): self + { + $this->activityLogs = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ActivityLogMetadata.php b/src/Types/ActivityLogMetadata.php new file mode 100644 index 00000000..2990717f --- /dev/null +++ b/src/Types/ActivityLogMetadata.php @@ -0,0 +1,254 @@ +signInMethod = $values['signInMethod'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->awayMode = $values['awayMode'] ?? null; + $this->awayStatusReason = $values['awayStatusReason'] ?? null; + $this->reassignConversations = $values['reassignConversations'] ?? null; + $this->source = $values['source'] ?? null; + $this->autoChanged = $values['autoChanged'] ?? null; + $this->updateBy = $values['updateBy'] ?? null; + $this->updateByName = $values['updateByName'] ?? null; + } + + /** + * @return ?string + */ + public function getSignInMethod(): ?string + { + return $this->signInMethod; + } + + /** + * @param ?string $value + */ + public function setSignInMethod(?string $value = null): self + { + $this->signInMethod = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAwayMode(): ?bool + { + return $this->awayMode; + } + + /** + * @param ?bool $value + */ + public function setAwayMode(?bool $value = null): self + { + $this->awayMode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAwayStatusReason(): ?string + { + return $this->awayStatusReason; + } + + /** + * @param ?string $value + */ + public function setAwayStatusReason(?string $value = null): self + { + $this->awayStatusReason = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getReassignConversations(): ?bool + { + return $this->reassignConversations; + } + + /** + * @param ?bool $value + */ + public function setReassignConversations(?bool $value = null): self + { + $this->reassignConversations = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSource(): ?string + { + return $this->source; + } + + /** + * @param ?string $value + */ + public function setSource(?string $value = null): self + { + $this->source = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAutoChanged(): ?string + { + return $this->autoChanged; + } + + /** + * @param ?string $value + */ + public function setAutoChanged(?string $value = null): self + { + $this->autoChanged = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdateBy(): ?int + { + return $this->updateBy; + } + + /** + * @param ?int $value + */ + public function setUpdateBy(?int $value = null): self + { + $this->updateBy = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUpdateByName(): ?string + { + return $this->updateByName; + } + + /** + * @param ?string $value + */ + public function setUpdateByName(?string $value = null): self + { + $this->updateByName = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ActivityLogPerformedBy.php b/src/Types/ActivityLogPerformedBy.php new file mode 100644 index 00000000..0f2fee68 --- /dev/null +++ b/src/Types/ActivityLogPerformedBy.php @@ -0,0 +1,129 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->email = $values['email'] ?? null; + $this->ip = $values['ip'] ?? null; + } + + /** + * @return ?'admin' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'admin' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIp(): ?string + { + return $this->ip; + } + + /** + * @param ?string $value + */ + public function setIp(?string $value = null): self + { + $this->ip = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AddressableList.php b/src/Types/AddressableList.php new file mode 100644 index 00000000..54942c80 --- /dev/null +++ b/src/Types/AddressableList.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->id = $values['id']; + $this->url = $values['url']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminList.php b/src/Types/AdminList.php new file mode 100644 index 00000000..cd100086 --- /dev/null +++ b/src/Types/AdminList.php @@ -0,0 +1,81 @@ + $admins A list of admins associated with a given workspace. + */ + #[JsonProperty('admins'), ArrayType([Admin::class])] + private array $admins; + + /** + * @param array{ + * type: 'admin.list', + * admins: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->admins = $values['admins']; + } + + /** + * @return 'admin.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getAdmins(): array + { + return $this->admins; + } + + /** + * @param array $value + */ + public function setAdmins(array $value): self + { + $this->admins = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminPriorityLevel.php b/src/Types/AdminPriorityLevel.php new file mode 100644 index 00000000..7463aabf --- /dev/null +++ b/src/Types/AdminPriorityLevel.php @@ -0,0 +1,80 @@ + $primaryAdminIds The primary admin ids for the team + */ + #[JsonProperty('primary_admin_ids'), ArrayType(['integer'])] + private ?array $primaryAdminIds; + + /** + * @var ?array $secondaryAdminIds The secondary admin ids for the team + */ + #[JsonProperty('secondary_admin_ids'), ArrayType(['integer'])] + private ?array $secondaryAdminIds; + + /** + * @param array{ + * primaryAdminIds?: ?array, + * secondaryAdminIds?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->primaryAdminIds = $values['primaryAdminIds'] ?? null; + $this->secondaryAdminIds = $values['secondaryAdminIds'] ?? null; + } + + /** + * @return ?array + */ + public function getPrimaryAdminIds(): ?array + { + return $this->primaryAdminIds; + } + + /** + * @param ?array $value + */ + public function setPrimaryAdminIds(?array $value = null): self + { + $this->primaryAdminIds = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSecondaryAdminIds(): ?array + { + return $this->secondaryAdminIds; + } + + /** + * @param ?array $value + */ + public function setSecondaryAdminIds(?array $value = null): self + { + $this->secondaryAdminIds = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminReplyConversationRequest.php b/src/Types/AdminReplyConversationRequest.php new file mode 100644 index 00000000..e68388f0 --- /dev/null +++ b/src/Types/AdminReplyConversationRequest.php @@ -0,0 +1,205 @@ + $messageType + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var 'admin' $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var ?string $body The text body of the reply. Notes accept some HTML formatting. Must be present for comment and note message types. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var string $adminId The id of the admin who is authoring the comment. + */ + #[JsonProperty('admin_id')] + private string $adminId; + + /** + * @var ?int $createdAt The time the reply was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @var ?array $attachmentFiles A list of files that will be added as attachments. You can include up to 10 files + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: value-of, + * type: 'admin', + * adminId: string, + * body?: ?string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body'] ?? null; + $this->adminId = $values['adminId']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return value-of + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param value-of $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminReplyConversationRequestMessageType.php b/src/Types/AdminReplyConversationRequestMessageType.php new file mode 100644 index 00000000..a7c7fae0 --- /dev/null +++ b/src/Types/AdminReplyConversationRequestMessageType.php @@ -0,0 +1,9 @@ + $messageType + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var 'admin' $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var ?string $body The text body of the reply. Notes accept some HTML formatting. Must be present for comment and note message types. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var string $adminId The id of the admin who is authoring the comment. + */ + #[JsonProperty('admin_id')] + private string $adminId; + + /** + * @var ?int $createdAt The time the reply was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $replyOptions The quick reply options to display. Must be present for quick_reply message types. + */ + #[JsonProperty('reply_options'), ArrayType([AdminReplyTicketRequestReplyOptionsItem::class])] + private ?array $replyOptions; + + /** + * @var ?array $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @param array{ + * messageType: value-of, + * type: 'admin', + * adminId: string, + * body?: ?string, + * createdAt?: ?int, + * replyOptions?: ?array, + * attachmentUrls?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body'] ?? null; + $this->adminId = $values['adminId']; + $this->createdAt = $values['createdAt'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + } + + /** + * @return value-of + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param value-of $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReplyOptions(): ?array + { + return $this->replyOptions; + } + + /** + * @param ?array $value + */ + public function setReplyOptions(?array $value = null): self + { + $this->replyOptions = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminReplyTicketRequestMessageType.php b/src/Types/AdminReplyTicketRequestMessageType.php new file mode 100644 index 00000000..01e9086d --- /dev/null +++ b/src/Types/AdminReplyTicketRequestMessageType.php @@ -0,0 +1,10 @@ +text = $values['text']; + $this->uuid = $values['uuid']; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * @param string $value + */ + public function setUuid(string $value): self + { + $this->uuid = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminWithApp.php b/src/Types/AdminWithApp.php new file mode 100644 index 00000000..4a1a2b9f --- /dev/null +++ b/src/Types/AdminWithApp.php @@ -0,0 +1,330 @@ + $teamIds This is a list of ids of the teams that this admin is part of. + */ + #[JsonProperty('team_ids'), ArrayType(['integer'])] + private array $teamIds; + + /** + * @var ?AdminWithAppAvatar $avatar This object represents the avatar associated with the admin. + */ + #[JsonProperty('avatar')] + private ?AdminWithAppAvatar $avatar; + + /** + * @var ?bool $emailVerified Identifies if this admin's email is verified. + */ + #[JsonProperty('email_verified')] + private ?bool $emailVerified; + + /** + * @var ?App $app App that the admin belongs to. + */ + #[JsonProperty('app')] + private ?App $app; + + /** + * @param array{ + * type: 'admin', + * id: string, + * name: string, + * email: string, + * jobTitle: string, + * awayModeEnabled: bool, + * awayModeReassign: bool, + * hasInboxSeat: bool, + * teamIds: array, + * avatar?: ?AdminWithAppAvatar, + * emailVerified?: ?bool, + * app?: ?App, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->name = $values['name']; + $this->email = $values['email']; + $this->jobTitle = $values['jobTitle']; + $this->awayModeEnabled = $values['awayModeEnabled']; + $this->awayModeReassign = $values['awayModeReassign']; + $this->hasInboxSeat = $values['hasInboxSeat']; + $this->teamIds = $values['teamIds']; + $this->avatar = $values['avatar'] ?? null; + $this->emailVerified = $values['emailVerified'] ?? null; + $this->app = $values['app'] ?? null; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function getJobTitle(): string + { + return $this->jobTitle; + } + + /** + * @param string $value + */ + public function setJobTitle(string $value): self + { + $this->jobTitle = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeEnabled(): bool + { + return $this->awayModeEnabled; + } + + /** + * @param bool $value + */ + public function setAwayModeEnabled(bool $value): self + { + $this->awayModeEnabled = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeReassign(): bool + { + return $this->awayModeReassign; + } + + /** + * @param bool $value + */ + public function setAwayModeReassign(bool $value): self + { + $this->awayModeReassign = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasInboxSeat(): bool + { + return $this->hasInboxSeat; + } + + /** + * @param bool $value + */ + public function setHasInboxSeat(bool $value): self + { + $this->hasInboxSeat = $value; + return $this; + } + + /** + * @return array + */ + public function getTeamIds(): array + { + return $this->teamIds; + } + + /** + * @param array $value + */ + public function setTeamIds(array $value): self + { + $this->teamIds = $value; + return $this; + } + + /** + * @return ?AdminWithAppAvatar + */ + public function getAvatar(): ?AdminWithAppAvatar + { + return $this->avatar; + } + + /** + * @param ?AdminWithAppAvatar $value + */ + public function setAvatar(?AdminWithAppAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getEmailVerified(): ?bool + { + return $this->emailVerified; + } + + /** + * @param ?bool $value + */ + public function setEmailVerified(?bool $value = null): self + { + $this->emailVerified = $value; + return $this; + } + + /** + * @return ?App + */ + public function getApp(): ?App + { + return $this->app; + } + + /** + * @param ?App $value + */ + public function setApp(?App $value = null): self + { + $this->app = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AdminWithAppAvatar.php b/src/Types/AdminWithAppAvatar.php new file mode 100644 index 00000000..9066188f --- /dev/null +++ b/src/Types/AdminWithAppAvatar.php @@ -0,0 +1,79 @@ +type = $values['type'] ?? null; + $this->imageUrl = $values['imageUrl'] ?? null; + } + + /** + * @return ?'avatar' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'avatar' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * @param ?string $value + */ + public function setImageUrl(?string $value = null): self + { + $this->imageUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/App.php b/src/Types/App.php new file mode 100644 index 00000000..ee8a5868 --- /dev/null +++ b/src/Types/App.php @@ -0,0 +1,204 @@ +type = $values['type']; + $this->idCode = $values['idCode']; + $this->name = $values['name']; + $this->region = $values['region']; + $this->timezone = $values['timezone']; + $this->createdAt = $values['createdAt']; + $this->identityVerification = $values['identityVerification']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getIdCode(): string + { + return $this->idCode; + } + + /** + * @param string $value + */ + public function setIdCode(string $value): self + { + $this->idCode = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getRegion(): string + { + return $this->region; + } + + /** + * @param string $value + */ + public function setRegion(string $value): self + { + $this->region = $value; + return $this; + } + + /** + * @return string + */ + public function getTimezone(): string + { + return $this->timezone; + } + + /** + * @param string $value + */ + public function setTimezone(string $value): self + { + $this->timezone = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return bool + */ + public function getIdentityVerification(): bool + { + return $this->identityVerification; + } + + /** + * @param bool $value + */ + public function setIdentityVerification(bool $value): self + { + $this->identityVerification = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ArticleContent.php b/src/Types/ArticleContent.php new file mode 100644 index 00000000..9581cf46 --- /dev/null +++ b/src/Types/ArticleContent.php @@ -0,0 +1,254 @@ + $state Whether the article is `published` or is a `draft` . + */ + #[JsonProperty('state')] + private string $state; + + /** + * @var ?int $createdAt The time when the article was created (seconds). + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The time when the article was last updated (seconds). + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?string $url The URL of the article. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @param array{ + * type: 'article_content', + * title: string, + * description: string, + * body: string, + * authorId: int, + * state: value-of, + * createdAt?: ?int, + * updatedAt?: ?int, + * url?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->title = $values['title']; + $this->description = $values['description']; + $this->body = $values['body']; + $this->authorId = $values['authorId']; + $this->state = $values['state']; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->url = $values['url'] ?? null; + } + + /** + * @return 'article_content' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'article_content' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getAuthorId(): int + { + return $this->authorId; + } + + /** + * @param int $value + */ + public function setAuthorId(int $value): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return value-of + */ + public function getState(): string + { + return $this->state; + } + + /** + * @param value-of $value + */ + public function setState(string $value): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ArticleContentState.php b/src/Types/ArticleContentState.php new file mode 100644 index 00000000..639d8aac --- /dev/null +++ b/src/Types/ArticleContentState.php @@ -0,0 +1,9 @@ + $data An array of Article objects + */ + #[JsonProperty('data'), ArrayType([ArticleListItem::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * totalCount: int, + * data: array, + * pages?: mixed, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return mixed + */ + public function getPages(): mixed + { + return $this->pages; + } + + /** + * @param mixed $value + */ + public function setPages(mixed $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ArticleStatistics.php b/src/Types/ArticleStatistics.php new file mode 100644 index 00000000..8628724e --- /dev/null +++ b/src/Types/ArticleStatistics.php @@ -0,0 +1,204 @@ +type = $values['type']; + $this->views = $values['views']; + $this->conversions = $values['conversions'] ?? null; + $this->reactions = $values['reactions']; + $this->happyReactionPercentage = $values['happyReactionPercentage']; + $this->neutralReactionPercentage = $values['neutralReactionPercentage']; + $this->sadReactionPercentage = $values['sadReactionPercentage']; + } + + /** + * @return 'article_statistics' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'article_statistics' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getViews(): int + { + return $this->views; + } + + /** + * @param int $value + */ + public function setViews(int $value): self + { + $this->views = $value; + return $this; + } + + /** + * @return ?int + */ + public function getConversions(): ?int + { + return $this->conversions; + } + + /** + * @param ?int $value + */ + public function setConversions(?int $value = null): self + { + $this->conversions = $value; + return $this; + } + + /** + * @return int + */ + public function getReactions(): int + { + return $this->reactions; + } + + /** + * @param int $value + */ + public function setReactions(int $value): self + { + $this->reactions = $value; + return $this; + } + + /** + * @return float + */ + public function getHappyReactionPercentage(): float + { + return $this->happyReactionPercentage; + } + + /** + * @param float $value + */ + public function setHappyReactionPercentage(float $value): self + { + $this->happyReactionPercentage = $value; + return $this; + } + + /** + * @return float + */ + public function getNeutralReactionPercentage(): float + { + return $this->neutralReactionPercentage; + } + + /** + * @param float $value + */ + public function setNeutralReactionPercentage(float $value): self + { + $this->neutralReactionPercentage = $value; + return $this; + } + + /** + * @return float + */ + public function getSadReactionPercentage(): float + { + return $this->sadReactionPercentage; + } + + /** + * @param float $value + */ + public function setSadReactionPercentage(float $value): self + { + $this->sadReactionPercentage = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ArticleTranslatedContent.php b/src/Types/ArticleTranslatedContent.php new file mode 100644 index 00000000..c1e9df14 --- /dev/null +++ b/src/Types/ArticleTranslatedContent.php @@ -0,0 +1,979 @@ +type = $values['type'] ?? null; + $this->ar = $values['ar'] ?? null; + $this->bg = $values['bg'] ?? null; + $this->bs = $values['bs'] ?? null; + $this->ca = $values['ca'] ?? null; + $this->cs = $values['cs'] ?? null; + $this->da = $values['da'] ?? null; + $this->de = $values['de'] ?? null; + $this->el = $values['el'] ?? null; + $this->en = $values['en'] ?? null; + $this->es = $values['es'] ?? null; + $this->et = $values['et'] ?? null; + $this->fi = $values['fi'] ?? null; + $this->fr = $values['fr'] ?? null; + $this->he = $values['he'] ?? null; + $this->hr = $values['hr'] ?? null; + $this->hu = $values['hu'] ?? null; + $this->id = $values['id'] ?? null; + $this->it = $values['it'] ?? null; + $this->ja = $values['ja'] ?? null; + $this->ko = $values['ko'] ?? null; + $this->lt = $values['lt'] ?? null; + $this->lv = $values['lv'] ?? null; + $this->mn = $values['mn'] ?? null; + $this->nb = $values['nb'] ?? null; + $this->nl = $values['nl'] ?? null; + $this->pl = $values['pl'] ?? null; + $this->pt = $values['pt'] ?? null; + $this->ro = $values['ro'] ?? null; + $this->ru = $values['ru'] ?? null; + $this->sl = $values['sl'] ?? null; + $this->sr = $values['sr'] ?? null; + $this->sv = $values['sv'] ?? null; + $this->tr = $values['tr'] ?? null; + $this->vi = $values['vi'] ?? null; + $this->ptBr = $values['ptBr'] ?? null; + $this->zhCn = $values['zhCn'] ?? null; + $this->zhTw = $values['zhTw'] ?? null; + } + + /** + * @return ?'article_translated_content' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'article_translated_content' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getAr(): ?ArticleContent + { + return $this->ar; + } + + /** + * @param ?ArticleContent $value + */ + public function setAr(?ArticleContent $value = null): self + { + $this->ar = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getBg(): ?ArticleContent + { + return $this->bg; + } + + /** + * @param ?ArticleContent $value + */ + public function setBg(?ArticleContent $value = null): self + { + $this->bg = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getBs(): ?ArticleContent + { + return $this->bs; + } + + /** + * @param ?ArticleContent $value + */ + public function setBs(?ArticleContent $value = null): self + { + $this->bs = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getCa(): ?ArticleContent + { + return $this->ca; + } + + /** + * @param ?ArticleContent $value + */ + public function setCa(?ArticleContent $value = null): self + { + $this->ca = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getCs(): ?ArticleContent + { + return $this->cs; + } + + /** + * @param ?ArticleContent $value + */ + public function setCs(?ArticleContent $value = null): self + { + $this->cs = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getDa(): ?ArticleContent + { + return $this->da; + } + + /** + * @param ?ArticleContent $value + */ + public function setDa(?ArticleContent $value = null): self + { + $this->da = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getDe(): ?ArticleContent + { + return $this->de; + } + + /** + * @param ?ArticleContent $value + */ + public function setDe(?ArticleContent $value = null): self + { + $this->de = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEl(): ?ArticleContent + { + return $this->el; + } + + /** + * @param ?ArticleContent $value + */ + public function setEl(?ArticleContent $value = null): self + { + $this->el = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEn(): ?ArticleContent + { + return $this->en; + } + + /** + * @param ?ArticleContent $value + */ + public function setEn(?ArticleContent $value = null): self + { + $this->en = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEs(): ?ArticleContent + { + return $this->es; + } + + /** + * @param ?ArticleContent $value + */ + public function setEs(?ArticleContent $value = null): self + { + $this->es = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEt(): ?ArticleContent + { + return $this->et; + } + + /** + * @param ?ArticleContent $value + */ + public function setEt(?ArticleContent $value = null): self + { + $this->et = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getFi(): ?ArticleContent + { + return $this->fi; + } + + /** + * @param ?ArticleContent $value + */ + public function setFi(?ArticleContent $value = null): self + { + $this->fi = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getFr(): ?ArticleContent + { + return $this->fr; + } + + /** + * @param ?ArticleContent $value + */ + public function setFr(?ArticleContent $value = null): self + { + $this->fr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getHe(): ?ArticleContent + { + return $this->he; + } + + /** + * @param ?ArticleContent $value + */ + public function setHe(?ArticleContent $value = null): self + { + $this->he = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getHr(): ?ArticleContent + { + return $this->hr; + } + + /** + * @param ?ArticleContent $value + */ + public function setHr(?ArticleContent $value = null): self + { + $this->hr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getHu(): ?ArticleContent + { + return $this->hu; + } + + /** + * @param ?ArticleContent $value + */ + public function setHu(?ArticleContent $value = null): self + { + $this->hu = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getId(): ?ArticleContent + { + return $this->id; + } + + /** + * @param ?ArticleContent $value + */ + public function setId(?ArticleContent $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getIt(): ?ArticleContent + { + return $this->it; + } + + /** + * @param ?ArticleContent $value + */ + public function setIt(?ArticleContent $value = null): self + { + $this->it = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getJa(): ?ArticleContent + { + return $this->ja; + } + + /** + * @param ?ArticleContent $value + */ + public function setJa(?ArticleContent $value = null): self + { + $this->ja = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getKo(): ?ArticleContent + { + return $this->ko; + } + + /** + * @param ?ArticleContent $value + */ + public function setKo(?ArticleContent $value = null): self + { + $this->ko = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getLt(): ?ArticleContent + { + return $this->lt; + } + + /** + * @param ?ArticleContent $value + */ + public function setLt(?ArticleContent $value = null): self + { + $this->lt = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getLv(): ?ArticleContent + { + return $this->lv; + } + + /** + * @param ?ArticleContent $value + */ + public function setLv(?ArticleContent $value = null): self + { + $this->lv = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getMn(): ?ArticleContent + { + return $this->mn; + } + + /** + * @param ?ArticleContent $value + */ + public function setMn(?ArticleContent $value = null): self + { + $this->mn = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getNb(): ?ArticleContent + { + return $this->nb; + } + + /** + * @param ?ArticleContent $value + */ + public function setNb(?ArticleContent $value = null): self + { + $this->nb = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getNl(): ?ArticleContent + { + return $this->nl; + } + + /** + * @param ?ArticleContent $value + */ + public function setNl(?ArticleContent $value = null): self + { + $this->nl = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getPl(): ?ArticleContent + { + return $this->pl; + } + + /** + * @param ?ArticleContent $value + */ + public function setPl(?ArticleContent $value = null): self + { + $this->pl = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getPt(): ?ArticleContent + { + return $this->pt; + } + + /** + * @param ?ArticleContent $value + */ + public function setPt(?ArticleContent $value = null): self + { + $this->pt = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getRo(): ?ArticleContent + { + return $this->ro; + } + + /** + * @param ?ArticleContent $value + */ + public function setRo(?ArticleContent $value = null): self + { + $this->ro = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getRu(): ?ArticleContent + { + return $this->ru; + } + + /** + * @param ?ArticleContent $value + */ + public function setRu(?ArticleContent $value = null): self + { + $this->ru = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getSl(): ?ArticleContent + { + return $this->sl; + } + + /** + * @param ?ArticleContent $value + */ + public function setSl(?ArticleContent $value = null): self + { + $this->sl = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getSr(): ?ArticleContent + { + return $this->sr; + } + + /** + * @param ?ArticleContent $value + */ + public function setSr(?ArticleContent $value = null): self + { + $this->sr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getSv(): ?ArticleContent + { + return $this->sv; + } + + /** + * @param ?ArticleContent $value + */ + public function setSv(?ArticleContent $value = null): self + { + $this->sv = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getTr(): ?ArticleContent + { + return $this->tr; + } + + /** + * @param ?ArticleContent $value + */ + public function setTr(?ArticleContent $value = null): self + { + $this->tr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getVi(): ?ArticleContent + { + return $this->vi; + } + + /** + * @param ?ArticleContent $value + */ + public function setVi(?ArticleContent $value = null): self + { + $this->vi = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getPtBr(): ?ArticleContent + { + return $this->ptBr; + } + + /** + * @param ?ArticleContent $value + */ + public function setPtBr(?ArticleContent $value = null): self + { + $this->ptBr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getZhCn(): ?ArticleContent + { + return $this->zhCn; + } + + /** + * @param ?ArticleContent $value + */ + public function setZhCn(?ArticleContent $value = null): self + { + $this->zhCn = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getZhTw(): ?ArticleContent + { + return $this->zhTw; + } + + /** + * @param ?ArticleContent $value + */ + public function setZhTw(?ArticleContent $value = null): self + { + $this->zhTw = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AssignConversationRequest.php b/src/Types/AssignConversationRequest.php new file mode 100644 index 00000000..e083b474 --- /dev/null +++ b/src/Types/AssignConversationRequest.php @@ -0,0 +1,129 @@ + $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $adminId The id of the admin who is performing the action. + */ + #[JsonProperty('admin_id')] + private string $adminId; + + /** + * @var string $assigneeId The `id` of the `admin` or `team` which will be assigned the conversation. A conversation can be assigned both an admin and a team.\nSet `0` if you want this assign to no admin or team (ie. Unassigned). + */ + #[JsonProperty('assignee_id')] + private string $assigneeId; + + /** + * @var ?string $body Optionally you can send a response in the conversation when it is assigned. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @param array{ + * type: value-of, + * adminId: string, + * assigneeId: string, + * body?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->adminId = $values['adminId']; + $this->assigneeId = $values['assigneeId']; + $this->body = $values['body'] ?? null; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return string + */ + public function getAssigneeId(): string + { + return $this->assigneeId; + } + + /** + * @param string $value + */ + public function setAssigneeId(string $value): self + { + $this->assigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/AssignConversationRequestType.php b/src/Types/AssignConversationRequestType.php new file mode 100644 index 00000000..c5f23f7f --- /dev/null +++ b/src/Types/AssignConversationRequestType.php @@ -0,0 +1,9 @@ + $style Styles the button. Default is 'primary'. + */ + #[JsonProperty('style')] + private ?string $style; + + /** + * @var ?bool $disabled Styles the button and prevents the action. Default is false. + */ + #[JsonProperty('disabled')] + private ?bool $disabled; + + /** + * @param array{ + * id: string, + * label: string, + * action: ActionComponent, + * style?: ?value-of, + * disabled?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->label = $values['label']; + $this->action = $values['action']; + $this->style = $values['style'] ?? null; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getLabel(): string + { + return $this->label; + } + + /** + * @param string $value + */ + public function setLabel(string $value): self + { + $this->label = $value; + return $this; + } + + /** + * @return ActionComponent + */ + public function getAction(): ActionComponent + { + return $this->action; + } + + /** + * @param ActionComponent $value + */ + public function setAction(ActionComponent $value): self + { + $this->action = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getStyle(): ?string + { + return $this->style; + } + + /** + * @param ?value-of $value + */ + public function setStyle(?string $value = null): self + { + $this->style = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ButtonComponentStyle.php b/src/Types/ButtonComponentStyle.php new file mode 100644 index 00000000..f0489589 --- /dev/null +++ b/src/Types/ButtonComponentStyle.php @@ -0,0 +1,10 @@ + $storedData Optional Stored Data that you want to be returned in the next sent request. Max Size is 64KB. + */ + #[JsonProperty('stored_data'), ArrayType(['string' => 'mixed'])] + private ?array $storedData; + + /** + * @param array{ + * content: ContentObject, + * contentUrl?: ?string, + * storedData?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->content = $values['content']; + $this->contentUrl = $values['contentUrl'] ?? null; + $this->storedData = $values['storedData'] ?? null; + } + + /** + * @return ContentObject + */ + public function getContent(): ContentObject + { + return $this->content; + } + + /** + * @param ContentObject $value + */ + public function setContent(ContentObject $value): self + { + $this->content = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContentUrl(): ?string + { + return $this->contentUrl; + } + + /** + * @param ?string $value + */ + public function setContentUrl(?string $value = null): self + { + $this->contentUrl = $value; + return $this; + } + + /** + * @return ?array + */ + public function getStoredData(): ?array + { + return $this->storedData; + } + + /** + * @param ?array $value + */ + public function setStoredData(?array $value = null): self + { + $this->storedData = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CheckboxComponent.php b/src/Types/CheckboxComponent.php new file mode 100644 index 00000000..80291557 --- /dev/null +++ b/src/Types/CheckboxComponent.php @@ -0,0 +1,184 @@ + $option The list of options. Minimum of 1. + */ + #[JsonProperty('option'), ArrayType([CheckboxOption::class])] + private array $option; + + /** + * @var string $label The text shown above the options. + */ + #[JsonProperty('label')] + private string $label; + + /** + * @var ?array $value The option's that are selected by default. + */ + #[JsonProperty('value'), ArrayType(['string'])] + private ?array $value; + + /** + * @var ?value-of $saveState Styles the input. Default is `unsaved`. Prevent action with `saved`. + */ + #[JsonProperty('save_state')] + private ?string $saveState; + + /** + * @var ?bool $disabled Styles all options and prevents the action. Default is false. Will be overridden if save_state is saved. + */ + #[JsonProperty('disabled')] + private ?bool $disabled; + + /** + * @param array{ + * id: string, + * option: array, + * label: string, + * value?: ?array, + * saveState?: ?value-of, + * disabled?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->option = $values['option']; + $this->label = $values['label']; + $this->value = $values['value'] ?? null; + $this->saveState = $values['saveState'] ?? null; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return array + */ + public function getOption(): array + { + return $this->option; + } + + /** + * @param array $value + */ + public function setOption(array $value): self + { + $this->option = $value; + return $this; + } + + /** + * @return string + */ + public function getLabel(): string + { + return $this->label; + } + + /** + * @param string $value + */ + public function setLabel(string $value): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?array + */ + public function getValue(): ?array + { + return $this->value; + } + + /** + * @param ?array $value + */ + public function setValue(?array $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getSaveState(): ?string + { + return $this->saveState; + } + + /** + * @param ?value-of $value + */ + public function setSaveState(?string $value = null): self + { + $this->saveState = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CheckboxComponentSaveState.php b/src/Types/CheckboxComponentSaveState.php new file mode 100644 index 00000000..fc07bc6f --- /dev/null +++ b/src/Types/CheckboxComponentSaveState.php @@ -0,0 +1,10 @@ +type = $values['type']; + $this->id = $values['id']; + $this->text = $values['text']; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return 'option' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'option' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CloseConversationRequest.php b/src/Types/CloseConversationRequest.php new file mode 100644 index 00000000..ee8344f2 --- /dev/null +++ b/src/Types/CloseConversationRequest.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->adminId = $values['adminId']; + $this->body = $values['body'] ?? null; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CollectionList.php b/src/Types/CollectionList.php new file mode 100644 index 00000000..22e19ca3 --- /dev/null +++ b/src/Types/CollectionList.php @@ -0,0 +1,131 @@ + $data An array of collection objects + */ + #[JsonProperty('data'), ArrayType([Collection::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * totalCount: int, + * data: array, + * pages?: ?OffsetPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?OffsetPages + */ + public function getPages(): ?OffsetPages + { + return $this->pages; + } + + /** + * @param ?OffsetPages $value + */ + public function setPages(?OffsetPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CompanyAttachedContacts.php b/src/Types/CompanyAttachedContacts.php new file mode 100644 index 00000000..a6f51d7f --- /dev/null +++ b/src/Types/CompanyAttachedContacts.php @@ -0,0 +1,131 @@ + $data An array containing Contact Objects + */ + #[JsonProperty('data'), ArrayType([Contact::class])] + private array $data; + + /** + * @var int $totalCount The total number of contacts + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type: 'list', + * data: array, + * totalCount: int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + $this->totalCount = $values['totalCount']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CompanyAttachedSegments.php b/src/Types/CompanyAttachedSegments.php new file mode 100644 index 00000000..29efd837 --- /dev/null +++ b/src/Types/CompanyAttachedSegments.php @@ -0,0 +1,81 @@ + $data An array containing Segment Objects + */ + #[JsonProperty('data'), ArrayType([Segment::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CompanyList.php b/src/Types/CompanyList.php new file mode 100644 index 00000000..79996606 --- /dev/null +++ b/src/Types/CompanyList.php @@ -0,0 +1,106 @@ + $data An array containing Company Objects. + */ + #[JsonProperty('data'), ArrayType([Company::class])] + private array $data; + + /** + * @param array{ + * totalCount: int, + * data: array, + * pages?: ?OffsetPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount']; + $this->data = $values['data']; + } + + /** + * @return ?OffsetPages + */ + public function getPages(): ?OffsetPages + { + return $this->pages; + } + + /** + * @param ?OffsetPages $value + */ + public function setPages(?OffsetPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CompanyScroll.php b/src/Types/CompanyScroll.php new file mode 100644 index 00000000..4cdedffc --- /dev/null +++ b/src/Types/CompanyScroll.php @@ -0,0 +1,156 @@ + $data + */ + #[JsonProperty('data'), ArrayType([Company::class])] + private array $data; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @var ?int $totalCount The total number of companies + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?string $scrollParam The scroll parameter to use in the next request to fetch the next page of results. + */ + #[JsonProperty('scroll_param')] + private ?string $scrollParam; + + /** + * @param array{ + * type: 'list', + * data: array, + * pages?: ?CursorPages, + * totalCount?: ?int, + * scrollParam?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->scrollParam = $values['scrollParam'] ?? null; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?string + */ + public function getScrollParam(): ?string + { + return $this->scrollParam; + } + + /** + * @param ?string $value + */ + public function setScrollParam(?string $value = null): self + { + $this->scrollParam = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Component.php b/src/Types/Component.php new file mode 100644 index 00000000..425b440e --- /dev/null +++ b/src/Types/Component.php @@ -0,0 +1,703 @@ +type = $values['type']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'button' + * |'checkbox' + * |'dropdown' + * |'input' + * |'list' + * |'single-select' + * |'textarea' + * |'data-table' + * |'divider' + * |'image' + * |'spacer' + * |'text' + * |'_unknown' + * ) + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return ( + * ButtonComponent + * |CheckboxComponent + * |DropdownComponent + * |InputComponent + * |ListComponent + * |SingleSelectComponent + * |TextAreaComponent + * |DataTableComponent + * |DividerComponent + * |ImageComponent + * |SpacerComponent + * |TextComponent + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param ButtonComponent $button + * @return Component + */ + public static function button(ButtonComponent $button): Component + { + return new Component([ + 'type' => 'button', + 'value' => $button, + ]); + } + + /** + * @param CheckboxComponent $checkbox + * @return Component + */ + public static function checkbox(CheckboxComponent $checkbox): Component + { + return new Component([ + 'type' => 'checkbox', + 'value' => $checkbox, + ]); + } + + /** + * @param DropdownComponent $dropdown + * @return Component + */ + public static function dropdown(DropdownComponent $dropdown): Component + { + return new Component([ + 'type' => 'dropdown', + 'value' => $dropdown, + ]); + } + + /** + * @param InputComponent $input + * @return Component + */ + public static function input(InputComponent $input): Component + { + return new Component([ + 'type' => 'input', + 'value' => $input, + ]); + } + + /** + * @param ListComponent $list + * @return Component + */ + public static function list(ListComponent $list): Component + { + return new Component([ + 'type' => 'list', + 'value' => $list, + ]); + } + + /** + * @param SingleSelectComponent $singleSelect + * @return Component + */ + public static function singleSelect(SingleSelectComponent $singleSelect): Component + { + return new Component([ + 'type' => 'single-select', + 'value' => $singleSelect, + ]); + } + + /** + * @param TextAreaComponent $textarea + * @return Component + */ + public static function textarea(TextAreaComponent $textarea): Component + { + return new Component([ + 'type' => 'textarea', + 'value' => $textarea, + ]); + } + + /** + * @param DataTableComponent $dataTable + * @return Component + */ + public static function dataTable(DataTableComponent $dataTable): Component + { + return new Component([ + 'type' => 'data-table', + 'value' => $dataTable, + ]); + } + + /** + * @param DividerComponent $divider + * @return Component + */ + public static function divider(DividerComponent $divider): Component + { + return new Component([ + 'type' => 'divider', + 'value' => $divider, + ]); + } + + /** + * @param ImageComponent $image + * @return Component + */ + public static function image(ImageComponent $image): Component + { + return new Component([ + 'type' => 'image', + 'value' => $image, + ]); + } + + /** + * @param SpacerComponent $spacer + * @return Component + */ + public static function spacer(SpacerComponent $spacer): Component + { + return new Component([ + 'type' => 'spacer', + 'value' => $spacer, + ]); + } + + /** + * @param TextComponent $text + * @return Component + */ + public static function text(TextComponent $text): Component + { + return new Component([ + 'type' => 'text', + 'value' => $text, + ]); + } + + /** + * @return bool + */ + public function isButton(): bool + { + return $this->value instanceof ButtonComponent && $this->type === 'button'; + } + + /** + * @return ButtonComponent + */ + public function asButton(): ButtonComponent + { + if (!($this->value instanceof ButtonComponent && $this->type === 'button')) { + throw new Exception( + "Expected button; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isCheckbox(): bool + { + return $this->value instanceof CheckboxComponent && $this->type === 'checkbox'; + } + + /** + * @return CheckboxComponent + */ + public function asCheckbox(): CheckboxComponent + { + if (!($this->value instanceof CheckboxComponent && $this->type === 'checkbox')) { + throw new Exception( + "Expected checkbox; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isDropdown(): bool + { + return $this->value instanceof DropdownComponent && $this->type === 'dropdown'; + } + + /** + * @return DropdownComponent + */ + public function asDropdown(): DropdownComponent + { + if (!($this->value instanceof DropdownComponent && $this->type === 'dropdown')) { + throw new Exception( + "Expected dropdown; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isInput(): bool + { + return $this->value instanceof InputComponent && $this->type === 'input'; + } + + /** + * @return InputComponent + */ + public function asInput(): InputComponent + { + if (!($this->value instanceof InputComponent && $this->type === 'input')) { + throw new Exception( + "Expected input; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isList_(): bool + { + return $this->value instanceof ListComponent && $this->type === 'list'; + } + + /** + * @return ListComponent + */ + public function asList_(): ListComponent + { + if (!($this->value instanceof ListComponent && $this->type === 'list')) { + throw new Exception( + "Expected list; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSingleSelect(): bool + { + return $this->value instanceof SingleSelectComponent && $this->type === 'single-select'; + } + + /** + * @return SingleSelectComponent + */ + public function asSingleSelect(): SingleSelectComponent + { + if (!($this->value instanceof SingleSelectComponent && $this->type === 'single-select')) { + throw new Exception( + "Expected single-select; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isTextarea(): bool + { + return $this->value instanceof TextAreaComponent && $this->type === 'textarea'; + } + + /** + * @return TextAreaComponent + */ + public function asTextarea(): TextAreaComponent + { + if (!($this->value instanceof TextAreaComponent && $this->type === 'textarea')) { + throw new Exception( + "Expected textarea; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isDataTable(): bool + { + return $this->value instanceof DataTableComponent && $this->type === 'data-table'; + } + + /** + * @return DataTableComponent + */ + public function asDataTable(): DataTableComponent + { + if (!($this->value instanceof DataTableComponent && $this->type === 'data-table')) { + throw new Exception( + "Expected data-table; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isDivider(): bool + { + return $this->value instanceof DividerComponent && $this->type === 'divider'; + } + + /** + * @return DividerComponent + */ + public function asDivider(): DividerComponent + { + if (!($this->value instanceof DividerComponent && $this->type === 'divider')) { + throw new Exception( + "Expected divider; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isImage(): bool + { + return $this->value instanceof ImageComponent && $this->type === 'image'; + } + + /** + * @return ImageComponent + */ + public function asImage(): ImageComponent + { + if (!($this->value instanceof ImageComponent && $this->type === 'image')) { + throw new Exception( + "Expected image; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSpacer(): bool + { + return $this->value instanceof SpacerComponent && $this->type === 'spacer'; + } + + /** + * @return SpacerComponent + */ + public function asSpacer(): SpacerComponent + { + if (!($this->value instanceof SpacerComponent && $this->type === 'spacer')) { + throw new Exception( + "Expected spacer; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isText(): bool + { + return $this->value instanceof TextComponent && $this->type === 'text'; + } + + /** + * @return TextComponent + */ + public function asText(): TextComponent + { + if (!($this->value instanceof TextComponent && $this->type === 'text')) { + throw new Exception( + "Expected text; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['type'] = $this->type; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->type) { + case 'button': + $value = $this->asButton()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'checkbox': + $value = $this->asCheckbox()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'dropdown': + $value = $this->asDropdown()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'input': + $value = $this->asInput()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'list': + $value = $this->asList_()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'single-select': + $value = $this->asSingleSelect()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'textarea': + $value = $this->asTextarea()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'data-table': + $value = $this->asDataTable()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'divider': + $value = $this->asDivider()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'image': + $value = $this->asImage()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'spacer': + $value = $this->asSpacer()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'text': + $value = $this->asText()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('type', $data)) { + throw new Exception( + "JSON data is missing property 'type'", + ); + } + $type = $data['type']; + if (!(is_string($type))) { + throw new Exception( + "Expected property 'type' in JSON data to be string, instead received " . get_debug_type($data['type']), + ); + } + + $args['type'] = $type; + switch ($type) { + case 'button': + $args['value'] = ButtonComponent::jsonDeserialize($data); + break; + case 'checkbox': + $args['value'] = CheckboxComponent::jsonDeserialize($data); + break; + case 'dropdown': + $args['value'] = DropdownComponent::jsonDeserialize($data); + break; + case 'input': + $args['value'] = InputComponent::jsonDeserialize($data); + break; + case 'list': + $args['value'] = ListComponent::jsonDeserialize($data); + break; + case 'single-select': + $args['value'] = SingleSelectComponent::jsonDeserialize($data); + break; + case 'textarea': + $args['value'] = TextAreaComponent::jsonDeserialize($data); + break; + case 'data-table': + $args['value'] = DataTableComponent::jsonDeserialize($data); + break; + case 'divider': + $args['value'] = DividerComponent::jsonDeserialize($data); + break; + case 'image': + $args['value'] = ImageComponent::jsonDeserialize($data); + break; + case 'spacer': + $args['value'] = SpacerComponent::jsonDeserialize($data); + break; + case 'text': + $args['value'] = TextComponent::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['type'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Types/ConfigureRequestComponentId.php b/src/Types/ConfigureRequestComponentId.php new file mode 100644 index 00000000..f7308bb7 --- /dev/null +++ b/src/Types/ConfigureRequestComponentId.php @@ -0,0 +1,203 @@ + $inputValues A list of key/value pairs of data, inputted by the teammate on the current canvas. + */ + #[JsonProperty('input_values'), ArrayType(['string' => 'mixed'])] + private array $inputValues; + + /** + * @param array{ + * workspaceId: string, + * workspaceRegion: string, + * componentId: string, + * admin: Admin, + * context: Context, + * currentCanvas: CanvasObject, + * inputValues: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->workspaceId = $values['workspaceId']; + $this->workspaceRegion = $values['workspaceRegion']; + $this->componentId = $values['componentId']; + $this->admin = $values['admin']; + $this->context = $values['context']; + $this->currentCanvas = $values['currentCanvas']; + $this->inputValues = $values['inputValues']; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceRegion(): string + { + return $this->workspaceRegion; + } + + /** + * @param string $value + */ + public function setWorkspaceRegion(string $value): self + { + $this->workspaceRegion = $value; + return $this; + } + + /** + * @return string + */ + public function getComponentId(): string + { + return $this->componentId; + } + + /** + * @param string $value + */ + public function setComponentId(string $value): self + { + $this->componentId = $value; + return $this; + } + + /** + * @return Admin + */ + public function getAdmin(): Admin + { + return $this->admin; + } + + /** + * @param Admin $value + */ + public function setAdmin(Admin $value): self + { + $this->admin = $value; + return $this; + } + + /** + * @return Context + */ + public function getContext(): Context + { + return $this->context; + } + + /** + * @param Context $value + */ + public function setContext(Context $value): self + { + $this->context = $value; + return $this; + } + + /** + * @return CanvasObject + */ + public function getCurrentCanvas(): CanvasObject + { + return $this->currentCanvas; + } + + /** + * @param CanvasObject $value + */ + public function setCurrentCanvas(CanvasObject $value): self + { + $this->currentCanvas = $value; + return $this; + } + + /** + * @return array + */ + public function getInputValues(): array + { + return $this->inputValues; + } + + /** + * @param array $value + */ + public function setInputValues(array $value): self + { + $this->inputValues = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConfigureRequestZero.php b/src/Types/ConfigureRequestZero.php new file mode 100644 index 00000000..0ed42921 --- /dev/null +++ b/src/Types/ConfigureRequestZero.php @@ -0,0 +1,102 @@ +workspaceId = $values['workspaceId']; + $this->admin = $values['admin']; + $this->context = $values['context']; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return Admin + */ + public function getAdmin(): Admin + { + return $this->admin; + } + + /** + * @param Admin $value + */ + public function setAdmin(Admin $value): self + { + $this->admin = $value; + return $this; + } + + /** + * @return Context + */ + public function getContext(): Context + { + return $this->context; + } + + /** + * @param Context $value + */ + public function setContext(Context $value): self + { + $this->context = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConfigureResponseCanvas.php b/src/Types/ConfigureResponseCanvas.php new file mode 100644 index 00000000..cfe2f39c --- /dev/null +++ b/src/Types/ConfigureResponseCanvas.php @@ -0,0 +1,51 @@ +canvas = $values['canvas']; + } + + /** + * @return CanvasObject + */ + public function getCanvas(): CanvasObject + { + return $this->canvas; + } + + /** + * @param CanvasObject $value + */ + public function setCanvas(CanvasObject $value): self + { + $this->canvas = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactArchived.php b/src/Types/ContactArchived.php new file mode 100644 index 00000000..5624a93b --- /dev/null +++ b/src/Types/ContactArchived.php @@ -0,0 +1,129 @@ +type = $values['type']; + $this->id = $values['id']; + $this->externalId = $values['externalId'] ?? null; + $this->archived = $values['archived']; + } + + /** + * @return 'contact' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'contact' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return bool + */ + public function getArchived(): bool + { + return $this->archived; + } + + /** + * @param bool $value + */ + public function setArchived(bool $value): self + { + $this->archived = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactAttachedCompanies.php b/src/Types/ContactAttachedCompanies.php new file mode 100644 index 00000000..f4de3476 --- /dev/null +++ b/src/Types/ContactAttachedCompanies.php @@ -0,0 +1,131 @@ + $companies An array containing Company Objects + */ + #[JsonProperty('companies'), ArrayType([Company::class])] + private array $companies; + + /** + * @var int $totalCount The total number of companies associated to this contact + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var ?PagesLink $pages + */ + #[JsonProperty('pages')] + private ?PagesLink $pages; + + /** + * @param array{ + * type: 'list', + * companies: array, + * totalCount: int, + * pages?: ?PagesLink, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->companies = $values['companies']; + $this->totalCount = $values['totalCount']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getCompanies(): array + { + return $this->companies; + } + + /** + * @param array $value + */ + public function setCompanies(array $value): self + { + $this->companies = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?PagesLink + */ + public function getPages(): ?PagesLink + { + return $this->pages; + } + + /** + * @param ?PagesLink $value + */ + public function setPages(?PagesLink $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactCompanies.php b/src/Types/ContactCompanies.php new file mode 100644 index 00000000..e70b4cd5 --- /dev/null +++ b/src/Types/ContactCompanies.php @@ -0,0 +1,155 @@ + $data An array containing Company Objects + */ + #[JsonProperty('data'), ArrayType([ContactCompany::class])] + private ?array $data; + + /** + * @var string $url Url to get more company resources for this contact + */ + #[JsonProperty('url')] + private string $url; + + /** + * @var int $totalCount Int representing the total number of companyies attached to this contact + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private bool $hasMore; + + /** + * @param array{ + * url: string, + * totalCount: int, + * hasMore: bool, + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + $this->url = $values['url']; + $this->totalCount = $values['totalCount']; + $this->hasMore = $values['hasMore']; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasMore(): bool + { + return $this->hasMore; + } + + /** + * @param bool $value + */ + public function setHasMore(bool $value): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactCompany.php b/src/Types/ContactCompany.php new file mode 100644 index 00000000..47daced6 --- /dev/null +++ b/src/Types/ContactCompany.php @@ -0,0 +1,104 @@ +id = $values['id']; + $this->type = $values['type']; + $this->url = $values['url']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'company' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'company' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactDeleted.php b/src/Types/ContactDeleted.php new file mode 100644 index 00000000..f9750ce7 --- /dev/null +++ b/src/Types/ContactDeleted.php @@ -0,0 +1,129 @@ +type = $values['type']; + $this->id = $values['id']; + $this->externalId = $values['externalId'] ?? null; + $this->deleted = $values['deleted']; + } + + /** + * @return 'contact' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'contact' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return bool + */ + public function getDeleted(): bool + { + return $this->deleted; + } + + /** + * @param bool $value + */ + public function setDeleted(bool $value): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactList.php b/src/Types/ContactList.php new file mode 100644 index 00000000..0484f4ec --- /dev/null +++ b/src/Types/ContactList.php @@ -0,0 +1,131 @@ + $data The list of contact objects + */ + #[JsonProperty('data'), ArrayType([Contact::class])] + private array $data; + + /** + * @var int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type: 'list', + * data: array, + * totalCount: int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + $this->totalCount = $values['totalCount']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactLocation.php b/src/Types/ContactLocation.php new file mode 100644 index 00000000..f7ababe4 --- /dev/null +++ b/src/Types/ContactLocation.php @@ -0,0 +1,129 @@ +type = $values['type']; + $this->country = $values['country'] ?? null; + $this->region = $values['region'] ?? null; + $this->city = $values['city'] ?? null; + } + + /** + * @return 'location' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'location' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCountry(): ?string + { + return $this->country; + } + + /** + * @param ?string $value + */ + public function setCountry(?string $value = null): self + { + $this->country = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRegion(): ?string + { + return $this->region; + } + + /** + * @param ?string $value + */ + public function setRegion(?string $value = null): self + { + $this->region = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCity(): ?string + { + return $this->city; + } + + /** + * @param ?string $value + */ + public function setCity(?string $value = null): self + { + $this->city = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactNotes.php b/src/Types/ContactNotes.php new file mode 100644 index 00000000..18fb28c6 --- /dev/null +++ b/src/Types/ContactNotes.php @@ -0,0 +1,130 @@ + $data This object represents the notes attached to a contact. + */ + #[JsonProperty('data'), ArrayType([AddressableList::class])] + private array $data; + + /** + * @var string $url Url to get more company resources for this contact + */ + #[JsonProperty('url')] + private string $url; + + /** + * @var int $totalCount Int representing the total number of companyies attached to this contact + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private bool $hasMore; + + /** + * @param array{ + * data: array, + * url: string, + * totalCount: int, + * hasMore: bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->data = $values['data']; + $this->url = $values['url']; + $this->totalCount = $values['totalCount']; + $this->hasMore = $values['hasMore']; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasMore(): bool + { + return $this->hasMore; + } + + /** + * @param bool $value + */ + public function setHasMore(bool $value): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReference.php b/src/Types/ContactReference.php new file mode 100644 index 00000000..2c40ec2b --- /dev/null +++ b/src/Types/ContactReference.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->id = $values['id']; + $this->externalId = $values['externalId'] ?? null; + } + + /** + * @return 'contact' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'contact' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyBaseRequest.php b/src/Types/ContactReplyBaseRequest.php new file mode 100644 index 00000000..f2978106 --- /dev/null +++ b/src/Types/ContactReplyBaseRequest.php @@ -0,0 +1,152 @@ + $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + } + + /** + * @return 'comment' + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param 'comment' $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'user' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'user' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyEmailRequest.php b/src/Types/ContactReplyEmailRequest.php new file mode 100644 index 00000000..c31921a9 --- /dev/null +++ b/src/Types/ContactReplyEmailRequest.php @@ -0,0 +1,93 @@ + $attachmentFiles A list of files that will be added as attachments. + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * email: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->email = $values['email']; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyIntercomUserIdRequest.php b/src/Types/ContactReplyIntercomUserIdRequest.php new file mode 100644 index 00000000..fc1dc44c --- /dev/null +++ b/src/Types/ContactReplyIntercomUserIdRequest.php @@ -0,0 +1,93 @@ + $attachmentFiles A list of files that will be added as attachments. + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * intercomUserId: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->intercomUserId = $values['intercomUserId']; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyTicketEmailRequest.php b/src/Types/ContactReplyTicketEmailRequest.php new file mode 100644 index 00000000..b5769fa8 --- /dev/null +++ b/src/Types/ContactReplyTicketEmailRequest.php @@ -0,0 +1,67 @@ +, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyTicketIntercomUserIdRequest.php b/src/Types/ContactReplyTicketIntercomUserIdRequest.php new file mode 100644 index 00000000..7e70b8c0 --- /dev/null +++ b/src/Types/ContactReplyTicketIntercomUserIdRequest.php @@ -0,0 +1,67 @@ +, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->intercomUserId = $values['intercomUserId']; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyTicketUserIdRequest.php b/src/Types/ContactReplyTicketUserIdRequest.php new file mode 100644 index 00000000..0a3e7c58 --- /dev/null +++ b/src/Types/ContactReplyTicketUserIdRequest.php @@ -0,0 +1,67 @@ +, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactReplyUserIdRequest.php b/src/Types/ContactReplyUserIdRequest.php new file mode 100644 index 00000000..8eef1da9 --- /dev/null +++ b/src/Types/ContactReplyUserIdRequest.php @@ -0,0 +1,93 @@ + $attachmentFiles A list of files that will be added as attachments. You can include up to 10 files. + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * userId: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->userId = $values['userId']; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactSegments.php b/src/Types/ContactSegments.php new file mode 100644 index 00000000..987ed4f8 --- /dev/null +++ b/src/Types/ContactSegments.php @@ -0,0 +1,81 @@ + $data Segment objects associated with the contact. + */ + #[JsonProperty('data'), ArrayType([Segment::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactSocialProfiles.php b/src/Types/ContactSocialProfiles.php new file mode 100644 index 00000000..61645e0c --- /dev/null +++ b/src/Types/ContactSocialProfiles.php @@ -0,0 +1,55 @@ + $data A list of social profiles objects associated with the contact. + */ + #[JsonProperty('data'), ArrayType([SocialProfile::class])] + private array $data; + + /** + * @param array{ + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->data = $values['data']; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactSubscriptionTypes.php b/src/Types/ContactSubscriptionTypes.php new file mode 100644 index 00000000..94585969 --- /dev/null +++ b/src/Types/ContactSubscriptionTypes.php @@ -0,0 +1,130 @@ + $data This object represents the subscriptions attached to a contact. + */ + #[JsonProperty('data'), ArrayType([AddressableList::class])] + private array $data; + + /** + * @var string $url Url to get more subscription type resources for this contact + */ + #[JsonProperty('url')] + private string $url; + + /** + * @var int $totalCount Int representing the total number of subscription types attached to this contact + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private bool $hasMore; + + /** + * @param array{ + * data: array, + * url: string, + * totalCount: int, + * hasMore: bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->data = $values['data']; + $this->url = $values['url']; + $this->totalCount = $values['totalCount']; + $this->hasMore = $values['hasMore']; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasMore(): bool + { + return $this->hasMore; + } + + /** + * @param bool $value + */ + public function setHasMore(bool $value): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactTags.php b/src/Types/ContactTags.php new file mode 100644 index 00000000..4810b9bd --- /dev/null +++ b/src/Types/ContactTags.php @@ -0,0 +1,130 @@ + $data This object represents the tags attached to a contact. + */ + #[JsonProperty('data'), ArrayType([AddressableList::class])] + private array $data; + + /** + * @var string $url url to get more tag resources for this contact + */ + #[JsonProperty('url')] + private string $url; + + /** + * @var int $totalCount Int representing the total number of tags attached to this contact + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private bool $hasMore; + + /** + * @param array{ + * data: array, + * url: string, + * totalCount: int, + * hasMore: bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->data = $values['data']; + $this->url = $values['url']; + $this->totalCount = $values['totalCount']; + $this->hasMore = $values['hasMore']; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasMore(): bool + { + return $this->hasMore; + } + + /** + * @param bool $value + */ + public function setHasMore(bool $value): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContactUnarchived.php b/src/Types/ContactUnarchived.php new file mode 100644 index 00000000..ff0df08c --- /dev/null +++ b/src/Types/ContactUnarchived.php @@ -0,0 +1,129 @@ +type = $values['type']; + $this->id = $values['id']; + $this->externalId = $values['externalId'] ?? null; + $this->archived = $values['archived']; + } + + /** + * @return 'contact' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'contact' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return bool + */ + public function getArchived(): bool + { + return $this->archived; + } + + /** + * @param bool $value + */ + public function setArchived(bool $value): self + { + $this->archived = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContentObject.php b/src/Types/ContentObject.php new file mode 100644 index 00000000..449307c5 --- /dev/null +++ b/src/Types/ContentObject.php @@ -0,0 +1,57 @@ + $components The list of components to be rendered. + */ + #[JsonProperty('components'), ArrayType([Component::class])] + private array $components; + + /** + * @param array{ + * components: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->components = $values['components']; + } + + /** + * @return array + */ + public function getComponents(): array + { + return $this->components; + } + + /** + * @param array $value + */ + public function setComponents(array $value): self + { + $this->components = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContentSourcesList.php b/src/Types/ContentSourcesList.php new file mode 100644 index 00000000..dd72fda5 --- /dev/null +++ b/src/Types/ContentSourcesList.php @@ -0,0 +1,103 @@ + $contentSources The content sources used by AI Agent in the conversation. + */ + #[JsonProperty('content_sources'), ArrayType([ContentSource::class])] + private array $contentSources; + + /** + * @param array{ + * type: 'content_source.list', + * totalCount: int, + * contentSources: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->totalCount = $values['totalCount']; + $this->contentSources = $values['contentSources']; + } + + /** + * @return 'content_source.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'content_source.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getContentSources(): array + { + return $this->contentSources; + } + + /** + * @param array $value + */ + public function setContentSources(array $value): self + { + $this->contentSources = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Context.php b/src/Types/Context.php new file mode 100644 index 00000000..7b884aa5 --- /dev/null +++ b/src/Types/Context.php @@ -0,0 +1,181 @@ + $location Where the app is added or the action took place. Can be either 'conversation', 'home', 'message', or 'operator'. + */ + #[JsonProperty('location')] + private ?string $location; + + /** + * @var ?string $locale The default end-user language of the Messenger. Use to localise Messenger App content. + */ + #[JsonProperty('locale')] + private ?string $locale; + + /** + * @var ?string $messengerActionColour The messengers action colour. Use in Sheets and Icons to make a Messenger App experience feel part of the host Messenger. + */ + #[JsonProperty('messenger_action_colour')] + private ?string $messengerActionColour; + + /** + * @var ?string $messengerBackgroundColour The messengers background colour. Use in Sheets and Icons to make a Messenger App experience feel part of the host Messenger. + */ + #[JsonProperty('messenger_background_colour')] + private ?string $messengerBackgroundColour; + + /** + * @var ?string $referrer The current page URL where the app is being used. + */ + #[JsonProperty('referrer')] + private ?string $referrer; + + /** + * @param array{ + * conversationId?: ?int, + * location?: ?value-of, + * locale?: ?string, + * messengerActionColour?: ?string, + * messengerBackgroundColour?: ?string, + * referrer?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->conversationId = $values['conversationId'] ?? null; + $this->location = $values['location'] ?? null; + $this->locale = $values['locale'] ?? null; + $this->messengerActionColour = $values['messengerActionColour'] ?? null; + $this->messengerBackgroundColour = $values['messengerBackgroundColour'] ?? null; + $this->referrer = $values['referrer'] ?? null; + } + + /** + * @return ?int + */ + public function getConversationId(): ?int + { + return $this->conversationId; + } + + /** + * @param ?int $value + */ + public function setConversationId(?int $value = null): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getLocation(): ?string + { + return $this->location; + } + + /** + * @param ?value-of $value + */ + public function setLocation(?string $value = null): self + { + $this->location = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLocale(): ?string + { + return $this->locale; + } + + /** + * @param ?string $value + */ + public function setLocale(?string $value = null): self + { + $this->locale = $value; + return $this; + } + + /** + * @return ?string + */ + public function getMessengerActionColour(): ?string + { + return $this->messengerActionColour; + } + + /** + * @param ?string $value + */ + public function setMessengerActionColour(?string $value = null): self + { + $this->messengerActionColour = $value; + return $this; + } + + /** + * @return ?string + */ + public function getMessengerBackgroundColour(): ?string + { + return $this->messengerBackgroundColour; + } + + /** + * @param ?string $value + */ + public function setMessengerBackgroundColour(?string $value = null): self + { + $this->messengerBackgroundColour = $value; + return $this; + } + + /** + * @return ?string + */ + public function getReferrer(): ?string + { + return $this->referrer; + } + + /** + * @param ?string $value + */ + public function setReferrer(?string $value = null): self + { + $this->referrer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ContextLocation.php b/src/Types/ContextLocation.php new file mode 100644 index 00000000..f0aa92dd --- /dev/null +++ b/src/Types/ContextLocation.php @@ -0,0 +1,11 @@ +contentType = $values['contentType']; + $this->data = $values['data']; + $this->name = $values['name']; + } + + /** + * @return string + */ + public function getContentType(): string + { + return $this->contentType; + } + + /** + * @param string $value + */ + public function setContentType(string $value): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return string + */ + public function getData(): string + { + return $this->data; + } + + /** + * @param string $value + */ + public function setData(string $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationContacts.php b/src/Types/ConversationContacts.php new file mode 100644 index 00000000..8989ef90 --- /dev/null +++ b/src/Types/ConversationContacts.php @@ -0,0 +1,80 @@ + $contacts The list of contacts (users or leads) involved in this conversation. This will only contain one customer unless more were added via the group conversation feature. + */ + #[JsonProperty('contacts'), ArrayType([ContactReference::class])] + private array $contacts; + + /** + * @param array{ + * type: 'contact.list', + * contacts: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->contacts = $values['contacts']; + } + + /** + * @return 'contact.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'contact.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getContacts(): array + { + return $this->contacts; + } + + /** + * @param array $value + */ + public function setContacts(array $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationFirstContactReply.php b/src/Types/ConversationFirstContactReply.php new file mode 100644 index 00000000..247e44bf --- /dev/null +++ b/src/Types/ConversationFirstContactReply.php @@ -0,0 +1,104 @@ +createdAt = $values['createdAt']; + $this->type = $values['type']; + $this->url = $values['url'] ?? null; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationPart.php b/src/Types/ConversationPart.php new file mode 100644 index 00000000..815e12ff --- /dev/null +++ b/src/Types/ConversationPart.php @@ -0,0 +1,330 @@ + $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?string $externalId The external id of the conversation part + */ + #[JsonProperty('external_id')] + private ?string $externalId; + + /** + * @var bool $redacted Whether or not the conversation part has been redacted. + */ + #[JsonProperty('redacted')] + private bool $redacted; + + /** + * @param array{ + * type: 'conversation_part', + * id: string, + * partType: string, + * createdAt: int, + * notifiedAt: int, + * author: ConversationPartAuthor, + * redacted: bool, + * body?: ?string, + * updatedAt?: ?int, + * assignedTo?: ?Reference, + * attachments?: ?array, + * externalId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->partType = $values['partType']; + $this->body = $values['body'] ?? null; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->notifiedAt = $values['notifiedAt']; + $this->assignedTo = $values['assignedTo'] ?? null; + $this->author = $values['author']; + $this->attachments = $values['attachments'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->redacted = $values['redacted']; + } + + /** + * @return 'conversation_part' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'conversation_part' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getPartType(): string + { + return $this->partType; + } + + /** + * @param string $value + */ + public function setPartType(string $value): self + { + $this->partType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return int + */ + public function getNotifiedAt(): int + { + return $this->notifiedAt; + } + + /** + * @param int $value + */ + public function setNotifiedAt(int $value): self + { + $this->notifiedAt = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getAssignedTo(): ?Reference + { + return $this->assignedTo; + } + + /** + * @param ?Reference $value + */ + public function setAssignedTo(?Reference $value = null): self + { + $this->assignedTo = $value; + return $this; + } + + /** + * @return ConversationPartAuthor + */ + public function getAuthor(): ConversationPartAuthor + { + return $this->author; + } + + /** + * @param ConversationPartAuthor $value + */ + public function setAuthor(ConversationPartAuthor $value): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return bool + */ + public function getRedacted(): bool + { + return $this->redacted; + } + + /** + * @param bool $value + */ + public function setRedacted(bool $value): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationPartAuthor.php b/src/Types/ConversationPartAuthor.php new file mode 100644 index 00000000..8bb3fa90 --- /dev/null +++ b/src/Types/ConversationPartAuthor.php @@ -0,0 +1,129 @@ +type = $values['type']; + $this->id = $values['id']; + $this->name = $values['name']; + $this->email = $values['email']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationParts.php b/src/Types/ConversationParts.php new file mode 100644 index 00000000..b3baa58c --- /dev/null +++ b/src/Types/ConversationParts.php @@ -0,0 +1,105 @@ + $conversationParts A list of Conversation Part objects for each part message in the conversation. This is only returned when Retrieving a Conversation, and ignored when Listing all Conversations. There is a limit of 500 parts. + */ + #[JsonProperty('conversation_parts'), ArrayType([ConversationPart::class])] + private array $conversationParts; + + /** + * @var int $totalCount + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @param array{ + * type: 'conversation_part.list', + * conversationParts: array, + * totalCount: int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->conversationParts = $values['conversationParts']; + $this->totalCount = $values['totalCount']; + } + + /** + * @return 'conversation_part.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'conversation_part.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getConversationParts(): array + { + return $this->conversationParts; + } + + /** + * @param array $value + */ + public function setConversationParts(array $value): self + { + $this->conversationParts = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationRating.php b/src/Types/ConversationRating.php new file mode 100644 index 00000000..41619f8c --- /dev/null +++ b/src/Types/ConversationRating.php @@ -0,0 +1,154 @@ +rating = $values['rating']; + $this->remark = $values['remark']; + $this->createdAt = $values['createdAt']; + $this->contact = $values['contact']; + $this->teammate = $values['teammate']; + } + + /** + * @return int + */ + public function getRating(): int + { + return $this->rating; + } + + /** + * @param int $value + */ + public function setRating(int $value): self + { + $this->rating = $value; + return $this; + } + + /** + * @return string + */ + public function getRemark(): string + { + return $this->remark; + } + + /** + * @param string $value + */ + public function setRemark(string $value): self + { + $this->remark = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ContactReference + */ + public function getContact(): ContactReference + { + return $this->contact; + } + + /** + * @param ContactReference $value + */ + public function setContact(ContactReference $value): self + { + $this->contact = $value; + return $this; + } + + /** + * @return Reference + */ + public function getTeammate(): Reference + { + return $this->teammate; + } + + /** + * @param Reference $value + */ + public function setTeammate(Reference $value): self + { + $this->teammate = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationSource.php b/src/Types/ConversationSource.php new file mode 100644 index 00000000..a2506eed --- /dev/null +++ b/src/Types/ConversationSource.php @@ -0,0 +1,255 @@ + $type This includes conversation, email, facebook, instagram, phone_call, phone_switch, push, sms, twitter and whatsapp. + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The id representing the message. + */ + #[JsonProperty('id')] + private string $id; + + /** + * @var string $deliveredAs The conversation's initiation type. Possible values are customer_initiated, campaigns_initiated (legacy campaigns), operator_initiated (Custom bot), automated (Series and other outbounds with dynamic audience message) and admin_initiated (fixed audience message, ticket initiated by an admin, group email). + */ + #[JsonProperty('delivered_as')] + private string $deliveredAs; + + /** + * @var string $subject Optional. The message subject. For Twitter, this will show a generic message regarding why the subject is obscured. + */ + #[JsonProperty('subject')] + private string $subject; + + /** + * @var ?string $body The message body, which may contain HTML. For Twitter, this will show a generic message regarding why the body is obscured. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var ConversationPartAuthor $author + */ + #[JsonProperty('author')] + private ConversationPartAuthor $author; + + /** + * @var ?array $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?string $url The URL where the conversation was started. For Twitter, Email, and Bots, this will be blank. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var bool $redacted Whether or not the source message has been redacted. Only applicable for contact initiated messages. + */ + #[JsonProperty('redacted')] + private bool $redacted; + + /** + * @param array{ + * type: value-of, + * id: string, + * deliveredAs: string, + * subject: string, + * author: ConversationPartAuthor, + * redacted: bool, + * body?: ?string, + * attachments?: ?array, + * url?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->deliveredAs = $values['deliveredAs']; + $this->subject = $values['subject']; + $this->body = $values['body'] ?? null; + $this->author = $values['author']; + $this->attachments = $values['attachments'] ?? null; + $this->url = $values['url'] ?? null; + $this->redacted = $values['redacted']; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getDeliveredAs(): string + { + return $this->deliveredAs; + } + + /** + * @param string $value + */ + public function setDeliveredAs(string $value): self + { + $this->deliveredAs = $value; + return $this; + } + + /** + * @return string + */ + public function getSubject(): string + { + return $this->subject; + } + + /** + * @param string $value + */ + public function setSubject(string $value): self + { + $this->subject = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ConversationPartAuthor + */ + public function getAuthor(): ConversationPartAuthor + { + return $this->author; + } + + /** + * @param ConversationPartAuthor $value + */ + public function setAuthor(ConversationPartAuthor $value): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return bool + */ + public function getRedacted(): bool + { + return $this->redacted; + } + + /** + * @param bool $value + */ + public function setRedacted(bool $value): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationSourceType.php b/src/Types/ConversationSourceType.php new file mode 100644 index 00000000..3486c1f8 --- /dev/null +++ b/src/Types/ConversationSourceType.php @@ -0,0 +1,17 @@ +type = $values['type']; + $this->timeToAssignment = $values['timeToAssignment'] ?? null; + $this->timeToAdminReply = $values['timeToAdminReply'] ?? null; + $this->timeToFirstClose = $values['timeToFirstClose'] ?? null; + $this->timeToLastClose = $values['timeToLastClose'] ?? null; + $this->medianTimeToReply = $values['medianTimeToReply'] ?? null; + $this->firstContactReplyAt = $values['firstContactReplyAt'] ?? null; + $this->firstAssignmentAt = $values['firstAssignmentAt'] ?? null; + $this->firstAdminReplyAt = $values['firstAdminReplyAt'] ?? null; + $this->firstCloseAt = $values['firstCloseAt'] ?? null; + $this->lastAssignmentAt = $values['lastAssignmentAt'] ?? null; + $this->lastAssignmentAdminReplyAt = $values['lastAssignmentAdminReplyAt'] ?? null; + $this->lastContactReplyAt = $values['lastContactReplyAt'] ?? null; + $this->lastAdminReplyAt = $values['lastAdminReplyAt'] ?? null; + $this->lastCloseAt = $values['lastCloseAt'] ?? null; + $this->lastClosedById = $values['lastClosedById'] ?? null; + $this->countReopens = $values['countReopens'] ?? null; + $this->countAssignments = $values['countAssignments'] ?? null; + $this->countConversationParts = $values['countConversationParts'] ?? null; + } + + /** + * @return 'conversation_statistics' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'conversation_statistics' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToAssignment(): ?int + { + return $this->timeToAssignment; + } + + /** + * @param ?int $value + */ + public function setTimeToAssignment(?int $value = null): self + { + $this->timeToAssignment = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToAdminReply(): ?int + { + return $this->timeToAdminReply; + } + + /** + * @param ?int $value + */ + public function setTimeToAdminReply(?int $value = null): self + { + $this->timeToAdminReply = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToFirstClose(): ?int + { + return $this->timeToFirstClose; + } + + /** + * @param ?int $value + */ + public function setTimeToFirstClose(?int $value = null): self + { + $this->timeToFirstClose = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToLastClose(): ?int + { + return $this->timeToLastClose; + } + + /** + * @param ?int $value + */ + public function setTimeToLastClose(?int $value = null): self + { + $this->timeToLastClose = $value; + return $this; + } + + /** + * @return ?int + */ + public function getMedianTimeToReply(): ?int + { + return $this->medianTimeToReply; + } + + /** + * @param ?int $value + */ + public function setMedianTimeToReply(?int $value = null): self + { + $this->medianTimeToReply = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstContactReplyAt(): ?int + { + return $this->firstContactReplyAt; + } + + /** + * @param ?int $value + */ + public function setFirstContactReplyAt(?int $value = null): self + { + $this->firstContactReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstAssignmentAt(): ?int + { + return $this->firstAssignmentAt; + } + + /** + * @param ?int $value + */ + public function setFirstAssignmentAt(?int $value = null): self + { + $this->firstAssignmentAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstAdminReplyAt(): ?int + { + return $this->firstAdminReplyAt; + } + + /** + * @param ?int $value + */ + public function setFirstAdminReplyAt(?int $value = null): self + { + $this->firstAdminReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstCloseAt(): ?int + { + return $this->firstCloseAt; + } + + /** + * @param ?int $value + */ + public function setFirstCloseAt(?int $value = null): self + { + $this->firstCloseAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastAssignmentAt(): ?int + { + return $this->lastAssignmentAt; + } + + /** + * @param ?int $value + */ + public function setLastAssignmentAt(?int $value = null): self + { + $this->lastAssignmentAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastAssignmentAdminReplyAt(): ?int + { + return $this->lastAssignmentAdminReplyAt; + } + + /** + * @param ?int $value + */ + public function setLastAssignmentAdminReplyAt(?int $value = null): self + { + $this->lastAssignmentAdminReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastContactReplyAt(): ?int + { + return $this->lastContactReplyAt; + } + + /** + * @param ?int $value + */ + public function setLastContactReplyAt(?int $value = null): self + { + $this->lastContactReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastAdminReplyAt(): ?int + { + return $this->lastAdminReplyAt; + } + + /** + * @param ?int $value + */ + public function setLastAdminReplyAt(?int $value = null): self + { + $this->lastAdminReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastCloseAt(): ?int + { + return $this->lastCloseAt; + } + + /** + * @param ?int $value + */ + public function setLastCloseAt(?int $value = null): self + { + $this->lastCloseAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLastClosedById(): ?string + { + return $this->lastClosedById; + } + + /** + * @param ?string $value + */ + public function setLastClosedById(?string $value = null): self + { + $this->lastClosedById = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCountReopens(): ?int + { + return $this->countReopens; + } + + /** + * @param ?int $value + */ + public function setCountReopens(?int $value = null): self + { + $this->countReopens = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCountAssignments(): ?int + { + return $this->countAssignments; + } + + /** + * @param ?int $value + */ + public function setCountAssignments(?int $value = null): self + { + $this->countAssignments = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCountConversationParts(): ?int + { + return $this->countConversationParts; + } + + /** + * @param ?int $value + */ + public function setCountConversationParts(?int $value = null): self + { + $this->countConversationParts = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ConversationTeammates.php b/src/Types/ConversationTeammates.php new file mode 100644 index 00000000..b32bab6b --- /dev/null +++ b/src/Types/ConversationTeammates.php @@ -0,0 +1,80 @@ + $admins The list of teammates who participated in the conversation (wrote at least one conversation part). + */ + #[JsonProperty('admins'), ArrayType([Reference::class])] + private array $admins; + + /** + * @param array{ + * type: 'admin.list', + * admins: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->admins = $values['admins']; + } + + /** + * @return 'admin.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getAdmins(): array + { + return $this->admins; + } + + /** + * @param array $value + */ + public function setAdmins(array $value): self + { + $this->admins = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateContactRequestWithEmail.php b/src/Types/CreateContactRequestWithEmail.php new file mode 100644 index 00000000..b571d6f1 --- /dev/null +++ b/src/Types/CreateContactRequestWithEmail.php @@ -0,0 +1,252 @@ + $customAttributes The custom attributes which are set for the contact + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * email: string, + * phone?: ?string, + * name?: ?string, + * avatar?: ?string, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * ownerId?: ?int, + * unsubscribedFromEmails?: ?bool, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->email = $values['email']; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateContactRequestWithExternalId.php b/src/Types/CreateContactRequestWithExternalId.php new file mode 100644 index 00000000..a57ef29a --- /dev/null +++ b/src/Types/CreateContactRequestWithExternalId.php @@ -0,0 +1,252 @@ + $customAttributes The custom attributes which are set for the contact + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * externalId: string, + * phone?: ?string, + * name?: ?string, + * avatar?: ?string, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * ownerId?: ?int, + * unsubscribedFromEmails?: ?bool, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->externalId = $values['externalId']; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateContactRequestWithRole.php b/src/Types/CreateContactRequestWithRole.php new file mode 100644 index 00000000..5d7c6e52 --- /dev/null +++ b/src/Types/CreateContactRequestWithRole.php @@ -0,0 +1,252 @@ + $customAttributes The custom attributes which are set for the contact + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * role: string, + * phone?: ?string, + * name?: ?string, + * avatar?: ?string, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * ownerId?: ?int, + * unsubscribedFromEmails?: ?bool, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->role = $values['role']; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getRole(): string + { + return $this->role; + } + + /** + * @param string $value + */ + public function setRole(string $value): self + { + $this->role = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateDataEventRequestWithEmail.php b/src/Types/CreateDataEventRequestWithEmail.php new file mode 100644 index 00000000..6036c4ce --- /dev/null +++ b/src/Types/CreateDataEventRequestWithEmail.php @@ -0,0 +1,127 @@ + $metadata Optional metadata about the event. + */ + #[JsonProperty('metadata'), ArrayType(['string' => 'string'])] + private ?array $metadata; + + /** + * @param array{ + * email: string, + * eventName: string, + * createdAt: int, + * metadata?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->email = $values['email']; + $this->eventName = $values['eventName']; + $this->createdAt = $values['createdAt']; + $this->metadata = $values['metadata'] ?? null; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function getEventName(): string + { + return $this->eventName; + } + + /** + * @param string $value + */ + public function setEventName(string $value): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getMetadata(): ?array + { + return $this->metadata; + } + + /** + * @param ?array $value + */ + public function setMetadata(?array $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateDataEventRequestWithId.php b/src/Types/CreateDataEventRequestWithId.php new file mode 100644 index 00000000..413a048f --- /dev/null +++ b/src/Types/CreateDataEventRequestWithId.php @@ -0,0 +1,127 @@ + $metadata Optional metadata about the event. + */ + #[JsonProperty('metadata'), ArrayType(['string' => 'string'])] + private ?array $metadata; + + /** + * @param array{ + * id: string, + * eventName: string, + * createdAt: int, + * metadata?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->eventName = $values['eventName']; + $this->createdAt = $values['createdAt']; + $this->metadata = $values['metadata'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getEventName(): string + { + return $this->eventName; + } + + /** + * @param string $value + */ + public function setEventName(string $value): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getMetadata(): ?array + { + return $this->metadata; + } + + /** + * @param ?array $value + */ + public function setMetadata(?array $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateDataEventRequestWithUserId.php b/src/Types/CreateDataEventRequestWithUserId.php new file mode 100644 index 00000000..291442ef --- /dev/null +++ b/src/Types/CreateDataEventRequestWithUserId.php @@ -0,0 +1,127 @@ + $metadata Optional metadata about the event. + */ + #[JsonProperty('metadata'), ArrayType(['string' => 'string'])] + private ?array $metadata; + + /** + * @param array{ + * userId: string, + * eventName: string, + * createdAt: int, + * metadata?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->userId = $values['userId']; + $this->eventName = $values['eventName']; + $this->createdAt = $values['createdAt']; + $this->metadata = $values['metadata'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function getEventName(): string + { + return $this->eventName; + } + + /** + * @param string $value + */ + public function setEventName(string $value): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getMetadata(): ?array + { + return $this->metadata; + } + + /** + * @param ?array $value + */ + public function setMetadata(?array $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateMessageRequest.php b/src/Types/CreateMessageRequest.php new file mode 100644 index 00000000..7bc95ec3 --- /dev/null +++ b/src/Types/CreateMessageRequest.php @@ -0,0 +1,236 @@ +messageType = $values['messageType']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'email' + * |'inapp' + * |'_unknown' + * ) + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @return ( + * CreateMessageRequestWithEmail + * |CreateMessageRequestWithInapp + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param CreateMessageRequestWithEmail $email + * @return CreateMessageRequest + */ + public static function email(CreateMessageRequestWithEmail $email): CreateMessageRequest + { + return new CreateMessageRequest([ + 'messageType' => 'email', + 'value' => $email, + ]); + } + + /** + * @param CreateMessageRequestWithInapp $inapp + * @return CreateMessageRequest + */ + public static function inapp(CreateMessageRequestWithInapp $inapp): CreateMessageRequest + { + return new CreateMessageRequest([ + 'messageType' => 'inapp', + 'value' => $inapp, + ]); + } + + /** + * @return bool + */ + public function isEmail(): bool + { + return $this->value instanceof CreateMessageRequestWithEmail && $this->messageType === 'email'; + } + + /** + * @return CreateMessageRequestWithEmail + */ + public function asEmail(): CreateMessageRequestWithEmail + { + if (!($this->value instanceof CreateMessageRequestWithEmail && $this->messageType === 'email')) { + throw new Exception( + "Expected email; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isInapp(): bool + { + return $this->value instanceof CreateMessageRequestWithInapp && $this->messageType === 'inapp'; + } + + /** + * @return CreateMessageRequestWithInapp + */ + public function asInapp(): CreateMessageRequestWithInapp + { + if (!($this->value instanceof CreateMessageRequestWithInapp && $this->messageType === 'inapp')) { + throw new Exception( + "Expected inapp; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['message_type'] = $this->messageType; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->messageType) { + case 'email': + $value = $this->asEmail()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'inapp': + $value = $this->asInapp()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('message_type', $data)) { + throw new Exception( + "JSON data is missing property 'message_type'", + ); + } + $messageType = $data['message_type']; + if (!(is_string($messageType))) { + throw new Exception( + "Expected property 'messageType' in JSON data to be string, instead received " . get_debug_type($data['message_type']), + ); + } + + $args['messageType'] = $messageType; + switch ($messageType) { + case 'email': + $args['value'] = CreateMessageRequestWithEmail::jsonDeserialize($data); + break; + case 'inapp': + $args['value'] = CreateMessageRequestWithInapp::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['messageType'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Types/CreateMessageRequestFrom.php b/src/Types/CreateMessageRequestFrom.php new file mode 100644 index 00000000..05c1c1da --- /dev/null +++ b/src/Types/CreateMessageRequestFrom.php @@ -0,0 +1,79 @@ +type = $values['type']; + $this->id = $values['id']; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateMessageRequestTo.php b/src/Types/CreateMessageRequestTo.php new file mode 100644 index 00000000..9bf4146d --- /dev/null +++ b/src/Types/CreateMessageRequestTo.php @@ -0,0 +1,79 @@ + $type The role associated to the contact - `user` or `lead`. + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The identifier for the contact which is given by Intercom. + */ + #[JsonProperty('id')] + private string $id; + + /** + * @param array{ + * type: value-of, + * id: string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateMessageRequestType.php b/src/Types/CreateMessageRequestType.php new file mode 100644 index 00000000..b9e2e7d0 --- /dev/null +++ b/src/Types/CreateMessageRequestType.php @@ -0,0 +1,9 @@ +subject = $values['subject']; + $this->body = $values['body']; + $this->template = $values['template']; + $this->from = $values['from']; + $this->to = $values['to']; + $this->createdAt = $values['createdAt'] ?? null; + $this->createConversationWithoutContactReply = $values['createConversationWithoutContactReply'] ?? null; + } + + /** + * @return string + */ + public function getSubject(): string + { + return $this->subject; + } + + /** + * @param string $value + */ + public function setSubject(string $value): self + { + $this->subject = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function getTemplate(): string + { + return $this->template; + } + + /** + * @param string $value + */ + public function setTemplate(string $value): self + { + $this->template = $value; + return $this; + } + + /** + * @return CreateMessageRequestFrom + */ + public function getFrom(): CreateMessageRequestFrom + { + return $this->from; + } + + /** + * @param CreateMessageRequestFrom $value + */ + public function setFrom(CreateMessageRequestFrom $value): self + { + $this->from = $value; + return $this; + } + + /** + * @return CreateMessageRequestTo + */ + public function getTo(): CreateMessageRequestTo + { + return $this->to; + } + + /** + * @param CreateMessageRequestTo $value + */ + public function setTo(CreateMessageRequestTo $value): self + { + $this->to = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getCreateConversationWithoutContactReply(): ?bool + { + return $this->createConversationWithoutContactReply; + } + + /** + * @param ?bool $value + */ + public function setCreateConversationWithoutContactReply(?bool $value = null): self + { + $this->createConversationWithoutContactReply = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateMessageRequestWithInapp.php b/src/Types/CreateMessageRequestWithInapp.php new file mode 100644 index 00000000..23a0dcc4 --- /dev/null +++ b/src/Types/CreateMessageRequestWithInapp.php @@ -0,0 +1,201 @@ +subject = $values['subject'] ?? null; + $this->body = $values['body']; + $this->template = $values['template'] ?? null; + $this->from = $values['from']; + $this->to = $values['to']; + $this->createdAt = $values['createdAt'] ?? null; + $this->createConversationWithoutContactReply = $values['createConversationWithoutContactReply'] ?? null; + } + + /** + * @return ?string + */ + public function getSubject(): ?string + { + return $this->subject; + } + + /** + * @param ?string $value + */ + public function setSubject(?string $value = null): self + { + $this->subject = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTemplate(): ?string + { + return $this->template; + } + + /** + * @param ?string $value + */ + public function setTemplate(?string $value = null): self + { + $this->template = $value; + return $this; + } + + /** + * @return CreateMessageRequestFrom + */ + public function getFrom(): CreateMessageRequestFrom + { + return $this->from; + } + + /** + * @param CreateMessageRequestFrom $value + */ + public function setFrom(CreateMessageRequestFrom $value): self + { + $this->from = $value; + return $this; + } + + /** + * @return CreateMessageRequestTo + */ + public function getTo(): CreateMessageRequestTo + { + return $this->to; + } + + /** + * @param CreateMessageRequestTo $value + */ + public function setTo(CreateMessageRequestTo $value): self + { + $this->to = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getCreateConversationWithoutContactReply(): ?bool + { + return $this->createConversationWithoutContactReply; + } + + /** + * @param ?bool $value + */ + public function setCreateConversationWithoutContactReply(?bool $value = null): self + { + $this->createConversationWithoutContactReply = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateOrUpdateTagRequest.php b/src/Types/CreateOrUpdateTagRequest.php new file mode 100644 index 00000000..72556e8e --- /dev/null +++ b/src/Types/CreateOrUpdateTagRequest.php @@ -0,0 +1,79 @@ +name = $values['name']; + $this->id = $values['id'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateTicketRequest.php b/src/Types/CreateTicketRequest.php new file mode 100644 index 00000000..a0bb8d5f --- /dev/null +++ b/src/Types/CreateTicketRequest.php @@ -0,0 +1,172 @@ + $contacts The list of contacts (users or leads) affected by this ticket. Currently only one is allowed + */ + #[JsonProperty('contacts'), ArrayType([new Union(CreateTicketRequestContactsItemId::class, CreateTicketRequestContactsItemExternalId::class, CreateTicketRequestContactsItemEmail::class)])] + private array $contacts; + + /** + * @var ?string $companyId The ID of the company that the ticket is associated with. The ID that you set upon company creation. + */ + #[JsonProperty('company_id')] + private ?string $companyId; + + /** + * @var ?int $createdAt The time the ticket was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $ticketAttributes + */ + #[JsonProperty('ticket_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $ticketAttributes; + + /** + * @param array{ + * ticketTypeId: string, + * contacts: array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )>, + * companyId?: ?string, + * createdAt?: ?int, + * ticketAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->ticketTypeId = $values['ticketTypeId']; + $this->contacts = $values['contacts']; + $this->companyId = $values['companyId'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->ticketAttributes = $values['ticketAttributes'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> + */ + public function getContacts(): array + { + return $this->contacts; + } + + /** + * @param array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> $value + */ + public function setContacts(array $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTicketAttributes(): ?array + { + return $this->ticketAttributes; + } + + /** + * @param ?array $value + */ + public function setTicketAttributes(?array $value = null): self + { + $this->ticketAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateTicketRequestContactsItemEmail.php b/src/Types/CreateTicketRequestContactsItemEmail.php new file mode 100644 index 00000000..7e6774aa --- /dev/null +++ b/src/Types/CreateTicketRequestContactsItemEmail.php @@ -0,0 +1,51 @@ +email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateTicketRequestContactsItemExternalId.php b/src/Types/CreateTicketRequestContactsItemExternalId.php new file mode 100644 index 00000000..159807f5 --- /dev/null +++ b/src/Types/CreateTicketRequestContactsItemExternalId.php @@ -0,0 +1,51 @@ +externalId = $values['externalId']; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CreateTicketRequestContactsItemId.php b/src/Types/CreateTicketRequestContactsItemId.php new file mode 100644 index 00000000..d205be5e --- /dev/null +++ b/src/Types/CreateTicketRequestContactsItemId.php @@ -0,0 +1,51 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CurrentCanvas.php b/src/Types/CurrentCanvas.php new file mode 100644 index 00000000..07cea618 --- /dev/null +++ b/src/Types/CurrentCanvas.php @@ -0,0 +1,54 @@ +currentCanvas = $values['currentCanvas']; + } + + /** + * @return CanvasObject + */ + public function getCurrentCanvas(): CanvasObject + { + return $this->currentCanvas; + } + + /** + * @param CanvasObject $value + */ + public function setCurrentCanvas(CanvasObject $value): self + { + $this->currentCanvas = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CursorPages.php b/src/Types/CursorPages.php new file mode 100644 index 00000000..eafc2154 --- /dev/null +++ b/src/Types/CursorPages.php @@ -0,0 +1,155 @@ +type = $values['type']; + $this->page = $values['page'] ?? null; + $this->next = $values['next'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->totalPages = $values['totalPages'] ?? null; + } + + /** + * @return 'pages' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'pages' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?StartingAfterPaging + */ + public function getNext(): ?StartingAfterPaging + { + return $this->next; + } + + /** + * @param ?StartingAfterPaging $value + */ + public function setNext(?StartingAfterPaging $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalPages(): ?int + { + return $this->totalPages; + } + + /** + * @param ?int $value + */ + public function setTotalPages(?int $value = null): self + { + $this->totalPages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CustomerRequestEmail.php b/src/Types/CustomerRequestEmail.php new file mode 100644 index 00000000..e40b94f4 --- /dev/null +++ b/src/Types/CustomerRequestEmail.php @@ -0,0 +1,51 @@ +email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CustomerRequestIntercomUserId.php b/src/Types/CustomerRequestIntercomUserId.php new file mode 100644 index 00000000..96867408 --- /dev/null +++ b/src/Types/CustomerRequestIntercomUserId.php @@ -0,0 +1,51 @@ +intercomUserId = $values['intercomUserId']; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/CustomerRequestUserId.php b/src/Types/CustomerRequestUserId.php new file mode 100644 index 00000000..79f3bfe5 --- /dev/null +++ b/src/Types/CustomerRequestUserId.php @@ -0,0 +1,51 @@ +userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataAttributeList.php b/src/Types/DataAttributeList.php new file mode 100644 index 00000000..47b9e8c1 --- /dev/null +++ b/src/Types/DataAttributeList.php @@ -0,0 +1,81 @@ + $data A list of data attributes + */ + #[JsonProperty('data'), ArrayType([DataAttribute::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataEventList.php b/src/Types/DataEventList.php new file mode 100644 index 00000000..47cbb0a4 --- /dev/null +++ b/src/Types/DataEventList.php @@ -0,0 +1,106 @@ + $events A list of data events + */ + #[JsonProperty('events'), ArrayType([DataEvent::class])] + private array $events; + + /** + * @var ?DataEventListPages $pages Pagination + */ + #[JsonProperty('pages')] + private ?DataEventListPages $pages; + + /** + * @param array{ + * type: 'event.list', + * events: array, + * pages?: ?DataEventListPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->events = $values['events']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'event.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'event.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getEvents(): array + { + return $this->events; + } + + /** + * @param array $value + */ + public function setEvents(array $value): self + { + $this->events = $value; + return $this; + } + + /** + * @return ?DataEventListPages + */ + public function getPages(): ?DataEventListPages + { + return $this->pages; + } + + /** + * @param ?DataEventListPages $value + */ + public function setPages(?DataEventListPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataEventListPages.php b/src/Types/DataEventListPages.php new file mode 100644 index 00000000..b4df1f94 --- /dev/null +++ b/src/Types/DataEventListPages.php @@ -0,0 +1,79 @@ +next = $values['next'] ?? null; + $this->since = $values['since'] ?? null; + } + + /** + * @return ?string + */ + public function getNext(): ?string + { + return $this->next; + } + + /** + * @param ?string $value + */ + public function setNext(?string $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSince(): ?string + { + return $this->since; + } + + /** + * @param ?string $value + */ + public function setSince(?string $value = null): self + { + $this->since = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataEventSummary.php b/src/Types/DataEventSummary.php new file mode 100644 index 00000000..46cf0a3e --- /dev/null +++ b/src/Types/DataEventSummary.php @@ -0,0 +1,155 @@ + $events A summary of data events + */ + #[JsonProperty('events'), ArrayType([DataEventSummaryItem::class])] + private array $events; + + /** + * @param array{ + * events: array, + * type?: ?'event.summary', + * email?: ?string, + * intercomUserId?: ?string, + * userId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->email = $values['email'] ?? null; + $this->intercomUserId = $values['intercomUserId'] ?? null; + $this->userId = $values['userId'] ?? null; + $this->events = $values['events']; + } + + /** + * @return ?'event.summary' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'event.summary' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIntercomUserId(): ?string + { + return $this->intercomUserId; + } + + /** + * @param ?string $value + */ + public function setIntercomUserId(?string $value = null): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return array + */ + public function getEvents(): array + { + return $this->events; + } + + /** + * @param array $value + */ + public function setEvents(array $value): self + { + $this->events = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataEventSummaryItem.php b/src/Types/DataEventSummaryItem.php new file mode 100644 index 00000000..472855ce --- /dev/null +++ b/src/Types/DataEventSummaryItem.php @@ -0,0 +1,154 @@ +name = $values['name']; + $this->first = $values['first']; + $this->last = $values['last']; + $this->count = $values['count']; + $this->description = $values['description'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getFirst(): string + { + return $this->first; + } + + /** + * @param string $value + */ + public function setFirst(string $value): self + { + $this->first = $value; + return $this; + } + + /** + * @return string + */ + public function getLast(): string + { + return $this->last; + } + + /** + * @param string $value + */ + public function setLast(string $value): self + { + $this->last = $value; + return $this; + } + + /** + * @return int + */ + public function getCount(): int + { + return $this->count; + } + + /** + * @param int $value + */ + public function setCount(int $value): self + { + $this->count = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataExportCsv.php b/src/Types/DataExportCsv.php new file mode 100644 index 00000000..8edf656d --- /dev/null +++ b/src/Types/DataExportCsv.php @@ -0,0 +1,679 @@ +userId = $values['userId']; + $this->userExternalId = $values['userExternalId'] ?? null; + $this->companyId = $values['companyId']; + $this->email = $values['email']; + $this->name = $values['name']; + $this->rulesetId = $values['rulesetId']; + $this->contentId = $values['contentId']; + $this->contentType = $values['contentType']; + $this->contentTitle = $values['contentTitle']; + $this->rulesetVersionId = $values['rulesetVersionId'] ?? null; + $this->receiptId = $values['receiptId'] ?? null; + $this->receivedAt = $values['receivedAt'] ?? null; + $this->seriesId = $values['seriesId'] ?? null; + $this->seriesTitle = $values['seriesTitle'] ?? null; + $this->nodeId = $values['nodeId'] ?? null; + $this->firstReply = $values['firstReply'] ?? null; + $this->firstCompletion = $values['firstCompletion'] ?? null; + $this->firstSeriesCompletion = $values['firstSeriesCompletion'] ?? null; + $this->firstSeriesDisengagement = $values['firstSeriesDisengagement'] ?? null; + $this->firstSeriesExit = $values['firstSeriesExit'] ?? null; + $this->firstGoalSuccess = $values['firstGoalSuccess'] ?? null; + $this->firstOpen = $values['firstOpen'] ?? null; + $this->firstClick = $values['firstClick'] ?? null; + $this->firstDismisall = $values['firstDismisall'] ?? null; + $this->firstUnsubscribe = $values['firstUnsubscribe'] ?? null; + $this->firstHardBounce = $values['firstHardBounce'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserExternalId(): ?string + { + return $this->userExternalId; + } + + /** + * @param ?string $value + */ + public function setUserExternalId(?string $value = null): self + { + $this->userExternalId = $value; + return $this; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getRulesetId(): string + { + return $this->rulesetId; + } + + /** + * @param string $value + */ + public function setRulesetId(string $value): self + { + $this->rulesetId = $value; + return $this; + } + + /** + * @return string + */ + public function getContentId(): string + { + return $this->contentId; + } + + /** + * @param string $value + */ + public function setContentId(string $value): self + { + $this->contentId = $value; + return $this; + } + + /** + * @return string + */ + public function getContentType(): string + { + return $this->contentType; + } + + /** + * @param string $value + */ + public function setContentType(string $value): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return string + */ + public function getContentTitle(): string + { + return $this->contentTitle; + } + + /** + * @param string $value + */ + public function setContentTitle(string $value): self + { + $this->contentTitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRulesetVersionId(): ?string + { + return $this->rulesetVersionId; + } + + /** + * @param ?string $value + */ + public function setRulesetVersionId(?string $value = null): self + { + $this->rulesetVersionId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getReceiptId(): ?string + { + return $this->receiptId; + } + + /** + * @param ?string $value + */ + public function setReceiptId(?string $value = null): self + { + $this->receiptId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getReceivedAt(): ?int + { + return $this->receivedAt; + } + + /** + * @param ?int $value + */ + public function setReceivedAt(?int $value = null): self + { + $this->receivedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSeriesId(): ?string + { + return $this->seriesId; + } + + /** + * @param ?string $value + */ + public function setSeriesId(?string $value = null): self + { + $this->seriesId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSeriesTitle(): ?string + { + return $this->seriesTitle; + } + + /** + * @param ?string $value + */ + public function setSeriesTitle(?string $value = null): self + { + $this->seriesTitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getNodeId(): ?string + { + return $this->nodeId; + } + + /** + * @param ?string $value + */ + public function setNodeId(?string $value = null): self + { + $this->nodeId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstReply(): ?int + { + return $this->firstReply; + } + + /** + * @param ?int $value + */ + public function setFirstReply(?int $value = null): self + { + $this->firstReply = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstCompletion(): ?int + { + return $this->firstCompletion; + } + + /** + * @param ?int $value + */ + public function setFirstCompletion(?int $value = null): self + { + $this->firstCompletion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstSeriesCompletion(): ?int + { + return $this->firstSeriesCompletion; + } + + /** + * @param ?int $value + */ + public function setFirstSeriesCompletion(?int $value = null): self + { + $this->firstSeriesCompletion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstSeriesDisengagement(): ?int + { + return $this->firstSeriesDisengagement; + } + + /** + * @param ?int $value + */ + public function setFirstSeriesDisengagement(?int $value = null): self + { + $this->firstSeriesDisengagement = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstSeriesExit(): ?int + { + return $this->firstSeriesExit; + } + + /** + * @param ?int $value + */ + public function setFirstSeriesExit(?int $value = null): self + { + $this->firstSeriesExit = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstGoalSuccess(): ?int + { + return $this->firstGoalSuccess; + } + + /** + * @param ?int $value + */ + public function setFirstGoalSuccess(?int $value = null): self + { + $this->firstGoalSuccess = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstOpen(): ?int + { + return $this->firstOpen; + } + + /** + * @param ?int $value + */ + public function setFirstOpen(?int $value = null): self + { + $this->firstOpen = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstClick(): ?int + { + return $this->firstClick; + } + + /** + * @param ?int $value + */ + public function setFirstClick(?int $value = null): self + { + $this->firstClick = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstDismisall(): ?int + { + return $this->firstDismisall; + } + + /** + * @param ?int $value + */ + public function setFirstDismisall(?int $value = null): self + { + $this->firstDismisall = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstUnsubscribe(): ?int + { + return $this->firstUnsubscribe; + } + + /** + * @param ?int $value + */ + public function setFirstUnsubscribe(?int $value = null): self + { + $this->firstUnsubscribe = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstHardBounce(): ?int + { + return $this->firstHardBounce; + } + + /** + * @param ?int $value + */ + public function setFirstHardBounce(?int $value = null): self + { + $this->firstHardBounce = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataTableComponent.php b/src/Types/DataTableComponent.php new file mode 100644 index 00000000..6fc12443 --- /dev/null +++ b/src/Types/DataTableComponent.php @@ -0,0 +1,55 @@ + $items The items that will be rendered in the data-table. + */ + #[JsonProperty('items'), ArrayType([DataTableItem::class])] + private array $items; + + /** + * @param array{ + * items: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->items = $values['items']; + } + + /** + * @return array + */ + public function getItems(): array + { + return $this->items; + } + + /** + * @param array $value + */ + public function setItems(array $value): self + { + $this->items = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DataTableItem.php b/src/Types/DataTableItem.php new file mode 100644 index 00000000..1b5221cf --- /dev/null +++ b/src/Types/DataTableItem.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->field = $values['field']; + $this->value = $values['value']; + } + + /** + * @return 'field-value' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'field-value' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getField(): string + { + return $this->field; + } + + /** + * @param string $value + */ + public function setField(string $value): self + { + $this->field = $value; + return $this; + } + + /** + * @return string + */ + public function getValue(): string + { + return $this->value; + } + + /** + * @param string $value + */ + public function setValue(string $value): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DeletedArticleObject.php b/src/Types/DeletedArticleObject.php new file mode 100644 index 00000000..c0e896d7 --- /dev/null +++ b/src/Types/DeletedArticleObject.php @@ -0,0 +1,104 @@ +id = $values['id']; + $this->object = $values['object']; + $this->deleted = $values['deleted']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'article' + */ + public function getObject(): string + { + return $this->object; + } + + /** + * @param 'article' $value + */ + public function setObject(string $value): self + { + $this->object = $value; + return $this; + } + + /** + * @return bool + */ + public function getDeleted(): bool + { + return $this->deleted; + } + + /** + * @param bool $value + */ + public function setDeleted(bool $value): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DeletedCollectionObject.php b/src/Types/DeletedCollectionObject.php new file mode 100644 index 00000000..7dd2b84e --- /dev/null +++ b/src/Types/DeletedCollectionObject.php @@ -0,0 +1,104 @@ +id = $values['id']; + $this->object = $values['object']; + $this->deleted = $values['deleted']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'collection' + */ + public function getObject(): string + { + return $this->object; + } + + /** + * @param 'collection' $value + */ + public function setObject(string $value): self + { + $this->object = $value; + return $this; + } + + /** + * @return bool + */ + public function getDeleted(): bool + { + return $this->deleted; + } + + /** + * @param bool $value + */ + public function setDeleted(bool $value): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DeletedCompanyObject.php b/src/Types/DeletedCompanyObject.php new file mode 100644 index 00000000..b22524d9 --- /dev/null +++ b/src/Types/DeletedCompanyObject.php @@ -0,0 +1,104 @@ +id = $values['id']; + $this->object = $values['object']; + $this->deleted = $values['deleted']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'company' + */ + public function getObject(): string + { + return $this->object; + } + + /** + * @param 'company' $value + */ + public function setObject(string $value): self + { + $this->object = $value; + return $this; + } + + /** + * @return bool + */ + public function getDeleted(): bool + { + return $this->deleted; + } + + /** + * @param bool $value + */ + public function setDeleted(bool $value): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DeletedObject.php b/src/Types/DeletedObject.php new file mode 100644 index 00000000..1faa5041 --- /dev/null +++ b/src/Types/DeletedObject.php @@ -0,0 +1,104 @@ +id = $values['id']; + $this->object = $values['object']; + $this->deleted = $values['deleted']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'news-item' + */ + public function getObject(): string + { + return $this->object; + } + + /** + * @param 'news-item' $value + */ + public function setObject(string $value): self + { + $this->object = $value; + return $this; + } + + /** + * @return bool + */ + public function getDeleted(): bool + { + return $this->deleted; + } + + /** + * @param bool $value + */ + public function setDeleted(bool $value): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DividerComponent.php b/src/Types/DividerComponent.php new file mode 100644 index 00000000..5423f26c --- /dev/null +++ b/src/Types/DividerComponent.php @@ -0,0 +1,79 @@ +id = $values['id'] ?? null; + $this->bottomMargin = $values['bottomMargin'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'none' + */ + public function getBottomMargin(): ?string + { + return $this->bottomMargin; + } + + /** + * @param ?'none' $value + */ + public function setBottomMargin(?string $value = null): self + { + $this->bottomMargin = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DropdownComponent.php b/src/Types/DropdownComponent.php new file mode 100644 index 00000000..061c327d --- /dev/null +++ b/src/Types/DropdownComponent.php @@ -0,0 +1,182 @@ + $options The list of options. Can provide 2 to 10. + */ + #[JsonProperty('options'), ArrayType([DropdownOption::class])] + private array $options; + + /** + * @var ?string $label The text shown above the dropdown. + */ + #[JsonProperty('label')] + private ?string $label; + + /** + * @var ?string $value The option that is selected by default. + */ + #[JsonProperty('value')] + private ?string $value; + + /** + * @var ?value-of $saveState Styles all options and prevents the action. Default is `unsaved`. Will be overridden if `save_state` is `saved`. + */ + #[JsonProperty('save_state')] + private ?string $saveState; + + /** + * @var ?bool $disabled Styles all options and prevents the action. Default is false. Will be overridden if save_state is saved. + */ + #[JsonProperty('disabled')] + private ?bool $disabled; + + /** + * @param array{ + * id: string, + * options: array, + * label?: ?string, + * value?: ?string, + * saveState?: ?value-of, + * disabled?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->options = $values['options']; + $this->label = $values['label'] ?? null; + $this->value = $values['value'] ?? null; + $this->saveState = $values['saveState'] ?? null; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @param array $value + */ + public function setOptions(array $value): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLabel(): ?string + { + return $this->label; + } + + /** + * @param ?string $value + */ + public function setLabel(?string $value = null): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * @param ?string $value + */ + public function setValue(?string $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getSaveState(): ?string + { + return $this->saveState; + } + + /** + * @param ?value-of $value + */ + public function setSaveState(?string $value = null): self + { + $this->saveState = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/DropdownComponentSaveState.php b/src/Types/DropdownComponentSaveState.php new file mode 100644 index 00000000..542de8df --- /dev/null +++ b/src/Types/DropdownComponentSaveState.php @@ -0,0 +1,10 @@ +type = $values['type']; + $this->id = $values['id']; + $this->text = $values['text']; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return 'option' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'option' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Error.php b/src/Types/Error.php new file mode 100644 index 00000000..dcbfe99b --- /dev/null +++ b/src/Types/Error.php @@ -0,0 +1,105 @@ + $errors An array of one or more error objects + */ + #[JsonProperty('errors'), ArrayType([ErrorErrorsItem::class])] + private array $errors; + + /** + * @param array{ + * type: 'error.list', + * errors: array, + * requestId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->requestId = $values['requestId'] ?? null; + $this->errors = $values['errors']; + } + + /** + * @return 'error.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'error.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRequestId(): ?string + { + return $this->requestId; + } + + /** + * @param ?string $value + */ + public function setRequestId(?string $value = null): self + { + $this->requestId = $value; + return $this; + } + + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * @param array $value + */ + public function setErrors(array $value): self + { + $this->errors = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ErrorErrorsItem.php b/src/Types/ErrorErrorsItem.php new file mode 100644 index 00000000..98d57e1e --- /dev/null +++ b/src/Types/ErrorErrorsItem.php @@ -0,0 +1,101 @@ +code = $values['code']; + $this->message = $values['message'] ?? null; + $this->field = $values['field'] ?? null; + } + + /** + * @return string + */ + public function getCode(): string + { + return $this->code; + } + + /** + * @param string $value + */ + public function setCode(string $value): self + { + $this->code = $value; + return $this; + } + + /** + * @return ?string + */ + public function getMessage(): ?string + { + return $this->message; + } + + /** + * @param ?string $value + */ + public function setMessage(?string $value = null): self + { + $this->message = $value; + return $this; + } + + /** + * @return ?string + */ + public function getField(): ?string + { + return $this->field; + } + + /** + * @param ?string $value + */ + public function setField(?string $value = null): self + { + $this->field = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Event.php b/src/Types/Event.php new file mode 100644 index 00000000..e9b90faf --- /dev/null +++ b/src/Types/Event.php @@ -0,0 +1,54 @@ +type = $values['type']; + } + + /** + * @return 'completed' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'completed' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/FileAttribute.php b/src/Types/FileAttribute.php new file mode 100644 index 00000000..60ed9619 --- /dev/null +++ b/src/Types/FileAttribute.php @@ -0,0 +1,204 @@ +type = $values['type']; + $this->name = $values['name']; + $this->url = $values['url']; + $this->contentType = $values['contentType']; + $this->filesize = $values['filesize']; + $this->width = $values['width']; + $this->height = $values['height']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function getContentType(): string + { + return $this->contentType; + } + + /** + * @param string $value + */ + public function setContentType(string $value): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return int + */ + public function getFilesize(): int + { + return $this->filesize; + } + + /** + * @param int $value + */ + public function setFilesize(int $value): self + { + $this->filesize = $value; + return $this; + } + + /** + * @return int + */ + public function getWidth(): int + { + return $this->width; + } + + /** + * @param int $value + */ + public function setWidth(int $value): self + { + $this->width = $value; + return $this; + } + + /** + * @return int + */ + public function getHeight(): int + { + return $this->height; + } + + /** + * @param int $value + */ + public function setHeight(int $value): self + { + $this->height = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/GroupContent.php b/src/Types/GroupContent.php new file mode 100644 index 00000000..52f43d64 --- /dev/null +++ b/src/Types/GroupContent.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->name = $values['name']; + $this->description = $values['description']; + } + + /** + * @return 'group_content' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'group_content' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/GroupTranslatedContent.php b/src/Types/GroupTranslatedContent.php new file mode 100644 index 00000000..77b3be4d --- /dev/null +++ b/src/Types/GroupTranslatedContent.php @@ -0,0 +1,979 @@ +type = $values['type']; + $this->ar = $values['ar'] ?? null; + $this->bg = $values['bg'] ?? null; + $this->bs = $values['bs'] ?? null; + $this->ca = $values['ca'] ?? null; + $this->cs = $values['cs'] ?? null; + $this->da = $values['da'] ?? null; + $this->de = $values['de'] ?? null; + $this->el = $values['el'] ?? null; + $this->en = $values['en'] ?? null; + $this->es = $values['es'] ?? null; + $this->et = $values['et'] ?? null; + $this->fi = $values['fi'] ?? null; + $this->fr = $values['fr'] ?? null; + $this->he = $values['he'] ?? null; + $this->hr = $values['hr'] ?? null; + $this->hu = $values['hu'] ?? null; + $this->id = $values['id'] ?? null; + $this->it = $values['it'] ?? null; + $this->ja = $values['ja'] ?? null; + $this->ko = $values['ko'] ?? null; + $this->lt = $values['lt'] ?? null; + $this->lv = $values['lv'] ?? null; + $this->mn = $values['mn'] ?? null; + $this->nb = $values['nb'] ?? null; + $this->nl = $values['nl'] ?? null; + $this->pl = $values['pl'] ?? null; + $this->pt = $values['pt'] ?? null; + $this->ro = $values['ro'] ?? null; + $this->ru = $values['ru'] ?? null; + $this->sl = $values['sl'] ?? null; + $this->sr = $values['sr'] ?? null; + $this->sv = $values['sv'] ?? null; + $this->tr = $values['tr'] ?? null; + $this->vi = $values['vi'] ?? null; + $this->ptBr = $values['ptBr'] ?? null; + $this->zhCn = $values['zhCn'] ?? null; + $this->zhTw = $values['zhTw'] ?? null; + } + + /** + * @return 'group_translated_content' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'group_translated_content' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getAr(): ?GroupContent + { + return $this->ar; + } + + /** + * @param ?GroupContent $value + */ + public function setAr(?GroupContent $value = null): self + { + $this->ar = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getBg(): ?GroupContent + { + return $this->bg; + } + + /** + * @param ?GroupContent $value + */ + public function setBg(?GroupContent $value = null): self + { + $this->bg = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getBs(): ?GroupContent + { + return $this->bs; + } + + /** + * @param ?GroupContent $value + */ + public function setBs(?GroupContent $value = null): self + { + $this->bs = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getCa(): ?GroupContent + { + return $this->ca; + } + + /** + * @param ?GroupContent $value + */ + public function setCa(?GroupContent $value = null): self + { + $this->ca = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getCs(): ?GroupContent + { + return $this->cs; + } + + /** + * @param ?GroupContent $value + */ + public function setCs(?GroupContent $value = null): self + { + $this->cs = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getDa(): ?GroupContent + { + return $this->da; + } + + /** + * @param ?GroupContent $value + */ + public function setDa(?GroupContent $value = null): self + { + $this->da = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getDe(): ?GroupContent + { + return $this->de; + } + + /** + * @param ?GroupContent $value + */ + public function setDe(?GroupContent $value = null): self + { + $this->de = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEl(): ?GroupContent + { + return $this->el; + } + + /** + * @param ?GroupContent $value + */ + public function setEl(?GroupContent $value = null): self + { + $this->el = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEn(): ?GroupContent + { + return $this->en; + } + + /** + * @param ?GroupContent $value + */ + public function setEn(?GroupContent $value = null): self + { + $this->en = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEs(): ?GroupContent + { + return $this->es; + } + + /** + * @param ?GroupContent $value + */ + public function setEs(?GroupContent $value = null): self + { + $this->es = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEt(): ?GroupContent + { + return $this->et; + } + + /** + * @param ?GroupContent $value + */ + public function setEt(?GroupContent $value = null): self + { + $this->et = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getFi(): ?GroupContent + { + return $this->fi; + } + + /** + * @param ?GroupContent $value + */ + public function setFi(?GroupContent $value = null): self + { + $this->fi = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getFr(): ?GroupContent + { + return $this->fr; + } + + /** + * @param ?GroupContent $value + */ + public function setFr(?GroupContent $value = null): self + { + $this->fr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getHe(): ?GroupContent + { + return $this->he; + } + + /** + * @param ?GroupContent $value + */ + public function setHe(?GroupContent $value = null): self + { + $this->he = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getHr(): ?GroupContent + { + return $this->hr; + } + + /** + * @param ?GroupContent $value + */ + public function setHr(?GroupContent $value = null): self + { + $this->hr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getHu(): ?GroupContent + { + return $this->hu; + } + + /** + * @param ?GroupContent $value + */ + public function setHu(?GroupContent $value = null): self + { + $this->hu = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getId(): ?GroupContent + { + return $this->id; + } + + /** + * @param ?GroupContent $value + */ + public function setId(?GroupContent $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getIt(): ?GroupContent + { + return $this->it; + } + + /** + * @param ?GroupContent $value + */ + public function setIt(?GroupContent $value = null): self + { + $this->it = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getJa(): ?GroupContent + { + return $this->ja; + } + + /** + * @param ?GroupContent $value + */ + public function setJa(?GroupContent $value = null): self + { + $this->ja = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getKo(): ?GroupContent + { + return $this->ko; + } + + /** + * @param ?GroupContent $value + */ + public function setKo(?GroupContent $value = null): self + { + $this->ko = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getLt(): ?GroupContent + { + return $this->lt; + } + + /** + * @param ?GroupContent $value + */ + public function setLt(?GroupContent $value = null): self + { + $this->lt = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getLv(): ?GroupContent + { + return $this->lv; + } + + /** + * @param ?GroupContent $value + */ + public function setLv(?GroupContent $value = null): self + { + $this->lv = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getMn(): ?GroupContent + { + return $this->mn; + } + + /** + * @param ?GroupContent $value + */ + public function setMn(?GroupContent $value = null): self + { + $this->mn = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getNb(): ?GroupContent + { + return $this->nb; + } + + /** + * @param ?GroupContent $value + */ + public function setNb(?GroupContent $value = null): self + { + $this->nb = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getNl(): ?GroupContent + { + return $this->nl; + } + + /** + * @param ?GroupContent $value + */ + public function setNl(?GroupContent $value = null): self + { + $this->nl = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getPl(): ?GroupContent + { + return $this->pl; + } + + /** + * @param ?GroupContent $value + */ + public function setPl(?GroupContent $value = null): self + { + $this->pl = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getPt(): ?GroupContent + { + return $this->pt; + } + + /** + * @param ?GroupContent $value + */ + public function setPt(?GroupContent $value = null): self + { + $this->pt = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getRo(): ?GroupContent + { + return $this->ro; + } + + /** + * @param ?GroupContent $value + */ + public function setRo(?GroupContent $value = null): self + { + $this->ro = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getRu(): ?GroupContent + { + return $this->ru; + } + + /** + * @param ?GroupContent $value + */ + public function setRu(?GroupContent $value = null): self + { + $this->ru = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getSl(): ?GroupContent + { + return $this->sl; + } + + /** + * @param ?GroupContent $value + */ + public function setSl(?GroupContent $value = null): self + { + $this->sl = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getSr(): ?GroupContent + { + return $this->sr; + } + + /** + * @param ?GroupContent $value + */ + public function setSr(?GroupContent $value = null): self + { + $this->sr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getSv(): ?GroupContent + { + return $this->sv; + } + + /** + * @param ?GroupContent $value + */ + public function setSv(?GroupContent $value = null): self + { + $this->sv = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getTr(): ?GroupContent + { + return $this->tr; + } + + /** + * @param ?GroupContent $value + */ + public function setTr(?GroupContent $value = null): self + { + $this->tr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getVi(): ?GroupContent + { + return $this->vi; + } + + /** + * @param ?GroupContent $value + */ + public function setVi(?GroupContent $value = null): self + { + $this->vi = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getPtBr(): ?GroupContent + { + return $this->ptBr; + } + + /** + * @param ?GroupContent $value + */ + public function setPtBr(?GroupContent $value = null): self + { + $this->ptBr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getZhCn(): ?GroupContent + { + return $this->zhCn; + } + + /** + * @param ?GroupContent $value + */ + public function setZhCn(?GroupContent $value = null): self + { + $this->zhCn = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getZhTw(): ?GroupContent + { + return $this->zhTw; + } + + /** + * @param ?GroupContent $value + */ + public function setZhTw(?GroupContent $value = null): self + { + $this->zhTw = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ImageComponent.php b/src/Types/ImageComponent.php new file mode 100644 index 00000000..49b6470d --- /dev/null +++ b/src/Types/ImageComponent.php @@ -0,0 +1,232 @@ + $align Aligns the image inside the component. Default is `left`. + */ + #[JsonProperty('align')] + private ?string $align; + + /** + * @var int $width The exact width of the image in pixels. + */ + #[JsonProperty('width')] + private int $width; + + /** + * @var int $height The exact height of the image in pixels. + */ + #[JsonProperty('height')] + private int $height; + + /** + * @var ?bool $rounded Rounds the corners of the image. Default is `false`. + */ + #[JsonProperty('rounded')] + private ?bool $rounded; + + /** + * @var ?'none' $bottomMargin Disables a component's margin-bottom of 10px. + */ + #[JsonProperty('bottom_margin')] + private ?string $bottomMargin; + + /** + * @var ?UrlActionComponent $action This can be a URL Action only. + */ + #[JsonProperty('action')] + private ?UrlActionComponent $action; + + /** + * @param array{ + * url: string, + * width: int, + * height: int, + * id?: ?string, + * align?: ?value-of, + * rounded?: ?bool, + * bottomMargin?: ?'none', + * action?: ?UrlActionComponent, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id'] ?? null; + $this->url = $values['url']; + $this->align = $values['align'] ?? null; + $this->width = $values['width']; + $this->height = $values['height']; + $this->rounded = $values['rounded'] ?? null; + $this->bottomMargin = $values['bottomMargin'] ?? null; + $this->action = $values['action'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getAlign(): ?string + { + return $this->align; + } + + /** + * @param ?value-of $value + */ + public function setAlign(?string $value = null): self + { + $this->align = $value; + return $this; + } + + /** + * @return int + */ + public function getWidth(): int + { + return $this->width; + } + + /** + * @param int $value + */ + public function setWidth(int $value): self + { + $this->width = $value; + return $this; + } + + /** + * @return int + */ + public function getHeight(): int + { + return $this->height; + } + + /** + * @param int $value + */ + public function setHeight(int $value): self + { + $this->height = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRounded(): ?bool + { + return $this->rounded; + } + + /** + * @param ?bool $value + */ + public function setRounded(?bool $value = null): self + { + $this->rounded = $value; + return $this; + } + + /** + * @return ?'none' + */ + public function getBottomMargin(): ?string + { + return $this->bottomMargin; + } + + /** + * @param ?'none' $value + */ + public function setBottomMargin(?string $value = null): self + { + $this->bottomMargin = $value; + return $this; + } + + /** + * @return ?UrlActionComponent + */ + public function getAction(): ?UrlActionComponent + { + return $this->action; + } + + /** + * @param ?UrlActionComponent $value + */ + public function setAction(?UrlActionComponent $value = null): self + { + $this->action = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ImageComponentAlign.php b/src/Types/ImageComponentAlign.php new file mode 100644 index 00000000..359ca129 --- /dev/null +++ b/src/Types/ImageComponentAlign.php @@ -0,0 +1,11 @@ + $cardCreationOptions Key-value pairs which were given as results in response to the Configure request. + */ + #[JsonProperty('card_creation_options'), ArrayType(['string' => 'mixed'])] + private array $cardCreationOptions; + + /** + * @var Context $context The context of where the app is added, where the user last visited, and information on the Messenger settings. + */ + #[JsonProperty('context')] + private Context $context; + + /** + * @var Conversation $conversation The conversation your app is being shown for. + */ + #[JsonProperty('conversation')] + private Conversation $conversation; + + /** + * @var Contact $contact The contact which is currently being viewed by the teammate in the conversation details panel. We send an individual initialize request for each customer when it's a group conversation. + */ + #[JsonProperty('contact')] + private Contact $contact; + + /** + * @param array{ + * workspaceId: string, + * workspaceRegion: string, + * admin: Admin, + * cardCreationOptions: array, + * context: Context, + * conversation: Conversation, + * contact: Contact, + * } $values + */ + public function __construct( + array $values, + ) { + $this->workspaceId = $values['workspaceId']; + $this->workspaceRegion = $values['workspaceRegion']; + $this->admin = $values['admin']; + $this->cardCreationOptions = $values['cardCreationOptions']; + $this->context = $values['context']; + $this->conversation = $values['conversation']; + $this->contact = $values['contact']; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceRegion(): string + { + return $this->workspaceRegion; + } + + /** + * @param string $value + */ + public function setWorkspaceRegion(string $value): self + { + $this->workspaceRegion = $value; + return $this; + } + + /** + * @return Admin + */ + public function getAdmin(): Admin + { + return $this->admin; + } + + /** + * @param Admin $value + */ + public function setAdmin(Admin $value): self + { + $this->admin = $value; + return $this; + } + + /** + * @return array + */ + public function getCardCreationOptions(): array + { + return $this->cardCreationOptions; + } + + /** + * @param array $value + */ + public function setCardCreationOptions(array $value): self + { + $this->cardCreationOptions = $value; + return $this; + } + + /** + * @return Context + */ + public function getContext(): Context + { + return $this->context; + } + + /** + * @param Context $value + */ + public function setContext(Context $value): self + { + $this->context = $value; + return $this; + } + + /** + * @return Conversation + */ + public function getConversation(): Conversation + { + return $this->conversation; + } + + /** + * @param Conversation $value + */ + public function setConversation(Conversation $value): self + { + $this->conversation = $value; + return $this; + } + + /** + * @return Contact + */ + public function getContact(): Contact + { + return $this->contact; + } + + /** + * @param Contact $value + */ + public function setContact(Contact $value): self + { + $this->contact = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/InitializeResponse.php b/src/Types/InitializeResponse.php new file mode 100644 index 00000000..51be89ac --- /dev/null +++ b/src/Types/InitializeResponse.php @@ -0,0 +1,54 @@ +canvas = $values['canvas']; + } + + /** + * @return CanvasObject + */ + public function getCanvas(): CanvasObject + { + return $this->canvas; + } + + /** + * @param CanvasObject $value + */ + public function setCanvas(CanvasObject $value): self + { + $this->canvas = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/InputComponent.php b/src/Types/InputComponent.php new file mode 100644 index 00000000..35599515 --- /dev/null +++ b/src/Types/InputComponent.php @@ -0,0 +1,207 @@ + $saveState Styles the input. Default is `unsaved`. Prevent action with `saved`. + */ + #[JsonProperty('save_state')] + private ?string $saveState; + + /** + * @var ?bool $disabled Styles the input and prevents the action. Default is false. Will be overridden if save_state is saved. + */ + #[JsonProperty('disabled')] + private ?bool $disabled; + + /** + * @param array{ + * id: string, + * label?: ?string, + * placeholder?: ?string, + * value?: ?string, + * action?: ?ActionComponent, + * saveState?: ?value-of, + * disabled?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->label = $values['label'] ?? null; + $this->placeholder = $values['placeholder'] ?? null; + $this->value = $values['value'] ?? null; + $this->action = $values['action'] ?? null; + $this->saveState = $values['saveState'] ?? null; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLabel(): ?string + { + return $this->label; + } + + /** + * @param ?string $value + */ + public function setLabel(?string $value = null): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPlaceholder(): ?string + { + return $this->placeholder; + } + + /** + * @param ?string $value + */ + public function setPlaceholder(?string $value = null): self + { + $this->placeholder = $value; + return $this; + } + + /** + * @return ?string + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * @param ?string $value + */ + public function setValue(?string $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return ?ActionComponent + */ + public function getAction(): ?ActionComponent + { + return $this->action; + } + + /** + * @param ?ActionComponent $value + */ + public function setAction(?ActionComponent $value = null): self + { + $this->action = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getSaveState(): ?string + { + return $this->saveState; + } + + /** + * @param ?value-of $value + */ + public function setSaveState(?string $value = null): self + { + $this->saveState = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/InputComponentSaveState.php b/src/Types/InputComponentSaveState.php new file mode 100644 index 00000000..c1075bef --- /dev/null +++ b/src/Types/InputComponentSaveState.php @@ -0,0 +1,10 @@ + $type ticket or conversation + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The ID of the linked object + */ + #[JsonProperty('id')] + private string $id; + + /** + * @var ?string $category Category of the Linked Ticket Object. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @param array{ + * type: value-of, + * id: string, + * category?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->category = $values['category'] ?? null; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?string $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/LinkedObjectList.php b/src/Types/LinkedObjectList.php new file mode 100644 index 00000000..3ccf6e8d --- /dev/null +++ b/src/Types/LinkedObjectList.php @@ -0,0 +1,130 @@ + $data An array containing the linked conversations and linked tickets. + */ + #[JsonProperty('data'), ArrayType([LinkedObject::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * totalCount: int, + * hasMore: bool, + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->totalCount = $values['totalCount']; + $this->hasMore = $values['hasMore']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return bool + */ + public function getHasMore(): bool + { + return $this->hasMore; + } + + /** + * @param bool $value + */ + public function setHasMore(bool $value): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/LinkedObjectType.php b/src/Types/LinkedObjectType.php new file mode 100644 index 00000000..3f43b49c --- /dev/null +++ b/src/Types/LinkedObjectType.php @@ -0,0 +1,9 @@ + $items The items that will be rendered in the list. + */ + #[JsonProperty('items'), ArrayType([new Union(ListItemWithImage::class, ListItemWithoutImage::class)])] + private array $items; + + /** + * @var ?bool $disabled Styles all list items and prevents the action. Default is `false`. + */ + #[JsonProperty('disabled')] + private ?bool $disabled; + + /** + * @param array{ + * items: array<( + * ListItemWithImage + * |ListItemWithoutImage + * )>, + * disabled?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->items = $values['items']; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return array<( + * ListItemWithImage + * |ListItemWithoutImage + * )> + */ + public function getItems(): array + { + return $this->items; + } + + /** + * @param array<( + * ListItemWithImage + * |ListItemWithoutImage + * )> $value + */ + public function setItems(array $value): self + { + $this->items = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ListItem.php b/src/Types/ListItem.php new file mode 100644 index 00000000..e3e9d8f1 --- /dev/null +++ b/src/Types/ListItem.php @@ -0,0 +1,229 @@ +type = $values['type']; + $this->id = $values['id']; + $this->title = $values['title']; + $this->subtitle = $values['subtitle'] ?? null; + $this->tertiaryText = $values['tertiaryText'] ?? null; + $this->roundedImage = $values['roundedImage'] ?? null; + $this->disabled = $values['disabled'] ?? null; + $this->action = $values['action'] ?? null; + } + + /** + * @return 'item' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'item' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSubtitle(): ?string + { + return $this->subtitle; + } + + /** + * @param ?string $value + */ + public function setSubtitle(?string $value = null): self + { + $this->subtitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTertiaryText(): ?string + { + return $this->tertiaryText; + } + + /** + * @param ?string $value + */ + public function setTertiaryText(?string $value = null): self + { + $this->tertiaryText = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRoundedImage(): ?bool + { + return $this->roundedImage; + } + + /** + * @param ?bool $value + */ + public function setRoundedImage(?bool $value = null): self + { + $this->roundedImage = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return ?ActionComponent + */ + public function getAction(): ?ActionComponent + { + return $this->action; + } + + /** + * @param ?ActionComponent $value + */ + public function setAction(?ActionComponent $value = null): self + { + $this->action = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ListItemWithImage.php b/src/Types/ListItemWithImage.php new file mode 100644 index 00000000..09e4a26d --- /dev/null +++ b/src/Types/ListItemWithImage.php @@ -0,0 +1,120 @@ +type = $values['type']; + $this->id = $values['id']; + $this->title = $values['title']; + $this->subtitle = $values['subtitle'] ?? null; + $this->tertiaryText = $values['tertiaryText'] ?? null; + $this->roundedImage = $values['roundedImage'] ?? null; + $this->disabled = $values['disabled'] ?? null; + $this->action = $values['action'] ?? null; + $this->image = $values['image']; + $this->imageWidth = $values['imageWidth']; + $this->imageHeight = $values['imageHeight']; + } + + /** + * @return string + */ + public function getImage(): string + { + return $this->image; + } + + /** + * @param string $value + */ + public function setImage(string $value): self + { + $this->image = $value; + return $this; + } + + /** + * @return int + */ + public function getImageWidth(): int + { + return $this->imageWidth; + } + + /** + * @param int $value + */ + public function setImageWidth(int $value): self + { + $this->imageWidth = $value; + return $this; + } + + /** + * @return int + */ + public function getImageHeight(): int + { + return $this->imageHeight; + } + + /** + * @param int $value + */ + public function setImageHeight(int $value): self + { + $this->imageHeight = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ListItemWithoutImage.php b/src/Types/ListItemWithoutImage.php new file mode 100644 index 00000000..5d65475a --- /dev/null +++ b/src/Types/ListItemWithoutImage.php @@ -0,0 +1,120 @@ +type = $values['type']; + $this->id = $values['id']; + $this->title = $values['title']; + $this->subtitle = $values['subtitle'] ?? null; + $this->tertiaryText = $values['tertiaryText'] ?? null; + $this->roundedImage = $values['roundedImage'] ?? null; + $this->disabled = $values['disabled'] ?? null; + $this->action = $values['action'] ?? null; + $this->image = $values['image'] ?? null; + $this->imageWidth = $values['imageWidth'] ?? null; + $this->imageHeight = $values['imageHeight'] ?? null; + } + + /** + * @return ?string + */ + public function getImage(): ?string + { + return $this->image; + } + + /** + * @param ?string $value + */ + public function setImage(?string $value = null): self + { + $this->image = $value; + return $this; + } + + /** + * @return ?int + */ + public function getImageWidth(): ?int + { + return $this->imageWidth; + } + + /** + * @param ?int $value + */ + public function setImageWidth(?int $value = null): self + { + $this->imageWidth = $value; + return $this; + } + + /** + * @return ?int + */ + public function getImageHeight(): ?int + { + return $this->imageHeight; + } + + /** + * @param ?int $value + */ + public function setImageHeight(?int $value = null): self + { + $this->imageHeight = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/LiveCanvasRequest.php b/src/Types/LiveCanvasRequest.php new file mode 100644 index 00000000..62b66ca1 --- /dev/null +++ b/src/Types/LiveCanvasRequest.php @@ -0,0 +1,157 @@ +workspaceId = $values['workspaceId']; + $this->workspaceRegion = $values['workspaceRegion']; + $this->canvas = $values['canvas']; + $this->context = $values['context']; + $this->contact = $values['contact']; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceRegion(): string + { + return $this->workspaceRegion; + } + + /** + * @param string $value + */ + public function setWorkspaceRegion(string $value): self + { + $this->workspaceRegion = $value; + return $this; + } + + /** + * @return CanvasObject + */ + public function getCanvas(): CanvasObject + { + return $this->canvas; + } + + /** + * @param CanvasObject $value + */ + public function setCanvas(CanvasObject $value): self + { + $this->canvas = $value; + return $this; + } + + /** + * @return Context + */ + public function getContext(): Context + { + return $this->context; + } + + /** + * @param Context $value + */ + public function setContext(Context $value): self + { + $this->context = $value; + return $this; + } + + /** + * @return Contact + */ + public function getContact(): Contact + { + return $this->contact; + } + + /** + * @param Contact $value + */ + public function setContact(Contact $value): self + { + $this->contact = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/LiveCanvasResponse.php b/src/Types/LiveCanvasResponse.php new file mode 100644 index 00000000..8f4ed3cf --- /dev/null +++ b/src/Types/LiveCanvasResponse.php @@ -0,0 +1,54 @@ +content = $values['content']; + } + + /** + * @return ContentObject + */ + public function getContent(): ContentObject + { + return $this->content; + } + + /** + * @param ContentObject $value + */ + public function setContent(ContentObject $value): self + { + $this->content = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/MultipleFilterSearchRequest.php b/src/Types/MultipleFilterSearchRequest.php new file mode 100644 index 00000000..371a458a --- /dev/null +++ b/src/Types/MultipleFilterSearchRequest.php @@ -0,0 +1,93 @@ + $operator An operator to allow boolean inspection between multiple fields. + */ + #[JsonProperty('operator')] + private ?string $operator; + + /** + * @var ?array<( + * MultipleFilterSearchRequest + * |SingleFilterSearchRequest + * )> $value + */ + #[JsonProperty('value'), ArrayType([new Union(MultipleFilterSearchRequest::class, SingleFilterSearchRequest::class)])] + private ?array $value; + + /** + * @param array{ + * operator?: ?value-of, + * value?: ?array<( + * MultipleFilterSearchRequest + * |SingleFilterSearchRequest + * )>, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->operator = $values['operator'] ?? null; + $this->value = $values['value'] ?? null; + } + + /** + * @return ?value-of + */ + public function getOperator(): ?string + { + return $this->operator; + } + + /** + * @param ?value-of $value + */ + public function setOperator(?string $value = null): self + { + $this->operator = $value; + return $this; + } + + /** + * @return ?array<( + * MultipleFilterSearchRequest + * |SingleFilterSearchRequest + * )> + */ + public function getValue(): ?array + { + return $this->value; + } + + /** + * @param ?array<( + * MultipleFilterSearchRequest + * |SingleFilterSearchRequest + * )> $value + */ + public function setValue(?array $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/MultipleFilterSearchRequestOperator.php b/src/Types/MultipleFilterSearchRequestOperator.php new file mode 100644 index 00000000..e7ba0445 --- /dev/null +++ b/src/Types/MultipleFilterSearchRequestOperator.php @@ -0,0 +1,9 @@ + $state News items will not be visible to your users in the assigned newsfeeds until they are set live. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?bool $deliverSilently When set to `true`, the news item will appear in the messenger newsfeed without showing a notification badge. + */ + #[JsonProperty('deliver_silently')] + private ?bool $deliverSilently; + + /** + * @var ?array $labels Label names displayed to users to categorize the news item. + */ + #[JsonProperty('labels'), ArrayType(['string'])] + private ?array $labels; + + /** + * @var ?array $reactions Ordered list of emoji reactions to the news item. When empty, reactions are disabled. + */ + #[JsonProperty('reactions'), ArrayType([new Union('string', 'null')])] + private ?array $reactions; + + /** + * @var ?array $newsfeedAssignments A list of newsfeed_assignments to assign to the specified newsfeed. + */ + #[JsonProperty('newsfeed_assignments'), ArrayType([NewsfeedAssignment::class])] + private ?array $newsfeedAssignments; + + /** + * @param array{ + * title: string, + * senderId: int, + * body?: ?string, + * state?: ?value-of, + * deliverSilently?: ?bool, + * labels?: ?array, + * reactions?: ?array, + * newsfeedAssignments?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->title = $values['title']; + $this->body = $values['body'] ?? null; + $this->senderId = $values['senderId']; + $this->state = $values['state'] ?? null; + $this->deliverSilently = $values['deliverSilently'] ?? null; + $this->labels = $values['labels'] ?? null; + $this->reactions = $values['reactions'] ?? null; + $this->newsfeedAssignments = $values['newsfeedAssignments'] ?? null; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getSenderId(): int + { + return $this->senderId; + } + + /** + * @param int $value + */ + public function setSenderId(int $value): self + { + $this->senderId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeliverSilently(): ?bool + { + return $this->deliverSilently; + } + + /** + * @param ?bool $value + */ + public function setDeliverSilently(?bool $value = null): self + { + $this->deliverSilently = $value; + return $this; + } + + /** + * @return ?array + */ + public function getLabels(): ?array + { + return $this->labels; + } + + /** + * @param ?array $value + */ + public function setLabels(?array $value = null): self + { + $this->labels = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReactions(): ?array + { + return $this->reactions; + } + + /** + * @param ?array $value + */ + public function setReactions(?array $value = null): self + { + $this->reactions = $value; + return $this; + } + + /** + * @return ?array + */ + public function getNewsfeedAssignments(): ?array + { + return $this->newsfeedAssignments; + } + + /** + * @param ?array $value + */ + public function setNewsfeedAssignments(?array $value = null): self + { + $this->newsfeedAssignments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/NewsItemRequestState.php b/src/Types/NewsItemRequestState.php new file mode 100644 index 00000000..1619befb --- /dev/null +++ b/src/Types/NewsItemRequestState.php @@ -0,0 +1,9 @@ + $data An array of notes. + */ + #[JsonProperty('data'), ArrayType([Note::class])] + private array $data; + + /** + * @var int $totalCount A count of the total number of notes. + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @param array{ + * type: 'list', + * data: array, + * totalCount: int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + $this->totalCount = $values['totalCount']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/OffsetPages.php b/src/Types/OffsetPages.php new file mode 100644 index 00000000..e0af2699 --- /dev/null +++ b/src/Types/OffsetPages.php @@ -0,0 +1,151 @@ +type = $values['type']; + $this->page = $values['page'] ?? null; + $this->next = $values['next'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->totalPages = $values['totalPages'] ?? null; + } + + /** + * @return 'offset_pages' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'offset_pages' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?string + */ + public function getNext(): ?string + { + return $this->next; + } + + /** + * @param ?string $value + */ + public function setNext(?string $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalPages(): ?int + { + return $this->totalPages; + } + + /** + * @param ?int $value + */ + public function setTotalPages(?int $value = null): self + { + $this->totalPages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/OpenConversationRequest.php b/src/Types/OpenConversationRequest.php new file mode 100644 index 00000000..f121aa16 --- /dev/null +++ b/src/Types/OpenConversationRequest.php @@ -0,0 +1,54 @@ +adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/PagesLink.php b/src/Types/PagesLink.php new file mode 100644 index 00000000..8a5519cc --- /dev/null +++ b/src/Types/PagesLink.php @@ -0,0 +1,156 @@ +type = $values['type']; + $this->page = $values['page']; + $this->next = $values['next'] ?? null; + $this->perPage = $values['perPage']; + $this->totalPages = $values['totalPages']; + } + + /** + * @return 'pages' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'pages' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getPage(): int + { + return $this->page; + } + + /** + * @param int $value + */ + public function setPage(int $value): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?string + */ + public function getNext(): ?string + { + return $this->next; + } + + /** + * @param ?string $value + */ + public function setNext(?string $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return int + */ + public function getPerPage(): int + { + return $this->perPage; + } + + /** + * @param int $value + */ + public function setPerPage(int $value): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalPages(): int + { + return $this->totalPages; + } + + /** + * @param int $value + */ + public function setTotalPages(int $value): self + { + $this->totalPages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/PaginatedConversationResponse.php b/src/Types/PaginatedConversationResponse.php new file mode 100644 index 00000000..13802508 --- /dev/null +++ b/src/Types/PaginatedConversationResponse.php @@ -0,0 +1,131 @@ + $conversations The list of conversation objects + */ + #[JsonProperty('conversations'), ArrayType([Conversation::class])] + private array $conversations; + + /** + * @var int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type: 'conversation.list', + * conversations: array, + * totalCount: int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->conversations = $values['conversations']; + $this->totalCount = $values['totalCount']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'conversation.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'conversation.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getConversations(): array + { + return $this->conversations; + } + + /** + * @param array $value + */ + public function setConversations(array $value): self + { + $this->conversations = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/PaginatedNewsItemResponse.php b/src/Types/PaginatedNewsItemResponse.php new file mode 100644 index 00000000..7eec90db --- /dev/null +++ b/src/Types/PaginatedNewsItemResponse.php @@ -0,0 +1,131 @@ + $data An array of News Items + */ + #[JsonProperty('data'), ArrayType([NewsItem::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * totalCount: int, + * data: array, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/PaginatedNewsfeedResponse.php b/src/Types/PaginatedNewsfeedResponse.php new file mode 100644 index 00000000..b5bfac71 --- /dev/null +++ b/src/Types/PaginatedNewsfeedResponse.php @@ -0,0 +1,131 @@ + $data An array of Newsfeeds + */ + #[JsonProperty('data'), ArrayType([Newsfeed::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * totalCount: int, + * data: array, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/PartAttachment.php b/src/Types/PartAttachment.php new file mode 100644 index 00000000..4411675c --- /dev/null +++ b/src/Types/PartAttachment.php @@ -0,0 +1,204 @@ +type = $values['type']; + $this->name = $values['name']; + $this->url = $values['url']; + $this->contentType = $values['contentType']; + $this->filesize = $values['filesize']; + $this->width = $values['width']; + $this->height = $values['height']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function getContentType(): string + { + return $this->contentType; + } + + /** + * @param string $value + */ + public function setContentType(string $value): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return int + */ + public function getFilesize(): int + { + return $this->filesize; + } + + /** + * @param int $value + */ + public function setFilesize(int $value): self + { + $this->filesize = $value; + return $this; + } + + /** + * @return int + */ + public function getWidth(): int + { + return $this->width; + } + + /** + * @param int $value + */ + public function setWidth(int $value): self + { + $this->width = $value; + return $this; + } + + /** + * @return int + */ + public function getHeight(): int + { + return $this->height; + } + + /** + * @param int $value + */ + public function setHeight(int $value): self + { + $this->height = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/PhoneSwitch.php b/src/Types/PhoneSwitch.php new file mode 100644 index 00000000..62f991bb --- /dev/null +++ b/src/Types/PhoneSwitch.php @@ -0,0 +1,79 @@ +type = $values['type']; + $this->phone = $values['phone']; + } + + /** + * @return 'phone_call_redirect' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'phone_call_redirect' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getPhone(): string + { + return $this->phone; + } + + /** + * @param string $value + */ + public function setPhone(string $value): self + { + $this->phone = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/RedactConversationRequest.php b/src/Types/RedactConversationRequest.php new file mode 100644 index 00000000..8e103c7d --- /dev/null +++ b/src/Types/RedactConversationRequest.php @@ -0,0 +1,233 @@ +type = $values['type']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'conversation_part' + * |'source' + * |'_unknown' + * ) + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return ( + * RedactConversationRequestConversationPart + * |RedactConversationRequestSource + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param RedactConversationRequestConversationPart $conversationPart + * @return RedactConversationRequest + */ + public static function conversationPart(RedactConversationRequestConversationPart $conversationPart): RedactConversationRequest + { + return new RedactConversationRequest([ + 'type' => 'conversation_part', + 'value' => $conversationPart, + ]); + } + + /** + * @param RedactConversationRequestSource $source + * @return RedactConversationRequest + */ + public static function source(RedactConversationRequestSource $source): RedactConversationRequest + { + return new RedactConversationRequest([ + 'type' => 'source', + 'value' => $source, + ]); + } + + /** + * @return bool + */ + public function isConversationPart(): bool + { + return $this->value instanceof RedactConversationRequestConversationPart && $this->type === 'conversation_part'; + } + + /** + * @return RedactConversationRequestConversationPart + */ + public function asConversationPart(): RedactConversationRequestConversationPart + { + if (!($this->value instanceof RedactConversationRequestConversationPart && $this->type === 'conversation_part')) { + throw new Exception( + "Expected conversation_part; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSource(): bool + { + return $this->value instanceof RedactConversationRequestSource && $this->type === 'source'; + } + + /** + * @return RedactConversationRequestSource + */ + public function asSource(): RedactConversationRequestSource + { + if (!($this->value instanceof RedactConversationRequestSource && $this->type === 'source')) { + throw new Exception( + "Expected source; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['type'] = $this->type; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->type) { + case 'conversation_part': + $value = $this->asConversationPart()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'source': + $value = $this->asSource()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('type', $data)) { + throw new Exception( + "JSON data is missing property 'type'", + ); + } + $type = $data['type']; + if (!(is_string($type))) { + throw new Exception( + "Expected property 'type' in JSON data to be string, instead received " . get_debug_type($data['type']), + ); + } + + $args['type'] = $type; + switch ($type) { + case 'conversation_part': + $args['value'] = RedactConversationRequestConversationPart::jsonDeserialize($data); + break; + case 'source': + $args['value'] = RedactConversationRequestSource::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['type'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Types/RedactConversationRequestConversationPart.php b/src/Types/RedactConversationRequestConversationPart.php new file mode 100644 index 00000000..e62f1aa0 --- /dev/null +++ b/src/Types/RedactConversationRequestConversationPart.php @@ -0,0 +1,79 @@ +conversationId = $values['conversationId']; + $this->conversationPartId = $values['conversationPartId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getConversationPartId(): string + { + return $this->conversationPartId; + } + + /** + * @param string $value + */ + public function setConversationPartId(string $value): self + { + $this->conversationPartId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/RedactConversationRequestSource.php b/src/Types/RedactConversationRequestSource.php new file mode 100644 index 00000000..dcc63940 --- /dev/null +++ b/src/Types/RedactConversationRequestSource.php @@ -0,0 +1,79 @@ +conversationId = $values['conversationId']; + $this->sourceId = $values['sourceId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getSourceId(): string + { + return $this->sourceId; + } + + /** + * @param string $value + */ + public function setSourceId(string $value): self + { + $this->sourceId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Reference.php b/src/Types/Reference.php new file mode 100644 index 00000000..65473b86 --- /dev/null +++ b/src/Types/Reference.php @@ -0,0 +1,79 @@ +type = $values['type']; + $this->id = $values['id'] ?? null; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/ResultsResponse.php b/src/Types/ResultsResponse.php new file mode 100644 index 00000000..d0df17d6 --- /dev/null +++ b/src/Types/ResultsResponse.php @@ -0,0 +1,55 @@ + $results Key-value pairs of data you want access to in the Initialize request + */ + #[JsonProperty('results'), ArrayType(['string' => 'mixed'])] + private array $results; + + /** + * @param array{ + * results: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->results = $values['results']; + } + + /** + * @return array + */ + public function getResults(): array + { + return $this->results; + } + + /** + * @param array $value + */ + public function setResults(array $value): self + { + $this->results = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SearchRequest.php b/src/Types/SearchRequest.php new file mode 100644 index 00000000..c064c389 --- /dev/null +++ b/src/Types/SearchRequest.php @@ -0,0 +1,92 @@ +query = $values['query']; + $this->pagination = $values['pagination'] ?? null; + } + + /** + * @return ( + * SingleFilterSearchRequest + * |MultipleFilterSearchRequest + * ) + */ + public function getQuery(): SingleFilterSearchRequest|MultipleFilterSearchRequest + { + return $this->query; + } + + /** + * @param ( + * SingleFilterSearchRequest + * |MultipleFilterSearchRequest + * ) $value + */ + public function setQuery(SingleFilterSearchRequest|MultipleFilterSearchRequest $value): self + { + $this->query = $value; + return $this; + } + + /** + * @return ?StartingAfterPaging + */ + public function getPagination(): ?StartingAfterPaging + { + return $this->pagination; + } + + /** + * @param ?StartingAfterPaging $value + */ + public function setPagination(?StartingAfterPaging $value = null): self + { + $this->pagination = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SegmentList.php b/src/Types/SegmentList.php new file mode 100644 index 00000000..52cbc4d5 --- /dev/null +++ b/src/Types/SegmentList.php @@ -0,0 +1,106 @@ + $segments A list of Segment objects + */ + #[JsonProperty('segments'), ArrayType([Segment::class])] + private array $segments; + + /** + * @var ?array $pages A pagination object, which may be empty, indicating no further pages to fetch. + */ + #[JsonProperty('pages'), ArrayType(['string' => 'mixed'])] + private ?array $pages; + + /** + * @param array{ + * type: 'segment.list', + * segments: array, + * pages?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->segments = $values['segments']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'segment.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'segment.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getSegments(): array + { + return $this->segments; + } + + /** + * @param array $value + */ + public function setSegments(array $value): self + { + $this->segments = $value; + return $this; + } + + /** + * @return ?array + */ + public function getPages(): ?array + { + return $this->pages; + } + + /** + * @param ?array $value + */ + public function setPages(?array $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SheetActionComponent.php b/src/Types/SheetActionComponent.php new file mode 100644 index 00000000..5b4b0d77 --- /dev/null +++ b/src/Types/SheetActionComponent.php @@ -0,0 +1,56 @@ +url = $values['url']; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SingleFilterSearchRequest.php b/src/Types/SingleFilterSearchRequest.php new file mode 100644 index 00000000..e3f39d40 --- /dev/null +++ b/src/Types/SingleFilterSearchRequest.php @@ -0,0 +1,125 @@ + $operator The accepted operators you can use to define how you want to search for the value. + */ + #[JsonProperty('operator')] + private ?string $operator; + + /** + * @var ( + * string + * |int + * |array + * |array + * )|null $value The value that you want to search on. + */ + #[JsonProperty('value'), Union('string', 'integer', ['string'], ['integer'], 'null')] + private string|int|array|null $value; + + /** + * @param array{ + * field?: ?string, + * operator?: ?value-of, + * value?: ( + * string + * |int + * |array + * |array + * )|null, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->field = $values['field'] ?? null; + $this->operator = $values['operator'] ?? null; + $this->value = $values['value'] ?? null; + } + + /** + * @return ?string + */ + public function getField(): ?string + { + return $this->field; + } + + /** + * @param ?string $value + */ + public function setField(?string $value = null): self + { + $this->field = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getOperator(): ?string + { + return $this->operator; + } + + /** + * @param ?value-of $value + */ + public function setOperator(?string $value = null): self + { + $this->operator = $value; + return $this; + } + + /** + * @return ( + * string + * |int + * |array + * |array + * )|null + */ + public function getValue(): string|int|array|null + { + return $this->value; + } + + /** + * @param ( + * string + * |int + * |array + * |array + * )|null $value + */ + public function setValue(string|int|array|null $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SingleFilterSearchRequestOperator.php b/src/Types/SingleFilterSearchRequestOperator.php new file mode 100644 index 00000000..6fa00dd2 --- /dev/null +++ b/src/Types/SingleFilterSearchRequestOperator.php @@ -0,0 +1,17 @@ +"; + case Contains = "~"; + case DoesNotContain = "!~"; + case StartsWith = "^"; + case EndsWith = "$"; +} diff --git a/src/Types/SingleSelectComponent.php b/src/Types/SingleSelectComponent.php new file mode 100644 index 00000000..ee3fc45c --- /dev/null +++ b/src/Types/SingleSelectComponent.php @@ -0,0 +1,210 @@ + $options The list of options. Can provide 2 to 10. + */ + #[JsonProperty('options'), ArrayType([SingleSelectOption::class])] + private array $options; + + /** + * @var ?string $label The text shown above the options. + */ + #[JsonProperty('label')] + private ?string $label; + + /** + * @var ?string $value The option that is selected by default. + */ + #[JsonProperty('value')] + private ?string $value; + + /** + * @var ?value-of $saveState Styles the input. Default is `unsaved`. Prevent action with `saved`. + */ + #[JsonProperty('save_state')] + private ?string $saveState; + + /** + * @var ?bool $disabled Styles all options and prevents the action. Default is false. Will be overridden if save_state is saved. + */ + #[JsonProperty('disabled')] + private ?bool $disabled; + + /** + * @var ?ActionComponent $action This can be a Submit Action, URL Action, or Sheets Action. + */ + #[JsonProperty('action')] + private ?ActionComponent $action; + + /** + * @param array{ + * id: string, + * options: array, + * label?: ?string, + * value?: ?string, + * saveState?: ?value-of, + * disabled?: ?bool, + * action?: ?ActionComponent, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->options = $values['options']; + $this->label = $values['label'] ?? null; + $this->value = $values['value'] ?? null; + $this->saveState = $values['saveState'] ?? null; + $this->disabled = $values['disabled'] ?? null; + $this->action = $values['action'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @param array $value + */ + public function setOptions(array $value): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLabel(): ?string + { + return $this->label; + } + + /** + * @param ?string $value + */ + public function setLabel(?string $value = null): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * @param ?string $value + */ + public function setValue(?string $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getSaveState(): ?string + { + return $this->saveState; + } + + /** + * @param ?value-of $value + */ + public function setSaveState(?string $value = null): self + { + $this->saveState = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return ?ActionComponent + */ + public function getAction(): ?ActionComponent + { + return $this->action; + } + + /** + * @param ?ActionComponent $value + */ + public function setAction(?ActionComponent $value = null): self + { + $this->action = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SingleSelectComponentSaveState.php b/src/Types/SingleSelectComponentSaveState.php new file mode 100644 index 00000000..3776c6a6 --- /dev/null +++ b/src/Types/SingleSelectComponentSaveState.php @@ -0,0 +1,10 @@ +type = $values['type']; + $this->id = $values['id']; + $this->text = $values['text']; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return 'option' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'option' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SlaApplied.php b/src/Types/SlaApplied.php new file mode 100644 index 00000000..79ced80b --- /dev/null +++ b/src/Types/SlaApplied.php @@ -0,0 +1,110 @@ + $slaStatus + */ + #[JsonProperty('sla_status')] + private string $slaStatus; + + /** + * @param array{ + * type: string, + * slaName: string, + * slaStatus: value-of, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->slaName = $values['slaName']; + $this->slaStatus = $values['slaStatus']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getSlaName(): string + { + return $this->slaName; + } + + /** + * @param string $value + */ + public function setSlaName(string $value): self + { + $this->slaName = $value; + return $this; + } + + /** + * @return value-of + */ + public function getSlaStatus(): string + { + return $this->slaStatus; + } + + /** + * @param value-of $value + */ + public function setSlaStatus(string $value): self + { + $this->slaStatus = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SlaAppliedSlaStatus.php b/src/Types/SlaAppliedSlaStatus.php new file mode 100644 index 00000000..e6ebba5e --- /dev/null +++ b/src/Types/SlaAppliedSlaStatus.php @@ -0,0 +1,11 @@ +adminId = $values['adminId']; + $this->snoozedUntil = $values['snoozedUntil']; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return int + */ + public function getSnoozedUntil(): int + { + return $this->snoozedUntil; + } + + /** + * @param int $value + */ + public function setSnoozedUntil(int $value): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SocialProfile.php b/src/Types/SocialProfile.php new file mode 100644 index 00000000..ac99d03b --- /dev/null +++ b/src/Types/SocialProfile.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->name = $values['name']; + $this->url = $values['url']; + } + + /** + * @return 'social_profile' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'social_profile' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SpacerComponent.php b/src/Types/SpacerComponent.php new file mode 100644 index 00000000..cf7331f4 --- /dev/null +++ b/src/Types/SpacerComponent.php @@ -0,0 +1,79 @@ + $size The amount of space between components. Default is `s`. + */ + #[JsonProperty('size')] + private ?string $size; + + /** + * @param array{ + * id?: ?string, + * size?: ?value-of, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->id = $values['id'] ?? null; + $this->size = $values['size'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getSize(): ?string + { + return $this->size; + } + + /** + * @param ?value-of $value + */ + public function setSize(?string $value = null): self + { + $this->size = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SpacerComponentSize.php b/src/Types/SpacerComponentSize.php new file mode 100644 index 00000000..57b3d994 --- /dev/null +++ b/src/Types/SpacerComponentSize.php @@ -0,0 +1,12 @@ +perPage = $values['perPage']; + $this->startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return int + */ + public function getPerPage(): int + { + return $this->perPage; + } + + /** + * @param int $value + */ + public function setPerPage(int $value): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SubmitActionComponent.php b/src/Types/SubmitActionComponent.php new file mode 100644 index 00000000..6b4d2c96 --- /dev/null +++ b/src/Types/SubmitActionComponent.php @@ -0,0 +1,19 @@ +toJson(); + } +} diff --git a/src/Types/SubmitRequest.php b/src/Types/SubmitRequest.php new file mode 100644 index 00000000..f88fe7a0 --- /dev/null +++ b/src/Types/SubmitRequest.php @@ -0,0 +1,283 @@ + $inputValues A list of key/value pairs of data, inputted by the teammate on the current canvas. + */ + #[JsonProperty('input_values'), ArrayType(['string' => 'mixed'])] + private array $inputValues; + + /** + * @var Contact $user The user who took the action. + */ + #[JsonProperty('user')] + private Contact $user; + + /** + * @param array{ + * workspaceId: string, + * workspaceRegion: string, + * admin: Admin, + * componentId: string, + * context: Context, + * conversation: Conversation, + * currentCanvas: CurrentCanvas, + * contact: Contact, + * inputValues: array, + * user: Contact, + * } $values + */ + public function __construct( + array $values, + ) { + $this->workspaceId = $values['workspaceId']; + $this->workspaceRegion = $values['workspaceRegion']; + $this->admin = $values['admin']; + $this->componentId = $values['componentId']; + $this->context = $values['context']; + $this->conversation = $values['conversation']; + $this->currentCanvas = $values['currentCanvas']; + $this->contact = $values['contact']; + $this->inputValues = $values['inputValues']; + $this->user = $values['user']; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceRegion(): string + { + return $this->workspaceRegion; + } + + /** + * @param string $value + */ + public function setWorkspaceRegion(string $value): self + { + $this->workspaceRegion = $value; + return $this; + } + + /** + * @return Admin + */ + public function getAdmin(): Admin + { + return $this->admin; + } + + /** + * @param Admin $value + */ + public function setAdmin(Admin $value): self + { + $this->admin = $value; + return $this; + } + + /** + * @return string + */ + public function getComponentId(): string + { + return $this->componentId; + } + + /** + * @param string $value + */ + public function setComponentId(string $value): self + { + $this->componentId = $value; + return $this; + } + + /** + * @return Context + */ + public function getContext(): Context + { + return $this->context; + } + + /** + * @param Context $value + */ + public function setContext(Context $value): self + { + $this->context = $value; + return $this; + } + + /** + * @return Conversation + */ + public function getConversation(): Conversation + { + return $this->conversation; + } + + /** + * @param Conversation $value + */ + public function setConversation(Conversation $value): self + { + $this->conversation = $value; + return $this; + } + + /** + * @return CurrentCanvas + */ + public function getCurrentCanvas(): CurrentCanvas + { + return $this->currentCanvas; + } + + /** + * @param CurrentCanvas $value + */ + public function setCurrentCanvas(CurrentCanvas $value): self + { + $this->currentCanvas = $value; + return $this; + } + + /** + * @return Contact + */ + public function getContact(): Contact + { + return $this->contact; + } + + /** + * @param Contact $value + */ + public function setContact(Contact $value): self + { + $this->contact = $value; + return $this; + } + + /** + * @return array + */ + public function getInputValues(): array + { + return $this->inputValues; + } + + /** + * @param array $value + */ + public function setInputValues(array $value): self + { + $this->inputValues = $value; + return $this; + } + + /** + * @return Contact + */ + public function getUser(): Contact + { + return $this->user; + } + + /** + * @param Contact $value + */ + public function setUser(Contact $value): self + { + $this->user = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SubmitResponse.php b/src/Types/SubmitResponse.php new file mode 100644 index 00000000..b4fb3a85 --- /dev/null +++ b/src/Types/SubmitResponse.php @@ -0,0 +1,113 @@ + $cardCreationOptions Optional. Key-value pairs that will be sent in the initialize request to insert an app into the conversation reply. + */ + #[JsonProperty('card_creation_options'), ArrayType(['string' => 'mixed'])] + private ?array $cardCreationOptions; + + /** + * @var ?Event $event Optional. Indicates if the app has completed its purpose. + */ + #[JsonProperty('event')] + private ?Event $event; + + /** + * @param array{ + * canvas: CanvasObject, + * cardCreationOptions?: ?array, + * event?: ?Event, + * } $values + */ + public function __construct( + array $values, + ) { + $this->canvas = $values['canvas']; + $this->cardCreationOptions = $values['cardCreationOptions'] ?? null; + $this->event = $values['event'] ?? null; + } + + /** + * @return CanvasObject + */ + public function getCanvas(): CanvasObject + { + return $this->canvas; + } + + /** + * @param CanvasObject $value + */ + public function setCanvas(CanvasObject $value): self + { + $this->canvas = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCardCreationOptions(): ?array + { + return $this->cardCreationOptions; + } + + /** + * @param ?array $value + */ + public function setCardCreationOptions(?array $value = null): self + { + $this->cardCreationOptions = $value; + return $this; + } + + /** + * @return ?Event + */ + public function getEvent(): ?Event + { + return $this->event; + } + + /** + * @param ?Event $value + */ + public function setEvent(?Event $value = null): self + { + $this->event = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/SubscriptionTypeList.php b/src/Types/SubscriptionTypeList.php new file mode 100644 index 00000000..7c292dd0 --- /dev/null +++ b/src/Types/SubscriptionTypeList.php @@ -0,0 +1,81 @@ + $data A list of subscription type objects associated with the workspace . + */ + #[JsonProperty('data'), ArrayType([SubscriptionType::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TagCompanyRequest.php b/src/Types/TagCompanyRequest.php new file mode 100644 index 00000000..65c4d1a1 --- /dev/null +++ b/src/Types/TagCompanyRequest.php @@ -0,0 +1,80 @@ + $companies The id or company_id of the company can be passed as input parameters. + */ + #[JsonProperty('companies'), ArrayType([TagCompanyRequestCompaniesItem::class])] + private array $companies; + + /** + * @param array{ + * name: string, + * companies: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->companies = $values['companies']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getCompanies(): array + { + return $this->companies; + } + + /** + * @param array $value + */ + public function setCompanies(array $value): self + { + $this->companies = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TagCompanyRequestCompaniesItem.php b/src/Types/TagCompanyRequestCompaniesItem.php new file mode 100644 index 00000000..9bb79a9e --- /dev/null +++ b/src/Types/TagCompanyRequestCompaniesItem.php @@ -0,0 +1,76 @@ +id = $values['id'] ?? null; + $this->companyId = $values['companyId'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TagList.php b/src/Types/TagList.php new file mode 100644 index 00000000..c9a3e646 --- /dev/null +++ b/src/Types/TagList.php @@ -0,0 +1,81 @@ + $data A list of tags objects associated with the workspace . + */ + #[JsonProperty('data'), ArrayType([Tag::class])] + private array $data; + + /** + * @param array{ + * type: 'list', + * data: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->data = $values['data']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getData(): array + { + return $this->data; + } + + /** + * @param array $value + */ + public function setData(array $value): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TagMultipleUsersRequest.php b/src/Types/TagMultipleUsersRequest.php new file mode 100644 index 00000000..390e3c33 --- /dev/null +++ b/src/Types/TagMultipleUsersRequest.php @@ -0,0 +1,80 @@ + $users + */ + #[JsonProperty('users'), ArrayType([TagMultipleUsersRequestUsersItem::class])] + private array $users; + + /** + * @param array{ + * name: string, + * users: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->users = $values['users']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getUsers(): array + { + return $this->users; + } + + /** + * @param array $value + */ + public function setUsers(array $value): self + { + $this->users = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TagMultipleUsersRequestUsersItem.php b/src/Types/TagMultipleUsersRequestUsersItem.php new file mode 100644 index 00000000..ca6c9a66 --- /dev/null +++ b/src/Types/TagMultipleUsersRequestUsersItem.php @@ -0,0 +1,51 @@ +id = $values['id'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Tags.php b/src/Types/Tags.php new file mode 100644 index 00000000..598c5439 --- /dev/null +++ b/src/Types/Tags.php @@ -0,0 +1,81 @@ + $tags A list of tags objects associated with the conversation. + */ + #[JsonProperty('tags'), ArrayType([Tag::class])] + private array $tags; + + /** + * @param array{ + * type: 'tag.list', + * tags: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->tags = $values['tags']; + } + + /** + * @return 'tag.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'tag.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * @param array $value + */ + public function setTags(array $value): self + { + $this->tags = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TeamList.php b/src/Types/TeamList.php new file mode 100644 index 00000000..86708755 --- /dev/null +++ b/src/Types/TeamList.php @@ -0,0 +1,81 @@ + $teams A list of team objects + */ + #[JsonProperty('teams'), ArrayType([Team::class])] + private array $teams; + + /** + * @param array{ + * type: 'team.list', + * teams: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->teams = $values['teams']; + } + + /** + * @return 'team.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'team.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getTeams(): array + { + return $this->teams; + } + + /** + * @param array $value + */ + public function setTeams(array $value): self + { + $this->teams = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TeamPriorityLevel.php b/src/Types/TeamPriorityLevel.php new file mode 100644 index 00000000..4cd0f2e5 --- /dev/null +++ b/src/Types/TeamPriorityLevel.php @@ -0,0 +1,80 @@ + $primaryTeamIds The primary team ids for the team + */ + #[JsonProperty('primary_team_ids'), ArrayType(['integer'])] + private ?array $primaryTeamIds; + + /** + * @var ?array $secondaryTeamIds The secondary team ids for the team + */ + #[JsonProperty('secondary_team_ids'), ArrayType(['integer'])] + private ?array $secondaryTeamIds; + + /** + * @param array{ + * primaryTeamIds?: ?array, + * secondaryTeamIds?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->primaryTeamIds = $values['primaryTeamIds'] ?? null; + $this->secondaryTeamIds = $values['secondaryTeamIds'] ?? null; + } + + /** + * @return ?array + */ + public function getPrimaryTeamIds(): ?array + { + return $this->primaryTeamIds; + } + + /** + * @param ?array $value + */ + public function setPrimaryTeamIds(?array $value = null): self + { + $this->primaryTeamIds = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSecondaryTeamIds(): ?array + { + return $this->secondaryTeamIds; + } + + /** + * @param ?array $value + */ + public function setSecondaryTeamIds(?array $value = null): self + { + $this->secondaryTeamIds = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TextAreaComponent.php b/src/Types/TextAreaComponent.php new file mode 100644 index 00000000..7d8ac7fe --- /dev/null +++ b/src/Types/TextAreaComponent.php @@ -0,0 +1,181 @@ +id = $values['id']; + $this->label = $values['label'] ?? null; + $this->placeholder = $values['placeholder'] ?? null; + $this->value = $values['value'] ?? null; + $this->error = $values['error'] ?? null; + $this->disabled = $values['disabled'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLabel(): ?string + { + return $this->label; + } + + /** + * @param ?string $value + */ + public function setLabel(?string $value = null): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPlaceholder(): ?string + { + return $this->placeholder; + } + + /** + * @param ?string $value + */ + public function setPlaceholder(?string $value = null): self + { + $this->placeholder = $value; + return $this; + } + + /** + * @return ?string + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * @param ?string $value + */ + public function setValue(?string $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getError(): ?bool + { + return $this->error; + } + + /** + * @param ?bool $value + */ + public function setError(?bool $value = null): self + { + $this->error = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDisabled(): ?bool + { + return $this->disabled; + } + + /** + * @param ?bool $value + */ + public function setDisabled(?bool $value = null): self + { + $this->disabled = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TextComponent.php b/src/Types/TextComponent.php new file mode 100644 index 00000000..df322298 --- /dev/null +++ b/src/Types/TextComponent.php @@ -0,0 +1,154 @@ + $align Aligns the text. Default is `left`. + */ + #[JsonProperty('align')] + private ?string $align; + + /** + * @var ?value-of $style Styles the text. Default is `paragraph`. + */ + #[JsonProperty('style')] + private ?string $style; + + /** + * @var ?'none' $bottomMargin Disables a component's margin-bottom of 10px. + */ + #[JsonProperty('bottom_margin')] + private ?string $bottomMargin; + + /** + * @param array{ + * text: string, + * id?: ?string, + * align?: ?value-of, + * style?: ?value-of, + * bottomMargin?: ?'none', + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id'] ?? null; + $this->text = $values['text']; + $this->align = $values['align'] ?? null; + $this->style = $values['style'] ?? null; + $this->bottomMargin = $values['bottomMargin'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getAlign(): ?string + { + return $this->align; + } + + /** + * @param ?value-of $value + */ + public function setAlign(?string $value = null): self + { + $this->align = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getStyle(): ?string + { + return $this->style; + } + + /** + * @param ?value-of $value + */ + public function setStyle(?string $value = null): self + { + $this->style = $value; + return $this; + } + + /** + * @return ?'none' + */ + public function getBottomMargin(): ?string + { + return $this->bottomMargin; + } + + /** + * @param ?'none' $value + */ + public function setBottomMargin(?string $value = null): self + { + $this->bottomMargin = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TextComponentAlign.php b/src/Types/TextComponentAlign.php new file mode 100644 index 00000000..ab4576a0 --- /dev/null +++ b/src/Types/TextComponentAlign.php @@ -0,0 +1,10 @@ + $tickets The list of ticket objects + */ + #[JsonProperty('tickets'), ArrayType([Ticket::class])] + private array $tickets; + + /** + * @var int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type: 'ticket.list', + * tickets: array, + * totalCount: int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->tickets = $values['tickets']; + $this->totalCount = $values['totalCount']; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return 'ticket.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getTickets(): array + { + return $this->tickets; + } + + /** + * @param array $value + */ + public function setTickets(array $value): self + { + $this->tickets = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TicketPartAuthor.php b/src/Types/TicketPartAuthor.php new file mode 100644 index 00000000..2f3e2920 --- /dev/null +++ b/src/Types/TicketPartAuthor.php @@ -0,0 +1,129 @@ + $type The type of the author + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The id of the author + */ + #[JsonProperty('id')] + private string $id; + + /** + * @var ?string $name The name of the author + */ + #[JsonProperty('name')] + private ?string $name; + + /** + * @var string $email The email of the author + */ + #[JsonProperty('email')] + private string $email; + + /** + * @param array{ + * type: value-of, + * id: string, + * email: string, + * name?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->name = $values['name'] ?? null; + $this->email = $values['email']; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TicketPartAuthorType.php b/src/Types/TicketPartAuthorType.php new file mode 100644 index 00000000..6990f0a1 --- /dev/null +++ b/src/Types/TicketPartAuthorType.php @@ -0,0 +1,11 @@ + $ticketParts A list of Ticket Part objects for each ticket. There is a limit of 500 parts. + */ + #[JsonProperty('ticket_parts'), ArrayType([TicketPart::class])] + private array $ticketParts; + + /** + * @var int $totalCount + */ + #[JsonProperty('total_count')] + private int $totalCount; + + /** + * @param array{ + * type: 'ticket_part.list', + * ticketParts: array, + * totalCount: int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->ticketParts = $values['ticketParts']; + $this->totalCount = $values['totalCount']; + } + + /** + * @return 'ticket_part.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_part.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getTicketParts(): array + { + return $this->ticketParts; + } + + /** + * @param array $value + */ + public function setTicketParts(array $value): self + { + $this->ticketParts = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TicketReply.php b/src/Types/TicketReply.php new file mode 100644 index 00000000..c2439b71 --- /dev/null +++ b/src/Types/TicketReply.php @@ -0,0 +1,255 @@ + $partType Type of the part + */ + #[JsonProperty('part_type')] + private string $partType; + + /** + * @var ?string $body The message body, which may contain HTML. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var int $createdAt The time the note was created. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var ?int $updatedAt The last time the note was updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?TicketPartAuthor $author + */ + #[JsonProperty('author')] + private ?TicketPartAuthor $author; + + /** + * @var ?array $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?bool $redacted Whether or not the ticket part has been redacted. + */ + #[JsonProperty('redacted')] + private ?bool $redacted; + + /** + * @param array{ + * type: 'ticket_part', + * id: string, + * partType: value-of, + * createdAt: int, + * body?: ?string, + * updatedAt?: ?int, + * author?: ?TicketPartAuthor, + * attachments?: ?array, + * redacted?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->partType = $values['partType']; + $this->body = $values['body'] ?? null; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->author = $values['author'] ?? null; + $this->attachments = $values['attachments'] ?? null; + $this->redacted = $values['redacted'] ?? null; + } + + /** + * @return 'ticket_part' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_part' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return value-of + */ + public function getPartType(): string + { + return $this->partType; + } + + /** + * @param value-of $value + */ + public function setPartType(string $value): self + { + $this->partType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?TicketPartAuthor + */ + public function getAuthor(): ?TicketPartAuthor + { + return $this->author; + } + + /** + * @param ?TicketPartAuthor $value + */ + public function setAuthor(?TicketPartAuthor $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRedacted(): ?bool + { + return $this->redacted; + } + + /** + * @param ?bool $value + */ + public function setRedacted(?bool $value = null): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TicketReplyPartType.php b/src/Types/TicketReplyPartType.php new file mode 100644 index 00000000..ec414525 --- /dev/null +++ b/src/Types/TicketReplyPartType.php @@ -0,0 +1,10 @@ + $dataType The type of the data attribute (allowed values: "string list integer decimal boolean datetime files") + */ + #[JsonProperty('data_type')] + private string $dataType; + + /** + * @var array $inputOptions Input options for the attribute + */ + #[JsonProperty('input_options'), ArrayType(['string' => 'mixed'])] + private array $inputOptions; + + /** + * @var int $order The order of the attribute against other attributes + */ + #[JsonProperty('order')] + private int $order; + + /** + * @var bool $requiredToCreate Whether the attribute is required or not for teammates. + */ + #[JsonProperty('required_to_create')] + private bool $requiredToCreate; + + /** + * @var bool $requiredToCreateForContacts Whether the attribute is required or not for contacts. + */ + #[JsonProperty('required_to_create_for_contacts')] + private bool $requiredToCreateForContacts; + + /** + * @var bool $visibleOnCreate Whether the attribute is visible or not to teammates. + */ + #[JsonProperty('visible_on_create')] + private bool $visibleOnCreate; + + /** + * @var bool $visibleToContacts Whether the attribute is visible or not to contacts. + */ + #[JsonProperty('visible_to_contacts')] + private bool $visibleToContacts; + + /** + * @var bool $default Whether the attribute is built in or not. + */ + #[JsonProperty('default')] + private bool $default; + + /** + * @var int $ticketTypeId The id of the ticket type that the attribute belongs to. + */ + #[JsonProperty('ticket_type_id')] + private int $ticketTypeId; + + /** + * @var bool $archived Whether the ticket type attribute is archived or not. + */ + #[JsonProperty('archived')] + private bool $archived; + + /** + * @var int $createdAt The date and time the ticket type attribute was created. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var ?int $updatedAt The date and time the ticket type attribute was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @param array{ + * type: 'ticket_type_attribute', + * id: string, + * workspaceId: string, + * name: string, + * description: string, + * dataType: value-of, + * inputOptions: array, + * order: int, + * requiredToCreate: bool, + * requiredToCreateForContacts: bool, + * visibleOnCreate: bool, + * visibleToContacts: bool, + * default: bool, + * ticketTypeId: int, + * archived: bool, + * createdAt: int, + * updatedAt?: ?int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->workspaceId = $values['workspaceId']; + $this->name = $values['name']; + $this->description = $values['description']; + $this->dataType = $values['dataType']; + $this->inputOptions = $values['inputOptions']; + $this->order = $values['order']; + $this->requiredToCreate = $values['requiredToCreate']; + $this->requiredToCreateForContacts = $values['requiredToCreateForContacts']; + $this->visibleOnCreate = $values['visibleOnCreate']; + $this->visibleToContacts = $values['visibleToContacts']; + $this->default = $values['default']; + $this->ticketTypeId = $values['ticketTypeId']; + $this->archived = $values['archived']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return 'ticket_type_attribute' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_type_attribute' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getWorkspaceId(): string + { + return $this->workspaceId; + } + + /** + * @param string $value + */ + public function setWorkspaceId(string $value): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return value-of + */ + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param value-of $value + */ + public function setDataType(string $value): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return array + */ + public function getInputOptions(): array + { + return $this->inputOptions; + } + + /** + * @param array $value + */ + public function setInputOptions(array $value): self + { + $this->inputOptions = $value; + return $this; + } + + /** + * @return int + */ + public function getOrder(): int + { + return $this->order; + } + + /** + * @param int $value + */ + public function setOrder(int $value): self + { + $this->order = $value; + return $this; + } + + /** + * @return bool + */ + public function getRequiredToCreate(): bool + { + return $this->requiredToCreate; + } + + /** + * @param bool $value + */ + public function setRequiredToCreate(bool $value): self + { + $this->requiredToCreate = $value; + return $this; + } + + /** + * @return bool + */ + public function getRequiredToCreateForContacts(): bool + { + return $this->requiredToCreateForContacts; + } + + /** + * @param bool $value + */ + public function setRequiredToCreateForContacts(bool $value): self + { + $this->requiredToCreateForContacts = $value; + return $this; + } + + /** + * @return bool + */ + public function getVisibleOnCreate(): bool + { + return $this->visibleOnCreate; + } + + /** + * @param bool $value + */ + public function setVisibleOnCreate(bool $value): self + { + $this->visibleOnCreate = $value; + return $this; + } + + /** + * @return bool + */ + public function getVisibleToContacts(): bool + { + return $this->visibleToContacts; + } + + /** + * @param bool $value + */ + public function setVisibleToContacts(bool $value): self + { + $this->visibleToContacts = $value; + return $this; + } + + /** + * @return bool + */ + public function getDefault(): bool + { + return $this->default; + } + + /** + * @param bool $value + */ + public function setDefault(bool $value): self + { + $this->default = $value; + return $this; + } + + /** + * @return int + */ + public function getTicketTypeId(): int + { + return $this->ticketTypeId; + } + + /** + * @param int $value + */ + public function setTicketTypeId(int $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return bool + */ + public function getArchived(): bool + { + return $this->archived; + } + + /** + * @param bool $value + */ + public function setArchived(bool $value): self + { + $this->archived = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TicketTypeAttributeDataType.php b/src/Types/TicketTypeAttributeDataType.php new file mode 100644 index 00000000..6ea8fa82 --- /dev/null +++ b/src/Types/TicketTypeAttributeDataType.php @@ -0,0 +1,14 @@ + $ticketTypeAttributes A list of ticket type attributes associated with a given ticket type. + */ + #[JsonProperty('ticket_type_attributes'), ArrayType([TicketTypeAttribute::class])] + private array $ticketTypeAttributes; + + /** + * @param array{ + * type: 'ticket_type_attributes.list', + * ticketTypeAttributes: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->ticketTypeAttributes = $values['ticketTypeAttributes']; + } + + /** + * @return 'ticket_type_attributes.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_type_attributes.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getTicketTypeAttributes(): array + { + return $this->ticketTypeAttributes; + } + + /** + * @param array $value + */ + public function setTicketTypeAttributes(array $value): self + { + $this->ticketTypeAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/TicketTypeList.php b/src/Types/TicketTypeList.php new file mode 100644 index 00000000..53612bb8 --- /dev/null +++ b/src/Types/TicketTypeList.php @@ -0,0 +1,81 @@ + $ticketTypes A list of ticket_types associated with a given workspace. + */ + #[JsonProperty('ticket_types'), ArrayType([TicketType::class])] + private array $ticketTypes; + + /** + * @param array{ + * type: 'ticket_type_attributes.list', + * ticketTypes: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->ticketTypes = $values['ticketTypes']; + } + + /** + * @return 'ticket_type_attributes.list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'ticket_type_attributes.list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return array + */ + public function getTicketTypes(): array + { + return $this->ticketTypes; + } + + /** + * @param array $value + */ + public function setTicketTypes(array $value): self + { + $this->ticketTypes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Translation.php b/src/Types/Translation.php new file mode 100644 index 00000000..8be582a2 --- /dev/null +++ b/src/Types/Translation.php @@ -0,0 +1,104 @@ +name = $values['name']; + $this->description = $values['description']; + $this->locale = $values['locale']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function getLocale(): string + { + return $this->locale; + } + + /** + * @param string $value + */ + public function setLocale(string $value): self + { + $this->locale = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/UntagCompanyRequest.php b/src/Types/UntagCompanyRequest.php new file mode 100644 index 00000000..85219f5f --- /dev/null +++ b/src/Types/UntagCompanyRequest.php @@ -0,0 +1,80 @@ + $companies The id or company_id of the company can be passed as input parameters. + */ + #[JsonProperty('companies'), ArrayType([UntagCompanyRequestCompaniesItem::class])] + private array $companies; + + /** + * @param array{ + * name: string, + * companies: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->companies = $values['companies']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getCompanies(): array + { + return $this->companies; + } + + /** + * @param array $value + */ + public function setCompanies(array $value): self + { + $this->companies = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/UntagCompanyRequestCompaniesItem.php b/src/Types/UntagCompanyRequestCompaniesItem.php new file mode 100644 index 00000000..badf1b7e --- /dev/null +++ b/src/Types/UntagCompanyRequestCompaniesItem.php @@ -0,0 +1,101 @@ +id = $values['id']; + $this->companyId = $values['companyId']; + $this->untag = $values['untag']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return true + */ + public function getUntag(): bool + { + return $this->untag; + } + + /** + * @param true $value + */ + public function setUntag(bool $value): self + { + $this->untag = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/UpdateVisitorRequestWithId.php b/src/Types/UpdateVisitorRequestWithId.php new file mode 100644 index 00000000..f4483ee4 --- /dev/null +++ b/src/Types/UpdateVisitorRequestWithId.php @@ -0,0 +1,102 @@ + $customAttributes The custom attributes which are set for the visitor. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'string'])] + private ?array $customAttributes; + + /** + * @param array{ + * id: string, + * name?: ?string, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->name = $values['name'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/UpdateVisitorRequestWithUserId.php b/src/Types/UpdateVisitorRequestWithUserId.php new file mode 100644 index 00000000..157691c5 --- /dev/null +++ b/src/Types/UpdateVisitorRequestWithUserId.php @@ -0,0 +1,102 @@ + $customAttributes The custom attributes which are set for the visitor. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'string'])] + private ?array $customAttributes; + + /** + * @param array{ + * userId: string, + * name?: ?string, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->userId = $values['userId']; + $this->name = $values['name'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/UrlActionComponent.php b/src/Types/UrlActionComponent.php new file mode 100644 index 00000000..fcac8784 --- /dev/null +++ b/src/Types/UrlActionComponent.php @@ -0,0 +1,54 @@ +url = $values['url']; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/Visitor.php b/src/Types/Visitor.php new file mode 100644 index 00000000..05a9dd9c --- /dev/null +++ b/src/Types/Visitor.php @@ -0,0 +1,855 @@ + $customAttributes The custom attributes you have set on the Visitor. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @var ?string $referrer The referer of the visitor. + */ + #[JsonProperty('referrer')] + private ?string $referrer; + + /** + * @var ?string $utmCampaign The utm_campaign of the visitor. + */ + #[JsonProperty('utm_campaign')] + private ?string $utmCampaign; + + /** + * @var ?string $utmContent The utm_content of the visitor. + */ + #[JsonProperty('utm_content')] + private ?string $utmContent; + + /** + * @var ?string $utmMedium The utm_medium of the visitor. + */ + #[JsonProperty('utm_medium')] + private ?string $utmMedium; + + /** + * @var ?string $utmSource The utm_source of the visitor. + */ + #[JsonProperty('utm_source')] + private ?string $utmSource; + + /** + * @var ?string $utmTerm The utm_term of the visitor. + */ + #[JsonProperty('utm_term')] + private ?string $utmTerm; + + /** + * @var ?bool $doNotTrack Identifies if this visitor has do not track enabled. + */ + #[JsonProperty('do_not_track')] + private ?bool $doNotTrack; + + /** + * @param array{ + * type: 'visitor', + * id: string, + * userId: string, + * anonymous: bool, + * email: string, + * appId: string, + * createdAt: int, + * signedUpAt: int, + * phone?: ?string, + * name?: ?string, + * pseudonym?: ?string, + * avatar?: ?VisitorAvatar, + * companies?: ?VisitorCompanies, + * locationData?: ?VisitorLocationData, + * lasRequestAt?: ?int, + * remoteCreatedAt?: ?int, + * updatedAt?: ?int, + * sessionCount?: ?int, + * socialProfiles?: ?VisitorSocialProfiles, + * ownerId?: ?string, + * unsubscribedFromEmails?: ?bool, + * markedEmailAsSpam?: ?bool, + * hasHardBounced?: ?bool, + * tags?: ?VisitorTags, + * segments?: ?VisitorSegments, + * customAttributes?: ?array, + * referrer?: ?string, + * utmCampaign?: ?string, + * utmContent?: ?string, + * utmMedium?: ?string, + * utmSource?: ?string, + * utmTerm?: ?string, + * doNotTrack?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->userId = $values['userId']; + $this->anonymous = $values['anonymous']; + $this->email = $values['email']; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->pseudonym = $values['pseudonym'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->appId = $values['appId']; + $this->companies = $values['companies'] ?? null; + $this->locationData = $values['locationData'] ?? null; + $this->lasRequestAt = $values['lasRequestAt'] ?? null; + $this->createdAt = $values['createdAt']; + $this->remoteCreatedAt = $values['remoteCreatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt']; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->sessionCount = $values['sessionCount'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->segments = $values['segments'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->referrer = $values['referrer'] ?? null; + $this->utmCampaign = $values['utmCampaign'] ?? null; + $this->utmContent = $values['utmContent'] ?? null; + $this->utmMedium = $values['utmMedium'] ?? null; + $this->utmSource = $values['utmSource'] ?? null; + $this->utmTerm = $values['utmTerm'] ?? null; + $this->doNotTrack = $values['doNotTrack'] ?? null; + } + + /** + * @return 'visitor' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'visitor' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return bool + */ + public function getAnonymous(): bool + { + return $this->anonymous; + } + + /** + * @param bool $value + */ + public function setAnonymous(bool $value): self + { + $this->anonymous = $value; + return $this; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPseudonym(): ?string + { + return $this->pseudonym; + } + + /** + * @param ?string $value + */ + public function setPseudonym(?string $value = null): self + { + $this->pseudonym = $value; + return $this; + } + + /** + * @return ?VisitorAvatar + */ + public function getAvatar(): ?VisitorAvatar + { + return $this->avatar; + } + + /** + * @param ?VisitorAvatar $value + */ + public function setAvatar(?VisitorAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return string + */ + public function getAppId(): string + { + return $this->appId; + } + + /** + * @param string $value + */ + public function setAppId(string $value): self + { + $this->appId = $value; + return $this; + } + + /** + * @return ?VisitorCompanies + */ + public function getCompanies(): ?VisitorCompanies + { + return $this->companies; + } + + /** + * @param ?VisitorCompanies $value + */ + public function setCompanies(?VisitorCompanies $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return ?VisitorLocationData + */ + public function getLocationData(): ?VisitorLocationData + { + return $this->locationData; + } + + /** + * @param ?VisitorLocationData $value + */ + public function setLocationData(?VisitorLocationData $value = null): self + { + $this->locationData = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLasRequestAt(): ?int + { + return $this->lasRequestAt; + } + + /** + * @param ?int $value + */ + public function setLasRequestAt(?int $value = null): self + { + $this->lasRequestAt = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRemoteCreatedAt(): ?int + { + return $this->remoteCreatedAt; + } + + /** + * @param ?int $value + */ + public function setRemoteCreatedAt(?int $value = null): self + { + $this->remoteCreatedAt = $value; + return $this; + } + + /** + * @return int + */ + public function getSignedUpAt(): int + { + return $this->signedUpAt; + } + + /** + * @param int $value + */ + public function setSignedUpAt(int $value): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSessionCount(): ?int + { + return $this->sessionCount; + } + + /** + * @param ?int $value + */ + public function setSessionCount(?int $value = null): self + { + $this->sessionCount = $value; + return $this; + } + + /** + * @return ?VisitorSocialProfiles + */ + public function getSocialProfiles(): ?VisitorSocialProfiles + { + return $this->socialProfiles; + } + + /** + * @param ?VisitorSocialProfiles $value + */ + public function setSocialProfiles(?VisitorSocialProfiles $value = null): self + { + $this->socialProfiles = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOwnerId(): ?string + { + return $this->ownerId; + } + + /** + * @param ?string $value + */ + public function setOwnerId(?string $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMarkedEmailAsSpam(): ?bool + { + return $this->markedEmailAsSpam; + } + + /** + * @param ?bool $value + */ + public function setMarkedEmailAsSpam(?bool $value = null): self + { + $this->markedEmailAsSpam = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasHardBounced(): ?bool + { + return $this->hasHardBounced; + } + + /** + * @param ?bool $value + */ + public function setHasHardBounced(?bool $value = null): self + { + $this->hasHardBounced = $value; + return $this; + } + + /** + * @return ?VisitorTags + */ + public function getTags(): ?VisitorTags + { + return $this->tags; + } + + /** + * @param ?VisitorTags $value + */ + public function setTags(?VisitorTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?VisitorSegments + */ + public function getSegments(): ?VisitorSegments + { + return $this->segments; + } + + /** + * @param ?VisitorSegments $value + */ + public function setSegments(?VisitorSegments $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?string + */ + public function getReferrer(): ?string + { + return $this->referrer; + } + + /** + * @param ?string $value + */ + public function setReferrer(?string $value = null): self + { + $this->referrer = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmCampaign(): ?string + { + return $this->utmCampaign; + } + + /** + * @param ?string $value + */ + public function setUtmCampaign(?string $value = null): self + { + $this->utmCampaign = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmContent(): ?string + { + return $this->utmContent; + } + + /** + * @param ?string $value + */ + public function setUtmContent(?string $value = null): self + { + $this->utmContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmMedium(): ?string + { + return $this->utmMedium; + } + + /** + * @param ?string $value + */ + public function setUtmMedium(?string $value = null): self + { + $this->utmMedium = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmSource(): ?string + { + return $this->utmSource; + } + + /** + * @param ?string $value + */ + public function setUtmSource(?string $value = null): self + { + $this->utmSource = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmTerm(): ?string + { + return $this->utmTerm; + } + + /** + * @param ?string $value + */ + public function setUtmTerm(?string $value = null): self + { + $this->utmTerm = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDoNotTrack(): ?bool + { + return $this->doNotTrack; + } + + /** + * @param ?bool $value + */ + public function setDoNotTrack(?bool $value = null): self + { + $this->doNotTrack = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorAvatar.php b/src/Types/VisitorAvatar.php new file mode 100644 index 00000000..151d8adf --- /dev/null +++ b/src/Types/VisitorAvatar.php @@ -0,0 +1,76 @@ +type = $values['type'] ?? null; + $this->imageUrl = $values['imageUrl'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * @param ?string $value + */ + public function setImageUrl(?string $value = null): self + { + $this->imageUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorCompanies.php b/src/Types/VisitorCompanies.php new file mode 100644 index 00000000..d0f9e7df --- /dev/null +++ b/src/Types/VisitorCompanies.php @@ -0,0 +1,78 @@ + $companies + */ + #[JsonProperty('companies'), ArrayType([Company::class])] + private ?array $companies; + + /** + * @param array{ + * type?: ?'company.list', + * companies?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->companies = $values['companies'] ?? null; + } + + /** + * @return ?'company.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'company.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCompanies(): ?array + { + return $this->companies; + } + + /** + * @param ?array $value + */ + public function setCompanies(?array $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorDeletedObject.php b/src/Types/VisitorDeletedObject.php new file mode 100644 index 00000000..4b9d5867 --- /dev/null +++ b/src/Types/VisitorDeletedObject.php @@ -0,0 +1,104 @@ +id = $values['id']; + $this->type = $values['type']; + $this->userId = $values['userId']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return 'visitor' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'visitor' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorLocationData.php b/src/Types/VisitorLocationData.php new file mode 100644 index 00000000..528ef5ca --- /dev/null +++ b/src/Types/VisitorLocationData.php @@ -0,0 +1,226 @@ +type = $values['type'] ?? null; + $this->cityName = $values['cityName'] ?? null; + $this->continentCode = $values['continentCode'] ?? null; + $this->countryCode = $values['countryCode'] ?? null; + $this->countryName = $values['countryName'] ?? null; + $this->postalCode = $values['postalCode'] ?? null; + $this->regionName = $values['regionName'] ?? null; + $this->timezone = $values['timezone'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCityName(): ?string + { + return $this->cityName; + } + + /** + * @param ?string $value + */ + public function setCityName(?string $value = null): self + { + $this->cityName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContinentCode(): ?string + { + return $this->continentCode; + } + + /** + * @param ?string $value + */ + public function setContinentCode(?string $value = null): self + { + $this->continentCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCountryCode(): ?string + { + return $this->countryCode; + } + + /** + * @param ?string $value + */ + public function setCountryCode(?string $value = null): self + { + $this->countryCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCountryName(): ?string + { + return $this->countryName; + } + + /** + * @param ?string $value + */ + public function setCountryName(?string $value = null): self + { + $this->countryName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPostalCode(): ?string + { + return $this->postalCode; + } + + /** + * @param ?string $value + */ + public function setPostalCode(?string $value = null): self + { + $this->postalCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRegionName(): ?string + { + return $this->regionName; + } + + /** + * @param ?string $value + */ + public function setRegionName(?string $value = null): self + { + $this->regionName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTimezone(): ?string + { + return $this->timezone; + } + + /** + * @param ?string $value + */ + public function setTimezone(?string $value = null): self + { + $this->timezone = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorSegments.php b/src/Types/VisitorSegments.php new file mode 100644 index 00000000..6ebc2eda --- /dev/null +++ b/src/Types/VisitorSegments.php @@ -0,0 +1,77 @@ + $segments + */ + #[JsonProperty('segments'), ArrayType(['string'])] + private ?array $segments; + + /** + * @param array{ + * type?: ?'segment.list', + * segments?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->segments = $values['segments'] ?? null; + } + + /** + * @return ?'segment.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'segment.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSegments(): ?array + { + return $this->segments; + } + + /** + * @param ?array $value + */ + public function setSegments(?array $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorSocialProfiles.php b/src/Types/VisitorSocialProfiles.php new file mode 100644 index 00000000..e8b49954 --- /dev/null +++ b/src/Types/VisitorSocialProfiles.php @@ -0,0 +1,77 @@ + $socialProfiles + */ + #[JsonProperty('social_profiles'), ArrayType(['string'])] + private ?array $socialProfiles; + + /** + * @param array{ + * type?: ?'social_profile.list', + * socialProfiles?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + } + + /** + * @return ?'social_profile.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'social_profile.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSocialProfiles(): ?array + { + return $this->socialProfiles; + } + + /** + * @param ?array $value + */ + public function setSocialProfiles(?array $value = null): self + { + $this->socialProfiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorTags.php b/src/Types/VisitorTags.php new file mode 100644 index 00000000..b37d17ec --- /dev/null +++ b/src/Types/VisitorTags.php @@ -0,0 +1,77 @@ + $tags + */ + #[JsonProperty('tags'), ArrayType([VisitorTagsTagsItem::class])] + private ?array $tags; + + /** + * @param array{ + * type?: ?'tag.list', + * tags?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->tags = $values['tags'] ?? null; + } + + /** + * @return ?'tag.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTags(): ?array + { + return $this->tags; + } + + /** + * @param ?array $value + */ + public function setTags(?array $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Types/VisitorTagsTagsItem.php b/src/Types/VisitorTagsTagsItem.php new file mode 100644 index 00000000..6061f6c4 --- /dev/null +++ b/src/Types/VisitorTagsTagsItem.php @@ -0,0 +1,101 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?'tag' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Admins/AdminsClient.php b/src/Unstable/Admins/AdminsClient.php new file mode 100644 index 00000000..f0e63614 --- /dev/null +++ b/src/Unstable/Admins/AdminsClient.php @@ -0,0 +1,352 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * + * You can view the currently authorised admin along with the embedded app object (a "workspace" in legacy terminology). + * + * > 🚧 Single Sign On + * > + * > If you are building a custom "Log in with Intercom" flow for your site, and you call the `/me` endpoint to identify the logged-in user, you should not accept any sign-ins from users with unverified email addresses as it poses a potential impersonation security risk. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?AdminWithApp + * @throws IntercomException + * @throws IntercomApiException + */ + public function identifyAdmin(?array $options = null): ?AdminWithApp + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "me", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return AdminWithApp::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can set an Admin as away for the Inbox. + * + * @param SetAwayAdminRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Admin + * @throws IntercomException + * @throws IntercomApiException + */ + public function setAwayAdmin(SetAwayAdminRequest $request, ?array $options = null): ?Admin + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins/{$request->getId()}/away", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Admin::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can get a log of activities by all admins in an app. + * + * @param ListActivityLogsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ActivityLogList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listActivityLogs(ListActivityLogsRequest $request, ?array $options = null): ActivityLogList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['created_at_after'] = $request->getCreatedAtAfter(); + if ($request->getCreatedAtBefore() != null) { + $query['created_at_before'] = $request->getCreatedAtBefore(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins/activity_logs", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ActivityLogList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of admins for a given workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return AdminList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAdmins(?array $options = null): AdminList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return AdminList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can retrieve the details of a single admin. + * + * @param RetrieveAdminRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Admin + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveAdmin(RetrieveAdminRequest $request, ?array $options = null): ?Admin + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "admins/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Admin::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Admins/Requests/ListActivityLogsRequest.php b/src/Unstable/Admins/Requests/ListActivityLogsRequest.php new file mode 100644 index 00000000..75968519 --- /dev/null +++ b/src/Unstable/Admins/Requests/ListActivityLogsRequest.php @@ -0,0 +1,65 @@ +createdAtAfter = $values['createdAtAfter']; + $this->createdAtBefore = $values['createdAtBefore'] ?? null; + } + + /** + * @return string + */ + public function getCreatedAtAfter(): string + { + return $this->createdAtAfter; + } + + /** + * @param string $value + */ + public function setCreatedAtAfter(string $value): self + { + $this->createdAtAfter = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCreatedAtBefore(): ?string + { + return $this->createdAtBefore; + } + + /** + * @param ?string $value + */ + public function setCreatedAtBefore(?string $value = null): self + { + $this->createdAtBefore = $value; + return $this; + } +} diff --git a/src/Unstable/Admins/Requests/RetrieveAdminRequest.php b/src/Unstable/Admins/Requests/RetrieveAdminRequest.php new file mode 100644 index 00000000..82a0e2bf --- /dev/null +++ b/src/Unstable/Admins/Requests/RetrieveAdminRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Admins/Requests/SetAwayAdminRequest.php b/src/Unstable/Admins/Requests/SetAwayAdminRequest.php new file mode 100644 index 00000000..4319e6e6 --- /dev/null +++ b/src/Unstable/Admins/Requests/SetAwayAdminRequest.php @@ -0,0 +1,117 @@ +id = $values['id']; + $this->awayModeEnabled = $values['awayModeEnabled']; + $this->awayModeReassign = $values['awayModeReassign']; + $this->awayStatusReasonId = $values['awayStatusReasonId'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeEnabled(): bool + { + return $this->awayModeEnabled; + } + + /** + * @param bool $value + */ + public function setAwayModeEnabled(bool $value): self + { + $this->awayModeEnabled = $value; + return $this; + } + + /** + * @return bool + */ + public function getAwayModeReassign(): bool + { + return $this->awayModeReassign; + } + + /** + * @param bool $value + */ + 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; + } +} diff --git a/src/Unstable/Admins/Types/Admin.php b/src/Unstable/Admins/Types/Admin.php new file mode 100644 index 00000000..20e93976 --- /dev/null +++ b/src/Unstable/Admins/Types/Admin.php @@ -0,0 +1,331 @@ + $teamIds This object represents the avatar associated with the admin. + */ + #[JsonProperty('team_ids'), ArrayType(['integer'])] + private ?array $teamIds; + + /** + * @var ?string $avatar Image for the associated team or teammate + */ + #[JsonProperty('avatar')] + private ?string $avatar; + + /** + * @var ?TeamPriorityLevel $teamPriorityLevel + */ + #[JsonProperty('team_priority_level')] + private ?TeamPriorityLevel $teamPriorityLevel; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * name?: ?string, + * email?: ?string, + * jobTitle?: ?string, + * awayModeEnabled?: ?bool, + * awayModeReassign?: ?bool, + * awayStatusReasonId?: ?int, + * hasInboxSeat?: ?bool, + * teamIds?: ?array, + * avatar?: ?string, + * teamPriorityLevel?: ?TeamPriorityLevel, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->email = $values['email'] ?? null; + $this->jobTitle = $values['jobTitle'] ?? null; + $this->awayModeEnabled = $values['awayModeEnabled'] ?? null; + $this->awayModeReassign = $values['awayModeReassign'] ?? null; + $this->awayStatusReasonId = $values['awayStatusReasonId'] ?? null; + $this->hasInboxSeat = $values['hasInboxSeat'] ?? null; + $this->teamIds = $values['teamIds'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->teamPriorityLevel = $values['teamPriorityLevel'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getJobTitle(): ?string + { + return $this->jobTitle; + } + + /** + * @param ?string $value + */ + public function setJobTitle(?string $value = null): self + { + $this->jobTitle = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAwayModeEnabled(): ?bool + { + return $this->awayModeEnabled; + } + + /** + * @param ?bool $value + */ + public function setAwayModeEnabled(?bool $value = null): self + { + $this->awayModeEnabled = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAwayModeReassign(): ?bool + { + return $this->awayModeReassign; + } + + /** + * @param ?bool $value + */ + public function setAwayModeReassign(?bool $value = null): 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; + } + + /** + * @return ?bool + */ + public function getHasInboxSeat(): ?bool + { + return $this->hasInboxSeat; + } + + /** + * @param ?bool $value + */ + public function setHasInboxSeat(?bool $value = null): self + { + $this->hasInboxSeat = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTeamIds(): ?array + { + return $this->teamIds; + } + + /** + * @param ?array $value + */ + public function setTeamIds(?array $value = null): self + { + $this->teamIds = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?TeamPriorityLevel + */ + public function getTeamPriorityLevel(): ?TeamPriorityLevel + { + return $this->teamPriorityLevel; + } + + /** + * @param ?TeamPriorityLevel $value + */ + public function setTeamPriorityLevel(?TeamPriorityLevel $value = null): self + { + $this->teamPriorityLevel = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiAgent/Types/AiAgent.php b/src/Unstable/AiAgent/Types/AiAgent.php new file mode 100644 index 00000000..d2a66c1d --- /dev/null +++ b/src/Unstable/AiAgent/Types/AiAgent.php @@ -0,0 +1,205 @@ + $sourceType The type of the source that triggered AI Agent involvement in the conversation. + */ + #[JsonProperty('source_type')] + private ?string $sourceType; + + /** + * @var ?string $sourceTitle The title of the source that triggered AI Agent involvement in the conversation. If this is `essentials_plan_setup` then it will return `null`. + */ + #[JsonProperty('source_title')] + private ?string $sourceTitle; + + /** + * @var ?string $lastAnswerType The type of the last answer delivered by AI Agent. If no answer was delivered then this will return `null` + */ + #[JsonProperty('last_answer_type')] + private ?string $lastAnswerType; + + /** + * @var ?string $resolutionState The resolution state of AI Agent. If no AI or custom answer has been delivered then this will return `null`. + */ + #[JsonProperty('resolution_state')] + private ?string $resolutionState; + + /** + * @var ?int $rating The customer satisfaction rating given to AI Agent, from 1-5. + */ + #[JsonProperty('rating')] + private ?int $rating; + + /** + * @var ?string $ratingRemark The customer satisfaction rating remark given to AI Agent. + */ + #[JsonProperty('rating_remark')] + private ?string $ratingRemark; + + /** + * @var ?ContentSourcesList $contentSources + */ + #[JsonProperty('content_sources')] + private ?ContentSourcesList $contentSources; + + /** + * @param array{ + * sourceType?: ?value-of, + * sourceTitle?: ?string, + * lastAnswerType?: ?string, + * resolutionState?: ?string, + * rating?: ?int, + * ratingRemark?: ?string, + * contentSources?: ?ContentSourcesList, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->sourceType = $values['sourceType'] ?? null; + $this->sourceTitle = $values['sourceTitle'] ?? null; + $this->lastAnswerType = $values['lastAnswerType'] ?? null; + $this->resolutionState = $values['resolutionState'] ?? null; + $this->rating = $values['rating'] ?? null; + $this->ratingRemark = $values['ratingRemark'] ?? null; + $this->contentSources = $values['contentSources'] ?? null; + } + + /** + * @return ?value-of + */ + public function getSourceType(): ?string + { + return $this->sourceType; + } + + /** + * @param ?value-of $value + */ + public function setSourceType(?string $value = null): self + { + $this->sourceType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSourceTitle(): ?string + { + return $this->sourceTitle; + } + + /** + * @param ?string $value + */ + public function setSourceTitle(?string $value = null): self + { + $this->sourceTitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLastAnswerType(): ?string + { + return $this->lastAnswerType; + } + + /** + * @param ?string $value + */ + public function setLastAnswerType(?string $value = null): self + { + $this->lastAnswerType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getResolutionState(): ?string + { + return $this->resolutionState; + } + + /** + * @param ?string $value + */ + public function setResolutionState(?string $value = null): self + { + $this->resolutionState = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRating(): ?int + { + return $this->rating; + } + + /** + * @param ?int $value + */ + public function setRating(?int $value = null): self + { + $this->rating = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRatingRemark(): ?string + { + return $this->ratingRemark; + } + + /** + * @param ?string $value + */ + public function setRatingRemark(?string $value = null): self + { + $this->ratingRemark = $value; + return $this; + } + + /** + * @return ?ContentSourcesList + */ + public function getContentSources(): ?ContentSourcesList + { + return $this->contentSources; + } + + /** + * @param ?ContentSourcesList $value + */ + public function setContentSources(?ContentSourcesList $value = null): self + { + $this->contentSources = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiAgent/Types/AiAgentSourceType.php b/src/Unstable/AiAgent/Types/AiAgentSourceType.php new file mode 100644 index 00000000..88b52d89 --- /dev/null +++ b/src/Unstable/AiAgent/Types/AiAgentSourceType.php @@ -0,0 +1,12 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can retrieve a list of all content import sources for a workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContentImportSourcesList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listContentImportSources(?array $options = null): ContentImportSourcesList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/content_import_sources", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContentImportSourcesList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new content import source by sending a POST request to this endpoint. + * + * @param CreateContentImportSourceRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContentImportSource + * @throws IntercomException + * @throws IntercomApiException + */ + public function createContentImportSource(CreateContentImportSourceRequest $request, ?array $options = null): ContentImportSource + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/content_import_sources", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContentImportSource::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * @param GetContentImportSourceRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContentImportSource + * @throws IntercomException + * @throws IntercomApiException + */ + public function getContentImportSource(GetContentImportSourceRequest $request, ?array $options = null): ContentImportSource + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/content_import_sources/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContentImportSource::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update an existing content import source. + * + * @param UpdateContentImportSourceRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContentImportSource + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateContentImportSource(UpdateContentImportSourceRequest $request, ?array $options = null): ContentImportSource + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/content_import_sources/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContentImportSource::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a content import source by making a DELETE request this endpoint. This will also delete all external pages that were imported from this source. + * + * @param DeleteContentImportSourceRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteContentImportSource(DeleteContentImportSourceRequest $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/content_import_sources/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can retrieve a list of all external pages for a workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ExternalPagesList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listExternalPages(?array $options = null): ExternalPagesList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/external_pages", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ExternalPagesList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new external page by sending a POST request to this endpoint. If an external page already exists with the specified source_id and external_id, it will be updated instead. + * + * @param CreateExternalPageRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ExternalPage + * @throws IntercomException + * @throws IntercomApiException + */ + public function createExternalPage(CreateExternalPageRequest $request, ?array $options = null): ExternalPage + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/external_pages", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ExternalPage::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can retrieve an external page. + * + * @param GetExternalPageRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ExternalPage + * @throws IntercomException + * @throws IntercomApiException + */ + public function getExternalPage(GetExternalPageRequest $request, ?array $options = null): ExternalPage + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/external_pages/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ExternalPage::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update an existing external page (if it was created via the API). + * + * @param UpdateExternalPageRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ExternalPage + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateExternalPage(UpdateExternalPageRequest $request, ?array $options = null): ExternalPage + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/external_pages/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ExternalPage::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Sending a DELETE request for an external page will remove it from the content library UI and from being used for AI answers. + * + * @param DeleteExternalPageRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ExternalPage + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteExternalPage(DeleteExternalPageRequest $request, ?array $options = null): ExternalPage + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ai/external_pages/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ExternalPage::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/AiContent/Requests/CreateContentImportSourceRequest.php b/src/Unstable/AiContent/Requests/CreateContentImportSourceRequest.php new file mode 100644 index 00000000..5e072671 --- /dev/null +++ b/src/Unstable/AiContent/Requests/CreateContentImportSourceRequest.php @@ -0,0 +1,94 @@ + $status The status of the content import source. + */ + #[JsonProperty('status')] + private ?string $status; + + /** + * @var string $url The URL of the content import source. + */ + #[JsonProperty('url')] + private string $url; + + /** + * @param array{ + * syncBehavior: 'api', + * url: string, + * status?: ?value-of, + * } $values + */ + public function __construct( + array $values, + ) { + $this->syncBehavior = $values['syncBehavior']; + $this->status = $values['status'] ?? null; + $this->url = $values['url']; + } + + /** + * @return 'api' + */ + public function getSyncBehavior(): string + { + return $this->syncBehavior; + } + + /** + * @param 'api' $value + */ + public function setSyncBehavior(string $value): self + { + $this->syncBehavior = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getStatus(): ?string + { + return $this->status; + } + + /** + * @param ?value-of $value + */ + public function setStatus(?string $value = null): self + { + $this->status = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/CreateExternalPageRequest.php b/src/Unstable/AiContent/Requests/CreateExternalPageRequest.php new file mode 100644 index 00000000..ac5483f5 --- /dev/null +++ b/src/Unstable/AiContent/Requests/CreateExternalPageRequest.php @@ -0,0 +1,218 @@ +title = $values['title']; + $this->html = $values['html']; + $this->url = $values['url'] ?? null; + $this->aiAgentAvailability = $values['aiAgentAvailability'] ?? null; + $this->aiCopilotAvailability = $values['aiCopilotAvailability'] ?? null; + $this->locale = $values['locale']; + $this->sourceId = $values['sourceId']; + $this->externalId = $values['externalId']; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return string + */ + public function getHtml(): string + { + return $this->html; + } + + /** + * @param string $value + */ + public function setHtml(string $value): self + { + $this->html = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAiAgentAvailability(): ?bool + { + return $this->aiAgentAvailability; + } + + /** + * @param ?bool $value + */ + public function setAiAgentAvailability(?bool $value = null): self + { + $this->aiAgentAvailability = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAiCopilotAvailability(): ?bool + { + return $this->aiCopilotAvailability; + } + + /** + * @param ?bool $value + */ + public function setAiCopilotAvailability(?bool $value = null): self + { + $this->aiCopilotAvailability = $value; + return $this; + } + + /** + * @return 'en' + */ + public function getLocale(): string + { + return $this->locale; + } + + /** + * @param 'en' $value + */ + public function setLocale(string $value): self + { + $this->locale = $value; + return $this; + } + + /** + * @return int + */ + public function getSourceId(): int + { + return $this->sourceId; + } + + /** + * @param int $value + */ + public function setSourceId(int $value): self + { + $this->sourceId = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/DeleteContentImportSourceRequest.php b/src/Unstable/AiContent/Requests/DeleteContentImportSourceRequest.php new file mode 100644 index 00000000..6bd8981d --- /dev/null +++ b/src/Unstable/AiContent/Requests/DeleteContentImportSourceRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/DeleteExternalPageRequest.php b/src/Unstable/AiContent/Requests/DeleteExternalPageRequest.php new file mode 100644 index 00000000..974e1dce --- /dev/null +++ b/src/Unstable/AiContent/Requests/DeleteExternalPageRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/GetContentImportSourceRequest.php b/src/Unstable/AiContent/Requests/GetContentImportSourceRequest.php new file mode 100644 index 00000000..361237aa --- /dev/null +++ b/src/Unstable/AiContent/Requests/GetContentImportSourceRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/GetExternalPageRequest.php b/src/Unstable/AiContent/Requests/GetExternalPageRequest.php new file mode 100644 index 00000000..36b5fb3d --- /dev/null +++ b/src/Unstable/AiContent/Requests/GetExternalPageRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/UpdateContentImportSourceRequest.php b/src/Unstable/AiContent/Requests/UpdateContentImportSourceRequest.php new file mode 100644 index 00000000..b5489ed1 --- /dev/null +++ b/src/Unstable/AiContent/Requests/UpdateContentImportSourceRequest.php @@ -0,0 +1,119 @@ + $syncBehavior If you intend to create or update External Pages via the API, this should be set to `api`. You can not change the value to or from api. + */ + #[JsonProperty('sync_behavior')] + private string $syncBehavior; + + /** + * @var ?value-of $status The status of the content import source. + */ + #[JsonProperty('status')] + private ?string $status; + + /** + * @var string $url The URL of the content import source. This may only be different from the existing value if the sync behavior is API. + */ + #[JsonProperty('url')] + private string $url; + + /** + * @param array{ + * id: string, + * syncBehavior: value-of, + * url: string, + * status?: ?value-of, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->syncBehavior = $values['syncBehavior']; + $this->status = $values['status'] ?? null; + $this->url = $values['url']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return value-of + */ + public function getSyncBehavior(): string + { + return $this->syncBehavior; + } + + /** + * @param value-of $value + */ + public function setSyncBehavior(string $value): self + { + $this->syncBehavior = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getStatus(): ?string + { + return $this->status; + } + + /** + * @param ?value-of $value + */ + public function setStatus(?string $value = null): self + { + $this->status = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Requests/UpdateExternalPageRequest.php b/src/Unstable/AiContent/Requests/UpdateExternalPageRequest.php new file mode 100644 index 00000000..1f8567ef --- /dev/null +++ b/src/Unstable/AiContent/Requests/UpdateExternalPageRequest.php @@ -0,0 +1,217 @@ +id = $values['id']; + $this->title = $values['title']; + $this->html = $values['html']; + $this->url = $values['url']; + $this->finAvailability = $values['finAvailability'] ?? null; + $this->locale = $values['locale']; + $this->sourceId = $values['sourceId']; + $this->externalId = $values['externalId'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return string + */ + public function getHtml(): string + { + return $this->html; + } + + /** + * @param string $value + */ + public function setHtml(string $value): self + { + $this->html = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getFinAvailability(): ?bool + { + return $this->finAvailability; + } + + /** + * @param ?bool $value + */ + public function setFinAvailability(?bool $value = null): self + { + $this->finAvailability = $value; + return $this; + } + + /** + * @return 'en' + */ + public function getLocale(): string + { + return $this->locale; + } + + /** + * @param 'en' $value + */ + public function setLocale(string $value): self + { + $this->locale = $value; + return $this; + } + + /** + * @return int + */ + public function getSourceId(): int + { + return $this->sourceId; + } + + /** + * @param int $value + */ + public function setSourceId(int $value): self + { + $this->sourceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } +} diff --git a/src/Unstable/AiContent/Types/ContentImportSource.php b/src/Unstable/AiContent/Types/ContentImportSource.php new file mode 100644 index 00000000..46694236 --- /dev/null +++ b/src/Unstable/AiContent/Types/ContentImportSource.php @@ -0,0 +1,229 @@ + $syncBehavior If you intend to create or update External Pages via the API, this should be set to `api`. + */ + #[JsonProperty('sync_behavior')] + private string $syncBehavior; + + /** + * @var value-of $status The status of the content import source. + */ + #[JsonProperty('status')] + private string $status; + + /** + * @var string $url The URL of the root of the external source. + */ + #[JsonProperty('url')] + private string $url; + + /** + * @var int $createdAt The time when the content import source was created. + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var int $updatedAt The time when the content import source was last updated. + */ + #[JsonProperty('updated_at')] + private int $updatedAt; + + /** + * @param array{ + * type: 'content_import_source', + * id: int, + * lastSyncedAt: int, + * syncBehavior: value-of, + * status: value-of, + * url: string, + * createdAt: int, + * updatedAt: int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->lastSyncedAt = $values['lastSyncedAt']; + $this->syncBehavior = $values['syncBehavior']; + $this->status = $values['status']; + $this->url = $values['url']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + } + + /** + * @return 'content_import_source' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'content_import_source' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return int + */ + public function getLastSyncedAt(): int + { + return $this->lastSyncedAt; + } + + /** + * @param int $value + */ + public function setLastSyncedAt(int $value): self + { + $this->lastSyncedAt = $value; + return $this; + } + + /** + * @return value-of + */ + public function getSyncBehavior(): string + { + return $this->syncBehavior; + } + + /** + * @param value-of $value + */ + public function setSyncBehavior(string $value): self + { + $this->syncBehavior = $value; + return $this; + } + + /** + * @return value-of + */ + public function getStatus(): string + { + return $this->status; + } + + /** + * @param value-of $value + */ + public function setStatus(string $value): self + { + $this->status = $value; + return $this; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $value + */ + public function setUrl(string $value): self + { + $this->url = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiContent/Types/ContentImportSourceStatus.php b/src/Unstable/AiContent/Types/ContentImportSourceStatus.php new file mode 100644 index 00000000..7795aa96 --- /dev/null +++ b/src/Unstable/AiContent/Types/ContentImportSourceStatus.php @@ -0,0 +1,9 @@ + $data An array of Content Import Source objects + */ + #[JsonProperty('data'), ArrayType([ContentImportSource::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * pages?: ?PagesLink, + * totalCount?: ?int, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?PagesLink + */ + public function getPages(): ?PagesLink + { + return $this->pages; + } + + /** + * @param ?PagesLink $value + */ + public function setPages(?PagesLink $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiContent/Types/CreateContentImportSourceRequestStatus.php b/src/Unstable/AiContent/Types/CreateContentImportSourceRequestStatus.php new file mode 100644 index 00000000..44bab297 --- /dev/null +++ b/src/Unstable/AiContent/Types/CreateContentImportSourceRequestStatus.php @@ -0,0 +1,9 @@ +type = $values['type']; + $this->id = $values['id']; + $this->title = $values['title']; + $this->html = $values['html']; + $this->url = $values['url'] ?? null; + $this->aiAgentAvailability = $values['aiAgentAvailability']; + $this->aiCopilotAvailability = $values['aiCopilotAvailability']; + $this->finAvailability = $values['finAvailability'] ?? null; + $this->locale = $values['locale']; + $this->sourceId = $values['sourceId']; + $this->externalId = $values['externalId']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->lastIngestedAt = $values['lastIngestedAt']; + } + + /** + * @return 'external_page' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'external_page' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return string + */ + public function getHtml(): string + { + return $this->html; + } + + /** + * @param string $value + */ + public function setHtml(string $value): self + { + $this->html = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return bool + */ + public function getAiAgentAvailability(): bool + { + return $this->aiAgentAvailability; + } + + /** + * @param bool $value + */ + public function setAiAgentAvailability(bool $value): self + { + $this->aiAgentAvailability = $value; + return $this; + } + + /** + * @return bool + */ + public function getAiCopilotAvailability(): bool + { + return $this->aiCopilotAvailability; + } + + /** + * @param bool $value + */ + public function setAiCopilotAvailability(bool $value): self + { + $this->aiCopilotAvailability = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getFinAvailability(): ?bool + { + return $this->finAvailability; + } + + /** + * @param ?bool $value + */ + public function setFinAvailability(?bool $value = null): self + { + $this->finAvailability = $value; + return $this; + } + + /** + * @return 'en' + */ + public function getLocale(): string + { + return $this->locale; + } + + /** + * @param 'en' $value + */ + public function setLocale(string $value): self + { + $this->locale = $value; + return $this; + } + + /** + * @return int + */ + public function getSourceId(): int + { + return $this->sourceId; + } + + /** + * @param int $value + */ + public function setSourceId(int $value): self + { + $this->sourceId = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return int + */ + public function getLastIngestedAt(): int + { + return $this->lastIngestedAt; + } + + /** + * @param int $value + */ + public function setLastIngestedAt(int $value): self + { + $this->lastIngestedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiContent/Types/ExternalPagesList.php b/src/Unstable/AiContent/Types/ExternalPagesList.php new file mode 100644 index 00000000..087ed6c5 --- /dev/null +++ b/src/Unstable/AiContent/Types/ExternalPagesList.php @@ -0,0 +1,131 @@ + $data An array of External Page objects + */ + #[JsonProperty('data'), ArrayType([ExternalPage::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * pages?: ?PagesLink, + * totalCount?: ?int, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?PagesLink + */ + public function getPages(): ?PagesLink + { + return $this->pages; + } + + /** + * @param ?PagesLink $value + */ + public function setPages(?PagesLink $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiContent/Types/UpdateContentImportSourceRequestStatus.php b/src/Unstable/AiContent/Types/UpdateContentImportSourceRequestStatus.php new file mode 100644 index 00000000..48ba0531 --- /dev/null +++ b/src/Unstable/AiContent/Types/UpdateContentImportSourceRequestStatus.php @@ -0,0 +1,9 @@ + $contentType The type of the content source. + */ + #[JsonProperty('content_type')] + private ?string $contentType; + + /** + * @var ?string $url The internal URL linking to the content source for teammates. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?string $title The title of the content source. + */ + #[JsonProperty('title')] + private ?string $title; + + /** + * @var ?string $locale The ISO 639 language code of the content source. + */ + #[JsonProperty('locale')] + private ?string $locale; + + /** + * @param array{ + * contentType?: ?value-of, + * url?: ?string, + * title?: ?string, + * locale?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->contentType = $values['contentType'] ?? null; + $this->url = $values['url'] ?? null; + $this->title = $values['title'] ?? null; + $this->locale = $values['locale'] ?? null; + } + + /** + * @return ?value-of + */ + public function getContentType(): ?string + { + return $this->contentType; + } + + /** + * @param ?value-of $value + */ + public function setContentType(?string $value = null): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLocale(): ?string + { + return $this->locale; + } + + /** + * @param ?string $value + */ + public function setLocale(?string $value = null): self + { + $this->locale = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AiContentSource/Types/ContentSourceContentType.php b/src/Unstable/AiContentSource/Types/ContentSourceContentType.php new file mode 100644 index 00000000..bec58aac --- /dev/null +++ b/src/Unstable/AiContentSource/Types/ContentSourceContentType.php @@ -0,0 +1,12 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all articles by making a GET request to `https://api.intercom.io/articles`. + * + * > 📘 How are the articles sorted and ordered? + * > + * > Articles will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated articles first. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ArticleList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listArticles(?array $options = null): ArticleList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ArticleList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new article by making a POST request to `https://api.intercom.io/articles`. + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Article + * @throws IntercomException + * @throws IntercomApiException + */ + public function createArticle(mixed $request, ?array $options = null): Article + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Article::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single article by making a GET request to `https://api.intercom.io/articles/`. + * + * @param RetrieveArticleRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Article + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveArticle(RetrieveArticleRequest $request, ?array $options = null): Article + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Article::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single article by making a DELETE request to `https://api.intercom.io/articles/`. + * + * @param DeleteArticleRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedArticleObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteArticle(DeleteArticleRequest $request, ?array $options = null): DeletedArticleObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedArticleObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for articles by making a GET request to `https://api.intercom.io/articles/search`. + * + * @param SearchArticlesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ArticleSearchResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function searchArticles(SearchArticlesRequest $request = new SearchArticlesRequest(), ?array $options = null): ArticleSearchResponse + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPhrase() != null) { + $query['phrase'] = $request->getPhrase(); + } + if ($request->getState() != null) { + $query['state'] = $request->getState(); + } + if ($request->getHelpCenterId() != null) { + $query['help_center_id'] = $request->getHelpCenterId(); + } + if ($request->getHighlight() != null) { + $query['highlight'] = $request->getHighlight(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "articles/search", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ArticleSearchResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Articles/Requests/DeleteArticleRequest.php b/src/Unstable/Articles/Requests/DeleteArticleRequest.php new file mode 100644 index 00000000..4befcc80 --- /dev/null +++ b/src/Unstable/Articles/Requests/DeleteArticleRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Articles/Requests/RetrieveArticleRequest.php b/src/Unstable/Articles/Requests/RetrieveArticleRequest.php new file mode 100644 index 00000000..ab29665b --- /dev/null +++ b/src/Unstable/Articles/Requests/RetrieveArticleRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Articles/Requests/SearchArticlesRequest.php b/src/Unstable/Articles/Requests/SearchArticlesRequest.php new file mode 100644 index 00000000..7ee313c1 --- /dev/null +++ b/src/Unstable/Articles/Requests/SearchArticlesRequest.php @@ -0,0 +1,113 @@ +phrase = $values['phrase'] ?? null; + $this->state = $values['state'] ?? null; + $this->helpCenterId = $values['helpCenterId'] ?? null; + $this->highlight = $values['highlight'] ?? null; + } + + /** + * @return ?string + */ + public function getPhrase(): ?string + { + return $this->phrase; + } + + /** + * @param ?string $value + */ + public function setPhrase(?string $value = null): self + { + $this->phrase = $value; + return $this; + } + + /** + * @return ?string + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?string $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHelpCenterId(): ?int + { + return $this->helpCenterId; + } + + /** + * @param ?int $value + */ + public function setHelpCenterId(?int $value = null): self + { + $this->helpCenterId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHighlight(): ?bool + { + return $this->highlight; + } + + /** + * @param ?bool $value + */ + public function setHighlight(?bool $value = null): self + { + $this->highlight = $value; + return $this; + } +} diff --git a/src/Unstable/Articles/Traits/ArticleListItem.php b/src/Unstable/Articles/Traits/ArticleListItem.php new file mode 100644 index 00000000..62c492bc --- /dev/null +++ b/src/Unstable/Articles/Traits/ArticleListItem.php @@ -0,0 +1,399 @@ + $state + * @property ?int $createdAt + * @property ?int $updatedAt + * @property ?string $url + * @property ?int $parentId + * @property ?array $parentIds + * @property ?string $parentType + * @property ?string $defaultLocale + * @property ?ArticleTranslatedContent $translatedContent + */ +trait ArticleListItem +{ + /** + * @var ?'article' $type The type of object - `article`. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $id The unique identifier for the article which is given by Intercom. + */ + #[JsonProperty('id')] + private ?string $id; + + /** + * @var ?string $workspaceId The id of the workspace which the article belongs to. + */ + #[JsonProperty('workspace_id')] + private ?string $workspaceId; + + /** + * @var ?string $title The title of the article. For multilingual articles, this will be the title of the default language's content. + */ + #[JsonProperty('title')] + private ?string $title; + + /** + * @var ?string $description The description of the article. For multilingual articles, this will be the description of the default language's content. + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var ?string $body The body of the article in HTML. For multilingual articles, this will be the body of the default language's content. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var ?int $authorId The id of the author of the article. For multilingual articles, this will be the id of the author of the default language's content. Must be a teammate on the help center's workspace. + */ + #[JsonProperty('author_id')] + private ?int $authorId; + + /** + * @var ?value-of $state Whether the article is `published` or is a `draft`. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?int $createdAt The time when the article was created. For multilingual articles, this will be the timestamp of creation of the default language's content in seconds. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The time when the article was last updated. For multilingual articles, this will be the timestamp of last update of the default language's content in seconds. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?string $url The URL of the article. For multilingual articles, this will be the URL of the default language's content. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?int $parentId; + + /** + * @var ?array $parentIds The ids of the article's parent collections or sections. An article without this field stands alone. + */ + #[JsonProperty('parent_ids'), ArrayType(['integer'])] + private ?array $parentIds; + + /** + * @var ?string $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?string $defaultLocale The default locale of the help center. This field is only returned for multilingual help centers. + */ + #[JsonProperty('default_locale')] + private ?string $defaultLocale; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @return ?'article' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'article' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAuthorId(): ?int + { + return $this->authorId; + } + + /** + * @param ?int $value + */ + public function setAuthorId(?int $value = null): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getParentId(): ?int + { + return $this->parentId; + } + + /** + * @param ?int $value + */ + public function setParentId(?int $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getParentIds(): ?array + { + return $this->parentIds; + } + + /** + * @param ?array $value + */ + public function setParentIds(?array $value = null): self + { + $this->parentIds = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?string $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultLocale(): ?string + { + return $this->defaultLocale; + } + + /** + * @param ?string $value + */ + public function setDefaultLocale(?string $value = null): self + { + $this->defaultLocale = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } +} diff --git a/src/Unstable/Articles/Types/Article.php b/src/Unstable/Articles/Types/Article.php new file mode 100644 index 00000000..7f7f49e5 --- /dev/null +++ b/src/Unstable/Articles/Types/Article.php @@ -0,0 +1,91 @@ +, + * createdAt?: ?int, + * updatedAt?: ?int, + * url?: ?string, + * parentId?: ?int, + * parentIds?: ?array, + * parentType?: ?string, + * defaultLocale?: ?string, + * translatedContent?: ?ArticleTranslatedContent, + * statistics?: ?ArticleStatistics, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->title = $values['title'] ?? null; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId'] ?? null; + $this->state = $values['state'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->url = $values['url'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentIds = $values['parentIds'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->defaultLocale = $values['defaultLocale'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->statistics = $values['statistics'] ?? null; + } + + /** + * @return ?ArticleStatistics + */ + public function getStatistics(): ?ArticleStatistics + { + return $this->statistics; + } + + /** + * @param ?ArticleStatistics $value + */ + public function setStatistics(?ArticleStatistics $value = null): self + { + $this->statistics = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Articles/Types/ArticleListItem.php b/src/Unstable/Articles/Types/ArticleListItem.php new file mode 100644 index 00000000..8cb9aa67 --- /dev/null +++ b/src/Unstable/Articles/Types/ArticleListItem.php @@ -0,0 +1,431 @@ + $state Whether the article is `published` or is a `draft`. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?int $createdAt The time when the article was created. For multilingual articles, this will be the timestamp of creation of the default language's content in seconds. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The time when the article was last updated. For multilingual articles, this will be the timestamp of last update of the default language's content in seconds. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?string $url The URL of the article. For multilingual articles, this will be the URL of the default language's content. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?int $parentId; + + /** + * @var ?array $parentIds The ids of the article's parent collections or sections. An article without this field stands alone. + */ + #[JsonProperty('parent_ids'), ArrayType(['integer'])] + private ?array $parentIds; + + /** + * @var ?string $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?string $defaultLocale The default locale of the help center. This field is only returned for multilingual help centers. + */ + #[JsonProperty('default_locale')] + private ?string $defaultLocale; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @param array{ + * type?: ?'article', + * id?: ?string, + * workspaceId?: ?string, + * title?: ?string, + * description?: ?string, + * body?: ?string, + * authorId?: ?int, + * state?: ?value-of, + * createdAt?: ?int, + * updatedAt?: ?int, + * url?: ?string, + * parentId?: ?int, + * parentIds?: ?array, + * parentType?: ?string, + * defaultLocale?: ?string, + * translatedContent?: ?ArticleTranslatedContent, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->title = $values['title'] ?? null; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId'] ?? null; + $this->state = $values['state'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->url = $values['url'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentIds = $values['parentIds'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->defaultLocale = $values['defaultLocale'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + } + + /** + * @return ?'article' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'article' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAuthorId(): ?int + { + return $this->authorId; + } + + /** + * @param ?int $value + */ + public function setAuthorId(?int $value = null): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getParentId(): ?int + { + return $this->parentId; + } + + /** + * @param ?int $value + */ + public function setParentId(?int $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getParentIds(): ?array + { + return $this->parentIds; + } + + /** + * @param ?array $value + */ + public function setParentIds(?array $value = null): self + { + $this->parentIds = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?string $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultLocale(): ?string + { + return $this->defaultLocale; + } + + /** + * @param ?string $value + */ + public function setDefaultLocale(?string $value = null): self + { + $this->defaultLocale = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Articles/Types/ArticleListItemState.php b/src/Unstable/Articles/Types/ArticleListItemState.php new file mode 100644 index 00000000..15747ab9 --- /dev/null +++ b/src/Unstable/Articles/Types/ArticleListItemState.php @@ -0,0 +1,9 @@ + $highlightedTitle An Article title highlighted. + */ + #[JsonProperty('highlighted_title'), ArrayType([ArticleSearchHighlightsHighlightedTitleItem::class])] + private ?array $highlightedTitle; + + /** + * @var ?array> $highlightedSummary An Article description and body text highlighted. + */ + #[JsonProperty('highlighted_summary'), ArrayType([[ArticleSearchHighlightsHighlightedSummaryItemItem::class]])] + private ?array $highlightedSummary; + + /** + * @param array{ + * articleId?: ?string, + * highlightedTitle?: ?array, + * highlightedSummary?: ?array>, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->articleId = $values['articleId'] ?? null; + $this->highlightedTitle = $values['highlightedTitle'] ?? null; + $this->highlightedSummary = $values['highlightedSummary'] ?? null; + } + + /** + * @return ?string + */ + public function getArticleId(): ?string + { + return $this->articleId; + } + + /** + * @param ?string $value + */ + public function setArticleId(?string $value = null): self + { + $this->articleId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getHighlightedTitle(): ?array + { + return $this->highlightedTitle; + } + + /** + * @param ?array $value + */ + public function setHighlightedTitle(?array $value = null): self + { + $this->highlightedTitle = $value; + return $this; + } + + /** + * @return ?array> + */ + public function getHighlightedSummary(): ?array + { + return $this->highlightedSummary; + } + + /** + * @param ?array> $value + */ + public function setHighlightedSummary(?array $value = null): self + { + $this->highlightedSummary = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItem.php b/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItem.php new file mode 100644 index 00000000..f7265af6 --- /dev/null +++ b/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItem.php @@ -0,0 +1,79 @@ + $type The type of text - `highlight` or `plain`. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $text The text of the title. + */ + #[JsonProperty('text')] + private ?string $text; + + /** + * @param array{ + * type?: ?value-of, + * text?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->text = $values['text'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getText(): ?string + { + return $this->text; + } + + /** + * @param ?string $value + */ + public function setText(?string $value = null): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItemType.php b/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItemType.php new file mode 100644 index 00000000..cb25cf12 --- /dev/null +++ b/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedSummaryItemItemType.php @@ -0,0 +1,9 @@ + $type The type of text - `highlight` or `plain`. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $text The text of the title. + */ + #[JsonProperty('text')] + private ?string $text; + + /** + * @param array{ + * type?: ?value-of, + * text?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->text = $values['text'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getText(): ?string + { + return $this->text; + } + + /** + * @param ?string $value + */ + public function setText(?string $value = null): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedTitleItemType.php b/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedTitleItemType.php new file mode 100644 index 00000000..774470e2 --- /dev/null +++ b/src/Unstable/Articles/Types/ArticleSearchHighlightsHighlightedTitleItemType.php @@ -0,0 +1,9 @@ +type = $values['type'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?ArticleSearchResponseData + */ + public function getData(): ?ArticleSearchResponseData + { + return $this->data; + } + + /** + * @param ?ArticleSearchResponseData $value + */ + public function setData(?ArticleSearchResponseData $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Articles/Types/ArticleSearchResponseData.php b/src/Unstable/Articles/Types/ArticleSearchResponseData.php new file mode 100644 index 00000000..b8e94e7e --- /dev/null +++ b/src/Unstable/Articles/Types/ArticleSearchResponseData.php @@ -0,0 +1,80 @@ + $articles An array of Article objects + */ + #[JsonProperty('articles'), ArrayType([Article::class])] + private ?array $articles; + + /** + * @var ?array $highlights A corresponding array of highlighted Article content + */ + #[JsonProperty('highlights'), ArrayType([ArticleSearchHighlights::class])] + private ?array $highlights; + + /** + * @param array{ + * articles?: ?array
, + * highlights?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->articles = $values['articles'] ?? null; + $this->highlights = $values['highlights'] ?? null; + } + + /** + * @return ?array
+ */ + public function getArticles(): ?array + { + return $this->articles; + } + + /** + * @param ?array
$value + */ + public function setArticles(?array $value = null): self + { + $this->articles = $value; + return $this; + } + + /** + * @return ?array + */ + public function getHighlights(): ?array + { + return $this->highlights; + } + + /** + * @param ?array $value + */ + public function setHighlights(?array $value = null): self + { + $this->highlights = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/AwayStatusReasons/AwayStatusReasonsClient.php b/src/Unstable/AwayStatusReasons/AwayStatusReasonsClient.php new file mode 100644 index 00000000..fd5466cd --- /dev/null +++ b/src/Unstable/AwayStatusReasons/AwayStatusReasonsClient.php @@ -0,0 +1,107 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * Returns a list of all away status reasons configured for the workspace, including deleted ones. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return array + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAwayStatusReasons(?array $options = null): array + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "away_status_reasons", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return JsonDecoder::decodeArray($json, [AwayStatusReason::class]); // @phpstan-ignore-line + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Companies/CompaniesClient.php b/src/Unstable/Companies/CompaniesClient.php new file mode 100644 index 00000000..e8fa08ba --- /dev/null +++ b/src/Unstable/Companies/CompaniesClient.php @@ -0,0 +1,757 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a single company by passing in `company_id` or `name`. + * + * `https://api.intercom.io/companies?name={name}` + * + * `https://api.intercom.io/companies?company_id={company_id}` + * + * You can fetch all companies and filter by `segment_id` or `tag_id` as a query parameter. + * + * `https://api.intercom.io/companies?tag_id={tag_id}` + * + * `https://api.intercom.io/companies?segment_id={segment_id}` + * + * @param RetrieveCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyList + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveCompany(RetrieveCompanyRequest $request = new RetrieveCompanyRequest(), ?array $options = null): CompanyList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getName() != null) { + $query['name'] = $request->getName(); + } + if ($request->getCompanyId() != null) { + $query['company_id'] = $request->getCompanyId(); + } + if ($request->getTagId() != null) { + $query['tag_id'] = $request->getTagId(); + } + if ($request->getSegmentId() != null) { + $query['segment_id'] = $request->getSegmentId(); + } + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create or update a company. + * + * Companies will be only visible in Intercom when there is at least one associated user. + * + * Companies are looked up via `company_id` in a `POST` request, if not found via `company_id`, the new company will be created, if found, that company will be updated. + * + * {% admonition type="warning" name="Using `company_id`" %} + * You can set a unique `company_id` value when creating a company. However, it is not possible to update `company_id`. Be sure to set a unique value once upon creation of the company. + * {% /admonition %} + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function createOrUpdateCompany(mixed $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a single company. + * + * @param RetrieveACompanyByIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveACompanyById(RetrieveACompanyByIdRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update a single company using the Intercom provisioned `id`. + * + * {% admonition type="warning" name="Using `company_id`" %} + * When updating a company it is not possible to update `company_id`. This can only be set once upon creation of the company. + * {% /admonition %} + * + * @param UpdateCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateCompany(UpdateCompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getId()}", + method: HttpMethod::PUT, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single company. + * + * @param DeleteCompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedCompanyObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteCompany(DeleteCompanyRequest $request, ?array $options = null): DeletedCompanyObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedCompanyObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all contacts that belong to a company. + * + * @param ListAttachedContactsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyAttachedContacts + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedContacts(ListAttachedContactsRequest $request, ?array $options = null): CompanyAttachedContacts + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getId()}/contacts", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyAttachedContacts::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all segments that belong to a company. + * + * @param ListAttachedSegmentsForCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyAttachedSegments + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAttachedSegmentsForCompanies(ListAttachedSegmentsForCompaniesRequest $request, ?array $options = null): CompanyAttachedSegments + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/{$request->getId()}/segments", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyAttachedSegments::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can list companies. The company list is sorted by the `last_request_at` field and by default is ordered descending, most recently requested first. + * + * Note that the API does not include companies who have no associated users in list responses. + * + * When using the Companies endpoint and the pages object to iterate through the returned companies, there is a limit of 10,000 Companies that can be returned. If you need to list or iterate on more than 10,000 Companies, please use the [Scroll API](https://developers.intercom.com/reference#iterating-over-all-companies). + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListAllCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CompanyList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAllCompanies(ListAllCompaniesRequest $request = new ListAllCompaniesRequest(), ?array $options = null): CompanyList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPage() != null) { + $query['page'] = $request->getPage(); + } + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getOrder() != null) { + $query['order'] = $request->getOrder(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/list", + method: HttpMethod::POST, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CompanyList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * The `list all companies` functionality does not work well for huge datasets, and can result in errors and performance problems when paging deeply. The Scroll API provides an efficient mechanism for iterating over all companies in a dataset. + * + * - Each app can only have 1 scroll open at a time. You'll get an error message if you try to have more than one open per app. + * - If the scroll isn't used for 1 minute, it expires and calls with that scroll param will fail + * - If the end of the scroll is reached, "companies" will be empty and the scroll parameter will expire + * + * {% admonition type="info" name="Scroll Parameter" %} + * You can get the first page of companies by simply sending a GET request to the scroll endpoint. + * For subsequent requests you will need to use the scroll parameter from the response. + * {% /admonition %} + * {% admonition type="danger" name="Scroll network timeouts" %} + * Since scroll is often used on large datasets network errors such as timeouts can be encountered. When this occurs you will see a HTTP 500 error with the following message: + * "Request failed due to an internal network error. Please restart the scroll operation." + * If this happens, you will need to restart your scroll query: It is not possible to continue from a specific point when using scroll. + * {% /admonition %} + * + * @param ScrollOverAllCompaniesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?CompanyScroll + * @throws IntercomException + * @throws IntercomApiException + */ + public function scrollOverAllCompanies(ScrollOverAllCompaniesRequest $request = new ScrollOverAllCompaniesRequest(), ?array $options = null): ?CompanyScroll + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getScrollParam() != null) { + $query['scroll_param'] = $request->getScrollParam(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "companies/scroll", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return CompanyScroll::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can attach a company to a single contact. + * + * @param AttachContactToACompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachContactToACompany(AttachContactToACompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/companies", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can detach a company from a single contact. + * + * @param DetachContactFromACompanyRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Company + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachContactFromACompany(DetachContactFromACompanyRequest $request, ?array $options = null): Company + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/companies/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Company::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Companies/Requests/AttachContactToACompanyRequest.php b/src/Unstable/Companies/Requests/AttachContactToACompanyRequest.php new file mode 100644 index 00000000..6039c12c --- /dev/null +++ b/src/Unstable/Companies/Requests/AttachContactToACompanyRequest.php @@ -0,0 +1,67 @@ +id = $values['id']; + $this->companyId = $values['companyId']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getCompanyId(): string + { + return $this->companyId; + } + + /** + * @param string $value + */ + public function setCompanyId(string $value): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/DeleteCompanyRequest.php b/src/Unstable/Companies/Requests/DeleteCompanyRequest.php new file mode 100644 index 00000000..d04eb812 --- /dev/null +++ b/src/Unstable/Companies/Requests/DeleteCompanyRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/DetachContactFromACompanyRequest.php b/src/Unstable/Companies/Requests/DetachContactFromACompanyRequest.php new file mode 100644 index 00000000..8ea6f864 --- /dev/null +++ b/src/Unstable/Companies/Requests/DetachContactFromACompanyRequest.php @@ -0,0 +1,65 @@ +contactId = $values['contactId']; + $this->id = $values['id']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/ListAllCompaniesRequest.php b/src/Unstable/Companies/Requests/ListAllCompaniesRequest.php new file mode 100644 index 00000000..984903c6 --- /dev/null +++ b/src/Unstable/Companies/Requests/ListAllCompaniesRequest.php @@ -0,0 +1,89 @@ +page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->order = $values['order'] ?? null; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOrder(): ?string + { + return $this->order; + } + + /** + * @param ?string $value + */ + public function setOrder(?string $value = null): self + { + $this->order = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/ListAttachedContactsRequest.php b/src/Unstable/Companies/Requests/ListAttachedContactsRequest.php new file mode 100644 index 00000000..cc0ff728 --- /dev/null +++ b/src/Unstable/Companies/Requests/ListAttachedContactsRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/ListAttachedSegmentsForCompaniesRequest.php b/src/Unstable/Companies/Requests/ListAttachedSegmentsForCompaniesRequest.php new file mode 100644 index 00000000..711bf5d7 --- /dev/null +++ b/src/Unstable/Companies/Requests/ListAttachedSegmentsForCompaniesRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/RetrieveACompanyByIdRequest.php b/src/Unstable/Companies/Requests/RetrieveACompanyByIdRequest.php new file mode 100644 index 00000000..ece187ae --- /dev/null +++ b/src/Unstable/Companies/Requests/RetrieveACompanyByIdRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/RetrieveCompanyRequest.php b/src/Unstable/Companies/Requests/RetrieveCompanyRequest.php new file mode 100644 index 00000000..71546214 --- /dev/null +++ b/src/Unstable/Companies/Requests/RetrieveCompanyRequest.php @@ -0,0 +1,161 @@ +name = $values['name'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->tagId = $values['tagId'] ?? null; + $this->segmentId = $values['segmentId'] ?? null; + $this->page = $values['page'] ?? null; + $this->perPage = $values['perPage'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTagId(): ?string + { + return $this->tagId; + } + + /** + * @param ?string $value + */ + public function setTagId(?string $value = null): self + { + $this->tagId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSegmentId(): ?string + { + return $this->segmentId; + } + + /** + * @param ?string $value + */ + public function setSegmentId(?string $value = null): self + { + $this->segmentId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/ScrollOverAllCompaniesRequest.php b/src/Unstable/Companies/Requests/ScrollOverAllCompaniesRequest.php new file mode 100644 index 00000000..a1994d51 --- /dev/null +++ b/src/Unstable/Companies/Requests/ScrollOverAllCompaniesRequest.php @@ -0,0 +1,41 @@ +scrollParam = $values['scrollParam'] ?? null; + } + + /** + * @return ?string + */ + public function getScrollParam(): ?string + { + return $this->scrollParam; + } + + /** + * @param ?string $value + */ + public function setScrollParam(?string $value = null): self + { + $this->scrollParam = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Requests/UpdateCompanyRequest.php b/src/Unstable/Companies/Requests/UpdateCompanyRequest.php new file mode 100644 index 00000000..fe89a0fc --- /dev/null +++ b/src/Unstable/Companies/Requests/UpdateCompanyRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Companies/Types/Company.php b/src/Unstable/Companies/Types/Company.php new file mode 100644 index 00000000..d61f9fe4 --- /dev/null +++ b/src/Unstable/Companies/Types/Company.php @@ -0,0 +1,505 @@ + $customAttributes The custom attributes you have set on the company. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'string'])] + private ?array $customAttributes; + + /** + * @var ?CompanyTags $tags The list of tags associated with the company + */ + #[JsonProperty('tags')] + private ?CompanyTags $tags; + + /** + * @var ?CompanySegments $segments The list of segments associated with the company + */ + #[JsonProperty('segments')] + private ?CompanySegments $segments; + + /** + * @param array{ + * type?: ?'company', + * id?: ?string, + * name?: ?string, + * appId?: ?string, + * plan?: ?CompanyPlan, + * companyId?: ?string, + * remoteCreatedAt?: ?int, + * createdAt?: ?int, + * updatedAt?: ?int, + * lastRequestAt?: ?int, + * size?: ?int, + * website?: ?string, + * industry?: ?string, + * monthlySpend?: ?int, + * sessionCount?: ?int, + * userCount?: ?int, + * customAttributes?: ?array, + * tags?: ?CompanyTags, + * segments?: ?CompanySegments, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->appId = $values['appId'] ?? null; + $this->plan = $values['plan'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->remoteCreatedAt = $values['remoteCreatedAt'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->lastRequestAt = $values['lastRequestAt'] ?? null; + $this->size = $values['size'] ?? null; + $this->website = $values['website'] ?? null; + $this->industry = $values['industry'] ?? null; + $this->monthlySpend = $values['monthlySpend'] ?? null; + $this->sessionCount = $values['sessionCount'] ?? null; + $this->userCount = $values['userCount'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->segments = $values['segments'] ?? null; + } + + /** + * @return ?'company' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'company' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAppId(): ?string + { + return $this->appId; + } + + /** + * @param ?string $value + */ + public function setAppId(?string $value = null): self + { + $this->appId = $value; + return $this; + } + + /** + * @return ?CompanyPlan + */ + public function getPlan(): ?CompanyPlan + { + return $this->plan; + } + + /** + * @param ?CompanyPlan $value + */ + public function setPlan(?CompanyPlan $value = null): self + { + $this->plan = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRemoteCreatedAt(): ?int + { + return $this->remoteCreatedAt; + } + + /** + * @param ?int $value + */ + public function setRemoteCreatedAt(?int $value = null): self + { + $this->remoteCreatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastRequestAt(): ?int + { + return $this->lastRequestAt; + } + + /** + * @param ?int $value + */ + public function setLastRequestAt(?int $value = null): self + { + $this->lastRequestAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSize(): ?int + { + return $this->size; + } + + /** + * @param ?int $value + */ + public function setSize(?int $value = null): self + { + $this->size = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWebsite(): ?string + { + return $this->website; + } + + /** + * @param ?string $value + */ + public function setWebsite(?string $value = null): self + { + $this->website = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIndustry(): ?string + { + return $this->industry; + } + + /** + * @param ?string $value + */ + public function setIndustry(?string $value = null): self + { + $this->industry = $value; + return $this; + } + + /** + * @return ?int + */ + public function getMonthlySpend(): ?int + { + return $this->monthlySpend; + } + + /** + * @param ?int $value + */ + public function setMonthlySpend(?int $value = null): self + { + $this->monthlySpend = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSessionCount(): ?int + { + return $this->sessionCount; + } + + /** + * @param ?int $value + */ + public function setSessionCount(?int $value = null): self + { + $this->sessionCount = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUserCount(): ?int + { + return $this->userCount; + } + + /** + * @param ?int $value + */ + public function setUserCount(?int $value = null): self + { + $this->userCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?CompanyTags + */ + public function getTags(): ?CompanyTags + { + return $this->tags; + } + + /** + * @param ?CompanyTags $value + */ + public function setTags(?CompanyTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?CompanySegments + */ + public function getSegments(): ?CompanySegments + { + return $this->segments; + } + + /** + * @param ?CompanySegments $value + */ + public function setSegments(?CompanySegments $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Companies/Types/CompanyPlan.php b/src/Unstable/Companies/Types/CompanyPlan.php new file mode 100644 index 00000000..f85feb9e --- /dev/null +++ b/src/Unstable/Companies/Types/CompanyPlan.php @@ -0,0 +1,101 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Companies/Types/CompanySegments.php b/src/Unstable/Companies/Types/CompanySegments.php new file mode 100644 index 00000000..baec465c --- /dev/null +++ b/src/Unstable/Companies/Types/CompanySegments.php @@ -0,0 +1,81 @@ + $segments + */ + #[JsonProperty('segments'), ArrayType([Segment::class])] + private ?array $segments; + + /** + * @param array{ + * type?: ?'segment.list', + * segments?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->segments = $values['segments'] ?? null; + } + + /** + * @return ?'segment.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'segment.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSegments(): ?array + { + return $this->segments; + } + + /** + * @param ?array $value + */ + public function setSegments(?array $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Companies/Types/CompanyTags.php b/src/Unstable/Companies/Types/CompanyTags.php new file mode 100644 index 00000000..55d3e412 --- /dev/null +++ b/src/Unstable/Companies/Types/CompanyTags.php @@ -0,0 +1,80 @@ + $tags + */ + #[JsonProperty('tags'), ArrayType(['mixed'])] + private ?array $tags; + + /** + * @param array{ + * type?: ?'tag.list', + * tags?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->tags = $values['tags'] ?? null; + } + + /** + * @return ?'tag.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTags(): ?array + { + return $this->tags; + } + + /** + * @param ?array $value + */ + public function setTags(?array $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/ContactsClient.php b/src/Unstable/Contacts/ContactsClient.php new file mode 100644 index 00000000..afd3f146 --- /dev/null +++ b/src/Unstable/Contacts/ContactsClient.php @@ -0,0 +1,1021 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of companies that are associated to a contact. + * + * @param ListCompaniesForAContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactAttachedCompanies + * @throws IntercomException + * @throws IntercomApiException + */ + public function listCompaniesForAContact(ListCompaniesForAContactRequest $request, ?array $options = null): ContactAttachedCompanies + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/companies", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactAttachedCompanies::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of segments that are associated to a contact. + * + * @param ListSegmentsForAContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactSegments + * @throws IntercomException + * @throws IntercomApiException + */ + public function listSegmentsForAContact(ListSegmentsForAContactRequest $request, ?array $options = null): ContactSegments + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/segments", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactSegments::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of subscription types that are attached to a contact. These can be subscriptions that a user has 'opted-in' to or has 'opted-out' from, depending on the subscription type. + * This will return a list of Subscription Type objects that the contact is associated with. + * + * The data property will show a combined list of: + * + * 1.Opt-out subscription types that the user has opted-out from. + * 2.Opt-in subscription types that the user has opted-in to receiving. + * + * @param ListSubscriptionsForAContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionTypeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listSubscriptionsForAContact(ListSubscriptionsForAContactRequest $request, ?array $options = null): SubscriptionTypeList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/subscriptions", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionTypeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all tags that are attached to a specific contact. + * + * @param ListTagsForAContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TagList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listTagsForAContact(ListTagsForAContactRequest $request, ?array $options = null): TagList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/tags", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TagList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single contact. + * + * @param ShowContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ShowContactResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function showContact(ShowContactRequest $request, ?array $options = null): ShowContactResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ShowContactResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update an existing contact (ie. user or lead). + * + * {% admonition type="info" %} + * This endpoint handles both **contact updates** and **custom object associations**. + * + * See _`update a contact with an association to a custom object instance`_ in the request/response examples to see the custom object association format. + * {% /admonition %} + * + * @param UpdateContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return UpdateContactResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateContact(UpdateContactRequest $request, ?array $options = null): UpdateContactResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return UpdateContactResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single contact. + * + * @param DeleteContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactDeleted + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteContact(DeleteContactRequest $request, ?array $options = null): ContactDeleted + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactDeleted::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can merge a contact with a `role` of `lead` into a contact with a `role` of `user`. + * + * @param MergeContactsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return MergeContactResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function mergeContact(MergeContactsRequest $request = new MergeContactsRequest(), ?array $options = null): MergeContactResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/merge", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return MergeContactResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple contacts by the value of their attributes in order to fetch exactly who you want. + * + * To search for contacts, you need to send a `POST` request to `https://api.intercom.io/contacts/search`. + * + * This will accept a query object in the body which will define your filters in order to search for contacts. + * + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `50` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * ### Contact Creation Delay + * + * If a contact has recently been created, there is a possibility that it will not yet be available when searching. This means that it may not appear in the response. This delay can take a few minutes. If you need to be instantly notified it is recommended to use webhooks and iterate to see if they match your search filters. + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiple's there can be: + * * There's a limit of max 2 nested filters + * * There's a limit of max 15 filters for each AND or OR group + * + * ### Searching for Timestamp Fields + * + * All timestamp fields (created_at, updated_at etc.) are indexed as Dates for Contact Search queries; Datetime queries are not currently supported. This means you can only query for timestamp fields by day - not hour, minute or second. + * For example, if you search for all Contacts with a created_at value greater (>) than 1577869200 (the UNIX timestamp for January 1st, 2020 9:00 AM), that will be interpreted as 1577836800 (January 1st, 2020 12:00 AM). The search results will then include Contacts created from January 2nd, 2020 12:00 AM onwards. + * If you'd like to get contacts created on January 1st, 2020 you should search with a created_at value equal (=) to 1577836800 (January 1st, 2020 12:00 AM). + * This behaviour applies only to timestamps used in search queries. The search results will still contain the full UNIX timestamp and be sorted accordingly. + * + * ### Accepted Fields + * + * Most key listed as part of the Contacts Model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`). + * + * | Field | Type | + * | ---------------------------------- | ------------------------------ | + * | id | String | + * | role | String
Accepts user or lead | + * | name | String | + * | avatar | String | + * | owner_id | Integer | + * | email | String | + * | email_domain | String | + * | phone | String | + * | formatted_phone | String | + * | external_id | String | + * | created_at | Date (UNIX Timestamp) | + * | signed_up_at | Date (UNIX Timestamp) | + * | updated_at | Date (UNIX Timestamp) | + * | last_seen_at | Date (UNIX Timestamp) | + * | last_contacted_at | Date (UNIX Timestamp) | + * | last_replied_at | Date (UNIX Timestamp) | + * | last_email_opened_at | Date (UNIX Timestamp) | + * | last_email_clicked_at | Date (UNIX Timestamp) | + * | language_override | String | + * | browser | String | + * | browser_language | String | + * | os | String | + * | location.country | String | + * | location.region | String | + * | location.city | String | + * | unsubscribed_from_emails | Boolean | + * | marked_email_as_spam | Boolean | + * | has_hard_bounced | Boolean | + * | ios_last_seen_at | Date (UNIX Timestamp) | + * | ios_app_version | String | + * | ios_device | String | + * | ios_app_device | String | + * | ios_os_version | String | + * | ios_app_name | String | + * | ios_sdk_version | String | + * | android_last_seen_at | Date (UNIX Timestamp) | + * | android_app_version | String | + * | android_device | String | + * | android_app_name | String | + * | andoid_sdk_version | String | + * | segment_id | String | + * | tag_id | String | + * | custom_attributes.{attribute_name} | String | + * + * ### Accepted Operators + * + * {% admonition type="warning" name="Searching based on `created_at`" %} + * You cannot use the `<=` or `>=` operators to search by `created_at`. + * {% /admonition %} + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :------------------------------- | :--------------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In
Shortcut for `OR` queries
Values must be in Array | + * | NIN | All | Not In
Shortcut for `OR !` queries
Values must be in Array | + * | > | Integer
Date (UNIX Timestamp) | Greater than | + * | < | Integer
Date (UNIX Timestamp) | Lower than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactList + * @throws IntercomException + * @throws IntercomApiException + */ + public function searchContacts(SearchRequest $request, ?array $options = null): ContactList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/search", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all contacts (ie. users or leads) in your workspace. + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `50` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listContacts(?array $options = null): ContactList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new contact (ie. user or lead). + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CreateContactResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function createContact(mixed $request, ?array $options = null): CreateContactResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CreateContactResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single contact by external ID. Note that this endpoint only supports users and not leads. + * + * @param ShowContactByExternalIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ShowContactByExternalIdResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function showContactByExternalId(ShowContactByExternalIdRequest $request, ?array $options = null): ShowContactByExternalIdResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/find_by_external_id/{$request->getExternalId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ShowContactByExternalIdResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can archive a single contact. + * + * @param ArchiveContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactArchived + * @throws IntercomException + * @throws IntercomApiException + */ + public function archiveContact(ArchiveContactRequest $request, ?array $options = null): ContactArchived + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/archive", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactArchived::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can unarchive a single contact. + * + * @param UnarchiveContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactUnarchived + * @throws IntercomException + * @throws IntercomApiException + */ + public function unarchiveContact(UnarchiveContactRequest $request, ?array $options = null): ContactUnarchived + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/unarchive", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactUnarchived::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Block a single contact.
**Note:** conversations of the contact will also be archived during the process.
More details in [FAQ How do I block Inbox spam?](https://www.intercom.com/help/en/articles/8838656-inbox-faqs) + * + * @param BlockContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ContactBlocked + * @throws IntercomException + * @throws IntercomApiException + */ + public function blockContact(BlockContactRequest $request, ?array $options = null): ContactBlocked + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/block", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ContactBlocked::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Contacts/Requests/ArchiveContactRequest.php b/src/Unstable/Contacts/Requests/ArchiveContactRequest.php new file mode 100644 index 00000000..975b001b --- /dev/null +++ b/src/Unstable/Contacts/Requests/ArchiveContactRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/BlockContactRequest.php b/src/Unstable/Contacts/Requests/BlockContactRequest.php new file mode 100644 index 00000000..f3d2650a --- /dev/null +++ b/src/Unstable/Contacts/Requests/BlockContactRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/DeleteContactRequest.php b/src/Unstable/Contacts/Requests/DeleteContactRequest.php new file mode 100644 index 00000000..a80b76de --- /dev/null +++ b/src/Unstable/Contacts/Requests/DeleteContactRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/ListCompaniesForAContactRequest.php b/src/Unstable/Contacts/Requests/ListCompaniesForAContactRequest.php new file mode 100644 index 00000000..82df18ec --- /dev/null +++ b/src/Unstable/Contacts/Requests/ListCompaniesForAContactRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/ListSegmentsForAContactRequest.php b/src/Unstable/Contacts/Requests/ListSegmentsForAContactRequest.php new file mode 100644 index 00000000..ebb1c25b --- /dev/null +++ b/src/Unstable/Contacts/Requests/ListSegmentsForAContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/ListSubscriptionsForAContactRequest.php b/src/Unstable/Contacts/Requests/ListSubscriptionsForAContactRequest.php new file mode 100644 index 00000000..91c60108 --- /dev/null +++ b/src/Unstable/Contacts/Requests/ListSubscriptionsForAContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/ListTagsForAContactRequest.php b/src/Unstable/Contacts/Requests/ListTagsForAContactRequest.php new file mode 100644 index 00000000..9671e214 --- /dev/null +++ b/src/Unstable/Contacts/Requests/ListTagsForAContactRequest.php @@ -0,0 +1,41 @@ +contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/MergeContactsRequest.php b/src/Unstable/Contacts/Requests/MergeContactsRequest.php new file mode 100644 index 00000000..1bd6d73a --- /dev/null +++ b/src/Unstable/Contacts/Requests/MergeContactsRequest.php @@ -0,0 +1,68 @@ +from = $values['from'] ?? null; + $this->into = $values['into'] ?? null; + } + + /** + * @return ?string + */ + public function getFrom(): ?string + { + return $this->from; + } + + /** + * @param ?string $value + */ + public function setFrom(?string $value = null): self + { + $this->from = $value; + return $this; + } + + /** + * @return ?string + */ + public function getInto(): ?string + { + return $this->into; + } + + /** + * @param ?string $value + */ + public function setInto(?string $value = null): self + { + $this->into = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/ShowContactByExternalIdRequest.php b/src/Unstable/Contacts/Requests/ShowContactByExternalIdRequest.php new file mode 100644 index 00000000..f731110e --- /dev/null +++ b/src/Unstable/Contacts/Requests/ShowContactByExternalIdRequest.php @@ -0,0 +1,41 @@ +externalId = $values['externalId']; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/ShowContactRequest.php b/src/Unstable/Contacts/Requests/ShowContactRequest.php new file mode 100644 index 00000000..72acfa2d --- /dev/null +++ b/src/Unstable/Contacts/Requests/ShowContactRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/UnarchiveContactRequest.php b/src/Unstable/Contacts/Requests/UnarchiveContactRequest.php new file mode 100644 index 00000000..d6234223 --- /dev/null +++ b/src/Unstable/Contacts/Requests/UnarchiveContactRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Requests/UpdateContactRequest.php b/src/Unstable/Contacts/Requests/UpdateContactRequest.php new file mode 100644 index 00000000..f3b1e69e --- /dev/null +++ b/src/Unstable/Contacts/Requests/UpdateContactRequest.php @@ -0,0 +1,318 @@ + $customAttributes The custom attributes which are set for the contact + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @param array{ + * id: string, + * role?: ?string, + * externalId?: ?string, + * email?: ?string, + * phone?: ?string, + * name?: ?string, + * avatar?: ?string, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * ownerId?: ?int, + * unsubscribedFromEmails?: ?bool, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->role = $values['role'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->email = $values['email'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRole(): ?string + { + return $this->role; + } + + /** + * @param ?string $value + */ + public function setRole(?string $value = null): self + { + $this->role = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAvatar(): ?string + { + return $this->avatar; + } + + /** + * @param ?string $value + */ + public function setAvatar(?string $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Traits/Contact.php b/src/Unstable/Contacts/Traits/Contact.php new file mode 100644 index 00000000..f1d043ac --- /dev/null +++ b/src/Unstable/Contacts/Traits/Contact.php @@ -0,0 +1,1123 @@ + $customAttributes + * @property ?ContactAvatar $avatar + * @property ?ContactTags $tags + * @property ?ContactNotes $notes + * @property ?ContactCompanies $companies + * @property ?ContactLocation $location + * @property ?ContactSocialProfiles $socialProfiles + */ +trait Contact +{ + /** + * @var ?string $type The type of object. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $id The unique identifier for the contact which is given by Intercom. + */ + #[JsonProperty('id')] + private ?string $id; + + /** + * @var ?string $externalId The unique identifier for the contact which is provided by the Client. + */ + #[JsonProperty('external_id')] + private ?string $externalId; + + /** + * @var ?string $workspaceId The id of the workspace which the contact belongs to. + */ + #[JsonProperty('workspace_id')] + private ?string $workspaceId; + + /** + * @var ?string $role The role of the contact. + */ + #[JsonProperty('role')] + private ?string $role; + + /** + * @var ?string $email The contact's email. + */ + #[JsonProperty('email')] + private ?string $email; + + /** + * @var ?string $emailDomain The contact's email domain. + */ + #[JsonProperty('email_domain')] + private ?string $emailDomain; + + /** + * @var ?string $phone The contacts phone. + */ + #[JsonProperty('phone')] + private ?string $phone; + + /** + * @var ?string $formattedPhone The contacts phone number normalized to the E164 format + */ + #[JsonProperty('formatted_phone')] + private ?string $formattedPhone; + + /** + * @var ?string $name The contacts name. + */ + #[JsonProperty('name')] + private ?string $name; + + /** + * @var ?int $ownerId The id of an admin that has been assigned account ownership of the contact. + */ + #[JsonProperty('owner_id')] + private ?int $ownerId; + + /** + * @var ?bool $hasHardBounced Whether the contact has had an email sent to them hard bounce. + */ + #[JsonProperty('has_hard_bounced')] + private ?bool $hasHardBounced; + + /** + * @var ?bool $markedEmailAsSpam Whether the contact has marked an email sent to them as spam. + */ + #[JsonProperty('marked_email_as_spam')] + private ?bool $markedEmailAsSpam; + + /** + * @var ?bool $unsubscribedFromEmails Whether the contact is unsubscribed from emails. + */ + #[JsonProperty('unsubscribed_from_emails')] + private ?bool $unsubscribedFromEmails; + + /** + * @var ?int $createdAt (UNIX timestamp) The time when the contact was created. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt (UNIX timestamp) The time when the contact was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?int $signedUpAt (UNIX timestamp) The time specified for when a contact signed up. + */ + #[JsonProperty('signed_up_at')] + private ?int $signedUpAt; + + /** + * @var ?int $lastSeenAt (UNIX timestamp) The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually). + */ + #[JsonProperty('last_seen_at')] + private ?int $lastSeenAt; + + /** + * @var ?int $lastRepliedAt (UNIX timestamp) The time when the contact last messaged in. + */ + #[JsonProperty('last_replied_at')] + private ?int $lastRepliedAt; + + /** + * @var ?int $lastContactedAt (UNIX timestamp) The time when the contact was last messaged. + */ + #[JsonProperty('last_contacted_at')] + private ?int $lastContactedAt; + + /** + * @var ?int $lastEmailOpenedAt (UNIX timestamp) The time when the contact last opened an email. + */ + #[JsonProperty('last_email_opened_at')] + private ?int $lastEmailOpenedAt; + + /** + * @var ?int $lastEmailClickedAt (UNIX timestamp) The time when the contact last clicked a link in an email. + */ + #[JsonProperty('last_email_clicked_at')] + private ?int $lastEmailClickedAt; + + /** + * @var ?string $languageOverride A preferred language setting for the contact, used by the Intercom Messenger even if their browser settings change. + */ + #[JsonProperty('language_override')] + private ?string $languageOverride; + + /** + * @var ?string $browser The name of the browser which the contact is using. + */ + #[JsonProperty('browser')] + private ?string $browser; + + /** + * @var ?string $browserVersion The version of the browser which the contact is using. + */ + #[JsonProperty('browser_version')] + private ?string $browserVersion; + + /** + * @var ?string $browserLanguage The language set by the browser which the contact is using. + */ + #[JsonProperty('browser_language')] + private ?string $browserLanguage; + + /** + * @var ?string $os The operating system which the contact is using. + */ + #[JsonProperty('os')] + private ?string $os; + + /** + * @var ?string $androidAppName The name of the Android app which the contact is using. + */ + #[JsonProperty('android_app_name')] + private ?string $androidAppName; + + /** + * @var ?string $androidAppVersion The version of the Android app which the contact is using. + */ + #[JsonProperty('android_app_version')] + private ?string $androidAppVersion; + + /** + * @var ?string $androidDevice The Android device which the contact is using. + */ + #[JsonProperty('android_device')] + private ?string $androidDevice; + + /** + * @var ?string $androidOsVersion The version of the Android OS which the contact is using. + */ + #[JsonProperty('android_os_version')] + private ?string $androidOsVersion; + + /** + * @var ?string $androidSdkVersion The version of the Android SDK which the contact is using. + */ + #[JsonProperty('android_sdk_version')] + private ?string $androidSdkVersion; + + /** + * @var ?int $androidLastSeenAt (UNIX timestamp) The time when the contact was last seen on an Android device. + */ + #[JsonProperty('android_last_seen_at')] + private ?int $androidLastSeenAt; + + /** + * @var ?string $iosAppName The name of the iOS app which the contact is using. + */ + #[JsonProperty('ios_app_name')] + private ?string $iosAppName; + + /** + * @var ?string $iosAppVersion The version of the iOS app which the contact is using. + */ + #[JsonProperty('ios_app_version')] + private ?string $iosAppVersion; + + /** + * @var ?string $iosDevice The iOS device which the contact is using. + */ + #[JsonProperty('ios_device')] + private ?string $iosDevice; + + /** + * @var ?string $iosOsVersion The version of iOS which the contact is using. + */ + #[JsonProperty('ios_os_version')] + private ?string $iosOsVersion; + + /** + * @var ?string $iosSdkVersion The version of the iOS SDK which the contact is using. + */ + #[JsonProperty('ios_sdk_version')] + private ?string $iosSdkVersion; + + /** + * @var ?int $iosLastSeenAt (UNIX timestamp) The last time the contact used the iOS app. + */ + #[JsonProperty('ios_last_seen_at')] + private ?int $iosLastSeenAt; + + /** + * @var ?array $customAttributes The custom attributes which are set for the contact. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @var ?ContactAvatar $avatar + */ + #[JsonProperty('avatar')] + private ?ContactAvatar $avatar; + + /** + * @var ?ContactTags $tags + */ + #[JsonProperty('tags')] + private ?ContactTags $tags; + + /** + * @var ?ContactNotes $notes + */ + #[JsonProperty('notes')] + private ?ContactNotes $notes; + + /** + * @var ?ContactCompanies $companies + */ + #[JsonProperty('companies')] + private ?ContactCompanies $companies; + + /** + * @var ?ContactLocation $location + */ + #[JsonProperty('location')] + private ?ContactLocation $location; + + /** + * @var ?ContactSocialProfiles $socialProfiles + */ + #[JsonProperty('social_profiles')] + private ?ContactSocialProfiles $socialProfiles; + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRole(): ?string + { + return $this->role; + } + + /** + * @param ?string $value + */ + public function setRole(?string $value = null): self + { + $this->role = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmailDomain(): ?string + { + return $this->emailDomain; + } + + /** + * @param ?string $value + */ + public function setEmailDomain(?string $value = null): self + { + $this->emailDomain = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getFormattedPhone(): ?string + { + return $this->formattedPhone; + } + + /** + * @param ?string $value + */ + public function setFormattedPhone(?string $value = null): self + { + $this->formattedPhone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasHardBounced(): ?bool + { + return $this->hasHardBounced; + } + + /** + * @param ?bool $value + */ + public function setHasHardBounced(?bool $value = null): self + { + $this->hasHardBounced = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMarkedEmailAsSpam(): ?bool + { + return $this->markedEmailAsSpam; + } + + /** + * @param ?bool $value + */ + public function setMarkedEmailAsSpam(?bool $value = null): self + { + $this->markedEmailAsSpam = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastRepliedAt(): ?int + { + return $this->lastRepliedAt; + } + + /** + * @param ?int $value + */ + public function setLastRepliedAt(?int $value = null): self + { + $this->lastRepliedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastContactedAt(): ?int + { + return $this->lastContactedAt; + } + + /** + * @param ?int $value + */ + public function setLastContactedAt(?int $value = null): self + { + $this->lastContactedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastEmailOpenedAt(): ?int + { + return $this->lastEmailOpenedAt; + } + + /** + * @param ?int $value + */ + public function setLastEmailOpenedAt(?int $value = null): self + { + $this->lastEmailOpenedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastEmailClickedAt(): ?int + { + return $this->lastEmailClickedAt; + } + + /** + * @param ?int $value + */ + public function setLastEmailClickedAt(?int $value = null): self + { + $this->lastEmailClickedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLanguageOverride(): ?string + { + return $this->languageOverride; + } + + /** + * @param ?string $value + */ + public function setLanguageOverride(?string $value = null): self + { + $this->languageOverride = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowser(): ?string + { + return $this->browser; + } + + /** + * @param ?string $value + */ + public function setBrowser(?string $value = null): self + { + $this->browser = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowserVersion(): ?string + { + return $this->browserVersion; + } + + /** + * @param ?string $value + */ + public function setBrowserVersion(?string $value = null): self + { + $this->browserVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowserLanguage(): ?string + { + return $this->browserLanguage; + } + + /** + * @param ?string $value + */ + public function setBrowserLanguage(?string $value = null): self + { + $this->browserLanguage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOs(): ?string + { + return $this->os; + } + + /** + * @param ?string $value + */ + public function setOs(?string $value = null): self + { + $this->os = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidAppName(): ?string + { + return $this->androidAppName; + } + + /** + * @param ?string $value + */ + public function setAndroidAppName(?string $value = null): self + { + $this->androidAppName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidAppVersion(): ?string + { + return $this->androidAppVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidAppVersion(?string $value = null): self + { + $this->androidAppVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidDevice(): ?string + { + return $this->androidDevice; + } + + /** + * @param ?string $value + */ + public function setAndroidDevice(?string $value = null): self + { + $this->androidDevice = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidOsVersion(): ?string + { + return $this->androidOsVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidOsVersion(?string $value = null): self + { + $this->androidOsVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidSdkVersion(): ?string + { + return $this->androidSdkVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidSdkVersion(?string $value = null): self + { + $this->androidSdkVersion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAndroidLastSeenAt(): ?int + { + return $this->androidLastSeenAt; + } + + /** + * @param ?int $value + */ + public function setAndroidLastSeenAt(?int $value = null): self + { + $this->androidLastSeenAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosAppName(): ?string + { + return $this->iosAppName; + } + + /** + * @param ?string $value + */ + public function setIosAppName(?string $value = null): self + { + $this->iosAppName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosAppVersion(): ?string + { + return $this->iosAppVersion; + } + + /** + * @param ?string $value + */ + public function setIosAppVersion(?string $value = null): self + { + $this->iosAppVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosDevice(): ?string + { + return $this->iosDevice; + } + + /** + * @param ?string $value + */ + public function setIosDevice(?string $value = null): self + { + $this->iosDevice = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosOsVersion(): ?string + { + return $this->iosOsVersion; + } + + /** + * @param ?string $value + */ + public function setIosOsVersion(?string $value = null): self + { + $this->iosOsVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosSdkVersion(): ?string + { + return $this->iosSdkVersion; + } + + /** + * @param ?string $value + */ + public function setIosSdkVersion(?string $value = null): self + { + $this->iosSdkVersion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getIosLastSeenAt(): ?int + { + return $this->iosLastSeenAt; + } + + /** + * @param ?int $value + */ + public function setIosLastSeenAt(?int $value = null): self + { + $this->iosLastSeenAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?ContactAvatar + */ + public function getAvatar(): ?ContactAvatar + { + return $this->avatar; + } + + /** + * @param ?ContactAvatar $value + */ + public function setAvatar(?ContactAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?ContactTags + */ + public function getTags(): ?ContactTags + { + return $this->tags; + } + + /** + * @param ?ContactTags $value + */ + public function setTags(?ContactTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?ContactNotes + */ + public function getNotes(): ?ContactNotes + { + return $this->notes; + } + + /** + * @param ?ContactNotes $value + */ + public function setNotes(?ContactNotes $value = null): self + { + $this->notes = $value; + return $this; + } + + /** + * @return ?ContactCompanies + */ + public function getCompanies(): ?ContactCompanies + { + return $this->companies; + } + + /** + * @param ?ContactCompanies $value + */ + public function setCompanies(?ContactCompanies $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return ?ContactLocation + */ + public function getLocation(): ?ContactLocation + { + return $this->location; + } + + /** + * @param ?ContactLocation $value + */ + public function setLocation(?ContactLocation $value = null): self + { + $this->location = $value; + return $this; + } + + /** + * @return ?ContactSocialProfiles + */ + public function getSocialProfiles(): ?ContactSocialProfiles + { + return $this->socialProfiles; + } + + /** + * @param ?ContactSocialProfiles $value + */ + public function setSocialProfiles(?ContactSocialProfiles $value = null): self + { + $this->socialProfiles = $value; + return $this; + } +} diff --git a/src/Unstable/Contacts/Types/Contact.php b/src/Unstable/Contacts/Types/Contact.php new file mode 100644 index 00000000..198b7757 --- /dev/null +++ b/src/Unstable/Contacts/Types/Contact.php @@ -0,0 +1,1185 @@ + $customAttributes The custom attributes which are set for the contact. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $customAttributes; + + /** + * @var ?ContactAvatar $avatar + */ + #[JsonProperty('avatar')] + private ?ContactAvatar $avatar; + + /** + * @var ?ContactTags $tags + */ + #[JsonProperty('tags')] + private ?ContactTags $tags; + + /** + * @var ?ContactNotes $notes + */ + #[JsonProperty('notes')] + private ?ContactNotes $notes; + + /** + * @var ?ContactCompanies $companies + */ + #[JsonProperty('companies')] + private ?ContactCompanies $companies; + + /** + * @var ?ContactLocation $location + */ + #[JsonProperty('location')] + private ?ContactLocation $location; + + /** + * @var ?ContactSocialProfiles $socialProfiles + */ + #[JsonProperty('social_profiles')] + private ?ContactSocialProfiles $socialProfiles; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * externalId?: ?string, + * workspaceId?: ?string, + * role?: ?string, + * email?: ?string, + * emailDomain?: ?string, + * phone?: ?string, + * formattedPhone?: ?string, + * name?: ?string, + * ownerId?: ?int, + * hasHardBounced?: ?bool, + * markedEmailAsSpam?: ?bool, + * unsubscribedFromEmails?: ?bool, + * createdAt?: ?int, + * updatedAt?: ?int, + * signedUpAt?: ?int, + * lastSeenAt?: ?int, + * lastRepliedAt?: ?int, + * lastContactedAt?: ?int, + * lastEmailOpenedAt?: ?int, + * lastEmailClickedAt?: ?int, + * languageOverride?: ?string, + * browser?: ?string, + * browserVersion?: ?string, + * browserLanguage?: ?string, + * os?: ?string, + * androidAppName?: ?string, + * androidAppVersion?: ?string, + * androidDevice?: ?string, + * androidOsVersion?: ?string, + * androidSdkVersion?: ?string, + * androidLastSeenAt?: ?int, + * iosAppName?: ?string, + * iosAppVersion?: ?string, + * iosDevice?: ?string, + * iosOsVersion?: ?string, + * iosSdkVersion?: ?string, + * iosLastSeenAt?: ?int, + * customAttributes?: ?array, + * avatar?: ?ContactAvatar, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * location?: ?ContactLocation, + * socialProfiles?: ?ContactSocialProfiles, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->role = $values['role'] ?? null; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRole(): ?string + { + return $this->role; + } + + /** + * @param ?string $value + */ + public function setRole(?string $value = null): self + { + $this->role = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmailDomain(): ?string + { + return $this->emailDomain; + } + + /** + * @param ?string $value + */ + public function setEmailDomain(?string $value = null): self + { + $this->emailDomain = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getFormattedPhone(): ?string + { + return $this->formattedPhone; + } + + /** + * @param ?string $value + */ + public function setFormattedPhone(?string $value = null): self + { + $this->formattedPhone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOwnerId(): ?int + { + return $this->ownerId; + } + + /** + * @param ?int $value + */ + public function setOwnerId(?int $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasHardBounced(): ?bool + { + return $this->hasHardBounced; + } + + /** + * @param ?bool $value + */ + public function setHasHardBounced(?bool $value = null): self + { + $this->hasHardBounced = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMarkedEmailAsSpam(): ?bool + { + return $this->markedEmailAsSpam; + } + + /** + * @param ?bool $value + */ + public function setMarkedEmailAsSpam(?bool $value = null): self + { + $this->markedEmailAsSpam = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastSeenAt(): ?int + { + return $this->lastSeenAt; + } + + /** + * @param ?int $value + */ + public function setLastSeenAt(?int $value = null): self + { + $this->lastSeenAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastRepliedAt(): ?int + { + return $this->lastRepliedAt; + } + + /** + * @param ?int $value + */ + public function setLastRepliedAt(?int $value = null): self + { + $this->lastRepliedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastContactedAt(): ?int + { + return $this->lastContactedAt; + } + + /** + * @param ?int $value + */ + public function setLastContactedAt(?int $value = null): self + { + $this->lastContactedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastEmailOpenedAt(): ?int + { + return $this->lastEmailOpenedAt; + } + + /** + * @param ?int $value + */ + public function setLastEmailOpenedAt(?int $value = null): self + { + $this->lastEmailOpenedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastEmailClickedAt(): ?int + { + return $this->lastEmailClickedAt; + } + + /** + * @param ?int $value + */ + public function setLastEmailClickedAt(?int $value = null): self + { + $this->lastEmailClickedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLanguageOverride(): ?string + { + return $this->languageOverride; + } + + /** + * @param ?string $value + */ + public function setLanguageOverride(?string $value = null): self + { + $this->languageOverride = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowser(): ?string + { + return $this->browser; + } + + /** + * @param ?string $value + */ + public function setBrowser(?string $value = null): self + { + $this->browser = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowserVersion(): ?string + { + return $this->browserVersion; + } + + /** + * @param ?string $value + */ + public function setBrowserVersion(?string $value = null): self + { + $this->browserVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBrowserLanguage(): ?string + { + return $this->browserLanguage; + } + + /** + * @param ?string $value + */ + public function setBrowserLanguage(?string $value = null): self + { + $this->browserLanguage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOs(): ?string + { + return $this->os; + } + + /** + * @param ?string $value + */ + public function setOs(?string $value = null): self + { + $this->os = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidAppName(): ?string + { + return $this->androidAppName; + } + + /** + * @param ?string $value + */ + public function setAndroidAppName(?string $value = null): self + { + $this->androidAppName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidAppVersion(): ?string + { + return $this->androidAppVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidAppVersion(?string $value = null): self + { + $this->androidAppVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidDevice(): ?string + { + return $this->androidDevice; + } + + /** + * @param ?string $value + */ + public function setAndroidDevice(?string $value = null): self + { + $this->androidDevice = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidOsVersion(): ?string + { + return $this->androidOsVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidOsVersion(?string $value = null): self + { + $this->androidOsVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAndroidSdkVersion(): ?string + { + return $this->androidSdkVersion; + } + + /** + * @param ?string $value + */ + public function setAndroidSdkVersion(?string $value = null): self + { + $this->androidSdkVersion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAndroidLastSeenAt(): ?int + { + return $this->androidLastSeenAt; + } + + /** + * @param ?int $value + */ + public function setAndroidLastSeenAt(?int $value = null): self + { + $this->androidLastSeenAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosAppName(): ?string + { + return $this->iosAppName; + } + + /** + * @param ?string $value + */ + public function setIosAppName(?string $value = null): self + { + $this->iosAppName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosAppVersion(): ?string + { + return $this->iosAppVersion; + } + + /** + * @param ?string $value + */ + public function setIosAppVersion(?string $value = null): self + { + $this->iosAppVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosDevice(): ?string + { + return $this->iosDevice; + } + + /** + * @param ?string $value + */ + public function setIosDevice(?string $value = null): self + { + $this->iosDevice = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosOsVersion(): ?string + { + return $this->iosOsVersion; + } + + /** + * @param ?string $value + */ + public function setIosOsVersion(?string $value = null): self + { + $this->iosOsVersion = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIosSdkVersion(): ?string + { + return $this->iosSdkVersion; + } + + /** + * @param ?string $value + */ + public function setIosSdkVersion(?string $value = null): self + { + $this->iosSdkVersion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getIosLastSeenAt(): ?int + { + return $this->iosLastSeenAt; + } + + /** + * @param ?int $value + */ + public function setIosLastSeenAt(?int $value = null): self + { + $this->iosLastSeenAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?ContactAvatar + */ + public function getAvatar(): ?ContactAvatar + { + return $this->avatar; + } + + /** + * @param ?ContactAvatar $value + */ + public function setAvatar(?ContactAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?ContactTags + */ + public function getTags(): ?ContactTags + { + return $this->tags; + } + + /** + * @param ?ContactTags $value + */ + public function setTags(?ContactTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?ContactNotes + */ + public function getNotes(): ?ContactNotes + { + return $this->notes; + } + + /** + * @param ?ContactNotes $value + */ + public function setNotes(?ContactNotes $value = null): self + { + $this->notes = $value; + return $this; + } + + /** + * @return ?ContactCompanies + */ + public function getCompanies(): ?ContactCompanies + { + return $this->companies; + } + + /** + * @param ?ContactCompanies $value + */ + public function setCompanies(?ContactCompanies $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return ?ContactLocation + */ + public function getLocation(): ?ContactLocation + { + return $this->location; + } + + /** + * @param ?ContactLocation $value + */ + public function setLocation(?ContactLocation $value = null): self + { + $this->location = $value; + return $this; + } + + /** + * @return ?ContactSocialProfiles + */ + public function getSocialProfiles(): ?ContactSocialProfiles + { + return $this->socialProfiles; + } + + /** + * @param ?ContactSocialProfiles $value + */ + public function setSocialProfiles(?ContactSocialProfiles $value = null): self + { + $this->socialProfiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/Types/ContactAvatar.php b/src/Unstable/Contacts/Types/ContactAvatar.php new file mode 100644 index 00000000..beb3390e --- /dev/null +++ b/src/Unstable/Contacts/Types/ContactAvatar.php @@ -0,0 +1,76 @@ +type = $values['type'] ?? null; + $this->imageUrl = $values['imageUrl'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * @param ?string $value + */ + public function setImageUrl(?string $value = null): self + { + $this->imageUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/Types/CreateContactResponse.php b/src/Unstable/Contacts/Types/CreateContactResponse.php new file mode 100644 index 00000000..cb278878 --- /dev/null +++ b/src/Unstable/Contacts/Types/CreateContactResponse.php @@ -0,0 +1,151 @@ +, + * avatar?: ?ContactAvatar, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * location?: ?ContactLocation, + * socialProfiles?: ?ContactSocialProfiles, + * enabledPushMessaging?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->role = $values['role'] ?? null; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->enabledPushMessaging = $values['enabledPushMessaging'] ?? null; + } + + /** + * @return ?bool + */ + public function getEnabledPushMessaging(): ?bool + { + return $this->enabledPushMessaging; + } + + /** + * @param ?bool $value + */ + public function setEnabledPushMessaging(?bool $value = null): self + { + $this->enabledPushMessaging = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/Types/MergeContactResponse.php b/src/Unstable/Contacts/Types/MergeContactResponse.php new file mode 100644 index 00000000..2ae3b477 --- /dev/null +++ b/src/Unstable/Contacts/Types/MergeContactResponse.php @@ -0,0 +1,151 @@ +, + * avatar?: ?ContactAvatar, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * location?: ?ContactLocation, + * socialProfiles?: ?ContactSocialProfiles, + * enabledPushMessaging?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->role = $values['role'] ?? null; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->enabledPushMessaging = $values['enabledPushMessaging'] ?? null; + } + + /** + * @return ?bool + */ + public function getEnabledPushMessaging(): ?bool + { + return $this->enabledPushMessaging; + } + + /** + * @param ?bool $value + */ + public function setEnabledPushMessaging(?bool $value = null): self + { + $this->enabledPushMessaging = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/Types/ShowContactByExternalIdResponse.php b/src/Unstable/Contacts/Types/ShowContactByExternalIdResponse.php new file mode 100644 index 00000000..ff000453 --- /dev/null +++ b/src/Unstable/Contacts/Types/ShowContactByExternalIdResponse.php @@ -0,0 +1,151 @@ +, + * avatar?: ?ContactAvatar, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * location?: ?ContactLocation, + * socialProfiles?: ?ContactSocialProfiles, + * enabledPushMessaging?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->role = $values['role'] ?? null; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->enabledPushMessaging = $values['enabledPushMessaging'] ?? null; + } + + /** + * @return ?bool + */ + public function getEnabledPushMessaging(): ?bool + { + return $this->enabledPushMessaging; + } + + /** + * @param ?bool $value + */ + public function setEnabledPushMessaging(?bool $value = null): self + { + $this->enabledPushMessaging = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/Types/ShowContactResponse.php b/src/Unstable/Contacts/Types/ShowContactResponse.php new file mode 100644 index 00000000..043dab89 --- /dev/null +++ b/src/Unstable/Contacts/Types/ShowContactResponse.php @@ -0,0 +1,151 @@ +, + * avatar?: ?ContactAvatar, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * location?: ?ContactLocation, + * socialProfiles?: ?ContactSocialProfiles, + * enabledPushMessaging?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->role = $values['role'] ?? null; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->enabledPushMessaging = $values['enabledPushMessaging'] ?? null; + } + + /** + * @return ?bool + */ + public function getEnabledPushMessaging(): ?bool + { + return $this->enabledPushMessaging; + } + + /** + * @param ?bool $value + */ + public function setEnabledPushMessaging(?bool $value = null): self + { + $this->enabledPushMessaging = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Contacts/Types/UpdateContactResponse.php b/src/Unstable/Contacts/Types/UpdateContactResponse.php new file mode 100644 index 00000000..7ed2fe2c --- /dev/null +++ b/src/Unstable/Contacts/Types/UpdateContactResponse.php @@ -0,0 +1,151 @@ +, + * avatar?: ?ContactAvatar, + * tags?: ?ContactTags, + * notes?: ?ContactNotes, + * companies?: ?ContactCompanies, + * location?: ?ContactLocation, + * socialProfiles?: ?ContactSocialProfiles, + * enabledPushMessaging?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->role = $values['role'] ?? null; + $this->email = $values['email'] ?? null; + $this->emailDomain = $values['emailDomain'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->formattedPhone = $values['formattedPhone'] ?? null; + $this->name = $values['name'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->lastSeenAt = $values['lastSeenAt'] ?? null; + $this->lastRepliedAt = $values['lastRepliedAt'] ?? null; + $this->lastContactedAt = $values['lastContactedAt'] ?? null; + $this->lastEmailOpenedAt = $values['lastEmailOpenedAt'] ?? null; + $this->lastEmailClickedAt = $values['lastEmailClickedAt'] ?? null; + $this->languageOverride = $values['languageOverride'] ?? null; + $this->browser = $values['browser'] ?? null; + $this->browserVersion = $values['browserVersion'] ?? null; + $this->browserLanguage = $values['browserLanguage'] ?? null; + $this->os = $values['os'] ?? null; + $this->androidAppName = $values['androidAppName'] ?? null; + $this->androidAppVersion = $values['androidAppVersion'] ?? null; + $this->androidDevice = $values['androidDevice'] ?? null; + $this->androidOsVersion = $values['androidOsVersion'] ?? null; + $this->androidSdkVersion = $values['androidSdkVersion'] ?? null; + $this->androidLastSeenAt = $values['androidLastSeenAt'] ?? null; + $this->iosAppName = $values['iosAppName'] ?? null; + $this->iosAppVersion = $values['iosAppVersion'] ?? null; + $this->iosDevice = $values['iosDevice'] ?? null; + $this->iosOsVersion = $values['iosOsVersion'] ?? null; + $this->iosSdkVersion = $values['iosSdkVersion'] ?? null; + $this->iosLastSeenAt = $values['iosLastSeenAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->notes = $values['notes'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->location = $values['location'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->enabledPushMessaging = $values['enabledPushMessaging'] ?? null; + } + + /** + * @return ?bool + */ + public function getEnabledPushMessaging(): ?bool + { + return $this->enabledPushMessaging; + } + + /** + * @param ?bool $value + */ + public function setEnabledPushMessaging(?bool $value = null): self + { + $this->enabledPushMessaging = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Conversations/ConversationsClient.php b/src/Unstable/Conversations/ConversationsClient.php new file mode 100644 index 00000000..473ac828 --- /dev/null +++ b/src/Unstable/Conversations/ConversationsClient.php @@ -0,0 +1,906 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all conversations. + * + * You can optionally request the result page size and the cursor to start after to fetch the result. + * {% admonition type="warning" name="Pagination" %} + * You can use pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#pagination-for-list-apis) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * @param ListConversationsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ConversationList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listConversations(ListConversationsRequest $request = new ListConversationsRequest(), ?array $options = null): ConversationList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getStartingAfter() != null) { + $query['starting_after'] = $request->getStartingAfter(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ConversationList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a conversation that has been initiated by a contact (ie. user or lead). + * The conversation can be an in-app message only. + * + * {% admonition type="info" name="Sending for visitors" %} + * You can also send a message from a visitor by specifying their `user_id` or `id` value in the `from` field, along with a `type` field value of `contact`. + * This visitor will be automatically converted to a contact with a lead role once the conversation is created. + * {% /admonition %} + * + * This will return the Message model that has been created. + * + * @param CreateConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Message + * @throws IntercomException + * @throws IntercomApiException + */ + public function createConversation(CreateConversationRequest $request, ?array $options = null): Message + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Message::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can fetch the details of a single conversation. + * + * This will return a single Conversation model with all its conversation parts. + * + * {% admonition type="warning" name="Hard limit of 500 parts" %} + * The maximum number of conversation parts that can be returned via the API is 500. If you have more than that we will return the 500 most recent conversation parts. + * {% /admonition %} + * + * For AI agent conversation metadata, please note that you need to have the agent enabled in your workspace, which is a [paid feature](https://www.intercom.com/help/en/articles/8205718-fin-resolutions#h_97f8c2e671). + * + * @param RetrieveConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveConversation(RetrieveConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getDisplayAs() != null) { + $query['display_as'] = $request->getDisplayAs(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can update an existing conversation. + * + * {% admonition type="info" name="Replying and other actions" %} + * If you want to reply to a coveration or take an action such as assign, unassign, open, close or snooze, take a look at the reply and manage endpoints. + * {% /admonition %} + * + * {% admonition type="info" %} + * This endpoint handles both **conversation updates** and **custom object associations**. + * + * See _`update a conversation with an association to a custom object instance`_ in the request/response examples to see the custom object association format. + * {% /admonition %} + * + * @param UpdateConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateConversation(UpdateConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getDisplayAs() != null) { + $query['display_as'] = $request->getDisplayAs(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}", + method: HttpMethod::PUT, + query: $query, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single conversation. + * + * @param DeleteConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ConversationDeleted + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteConversation(DeleteConversationRequest $request, ?array $options = null): ConversationDeleted + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ConversationDeleted::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple conversations by the value of their attributes in order to fetch exactly which ones you want. + * + * To search for conversations, you need to send a `POST` request to `https://api.intercom.io/conversations/search`. + * + * This will accept a query object in the body which will define your filters in order to search for conversations. + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `20` results per page and maximum is `150`. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiple's there can be: + * - There's a limit of max 2 nested filters + * - There's a limit of max 15 filters for each AND or OR group + * + * ### Accepted Fields + * + * Most keys listed in the conversation model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foorbar"`). + * The `source.body` field is unique as the search will not be performed against the entire value, but instead against every element of the value separately. For example, when searching for a conversation with a `"I need support"` body - the query should contain a `=` operator with the value `"support"` for such conversation to be returned. A query with a `=` operator and a `"need support"` value will not yield a result. + * + * | Field | Type | + * | :---------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | + * | id | String | + * | created_at | Date (UNIX timestamp) | + * | updated_at | Date (UNIX timestamp) | + * | source.type | String
Accepted fields are `conversation`, `email`, `facebook`, `instagram`, `phone_call`, `phone_switch`, `push`, `sms`, `twitter` and `whatsapp`. | + * | source.id | String | + * | source.delivered_as | String | + * | source.subject | String | + * | source.body | String | + * | source.author.id | String | + * | source.author.type | String | + * | source.author.name | String | + * | source.author.email | String | + * | source.url | String | + * | contact_ids | String | + * | teammate_ids | String | + * | admin_assignee_id | String | + * | team_assignee_id | String | + * | channel_initiated | String | + * | open | Boolean | + * | read | Boolean | + * | state | String | + * | waiting_since | Date (UNIX timestamp) | + * | snoozed_until | Date (UNIX timestamp) | + * | tag_ids | String | + * | priority | String | + * | statistics.time_to_assignment | Integer | + * | statistics.time_to_admin_reply | Integer | + * | statistics.time_to_first_close | Integer | + * | statistics.time_to_last_close | Integer | + * | statistics.median_time_to_reply | Integer | + * | statistics.first_contact_reply_at | Date (UNIX timestamp) | + * | statistics.first_assignment_at | Date (UNIX timestamp) | + * | statistics.first_admin_reply_at | Date (UNIX timestamp) | + * | statistics.first_close_at | Date (UNIX timestamp) | + * | statistics.last_assignment_at | Date (UNIX timestamp) | + * | statistics.last_assignment_admin_reply_at | Date (UNIX timestamp) | + * | statistics.last_contact_reply_at | Date (UNIX timestamp) | + * | statistics.last_admin_reply_at | Date (UNIX timestamp) | + * | statistics.last_close_at | Date (UNIX timestamp) | + * | statistics.last_closed_by_id | String | + * | statistics.count_reopens | Integer | + * | statistics.count_assignments | Integer | + * | statistics.count_conversation_parts | Integer | + * | conversation_rating.requested_at | Date (UNIX timestamp) | + * | conversation_rating.replied_at | Date (UNIX timestamp) | + * | conversation_rating.score | Integer | + * | conversation_rating.remark | String | + * | conversation_rating.contact_id | String | + * | conversation_rating.admin_d | String | + * | ai_agent_participated | Boolean | + * | ai_agent.resolution_state | String | + * | ai_agent.last_answer_type | String | + * | ai_agent.rating | Integer | + * | ai_agent.rating_remark | String | + * | ai_agent.source_type | String | + * | ai_agent.source_title | String | + * + * ### Accepted Operators + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :----------------------------- | :----------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In Shortcut for `OR` queries Values most be in Array | + * | NIN | All | Not In Shortcut for `OR !` queries Values must be in Array | + * | > | Integer Date (UNIX Timestamp) | Greater (or equal) than | + * | < | Integer Date (UNIX Timestamp) | Lower (or equal) than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ConversationList + * @throws IntercomException + * @throws IntercomApiException + */ + public function searchConversations(SearchRequest $request, ?array $options = null): ConversationList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/search", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return ConversationList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can reply to a conversation with a message from an admin or on behalf of a contact, or with a note for admins. + * + * @param ReplyConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function replyConversation(ReplyConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}/reply", + method: HttpMethod::POST, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * For managing conversations you can: + * - Close a conversation + * - Snooze a conversation to reopen on a future date + * - Open a conversation which is `snoozed` or `closed` + * - Assign a conversation to an admin and/or team. + * + * @param ManageConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function manageConversation(ManageConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}/parts", + method: HttpMethod::POST, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can add participants who are contacts to a conversation, on behalf of either another contact or an admin. + * + * {% admonition type="warning" name="Contacts without an email" %} + * If you add a contact via the email parameter and there is no user/lead found on that workspace with he given email, then we will create a new contact with `role` set to `lead`. + * {% /admonition %} + * + * @param AttachContactToConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachContactToConversation(AttachContactToConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}/customers", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can add participants who are contacts to a conversation, on behalf of either another contact or an admin. + * + * {% admonition type="warning" name="Contacts without an email" %} + * If you add a contact via the email parameter and there is no user/lead found on that workspace with he given email, then we will create a new contact with `role` set to `lead`. + * {% /admonition %} + * + * @param DetachContactFromConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachContactFromConversation(DetachContactFromConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/customers/{$request->getContactId()}", + method: HttpMethod::DELETE, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can redact a conversation part or the source message of a conversation (as seen in the source object). + * + * {% admonition type="info" name="Redacting parts and messages" %} + * If you are redacting a conversation part, it must have a `body`. If you are redacting a source message, it must have been created by a contact. We will return a `conversation_part_not_redactable` error if these criteria are not met. + * {% /admonition %} + * + * @param RedactConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Conversation + * @throws IntercomException + * @throws IntercomApiException + */ + public function redactConversation(RedactConversationRequest $request, ?array $options = null): Conversation + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/redact", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Conversation::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can convert a conversation to a ticket. + * + * @param ConvertConversationToTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function convertConversationToTicket(ConvertConversationToTicketRequest $request, ?array $options = null): ?Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getId()}/convert", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Conversations/Requests/AttachContactToConversationRequest.php b/src/Unstable/Conversations/Requests/AttachContactToConversationRequest.php new file mode 100644 index 00000000..02e628c5 --- /dev/null +++ b/src/Unstable/Conversations/Requests/AttachContactToConversationRequest.php @@ -0,0 +1,112 @@ +id = $values['id']; + $this->adminId = $values['adminId'] ?? null; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ( + * AttachContactToConversationRequestCustomerIntercomUserId + * |AttachContactToConversationRequestCustomerUserId + * |AttachContactToConversationRequestCustomerCustomer + * )|null + */ + public function getCustomer(): AttachContactToConversationRequestCustomerIntercomUserId|AttachContactToConversationRequestCustomerUserId|AttachContactToConversationRequestCustomerCustomer|null + { + return $this->customer; + } + + /** + * @param ( + * AttachContactToConversationRequestCustomerIntercomUserId + * |AttachContactToConversationRequestCustomerUserId + * |AttachContactToConversationRequestCustomerCustomer + * )|null $value + */ + public function setCustomer(AttachContactToConversationRequestCustomerIntercomUserId|AttachContactToConversationRequestCustomerUserId|AttachContactToConversationRequestCustomerCustomer|null $value = null): self + { + $this->customer = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/ConvertConversationToTicketRequest.php b/src/Unstable/Conversations/Requests/ConvertConversationToTicketRequest.php new file mode 100644 index 00000000..2f652570 --- /dev/null +++ b/src/Unstable/Conversations/Requests/ConvertConversationToTicketRequest.php @@ -0,0 +1,118 @@ + + * |null + * )> $attributes + */ + #[JsonProperty('attributes'), ArrayType(['string' => new Union(new Union('string', 'null'), 'float', 'bool', ['mixed'])])] + private ?array $attributes; + + /** + * @param array{ + * id: int, + * ticketTypeId: string, + * attributes?: ?array + * |null + * )>, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->ticketTypeId = $values['ticketTypeId']; + $this->attributes = $values['attributes'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return ?array + * |null + * )> + */ + public function getAttributes(): ?array + { + return $this->attributes; + } + + /** + * @param ?array + * |null + * )> $value + */ + public function setAttributes(?array $value = null): self + { + $this->attributes = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/CreateConversationRequest.php b/src/Unstable/Conversations/Requests/CreateConversationRequest.php new file mode 100644 index 00000000..a8c3c58e --- /dev/null +++ b/src/Unstable/Conversations/Requests/CreateConversationRequest.php @@ -0,0 +1,94 @@ +from = $values['from']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + } + + /** + * @return CreateConversationRequestFrom + */ + public function getFrom(): CreateConversationRequestFrom + { + return $this->from; + } + + /** + * @param CreateConversationRequestFrom $value + */ + public function setFrom(CreateConversationRequestFrom $value): self + { + $this->from = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/DeleteConversationRequest.php b/src/Unstable/Conversations/Requests/DeleteConversationRequest.php new file mode 100644 index 00000000..cbb3cc00 --- /dev/null +++ b/src/Unstable/Conversations/Requests/DeleteConversationRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/DetachContactFromConversationRequest.php b/src/Unstable/Conversations/Requests/DetachContactFromConversationRequest.php new file mode 100644 index 00000000..bd2c32b1 --- /dev/null +++ b/src/Unstable/Conversations/Requests/DetachContactFromConversationRequest.php @@ -0,0 +1,91 @@ +conversationId = $values['conversationId']; + $this->contactId = $values['contactId']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/ListConversationsRequest.php b/src/Unstable/Conversations/Requests/ListConversationsRequest.php new file mode 100644 index 00000000..205e9ae1 --- /dev/null +++ b/src/Unstable/Conversations/Requests/ListConversationsRequest.php @@ -0,0 +1,65 @@ +perPage = $values['perPage'] ?? null; + $this->startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/ManageConversationRequest.php b/src/Unstable/Conversations/Requests/ManageConversationRequest.php new file mode 100644 index 00000000..e14e6c87 --- /dev/null +++ b/src/Unstable/Conversations/Requests/ManageConversationRequest.php @@ -0,0 +1,66 @@ +id = $values['id']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ManageConversationRequestBody + */ + public function getBody(): ManageConversationRequestBody + { + return $this->body; + } + + /** + * @param ManageConversationRequestBody $value + */ + public function setBody(ManageConversationRequestBody $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/ReplyConversationRequest.php b/src/Unstable/Conversations/Requests/ReplyConversationRequest.php new file mode 100644 index 00000000..4931520d --- /dev/null +++ b/src/Unstable/Conversations/Requests/ReplyConversationRequest.php @@ -0,0 +1,89 @@ +id = $values['id']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ( + * ContactReplyIntercomUserIdRequest + * |ContactReplyEmailRequest + * |ContactReplyUserIdRequest + * |AdminReplyConversationRequest + * ) + */ + public function getBody(): ContactReplyIntercomUserIdRequest|ContactReplyEmailRequest|ContactReplyUserIdRequest|AdminReplyConversationRequest + { + return $this->body; + } + + /** + * @param ( + * ContactReplyIntercomUserIdRequest + * |ContactReplyEmailRequest + * |ContactReplyUserIdRequest + * |AdminReplyConversationRequest + * ) $value + */ + public function setBody(ContactReplyIntercomUserIdRequest|ContactReplyEmailRequest|ContactReplyUserIdRequest|AdminReplyConversationRequest $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/RetrieveConversationRequest.php b/src/Unstable/Conversations/Requests/RetrieveConversationRequest.php new file mode 100644 index 00000000..b549593e --- /dev/null +++ b/src/Unstable/Conversations/Requests/RetrieveConversationRequest.php @@ -0,0 +1,65 @@ +id = $values['id']; + $this->displayAs = $values['displayAs'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDisplayAs(): ?string + { + return $this->displayAs; + } + + /** + * @param ?string $value + */ + public function setDisplayAs(?string $value = null): self + { + $this->displayAs = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Requests/UpdateConversationRequest.php b/src/Unstable/Conversations/Requests/UpdateConversationRequest.php new file mode 100644 index 00000000..8532a595 --- /dev/null +++ b/src/Unstable/Conversations/Requests/UpdateConversationRequest.php @@ -0,0 +1,190 @@ + $customAttributes + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => new Union('string', 'integer', 'datetime', CustomObjectInstanceList::class)])] + private ?array $customAttributes; + + /** + * @var ?string $companyId The ID of the company that the conversation is associated with. The unique identifier for the company which is given by Intercom. Set to nil to remove company. + */ + #[JsonProperty('company_id')] + private ?string $companyId; + + /** + * @param array{ + * id: int, + * displayAs?: ?string, + * read?: ?bool, + * title?: ?string, + * customAttributes?: ?array, + * companyId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->displayAs = $values['displayAs'] ?? null; + $this->read = $values['read'] ?? null; + $this->title = $values['title'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->companyId = $values['companyId'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDisplayAs(): ?string + { + return $this->displayAs; + } + + /** + * @param ?string $value + */ + public function setDisplayAs(?string $value = null): self + { + $this->displayAs = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRead(): ?bool + { + return $this->read; + } + + /** + * @param ?bool $value + */ + public function setRead(?bool $value = null): self + { + $this->read = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } +} diff --git a/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerCustomer.php b/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerCustomer.php new file mode 100644 index 00000000..b1432bc4 --- /dev/null +++ b/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerCustomer.php @@ -0,0 +1,96 @@ +email = $values['email']; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null + */ + public function getCustomer(): CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null + { + return $this->customer; + } + + /** + * @param ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null $value + */ + public function setCustomer(CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null $value = null): self + { + $this->customer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerIntercomUserId.php b/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerIntercomUserId.php new file mode 100644 index 00000000..6b21e4da --- /dev/null +++ b/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerIntercomUserId.php @@ -0,0 +1,96 @@ +intercomUserId = $values['intercomUserId']; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null + */ + public function getCustomer(): CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null + { + return $this->customer; + } + + /** + * @param ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null $value + */ + public function setCustomer(CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null $value = null): self + { + $this->customer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerUserId.php b/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerUserId.php new file mode 100644 index 00000000..a50cd1a0 --- /dev/null +++ b/src/Unstable/Conversations/Types/AttachContactToConversationRequestCustomerUserId.php @@ -0,0 +1,96 @@ +userId = $values['userId']; + $this->customer = $values['customer'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null + */ + public function getCustomer(): CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null + { + return $this->customer; + } + + /** + * @param ( + * CustomerRequestIntercomUserId + * |CustomerRequestUserId + * |CustomerRequestEmail + * )|null $value + */ + public function setCustomer(CustomerRequestIntercomUserId|CustomerRequestUserId|CustomerRequestEmail|null $value = null): self + { + $this->customer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Conversations/Types/Conversation.php b/src/Unstable/Conversations/Types/Conversation.php new file mode 100644 index 00000000..39f284bf --- /dev/null +++ b/src/Unstable/Conversations/Types/Conversation.php @@ -0,0 +1,739 @@ + $state Can be set to "open", "closed" or "snoozed". + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?bool $read Indicates whether a conversation has been read. + */ + #[JsonProperty('read')] + private ?bool $read; + + /** + * @var ?value-of $priority If marked as priority, it will return priority or else not_priority. + */ + #[JsonProperty('priority')] + private ?string $priority; + + /** + * @var ?int $adminAssigneeId The id of the admin assigned to the conversation. If it's not assigned to an admin it will return null. + */ + #[JsonProperty('admin_assignee_id')] + private ?int $adminAssigneeId; + + /** + * @var ?string $teamAssigneeId The id of the team assigned to the conversation. If it's not assigned to a team it will return null. + */ + #[JsonProperty('team_assignee_id')] + private ?string $teamAssigneeId; + + /** + * @var ?string $companyId The ID of the company that the conversation is associated with. The unique identifier for the company which is given by Intercom. + */ + #[JsonProperty('company_id')] + private ?string $companyId; + + /** + * @var ?Tags $tags + */ + #[JsonProperty('tags')] + private ?Tags $tags; + + /** + * @var ?ConversationRating $conversationRating + */ + #[JsonProperty('conversation_rating')] + private ?ConversationRating $conversationRating; + + /** + * @var ?ConversationSource $source + */ + #[JsonProperty('source')] + private ?ConversationSource $source; + + /** + * @var ?ConversationContacts $contacts + */ + #[JsonProperty('contacts')] + private ?ConversationContacts $contacts; + + /** + * @var ?ConversationTeammates $teammates + */ + #[JsonProperty('teammates')] + private ?ConversationTeammates $teammates; + + /** + * @var ?array $customAttributes + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => new Union('string', 'integer', 'datetime', CustomObjectInstanceList::class)])] + private ?array $customAttributes; + + /** + * @var ?ConversationFirstContactReply $firstContactReply + */ + #[JsonProperty('first_contact_reply')] + private ?ConversationFirstContactReply $firstContactReply; + + /** + * @var ?SlaApplied $slaApplied + */ + #[JsonProperty('sla_applied')] + private ?SlaApplied $slaApplied; + + /** + * @var ?ConversationStatistics $statistics + */ + #[JsonProperty('statistics')] + private ?ConversationStatistics $statistics; + + /** + * @var ?ConversationParts $conversationParts + */ + #[JsonProperty('conversation_parts')] + private ?ConversationParts $conversationParts; + + /** + * @var ?LinkedObjectList $linkedObjects + */ + #[JsonProperty('linked_objects')] + private ?LinkedObjectList $linkedObjects; + + /** + * @var ?bool $aiAgentParticipated Indicates whether the AI Agent participated in the conversation. + */ + #[JsonProperty('ai_agent_participated')] + private ?bool $aiAgentParticipated; + + /** + * @var ?AiAgent $aiAgent + */ + #[JsonProperty('ai_agent')] + private ?AiAgent $aiAgent; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * title?: ?string, + * createdAt?: ?int, + * updatedAt?: ?int, + * waitingSince?: ?int, + * snoozedUntil?: ?int, + * open?: ?bool, + * state?: ?value-of, + * read?: ?bool, + * priority?: ?value-of, + * adminAssigneeId?: ?int, + * teamAssigneeId?: ?string, + * companyId?: ?string, + * tags?: ?Tags, + * conversationRating?: ?ConversationRating, + * source?: ?ConversationSource, + * contacts?: ?ConversationContacts, + * teammates?: ?ConversationTeammates, + * customAttributes?: ?array, + * firstContactReply?: ?ConversationFirstContactReply, + * slaApplied?: ?SlaApplied, + * statistics?: ?ConversationStatistics, + * conversationParts?: ?ConversationParts, + * linkedObjects?: ?LinkedObjectList, + * aiAgentParticipated?: ?bool, + * aiAgent?: ?AiAgent, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->title = $values['title'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->waitingSince = $values['waitingSince'] ?? null; + $this->snoozedUntil = $values['snoozedUntil'] ?? null; + $this->open = $values['open'] ?? null; + $this->state = $values['state'] ?? null; + $this->read = $values['read'] ?? null; + $this->priority = $values['priority'] ?? null; + $this->adminAssigneeId = $values['adminAssigneeId'] ?? null; + $this->teamAssigneeId = $values['teamAssigneeId'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->conversationRating = $values['conversationRating'] ?? null; + $this->source = $values['source'] ?? null; + $this->contacts = $values['contacts'] ?? null; + $this->teammates = $values['teammates'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->firstContactReply = $values['firstContactReply'] ?? null; + $this->slaApplied = $values['slaApplied'] ?? null; + $this->statistics = $values['statistics'] ?? null; + $this->conversationParts = $values['conversationParts'] ?? null; + $this->linkedObjects = $values['linkedObjects'] ?? null; + $this->aiAgentParticipated = $values['aiAgentParticipated'] ?? null; + $this->aiAgent = $values['aiAgent'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getWaitingSince(): ?int + { + return $this->waitingSince; + } + + /** + * @param ?int $value + */ + public function setWaitingSince(?int $value = null): self + { + $this->waitingSince = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSnoozedUntil(): ?int + { + return $this->snoozedUntil; + } + + /** + * @param ?int $value + */ + public function setSnoozedUntil(?int $value = null): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getOpen(): ?bool + { + return $this->open; + } + + /** + * @param ?bool $value + */ + public function setOpen(?bool $value = null): self + { + $this->open = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRead(): ?bool + { + return $this->read; + } + + /** + * @param ?bool $value + */ + public function setRead(?bool $value = null): self + { + $this->read = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getPriority(): ?string + { + return $this->priority; + } + + /** + * @param ?value-of $value + */ + public function setPriority(?string $value = null): self + { + $this->priority = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAdminAssigneeId(): ?int + { + return $this->adminAssigneeId; + } + + /** + * @param ?int $value + */ + public function setAdminAssigneeId(?int $value = null): self + { + $this->adminAssigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTeamAssigneeId(): ?string + { + return $this->teamAssigneeId; + } + + /** + * @param ?string $value + */ + public function setTeamAssigneeId(?string $value = null): self + { + $this->teamAssigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?Tags + */ + public function getTags(): ?Tags + { + return $this->tags; + } + + /** + * @param ?Tags $value + */ + public function setTags(?Tags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?ConversationRating + */ + public function getConversationRating(): ?ConversationRating + { + return $this->conversationRating; + } + + /** + * @param ?ConversationRating $value + */ + public function setConversationRating(?ConversationRating $value = null): self + { + $this->conversationRating = $value; + return $this; + } + + /** + * @return ?ConversationSource + */ + public function getSource(): ?ConversationSource + { + return $this->source; + } + + /** + * @param ?ConversationSource $value + */ + public function setSource(?ConversationSource $value = null): self + { + $this->source = $value; + return $this; + } + + /** + * @return ?ConversationContacts + */ + public function getContacts(): ?ConversationContacts + { + return $this->contacts; + } + + /** + * @param ?ConversationContacts $value + */ + public function setContacts(?ConversationContacts $value = null): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ?ConversationTeammates + */ + public function getTeammates(): ?ConversationTeammates + { + return $this->teammates; + } + + /** + * @param ?ConversationTeammates $value + */ + public function setTeammates(?ConversationTeammates $value = null): self + { + $this->teammates = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?ConversationFirstContactReply + */ + public function getFirstContactReply(): ?ConversationFirstContactReply + { + return $this->firstContactReply; + } + + /** + * @param ?ConversationFirstContactReply $value + */ + public function setFirstContactReply(?ConversationFirstContactReply $value = null): self + { + $this->firstContactReply = $value; + return $this; + } + + /** + * @return ?SlaApplied + */ + public function getSlaApplied(): ?SlaApplied + { + return $this->slaApplied; + } + + /** + * @param ?SlaApplied $value + */ + public function setSlaApplied(?SlaApplied $value = null): self + { + $this->slaApplied = $value; + return $this; + } + + /** + * @return ?ConversationStatistics + */ + public function getStatistics(): ?ConversationStatistics + { + return $this->statistics; + } + + /** + * @param ?ConversationStatistics $value + */ + public function setStatistics(?ConversationStatistics $value = null): self + { + $this->statistics = $value; + return $this; + } + + /** + * @return ?ConversationParts + */ + public function getConversationParts(): ?ConversationParts + { + return $this->conversationParts; + } + + /** + * @param ?ConversationParts $value + */ + public function setConversationParts(?ConversationParts $value = null): self + { + $this->conversationParts = $value; + return $this; + } + + /** + * @return ?LinkedObjectList + */ + public function getLinkedObjects(): ?LinkedObjectList + { + return $this->linkedObjects; + } + + /** + * @param ?LinkedObjectList $value + */ + public function setLinkedObjects(?LinkedObjectList $value = null): self + { + $this->linkedObjects = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAiAgentParticipated(): ?bool + { + return $this->aiAgentParticipated; + } + + /** + * @param ?bool $value + */ + public function setAiAgentParticipated(?bool $value = null): self + { + $this->aiAgentParticipated = $value; + return $this; + } + + /** + * @return ?AiAgent + */ + public function getAiAgent(): ?AiAgent + { + return $this->aiAgent; + } + + /** + * @param ?AiAgent $value + */ + public function setAiAgent(?AiAgent $value = null): self + { + $this->aiAgent = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Conversations/Types/ConversationPriority.php b/src/Unstable/Conversations/Types/ConversationPriority.php new file mode 100644 index 00000000..62c37f68 --- /dev/null +++ b/src/Unstable/Conversations/Types/ConversationPriority.php @@ -0,0 +1,9 @@ + $type The role associated to the contact - user or lead. + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The identifier for the contact which is given by Intercom. + */ + #[JsonProperty('id')] + private string $id; + + /** + * @param array{ + * type: value-of, + * id: string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Conversations/Types/CreateConversationRequestFromType.php b/src/Unstable/Conversations/Types/CreateConversationRequestFromType.php new file mode 100644 index 00000000..ef9f1408 --- /dev/null +++ b/src/Unstable/Conversations/Types/CreateConversationRequestFromType.php @@ -0,0 +1,10 @@ +messageType = $values['messageType']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'close' + * |'snoozed' + * |'open' + * |'assignment' + * |'_unknown' + * ) + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @return ( + * CloseConversationRequest + * |SnoozeConversationRequest + * |OpenConversationRequest + * |AssignConversationRequest + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param CloseConversationRequest $close + * @return ManageConversationRequestBody + */ + public static function close(CloseConversationRequest $close): ManageConversationRequestBody + { + return new ManageConversationRequestBody([ + 'messageType' => 'close', + 'value' => $close, + ]); + } + + /** + * @param SnoozeConversationRequest $snoozed + * @return ManageConversationRequestBody + */ + public static function snoozed(SnoozeConversationRequest $snoozed): ManageConversationRequestBody + { + return new ManageConversationRequestBody([ + 'messageType' => 'snoozed', + 'value' => $snoozed, + ]); + } + + /** + * @param OpenConversationRequest $open + * @return ManageConversationRequestBody + */ + public static function open(OpenConversationRequest $open): ManageConversationRequestBody + { + return new ManageConversationRequestBody([ + 'messageType' => 'open', + 'value' => $open, + ]); + } + + /** + * @param AssignConversationRequest $assignment + * @return ManageConversationRequestBody + */ + public static function assignment(AssignConversationRequest $assignment): ManageConversationRequestBody + { + return new ManageConversationRequestBody([ + 'messageType' => 'assignment', + 'value' => $assignment, + ]); + } + + /** + * @return bool + */ + public function isClose(): bool + { + return $this->value instanceof CloseConversationRequest && $this->messageType === 'close'; + } + + /** + * @return CloseConversationRequest + */ + public function asClose(): CloseConversationRequest + { + if (!($this->value instanceof CloseConversationRequest && $this->messageType === 'close')) { + throw new Exception( + "Expected close; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSnoozed(): bool + { + return $this->value instanceof SnoozeConversationRequest && $this->messageType === 'snoozed'; + } + + /** + * @return SnoozeConversationRequest + */ + public function asSnoozed(): SnoozeConversationRequest + { + if (!($this->value instanceof SnoozeConversationRequest && $this->messageType === 'snoozed')) { + throw new Exception( + "Expected snoozed; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isOpen(): bool + { + return $this->value instanceof OpenConversationRequest && $this->messageType === 'open'; + } + + /** + * @return OpenConversationRequest + */ + public function asOpen(): OpenConversationRequest + { + if (!($this->value instanceof OpenConversationRequest && $this->messageType === 'open')) { + throw new Exception( + "Expected open; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isAssignment(): bool + { + return $this->value instanceof AssignConversationRequest && $this->messageType === 'assignment'; + } + + /** + * @return AssignConversationRequest + */ + public function asAssignment(): AssignConversationRequest + { + if (!($this->value instanceof AssignConversationRequest && $this->messageType === 'assignment')) { + throw new Exception( + "Expected assignment; got " . $this->messageType . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['message_type'] = $this->messageType; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->messageType) { + case 'close': + $value = $this->asClose()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'snoozed': + $value = $this->asSnoozed()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'open': + $value = $this->asOpen()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'assignment': + $value = $this->asAssignment()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('message_type', $data)) { + throw new Exception( + "JSON data is missing property 'message_type'", + ); + } + $messageType = $data['message_type']; + if (!(is_string($messageType))) { + throw new Exception( + "Expected property 'messageType' in JSON data to be string, instead received " . get_debug_type($data['message_type']), + ); + } + + $args['messageType'] = $messageType; + switch ($messageType) { + case 'close': + $args['value'] = CloseConversationRequest::jsonDeserialize($data); + break; + case 'snoozed': + $args['value'] = SnoozeConversationRequest::jsonDeserialize($data); + break; + case 'open': + $args['value'] = OpenConversationRequest::jsonDeserialize($data); + break; + case 'assignment': + $args['value'] = AssignConversationRequest::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['messageType'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Unstable/CustomChannelEvents/CustomChannelEventsClient.php b/src/Unstable/CustomChannelEvents/CustomChannelEventsClient.php new file mode 100644 index 00000000..30dfdc2b --- /dev/null +++ b/src/Unstable/CustomChannelEvents/CustomChannelEventsClient.php @@ -0,0 +1,284 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * Notifies Intercom that a new conversation was created in your custom channel/platform. This triggers conversation creation and workflow automations within Intercom for your custom channel integration. + * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. + * + * @param CustomChannelBaseEvent $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CustomChannelNotificationResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function notifyNewConversation(CustomChannelBaseEvent $request, ?array $options = null): CustomChannelNotificationResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_channel_events/notify_new_conversation", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CustomChannelNotificationResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Notifies Intercom that a new message was sent in a conversation on your custom channel/platform. This allows Intercom to process the message and trigger any relevant workflow automations. + * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. + * + * @param NotifyNewMessageRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CustomChannelNotificationResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function notifyNewMessage(NotifyNewMessageRequest $request, ?array $options = null): CustomChannelNotificationResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_channel_events/notify_new_message", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CustomChannelNotificationResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Notifies Intercom that a user selected a quick reply option in your custom channel/platform. This allows Intercom to process the response and trigger any relevant workflow automations. + * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. + * + * @param NotifyQuickReplySelectedRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CustomChannelNotificationResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function notifyQuickReplySelected(NotifyQuickReplySelectedRequest $request, ?array $options = null): CustomChannelNotificationResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_channel_events/notify_quick_reply_selected", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CustomChannelNotificationResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Notifies Intercom that a user provided a response to an attribute collector in your custom channel/platform. This allows Intercom to process the attribute and trigger any relevant workflow automations. + * > **Note:** This endpoint is currently under managed availability. Please reach out to your accounts team to discuss access and tailored, hands-on support. + * + * @param NotifyAttributeCollectedRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CustomChannelNotificationResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function notifyAttributeCollected(NotifyAttributeCollectedRequest $request, ?array $options = null): CustomChannelNotificationResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_channel_events/notify_attribute_collected", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CustomChannelNotificationResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/CustomChannelEvents/Requests/NotifyAttributeCollectedRequest.php b/src/Unstable/CustomChannelEvents/Requests/NotifyAttributeCollectedRequest.php new file mode 100644 index 00000000..4d1230d7 --- /dev/null +++ b/src/Unstable/CustomChannelEvents/Requests/NotifyAttributeCollectedRequest.php @@ -0,0 +1,54 @@ +attribute = $values['attribute']; + $this->eventId = $values['eventId']; + $this->externalConversationId = $values['externalConversationId']; + $this->contact = $values['contact']; + } + + /** + * @return CustomChannelAttribute + */ + public function getAttribute(): CustomChannelAttribute + { + return $this->attribute; + } + + /** + * @param CustomChannelAttribute $value + */ + public function setAttribute(CustomChannelAttribute $value): self + { + $this->attribute = $value; + return $this; + } +} diff --git a/src/Unstable/CustomChannelEvents/Requests/NotifyNewMessageRequest.php b/src/Unstable/CustomChannelEvents/Requests/NotifyNewMessageRequest.php new file mode 100644 index 00000000..baf5128c --- /dev/null +++ b/src/Unstable/CustomChannelEvents/Requests/NotifyNewMessageRequest.php @@ -0,0 +1,53 @@ +body = $values['body']; + $this->eventId = $values['eventId']; + $this->externalConversationId = $values['externalConversationId']; + $this->contact = $values['contact']; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Unstable/CustomChannelEvents/Requests/NotifyQuickReplySelectedRequest.php b/src/Unstable/CustomChannelEvents/Requests/NotifyQuickReplySelectedRequest.php new file mode 100644 index 00000000..292a91bf --- /dev/null +++ b/src/Unstable/CustomChannelEvents/Requests/NotifyQuickReplySelectedRequest.php @@ -0,0 +1,53 @@ +quickReplyOptionId = $values['quickReplyOptionId']; + $this->eventId = $values['eventId']; + $this->externalConversationId = $values['externalConversationId']; + $this->contact = $values['contact']; + } + + /** + * @return string + */ + public function getQuickReplyOptionId(): string + { + return $this->quickReplyOptionId; + } + + /** + * @param string $value + */ + public function setQuickReplyOptionId(string $value): self + { + $this->quickReplyOptionId = $value; + return $this; + } +} diff --git a/src/Unstable/CustomObjectInstances/CustomObjectInstancesClient.php b/src/Unstable/CustomObjectInstances/CustomObjectInstancesClient.php new file mode 100644 index 00000000..250331a3 --- /dev/null +++ b/src/Unstable/CustomObjectInstances/CustomObjectInstancesClient.php @@ -0,0 +1,349 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * Fetch a Custom Object Instance by external_id. + * + * @param GetCustomObjectInstancesByExternalIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?CustomObjectInstance + * @throws IntercomException + * @throws IntercomApiException + */ + public function getCustomObjectInstancesByExternalId(GetCustomObjectInstancesByExternalIdRequest $request, ?array $options = null): ?CustomObjectInstance + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['external_id'] = $request->getExternalId(); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_object_instances/{$request->getCustomObjectTypeIdentifier()}", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return CustomObjectInstance::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Create or update a custom object instance + * + * @param CreateOrUpdateCustomObjectInstanceRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?CustomObjectInstance + * @throws IntercomException + * @throws IntercomApiException + */ + public function createCustomObjectInstances(CreateOrUpdateCustomObjectInstanceRequest $request, ?array $options = null): ?CustomObjectInstance + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_object_instances/{$request->getCustomObjectTypeIdentifier()}", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return CustomObjectInstance::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Delete a single Custom Object instance by external_id. + * + * @param DeleteCustomObjectInstancesByIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CustomObjectInstanceDeleted + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteCustomObjectInstancesById(DeleteCustomObjectInstancesByIdRequest $request, ?array $options = null): CustomObjectInstanceDeleted + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['external_id'] = $request->getExternalId(); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_object_instances/{$request->getCustomObjectTypeIdentifier()}", + method: HttpMethod::DELETE, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CustomObjectInstanceDeleted::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Fetch a Custom Object Instance by id. + * + * @param GetCustomObjectInstancesByIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?CustomObjectInstance + * @throws IntercomException + * @throws IntercomApiException + */ + public function getCustomObjectInstancesById(GetCustomObjectInstancesByIdRequest $request, ?array $options = null): ?CustomObjectInstance + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_object_instances/{$request->getCustomObjectTypeIdentifier()}/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return CustomObjectInstance::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Delete a single Custom Object instance using the Intercom defined id. + * + * @param DeleteCustomObjectInstancesByExternalIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CustomObjectInstanceDeleted + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteCustomObjectInstancesByExternalId(DeleteCustomObjectInstancesByExternalIdRequest $request, ?array $options = null): CustomObjectInstanceDeleted + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "custom_object_instances/{$request->getCustomObjectTypeIdentifier()}/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CustomObjectInstanceDeleted::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/CustomObjectInstances/Requests/CreateOrUpdateCustomObjectInstanceRequest.php b/src/Unstable/CustomObjectInstances/Requests/CreateOrUpdateCustomObjectInstanceRequest.php new file mode 100644 index 00000000..5f18b68f --- /dev/null +++ b/src/Unstable/CustomObjectInstances/Requests/CreateOrUpdateCustomObjectInstanceRequest.php @@ -0,0 +1,144 @@ + $customAttributes The custom attributes which are set for the Custom Object instance. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => new Union('string', 'null')])] + private ?array $customAttributes; + + /** + * @param array{ + * customObjectTypeIdentifier: string, + * externalId?: ?string, + * externalCreatedAt?: ?int, + * externalUpdatedAt?: ?int, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->customObjectTypeIdentifier = $values['customObjectTypeIdentifier']; + $this->externalId = $values['externalId'] ?? null; + $this->externalCreatedAt = $values['externalCreatedAt'] ?? null; + $this->externalUpdatedAt = $values['externalUpdatedAt'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return string + */ + public function getCustomObjectTypeIdentifier(): string + { + return $this->customObjectTypeIdentifier; + } + + /** + * @param string $value + */ + public function setCustomObjectTypeIdentifier(string $value): self + { + $this->customObjectTypeIdentifier = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getExternalCreatedAt(): ?int + { + return $this->externalCreatedAt; + } + + /** + * @param ?int $value + */ + public function setExternalCreatedAt(?int $value = null): self + { + $this->externalCreatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getExternalUpdatedAt(): ?int + { + return $this->externalUpdatedAt; + } + + /** + * @param ?int $value + */ + public function setExternalUpdatedAt(?int $value = null): self + { + $this->externalUpdatedAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } +} diff --git a/src/Unstable/CustomObjectInstances/Requests/DeleteCustomObjectInstancesByExternalIdRequest.php b/src/Unstable/CustomObjectInstances/Requests/DeleteCustomObjectInstancesByExternalIdRequest.php new file mode 100644 index 00000000..cd98c17a --- /dev/null +++ b/src/Unstable/CustomObjectInstances/Requests/DeleteCustomObjectInstancesByExternalIdRequest.php @@ -0,0 +1,65 @@ +customObjectTypeIdentifier = $values['customObjectTypeIdentifier']; + $this->id = $values['id']; + } + + /** + * @return string + */ + public function getCustomObjectTypeIdentifier(): string + { + return $this->customObjectTypeIdentifier; + } + + /** + * @param string $value + */ + public function setCustomObjectTypeIdentifier(string $value): self + { + $this->customObjectTypeIdentifier = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/CustomObjectInstances/Requests/DeleteCustomObjectInstancesByIdRequest.php b/src/Unstable/CustomObjectInstances/Requests/DeleteCustomObjectInstancesByIdRequest.php new file mode 100644 index 00000000..16a07999 --- /dev/null +++ b/src/Unstable/CustomObjectInstances/Requests/DeleteCustomObjectInstancesByIdRequest.php @@ -0,0 +1,65 @@ +customObjectTypeIdentifier = $values['customObjectTypeIdentifier']; + $this->externalId = $values['externalId']; + } + + /** + * @return string + */ + public function getCustomObjectTypeIdentifier(): string + { + return $this->customObjectTypeIdentifier; + } + + /** + * @param string $value + */ + public function setCustomObjectTypeIdentifier(string $value): self + { + $this->customObjectTypeIdentifier = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } +} diff --git a/src/Unstable/CustomObjectInstances/Requests/GetCustomObjectInstancesByExternalIdRequest.php b/src/Unstable/CustomObjectInstances/Requests/GetCustomObjectInstancesByExternalIdRequest.php new file mode 100644 index 00000000..51b73c69 --- /dev/null +++ b/src/Unstable/CustomObjectInstances/Requests/GetCustomObjectInstancesByExternalIdRequest.php @@ -0,0 +1,65 @@ +customObjectTypeIdentifier = $values['customObjectTypeIdentifier']; + $this->externalId = $values['externalId']; + } + + /** + * @return string + */ + public function getCustomObjectTypeIdentifier(): string + { + return $this->customObjectTypeIdentifier; + } + + /** + * @param string $value + */ + public function setCustomObjectTypeIdentifier(string $value): self + { + $this->customObjectTypeIdentifier = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } +} diff --git a/src/Unstable/CustomObjectInstances/Requests/GetCustomObjectInstancesByIdRequest.php b/src/Unstable/CustomObjectInstances/Requests/GetCustomObjectInstancesByIdRequest.php new file mode 100644 index 00000000..b58f2926 --- /dev/null +++ b/src/Unstable/CustomObjectInstances/Requests/GetCustomObjectInstancesByIdRequest.php @@ -0,0 +1,65 @@ +customObjectTypeIdentifier = $values['customObjectTypeIdentifier']; + $this->id = $values['id']; + } + + /** + * @return string + */ + public function getCustomObjectTypeIdentifier(): string + { + return $this->customObjectTypeIdentifier; + } + + /** + * @param string $value + */ + public function setCustomObjectTypeIdentifier(string $value): self + { + $this->customObjectTypeIdentifier = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/CustomObjectInstances/Types/CustomObjectInstance.php b/src/Unstable/CustomObjectInstances/Types/CustomObjectInstance.php new file mode 100644 index 00000000..5de4feb6 --- /dev/null +++ b/src/Unstable/CustomObjectInstances/Types/CustomObjectInstance.php @@ -0,0 +1,230 @@ + $customAttributes The custom attributes you have set on the custom object instance. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'string'])] + private ?array $customAttributes; + + /** + * @param array{ + * id?: ?string, + * externalId?: ?string, + * externalCreatedAt?: ?int, + * externalUpdatedAt?: ?int, + * createdAt?: ?int, + * updatedAt?: ?int, + * type?: ?string, + * customAttributes?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->externalCreatedAt = $values['externalCreatedAt'] ?? null; + $this->externalUpdatedAt = $values['externalUpdatedAt'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->type = $values['type'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getExternalCreatedAt(): ?int + { + return $this->externalCreatedAt; + } + + /** + * @param ?int $value + */ + public function setExternalCreatedAt(?int $value = null): self + { + $this->externalCreatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getExternalUpdatedAt(): ?int + { + return $this->externalUpdatedAt; + } + + /** + * @param ?int $value + */ + public function setExternalUpdatedAt(?int $value = null): self + { + $this->externalUpdatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataAttributes/DataAttributesClient.php b/src/Unstable/DataAttributes/DataAttributesClient.php new file mode 100644 index 00000000..0a74aecc --- /dev/null +++ b/src/Unstable/DataAttributes/DataAttributesClient.php @@ -0,0 +1,236 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all data attributes belonging to a workspace for contacts, companies or conversations. + * + * @param LisDataAttributesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataAttributeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function lisDataAttributes(LisDataAttributesRequest $request = new LisDataAttributesRequest(), ?array $options = null): DataAttributeList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getModel() != null) { + $query['model'] = $request->getModel(); + } + if ($request->getIncludeArchived() != null) { + $query['include_archived'] = $request->getIncludeArchived(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "data_attributes", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataAttributeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a data attributes for a `contact` or a `company`. + * + * @param CreateDataAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function createDataAttribute(CreateDataAttributeRequest $request, ?array $options = null): DataAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "data_attributes", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You can update a data attribute. + * + * > 🚧 Updating the data type is not possible + * > + * > It is currently a dangerous action to execute changing a data attribute's type via the API. You will need to update the type via the UI instead. + * + * @param UpdateDataAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateDataAttribute(UpdateDataAttributeRequest $request, ?array $options = null): DataAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "data_attributes/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/DataAttributes/Requests/CreateDataAttributeRequest.php b/src/Unstable/DataAttributes/Requests/CreateDataAttributeRequest.php new file mode 100644 index 00000000..06625dd4 --- /dev/null +++ b/src/Unstable/DataAttributes/Requests/CreateDataAttributeRequest.php @@ -0,0 +1,171 @@ + $model The model that the data attribute belongs to. + */ + #[JsonProperty('model')] + private string $model; + + /** + * @var value-of $dataType The type of data stored for this attribute. + */ + #[JsonProperty('data_type')] + private string $dataType; + + /** + * @var ?string $description The readable description you see in the UI for the attribute. + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var ?array $options To create list attributes. Provide a set of hashes with `value` as the key of the options you want to make. `data_type` must be `string`. + */ + #[JsonProperty('options'), ArrayType(['string'])] + private ?array $options; + + /** + * @var ?bool $messengerWritable Can this attribute be updated by the Messenger + */ + #[JsonProperty('messenger_writable')] + private ?bool $messengerWritable; + + /** + * @param array{ + * name: string, + * model: value-of, + * dataType: value-of, + * description?: ?string, + * options?: ?array, + * messengerWritable?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->model = $values['model']; + $this->dataType = $values['dataType']; + $this->description = $values['description'] ?? null; + $this->options = $values['options'] ?? null; + $this->messengerWritable = $values['messengerWritable'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return value-of + */ + public function getModel(): string + { + return $this->model; + } + + /** + * @param value-of $value + */ + public function setModel(string $value): self + { + $this->model = $value; + return $this; + } + + /** + * @return value-of + */ + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param value-of $value + */ + public function setDataType(string $value): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?array + */ + public function getOptions(): ?array + { + return $this->options; + } + + /** + * @param ?array $value + */ + public function setOptions(?array $value = null): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMessengerWritable(): ?bool + { + return $this->messengerWritable; + } + + /** + * @param ?bool $value + */ + public function setMessengerWritable(?bool $value = null): self + { + $this->messengerWritable = $value; + return $this; + } +} diff --git a/src/Unstable/DataAttributes/Requests/LisDataAttributesRequest.php b/src/Unstable/DataAttributes/Requests/LisDataAttributesRequest.php new file mode 100644 index 00000000..4d41b3e9 --- /dev/null +++ b/src/Unstable/DataAttributes/Requests/LisDataAttributesRequest.php @@ -0,0 +1,66 @@ + $model Specify the data attribute model to return. + */ + private ?string $model; + + /** + * @var ?bool $includeArchived Include archived attributes in the list. By default we return only non archived data attributes. + */ + private ?bool $includeArchived; + + /** + * @param array{ + * model?: ?value-of, + * includeArchived?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->model = $values['model'] ?? null; + $this->includeArchived = $values['includeArchived'] ?? null; + } + + /** + * @return ?value-of + */ + public function getModel(): ?string + { + return $this->model; + } + + /** + * @param ?value-of $value + */ + public function setModel(?string $value = null): self + { + $this->model = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIncludeArchived(): ?bool + { + return $this->includeArchived; + } + + /** + * @param ?bool $value + */ + public function setIncludeArchived(?bool $value = null): self + { + $this->includeArchived = $value; + return $this; + } +} diff --git a/src/Unstable/DataAttributes/Requests/UpdateDataAttributeRequest.php b/src/Unstable/DataAttributes/Requests/UpdateDataAttributeRequest.php new file mode 100644 index 00000000..5036ad46 --- /dev/null +++ b/src/Unstable/DataAttributes/Requests/UpdateDataAttributeRequest.php @@ -0,0 +1,143 @@ + $options To create list attributes. Provide a set of hashes with `value` as the key of the options you want to make. `data_type` must be `string`. + */ + #[JsonProperty('options'), ArrayType(['string'])] + private ?array $options; + + /** + * @var ?bool $messengerWritable Can this attribute be updated by the Messenger + */ + #[JsonProperty('messenger_writable')] + private ?bool $messengerWritable; + + /** + * @param array{ + * id: int, + * archived?: ?bool, + * description?: ?string, + * options?: ?array, + * messengerWritable?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->archived = $values['archived'] ?? null; + $this->description = $values['description'] ?? null; + $this->options = $values['options'] ?? null; + $this->messengerWritable = $values['messengerWritable'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?array + */ + public function getOptions(): ?array + { + return $this->options; + } + + /** + * @param ?array $value + */ + public function setOptions(?array $value = null): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMessengerWritable(): ?bool + { + return $this->messengerWritable; + } + + /** + * @param ?bool $value + */ + public function setMessengerWritable(?bool $value = null): self + { + $this->messengerWritable = $value; + return $this; + } +} diff --git a/src/Unstable/DataAttributes/Types/CreateDataAttributeRequestDataType.php b/src/Unstable/DataAttributes/Types/CreateDataAttributeRequestDataType.php new file mode 100644 index 00000000..e31d2590 --- /dev/null +++ b/src/Unstable/DataAttributes/Types/CreateDataAttributeRequestDataType.php @@ -0,0 +1,13 @@ + $model Value is `contact` for user/lead attributes and `company` for company attributes. + */ + #[JsonProperty('model')] + private ?string $model; + + /** + * @var ?string $name Name of the attribute. + */ + #[JsonProperty('name')] + private ?string $name; + + /** + * @var ?string $fullName Full name of the attribute. Should match the name unless it's a nested attribute. We can split full_name on `.` to access nested user object values. + */ + #[JsonProperty('full_name')] + private ?string $fullName; + + /** + * @var ?string $label Readable name of the attribute (i.e. name you see in the UI) + */ + #[JsonProperty('label')] + private ?string $label; + + /** + * @var ?string $description Readable description of the attribute. + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var ?value-of $dataType The data type of the attribute. + */ + #[JsonProperty('data_type')] + private ?string $dataType; + + /** + * @var ?array $options List of predefined options for attribute value. + */ + #[JsonProperty('options'), ArrayType(['string'])] + private ?array $options; + + /** + * @var ?bool $apiWritable Can this attribute be updated through API + */ + #[JsonProperty('api_writable')] + private ?bool $apiWritable; + + /** + * @var ?bool $messengerWritable Can this attribute be updated by the Messenger + */ + #[JsonProperty('messenger_writable')] + private ?bool $messengerWritable; + + /** + * @var ?bool $uiWritable Can this attribute be updated in the UI + */ + #[JsonProperty('ui_writable')] + private ?bool $uiWritable; + + /** + * @var ?bool $custom Set to true if this is a CDA + */ + #[JsonProperty('custom')] + private ?bool $custom; + + /** + * @var ?bool $archived Is this attribute archived. (Only applicable to CDAs) + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?int $createdAt The time the attribute was created as a UTC Unix timestamp + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The time the attribute was last updated as a UTC Unix timestamp + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?string $adminId Teammate who created the attribute. Only applicable to CDAs + */ + #[JsonProperty('admin_id')] + private ?string $adminId; + + /** + * @param array{ + * type?: ?'data_attribute', + * id?: ?int, + * model?: ?value-of, + * name?: ?string, + * fullName?: ?string, + * label?: ?string, + * description?: ?string, + * dataType?: ?value-of, + * options?: ?array, + * apiWritable?: ?bool, + * messengerWritable?: ?bool, + * uiWritable?: ?bool, + * custom?: ?bool, + * archived?: ?bool, + * createdAt?: ?int, + * updatedAt?: ?int, + * adminId?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->model = $values['model'] ?? null; + $this->name = $values['name'] ?? null; + $this->fullName = $values['fullName'] ?? null; + $this->label = $values['label'] ?? null; + $this->description = $values['description'] ?? null; + $this->dataType = $values['dataType'] ?? null; + $this->options = $values['options'] ?? null; + $this->apiWritable = $values['apiWritable'] ?? null; + $this->messengerWritable = $values['messengerWritable'] ?? null; + $this->uiWritable = $values['uiWritable'] ?? null; + $this->custom = $values['custom'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->adminId = $values['adminId'] ?? null; + } + + /** + * @return ?'data_attribute' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'data_attribute' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getId(): ?int + { + return $this->id; + } + + /** + * @param ?int $value + */ + public function setId(?int $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getModel(): ?string + { + return $this->model; + } + + /** + * @param ?value-of $value + */ + public function setModel(?string $value = null): self + { + $this->model = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getFullName(): ?string + { + return $this->fullName; + } + + /** + * @param ?string $value + */ + public function setFullName(?string $value = null): self + { + $this->fullName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLabel(): ?string + { + return $this->label; + } + + /** + * @param ?string $value + */ + public function setLabel(?string $value = null): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getDataType(): ?string + { + return $this->dataType; + } + + /** + * @param ?value-of $value + */ + public function setDataType(?string $value = null): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?array + */ + public function getOptions(): ?array + { + return $this->options; + } + + /** + * @param ?array $value + */ + public function setOptions(?array $value = null): self + { + $this->options = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getApiWritable(): ?bool + { + return $this->apiWritable; + } + + /** + * @param ?bool $value + */ + public function setApiWritable(?bool $value = null): self + { + $this->apiWritable = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMessengerWritable(): ?bool + { + return $this->messengerWritable; + } + + /** + * @param ?bool $value + */ + public function setMessengerWritable(?bool $value = null): self + { + $this->messengerWritable = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUiWritable(): ?bool + { + return $this->uiWritable; + } + + /** + * @param ?bool $value + */ + public function setUiWritable(?bool $value = null): self + { + $this->uiWritable = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getCustom(): ?bool + { + return $this->custom; + } + + /** + * @param ?bool $value + */ + public function setCustom(?bool $value = null): self + { + $this->custom = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataAttributes/Types/DataAttributeDataType.php b/src/Unstable/DataAttributes/Types/DataAttributeDataType.php new file mode 100644 index 00000000..e15499d3 --- /dev/null +++ b/src/Unstable/DataAttributes/Types/DataAttributeDataType.php @@ -0,0 +1,12 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * + * > 🚧 + * > + * > Please note that you can only 'list' events that are less than 90 days old. Event counts and summaries will still include your events older than 90 days but you cannot 'list' these events individually if they are older than 90 days + * + * The events belonging to a customer can be listed by sending a GET request to `https://api.intercom.io/events` with a user or lead identifier along with a `type` parameter. The identifier parameter can be one of `user_id`, `email` or `intercom_user_id`. The `type` parameter value must be `user`. + * + * - `https://api.intercom.io/events?type=user&user_id={user_id}` + * - `https://api.intercom.io/events?type=user&email={email}` + * - `https://api.intercom.io/events?type=user&intercom_user_id={id}` (this call can be used to list leads) + * + * The `email` parameter value should be [url encoded](http://en.wikipedia.org/wiki/Percent-encoding) when sending. + * + * You can optionally define the result page size as well with the `per_page` parameter. + * + * @param LisDataEventsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataEventSummary + * @throws IntercomException + * @throws IntercomApiException + */ + public function lisDataEvents(LisDataEventsRequest $request, ?array $options = null): DataEventSummary + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['filter'] = JsonSerializer::serializeUnion($request->getFilter(), new Union(LisDataEventsRequestFilterUserId::class, LisDataEventsRequestFilterIntercomUserId::class, LisDataEventsRequestFilterEmail::class)); + $query['type'] = $request->getType(); + if ($request->getSummary() != null) { + $query['summary'] = $request->getSummary(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "events", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataEventSummary::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * + * You will need an Access Token that has write permissions to send Events. Once you have a key you can submit events via POST to the Events resource, which is located at https://api.intercom.io/events, or you can send events using one of the client libraries. When working with the HTTP API directly a client should send the event with a `Content-Type` of `application/json`. + * + * When using the JavaScript API, [adding the code to your app](http://docs.intercom.io/configuring-Intercom/tracking-user-events-in-your-app) makes the Events API available. Once added, you can submit an event using the `trackEvent` method. This will associate the event with the Lead or currently logged-in user or logged-out visitor/lead and send it to Intercom. The final parameter is a map that can be used to send optional metadata about the event. + * + * With the Ruby client you pass a hash describing the event to `Intercom::Event.create`, or call the `track_user` method directly on the current user object (e.g. `user.track_event`). + * + * **NB: For the JSON object types, please note that we do not currently support nested JSON structure.** + * + * | Type | Description | Example | + * | :-------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- | + * | String | The value is a JSON String | `"source":"desktop"` | + * | Number | The value is a JSON Number | `"load": 3.67` | + * | Date | The key ends with the String `_date` and the value is a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time), assumed to be in the [UTC](http://en.wikipedia.org/wiki/Coordinated_Universal_Time) timezone. | `"contact_date": 1392036272` | + * | Link | The value is a HTTP or HTTPS URI. | `"article": "https://example.org/ab1de.html"` | + * | Rich Link | The value is a JSON object that contains `url` and `value` keys. | `"article": {"url": "https://example.org/ab1de.html", "value":"the dude abides"}` | + * | Monetary Amount | The value is a JSON object that contains `amount` and `currency` keys. The `amount` key is a positive integer representing the amount in cents. The price in the example to the right denotes €349.99. | `"price": {"amount": 34999, "currency": "eur"}` | + * + * **Lead Events** + * + * When submitting events for Leads, you will need to specify the Lead's `id`. + * + * **Metadata behaviour** + * + * - We currently limit the number of tracked metadata keys to 10 per event. Once the quota is reached, we ignore any further keys we receive. The first 10 metadata keys are determined by the order in which they are sent in with the event. + * - It is not possible to change the metadata keys once the event has been sent. A new event will need to be created with the new keys and you can archive the old one. + * - There might be up to 24 hrs delay when you send a new metadata for an existing event. + * + * **Event de-duplication** + * + * The API may detect and ignore duplicate events. Each event is uniquely identified as a combination of the following data - the Workspace identifier, the Contact external identifier, the Data Event name and the Data Event created time. As a result, it is **strongly recommended** to send a second granularity Unix timestamp in the `created_at` field. + * + * Duplicated events are responded to using the normal `202 Accepted` code - an error is not thrown, however repeat requests will be counted against any rate limit that is in place. + * + * ### HTTP API Responses + * + * - Successful responses to submitted events return `202 Accepted` with an empty body. + * - Unauthorised access will be rejected with a `401 Unauthorized` or `403 Forbidden` response code. + * - Events sent about users that cannot be found will return a `404 Not Found`. + * - Event lists containing duplicate events will have those duplicates ignored. + * - Server errors will return a `500` response code and may contain an error message in the body. + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function createDataEvent(mixed $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "events", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Create event summaries for a user. Event summaries are used to track the number of times an event has occurred, the first time it occurred and the last time it occurred. + * + * @param CreateDataEventSummariesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function dataEventSummaries(CreateDataEventSummariesRequest $request = new CreateDataEventSummariesRequest(), ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "events/summaries", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/DataEvents/Requests/CreateDataEventSummariesRequest.php b/src/Unstable/DataEvents/Requests/CreateDataEventSummariesRequest.php new file mode 100644 index 00000000..847f5c47 --- /dev/null +++ b/src/Unstable/DataEvents/Requests/CreateDataEventSummariesRequest.php @@ -0,0 +1,69 @@ +userId = $values['userId'] ?? null; + $this->eventSummaries = $values['eventSummaries'] ?? null; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?CreateDataEventSummariesRequestEventSummaries + */ + public function getEventSummaries(): ?CreateDataEventSummariesRequestEventSummaries + { + return $this->eventSummaries; + } + + /** + * @param ?CreateDataEventSummariesRequestEventSummaries $value + */ + public function setEventSummaries(?CreateDataEventSummariesRequestEventSummaries $value = null): self + { + $this->eventSummaries = $value; + return $this; + } +} diff --git a/src/Unstable/DataEvents/Requests/LisDataEventsRequest.php b/src/Unstable/DataEvents/Requests/LisDataEventsRequest.php new file mode 100644 index 00000000..24ab1a72 --- /dev/null +++ b/src/Unstable/DataEvents/Requests/LisDataEventsRequest.php @@ -0,0 +1,108 @@ +filter = $values['filter']; + $this->type = $values['type']; + $this->summary = $values['summary'] ?? null; + } + + /** + * @return ( + * LisDataEventsRequestFilterUserId + * |LisDataEventsRequestFilterIntercomUserId + * |LisDataEventsRequestFilterEmail + * ) + */ + public function getFilter(): LisDataEventsRequestFilterUserId|LisDataEventsRequestFilterIntercomUserId|LisDataEventsRequestFilterEmail + { + return $this->filter; + } + + /** + * @param ( + * LisDataEventsRequestFilterUserId + * |LisDataEventsRequestFilterIntercomUserId + * |LisDataEventsRequestFilterEmail + * ) $value + */ + public function setFilter(LisDataEventsRequestFilterUserId|LisDataEventsRequestFilterIntercomUserId|LisDataEventsRequestFilterEmail $value): self + { + $this->filter = $value; + return $this; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getSummary(): ?bool + { + return $this->summary; + } + + /** + * @param ?bool $value + */ + public function setSummary(?bool $value = null): self + { + $this->summary = $value; + return $this; + } +} diff --git a/src/Unstable/DataEvents/Types/CreateDataEventSummariesRequestEventSummaries.php b/src/Unstable/DataEvents/Types/CreateDataEventSummariesRequestEventSummaries.php new file mode 100644 index 00000000..9fb493fc --- /dev/null +++ b/src/Unstable/DataEvents/Types/CreateDataEventSummariesRequestEventSummaries.php @@ -0,0 +1,129 @@ +eventName = $values['eventName'] ?? null; + $this->count = $values['count'] ?? null; + $this->first = $values['first'] ?? null; + $this->last = $values['last'] ?? null; + } + + /** + * @return ?string + */ + public function getEventName(): ?string + { + return $this->eventName; + } + + /** + * @param ?string $value + */ + public function setEventName(?string $value = null): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCount(): ?int + { + return $this->count; + } + + /** + * @param ?int $value + */ + public function setCount(?int $value = null): self + { + $this->count = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirst(): ?int + { + return $this->first; + } + + /** + * @param ?int $value + */ + public function setFirst(?int $value = null): self + { + $this->first = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLast(): ?int + { + return $this->last; + } + + /** + * @param ?int $value + */ + public function setLast(?int $value = null): self + { + $this->last = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataEvents/Types/DataEvent.php b/src/Unstable/DataEvents/Types/DataEvent.php new file mode 100644 index 00000000..bfbab4fc --- /dev/null +++ b/src/Unstable/DataEvents/Types/DataEvent.php @@ -0,0 +1,230 @@ + $metadata Optional metadata about the event. + */ + #[JsonProperty('metadata'), ArrayType(['string' => 'string'])] + private ?array $metadata; + + /** + * @param array{ + * eventName: string, + * createdAt: int, + * type?: ?'event', + * userId?: ?string, + * id?: ?string, + * intercomUserId?: ?string, + * email?: ?string, + * metadata?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->eventName = $values['eventName']; + $this->createdAt = $values['createdAt']; + $this->userId = $values['userId'] ?? null; + $this->id = $values['id'] ?? null; + $this->intercomUserId = $values['intercomUserId'] ?? null; + $this->email = $values['email'] ?? null; + $this->metadata = $values['metadata'] ?? null; + } + + /** + * @return ?'event' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'event' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getEventName(): string + { + return $this->eventName; + } + + /** + * @param string $value + */ + public function setEventName(string $value): self + { + $this->eventName = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIntercomUserId(): ?string + { + return $this->intercomUserId; + } + + /** + * @param ?string $value + */ + public function setIntercomUserId(?string $value = null): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?array + */ + public function getMetadata(): ?array + { + return $this->metadata; + } + + /** + * @param ?array $value + */ + public function setMetadata(?array $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterEmail.php b/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterEmail.php new file mode 100644 index 00000000..b4f44052 --- /dev/null +++ b/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterEmail.php @@ -0,0 +1,51 @@ +email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterIntercomUserId.php b/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterIntercomUserId.php new file mode 100644 index 00000000..11eb532b --- /dev/null +++ b/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterIntercomUserId.php @@ -0,0 +1,51 @@ +intercomUserId = $values['intercomUserId']; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterUserId.php b/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterUserId.php new file mode 100644 index 00000000..61ca526d --- /dev/null +++ b/src/Unstable/DataEvents/Types/LisDataEventsRequestFilterUserId.php @@ -0,0 +1,51 @@ +userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataExport/DataExportClient.php b/src/Unstable/DataExport/DataExportClient.php new file mode 100644 index 00000000..4085bcec --- /dev/null +++ b/src/Unstable/DataExport/DataExportClient.php @@ -0,0 +1,297 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * To create your export job, you need to send a `POST` request to the export endpoint `https://api.intercom.io/export/content/data`. + * + * The only parameters you need to provide are the range of dates that you want exported. + * + * >🚧 Limit of one active job + * > + * > You can only have one active job per workspace. You will receive a HTTP status code of 429 with the message Exceeded rate limit of 1 pending message data export jobs if you attempt to create a second concurrent job. + * + * >❗️ Updated_at not included + * > + * > It should be noted that the timeframe only includes messages sent during the time period and not messages that were only updated during this period. For example, if a message was updated yesterday but sent two days ago, you would need to set the created_at_after date before the message was sent to include that in your retrieval job. + * + * >📘 Date ranges are inclusive + * > + * > Requesting data for 2018-06-01 until 2018-06-30 will get all data for those days including those specified - e.g. 2018-06-01 00:00:00 until 2018-06-30 23:59:99. + * + * @param CreateDataExportsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataExport + * @throws IntercomException + * @throws IntercomApiException + */ + public function createDataExport(CreateDataExportsRequest $request, ?array $options = null): DataExport + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/content/data", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataExport::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can view the status of your job by sending a `GET` request to the URL + * `https://api.intercom.io/export/content/data/{job_identifier}` - the `{job_identifier}` is the value returned in the response when you first created the export job. More on it can be seen in the Export Job Model. + * + * > 🚧 Jobs expire after two days + * > All jobs that have completed processing (and are thus available to download from the provided URL) will have an expiry limit of two days from when the export ob completed. After this, the data will no longer be available. + * + * @param GetDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataExport + * @throws IntercomException + * @throws IntercomApiException + */ + public function getDataExport(GetDataExportRequest $request, ?array $options = null): DataExport + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/content/data/{$request->getJobIdentifier()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataExport::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can cancel your job + * + * @param CancelDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DataExport + * @throws IntercomException + * @throws IntercomApiException + */ + public function cancelDataExport(CancelDataExportRequest $request, ?array $options = null): DataExport + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/cancel/{$request->getJobIdentifier()}", + method: HttpMethod::POST, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DataExport::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * When a job has a status of complete, and thus a filled download_url, you can download your data by hitting that provided URL, formatted like so: https://api.intercom.io/download/content/data/xyz1234. + * + * Your exported message data will be streamed continuously back down to you in a gzipped CSV format. + * + * > 📘 Octet header required + * > + * > You will have to specify the header Accept: `application/octet-stream` when hitting this endpoint. + * + * @param DownloadDataExportRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function downloadDataExport(DownloadDataExportRequest $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "download/content/data/{$request->getJobIdentifier()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/DataExport/Requests/CancelDataExportRequest.php b/src/Unstable/DataExport/Requests/CancelDataExportRequest.php new file mode 100644 index 00000000..18d8b0c8 --- /dev/null +++ b/src/Unstable/DataExport/Requests/CancelDataExportRequest.php @@ -0,0 +1,41 @@ +jobIdentifier = $values['jobIdentifier']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } +} diff --git a/src/Unstable/DataExport/Requests/CreateDataExportsRequest.php b/src/Unstable/DataExport/Requests/CreateDataExportsRequest.php new file mode 100644 index 00000000..51427ef4 --- /dev/null +++ b/src/Unstable/DataExport/Requests/CreateDataExportsRequest.php @@ -0,0 +1,68 @@ +createdAtAfter = $values['createdAtAfter']; + $this->createdAtBefore = $values['createdAtBefore']; + } + + /** + * @return int + */ + public function getCreatedAtAfter(): int + { + return $this->createdAtAfter; + } + + /** + * @param int $value + */ + public function setCreatedAtAfter(int $value): self + { + $this->createdAtAfter = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAtBefore(): int + { + return $this->createdAtBefore; + } + + /** + * @param int $value + */ + public function setCreatedAtBefore(int $value): self + { + $this->createdAtBefore = $value; + return $this; + } +} diff --git a/src/Unstable/DataExport/Requests/DownloadDataExportRequest.php b/src/Unstable/DataExport/Requests/DownloadDataExportRequest.php new file mode 100644 index 00000000..e5e8f72d --- /dev/null +++ b/src/Unstable/DataExport/Requests/DownloadDataExportRequest.php @@ -0,0 +1,41 @@ +jobIdentifier = $values['jobIdentifier']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } +} diff --git a/src/Unstable/DataExport/Requests/GetDataExportRequest.php b/src/Unstable/DataExport/Requests/GetDataExportRequest.php new file mode 100644 index 00000000..5e8ca277 --- /dev/null +++ b/src/Unstable/DataExport/Requests/GetDataExportRequest.php @@ -0,0 +1,41 @@ +jobIdentifier = $values['jobIdentifier']; + } + + /** + * @return string + */ + public function getJobIdentifier(): string + { + return $this->jobIdentifier; + } + + /** + * @param string $value + */ + public function setJobIdentifier(string $value): self + { + $this->jobIdentifier = $value; + return $this; + } +} diff --git a/src/Unstable/DataExport/Types/DataExport.php b/src/Unstable/DataExport/Types/DataExport.php new file mode 100644 index 00000000..faa5bbe7 --- /dev/null +++ b/src/Unstable/DataExport/Types/DataExport.php @@ -0,0 +1,129 @@ + $status The current state of your job. + */ + #[JsonProperty('status')] + private ?string $status; + + /** + * @var ?string $downloadExpiresAt The time after which you will not be able to access the data. + */ + #[JsonProperty('download_expires_at')] + private ?string $downloadExpiresAt; + + /** + * @var ?string $downloadUrl The location where you can download your data. + */ + #[JsonProperty('download_url')] + private ?string $downloadUrl; + + /** + * @param array{ + * jobIdentfier?: ?string, + * status?: ?value-of, + * downloadExpiresAt?: ?string, + * downloadUrl?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->jobIdentfier = $values['jobIdentfier'] ?? null; + $this->status = $values['status'] ?? null; + $this->downloadExpiresAt = $values['downloadExpiresAt'] ?? null; + $this->downloadUrl = $values['downloadUrl'] ?? null; + } + + /** + * @return ?string + */ + public function getJobIdentfier(): ?string + { + return $this->jobIdentfier; + } + + /** + * @param ?string $value + */ + public function setJobIdentfier(?string $value = null): self + { + $this->jobIdentfier = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getStatus(): ?string + { + return $this->status; + } + + /** + * @param ?value-of $value + */ + public function setStatus(?string $value = null): self + { + $this->status = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDownloadExpiresAt(): ?string + { + return $this->downloadExpiresAt; + } + + /** + * @param ?string $value + */ + public function setDownloadExpiresAt(?string $value = null): self + { + $this->downloadExpiresAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDownloadUrl(): ?string + { + return $this->downloadUrl; + } + + /** + * @param ?string $value + */ + public function setDownloadUrl(?string $value = null): self + { + $this->downloadUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/DataExport/Types/DataExportStatus.php b/src/Unstable/DataExport/Types/DataExportStatus.php new file mode 100644 index 00000000..4158b082 --- /dev/null +++ b/src/Unstable/DataExport/Types/DataExportStatus.php @@ -0,0 +1,13 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * @param PostExportReportingDataEnqueueRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PostExportReportingDataEnqueueResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function enqueueANewReportingDataExportJob(PostExportReportingDataEnqueueRequest $request, ?array $options = null): PostExportReportingDataEnqueueResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/reporting_data/enqueue", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PostExportReportingDataEnqueueResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return GetExportReportingDataGetDatasetsResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAvailableDatasetsAndAttributes(?array $options = null): GetExportReportingDataGetDatasetsResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "export/reporting_data/get_datasets", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return GetExportReportingDataGetDatasetsResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Export/Requests/PostExportReportingDataEnqueueRequest.php b/src/Unstable/Export/Requests/PostExportReportingDataEnqueueRequest.php new file mode 100644 index 00000000..7c397d22 --- /dev/null +++ b/src/Unstable/Export/Requests/PostExportReportingDataEnqueueRequest.php @@ -0,0 +1,119 @@ + $attributeIds + */ + #[JsonProperty('attribute_ids'), ArrayType(['string'])] + private array $attributeIds; + + /** + * @var int $startTime + */ + #[JsonProperty('start_time')] + private int $startTime; + + /** + * @var int $endTime + */ + #[JsonProperty('end_time')] + private int $endTime; + + /** + * @param array{ + * datasetId: string, + * attributeIds: array, + * startTime: int, + * endTime: int, + * } $values + */ + public function __construct( + array $values, + ) { + $this->datasetId = $values['datasetId']; + $this->attributeIds = $values['attributeIds']; + $this->startTime = $values['startTime']; + $this->endTime = $values['endTime']; + } + + /** + * @return string + */ + public function getDatasetId(): string + { + return $this->datasetId; + } + + /** + * @param string $value + */ + public function setDatasetId(string $value): self + { + $this->datasetId = $value; + return $this; + } + + /** + * @return array + */ + public function getAttributeIds(): array + { + return $this->attributeIds; + } + + /** + * @param array $value + */ + public function setAttributeIds(array $value): self + { + $this->attributeIds = $value; + return $this; + } + + /** + * @return int + */ + public function getStartTime(): int + { + return $this->startTime; + } + + /** + * @param int $value + */ + public function setStartTime(int $value): self + { + $this->startTime = $value; + return $this; + } + + /** + * @return int + */ + public function getEndTime(): int + { + return $this->endTime; + } + + /** + * @param int $value + */ + public function setEndTime(int $value): self + { + $this->endTime = $value; + return $this; + } +} diff --git a/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponse.php b/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponse.php new file mode 100644 index 00000000..78852f3e --- /dev/null +++ b/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponse.php @@ -0,0 +1,77 @@ + $data + */ + #[JsonProperty('data'), ArrayType([GetExportReportingDataGetDatasetsResponseDataItem::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?string, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponseDataItem.php b/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponseDataItem.php new file mode 100644 index 00000000..13e00325 --- /dev/null +++ b/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponseDataItem.php @@ -0,0 +1,152 @@ + $attributes + */ + #[JsonProperty('attributes'), ArrayType([GetExportReportingDataGetDatasetsResponseDataItemAttributesItem::class])] + private ?array $attributes; + + /** + * @param array{ + * id?: ?string, + * name?: ?string, + * description?: ?string, + * defaultTimeAttributeId?: ?string, + * attributes?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->defaultTimeAttributeId = $values['defaultTimeAttributeId'] ?? null; + $this->attributes = $values['attributes'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultTimeAttributeId(): ?string + { + return $this->defaultTimeAttributeId; + } + + /** + * @param ?string $value + */ + public function setDefaultTimeAttributeId(?string $value = null): self + { + $this->defaultTimeAttributeId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttributes(): ?array + { + return $this->attributes; + } + + /** + * @param ?array $value + */ + public function setAttributes(?array $value = null): self + { + $this->attributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponseDataItemAttributesItem.php b/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponseDataItemAttributesItem.php new file mode 100644 index 00000000..e66fe571 --- /dev/null +++ b/src/Unstable/Export/Types/GetExportReportingDataGetDatasetsResponseDataItemAttributesItem.php @@ -0,0 +1,76 @@ +id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Export/Types/PostExportReportingDataEnqueueResponse.php b/src/Unstable/Export/Types/PostExportReportingDataEnqueueResponse.php new file mode 100644 index 00000000..0fa4e999 --- /dev/null +++ b/src/Unstable/Export/Types/PostExportReportingDataEnqueueResponse.php @@ -0,0 +1,126 @@ +jobIdentifier = $values['jobIdentifier'] ?? null; + $this->status = $values['status'] ?? null; + $this->downloadUrl = $values['downloadUrl'] ?? null; + $this->downloadExpiresAt = $values['downloadExpiresAt'] ?? null; + } + + /** + * @return ?string + */ + public function getJobIdentifier(): ?string + { + return $this->jobIdentifier; + } + + /** + * @param ?string $value + */ + public function setJobIdentifier(?string $value = null): self + { + $this->jobIdentifier = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStatus(): ?string + { + return $this->status; + } + + /** + * @param ?string $value + */ + public function setStatus(?string $value = null): self + { + $this->status = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDownloadUrl(): ?string + { + return $this->downloadUrl; + } + + /** + * @param ?string $value + */ + public function setDownloadUrl(?string $value = null): self + { + $this->downloadUrl = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDownloadExpiresAt(): ?string + { + return $this->downloadExpiresAt; + } + + /** + * @param ?string $value + */ + public function setDownloadExpiresAt(?string $value = null): self + { + $this->downloadExpiresAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/HelpCenter/HelpCenterClient.php b/src/Unstable/HelpCenter/HelpCenterClient.php new file mode 100644 index 00000000..5608aa75 --- /dev/null +++ b/src/Unstable/HelpCenter/HelpCenterClient.php @@ -0,0 +1,448 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all collections by making a GET request to `https://api.intercom.io/help_center/collections`. + * + * Collections will be returned in descending order on the `updated_at` attribute. This means if you need to iterate through results then we'll show the most recently updated collections first. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return CollectionList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listAllCollections(?array $options = null): CollectionList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return CollectionList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new collection by making a POST request to `https://api.intercom.io/help_center/collections.` + * + * @param CreateCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Collection + * @throws IntercomException + * @throws IntercomApiException + */ + public function createCollection(CreateCollectionRequest $request, ?array $options = null): Collection + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Collection::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single collection by making a GET request to `https://api.intercom.io/help_center/collections/`. + * + * @param RetrieveCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Collection + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveCollection(RetrieveCollectionRequest $request, ?array $options = null): Collection + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Collection::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update the details of a single collection by making a PUT request to `https://api.intercom.io/collections/`. + * + * @param UpdateCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Collection + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateCollection(UpdateCollectionRequest $request, ?array $options = null): Collection + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Collection::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single collection by making a DELETE request to `https://api.intercom.io/collections/`. + * + * @param DeleteCollectionRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedCollectionObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteCollection(DeleteCollectionRequest $request, ?array $options = null): DeletedCollectionObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/collections/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedCollectionObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single Help Center by making a GET request to `https://api.intercom.io/help_center/help_center/`. + * + * @param RetrieveHelpCenterRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return HelpCenter + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveHelpCenter(RetrieveHelpCenterRequest $request, ?array $options = null): HelpCenter + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/help_centers/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return HelpCenter::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can list all Help Centers by making a GET request to `https://api.intercom.io/help_center/help_centers`. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return HelpCenterList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listHelpCenters(?array $options = null): HelpCenterList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "help_center/help_centers", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return HelpCenterList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/HelpCenter/Requests/CreateCollectionRequest.php b/src/Unstable/HelpCenter/Requests/CreateCollectionRequest.php new file mode 100644 index 00000000..e68aa027 --- /dev/null +++ b/src/Unstable/HelpCenter/Requests/CreateCollectionRequest.php @@ -0,0 +1,144 @@ +name = $values['name']; + $this->description = $values['description'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->helpCenterId = $values['helpCenterId'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?GroupTranslatedContent + */ + public function getTranslatedContent(): ?GroupTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?GroupTranslatedContent $value + */ + public function setTranslatedContent(?GroupTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHelpCenterId(): ?int + { + return $this->helpCenterId; + } + + /** + * @param ?int $value + */ + public function setHelpCenterId(?int $value = null): self + { + $this->helpCenterId = $value; + return $this; + } +} diff --git a/src/Unstable/HelpCenter/Requests/DeleteCollectionRequest.php b/src/Unstable/HelpCenter/Requests/DeleteCollectionRequest.php new file mode 100644 index 00000000..3e815ab9 --- /dev/null +++ b/src/Unstable/HelpCenter/Requests/DeleteCollectionRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/HelpCenter/Requests/RetrieveCollectionRequest.php b/src/Unstable/HelpCenter/Requests/RetrieveCollectionRequest.php new file mode 100644 index 00000000..e866c1f2 --- /dev/null +++ b/src/Unstable/HelpCenter/Requests/RetrieveCollectionRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/HelpCenter/Requests/RetrieveHelpCenterRequest.php b/src/Unstable/HelpCenter/Requests/RetrieveHelpCenterRequest.php new file mode 100644 index 00000000..85b52159 --- /dev/null +++ b/src/Unstable/HelpCenter/Requests/RetrieveHelpCenterRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/HelpCenter/Requests/UpdateCollectionRequest.php b/src/Unstable/HelpCenter/Requests/UpdateCollectionRequest.php new file mode 100644 index 00000000..d180e0fc --- /dev/null +++ b/src/Unstable/HelpCenter/Requests/UpdateCollectionRequest.php @@ -0,0 +1,143 @@ +id = $values['id']; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->parentId = $values['parentId'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?GroupTranslatedContent + */ + public function getTranslatedContent(): ?GroupTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?GroupTranslatedContent $value + */ + public function setTranslatedContent(?GroupTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } +} diff --git a/src/Unstable/HelpCenter/Types/Collection.php b/src/Unstable/HelpCenter/Types/Collection.php new file mode 100644 index 00000000..e531d38b --- /dev/null +++ b/src/Unstable/HelpCenter/Types/Collection.php @@ -0,0 +1,355 @@ +id = $values['id'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->url = $values['url'] ?? null; + $this->icon = $values['icon'] ?? null; + $this->order = $values['order'] ?? null; + $this->defaultLocale = $values['defaultLocale'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->helpCenterId = $values['helpCenterId'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param ?string $value + */ + public function setIcon(?string $value = null): self + { + $this->icon = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOrder(): ?int + { + return $this->order; + } + + /** + * @param ?int $value + */ + public function setOrder(?int $value = null): self + { + $this->order = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDefaultLocale(): ?string + { + return $this->defaultLocale; + } + + /** + * @param ?string $value + */ + public function setDefaultLocale(?string $value = null): self + { + $this->defaultLocale = $value; + return $this; + } + + /** + * @return ?GroupTranslatedContent + */ + public function getTranslatedContent(): ?GroupTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?GroupTranslatedContent $value + */ + public function setTranslatedContent(?GroupTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHelpCenterId(): ?int + { + return $this->helpCenterId; + } + + /** + * @param ?int $value + */ + public function setHelpCenterId(?int $value = null): self + { + $this->helpCenterId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/HelpCenter/Types/HelpCenter.php b/src/Unstable/HelpCenter/Types/HelpCenter.php new file mode 100644 index 00000000..bafc7ab4 --- /dev/null +++ b/src/Unstable/HelpCenter/Types/HelpCenter.php @@ -0,0 +1,204 @@ +id = $values['id'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->identifier = $values['identifier'] ?? null; + $this->websiteTurnedOn = $values['websiteTurnedOn'] ?? null; + $this->displayName = $values['displayName'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIdentifier(): ?string + { + return $this->identifier; + } + + /** + * @param ?string $value + */ + public function setIdentifier(?string $value = null): self + { + $this->identifier = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getWebsiteTurnedOn(): ?bool + { + return $this->websiteTurnedOn; + } + + /** + * @param ?bool $value + */ + public function setWebsiteTurnedOn(?bool $value = null): self + { + $this->websiteTurnedOn = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDisplayName(): ?string + { + return $this->displayName; + } + + /** + * @param ?string $value + */ + public function setDisplayName(?string $value = null): self + { + $this->displayName = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/HelpCenter/Types/HelpCenterList.php b/src/Unstable/HelpCenter/Types/HelpCenterList.php new file mode 100644 index 00000000..41e436be --- /dev/null +++ b/src/Unstable/HelpCenter/Types/HelpCenterList.php @@ -0,0 +1,80 @@ + $data An array of Help Center objects + */ + #[JsonProperty('data'), ArrayType([HelpCenter::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Jobs/JobsClient.php b/src/Unstable/Jobs/JobsClient.php new file mode 100644 index 00000000..767e6f5c --- /dev/null +++ b/src/Unstable/Jobs/JobsClient.php @@ -0,0 +1,108 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * Retrieve the status of job execution. + * + * @param JobsStatusRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Jobs + * @throws IntercomException + * @throws IntercomApiException + */ + public function status(JobsStatusRequest $request, ?array $options = null): Jobs + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "jobs/status/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Jobs::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Jobs/Requests/JobsStatusRequest.php b/src/Unstable/Jobs/Requests/JobsStatusRequest.php new file mode 100644 index 00000000..a9254ad7 --- /dev/null +++ b/src/Unstable/Jobs/Requests/JobsStatusRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Jobs/Types/Jobs.php b/src/Unstable/Jobs/Types/Jobs.php new file mode 100644 index 00000000..33def70e --- /dev/null +++ b/src/Unstable/Jobs/Types/Jobs.php @@ -0,0 +1,204 @@ + $status The status of the job execution. + */ + #[JsonProperty('status')] + private ?string $status; + + /** + * @var ?string $resourceType The type of resource created during job execution. + */ + #[JsonProperty('resource_type')] + private ?string $resourceType; + + /** + * @var ?string $resourceId The id of the resource created during job execution (e.g. ticket id) + */ + #[JsonProperty('resource_id')] + private ?string $resourceId; + + /** + * @var ?string $resourceUrl The url of the resource created during job exeuction. Use this url to fetch the resource. + */ + #[JsonProperty('resource_url')] + private ?string $resourceUrl; + + /** + * @param array{ + * id: string, + * type?: ?'job', + * url?: ?string, + * status?: ?value-of, + * resourceType?: ?string, + * resourceId?: ?string, + * resourceUrl?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id']; + $this->url = $values['url'] ?? null; + $this->status = $values['status'] ?? null; + $this->resourceType = $values['resourceType'] ?? null; + $this->resourceId = $values['resourceId'] ?? null; + $this->resourceUrl = $values['resourceUrl'] ?? null; + } + + /** + * @return ?'job' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'job' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getStatus(): ?string + { + return $this->status; + } + + /** + * @param ?value-of $value + */ + public function setStatus(?string $value = null): self + { + $this->status = $value; + return $this; + } + + /** + * @return ?string + */ + public function getResourceType(): ?string + { + return $this->resourceType; + } + + /** + * @param ?string $value + */ + public function setResourceType(?string $value = null): self + { + $this->resourceType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getResourceId(): ?string + { + return $this->resourceId; + } + + /** + * @param ?string $value + */ + public function setResourceId(?string $value = null): self + { + $this->resourceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getResourceUrl(): ?string + { + return $this->resourceUrl; + } + + /** + * @param ?string $value + */ + public function setResourceUrl(?string $value = null): self + { + $this->resourceUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Jobs/Types/JobsStatus.php b/src/Unstable/Jobs/Types/JobsStatus.php new file mode 100644 index 00000000..1cad0e42 --- /dev/null +++ b/src/Unstable/Jobs/Types/JobsStatus.php @@ -0,0 +1,10 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all macros (saved replies) in your workspace for use in automating responses. + * + * The macros are returned in descending order by updated_at. + * + * **Pagination** + * + * This endpoint uses cursor-based pagination via the `starting_after` parameter. The cursor is a Base64-encoded JSON array containing `[updated_at, id]` of the last item from the previous page. + * + * **Placeholder Transformation** + * + * The API transforms Intercom placeholders to a more standard XML-like format: + * - From: `{{user.name | fallback: 'there'}}` + * - To: `` + * + * @param ListMacrosRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return MacroList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listMacros(ListMacrosRequest $request = new ListMacrosRequest(), ?array $options = null): MacroList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getStartingAfter() != null) { + $query['starting_after'] = $request->getStartingAfter(); + } + if ($request->getUpdatedSince() != null) { + $query['updated_since'] = $request->getUpdatedSince(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "macros", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return MacroList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a single macro (saved reply) by its ID. The macro will only be returned if it is visible to the authenticated user based on its visibility settings. + * + * **Visibility Rules** + * + * A macro is returned based on its `visible_to` setting: + * - `everyone`: Always visible to all team members + * - `specific_teams`: Only visible if the authenticated user belongs to one of the teams specified in `visible_to_team_ids` + * + * If a macro exists but is not visible to the authenticated user, a 404 error is returned. + * + * **Placeholder Transformation** + * + * The API transforms Intercom placeholders to a more standard XML-like format in the `body` field: + * - From: `{{user.name | fallback: 'there'}}` + * - To: `` + * + * Default values in placeholders are HTML-escaped for security. + * + * @param GetMacroRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Macro + * @throws IntercomException + * @throws IntercomApiException + */ + public function getMacro(GetMacroRequest $request, ?array $options = null): ?Macro + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "macros/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Macro::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Macros/Requests/GetMacroRequest.php b/src/Unstable/Macros/Requests/GetMacroRequest.php new file mode 100644 index 00000000..c89919b6 --- /dev/null +++ b/src/Unstable/Macros/Requests/GetMacroRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Macros/Requests/ListMacrosRequest.php b/src/Unstable/Macros/Requests/ListMacrosRequest.php new file mode 100644 index 00000000..1d5a3ac5 --- /dev/null +++ b/src/Unstable/Macros/Requests/ListMacrosRequest.php @@ -0,0 +1,89 @@ +perPage = $values['perPage'] ?? null; + $this->startingAfter = $values['startingAfter'] ?? null; + $this->updatedSince = $values['updatedSince'] ?? null; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedSince(): ?int + { + return $this->updatedSince; + } + + /** + * @param ?int $value + */ + public function setUpdatedSince(?int $value = null): self + { + $this->updatedSince = $value; + return $this; + } +} diff --git a/src/Unstable/Macros/Types/Macro.php b/src/Unstable/Macros/Types/Macro.php new file mode 100644 index 00000000..53dcd59c --- /dev/null +++ b/src/Unstable/Macros/Types/Macro.php @@ -0,0 +1,282 @@ + $visibleTo Who can view this macro. + */ + #[JsonProperty('visible_to')] + private ?string $visibleTo; + + /** + * @var ?array $visibleToTeamIds The team IDs that can view this macro when visible_to is set to specific_teams. + */ + #[JsonProperty('visible_to_team_ids'), ArrayType(['string'])] + private ?array $visibleToTeamIds; + + /** + * @var ?array> $availableOn Where the macro is available for use. + */ + #[JsonProperty('available_on'), ArrayType(['string'])] + private ?array $availableOn; + + /** + * @param array{ + * type?: ?'macro', + * id?: ?string, + * name?: ?string, + * body?: ?string, + * bodyText?: ?string, + * createdAt?: ?DateTime, + * updatedAt?: ?DateTime, + * visibleTo?: ?value-of, + * visibleToTeamIds?: ?array, + * availableOn?: ?array>, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->body = $values['body'] ?? null; + $this->bodyText = $values['bodyText'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->visibleTo = $values['visibleTo'] ?? null; + $this->visibleToTeamIds = $values['visibleToTeamIds'] ?? null; + $this->availableOn = $values['availableOn'] ?? null; + } + + /** + * @return ?'macro' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'macro' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBodyText(): ?string + { + return $this->bodyText; + } + + /** + * @param ?string $value + */ + public function setBodyText(?string $value = null): self + { + $this->bodyText = $value; + return $this; + } + + /** + * @return ?DateTime + */ + public function getCreatedAt(): ?DateTime + { + return $this->createdAt; + } + + /** + * @param ?DateTime $value + */ + public function setCreatedAt(?DateTime $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?DateTime + */ + public function getUpdatedAt(): ?DateTime + { + return $this->updatedAt; + } + + /** + * @param ?DateTime $value + */ + public function setUpdatedAt(?DateTime $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getVisibleTo(): ?string + { + return $this->visibleTo; + } + + /** + * @param ?value-of $value + */ + public function setVisibleTo(?string $value = null): self + { + $this->visibleTo = $value; + return $this; + } + + /** + * @return ?array + */ + public function getVisibleToTeamIds(): ?array + { + return $this->visibleToTeamIds; + } + + /** + * @param ?array $value + */ + public function setVisibleToTeamIds(?array $value = null): self + { + $this->visibleToTeamIds = $value; + return $this; + } + + /** + * @return ?array> + */ + public function getAvailableOn(): ?array + { + return $this->availableOn; + } + + /** + * @param ?array> $value + */ + public function setAvailableOn(?array $value = null): self + { + $this->availableOn = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Macros/Types/MacroAvailableOnItem.php b/src/Unstable/Macros/Types/MacroAvailableOnItem.php new file mode 100644 index 00000000..c96893ca --- /dev/null +++ b/src/Unstable/Macros/Types/MacroAvailableOnItem.php @@ -0,0 +1,9 @@ + $data The list of macro objects + */ + #[JsonProperty('data'), ArrayType([new Union(Macro::class, 'null')])] + private ?array $data; + + /** + * @var ?MacroListPages $pages Pagination information + */ + #[JsonProperty('pages')] + private ?MacroListPages $pages; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * pages?: ?MacroListPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?MacroListPages + */ + public function getPages(): ?MacroListPages + { + return $this->pages; + } + + /** + * @param ?MacroListPages $value + */ + public function setPages(?MacroListPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Macros/Types/MacroListPages.php b/src/Unstable/Macros/Types/MacroListPages.php new file mode 100644 index 00000000..76164e57 --- /dev/null +++ b/src/Unstable/Macros/Types/MacroListPages.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->next = $values['next'] ?? null; + } + + /** + * @return ?'pages' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'pages' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?MacroListPagesNext + */ + public function getNext(): ?MacroListPagesNext + { + return $this->next; + } + + /** + * @param ?MacroListPagesNext $value + */ + public function setNext(?MacroListPagesNext $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Macros/Types/MacroListPagesNext.php b/src/Unstable/Macros/Types/MacroListPagesNext.php new file mode 100644 index 00000000..cd5e3874 --- /dev/null +++ b/src/Unstable/Macros/Types/MacroListPagesNext.php @@ -0,0 +1,54 @@ +startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Macros/Types/MacroVisibleTo.php b/src/Unstable/Macros/Types/MacroVisibleTo.php new file mode 100644 index 00000000..d14510db --- /dev/null +++ b/src/Unstable/Macros/Types/MacroVisibleTo.php @@ -0,0 +1,9 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can create a message that has been initiated by an admin. The conversation can be either an in-app message, an email, sms or whatsapp. + * + * > 🚧 Sending for visitors + * > + * > There can be a short delay between when a contact is created and when a contact becomes available to be messaged through the API. A 404 Not Found error will be returned in this case. + * + * This will return the Message model that has been created. + * + * > 🚧 Retrieving Associated Conversations + * > + * > As this is a message, there will be no conversation present until the contact responds. Once they do, you will have to search for a contact's conversations with the id of the message. + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Message + * @throws IntercomException + * @throws IntercomApiException + */ + public function createMessage(mixed $request, ?array $options = null): Message + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "messages", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Message::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Retrieves statuses of messages sent from the Outbound module. Currently, this API only supports WhatsApp messages. + * + * + * This endpoint returns paginated status events for WhatsApp messages sent via the Outbound module, providing + * information about delivery state and related message details. + * + * @param GetWhatsAppMessageStatusRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return WhatsappMessageStatusList + * @throws IntercomException + * @throws IntercomApiException + */ + public function getWhatsAppMessageStatus(GetWhatsAppMessageStatusRequest $request, ?array $options = null): WhatsappMessageStatusList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['ruleset_id'] = $request->getRulesetId(); + if ($request->getPerPage() != null) { + $query['per_page'] = $request->getPerPage(); + } + if ($request->getStartingAfter() != null) { + $query['starting_after'] = $request->getStartingAfter(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "messages/status", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return WhatsappMessageStatusList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Messages/Requests/GetWhatsAppMessageStatusRequest.php b/src/Unstable/Messages/Requests/GetWhatsAppMessageStatusRequest.php new file mode 100644 index 00000000..d06d2a28 --- /dev/null +++ b/src/Unstable/Messages/Requests/GetWhatsAppMessageStatusRequest.php @@ -0,0 +1,89 @@ +rulesetId = $values['rulesetId']; + $this->perPage = $values['perPage'] ?? null; + $this->startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return string + */ + public function getRulesetId(): string + { + return $this->rulesetId; + } + + /** + * @param string $value + */ + public function setRulesetId(string $value): self + { + $this->rulesetId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } +} diff --git a/src/Unstable/Messages/Types/Message.php b/src/Unstable/Messages/Types/Message.php new file mode 100644 index 00000000..f4f1fa04 --- /dev/null +++ b/src/Unstable/Messages/Types/Message.php @@ -0,0 +1,204 @@ + $messageType The type of message that was sent. Can be email, inapp, facebook, twitter, sms or whatsapp. + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var ?string $conversationId The associated conversation_id + */ + #[JsonProperty('conversation_id')] + private ?string $conversationId; + + /** + * @param array{ + * type: string, + * id: string, + * createdAt: int, + * body: string, + * messageType: value-of, + * subject?: ?string, + * conversationId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->createdAt = $values['createdAt']; + $this->subject = $values['subject'] ?? null; + $this->body = $values['body']; + $this->messageType = $values['messageType']; + $this->conversationId = $values['conversationId'] ?? null; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSubject(): ?string + { + return $this->subject; + } + + /** + * @param ?string $value + */ + public function setSubject(?string $value = null): self + { + $this->subject = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return value-of + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param value-of $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getConversationId(): ?string + { + return $this->conversationId; + } + + /** + * @param ?string $value + */ + public function setConversationId(?string $value = null): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Messages/Types/MessageMessageType.php b/src/Unstable/Messages/Types/MessageMessageType.php new file mode 100644 index 00000000..fcfceb55 --- /dev/null +++ b/src/Unstable/Messages/Types/MessageMessageType.php @@ -0,0 +1,13 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all news items + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function listNewsItems(?array $options = null): PaginatedResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a news item + * + * @param NewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NewsItem + * @throws IntercomException + * @throws IntercomApiException + */ + public function createNewsItem(NewsItemRequest $request, ?array $options = null): NewsItem + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NewsItem::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single news item. + * + * @param RetrieveNewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NewsItem + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveNewsItem(RetrieveNewsItemRequest $request, ?array $options = null): NewsItem + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NewsItem::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * @param UpdateNewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NewsItem + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateNewsItem(UpdateNewsItemRequest $request, ?array $options = null): NewsItem + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items/{$request->getId()}", + method: HttpMethod::PUT, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NewsItem::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a single news item. + * + * @param DeleteNewsItemRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeletedObject + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteNewsItem(DeleteNewsItemRequest $request, ?array $options = null): DeletedObject + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/news_items/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeletedObject::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all news items that are live on a given newsfeed + * + * @param ListLiveNewsfeedItemsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function listLiveNewsfeedItems(ListLiveNewsfeedItemsRequest $request, ?array $options = null): PaginatedResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/newsfeeds/{$request->getId()}/items", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all newsfeeds + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return PaginatedResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function listNewsfeeds(?array $options = null): PaginatedResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/newsfeeds", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return PaginatedResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single newsfeed + * + * @param RetrieveNewsfeedRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Newsfeed + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveNewsfeed(RetrieveNewsfeedRequest $request, ?array $options = null): Newsfeed + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "news/newsfeeds/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Newsfeed::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/News/Requests/DeleteNewsItemRequest.php b/src/Unstable/News/Requests/DeleteNewsItemRequest.php new file mode 100644 index 00000000..6c2012ad --- /dev/null +++ b/src/Unstable/News/Requests/DeleteNewsItemRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/News/Requests/ListLiveNewsfeedItemsRequest.php b/src/Unstable/News/Requests/ListLiveNewsfeedItemsRequest.php new file mode 100644 index 00000000..af36040e --- /dev/null +++ b/src/Unstable/News/Requests/ListLiveNewsfeedItemsRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/News/Requests/RetrieveNewsItemRequest.php b/src/Unstable/News/Requests/RetrieveNewsItemRequest.php new file mode 100644 index 00000000..da69e611 --- /dev/null +++ b/src/Unstable/News/Requests/RetrieveNewsItemRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/News/Requests/RetrieveNewsfeedRequest.php b/src/Unstable/News/Requests/RetrieveNewsfeedRequest.php new file mode 100644 index 00000000..3ff99160 --- /dev/null +++ b/src/Unstable/News/Requests/RetrieveNewsfeedRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/News/Requests/UpdateNewsItemRequest.php b/src/Unstable/News/Requests/UpdateNewsItemRequest.php new file mode 100644 index 00000000..da433458 --- /dev/null +++ b/src/Unstable/News/Requests/UpdateNewsItemRequest.php @@ -0,0 +1,66 @@ +id = $values['id']; + $this->body = $values['body']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return NewsItemRequest + */ + public function getBody(): NewsItemRequest + { + return $this->body; + } + + /** + * @param NewsItemRequest $value + */ + public function setBody(NewsItemRequest $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Unstable/News/Types/NewsItem.php b/src/Unstable/News/Types/NewsItem.php new file mode 100644 index 00000000..e3686fa9 --- /dev/null +++ b/src/Unstable/News/Types/NewsItem.php @@ -0,0 +1,356 @@ + $state News items will not be visible to your users in the assigned newsfeeds until they are set live. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?array $newsfeedAssignments A list of newsfeed_assignments to assign to the specified newsfeed. + */ + #[JsonProperty('newsfeed_assignments'), ArrayType([NewsfeedAssignment::class])] + private ?array $newsfeedAssignments; + + /** + * @var ?array $labels Label names displayed to users to categorize the news item. + */ + #[JsonProperty('labels'), ArrayType([new Union('string', 'null')])] + private ?array $labels; + + /** + * @var ?string $coverImageUrl URL of the image used as cover. Must have .jpg or .png extension. + */ + #[JsonProperty('cover_image_url')] + private ?string $coverImageUrl; + + /** + * @var ?array $reactions Ordered list of emoji reactions to the news item. When empty, reactions are disabled. + */ + #[JsonProperty('reactions'), ArrayType([new Union('string', 'null')])] + private ?array $reactions; + + /** + * @var ?bool $deliverSilently When set to true, the news item will appear in the messenger newsfeed without showing a notification badge. + */ + #[JsonProperty('deliver_silently')] + private ?bool $deliverSilently; + + /** + * @var ?int $createdAt Timestamp for when the news item was created. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt Timestamp for when the news item was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @param array{ + * id?: ?string, + * workspaceId?: ?string, + * title?: ?string, + * body?: ?string, + * senderId?: ?int, + * state?: ?value-of, + * newsfeedAssignments?: ?array, + * labels?: ?array, + * coverImageUrl?: ?string, + * reactions?: ?array, + * deliverSilently?: ?bool, + * createdAt?: ?int, + * updatedAt?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->id = $values['id'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->title = $values['title'] ?? null; + $this->body = $values['body'] ?? null; + $this->senderId = $values['senderId'] ?? null; + $this->state = $values['state'] ?? null; + $this->newsfeedAssignments = $values['newsfeedAssignments'] ?? null; + $this->labels = $values['labels'] ?? null; + $this->coverImageUrl = $values['coverImageUrl'] ?? null; + $this->reactions = $values['reactions'] ?? null; + $this->deliverSilently = $values['deliverSilently'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSenderId(): ?int + { + return $this->senderId; + } + + /** + * @param ?int $value + */ + public function setSenderId(?int $value = null): self + { + $this->senderId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?array + */ + public function getNewsfeedAssignments(): ?array + { + return $this->newsfeedAssignments; + } + + /** + * @param ?array $value + */ + public function setNewsfeedAssignments(?array $value = null): self + { + $this->newsfeedAssignments = $value; + return $this; + } + + /** + * @return ?array + */ + public function getLabels(): ?array + { + return $this->labels; + } + + /** + * @param ?array $value + */ + public function setLabels(?array $value = null): self + { + $this->labels = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCoverImageUrl(): ?string + { + return $this->coverImageUrl; + } + + /** + * @param ?string $value + */ + public function setCoverImageUrl(?string $value = null): self + { + $this->coverImageUrl = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReactions(): ?array + { + return $this->reactions; + } + + /** + * @param ?array $value + */ + public function setReactions(?array $value = null): self + { + $this->reactions = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeliverSilently(): ?bool + { + return $this->deliverSilently; + } + + /** + * @param ?bool $value + */ + public function setDeliverSilently(?bool $value = null): self + { + $this->deliverSilently = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/News/Types/NewsItemState.php b/src/Unstable/News/Types/NewsItemState.php new file mode 100644 index 00000000..e855e2bf --- /dev/null +++ b/src/Unstable/News/Types/NewsItemState.php @@ -0,0 +1,9 @@ +id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/News/Types/NewsfeedAssignment.php b/src/Unstable/News/Types/NewsfeedAssignment.php new file mode 100644 index 00000000..6ac17aee --- /dev/null +++ b/src/Unstable/News/Types/NewsfeedAssignment.php @@ -0,0 +1,79 @@ +newsfeedId = $values['newsfeedId'] ?? null; + $this->publishedAt = $values['publishedAt'] ?? null; + } + + /** + * @return ?int + */ + public function getNewsfeedId(): ?int + { + return $this->newsfeedId; + } + + /** + * @param ?int $value + */ + public function setNewsfeedId(?int $value = null): self + { + $this->newsfeedId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPublishedAt(): ?int + { + return $this->publishedAt; + } + + /** + * @param ?int $value + */ + public function setPublishedAt(?int $value = null): self + { + $this->publishedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Notes/NotesClient.php b/src/Unstable/Notes/NotesClient.php new file mode 100644 index 00000000..062f704b --- /dev/null +++ b/src/Unstable/Notes/NotesClient.php @@ -0,0 +1,222 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of notes that are associated to a contact. + * + * @param ListNotesRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return NoteList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listNotes(ListNotesRequest $request, ?array $options = null): NoteList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/notes", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return NoteList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can add a note to a single contact. + * + * @param CreateNoteRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Note + * @throws IntercomException + * @throws IntercomApiException + */ + public function createNote(CreateNoteRequest $request, ?array $options = null): Note + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getId()}/notes", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Note::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single note. + * + * @param RetrieveNoteRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Note + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveNote(RetrieveNoteRequest $request, ?array $options = null): Note + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "notes/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Note::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Notes/Requests/CreateNoteRequest.php b/src/Unstable/Notes/Requests/CreateNoteRequest.php new file mode 100644 index 00000000..1aa618fe --- /dev/null +++ b/src/Unstable/Notes/Requests/CreateNoteRequest.php @@ -0,0 +1,117 @@ +id = $values['id']; + $this->body = $values['body']; + $this->contactId = $values['contactId'] ?? null; + $this->adminId = $values['adminId'] ?? null; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContactId(): ?string + { + return $this->contactId; + } + + /** + * @param ?string $value + */ + public function setContactId(?string $value = null): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminId(): ?string + { + return $this->adminId; + } + + /** + * @param ?string $value + */ + public function setAdminId(?string $value = null): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Unstable/Notes/Requests/ListNotesRequest.php b/src/Unstable/Notes/Requests/ListNotesRequest.php new file mode 100644 index 00000000..57a1e026 --- /dev/null +++ b/src/Unstable/Notes/Requests/ListNotesRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Notes/Requests/RetrieveNoteRequest.php b/src/Unstable/Notes/Requests/RetrieveNoteRequest.php new file mode 100644 index 00000000..49ef9cf9 --- /dev/null +++ b/src/Unstable/Notes/Requests/RetrieveNoteRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $value + */ + public function setId(int $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Notes/Types/Note.php b/src/Unstable/Notes/Types/Note.php new file mode 100644 index 00000000..8c6573ca --- /dev/null +++ b/src/Unstable/Notes/Types/Note.php @@ -0,0 +1,180 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->contact = $values['contact'] ?? null; + $this->author = $values['author'] ?? null; + $this->body = $values['body'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?NoteContact + */ + public function getContact(): ?NoteContact + { + return $this->contact; + } + + /** + * @param ?NoteContact $value + */ + public function setContact(?NoteContact $value = null): self + { + $this->contact = $value; + return $this; + } + + /** + * @return ?Admin + */ + public function getAuthor(): ?Admin + { + return $this->author; + } + + /** + * @param ?Admin $value + */ + public function setAuthor(?Admin $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Notes/Types/NoteContact.php b/src/Unstable/Notes/Types/NoteContact.php new file mode 100644 index 00000000..7c8c3f4f --- /dev/null +++ b/src/Unstable/Notes/Types/NoteContact.php @@ -0,0 +1,79 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Segments/Requests/ListSegmentsRequest.php b/src/Unstable/Segments/Requests/ListSegmentsRequest.php new file mode 100644 index 00000000..af088e3a --- /dev/null +++ b/src/Unstable/Segments/Requests/ListSegmentsRequest.php @@ -0,0 +1,41 @@ +includeCount = $values['includeCount'] ?? null; + } + + /** + * @return ?bool + */ + public function getIncludeCount(): ?bool + { + return $this->includeCount; + } + + /** + * @param ?bool $value + */ + public function setIncludeCount(?bool $value = null): self + { + $this->includeCount = $value; + return $this; + } +} diff --git a/src/Unstable/Segments/Requests/RetrieveSegmentRequest.php b/src/Unstable/Segments/Requests/RetrieveSegmentRequest.php new file mode 100644 index 00000000..0fc49ce0 --- /dev/null +++ b/src/Unstable/Segments/Requests/RetrieveSegmentRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Segments/SegmentsClient.php b/src/Unstable/Segments/SegmentsClient.php new file mode 100644 index 00000000..125b7514 --- /dev/null +++ b/src/Unstable/Segments/SegmentsClient.php @@ -0,0 +1,170 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch a list of all segments. + * + * @param ListSegmentsRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SegmentList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listSegments(ListSegmentsRequest $request = new ListSegmentsRequest(), ?array $options = null): SegmentList + { + $options = array_merge($this->options, $options ?? []); + $query = []; + if ($request->getIncludeCount() != null) { + $query['include_count'] = $request->getIncludeCount(); + } + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "segments", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SegmentList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single segment. + * + * @param RetrieveSegmentRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Segment + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveSegment(RetrieveSegmentRequest $request, ?array $options = null): Segment + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "segments/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Segment::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Segments/Types/Segment.php b/src/Unstable/Segments/Types/Segment.php new file mode 100644 index 00000000..b753be40 --- /dev/null +++ b/src/Unstable/Segments/Types/Segment.php @@ -0,0 +1,204 @@ + $personType Type of the contact: contact (lead) or user. + */ + #[JsonProperty('person_type')] + private ?string $personType; + + /** + * @var ?int $count The number of items in the user segment. It's returned when `include_count=true` is included in the request. + */ + #[JsonProperty('count')] + private ?int $count; + + /** + * @param array{ + * type?: ?'segment', + * id?: ?string, + * name?: ?string, + * createdAt?: ?int, + * updatedAt?: ?int, + * personType?: ?value-of, + * count?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->personType = $values['personType'] ?? null; + $this->count = $values['count'] ?? null; + } + + /** + * @return ?'segment' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'segment' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getPersonType(): ?string + { + return $this->personType; + } + + /** + * @param ?value-of $value + */ + public function setPersonType(?string $value = null): self + { + $this->personType = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCount(): ?int + { + return $this->count; + } + + /** + * @param ?int $value + */ + public function setCount(?int $value = null): self + { + $this->count = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Segments/Types/SegmentPersonType.php b/src/Unstable/Segments/Types/SegmentPersonType.php new file mode 100644 index 00000000..59599948 --- /dev/null +++ b/src/Unstable/Segments/Types/SegmentPersonType.php @@ -0,0 +1,9 @@ +contactId = $values['contactId']; + $this->id = $values['id']; + $this->consentType = $values['consentType']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getConsentType(): string + { + return $this->consentType; + } + + /** + * @param string $value + */ + public function setConsentType(string $value): self + { + $this->consentType = $value; + return $this; + } +} diff --git a/src/Unstable/SubscriptionTypes/Requests/DetachSubscriptionTypeToContactRequest.php b/src/Unstable/SubscriptionTypes/Requests/DetachSubscriptionTypeToContactRequest.php new file mode 100644 index 00000000..4b01e997 --- /dev/null +++ b/src/Unstable/SubscriptionTypes/Requests/DetachSubscriptionTypeToContactRequest.php @@ -0,0 +1,65 @@ +contactId = $values['contactId']; + $this->id = $values['id']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/SubscriptionTypes/SubscriptionTypesClient.php b/src/Unstable/SubscriptionTypes/SubscriptionTypesClient.php new file mode 100644 index 00000000..fd15aa68 --- /dev/null +++ b/src/Unstable/SubscriptionTypes/SubscriptionTypesClient.php @@ -0,0 +1,226 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can add a specific subscription to a contact. In Intercom, we have two different subscription types based on user consent - opt-out and opt-in: + * + * 1.Attaching a contact to an opt-out subscription type will opt that user out from receiving messages related to that subscription type. + * + * 2.Attaching a contact to an opt-in subscription type will opt that user in to receiving messages related to that subscription type. + * + * This will return a subscription type model for the subscription type that was added to the contact. + * + * @param AttachSubscriptionTypeToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionType + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachSubscriptionTypeToContact(AttachSubscriptionTypeToContactRequest $request, ?array $options = null): SubscriptionType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/subscriptions", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove a specific subscription from a contact. This will return a subscription type model for the subscription type that was removed from the contact. + * + * @param DetachSubscriptionTypeToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionType + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachSubscriptionTypeToContact(DetachSubscriptionTypeToContactRequest $request, ?array $options = null): SubscriptionType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/subscriptions/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can list all subscription types. A list of subscription type objects will be returned. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return SubscriptionTypeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listSubscriptionTypes(?array $options = null): SubscriptionTypeList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "subscription_types", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return SubscriptionTypeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/SubscriptionTypes/Types/SubscriptionType.php b/src/Unstable/SubscriptionTypes/Types/SubscriptionType.php new file mode 100644 index 00000000..423e7c81 --- /dev/null +++ b/src/Unstable/SubscriptionTypes/Types/SubscriptionType.php @@ -0,0 +1,206 @@ + $state The state of the subscription type. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?Translation $defaultTranslation + */ + #[JsonProperty('default_translation')] + private ?Translation $defaultTranslation; + + /** + * @var ?array $translations An array of translations objects with the localised version of the subscription type in each available locale within your translation settings. + */ + #[JsonProperty('translations'), ArrayType([Translation::class])] + private ?array $translations; + + /** + * @var ?value-of $consentType Describes the type of consent. + */ + #[JsonProperty('consent_type')] + private ?string $consentType; + + /** + * @var ?array> $contentTypes The message types that this subscription supports - can contain `email` or `sms_message`. + */ + #[JsonProperty('content_types'), ArrayType(['string'])] + private ?array $contentTypes; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * state?: ?value-of, + * defaultTranslation?: ?Translation, + * translations?: ?array, + * consentType?: ?value-of, + * contentTypes?: ?array>, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->state = $values['state'] ?? null; + $this->defaultTranslation = $values['defaultTranslation'] ?? null; + $this->translations = $values['translations'] ?? null; + $this->consentType = $values['consentType'] ?? null; + $this->contentTypes = $values['contentTypes'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?Translation + */ + public function getDefaultTranslation(): ?Translation + { + return $this->defaultTranslation; + } + + /** + * @param ?Translation $value + */ + public function setDefaultTranslation(?Translation $value = null): self + { + $this->defaultTranslation = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTranslations(): ?array + { + return $this->translations; + } + + /** + * @param ?array $value + */ + public function setTranslations(?array $value = null): self + { + $this->translations = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getConsentType(): ?string + { + return $this->consentType; + } + + /** + * @param ?value-of $value + */ + public function setConsentType(?string $value = null): self + { + $this->consentType = $value; + return $this; + } + + /** + * @return ?array> + */ + public function getContentTypes(): ?array + { + return $this->contentTypes; + } + + /** + * @param ?array> $value + */ + public function setContentTypes(?array $value = null): self + { + $this->contentTypes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/SubscriptionTypes/Types/SubscriptionTypeConsentType.php b/src/Unstable/SubscriptionTypes/Types/SubscriptionTypeConsentType.php new file mode 100644 index 00000000..e6d351f4 --- /dev/null +++ b/src/Unstable/SubscriptionTypes/Types/SubscriptionTypeConsentType.php @@ -0,0 +1,9 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can use the API to deflect phone calls to the Intercom Messenger. + * Calling this endpoint will send an SMS with a link to the Messenger to the phone number specified. + * + * If custom attributes are specified, they will be added to the user or lead's custom data attributes. + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?PhoneSwitch + * @throws IntercomException + * @throws IntercomApiException + */ + public function createPhoneSwitch(mixed $request, ?array $options = null): ?PhoneSwitch + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "phone_call_redirects", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return PhoneSwitch::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Tags/Requests/AttachTagToContactRequest.php b/src/Unstable/Tags/Requests/AttachTagToContactRequest.php new file mode 100644 index 00000000..ab56c1b5 --- /dev/null +++ b/src/Unstable/Tags/Requests/AttachTagToContactRequest.php @@ -0,0 +1,67 @@ +contactId = $values['contactId']; + $this->id = $values['id']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/AttachTagToConversationRequest.php b/src/Unstable/Tags/Requests/AttachTagToConversationRequest.php new file mode 100644 index 00000000..aef6f82e --- /dev/null +++ b/src/Unstable/Tags/Requests/AttachTagToConversationRequest.php @@ -0,0 +1,92 @@ +conversationId = $values['conversationId']; + $this->id = $values['id']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/AttachTagToTicketRequest.php b/src/Unstable/Tags/Requests/AttachTagToTicketRequest.php new file mode 100644 index 00000000..6e852b6a --- /dev/null +++ b/src/Unstable/Tags/Requests/AttachTagToTicketRequest.php @@ -0,0 +1,92 @@ +ticketId = $values['ticketId']; + $this->id = $values['id']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/DeleteTagRequest.php b/src/Unstable/Tags/Requests/DeleteTagRequest.php new file mode 100644 index 00000000..a80b46a1 --- /dev/null +++ b/src/Unstable/Tags/Requests/DeleteTagRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/DetachTagFromContactRequest.php b/src/Unstable/Tags/Requests/DetachTagFromContactRequest.php new file mode 100644 index 00000000..a4ed44ee --- /dev/null +++ b/src/Unstable/Tags/Requests/DetachTagFromContactRequest.php @@ -0,0 +1,65 @@ +contactId = $values['contactId']; + $this->id = $values['id']; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/DetachTagFromConversationRequest.php b/src/Unstable/Tags/Requests/DetachTagFromConversationRequest.php new file mode 100644 index 00000000..e907cce6 --- /dev/null +++ b/src/Unstable/Tags/Requests/DetachTagFromConversationRequest.php @@ -0,0 +1,91 @@ +conversationId = $values['conversationId']; + $this->id = $values['id']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/DetachTagFromTicketRequest.php b/src/Unstable/Tags/Requests/DetachTagFromTicketRequest.php new file mode 100644 index 00000000..bb5941d7 --- /dev/null +++ b/src/Unstable/Tags/Requests/DetachTagFromTicketRequest.php @@ -0,0 +1,91 @@ +ticketId = $values['ticketId']; + $this->id = $values['id']; + $this->adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getTicketId(): string + { + return $this->ticketId; + } + + /** + * @param string $value + */ + public function setTicketId(string $value): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/Requests/FindTagRequest.php b/src/Unstable/Tags/Requests/FindTagRequest.php new file mode 100644 index 00000000..b908c395 --- /dev/null +++ b/src/Unstable/Tags/Requests/FindTagRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Tags/TagsClient.php b/src/Unstable/Tags/TagsClient.php new file mode 100644 index 00000000..0edf4fca --- /dev/null +++ b/src/Unstable/Tags/TagsClient.php @@ -0,0 +1,636 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can tag a specific contact. This will return a tag object for the tag that was added to the contact. + * + * @param AttachTagToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachTagToContact(AttachTagToContactRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/tags", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove tag from a specific contact. This will return a tag object for the tag that was removed from the contact. + * + * @param DetachTagFromContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachTagFromContact(DetachTagFromContactRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "contacts/{$request->getContactId()}/tags/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can tag a specific conversation. This will return a tag object for the tag that was added to the conversation. + * + * @param AttachTagToConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachTagToConversation(AttachTagToConversationRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/tags", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove tag from a specific conversation. This will return a tag object for the tag that was removed from the conversation. + * + * @param DetachTagFromConversationRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachTagFromConversation(DetachTagFromConversationRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "conversations/{$request->getConversationId()}/tags/{$request->getId()}", + method: HttpMethod::DELETE, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch a list of all tags for a given workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TagList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listTags(?array $options = null): TagList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TagList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can use this endpoint to perform the following operations: + * + * **1. Create a new tag:** You can create a new tag by passing in the tag name as specified in "Create or Update Tag Request Payload" described below. + * + * **2. Update an existing tag:** You can update an existing tag by passing the id of the tag as specified in "Create or Update Tag Request Payload" described below. + * + * **3. Tag Companies:** You can tag single company or a list of companies. You can tag a company by passing in the tag name and the company details as specified in "Tag Company Request Payload" described below. Also, if the tag doesn't exist then a new one will be created automatically. + * + * **4. Untag Companies:** You can untag a single company or a list of companies. You can untag a company by passing in the tag id and the company details as specified in "Untag Company Request Payload" described below. + * + * **5. Tag Multiple Users:** You can tag a list of users. You can tag the users by passing in the tag name and the user details as specified in "Tag Users Request Payload" described below. + * + * Each operation will return a tag object. + * + * @param ( + * CreateOrUpdateTagRequest + * |TagCompanyRequest + * |UntagCompanyRequest + * |TagMultipleUsersRequest + * ) $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function createTag(CreateOrUpdateTagRequest|TagCompanyRequest|UntagCompanyRequest|TagMultipleUsersRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags", + method: HttpMethod::POST, + body: JsonSerializer::serializeUnion($request, new Union(CreateOrUpdateTagRequest::class, TagCompanyRequest::class, UntagCompanyRequest::class, TagMultipleUsersRequest::class)), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of tags that are on the workspace by their id. + * This will return a tag object. + * + * @param FindTagRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function findTag(FindTagRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete the details of tags that are on the workspace by passing in the id. + * + * @param DeleteTagRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteTag(DeleteTagRequest $request, ?array $options = null): void + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tags/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + return; + } + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can tag a specific ticket. This will return a tag object for the tag that was added to the ticket. + * + * @param AttachTagToTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function attachTagToTicket(AttachTagToTicketRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}/tags", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can remove tag from a specific ticket. This will return a tag object for the tag that was removed from the ticket. + * + * @param DetachTagFromTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Tag + * @throws IntercomException + * @throws IntercomApiException + */ + public function detachTagFromTicket(DetachTagFromTicketRequest $request, ?array $options = null): Tag + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getTicketId()}/tags/{$request->getId()}", + method: HttpMethod::DELETE, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Tag::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Tags/Types/Tag.php b/src/Unstable/Tags/Types/Tag.php new file mode 100644 index 00000000..f1966fa3 --- /dev/null +++ b/src/Unstable/Tags/Types/Tag.php @@ -0,0 +1,155 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->appliedAt = $values['appliedAt'] ?? null; + $this->appliedBy = $values['appliedBy'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAppliedAt(): ?int + { + return $this->appliedAt; + } + + /** + * @param ?int $value + */ + public function setAppliedAt(?int $value = null): self + { + $this->appliedAt = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getAppliedBy(): ?Reference + { + return $this->appliedBy; + } + + /** + * @param ?Reference $value + */ + public function setAppliedBy(?Reference $value = null): self + { + $this->appliedBy = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tags/Types/TagBasic.php b/src/Unstable/Tags/Types/TagBasic.php new file mode 100644 index 00000000..2f855a3f --- /dev/null +++ b/src/Unstable/Tags/Types/TagBasic.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Teams/Requests/RetrieveTeamRequest.php b/src/Unstable/Teams/Requests/RetrieveTeamRequest.php new file mode 100644 index 00000000..9cb8b3bf --- /dev/null +++ b/src/Unstable/Teams/Requests/RetrieveTeamRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Teams/TeamsClient.php b/src/Unstable/Teams/TeamsClient.php new file mode 100644 index 00000000..61b57d04 --- /dev/null +++ b/src/Unstable/Teams/TeamsClient.php @@ -0,0 +1,163 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * This will return a list of team objects for the App. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TeamList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listTeams(?array $options = null): TeamList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "teams", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TeamList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single team, containing an array of admins that belong to this team. + * + * @param RetrieveTeamRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Team + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveTeam(RetrieveTeamRequest $request, ?array $options = null): Team + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "teams/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Team::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Teams/Types/Team.php b/src/Unstable/Teams/Types/Team.php new file mode 100644 index 00000000..e0f8a55d --- /dev/null +++ b/src/Unstable/Teams/Types/Team.php @@ -0,0 +1,156 @@ + $adminIds The list of admin IDs that are a part of the team. + */ + #[JsonProperty('admin_ids'), ArrayType(['integer'])] + private ?array $adminIds; + + /** + * @var ?AdminPriorityLevel $adminPriorityLevel + */ + #[JsonProperty('admin_priority_level')] + private ?AdminPriorityLevel $adminPriorityLevel; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * name?: ?string, + * adminIds?: ?array, + * adminPriorityLevel?: ?AdminPriorityLevel, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->adminIds = $values['adminIds'] ?? null; + $this->adminPriorityLevel = $values['adminPriorityLevel'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAdminIds(): ?array + { + return $this->adminIds; + } + + /** + * @param ?array $value + */ + public function setAdminIds(?array $value = null): self + { + $this->adminIds = $value; + return $this; + } + + /** + * @return ?AdminPriorityLevel + */ + public function getAdminPriorityLevel(): ?AdminPriorityLevel + { + return $this->adminPriorityLevel; + } + + /** + * @param ?AdminPriorityLevel $value + */ + public function setAdminPriorityLevel(?AdminPriorityLevel $value = null): self + { + $this->adminPriorityLevel = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/TicketStates/TicketStatesClient.php b/src/Unstable/TicketStates/TicketStatesClient.php new file mode 100644 index 00000000..ed6272f8 --- /dev/null +++ b/src/Unstable/TicketStates/TicketStatesClient.php @@ -0,0 +1,106 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can get a list of all ticket states for a workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketStateList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listTicketStates(?array $options = null): TicketStateList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_states", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketStateList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/TicketTypeAttributes/Requests/CreateTicketTypeAttributeRequest.php b/src/Unstable/TicketTypeAttributes/Requests/CreateTicketTypeAttributeRequest.php new file mode 100644 index 00000000..f4fc4958 --- /dev/null +++ b/src/Unstable/TicketTypeAttributes/Requests/CreateTicketTypeAttributeRequest.php @@ -0,0 +1,293 @@ + $dataType The data type of the attribute + */ + #[JsonProperty('data_type')] + private string $dataType; + + /** + * @var ?bool $requiredToCreate Whether the attribute is required to be filled in when teammates are creating the ticket in Inbox. + */ + #[JsonProperty('required_to_create')] + private ?bool $requiredToCreate; + + /** + * @var ?bool $requiredToCreateForContacts Whether the attribute is required to be filled in when contacts are creating the ticket in Messenger. + */ + #[JsonProperty('required_to_create_for_contacts')] + private ?bool $requiredToCreateForContacts; + + /** + * @var ?bool $visibleOnCreate Whether the attribute is visible to teammates when creating a ticket in Inbox. + */ + #[JsonProperty('visible_on_create')] + private ?bool $visibleOnCreate; + + /** + * @var ?bool $visibleToContacts Whether the attribute is visible to contacts when creating a ticket in Messenger. + */ + #[JsonProperty('visible_to_contacts')] + private ?bool $visibleToContacts; + + /** + * @var ?bool $multiline Whether the attribute allows multiple lines of text (only applicable to string attributes) + */ + #[JsonProperty('multiline')] + private ?bool $multiline; + + /** + * @var ?string $listItems A comma delimited list of items for the attribute value (only applicable to list attributes) + */ + #[JsonProperty('list_items')] + private ?string $listItems; + + /** + * @var ?bool $allowMultipleValues Whether the attribute allows multiple files to be attached to it (only applicable to file attributes) + */ + #[JsonProperty('allow_multiple_values')] + private ?bool $allowMultipleValues; + + /** + * @param array{ + * ticketTypeId: string, + * name: string, + * description: string, + * dataType: value-of, + * requiredToCreate?: ?bool, + * requiredToCreateForContacts?: ?bool, + * visibleOnCreate?: ?bool, + * visibleToContacts?: ?bool, + * multiline?: ?bool, + * listItems?: ?string, + * allowMultipleValues?: ?bool, + * } $values + */ + public function __construct( + array $values, + ) { + $this->ticketTypeId = $values['ticketTypeId']; + $this->name = $values['name']; + $this->description = $values['description']; + $this->dataType = $values['dataType']; + $this->requiredToCreate = $values['requiredToCreate'] ?? null; + $this->requiredToCreateForContacts = $values['requiredToCreateForContacts'] ?? null; + $this->visibleOnCreate = $values['visibleOnCreate'] ?? null; + $this->visibleToContacts = $values['visibleToContacts'] ?? null; + $this->multiline = $values['multiline'] ?? null; + $this->listItems = $values['listItems'] ?? null; + $this->allowMultipleValues = $values['allowMultipleValues'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @param string $value + */ + public function setDescription(string $value): self + { + $this->description = $value; + return $this; + } + + /** + * @return value-of + */ + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param value-of $value + */ + public function setDataType(string $value): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreate(): ?bool + { + return $this->requiredToCreate; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreate(?bool $value = null): self + { + $this->requiredToCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreateForContacts(): ?bool + { + return $this->requiredToCreateForContacts; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreateForContacts(?bool $value = null): self + { + $this->requiredToCreateForContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleOnCreate(): ?bool + { + return $this->visibleOnCreate; + } + + /** + * @param ?bool $value + */ + public function setVisibleOnCreate(?bool $value = null): self + { + $this->visibleOnCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleToContacts(): ?bool + { + return $this->visibleToContacts; + } + + /** + * @param ?bool $value + */ + public function setVisibleToContacts(?bool $value = null): self + { + $this->visibleToContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMultiline(): ?bool + { + return $this->multiline; + } + + /** + * @param ?bool $value + */ + public function setMultiline(?bool $value = null): self + { + $this->multiline = $value; + return $this; + } + + /** + * @return ?string + */ + public function getListItems(): ?string + { + return $this->listItems; + } + + /** + * @param ?string $value + */ + public function setListItems(?string $value = null): self + { + $this->listItems = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAllowMultipleValues(): ?bool + { + return $this->allowMultipleValues; + } + + /** + * @param ?bool $value + */ + public function setAllowMultipleValues(?bool $value = null): self + { + $this->allowMultipleValues = $value; + return $this; + } +} diff --git a/src/Unstable/TicketTypeAttributes/Requests/UpdateTicketTypeAttributeRequest.php b/src/Unstable/TicketTypeAttributes/Requests/UpdateTicketTypeAttributeRequest.php new file mode 100644 index 00000000..1e10c7d1 --- /dev/null +++ b/src/Unstable/TicketTypeAttributes/Requests/UpdateTicketTypeAttributeRequest.php @@ -0,0 +1,316 @@ +ticketTypeId = $values['ticketTypeId']; + $this->id = $values['id']; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->requiredToCreate = $values['requiredToCreate'] ?? null; + $this->requiredToCreateForContacts = $values['requiredToCreateForContacts'] ?? null; + $this->visibleOnCreate = $values['visibleOnCreate'] ?? null; + $this->visibleToContacts = $values['visibleToContacts'] ?? null; + $this->multiline = $values['multiline'] ?? null; + $this->listItems = $values['listItems'] ?? null; + $this->allowMultipleValues = $values['allowMultipleValues'] ?? null; + $this->archived = $values['archived'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreate(): ?bool + { + return $this->requiredToCreate; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreate(?bool $value = null): self + { + $this->requiredToCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreateForContacts(): ?bool + { + return $this->requiredToCreateForContacts; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreateForContacts(?bool $value = null): self + { + $this->requiredToCreateForContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleOnCreate(): ?bool + { + return $this->visibleOnCreate; + } + + /** + * @param ?bool $value + */ + public function setVisibleOnCreate(?bool $value = null): self + { + $this->visibleOnCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleToContacts(): ?bool + { + return $this->visibleToContacts; + } + + /** + * @param ?bool $value + */ + public function setVisibleToContacts(?bool $value = null): self + { + $this->visibleToContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMultiline(): ?bool + { + return $this->multiline; + } + + /** + * @param ?bool $value + */ + public function setMultiline(?bool $value = null): self + { + $this->multiline = $value; + return $this; + } + + /** + * @return ?string + */ + public function getListItems(): ?string + { + return $this->listItems; + } + + /** + * @param ?string $value + */ + public function setListItems(?string $value = null): self + { + $this->listItems = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAllowMultipleValues(): ?bool + { + return $this->allowMultipleValues; + } + + /** + * @param ?bool $value + */ + public function setAllowMultipleValues(?bool $value = null): self + { + $this->allowMultipleValues = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } +} diff --git a/src/Unstable/TicketTypeAttributes/TicketTypeAttributesClient.php b/src/Unstable/TicketTypeAttributes/TicketTypeAttributesClient.php new file mode 100644 index 00000000..70efaf67 --- /dev/null +++ b/src/Unstable/TicketTypeAttributes/TicketTypeAttributesClient.php @@ -0,0 +1,172 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can create a new attribute for a ticket type. + * + * @param CreateTicketTypeAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?TicketTypeAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function createTicketTypeAttribute(CreateTicketTypeAttributeRequest $request, ?array $options = null): ?TicketTypeAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getTicketTypeId()}/attributes", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return TicketTypeAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update an existing attribute for a ticket type. + * + * @param UpdateTicketTypeAttributeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?TicketTypeAttribute + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateTicketTypeAttribute(UpdateTicketTypeAttributeRequest $request, ?array $options = null): ?TicketTypeAttribute + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getTicketTypeId()}/attributes/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return TicketTypeAttribute::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/TicketTypeAttributes/Types/CreateTicketTypeAttributeRequestDataType.php b/src/Unstable/TicketTypeAttributes/Types/CreateTicketTypeAttributeRequestDataType.php new file mode 100644 index 00000000..f1e5fa58 --- /dev/null +++ b/src/Unstable/TicketTypeAttributes/Types/CreateTicketTypeAttributeRequestDataType.php @@ -0,0 +1,14 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/TicketTypes/TicketTypesClient.php b/src/Unstable/TicketTypes/TicketTypesClient.php new file mode 100644 index 00000000..5a80c2e4 --- /dev/null +++ b/src/Unstable/TicketTypes/TicketTypesClient.php @@ -0,0 +1,229 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can get a list of all ticket types for a workspace. + * + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketTypeList + * @throws IntercomException + * @throws IntercomApiException + */ + public function listTicketTypes(?array $options = null): TicketTypeList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketTypeList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can create a new ticket type. + * > 📘 Creating ticket types. + * > + * > Every ticket type will be created with two default attributes: _default_title_ and _default_description_. + * > For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/) + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?TicketType + * @throws IntercomException + * @throws IntercomApiException + */ + public function createTicketType(mixed $request, ?array $options = null): ?TicketType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return TicketType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single ticket type. + * + * @param GetTicketTypeRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?TicketType + * @throws IntercomException + * @throws IntercomApiException + */ + public function getTicketType(GetTicketTypeRequest $request, ?array $options = null): ?TicketType + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "ticket_types/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return TicketType::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Tickets/Requests/DeleteTicketRequest.php b/src/Unstable/Tickets/Requests/DeleteTicketRequest.php new file mode 100644 index 00000000..3f56f5f9 --- /dev/null +++ b/src/Unstable/Tickets/Requests/DeleteTicketRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Tickets/Requests/EnqueueCreateTicketRequest.php b/src/Unstable/Tickets/Requests/EnqueueCreateTicketRequest.php new file mode 100644 index 00000000..b78bb51e --- /dev/null +++ b/src/Unstable/Tickets/Requests/EnqueueCreateTicketRequest.php @@ -0,0 +1,66 @@ +, + * skipNotifications?: ?bool, + * conversationToLinkId?: ?string, + * companyId?: ?string, + * createdAt?: ?int, + * assignment?: ?CreateTicketRequestAssignment, + * } $values + */ + public function __construct( + array $values, + ) { + $this->skipNotifications = $values['skipNotifications'] ?? null; + $this->ticketTypeId = $values['ticketTypeId']; + $this->contacts = $values['contacts']; + $this->conversationToLinkId = $values['conversationToLinkId'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->assignment = $values['assignment'] ?? null; + } + + /** + * @return ?bool + */ + public function getSkipNotifications(): ?bool + { + return $this->skipNotifications; + } + + /** + * @param ?bool $value + */ + public function setSkipNotifications(?bool $value = null): self + { + $this->skipNotifications = $value; + return $this; + } +} diff --git a/src/Unstable/Tickets/Requests/GetTicketRequest.php b/src/Unstable/Tickets/Requests/GetTicketRequest.php new file mode 100644 index 00000000..6fc5bf96 --- /dev/null +++ b/src/Unstable/Tickets/Requests/GetTicketRequest.php @@ -0,0 +1,41 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } +} diff --git a/src/Unstable/Tickets/Requests/ReplyTicketRequest.php b/src/Unstable/Tickets/Requests/ReplyTicketRequest.php new file mode 100644 index 00000000..4bb9a483 --- /dev/null +++ b/src/Unstable/Tickets/Requests/ReplyTicketRequest.php @@ -0,0 +1,89 @@ +id = $values['id']; + $this->body = $values['body']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ( + * ContactReplyTicketIntercomUserIdRequest + * |ContactReplyTicketUserIdRequest + * |ContactReplyTicketEmailRequest + * |AdminReplyTicketRequest + * ) + */ + public function getBody(): ContactReplyTicketIntercomUserIdRequest|ContactReplyTicketUserIdRequest|ContactReplyTicketEmailRequest|AdminReplyTicketRequest + { + return $this->body; + } + + /** + * @param ( + * ContactReplyTicketIntercomUserIdRequest + * |ContactReplyTicketUserIdRequest + * |ContactReplyTicketEmailRequest + * |AdminReplyTicketRequest + * ) $value + */ + public function setBody(ContactReplyTicketIntercomUserIdRequest|ContactReplyTicketUserIdRequest|ContactReplyTicketEmailRequest|AdminReplyTicketRequest $value): self + { + $this->body = $value; + return $this; + } +} diff --git a/src/Unstable/Tickets/Requests/UpdateTicketRequest.php b/src/Unstable/Tickets/Requests/UpdateTicketRequest.php new file mode 100644 index 00000000..6c0f5eda --- /dev/null +++ b/src/Unstable/Tickets/Requests/UpdateTicketRequest.php @@ -0,0 +1,243 @@ + $ticketAttributes The attributes set on the ticket. + */ + #[JsonProperty('ticket_attributes'), ArrayType(['string' => 'mixed'])] + private ?array $ticketAttributes; + + /** + * @var ?string $ticketStateId The ID of the ticket state associated with the ticket type. + */ + #[JsonProperty('ticket_state_id')] + private ?string $ticketStateId; + + /** + * @var ?string $companyId The ID of the company that the ticket is associated with. The unique identifier for the company which is given by Intercom. Set to nil to remove company. + */ + #[JsonProperty('company_id')] + private ?string $companyId; + + /** + * @var ?bool $open Specify if a ticket is open. Set to false to close a ticket. Closing a ticket will also unsnooze it. + */ + #[JsonProperty('open')] + private ?bool $open; + + /** + * @var ?bool $isShared Specify whether the ticket is visible to users. + */ + #[JsonProperty('is_shared')] + private ?bool $isShared; + + /** + * @var ?int $snoozedUntil The time you want the ticket to reopen. + */ + #[JsonProperty('snoozed_until')] + private ?int $snoozedUntil; + + /** + * @var ?int $adminId The ID of the admin performing ticket update. Needed for workflows execution and attributing actions to specific admins. + */ + #[JsonProperty('admin_id')] + private ?int $adminId; + + /** + * @var ?string $assigneeId The ID of the admin or team to which the ticket is assigned. Set this 0 to unassign it. + */ + #[JsonProperty('assignee_id')] + private ?string $assigneeId; + + /** + * @param array{ + * id: string, + * ticketAttributes?: ?array, + * ticketStateId?: ?string, + * companyId?: ?string, + * open?: ?bool, + * isShared?: ?bool, + * snoozedUntil?: ?int, + * adminId?: ?int, + * assigneeId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->ticketAttributes = $values['ticketAttributes'] ?? null; + $this->ticketStateId = $values['ticketStateId'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->open = $values['open'] ?? null; + $this->isShared = $values['isShared'] ?? null; + $this->snoozedUntil = $values['snoozedUntil'] ?? null; + $this->adminId = $values['adminId'] ?? null; + $this->assigneeId = $values['assigneeId'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTicketAttributes(): ?array + { + return $this->ticketAttributes; + } + + /** + * @param ?array $value + */ + public function setTicketAttributes(?array $value = null): self + { + $this->ticketAttributes = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTicketStateId(): ?string + { + return $this->ticketStateId; + } + + /** + * @param ?string $value + */ + public function setTicketStateId(?string $value = null): self + { + $this->ticketStateId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getOpen(): ?bool + { + return $this->open; + } + + /** + * @param ?bool $value + */ + public function setOpen(?bool $value = null): self + { + $this->open = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsShared(): ?bool + { + return $this->isShared; + } + + /** + * @param ?bool $value + */ + public function setIsShared(?bool $value = null): self + { + $this->isShared = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSnoozedUntil(): ?int + { + return $this->snoozedUntil; + } + + /** + * @param ?int $value + */ + public function setSnoozedUntil(?int $value = null): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAdminId(): ?int + { + return $this->adminId; + } + + /** + * @param ?int $value + */ + public function setAdminId(?int $value = null): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAssigneeId(): ?string + { + return $this->assigneeId; + } + + /** + * @param ?string $value + */ + public function setAssigneeId(?string $value = null): self + { + $this->assigneeId = $value; + return $this; + } +} diff --git a/src/Unstable/Tickets/TicketsClient.php b/src/Unstable/Tickets/TicketsClient.php new file mode 100644 index 00000000..24f0f51a --- /dev/null +++ b/src/Unstable/Tickets/TicketsClient.php @@ -0,0 +1,470 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can reply to a ticket with a message from an admin or on behalf of a contact, or with a note for admins. + * + * @param ReplyTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketReply + * @throws IntercomException + * @throws IntercomApiException + */ + public function replyTicket(ReplyTicketRequest $request, ?array $options = null): TicketReply + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getId()}/reply", + method: HttpMethod::POST, + body: $request->getBody(), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketReply::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Enqueues ticket creation for asynchronous processing, returning if the job was enqueued successfully to be processed. We attempt to perform a best-effort validation on inputs before tasks are enqueued. If the given parameters are incorrect, we won't enqueue the job. + * + * @param EnqueueCreateTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Jobs + * @throws IntercomException + * @throws IntercomApiException + */ + public function enqueueCreateTicket(EnqueueCreateTicketRequest $request, ?array $options = null): Jobs + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/enqueue", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Jobs::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can fetch the details of a single ticket. + * + * @param GetTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function getTicket(GetTicketRequest $request, ?array $options = null): ?Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getId()}", + method: HttpMethod::GET, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can update a ticket. + * + * @param UpdateTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Ticket + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateTicket(UpdateTicketRequest $request, ?array $options = null): ?Ticket + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getId()}", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Ticket::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can delete a ticket using the Intercom provided ID. + * + * @param DeleteTicketRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return DeleteTicketResponse + * @throws IntercomException + * @throws IntercomApiException + */ + public function deleteTicket(DeleteTicketRequest $request, ?array $options = null): DeleteTicketResponse + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/{$request->getId()}", + method: HttpMethod::DELETE, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return DeleteTicketResponse::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can search for multiple tickets by the value of their attributes in order to fetch exactly which ones you want. + * + * To search for tickets, you send a `POST` request to `https://api.intercom.io/tickets/search`. + * + * This will accept a query object in the body which will define your filters. + * {% admonition type="warning" name="Optimizing search queries" %} + * Search queries can be complex, so optimizing them can help the performance of your search. + * Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize + * pagination to limit the number of results returned. The default is `20` results per page. + * See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param. + * {% /admonition %} + * + * ### Nesting & Limitations + * + * You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4). + * There are some limitations to the amount of multiples there can be: + * - There's a limit of max 2 nested filters + * - There's a limit of max 15 filters for each AND or OR group + * + * ### Accepted Fields + * + * Most keys listed as part of the Ticket model are searchable, whether writeable or not. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foobar"`). + * The `source.body` field is unique as the search will not be performed against the entire value, but instead against every element of the value separately. For example, when searching for a conversation with a `"I need support"` body - the query should contain a `=` operator with the value `"support"` for such conversation to be returned. A query with a `=` operator and a `"need support"` value will not yield a result. + * + * | Field | Type | + * | :---------------------------------------- | :--------------------------------------------------------------------------------------- | + * | id | String | + * | created_at | Date (UNIX timestamp) | + * | updated_at | Date (UNIX timestamp) | + * | _default_title_ | String | + * | _default_description_ | String | + * | category | String | + * | ticket_type_id | String | + * | contact_ids | String | + * | teammate_ids | String | + * | admin_assignee_id | String | + * | team_assignee_id | String | + * | open | Boolean | + * | state | String | + * | snoozed_until | Date (UNIX timestamp) | + * | ticket_attribute.{id} | String or Boolean or Date (UNIX timestamp) or Float or Integer | + * + * {% admonition type="info" name="Searching by Category" %} + * When searching for tickets by the **`category`** field, specific terms must be used instead of the category names: + * * For **Customer** category tickets, use the term `request`. + * * For **Back-office** category tickets, use the term `task`. + * * For **Tracker** category tickets, use the term `tracker`. + * {% /admonition %} + * + * ### Accepted Operators + * + * {% admonition type="info" name="Searching based on `created_at`" %} + * You may use the `<=` or `>=` operators to search by `created_at`. + * {% /admonition %} + * + * The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). + * + * | Operator | Valid Types | Description | + * | :------- | :----------------------------- | :----------------------------------------------------------- | + * | = | All | Equals | + * | != | All | Doesn't Equal | + * | IN | All | In Shortcut for `OR` queries Values most be in Array | + * | NIN | All | Not In Shortcut for `OR !` queries Values must be in Array | + * | > | Integer Date (UNIX Timestamp) | Greater (or equal) than | + * | < | Integer Date (UNIX Timestamp) | Lower (or equal) than | + * | ~ | String | Contains | + * | !~ | String | Doesn't Contain | + * | ^ | String | Starts With | + * | $ | String | Ends With | + * + * @param SearchRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return TicketList + * @throws IntercomException + * @throws IntercomApiException + */ + public function searchTickets(SearchRequest $request, ?array $options = null): TicketList + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "tickets/search", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return TicketList::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Unstable/Tickets/Types/DeleteTicketResponse.php b/src/Unstable/Tickets/Types/DeleteTicketResponse.php new file mode 100644 index 00000000..7ed8896a --- /dev/null +++ b/src/Unstable/Tickets/Types/DeleteTicketResponse.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->object = $values['object'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'ticket' + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?'ticket' $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/Ticket.php b/src/Unstable/Tickets/Types/Ticket.php new file mode 100644 index 00000000..aadce148 --- /dev/null +++ b/src/Unstable/Tickets/Types/Ticket.php @@ -0,0 +1,487 @@ + $category Category of the Ticket. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?array + * |FileAttribute + * |null + * )> $ticketAttributes + */ + #[JsonProperty('ticket_attributes'), ArrayType(['string' => new Union(new Union('string', 'null'), 'float', 'bool', ['mixed'], FileAttribute::class)])] + private ?array $ticketAttributes; + + /** + * @var ?TicketState $ticketState + */ + #[JsonProperty('ticket_state')] + private ?TicketState $ticketState; + + /** + * @var ?TicketType $ticketType + */ + #[JsonProperty('ticket_type')] + private ?TicketType $ticketType; + + /** + * @var ?TicketContacts $contacts + */ + #[JsonProperty('contacts')] + private ?TicketContacts $contacts; + + /** + * @var ?string $adminAssigneeId The id representing the admin assigned to the ticket. + */ + #[JsonProperty('admin_assignee_id')] + private ?string $adminAssigneeId; + + /** + * @var ?string $teamAssigneeId The id representing the team assigned to the ticket. + */ + #[JsonProperty('team_assignee_id')] + private ?string $teamAssigneeId; + + /** + * @var ?int $createdAt The time the ticket was created as a UTC Unix timestamp. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The last time the ticket was updated as a UTC Unix timestamp. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?bool $open Whether or not the ticket is open. If false, the ticket is closed. + */ + #[JsonProperty('open')] + private ?bool $open; + + /** + * @var ?int $snoozedUntil The time the ticket will be snoozed until as a UTC Unix timestamp. If null, the ticket is not currently snoozed. + */ + #[JsonProperty('snoozed_until')] + private ?int $snoozedUntil; + + /** + * @var ?LinkedObjectList $linkedObjects + */ + #[JsonProperty('linked_objects')] + private ?LinkedObjectList $linkedObjects; + + /** + * @var ?TicketParts $ticketParts + */ + #[JsonProperty('ticket_parts')] + private ?TicketParts $ticketParts; + + /** + * @var ?bool $isShared Whether or not the ticket is shared with the customer. + */ + #[JsonProperty('is_shared')] + private ?bool $isShared; + + /** + * @param array{ + * type?: ?'ticket', + * id?: ?string, + * ticketId?: ?string, + * category?: ?value-of, + * ticketAttributes?: ?array + * |FileAttribute + * |null + * )>, + * ticketState?: ?TicketState, + * ticketType?: ?TicketType, + * contacts?: ?TicketContacts, + * adminAssigneeId?: ?string, + * teamAssigneeId?: ?string, + * createdAt?: ?int, + * updatedAt?: ?int, + * open?: ?bool, + * snoozedUntil?: ?int, + * linkedObjects?: ?LinkedObjectList, + * ticketParts?: ?TicketParts, + * isShared?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->ticketId = $values['ticketId'] ?? null; + $this->category = $values['category'] ?? null; + $this->ticketAttributes = $values['ticketAttributes'] ?? null; + $this->ticketState = $values['ticketState'] ?? null; + $this->ticketType = $values['ticketType'] ?? null; + $this->contacts = $values['contacts'] ?? null; + $this->adminAssigneeId = $values['adminAssigneeId'] ?? null; + $this->teamAssigneeId = $values['teamAssigneeId'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->open = $values['open'] ?? null; + $this->snoozedUntil = $values['snoozedUntil'] ?? null; + $this->linkedObjects = $values['linkedObjects'] ?? null; + $this->ticketParts = $values['ticketParts'] ?? null; + $this->isShared = $values['isShared'] ?? null; + } + + /** + * @return ?'ticket' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'ticket' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTicketId(): ?string + { + return $this->ticketId; + } + + /** + * @param ?string $value + */ + public function setTicketId(?string $value = null): self + { + $this->ticketId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?array + * |FileAttribute + * |null + * )> + */ + public function getTicketAttributes(): ?array + { + return $this->ticketAttributes; + } + + /** + * @param ?array + * |FileAttribute + * |null + * )> $value + */ + public function setTicketAttributes(?array $value = null): self + { + $this->ticketAttributes = $value; + return $this; + } + + /** + * @return ?TicketState + */ + public function getTicketState(): ?TicketState + { + return $this->ticketState; + } + + /** + * @param ?TicketState $value + */ + public function setTicketState(?TicketState $value = null): self + { + $this->ticketState = $value; + return $this; + } + + /** + * @return ?TicketType + */ + public function getTicketType(): ?TicketType + { + return $this->ticketType; + } + + /** + * @param ?TicketType $value + */ + public function setTicketType(?TicketType $value = null): self + { + $this->ticketType = $value; + return $this; + } + + /** + * @return ?TicketContacts + */ + public function getContacts(): ?TicketContacts + { + return $this->contacts; + } + + /** + * @param ?TicketContacts $value + */ + public function setContacts(?TicketContacts $value = null): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAdminAssigneeId(): ?string + { + return $this->adminAssigneeId; + } + + /** + * @param ?string $value + */ + public function setAdminAssigneeId(?string $value = null): self + { + $this->adminAssigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTeamAssigneeId(): ?string + { + return $this->teamAssigneeId; + } + + /** + * @param ?string $value + */ + public function setTeamAssigneeId(?string $value = null): self + { + $this->teamAssigneeId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getOpen(): ?bool + { + return $this->open; + } + + /** + * @param ?bool $value + */ + public function setOpen(?bool $value = null): self + { + $this->open = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSnoozedUntil(): ?int + { + return $this->snoozedUntil; + } + + /** + * @param ?int $value + */ + public function setSnoozedUntil(?int $value = null): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return ?LinkedObjectList + */ + public function getLinkedObjects(): ?LinkedObjectList + { + return $this->linkedObjects; + } + + /** + * @param ?LinkedObjectList $value + */ + public function setLinkedObjects(?LinkedObjectList $value = null): self + { + $this->linkedObjects = $value; + return $this; + } + + /** + * @return ?TicketParts + */ + public function getTicketParts(): ?TicketParts + { + return $this->ticketParts; + } + + /** + * @param ?TicketParts $value + */ + public function setTicketParts(?TicketParts $value = null): self + { + $this->ticketParts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsShared(): ?bool + { + return $this->isShared; + } + + /** + * @param ?bool $value + */ + public function setIsShared(?bool $value = null): self + { + $this->isShared = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketCategory.php b/src/Unstable/Tickets/Types/TicketCategory.php new file mode 100644 index 00000000..1210a631 --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketCategory.php @@ -0,0 +1,10 @@ + $contacts The list of contacts affected by this ticket. + */ + #[JsonProperty('contacts'), ArrayType([ContactReference::class])] + private ?array $contacts; + + /** + * @param array{ + * type?: ?'contact.list', + * contacts?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->contacts = $values['contacts'] ?? null; + } + + /** + * @return ?'contact.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'contact.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getContacts(): ?array + { + return $this->contacts; + } + + /** + * @param ?array $value + */ + public function setContacts(?array $value = null): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketPart.php b/src/Unstable/Tickets/Types/TicketPart.php new file mode 100644 index 00000000..0f1c798d --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketPart.php @@ -0,0 +1,408 @@ + $previousTicketState The previous state of the ticket. + */ + #[JsonProperty('previous_ticket_state')] + private ?string $previousTicketState; + + /** + * @var ?value-of $ticketState The state of the ticket. + */ + #[JsonProperty('ticket_state')] + private ?string $ticketState; + + /** + * @var ?int $createdAt The time the ticket part was created. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The last time the ticket part was updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?Reference $assignedTo The id of the admin that was assigned the ticket by this ticket_part (null if there has been no change in assignment.) + */ + #[JsonProperty('assigned_to')] + private ?Reference $assignedTo; + + /** + * @var ?TicketPartAuthor $author + */ + #[JsonProperty('author')] + private ?TicketPartAuthor $author; + + /** + * @var ?array $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?string $externalId The external id of the ticket part + */ + #[JsonProperty('external_id')] + private ?string $externalId; + + /** + * @var ?bool $redacted Whether or not the ticket part has been redacted. + */ + #[JsonProperty('redacted')] + private ?bool $redacted; + + /** + * @var ?string $appPackageCode The app package code if this part was created via API. Note this field won't show if the part was not created via API. + */ + #[JsonProperty('app_package_code')] + private ?string $appPackageCode; + + /** + * @var ?TicketPartUpdatedAttributeData $updatedAttributeData The updated attribute data of the ticket part. Only present for attribute update parts. + */ + #[JsonProperty('updated_attribute_data')] + private ?TicketPartUpdatedAttributeData $updatedAttributeData; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * partType?: ?string, + * body?: ?string, + * previousTicketState?: ?value-of, + * ticketState?: ?value-of, + * createdAt?: ?int, + * updatedAt?: ?int, + * assignedTo?: ?Reference, + * author?: ?TicketPartAuthor, + * attachments?: ?array, + * externalId?: ?string, + * redacted?: ?bool, + * appPackageCode?: ?string, + * updatedAttributeData?: ?TicketPartUpdatedAttributeData, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->partType = $values['partType'] ?? null; + $this->body = $values['body'] ?? null; + $this->previousTicketState = $values['previousTicketState'] ?? null; + $this->ticketState = $values['ticketState'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->assignedTo = $values['assignedTo'] ?? null; + $this->author = $values['author'] ?? null; + $this->attachments = $values['attachments'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->redacted = $values['redacted'] ?? null; + $this->appPackageCode = $values['appPackageCode'] ?? null; + $this->updatedAttributeData = $values['updatedAttributeData'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPartType(): ?string + { + return $this->partType; + } + + /** + * @param ?string $value + */ + public function setPartType(?string $value = null): self + { + $this->partType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getPreviousTicketState(): ?string + { + return $this->previousTicketState; + } + + /** + * @param ?value-of $value + */ + public function setPreviousTicketState(?string $value = null): self + { + $this->previousTicketState = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getTicketState(): ?string + { + return $this->ticketState; + } + + /** + * @param ?value-of $value + */ + public function setTicketState(?string $value = null): self + { + $this->ticketState = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getAssignedTo(): ?Reference + { + return $this->assignedTo; + } + + /** + * @param ?Reference $value + */ + public function setAssignedTo(?Reference $value = null): self + { + $this->assignedTo = $value; + return $this; + } + + /** + * @return ?TicketPartAuthor + */ + public function getAuthor(): ?TicketPartAuthor + { + return $this->author; + } + + /** + * @param ?TicketPartAuthor $value + */ + public function setAuthor(?TicketPartAuthor $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRedacted(): ?bool + { + return $this->redacted; + } + + /** + * @param ?bool $value + */ + public function setRedacted(?bool $value = null): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAppPackageCode(): ?string + { + return $this->appPackageCode; + } + + /** + * @param ?string $value + */ + public function setAppPackageCode(?string $value = null): self + { + $this->appPackageCode = $value; + return $this; + } + + /** + * @return ?TicketPartUpdatedAttributeData + */ + public function getUpdatedAttributeData(): ?TicketPartUpdatedAttributeData + { + return $this->updatedAttributeData; + } + + /** + * @param ?TicketPartUpdatedAttributeData $value + */ + public function setUpdatedAttributeData(?TicketPartUpdatedAttributeData $value = null): self + { + $this->updatedAttributeData = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketPartPreviousTicketState.php b/src/Unstable/Tickets/Types/TicketPartPreviousTicketState.php new file mode 100644 index 00000000..80b98710 --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketPartPreviousTicketState.php @@ -0,0 +1,11 @@ +attribute = $values['attribute']; + $this->value = $values['value']; + } + + /** + * @return TicketPartUpdatedAttributeDataAttribute + */ + public function getAttribute(): TicketPartUpdatedAttributeDataAttribute + { + return $this->attribute; + } + + /** + * @param TicketPartUpdatedAttributeDataAttribute $value + */ + public function setAttribute(TicketPartUpdatedAttributeDataAttribute $value): self + { + $this->attribute = $value; + return $this; + } + + /** + * @return TicketPartUpdatedAttributeDataValue + */ + public function getValue(): TicketPartUpdatedAttributeDataValue + { + return $this->value; + } + + /** + * @param TicketPartUpdatedAttributeDataValue $value + */ + public function setValue(TicketPartUpdatedAttributeDataValue $value): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketPartUpdatedAttributeDataAttribute.php b/src/Unstable/Tickets/Types/TicketPartUpdatedAttributeDataAttribute.php new file mode 100644 index 00000000..07cad123 --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketPartUpdatedAttributeDataAttribute.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->id = $values['id']; + $this->label = $values['label']; + } + + /** + * @return 'attribute' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'attribute' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getLabel(): string + { + return $this->label; + } + + /** + * @param string $value + */ + public function setLabel(string $value): self + { + $this->label = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketPartUpdatedAttributeDataValue.php b/src/Unstable/Tickets/Types/TicketPartUpdatedAttributeDataValue.php new file mode 100644 index 00000000..8d7b3fde --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketPartUpdatedAttributeDataValue.php @@ -0,0 +1,133 @@ + + * |null + * ) $id + */ + #[JsonProperty('id'), Union(new Union('string', 'null'), ['integer'])] + private string|array|null $id; + + /** + * @var ( + * string + * |array + * ) $label + */ + #[JsonProperty('label'), Union('string', ['string'])] + private string|array $label; + + /** + * @param array{ + * type: 'value', + * id: ( + * string + * |array + * |null + * ), + * label: ( + * string + * |array + * ), + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + $this->label = $values['label']; + } + + /** + * @return 'value' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'value' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ( + * string + * |array + * |null + * ) + */ + public function getId(): string|array|null + { + return $this->id; + } + + /** + * @param ( + * string + * |array + * |null + * ) $value + */ + public function setId(string|array|null $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ( + * string + * |array + * ) + */ + public function getLabel(): string|array + { + return $this->label; + } + + /** + * @param ( + * string + * |array + * ) $value + */ + public function setLabel(string|array $value): self + { + $this->label = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketState.php b/src/Unstable/Tickets/Types/TicketState.php new file mode 100644 index 00000000..9721e933 --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketState.php @@ -0,0 +1,154 @@ + $category The category of the ticket state + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?string $internalLabel The state the ticket is currently in, in a human readable form - visible in Intercom + */ + #[JsonProperty('internal_label')] + private ?string $internalLabel; + + /** + * @var ?string $externalLabel The state the ticket is currently in, in a human readable form - visible to customers, in the messenger, email and tickets portal. + */ + #[JsonProperty('external_label')] + private ?string $externalLabel; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * category?: ?value-of, + * internalLabel?: ?string, + * externalLabel?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->category = $values['category'] ?? null; + $this->internalLabel = $values['internalLabel'] ?? null; + $this->externalLabel = $values['externalLabel'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?string + */ + public function getInternalLabel(): ?string + { + return $this->internalLabel; + } + + /** + * @param ?string $value + */ + public function setInternalLabel(?string $value = null): self + { + $this->internalLabel = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalLabel(): ?string + { + return $this->externalLabel; + } + + /** + * @param ?string $value + */ + public function setExternalLabel(?string $value = null): self + { + $this->externalLabel = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketStateCategory.php b/src/Unstable/Tickets/Types/TicketStateCategory.php new file mode 100644 index 00000000..63bcc0e1 --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketStateCategory.php @@ -0,0 +1,11 @@ + $category The category of the ticket state + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?string $internalLabel The state the ticket is currently in, in a human readable form - visible in Intercom + */ + #[JsonProperty('internal_label')] + private ?string $internalLabel; + + /** + * @var ?string $externalLabel The state the ticket is currently in, in a human readable form - visible to customers, in the messenger, email and tickets portal. + */ + #[JsonProperty('external_label')] + private ?string $externalLabel; + + /** + * @var ?bool $archived Whether the ticket state is archived + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?TicketStateDetailedTicketTypes $ticketTypes A list of ticket types associated with a given ticket state. + */ + #[JsonProperty('ticket_types')] + private ?TicketStateDetailedTicketTypes $ticketTypes; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * category?: ?value-of, + * internalLabel?: ?string, + * externalLabel?: ?string, + * archived?: ?bool, + * ticketTypes?: ?TicketStateDetailedTicketTypes, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->category = $values['category'] ?? null; + $this->internalLabel = $values['internalLabel'] ?? null; + $this->externalLabel = $values['externalLabel'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->ticketTypes = $values['ticketTypes'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?string + */ + public function getInternalLabel(): ?string + { + return $this->internalLabel; + } + + /** + * @param ?string $value + */ + public function setInternalLabel(?string $value = null): self + { + $this->internalLabel = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalLabel(): ?string + { + return $this->externalLabel; + } + + /** + * @param ?string $value + */ + public function setExternalLabel(?string $value = null): self + { + $this->externalLabel = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?TicketStateDetailedTicketTypes + */ + public function getTicketTypes(): ?TicketStateDetailedTicketTypes + { + return $this->ticketTypes; + } + + /** + * @param ?TicketStateDetailedTicketTypes $value + */ + public function setTicketTypes(?TicketStateDetailedTicketTypes $value = null): self + { + $this->ticketTypes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketStateDetailedCategory.php b/src/Unstable/Tickets/Types/TicketStateDetailedCategory.php new file mode 100644 index 00000000..dd7b3c8e --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketStateDetailedCategory.php @@ -0,0 +1,11 @@ + $data A list of ticket type attributes associated with a given ticket type. + */ + #[JsonProperty('data'), ArrayType([new Union(TicketType::class, 'null')])] + private ?array $data; + + /** + * @param array{ + * type?: ?string, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketType.php b/src/Unstable/Tickets/Types/TicketType.php new file mode 100644 index 00000000..1a3b00da --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketType.php @@ -0,0 +1,330 @@ + $category Category of the Ticket Type. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?string $name The name of the ticket type + */ + #[JsonProperty('name')] + private ?string $name; + + /** + * @var ?string $description The description of the ticket type + */ + #[JsonProperty('description')] + private ?string $description; + + /** + * @var ?string $icon The icon of the ticket type + */ + #[JsonProperty('icon')] + private ?string $icon; + + /** + * @var ?string $workspaceId The id of the workspace that the ticket type belongs to. + */ + #[JsonProperty('workspace_id')] + private ?string $workspaceId; + + /** + * @var ?TicketTypeAttributeList $ticketTypeAttributes + */ + #[JsonProperty('ticket_type_attributes')] + private ?TicketTypeAttributeList $ticketTypeAttributes; + + /** + * @var ?TicketTypeTicketStates $ticketStates A list of ticket states associated with a given ticket type. + */ + #[JsonProperty('ticket_states')] + private ?TicketTypeTicketStates $ticketStates; + + /** + * @var ?bool $archived Whether the ticket type is archived or not. + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?int $createdAt The date and time the ticket type was created. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The date and time the ticket type was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * category?: ?value-of, + * name?: ?string, + * description?: ?string, + * icon?: ?string, + * workspaceId?: ?string, + * ticketTypeAttributes?: ?TicketTypeAttributeList, + * ticketStates?: ?TicketTypeTicketStates, + * archived?: ?bool, + * createdAt?: ?int, + * updatedAt?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->category = $values['category'] ?? null; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->icon = $values['icon'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->ticketTypeAttributes = $values['ticketTypeAttributes'] ?? null; + $this->ticketStates = $values['ticketStates'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param ?string $value + */ + public function setIcon(?string $value = null): self + { + $this->icon = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?TicketTypeAttributeList + */ + public function getTicketTypeAttributes(): ?TicketTypeAttributeList + { + return $this->ticketTypeAttributes; + } + + /** + * @param ?TicketTypeAttributeList $value + */ + public function setTicketTypeAttributes(?TicketTypeAttributeList $value = null): self + { + $this->ticketTypeAttributes = $value; + return $this; + } + + /** + * @return ?TicketTypeTicketStates + */ + public function getTicketStates(): ?TicketTypeTicketStates + { + return $this->ticketStates; + } + + /** + * @param ?TicketTypeTicketStates $value + */ + public function setTicketStates(?TicketTypeTicketStates $value = null): self + { + $this->ticketStates = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Tickets/Types/TicketTypeCategory.php b/src/Unstable/Tickets/Types/TicketTypeCategory.php new file mode 100644 index 00000000..243c3428 --- /dev/null +++ b/src/Unstable/Tickets/Types/TicketTypeCategory.php @@ -0,0 +1,10 @@ + $data A list of ticket states associated with a given ticket type. + */ + #[JsonProperty('data'), ArrayType([new Union(TicketState::class, 'null')])] + private ?array $data; + + /** + * @param array{ + * type?: ?string, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Traits/ContactReference.php b/src/Unstable/Traits/ContactReference.php new file mode 100644 index 00000000..b1fd8936 --- /dev/null +++ b/src/Unstable/Traits/ContactReference.php @@ -0,0 +1,84 @@ +type; + } + + /** + * @param ?'contact' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } +} diff --git a/src/Unstable/Traits/ContactReplyBaseRequest.php b/src/Unstable/Traits/ContactReplyBaseRequest.php new file mode 100644 index 00000000..d387c228 --- /dev/null +++ b/src/Unstable/Traits/ContactReplyBaseRequest.php @@ -0,0 +1,156 @@ + $attachmentUrls + * @property ?array $replyOptions + */ +trait ContactReplyBaseRequest +{ + /** + * @var 'comment' $messageType + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var 'user' $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $body The text body of the comment. + */ + #[JsonProperty('body')] + private string $body; + + /** + * @var ?int $createdAt The time the reply was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @var ?array $replyOptions The quick reply selection the contact wishes to respond with. These map to buttons displayed in the Messenger UI if sent by a bot, or the reply options sent by an Admin via the API. + */ + #[JsonProperty('reply_options'), ArrayType([ContactReplyBaseRequestReplyOptionsItem::class])] + private ?array $replyOptions; + + /** + * @return 'comment' + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param 'comment' $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'user' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'user' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReplyOptions(): ?array + { + return $this->replyOptions; + } + + /** + * @param ?array $value + */ + public function setReplyOptions(?array $value = null): self + { + $this->replyOptions = $value; + return $this; + } +} diff --git a/src/Unstable/Traits/CreateTicketRequestBody.php b/src/Unstable/Traits/CreateTicketRequestBody.php new file mode 100644 index 00000000..f76dc3b6 --- /dev/null +++ b/src/Unstable/Traits/CreateTicketRequestBody.php @@ -0,0 +1,184 @@ + $contacts + * @property ?string $conversationToLinkId + * @property ?string $companyId + * @property ?int $createdAt + * @property ?CreateTicketRequestAssignment $assignment + */ +trait CreateTicketRequestBody +{ + /** + * @var string $ticketTypeId The ID of the type of ticket you want to create + */ + #[JsonProperty('ticket_type_id')] + private string $ticketTypeId; + + /** + * @var array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> $contacts The list of contacts (users or leads) affected by this ticket. Currently only one is allowed + */ + #[JsonProperty('contacts'), ArrayType([new Union(CreateTicketRequestContactsItemId::class, CreateTicketRequestContactsItemExternalId::class, CreateTicketRequestContactsItemEmail::class)])] + private array $contacts; + + /** + * The ID of the conversation you want to link to the ticket. Here are the valid ways of linking two tickets: + * - conversation | back-office ticket + * - customer tickets | non-shared back-office ticket + * - conversation | tracker ticket + * - customer ticket | tracker ticket + * + * @var ?string $conversationToLinkId + */ + #[JsonProperty('conversation_to_link_id')] + private ?string $conversationToLinkId; + + /** + * @var ?string $companyId The ID of the company that the ticket is associated with. The unique identifier for the company which is given by Intercom + */ + #[JsonProperty('company_id')] + private ?string $companyId; + + /** + * @var ?int $createdAt The time the ticket was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?CreateTicketRequestAssignment $assignment + */ + #[JsonProperty('assignment')] + private ?CreateTicketRequestAssignment $assignment; + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> + */ + public function getContacts(): array + { + return $this->contacts; + } + + /** + * @param array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> $value + */ + public function setContacts(array $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ?string + */ + public function getConversationToLinkId(): ?string + { + return $this->conversationToLinkId; + } + + /** + * @param ?string $value + */ + public function setConversationToLinkId(?string $value = null): self + { + $this->conversationToLinkId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?CreateTicketRequestAssignment + */ + public function getAssignment(): ?CreateTicketRequestAssignment + { + return $this->assignment; + } + + /** + * @param ?CreateTicketRequestAssignment $value + */ + public function setAssignment(?CreateTicketRequestAssignment $value = null): self + { + $this->assignment = $value; + return $this; + } +} diff --git a/src/Unstable/Traits/CustomChannelBaseEvent.php b/src/Unstable/Traits/CustomChannelBaseEvent.php new file mode 100644 index 00000000..3fd4113a --- /dev/null +++ b/src/Unstable/Traits/CustomChannelBaseEvent.php @@ -0,0 +1,83 @@ +eventId; + } + + /** + * @param string $value + */ + public function setEventId(string $value): self + { + $this->eventId = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalConversationId(): string + { + return $this->externalConversationId; + } + + /** + * @param string $value + */ + public function setExternalConversationId(string $value): self + { + $this->externalConversationId = $value; + return $this; + } + + /** + * @return CustomChannelContact + */ + public function getContact(): CustomChannelContact + { + return $this->contact; + } + + /** + * @param CustomChannelContact $value + */ + public function setContact(CustomChannelContact $value): self + { + $this->contact = $value; + return $this; + } +} diff --git a/src/Unstable/Traits/QuickReplyOption.php b/src/Unstable/Traits/QuickReplyOption.php new file mode 100644 index 00000000..65ba7beb --- /dev/null +++ b/src/Unstable/Traits/QuickReplyOption.php @@ -0,0 +1,58 @@ +text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * @param string $value + */ + public function setUuid(string $value): self + { + $this->uuid = $value; + return $this; + } +} diff --git a/src/Unstable/Types/ActivityLog.php b/src/Unstable/Types/ActivityLog.php new file mode 100644 index 00000000..dd2f298e --- /dev/null +++ b/src/Unstable/Types/ActivityLog.php @@ -0,0 +1,179 @@ + $activityType + */ + #[JsonProperty('activity_type')] + private ?string $activityType; + + /** + * @var ?string $activityDescription A sentence or two describing the activity. + */ + #[JsonProperty('activity_description')] + private ?string $activityDescription; + + /** + * @param array{ + * id?: ?string, + * performedBy?: ?ActivityLogPerformedBy, + * metadata?: ?ActivityLogMetadata, + * createdAt?: ?int, + * activityType?: ?value-of, + * activityDescription?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->id = $values['id'] ?? null; + $this->performedBy = $values['performedBy'] ?? null; + $this->metadata = $values['metadata'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->activityType = $values['activityType'] ?? null; + $this->activityDescription = $values['activityDescription'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?ActivityLogPerformedBy + */ + public function getPerformedBy(): ?ActivityLogPerformedBy + { + return $this->performedBy; + } + + /** + * @param ?ActivityLogPerformedBy $value + */ + public function setPerformedBy(?ActivityLogPerformedBy $value = null): self + { + $this->performedBy = $value; + return $this; + } + + /** + * @return ?ActivityLogMetadata + */ + public function getMetadata(): ?ActivityLogMetadata + { + return $this->metadata; + } + + /** + * @param ?ActivityLogMetadata $value + */ + public function setMetadata(?ActivityLogMetadata $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getActivityType(): ?string + { + return $this->activityType; + } + + /** + * @param ?value-of $value + */ + public function setActivityType(?string $value = null): self + { + $this->activityType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getActivityDescription(): ?string + { + return $this->activityDescription; + } + + /** + * @param ?string $value + */ + public function setActivityDescription(?string $value = null): self + { + $this->activityDescription = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ActivityLogActivityType.php b/src/Unstable/Types/ActivityLogActivityType.php new file mode 100644 index 00000000..f8cddd31 --- /dev/null +++ b/src/Unstable/Types/ActivityLogActivityType.php @@ -0,0 +1,74 @@ + $activityLogs An array of activity logs + */ + #[JsonProperty('activity_logs'), ArrayType([new Union(ActivityLog::class, 'null')])] + private ?array $activityLogs; + + /** + * @param array{ + * type?: ?string, + * pages?: ?CursorPages, + * activityLogs?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->activityLogs = $values['activityLogs'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?array + */ + public function getActivityLogs(): ?array + { + return $this->activityLogs; + } + + /** + * @param ?array $value + */ + public function setActivityLogs(?array $value = null): self + { + $this->activityLogs = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ActivityLogMetadata.php b/src/Unstable/Types/ActivityLogMetadata.php new file mode 100644 index 00000000..c66967db --- /dev/null +++ b/src/Unstable/Types/ActivityLogMetadata.php @@ -0,0 +1,254 @@ +signInMethod = $values['signInMethod'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->awayMode = $values['awayMode'] ?? null; + $this->awayStatusReason = $values['awayStatusReason'] ?? null; + $this->reassignConversations = $values['reassignConversations'] ?? null; + $this->source = $values['source'] ?? null; + $this->autoChanged = $values['autoChanged'] ?? null; + $this->updateBy = $values['updateBy'] ?? null; + $this->updateByName = $values['updateByName'] ?? null; + } + + /** + * @return ?string + */ + public function getSignInMethod(): ?string + { + return $this->signInMethod; + } + + /** + * @param ?string $value + */ + public function setSignInMethod(?string $value = null): self + { + $this->signInMethod = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAwayMode(): ?bool + { + return $this->awayMode; + } + + /** + * @param ?bool $value + */ + public function setAwayMode(?bool $value = null): self + { + $this->awayMode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAwayStatusReason(): ?string + { + return $this->awayStatusReason; + } + + /** + * @param ?string $value + */ + public function setAwayStatusReason(?string $value = null): self + { + $this->awayStatusReason = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getReassignConversations(): ?bool + { + return $this->reassignConversations; + } + + /** + * @param ?bool $value + */ + public function setReassignConversations(?bool $value = null): self + { + $this->reassignConversations = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSource(): ?string + { + return $this->source; + } + + /** + * @param ?string $value + */ + public function setSource(?string $value = null): self + { + $this->source = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAutoChanged(): ?string + { + return $this->autoChanged; + } + + /** + * @param ?string $value + */ + public function setAutoChanged(?string $value = null): self + { + $this->autoChanged = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdateBy(): ?int + { + return $this->updateBy; + } + + /** + * @param ?int $value + */ + public function setUpdateBy(?int $value = null): self + { + $this->updateBy = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUpdateByName(): ?string + { + return $this->updateByName; + } + + /** + * @param ?string $value + */ + public function setUpdateByName(?string $value = null): self + { + $this->updateByName = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ActivityLogPerformedBy.php b/src/Unstable/Types/ActivityLogPerformedBy.php new file mode 100644 index 00000000..193efe80 --- /dev/null +++ b/src/Unstable/Types/ActivityLogPerformedBy.php @@ -0,0 +1,129 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->email = $values['email'] ?? null; + $this->ip = $values['ip'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIp(): ?string + { + return $this->ip; + } + + /** + * @param ?string $value + */ + public function setIp(?string $value = null): self + { + $this->ip = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AddressableList.php b/src/Unstable/Types/AddressableList.php new file mode 100644 index 00000000..86dfd529 --- /dev/null +++ b/src/Unstable/Types/AddressableList.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->url = $values['url'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminList.php b/src/Unstable/Types/AdminList.php new file mode 100644 index 00000000..eb44133d --- /dev/null +++ b/src/Unstable/Types/AdminList.php @@ -0,0 +1,82 @@ + $admins A list of admins associated with a given workspace. + */ + #[JsonProperty('admins'), ArrayType([new Union(Admin::class, 'null')])] + private ?array $admins; + + /** + * @param array{ + * type?: ?string, + * admins?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->admins = $values['admins'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAdmins(): ?array + { + return $this->admins; + } + + /** + * @param ?array $value + */ + public function setAdmins(?array $value = null): self + { + $this->admins = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminPriorityLevel.php b/src/Unstable/Types/AdminPriorityLevel.php new file mode 100644 index 00000000..db73a767 --- /dev/null +++ b/src/Unstable/Types/AdminPriorityLevel.php @@ -0,0 +1,80 @@ + $primaryAdminIds The primary admin ids for the team + */ + #[JsonProperty('primary_admin_ids'), ArrayType(['integer'])] + private ?array $primaryAdminIds; + + /** + * @var ?array $secondaryAdminIds The secondary admin ids for the team + */ + #[JsonProperty('secondary_admin_ids'), ArrayType(['integer'])] + private ?array $secondaryAdminIds; + + /** + * @param array{ + * primaryAdminIds?: ?array, + * secondaryAdminIds?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->primaryAdminIds = $values['primaryAdminIds'] ?? null; + $this->secondaryAdminIds = $values['secondaryAdminIds'] ?? null; + } + + /** + * @return ?array + */ + public function getPrimaryAdminIds(): ?array + { + return $this->primaryAdminIds; + } + + /** + * @param ?array $value + */ + public function setPrimaryAdminIds(?array $value = null): self + { + $this->primaryAdminIds = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSecondaryAdminIds(): ?array + { + return $this->secondaryAdminIds; + } + + /** + * @param ?array $value + */ + public function setSecondaryAdminIds(?array $value = null): self + { + $this->secondaryAdminIds = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminReplyConversationRequest.php b/src/Unstable/Types/AdminReplyConversationRequest.php new file mode 100644 index 00000000..4e6b3c09 --- /dev/null +++ b/src/Unstable/Types/AdminReplyConversationRequest.php @@ -0,0 +1,230 @@ + $messageType + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var 'admin' $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var ?string $body The text body of the reply. Notes accept some HTML formatting. Must be present for comment and note message types. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var string $adminId The id of the admin who is authoring the comment. + */ + #[JsonProperty('admin_id')] + private string $adminId; + + /** + * @var ?int $createdAt The time the reply was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $replyOptions The quick reply options to display to the end user. Must be present for quick_reply message types. + */ + #[JsonProperty('reply_options'), ArrayType([QuickReplyOption::class])] + private ?array $replyOptions; + + /** + * @var ?array $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @var ?array $attachmentFiles A list of files that will be added as attachments. You can include up to 10 files + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: value-of, + * type: 'admin', + * adminId: string, + * body?: ?string, + * createdAt?: ?int, + * replyOptions?: ?array, + * attachmentUrls?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body'] ?? null; + $this->adminId = $values['adminId']; + $this->createdAt = $values['createdAt'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return value-of + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param value-of $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReplyOptions(): ?array + { + return $this->replyOptions; + } + + /** + * @param ?array $value + */ + public function setReplyOptions(?array $value = null): self + { + $this->replyOptions = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminReplyConversationRequestMessageType.php b/src/Unstable/Types/AdminReplyConversationRequestMessageType.php new file mode 100644 index 00000000..4d45439e --- /dev/null +++ b/src/Unstable/Types/AdminReplyConversationRequestMessageType.php @@ -0,0 +1,10 @@ + $messageType + */ + #[JsonProperty('message_type')] + private string $messageType; + + /** + * @var 'admin' $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var ?string $body The text body of the reply. Notes accept some HTML formatting. Must be present for comment and note message types. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var string $adminId The id of the admin who is authoring the comment. + */ + #[JsonProperty('admin_id')] + private string $adminId; + + /** + * @var ?int $createdAt The time the reply was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?array $replyOptions The quick reply options to display. Must be present for quick_reply message types. + */ + #[JsonProperty('reply_options'), ArrayType([AdminReplyTicketRequestReplyOptionsItem::class])] + private ?array $replyOptions; + + /** + * @var ?array $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @param array{ + * messageType: value-of, + * type: 'admin', + * adminId: string, + * body?: ?string, + * createdAt?: ?int, + * replyOptions?: ?array, + * attachmentUrls?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body'] ?? null; + $this->adminId = $values['adminId']; + $this->createdAt = $values['createdAt'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + } + + /** + * @return value-of + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param value-of $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReplyOptions(): ?array + { + return $this->replyOptions; + } + + /** + * @param ?array $value + */ + public function setReplyOptions(?array $value = null): self + { + $this->replyOptions = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminReplyTicketRequestMessageType.php b/src/Unstable/Types/AdminReplyTicketRequestMessageType.php new file mode 100644 index 00000000..57ba2d07 --- /dev/null +++ b/src/Unstable/Types/AdminReplyTicketRequestMessageType.php @@ -0,0 +1,10 @@ +text = $values['text']; + $this->uuid = $values['uuid']; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * @param string $value + */ + public function setUuid(string $value): self + { + $this->uuid = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminWithApp.php b/src/Unstable/Types/AdminWithApp.php new file mode 100644 index 00000000..ad0cc479 --- /dev/null +++ b/src/Unstable/Types/AdminWithApp.php @@ -0,0 +1,330 @@ + $teamIds This is a list of ids of the teams that this admin is part of. + */ + #[JsonProperty('team_ids'), ArrayType(['integer'])] + private ?array $teamIds; + + /** + * @var ?AdminWithAppAvatar $avatar This object represents the avatar associated with the admin. + */ + #[JsonProperty('avatar')] + private ?AdminWithAppAvatar $avatar; + + /** + * @var ?bool $emailVerified Identifies if this admin's email is verified. + */ + #[JsonProperty('email_verified')] + private ?bool $emailVerified; + + /** + * @var ?App $app App that the admin belongs to. + */ + #[JsonProperty('app')] + private ?App $app; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * name?: ?string, + * email?: ?string, + * jobTitle?: ?string, + * awayModeEnabled?: ?bool, + * awayModeReassign?: ?bool, + * hasInboxSeat?: ?bool, + * teamIds?: ?array, + * avatar?: ?AdminWithAppAvatar, + * emailVerified?: ?bool, + * app?: ?App, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->email = $values['email'] ?? null; + $this->jobTitle = $values['jobTitle'] ?? null; + $this->awayModeEnabled = $values['awayModeEnabled'] ?? null; + $this->awayModeReassign = $values['awayModeReassign'] ?? null; + $this->hasInboxSeat = $values['hasInboxSeat'] ?? null; + $this->teamIds = $values['teamIds'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->emailVerified = $values['emailVerified'] ?? null; + $this->app = $values['app'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getJobTitle(): ?string + { + return $this->jobTitle; + } + + /** + * @param ?string $value + */ + public function setJobTitle(?string $value = null): self + { + $this->jobTitle = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAwayModeEnabled(): ?bool + { + return $this->awayModeEnabled; + } + + /** + * @param ?bool $value + */ + public function setAwayModeEnabled(?bool $value = null): self + { + $this->awayModeEnabled = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAwayModeReassign(): ?bool + { + return $this->awayModeReassign; + } + + /** + * @param ?bool $value + */ + public function setAwayModeReassign(?bool $value = null): self + { + $this->awayModeReassign = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasInboxSeat(): ?bool + { + return $this->hasInboxSeat; + } + + /** + * @param ?bool $value + */ + public function setHasInboxSeat(?bool $value = null): self + { + $this->hasInboxSeat = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTeamIds(): ?array + { + return $this->teamIds; + } + + /** + * @param ?array $value + */ + public function setTeamIds(?array $value = null): self + { + $this->teamIds = $value; + return $this; + } + + /** + * @return ?AdminWithAppAvatar + */ + public function getAvatar(): ?AdminWithAppAvatar + { + return $this->avatar; + } + + /** + * @param ?AdminWithAppAvatar $value + */ + public function setAvatar(?AdminWithAppAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getEmailVerified(): ?bool + { + return $this->emailVerified; + } + + /** + * @param ?bool $value + */ + public function setEmailVerified(?bool $value = null): self + { + $this->emailVerified = $value; + return $this; + } + + /** + * @return ?App + */ + public function getApp(): ?App + { + return $this->app; + } + + /** + * @param ?App $value + */ + public function setApp(?App $value = null): self + { + $this->app = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AdminWithAppAvatar.php b/src/Unstable/Types/AdminWithAppAvatar.php new file mode 100644 index 00000000..d4874fad --- /dev/null +++ b/src/Unstable/Types/AdminWithAppAvatar.php @@ -0,0 +1,79 @@ +type = $values['type'] ?? null; + $this->imageUrl = $values['imageUrl'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * @param ?string $value + */ + public function setImageUrl(?string $value = null): self + { + $this->imageUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/App.php b/src/Unstable/Types/App.php new file mode 100644 index 00000000..dacc0a3e --- /dev/null +++ b/src/Unstable/Types/App.php @@ -0,0 +1,204 @@ +type = $values['type'] ?? null; + $this->idCode = $values['idCode'] ?? null; + $this->name = $values['name'] ?? null; + $this->region = $values['region'] ?? null; + $this->timezone = $values['timezone'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->identityVerification = $values['identityVerification'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIdCode(): ?string + { + return $this->idCode; + } + + /** + * @param ?string $value + */ + public function setIdCode(?string $value = null): self + { + $this->idCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRegion(): ?string + { + return $this->region; + } + + /** + * @param ?string $value + */ + public function setRegion(?string $value = null): self + { + $this->region = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTimezone(): ?string + { + return $this->timezone; + } + + /** + * @param ?string $value + */ + public function setTimezone(?string $value = null): self + { + $this->timezone = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIdentityVerification(): ?bool + { + return $this->identityVerification; + } + + /** + * @param ?bool $value + */ + public function setIdentityVerification(?bool $value = null): self + { + $this->identityVerification = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ArticleContent.php b/src/Unstable/Types/ArticleContent.php new file mode 100644 index 00000000..5a9cd884 --- /dev/null +++ b/src/Unstable/Types/ArticleContent.php @@ -0,0 +1,254 @@ + $state Whether the article is `published` or is a `draft` . + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?int $createdAt The time when the article was created (seconds). + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The time when the article was last updated (seconds). + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?string $url The URL of the article. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @param array{ + * type?: ?string, + * title?: ?string, + * description?: ?string, + * body?: ?string, + * authorId?: ?int, + * state?: ?value-of, + * createdAt?: ?int, + * updatedAt?: ?int, + * url?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->title = $values['title'] ?? null; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId'] ?? null; + $this->state = $values['state'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->url = $values['url'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAuthorId(): ?int + { + return $this->authorId; + } + + /** + * @param ?int $value + */ + public function setAuthorId(?int $value = null): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ArticleContentState.php b/src/Unstable/Types/ArticleContentState.php new file mode 100644 index 00000000..dd1c77d2 --- /dev/null +++ b/src/Unstable/Types/ArticleContentState.php @@ -0,0 +1,9 @@ + $data An array of Article objects + */ + #[JsonProperty('data'), ArrayType([ArticleListItem::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * pages?: ?CursorPages, + * totalCount?: ?int, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ArticleStatistics.php b/src/Unstable/Types/ArticleStatistics.php new file mode 100644 index 00000000..7f34b7fc --- /dev/null +++ b/src/Unstable/Types/ArticleStatistics.php @@ -0,0 +1,204 @@ +type = $values['type'] ?? null; + $this->views = $values['views'] ?? null; + $this->conversions = $values['conversions'] ?? null; + $this->reactions = $values['reactions'] ?? null; + $this->happyReactionPercentage = $values['happyReactionPercentage'] ?? null; + $this->neutralReactionPercentage = $values['neutralReactionPercentage'] ?? null; + $this->sadReactionPercentage = $values['sadReactionPercentage'] ?? null; + } + + /** + * @return ?'article_statistics' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'article_statistics' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getViews(): ?int + { + return $this->views; + } + + /** + * @param ?int $value + */ + public function setViews(?int $value = null): self + { + $this->views = $value; + return $this; + } + + /** + * @return ?int + */ + public function getConversions(): ?int + { + return $this->conversions; + } + + /** + * @param ?int $value + */ + public function setConversions(?int $value = null): self + { + $this->conversions = $value; + return $this; + } + + /** + * @return ?int + */ + public function getReactions(): ?int + { + return $this->reactions; + } + + /** + * @param ?int $value + */ + public function setReactions(?int $value = null): self + { + $this->reactions = $value; + return $this; + } + + /** + * @return ?float + */ + public function getHappyReactionPercentage(): ?float + { + return $this->happyReactionPercentage; + } + + /** + * @param ?float $value + */ + public function setHappyReactionPercentage(?float $value = null): self + { + $this->happyReactionPercentage = $value; + return $this; + } + + /** + * @return ?float + */ + public function getNeutralReactionPercentage(): ?float + { + return $this->neutralReactionPercentage; + } + + /** + * @param ?float $value + */ + public function setNeutralReactionPercentage(?float $value = null): self + { + $this->neutralReactionPercentage = $value; + return $this; + } + + /** + * @return ?float + */ + public function getSadReactionPercentage(): ?float + { + return $this->sadReactionPercentage; + } + + /** + * @param ?float $value + */ + public function setSadReactionPercentage(?float $value = null): self + { + $this->sadReactionPercentage = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ArticleTranslatedContent.php b/src/Unstable/Types/ArticleTranslatedContent.php new file mode 100644 index 00000000..f0a79fac --- /dev/null +++ b/src/Unstable/Types/ArticleTranslatedContent.php @@ -0,0 +1,979 @@ +type = $values['type'] ?? null; + $this->ar = $values['ar'] ?? null; + $this->bg = $values['bg'] ?? null; + $this->bs = $values['bs'] ?? null; + $this->ca = $values['ca'] ?? null; + $this->cs = $values['cs'] ?? null; + $this->da = $values['da'] ?? null; + $this->de = $values['de'] ?? null; + $this->el = $values['el'] ?? null; + $this->en = $values['en'] ?? null; + $this->es = $values['es'] ?? null; + $this->et = $values['et'] ?? null; + $this->fi = $values['fi'] ?? null; + $this->fr = $values['fr'] ?? null; + $this->he = $values['he'] ?? null; + $this->hr = $values['hr'] ?? null; + $this->hu = $values['hu'] ?? null; + $this->id = $values['id'] ?? null; + $this->it = $values['it'] ?? null; + $this->ja = $values['ja'] ?? null; + $this->ko = $values['ko'] ?? null; + $this->lt = $values['lt'] ?? null; + $this->lv = $values['lv'] ?? null; + $this->mn = $values['mn'] ?? null; + $this->nb = $values['nb'] ?? null; + $this->nl = $values['nl'] ?? null; + $this->pl = $values['pl'] ?? null; + $this->pt = $values['pt'] ?? null; + $this->ro = $values['ro'] ?? null; + $this->ru = $values['ru'] ?? null; + $this->sl = $values['sl'] ?? null; + $this->sr = $values['sr'] ?? null; + $this->sv = $values['sv'] ?? null; + $this->tr = $values['tr'] ?? null; + $this->vi = $values['vi'] ?? null; + $this->ptBr = $values['ptBr'] ?? null; + $this->zhCn = $values['zhCn'] ?? null; + $this->zhTw = $values['zhTw'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getAr(): ?ArticleContent + { + return $this->ar; + } + + /** + * @param ?ArticleContent $value + */ + public function setAr(?ArticleContent $value = null): self + { + $this->ar = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getBg(): ?ArticleContent + { + return $this->bg; + } + + /** + * @param ?ArticleContent $value + */ + public function setBg(?ArticleContent $value = null): self + { + $this->bg = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getBs(): ?ArticleContent + { + return $this->bs; + } + + /** + * @param ?ArticleContent $value + */ + public function setBs(?ArticleContent $value = null): self + { + $this->bs = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getCa(): ?ArticleContent + { + return $this->ca; + } + + /** + * @param ?ArticleContent $value + */ + public function setCa(?ArticleContent $value = null): self + { + $this->ca = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getCs(): ?ArticleContent + { + return $this->cs; + } + + /** + * @param ?ArticleContent $value + */ + public function setCs(?ArticleContent $value = null): self + { + $this->cs = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getDa(): ?ArticleContent + { + return $this->da; + } + + /** + * @param ?ArticleContent $value + */ + public function setDa(?ArticleContent $value = null): self + { + $this->da = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getDe(): ?ArticleContent + { + return $this->de; + } + + /** + * @param ?ArticleContent $value + */ + public function setDe(?ArticleContent $value = null): self + { + $this->de = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEl(): ?ArticleContent + { + return $this->el; + } + + /** + * @param ?ArticleContent $value + */ + public function setEl(?ArticleContent $value = null): self + { + $this->el = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEn(): ?ArticleContent + { + return $this->en; + } + + /** + * @param ?ArticleContent $value + */ + public function setEn(?ArticleContent $value = null): self + { + $this->en = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEs(): ?ArticleContent + { + return $this->es; + } + + /** + * @param ?ArticleContent $value + */ + public function setEs(?ArticleContent $value = null): self + { + $this->es = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getEt(): ?ArticleContent + { + return $this->et; + } + + /** + * @param ?ArticleContent $value + */ + public function setEt(?ArticleContent $value = null): self + { + $this->et = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getFi(): ?ArticleContent + { + return $this->fi; + } + + /** + * @param ?ArticleContent $value + */ + public function setFi(?ArticleContent $value = null): self + { + $this->fi = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getFr(): ?ArticleContent + { + return $this->fr; + } + + /** + * @param ?ArticleContent $value + */ + public function setFr(?ArticleContent $value = null): self + { + $this->fr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getHe(): ?ArticleContent + { + return $this->he; + } + + /** + * @param ?ArticleContent $value + */ + public function setHe(?ArticleContent $value = null): self + { + $this->he = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getHr(): ?ArticleContent + { + return $this->hr; + } + + /** + * @param ?ArticleContent $value + */ + public function setHr(?ArticleContent $value = null): self + { + $this->hr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getHu(): ?ArticleContent + { + return $this->hu; + } + + /** + * @param ?ArticleContent $value + */ + public function setHu(?ArticleContent $value = null): self + { + $this->hu = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getId(): ?ArticleContent + { + return $this->id; + } + + /** + * @param ?ArticleContent $value + */ + public function setId(?ArticleContent $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getIt(): ?ArticleContent + { + return $this->it; + } + + /** + * @param ?ArticleContent $value + */ + public function setIt(?ArticleContent $value = null): self + { + $this->it = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getJa(): ?ArticleContent + { + return $this->ja; + } + + /** + * @param ?ArticleContent $value + */ + public function setJa(?ArticleContent $value = null): self + { + $this->ja = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getKo(): ?ArticleContent + { + return $this->ko; + } + + /** + * @param ?ArticleContent $value + */ + public function setKo(?ArticleContent $value = null): self + { + $this->ko = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getLt(): ?ArticleContent + { + return $this->lt; + } + + /** + * @param ?ArticleContent $value + */ + public function setLt(?ArticleContent $value = null): self + { + $this->lt = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getLv(): ?ArticleContent + { + return $this->lv; + } + + /** + * @param ?ArticleContent $value + */ + public function setLv(?ArticleContent $value = null): self + { + $this->lv = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getMn(): ?ArticleContent + { + return $this->mn; + } + + /** + * @param ?ArticleContent $value + */ + public function setMn(?ArticleContent $value = null): self + { + $this->mn = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getNb(): ?ArticleContent + { + return $this->nb; + } + + /** + * @param ?ArticleContent $value + */ + public function setNb(?ArticleContent $value = null): self + { + $this->nb = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getNl(): ?ArticleContent + { + return $this->nl; + } + + /** + * @param ?ArticleContent $value + */ + public function setNl(?ArticleContent $value = null): self + { + $this->nl = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getPl(): ?ArticleContent + { + return $this->pl; + } + + /** + * @param ?ArticleContent $value + */ + public function setPl(?ArticleContent $value = null): self + { + $this->pl = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getPt(): ?ArticleContent + { + return $this->pt; + } + + /** + * @param ?ArticleContent $value + */ + public function setPt(?ArticleContent $value = null): self + { + $this->pt = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getRo(): ?ArticleContent + { + return $this->ro; + } + + /** + * @param ?ArticleContent $value + */ + public function setRo(?ArticleContent $value = null): self + { + $this->ro = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getRu(): ?ArticleContent + { + return $this->ru; + } + + /** + * @param ?ArticleContent $value + */ + public function setRu(?ArticleContent $value = null): self + { + $this->ru = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getSl(): ?ArticleContent + { + return $this->sl; + } + + /** + * @param ?ArticleContent $value + */ + public function setSl(?ArticleContent $value = null): self + { + $this->sl = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getSr(): ?ArticleContent + { + return $this->sr; + } + + /** + * @param ?ArticleContent $value + */ + public function setSr(?ArticleContent $value = null): self + { + $this->sr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getSv(): ?ArticleContent + { + return $this->sv; + } + + /** + * @param ?ArticleContent $value + */ + public function setSv(?ArticleContent $value = null): self + { + $this->sv = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getTr(): ?ArticleContent + { + return $this->tr; + } + + /** + * @param ?ArticleContent $value + */ + public function setTr(?ArticleContent $value = null): self + { + $this->tr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getVi(): ?ArticleContent + { + return $this->vi; + } + + /** + * @param ?ArticleContent $value + */ + public function setVi(?ArticleContent $value = null): self + { + $this->vi = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getPtBr(): ?ArticleContent + { + return $this->ptBr; + } + + /** + * @param ?ArticleContent $value + */ + public function setPtBr(?ArticleContent $value = null): self + { + $this->ptBr = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getZhCn(): ?ArticleContent + { + return $this->zhCn; + } + + /** + * @param ?ArticleContent $value + */ + public function setZhCn(?ArticleContent $value = null): self + { + $this->zhCn = $value; + return $this; + } + + /** + * @return ?ArticleContent + */ + public function getZhTw(): ?ArticleContent + { + return $this->zhTw; + } + + /** + * @param ?ArticleContent $value + */ + public function setZhTw(?ArticleContent $value = null): self + { + $this->zhTw = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AssignConversationRequest.php b/src/Unstable/Types/AssignConversationRequest.php new file mode 100644 index 00000000..a8f76623 --- /dev/null +++ b/src/Unstable/Types/AssignConversationRequest.php @@ -0,0 +1,129 @@ + $type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $adminId The id of the admin who is performing the action. + */ + #[JsonProperty('admin_id')] + private string $adminId; + + /** + * @var string $assigneeId The `id` of the `admin` or `team` which will be assigned the conversation. A conversation can be assigned both an admin and a team.\nSet `0` if you want this assign to no admin or team (ie. Unassigned). + */ + #[JsonProperty('assignee_id')] + private string $assigneeId; + + /** + * @var ?string $body Optionally you can send a response in the conversation when it is assigned. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @param array{ + * type: value-of, + * adminId: string, + * assigneeId: string, + * body?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->adminId = $values['adminId']; + $this->assigneeId = $values['assigneeId']; + $this->body = $values['body'] ?? null; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return string + */ + public function getAssigneeId(): string + { + return $this->assigneeId; + } + + /** + * @param string $value + */ + public function setAssigneeId(string $value): self + { + $this->assigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/AssignConversationRequestType.php b/src/Unstable/Types/AssignConversationRequestType.php new file mode 100644 index 00000000..26cbd92e --- /dev/null +++ b/src/Unstable/Types/AssignConversationRequestType.php @@ -0,0 +1,9 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->label = $values['label'] ?? null; + $this->emoji = $values['emoji'] ?? null; + $this->order = $values['order'] ?? null; + $this->deleted = $values['deleted'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLabel(): ?string + { + return $this->label; + } + + /** + * @param ?string $value + */ + public function setLabel(?string $value = null): self + { + $this->label = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmoji(): ?string + { + return $this->emoji; + } + + /** + * @param ?string $value + */ + public function setEmoji(?string $value = null): self + { + $this->emoji = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOrder(): ?int + { + return $this->order; + } + + /** + * @param ?int $value + */ + public function setOrder(?int $value = null): self + { + $this->order = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CloseConversationRequest.php b/src/Unstable/Types/CloseConversationRequest.php new file mode 100644 index 00000000..47036486 --- /dev/null +++ b/src/Unstable/Types/CloseConversationRequest.php @@ -0,0 +1,104 @@ +type = $values['type']; + $this->adminId = $values['adminId']; + $this->body = $values['body'] ?? null; + } + + /** + * @return 'admin' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'admin' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CollectionList.php b/src/Unstable/Types/CollectionList.php new file mode 100644 index 00000000..a5133dd2 --- /dev/null +++ b/src/Unstable/Types/CollectionList.php @@ -0,0 +1,131 @@ + $data An array of collection objects + */ + #[JsonProperty('data'), ArrayType([Collection::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * pages?: ?CursorPages, + * totalCount?: ?int, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CompanyAttachedContacts.php b/src/Unstable/Types/CompanyAttachedContacts.php new file mode 100644 index 00000000..76329af1 --- /dev/null +++ b/src/Unstable/Types/CompanyAttachedContacts.php @@ -0,0 +1,131 @@ + $data An array containing Contact Objects + */ + #[JsonProperty('data'), ArrayType([Contact::class])] + private ?array $data; + + /** + * @var ?int $totalCount The total number of contacts + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * totalCount?: ?int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CompanyAttachedSegments.php b/src/Unstable/Types/CompanyAttachedSegments.php new file mode 100644 index 00000000..4c830efa --- /dev/null +++ b/src/Unstable/Types/CompanyAttachedSegments.php @@ -0,0 +1,81 @@ + $data An array containing Segment Objects + */ + #[JsonProperty('data'), ArrayType([Segment::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CompanyData.php b/src/Unstable/Types/CompanyData.php new file mode 100644 index 00000000..301a7ce5 --- /dev/null +++ b/src/Unstable/Types/CompanyData.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->type = $values['type'] ?? null; + $this->url = $values['url'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'company' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'company' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CompanyList.php b/src/Unstable/Types/CompanyList.php new file mode 100644 index 00000000..76dbf331 --- /dev/null +++ b/src/Unstable/Types/CompanyList.php @@ -0,0 +1,131 @@ + $data An array containing Company Objects. + */ + #[JsonProperty('data'), ArrayType([Company::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * pages?: ?CursorPages, + * totalCount?: ?int, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CompanyScroll.php b/src/Unstable/Types/CompanyScroll.php new file mode 100644 index 00000000..c1873792 --- /dev/null +++ b/src/Unstable/Types/CompanyScroll.php @@ -0,0 +1,156 @@ + $data + */ + #[JsonProperty('data'), ArrayType([Company::class])] + private ?array $data; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @var ?int $totalCount The total number of companies + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?string $scrollParam The scroll parameter to use in the next request to fetch the next page of results. + */ + #[JsonProperty('scroll_param')] + private ?string $scrollParam; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * pages?: ?CursorPages, + * totalCount?: ?int, + * scrollParam?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->scrollParam = $values['scrollParam'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?string + */ + public function getScrollParam(): ?string + { + return $this->scrollParam; + } + + /** + * @param ?string $value + */ + public function setScrollParam(?string $value = null): self + { + $this->scrollParam = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactArchived.php b/src/Unstable/Types/ContactArchived.php new file mode 100644 index 00000000..d068de3a --- /dev/null +++ b/src/Unstable/Types/ContactArchived.php @@ -0,0 +1,63 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->archived = $values['archived'] ?? null; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactAttachedCompanies.php b/src/Unstable/Types/ContactAttachedCompanies.php new file mode 100644 index 00000000..7bfc2fce --- /dev/null +++ b/src/Unstable/Types/ContactAttachedCompanies.php @@ -0,0 +1,131 @@ + $companies An array containing Company Objects + */ + #[JsonProperty('companies'), ArrayType([Company::class])] + private ?array $companies; + + /** + * @var ?int $totalCount The total number of companies associated to this contact + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?PagesLink $pages + */ + #[JsonProperty('pages')] + private ?PagesLink $pages; + + /** + * @param array{ + * type?: ?'list', + * companies?: ?array, + * totalCount?: ?int, + * pages?: ?PagesLink, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCompanies(): ?array + { + return $this->companies; + } + + /** + * @param ?array $value + */ + public function setCompanies(?array $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?PagesLink + */ + public function getPages(): ?PagesLink + { + return $this->pages; + } + + /** + * @param ?PagesLink $value + */ + public function setPages(?PagesLink $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactBlocked.php b/src/Unstable/Types/ContactBlocked.php new file mode 100644 index 00000000..ee405652 --- /dev/null +++ b/src/Unstable/Types/ContactBlocked.php @@ -0,0 +1,63 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->blocked = $values['blocked'] ?? null; + } + + /** + * @return ?bool + */ + public function getBlocked(): ?bool + { + return $this->blocked; + } + + /** + * @param ?bool $value + */ + public function setBlocked(?bool $value = null): self + { + $this->blocked = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactCompanies.php b/src/Unstable/Types/ContactCompanies.php new file mode 100644 index 00000000..3d6d404d --- /dev/null +++ b/src/Unstable/Types/ContactCompanies.php @@ -0,0 +1,130 @@ + $data An array of company data objects attached to the contact. + */ + #[JsonProperty('data'), ArrayType([CompanyData::class])] + private ?array $data; + + /** + * @var ?string $url Url to get more company resources for this contact + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $totalCount Integer representing the total number of companies attached to this contact + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private ?bool $hasMore; + + /** + * @param array{ + * data?: ?array, + * url?: ?string, + * totalCount?: ?int, + * hasMore?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->data = $values['data'] ?? null; + $this->url = $values['url'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->hasMore = $values['hasMore'] ?? null; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasMore(): ?bool + { + return $this->hasMore; + } + + /** + * @param ?bool $value + */ + public function setHasMore(?bool $value = null): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactDeleted.php b/src/Unstable/Types/ContactDeleted.php new file mode 100644 index 00000000..d2801ec0 --- /dev/null +++ b/src/Unstable/Types/ContactDeleted.php @@ -0,0 +1,63 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactList.php b/src/Unstable/Types/ContactList.php new file mode 100644 index 00000000..24cf5a51 --- /dev/null +++ b/src/Unstable/Types/ContactList.php @@ -0,0 +1,131 @@ + $data The list of contact objects + */ + #[JsonProperty('data'), ArrayType([Contact::class])] + private ?array $data; + + /** + * @var ?int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * totalCount?: ?int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactLocation.php b/src/Unstable/Types/ContactLocation.php new file mode 100644 index 00000000..3641b47a --- /dev/null +++ b/src/Unstable/Types/ContactLocation.php @@ -0,0 +1,129 @@ +type = $values['type'] ?? null; + $this->country = $values['country'] ?? null; + $this->region = $values['region'] ?? null; + $this->city = $values['city'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCountry(): ?string + { + return $this->country; + } + + /** + * @param ?string $value + */ + public function setCountry(?string $value = null): self + { + $this->country = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRegion(): ?string + { + return $this->region; + } + + /** + * @param ?string $value + */ + public function setRegion(?string $value = null): self + { + $this->region = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCity(): ?string + { + return $this->city; + } + + /** + * @param ?string $value + */ + public function setCity(?string $value = null): self + { + $this->city = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactNotes.php b/src/Unstable/Types/ContactNotes.php new file mode 100644 index 00000000..7ac8ebf8 --- /dev/null +++ b/src/Unstable/Types/ContactNotes.php @@ -0,0 +1,130 @@ + $data This object represents the notes attached to a contact. + */ + #[JsonProperty('data'), ArrayType([AddressableList::class])] + private ?array $data; + + /** + * @var ?string $url Url to get more company resources for this contact + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $totalCount Int representing the total number of companyies attached to this contact + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private ?bool $hasMore; + + /** + * @param array{ + * data?: ?array, + * url?: ?string, + * totalCount?: ?int, + * hasMore?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->data = $values['data'] ?? null; + $this->url = $values['url'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->hasMore = $values['hasMore'] ?? null; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasMore(): ?bool + { + return $this->hasMore; + } + + /** + * @param ?bool $value + */ + public function setHasMore(?bool $value = null): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReference.php b/src/Unstable/Types/ContactReference.php new file mode 100644 index 00000000..24f9f150 --- /dev/null +++ b/src/Unstable/Types/ContactReference.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + } + + /** + * @return ?'contact' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'contact' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyBaseRequest.php b/src/Unstable/Types/ContactReplyBaseRequest.php new file mode 100644 index 00000000..97115018 --- /dev/null +++ b/src/Unstable/Types/ContactReplyBaseRequest.php @@ -0,0 +1,177 @@ + $attachmentUrls A list of image URLs that will be added as attachments. You can include up to 10 URLs. + */ + #[JsonProperty('attachment_urls'), ArrayType(['string'])] + private ?array $attachmentUrls; + + /** + * @var ?array $replyOptions The quick reply selection the contact wishes to respond with. These map to buttons displayed in the Messenger UI if sent by a bot, or the reply options sent by an Admin via the API. + */ + #[JsonProperty('reply_options'), ArrayType([ContactReplyBaseRequestReplyOptionsItem::class])] + private ?array $replyOptions; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * replyOptions?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + } + + /** + * @return 'comment' + */ + public function getMessageType(): string + { + return $this->messageType; + } + + /** + * @param 'comment' $value + */ + public function setMessageType(string $value): self + { + $this->messageType = $value; + return $this; + } + + /** + * @return 'user' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'user' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getBody(): string + { + return $this->body; + } + + /** + * @param string $value + */ + public function setBody(string $value): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentUrls(): ?array + { + return $this->attachmentUrls; + } + + /** + * @param ?array $value + */ + public function setAttachmentUrls(?array $value = null): self + { + $this->attachmentUrls = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReplyOptions(): ?array + { + return $this->replyOptions; + } + + /** + * @param ?array $value + */ + public function setReplyOptions(?array $value = null): self + { + $this->replyOptions = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyBaseRequestReplyOptionsItem.php b/src/Unstable/Types/ContactReplyBaseRequestReplyOptionsItem.php new file mode 100644 index 00000000..057d6829 --- /dev/null +++ b/src/Unstable/Types/ContactReplyBaseRequestReplyOptionsItem.php @@ -0,0 +1,76 @@ +text = $values['text']; + $this->uuid = $values['uuid']; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * @param string $value + */ + public function setUuid(string $value): self + { + $this->uuid = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyEmailRequest.php b/src/Unstable/Types/ContactReplyEmailRequest.php new file mode 100644 index 00000000..7771ba0a --- /dev/null +++ b/src/Unstable/Types/ContactReplyEmailRequest.php @@ -0,0 +1,95 @@ + $attachmentFiles A list of files that will be added as attachments. + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * email: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * replyOptions?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->email = $values['email']; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyIntercomUserIdRequest.php b/src/Unstable/Types/ContactReplyIntercomUserIdRequest.php new file mode 100644 index 00000000..3b55f201 --- /dev/null +++ b/src/Unstable/Types/ContactReplyIntercomUserIdRequest.php @@ -0,0 +1,95 @@ + $attachmentFiles A list of files that will be added as attachments. + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * intercomUserId: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * replyOptions?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->intercomUserId = $values['intercomUserId']; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyTicketEmailRequest.php b/src/Unstable/Types/ContactReplyTicketEmailRequest.php new file mode 100644 index 00000000..54b0c344 --- /dev/null +++ b/src/Unstable/Types/ContactReplyTicketEmailRequest.php @@ -0,0 +1,69 @@ +, + * replyOptions?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyTicketIntercomUserIdRequest.php b/src/Unstable/Types/ContactReplyTicketIntercomUserIdRequest.php new file mode 100644 index 00000000..4b5a79e0 --- /dev/null +++ b/src/Unstable/Types/ContactReplyTicketIntercomUserIdRequest.php @@ -0,0 +1,69 @@ +, + * replyOptions?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->intercomUserId = $values['intercomUserId']; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyTicketUserIdRequest.php b/src/Unstable/Types/ContactReplyTicketUserIdRequest.php new file mode 100644 index 00000000..79e818f6 --- /dev/null +++ b/src/Unstable/Types/ContactReplyTicketUserIdRequest.php @@ -0,0 +1,69 @@ +, + * replyOptions?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactReplyUserIdRequest.php b/src/Unstable/Types/ContactReplyUserIdRequest.php new file mode 100644 index 00000000..271453e1 --- /dev/null +++ b/src/Unstable/Types/ContactReplyUserIdRequest.php @@ -0,0 +1,95 @@ + $attachmentFiles A list of files that will be added as attachments. You can include up to 10 files. + */ + #[JsonProperty('attachment_files'), ArrayType([ConversationAttachmentFiles::class])] + private ?array $attachmentFiles; + + /** + * @param array{ + * messageType: 'comment', + * type: 'user', + * body: string, + * userId: string, + * createdAt?: ?int, + * attachmentUrls?: ?array, + * replyOptions?: ?array, + * attachmentFiles?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->messageType = $values['messageType']; + $this->type = $values['type']; + $this->body = $values['body']; + $this->createdAt = $values['createdAt'] ?? null; + $this->attachmentUrls = $values['attachmentUrls'] ?? null; + $this->replyOptions = $values['replyOptions'] ?? null; + $this->userId = $values['userId']; + $this->attachmentFiles = $values['attachmentFiles'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachmentFiles(): ?array + { + return $this->attachmentFiles; + } + + /** + * @param ?array $value + */ + public function setAttachmentFiles(?array $value = null): self + { + $this->attachmentFiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactSegments.php b/src/Unstable/Types/ContactSegments.php new file mode 100644 index 00000000..d90fd7c4 --- /dev/null +++ b/src/Unstable/Types/ContactSegments.php @@ -0,0 +1,81 @@ + $data Segment objects associated with the contact. + */ + #[JsonProperty('data'), ArrayType([Segment::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactSocialProfiles.php b/src/Unstable/Types/ContactSocialProfiles.php new file mode 100644 index 00000000..84feeedc --- /dev/null +++ b/src/Unstable/Types/ContactSocialProfiles.php @@ -0,0 +1,55 @@ + $data A list of social profiles objects associated with the contact. + */ + #[JsonProperty('data'), ArrayType([SocialProfile::class])] + private ?array $data; + + /** + * @param array{ + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->data = $values['data'] ?? null; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactSubscriptionTypes.php b/src/Unstable/Types/ContactSubscriptionTypes.php new file mode 100644 index 00000000..e1e4b095 --- /dev/null +++ b/src/Unstable/Types/ContactSubscriptionTypes.php @@ -0,0 +1,130 @@ + $data This object represents the subscriptions attached to a contact. + */ + #[JsonProperty('data'), ArrayType([AddressableList::class])] + private ?array $data; + + /** + * @var ?string $url Url to get more subscription type resources for this contact + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $totalCount Int representing the total number of subscription types attached to this contact + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private ?bool $hasMore; + + /** + * @param array{ + * data?: ?array, + * url?: ?string, + * totalCount?: ?int, + * hasMore?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->data = $values['data'] ?? null; + $this->url = $values['url'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->hasMore = $values['hasMore'] ?? null; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasMore(): ?bool + { + return $this->hasMore; + } + + /** + * @param ?bool $value + */ + public function setHasMore(?bool $value = null): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactTags.php b/src/Unstable/Types/ContactTags.php new file mode 100644 index 00000000..04573e4f --- /dev/null +++ b/src/Unstable/Types/ContactTags.php @@ -0,0 +1,130 @@ + $data This object represents the tags attached to a contact. + */ + #[JsonProperty('data'), ArrayType([AddressableList::class])] + private ?array $data; + + /** + * @var ?string $url url to get more tag resources for this contact + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?int $totalCount Int representing the total number of tags attached to this contact + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?bool $hasMore Whether there's more Addressable Objects to be viewed. If true, use the url to view all + */ + #[JsonProperty('has_more')] + private ?bool $hasMore; + + /** + * @param array{ + * data?: ?array, + * url?: ?string, + * totalCount?: ?int, + * hasMore?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->data = $values['data'] ?? null; + $this->url = $values['url'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->hasMore = $values['hasMore'] ?? null; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasMore(): ?bool + { + return $this->hasMore; + } + + /** + * @param ?bool $value + */ + public function setHasMore(?bool $value = null): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContactUnarchived.php b/src/Unstable/Types/ContactUnarchived.php new file mode 100644 index 00000000..02e9265c --- /dev/null +++ b/src/Unstable/Types/ContactUnarchived.php @@ -0,0 +1,63 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->archived = $values['archived'] ?? null; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ContentSourcesList.php b/src/Unstable/Types/ContentSourcesList.php new file mode 100644 index 00000000..a1a54085 --- /dev/null +++ b/src/Unstable/Types/ContentSourcesList.php @@ -0,0 +1,103 @@ + $contentSources The content sources used by AI Agent in the conversation. + */ + #[JsonProperty('content_sources'), ArrayType([ContentSource::class])] + private ?array $contentSources; + + /** + * @param array{ + * type?: ?'content_source.list', + * totalCount?: ?int, + * contentSources?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->contentSources = $values['contentSources'] ?? null; + } + + /** + * @return ?'content_source.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'content_source.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getContentSources(): ?array + { + return $this->contentSources; + } + + /** + * @param ?array $value + */ + public function setContentSources(?array $value = null): self + { + $this->contentSources = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttachmentFiles.php b/src/Unstable/Types/ConversationAttachmentFiles.php new file mode 100644 index 00000000..4d7a343c --- /dev/null +++ b/src/Unstable/Types/ConversationAttachmentFiles.php @@ -0,0 +1,104 @@ +contentType = $values['contentType'] ?? null; + $this->data = $values['data'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getContentType(): ?string + { + return $this->contentType; + } + + /** + * @param ?string $value + */ + public function setContentType(?string $value = null): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getData(): ?string + { + return $this->data; + } + + /** + * @param ?string $value + */ + public function setData(?string $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByAdmin.php b/src/Unstable/Types/ConversationAttributeUpdatedByAdmin.php new file mode 100644 index 00000000..d55ac2c6 --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByAdmin.php @@ -0,0 +1,79 @@ +conversation_attribute_updated_by_admin. + */ +class ConversationAttributeUpdatedByAdmin extends JsonSerializableType +{ + /** + * @var ?ConversationAttributeUpdatedByAdminAttribute $attribute + */ + #[JsonProperty('attribute')] + private ?ConversationAttributeUpdatedByAdminAttribute $attribute; + + /** + * @var ?ConversationAttributeUpdatedByAdminValue $value + */ + #[JsonProperty('value')] + private ?ConversationAttributeUpdatedByAdminValue $value; + + /** + * @param array{ + * attribute?: ?ConversationAttributeUpdatedByAdminAttribute, + * value?: ?ConversationAttributeUpdatedByAdminValue, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->attribute = $values['attribute'] ?? null; + $this->value = $values['value'] ?? null; + } + + /** + * @return ?ConversationAttributeUpdatedByAdminAttribute + */ + public function getAttribute(): ?ConversationAttributeUpdatedByAdminAttribute + { + return $this->attribute; + } + + /** + * @param ?ConversationAttributeUpdatedByAdminAttribute $value + */ + public function setAttribute(?ConversationAttributeUpdatedByAdminAttribute $value = null): self + { + $this->attribute = $value; + return $this; + } + + /** + * @return ?ConversationAttributeUpdatedByAdminValue + */ + public function getValue(): ?ConversationAttributeUpdatedByAdminValue + { + return $this->value; + } + + /** + * @param ?ConversationAttributeUpdatedByAdminValue $value + */ + public function setValue(?ConversationAttributeUpdatedByAdminValue $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByAdminAttribute.php b/src/Unstable/Types/ConversationAttributeUpdatedByAdminAttribute.php new file mode 100644 index 00000000..87d02383 --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByAdminAttribute.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByAdminValue.php b/src/Unstable/Types/ConversationAttributeUpdatedByAdminValue.php new file mode 100644 index 00000000..8ef23c0e --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByAdminValue.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByWorkflow.php b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflow.php new file mode 100644 index 00000000..d2601218 --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflow.php @@ -0,0 +1,104 @@ +conversation_attribute_updated_by_workflow. + */ +class ConversationAttributeUpdatedByWorkflow extends JsonSerializableType +{ + /** + * @var ?ConversationAttributeUpdatedByWorkflowWorkflow $workflow + */ + #[JsonProperty('workflow')] + private ?ConversationAttributeUpdatedByWorkflowWorkflow $workflow; + + /** + * @var ?ConversationAttributeUpdatedByWorkflowAttribute $attribute + */ + #[JsonProperty('attribute')] + private ?ConversationAttributeUpdatedByWorkflowAttribute $attribute; + + /** + * @var ?ConversationAttributeUpdatedByWorkflowValue $value + */ + #[JsonProperty('value')] + private ?ConversationAttributeUpdatedByWorkflowValue $value; + + /** + * @param array{ + * workflow?: ?ConversationAttributeUpdatedByWorkflowWorkflow, + * attribute?: ?ConversationAttributeUpdatedByWorkflowAttribute, + * value?: ?ConversationAttributeUpdatedByWorkflowValue, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->workflow = $values['workflow'] ?? null; + $this->attribute = $values['attribute'] ?? null; + $this->value = $values['value'] ?? null; + } + + /** + * @return ?ConversationAttributeUpdatedByWorkflowWorkflow + */ + public function getWorkflow(): ?ConversationAttributeUpdatedByWorkflowWorkflow + { + return $this->workflow; + } + + /** + * @param ?ConversationAttributeUpdatedByWorkflowWorkflow $value + */ + public function setWorkflow(?ConversationAttributeUpdatedByWorkflowWorkflow $value = null): self + { + $this->workflow = $value; + return $this; + } + + /** + * @return ?ConversationAttributeUpdatedByWorkflowAttribute + */ + public function getAttribute(): ?ConversationAttributeUpdatedByWorkflowAttribute + { + return $this->attribute; + } + + /** + * @param ?ConversationAttributeUpdatedByWorkflowAttribute $value + */ + public function setAttribute(?ConversationAttributeUpdatedByWorkflowAttribute $value = null): self + { + $this->attribute = $value; + return $this; + } + + /** + * @return ?ConversationAttributeUpdatedByWorkflowValue + */ + public function getValue(): ?ConversationAttributeUpdatedByWorkflowValue + { + return $this->value; + } + + /** + * @param ?ConversationAttributeUpdatedByWorkflowValue $value + */ + public function setValue(?ConversationAttributeUpdatedByWorkflowValue $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowAttribute.php b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowAttribute.php new file mode 100644 index 00000000..8002c16c --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowAttribute.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowValue.php b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowValue.php new file mode 100644 index 00000000..85f6a23f --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowValue.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowWorkflow.php b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowWorkflow.php new file mode 100644 index 00000000..3a5a9d1a --- /dev/null +++ b/src/Unstable/Types/ConversationAttributeUpdatedByWorkflowWorkflow.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationContacts.php b/src/Unstable/Types/ConversationContacts.php new file mode 100644 index 00000000..9175fb83 --- /dev/null +++ b/src/Unstable/Types/ConversationContacts.php @@ -0,0 +1,80 @@ + $contacts The list of contacts (users or leads) involved in this conversation. This will only contain one customer unless more were added via the group conversation feature. + */ + #[JsonProperty('contacts'), ArrayType([ContactReference::class])] + private ?array $contacts; + + /** + * @param array{ + * type?: ?'contact.list', + * contacts?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->contacts = $values['contacts'] ?? null; + } + + /** + * @return ?'contact.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'contact.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getContacts(): ?array + { + return $this->contacts; + } + + /** + * @param ?array $value + */ + public function setContacts(?array $value = null): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationDeleted.php b/src/Unstable/Types/ConversationDeleted.php new file mode 100644 index 00000000..0476628d --- /dev/null +++ b/src/Unstable/Types/ConversationDeleted.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->object = $values['object'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'conversation' + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?'conversation' $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationFirstContactReply.php b/src/Unstable/Types/ConversationFirstContactReply.php new file mode 100644 index 00000000..dff63cde --- /dev/null +++ b/src/Unstable/Types/ConversationFirstContactReply.php @@ -0,0 +1,104 @@ +createdAt = $values['createdAt'] ?? null; + $this->type = $values['type'] ?? null; + $this->url = $values['url'] ?? null; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationList.php b/src/Unstable/Types/ConversationList.php new file mode 100644 index 00000000..a4ed113a --- /dev/null +++ b/src/Unstable/Types/ConversationList.php @@ -0,0 +1,131 @@ + $conversations The list of conversation objects + */ + #[JsonProperty('conversations'), ArrayType([Conversation::class])] + private ?array $conversations; + + /** + * @var ?int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type?: ?'conversation.list', + * conversations?: ?array, + * totalCount?: ?int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->conversations = $values['conversations'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'conversation.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'conversation.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getConversations(): ?array + { + return $this->conversations; + } + + /** + * @param ?array $value + */ + public function setConversations(?array $value = null): self + { + $this->conversations = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationPart.php b/src/Unstable/Types/ConversationPart.php new file mode 100644 index 00000000..75f39a34 --- /dev/null +++ b/src/Unstable/Types/ConversationPart.php @@ -0,0 +1,506 @@ + $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?string $externalId The external id of the conversation part + */ + #[JsonProperty('external_id')] + private ?string $externalId; + + /** + * @var ?bool $redacted Whether or not the conversation part has been redacted. + */ + #[JsonProperty('redacted')] + private ?bool $redacted; + + /** + * @var ?EmailMessageMetadata $emailMessageMetadata + */ + #[JsonProperty('email_message_metadata')] + private ?EmailMessageMetadata $emailMessageMetadata; + + /** + * @var ?ConversationPartMetadata $metadata + */ + #[JsonProperty('metadata')] + private ?ConversationPartMetadata $metadata; + + /** + * @var ?value-of $state Indicates the current state of conversation when the conversation part was created. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?array $tags A list of tags objects associated with the conversation part. + */ + #[JsonProperty('tags'), ArrayType([TagBasic::class])] + private ?array $tags; + + /** + * @var ( + * ConversationAttributeUpdatedByWorkflow + * |ConversationAttributeUpdatedByAdmin + * |CustomActionStarted + * |CustomActionFinished + * |OperatorWorkflowEvent + * )|null $eventDetails + */ + #[JsonProperty('event_details'), Union(ConversationAttributeUpdatedByWorkflow::class, ConversationAttributeUpdatedByAdmin::class, CustomActionStarted::class, CustomActionFinished::class, OperatorWorkflowEvent::class, 'null')] + private ConversationAttributeUpdatedByWorkflow|ConversationAttributeUpdatedByAdmin|CustomActionStarted|CustomActionFinished|OperatorWorkflowEvent|null $eventDetails; + + /** + * @var ?string $appPackageCode The app package code if this part was created via API. null if the part was not created via API. + */ + #[JsonProperty('app_package_code')] + private ?string $appPackageCode; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * partType?: ?string, + * body?: ?string, + * createdAt?: ?int, + * updatedAt?: ?int, + * notifiedAt?: ?int, + * assignedTo?: ?Reference, + * author?: ?ConversationPartAuthor, + * attachments?: ?array, + * externalId?: ?string, + * redacted?: ?bool, + * emailMessageMetadata?: ?EmailMessageMetadata, + * metadata?: ?ConversationPartMetadata, + * state?: ?value-of, + * tags?: ?array, + * eventDetails?: ( + * ConversationAttributeUpdatedByWorkflow + * |ConversationAttributeUpdatedByAdmin + * |CustomActionStarted + * |CustomActionFinished + * |OperatorWorkflowEvent + * )|null, + * appPackageCode?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->partType = $values['partType'] ?? null; + $this->body = $values['body'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->notifiedAt = $values['notifiedAt'] ?? null; + $this->assignedTo = $values['assignedTo'] ?? null; + $this->author = $values['author'] ?? null; + $this->attachments = $values['attachments'] ?? null; + $this->externalId = $values['externalId'] ?? null; + $this->redacted = $values['redacted'] ?? null; + $this->emailMessageMetadata = $values['emailMessageMetadata'] ?? null; + $this->metadata = $values['metadata'] ?? null; + $this->state = $values['state'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->eventDetails = $values['eventDetails'] ?? null; + $this->appPackageCode = $values['appPackageCode'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPartType(): ?string + { + return $this->partType; + } + + /** + * @param ?string $value + */ + public function setPartType(?string $value = null): self + { + $this->partType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getNotifiedAt(): ?int + { + return $this->notifiedAt; + } + + /** + * @param ?int $value + */ + public function setNotifiedAt(?int $value = null): self + { + $this->notifiedAt = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getAssignedTo(): ?Reference + { + return $this->assignedTo; + } + + /** + * @param ?Reference $value + */ + public function setAssignedTo(?Reference $value = null): self + { + $this->assignedTo = $value; + return $this; + } + + /** + * @return ?ConversationPartAuthor + */ + public function getAuthor(): ?ConversationPartAuthor + { + return $this->author; + } + + /** + * @param ?ConversationPartAuthor $value + */ + public function setAuthor(?ConversationPartAuthor $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?string + */ + public function getExternalId(): ?string + { + return $this->externalId; + } + + /** + * @param ?string $value + */ + public function setExternalId(?string $value = null): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRedacted(): ?bool + { + return $this->redacted; + } + + /** + * @param ?bool $value + */ + public function setRedacted(?bool $value = null): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return ?EmailMessageMetadata + */ + public function getEmailMessageMetadata(): ?EmailMessageMetadata + { + return $this->emailMessageMetadata; + } + + /** + * @param ?EmailMessageMetadata $value + */ + public function setEmailMessageMetadata(?EmailMessageMetadata $value = null): self + { + $this->emailMessageMetadata = $value; + return $this; + } + + /** + * @return ?ConversationPartMetadata + */ + public function getMetadata(): ?ConversationPartMetadata + { + return $this->metadata; + } + + /** + * @param ?ConversationPartMetadata $value + */ + public function setMetadata(?ConversationPartMetadata $value = null): self + { + $this->metadata = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTags(): ?array + { + return $this->tags; + } + + /** + * @param ?array $value + */ + public function setTags(?array $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ( + * ConversationAttributeUpdatedByWorkflow + * |ConversationAttributeUpdatedByAdmin + * |CustomActionStarted + * |CustomActionFinished + * |OperatorWorkflowEvent + * )|null + */ + public function getEventDetails(): ConversationAttributeUpdatedByWorkflow|ConversationAttributeUpdatedByAdmin|CustomActionStarted|CustomActionFinished|OperatorWorkflowEvent|null + { + return $this->eventDetails; + } + + /** + * @param ( + * ConversationAttributeUpdatedByWorkflow + * |ConversationAttributeUpdatedByAdmin + * |CustomActionStarted + * |CustomActionFinished + * |OperatorWorkflowEvent + * )|null $value + */ + public function setEventDetails(ConversationAttributeUpdatedByWorkflow|ConversationAttributeUpdatedByAdmin|CustomActionStarted|CustomActionFinished|OperatorWorkflowEvent|null $value = null): self + { + $this->eventDetails = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAppPackageCode(): ?string + { + return $this->appPackageCode; + } + + /** + * @param ?string $value + */ + public function setAppPackageCode(?string $value = null): self + { + $this->appPackageCode = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationPartAuthor.php b/src/Unstable/Types/ConversationPartAuthor.php new file mode 100644 index 00000000..0dca1967 --- /dev/null +++ b/src/Unstable/Types/ConversationPartAuthor.php @@ -0,0 +1,179 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->email = $values['email'] ?? null; + $this->fromAiAgent = $values['fromAiAgent'] ?? null; + $this->isAiAnswer = $values['isAiAnswer'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getFromAiAgent(): ?bool + { + return $this->fromAiAgent; + } + + /** + * @param ?bool $value + */ + public function setFromAiAgent(?bool $value = null): self + { + $this->fromAiAgent = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsAiAnswer(): ?bool + { + return $this->isAiAnswer; + } + + /** + * @param ?bool $value + */ + public function setIsAiAnswer(?bool $value = null): self + { + $this->isAiAnswer = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationPartMetadata.php b/src/Unstable/Types/ConversationPartMetadata.php new file mode 100644 index 00000000..8db048ac --- /dev/null +++ b/src/Unstable/Types/ConversationPartMetadata.php @@ -0,0 +1,80 @@ + $quickReplyOptions The quick reply options sent by the Admin or bot, presented in this conversation part. + */ + #[JsonProperty('quick_reply_options'), ArrayType([ConversationPartMetadataQuickReplyOptionsItem::class])] + private ?array $quickReplyOptions; + + /** + * @var ?string $quickReplyUuid The unique identifier for the quick reply option that was clicked by the end user. + */ + #[JsonProperty('quick_reply_uuid')] + private ?string $quickReplyUuid; + + /** + * @param array{ + * quickReplyOptions?: ?array, + * quickReplyUuid?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->quickReplyOptions = $values['quickReplyOptions'] ?? null; + $this->quickReplyUuid = $values['quickReplyUuid'] ?? null; + } + + /** + * @return ?array + */ + public function getQuickReplyOptions(): ?array + { + return $this->quickReplyOptions; + } + + /** + * @param ?array $value + */ + public function setQuickReplyOptions(?array $value = null): self + { + $this->quickReplyOptions = $value; + return $this; + } + + /** + * @return ?string + */ + public function getQuickReplyUuid(): ?string + { + return $this->quickReplyUuid; + } + + /** + * @param ?string $value + */ + public function setQuickReplyUuid(?string $value = null): self + { + $this->quickReplyUuid = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationPartMetadataQuickReplyOptionsItem.php b/src/Unstable/Types/ConversationPartMetadataQuickReplyOptionsItem.php new file mode 100644 index 00000000..81abcf3d --- /dev/null +++ b/src/Unstable/Types/ConversationPartMetadataQuickReplyOptionsItem.php @@ -0,0 +1,59 @@ + $translations The translations for the quick reply option. + */ + #[JsonProperty('translations'), ArrayType(['string' => 'mixed'])] + private ?array $translations; + + /** + * @param array{ + * text: string, + * uuid: string, + * translations?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->text = $values['text']; + $this->uuid = $values['uuid']; + $this->translations = $values['translations'] ?? null; + } + + /** + * @return ?array + */ + public function getTranslations(): ?array + { + return $this->translations; + } + + /** + * @param ?array $value + */ + public function setTranslations(?array $value = null): self + { + $this->translations = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationPartState.php b/src/Unstable/Types/ConversationPartState.php new file mode 100644 index 00000000..9a0033b8 --- /dev/null +++ b/src/Unstable/Types/ConversationPartState.php @@ -0,0 +1,10 @@ + $conversationParts A list of Conversation Part objects for each part message in the conversation. This is only returned when Retrieving a Conversation, and ignored when Listing all Conversations. There is a limit of 500 parts. + */ + #[JsonProperty('conversation_parts'), ArrayType([ConversationPart::class])] + private ?array $conversationParts; + + /** + * @var ?int $totalCount + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @param array{ + * type?: ?'conversation_part.list', + * conversationParts?: ?array, + * totalCount?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->conversationParts = $values['conversationParts'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + } + + /** + * @return ?'conversation_part.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'conversation_part.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getConversationParts(): ?array + { + return $this->conversationParts; + } + + /** + * @param ?array $value + */ + public function setConversationParts(?array $value = null): self + { + $this->conversationParts = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationRating.php b/src/Unstable/Types/ConversationRating.php new file mode 100644 index 00000000..25352f3a --- /dev/null +++ b/src/Unstable/Types/ConversationRating.php @@ -0,0 +1,154 @@ +rating = $values['rating'] ?? null; + $this->remark = $values['remark'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->contact = $values['contact'] ?? null; + $this->teammate = $values['teammate'] ?? null; + } + + /** + * @return ?int + */ + public function getRating(): ?int + { + return $this->rating; + } + + /** + * @param ?int $value + */ + public function setRating(?int $value = null): self + { + $this->rating = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRemark(): ?string + { + return $this->remark; + } + + /** + * @param ?string $value + */ + public function setRemark(?string $value = null): self + { + $this->remark = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?ContactReference + */ + public function getContact(): ?ContactReference + { + return $this->contact; + } + + /** + * @param ?ContactReference $value + */ + public function setContact(?ContactReference $value = null): self + { + $this->contact = $value; + return $this; + } + + /** + * @return ?Reference + */ + public function getTeammate(): ?Reference + { + return $this->teammate; + } + + /** + * @param ?Reference $value + */ + public function setTeammate(?Reference $value = null): self + { + $this->teammate = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationResponseTime.php b/src/Unstable/Types/ConversationResponseTime.php new file mode 100644 index 00000000..413b5480 --- /dev/null +++ b/src/Unstable/Types/ConversationResponseTime.php @@ -0,0 +1,104 @@ +teamId = $values['teamId'] ?? null; + $this->teamName = $values['teamName'] ?? null; + $this->responseTime = $values['responseTime'] ?? null; + } + + /** + * @return ?int + */ + public function getTeamId(): ?int + { + return $this->teamId; + } + + /** + * @param ?int $value + */ + public function setTeamId(?int $value = null): self + { + $this->teamId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTeamName(): ?string + { + return $this->teamName; + } + + /** + * @param ?string $value + */ + public function setTeamName(?string $value = null): self + { + $this->teamName = $value; + return $this; + } + + /** + * @return ?int + */ + public function getResponseTime(): ?int + { + return $this->responseTime; + } + + /** + * @param ?int $value + */ + public function setResponseTime(?int $value = null): self + { + $this->responseTime = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationSource.php b/src/Unstable/Types/ConversationSource.php new file mode 100644 index 00000000..22508ba9 --- /dev/null +++ b/src/Unstable/Types/ConversationSource.php @@ -0,0 +1,255 @@ + $type This includes conversation, email, facebook, instagram, phone_call, phone_switch, push, sms, twitter and whatsapp. + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $id The id representing the message. + */ + #[JsonProperty('id')] + private ?string $id; + + /** + * @var ?string $deliveredAs The conversation's initiation type. Possible values are customer_initiated, campaigns_initiated (legacy campaigns), operator_initiated (Custom bot), automated (Series and other outbounds with dynamic audience message) and admin_initiated (fixed audience message, ticket initiated by an admin, group email). + */ + #[JsonProperty('delivered_as')] + private ?string $deliveredAs; + + /** + * @var ?string $subject Optional. The message subject. For Twitter, this will show a generic message regarding why the subject is obscured. + */ + #[JsonProperty('subject')] + private ?string $subject; + + /** + * @var ?string $body The message body, which may contain HTML. For Twitter, this will show a generic message regarding why the body is obscured. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var ?ConversationPartAuthor $author + */ + #[JsonProperty('author')] + private ?ConversationPartAuthor $author; + + /** + * @var ?array $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?string $url The URL where the conversation was started. For Twitter, Email, and Bots, this will be blank. + */ + #[JsonProperty('url')] + private ?string $url; + + /** + * @var ?bool $redacted Whether or not the source message has been redacted. Only applicable for contact initiated messages. + */ + #[JsonProperty('redacted')] + private ?bool $redacted; + + /** + * @param array{ + * type?: ?value-of, + * id?: ?string, + * deliveredAs?: ?string, + * subject?: ?string, + * body?: ?string, + * author?: ?ConversationPartAuthor, + * attachments?: ?array, + * url?: ?string, + * redacted?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->deliveredAs = $values['deliveredAs'] ?? null; + $this->subject = $values['subject'] ?? null; + $this->body = $values['body'] ?? null; + $this->author = $values['author'] ?? null; + $this->attachments = $values['attachments'] ?? null; + $this->url = $values['url'] ?? null; + $this->redacted = $values['redacted'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDeliveredAs(): ?string + { + return $this->deliveredAs; + } + + /** + * @param ?string $value + */ + public function setDeliveredAs(?string $value = null): self + { + $this->deliveredAs = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSubject(): ?string + { + return $this->subject; + } + + /** + * @param ?string $value + */ + public function setSubject(?string $value = null): self + { + $this->subject = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?ConversationPartAuthor + */ + public function getAuthor(): ?ConversationPartAuthor + { + return $this->author; + } + + /** + * @param ?ConversationPartAuthor $value + */ + public function setAuthor(?ConversationPartAuthor $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRedacted(): ?bool + { + return $this->redacted; + } + + /** + * @param ?bool $value + */ + public function setRedacted(?bool $value = null): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationSourceType.php b/src/Unstable/Types/ConversationSourceType.php new file mode 100644 index 00000000..afc1abef --- /dev/null +++ b/src/Unstable/Types/ConversationSourceType.php @@ -0,0 +1,17 @@ + $assignedTeamFirstResponseTimeByTeam An array of conversation response time objects + */ + #[JsonProperty('assigned_team_first_response_time_by_team'), ArrayType([ConversationResponseTime::class])] + private ?array $assignedTeamFirstResponseTimeByTeam; + + /** + * @var ?array $assignedTeamFirstResponseTimeInOfficeHours An array of conversation response time objects within office hours + */ + #[JsonProperty('assigned_team_first_response_time_in_office_hours'), ArrayType([ConversationResponseTime::class])] + private ?array $assignedTeamFirstResponseTimeInOfficeHours; + + /** + * @var ?int $handlingTime Time from conversation assignment to conversation close in seconds. + */ + #[JsonProperty('handling_time')] + private ?int $handlingTime; + + /** + * @param array{ + * type?: ?string, + * timeToAssignment?: ?int, + * timeToAdminReply?: ?int, + * timeToFirstClose?: ?int, + * timeToLastClose?: ?int, + * medianTimeToReply?: ?int, + * firstContactReplyAt?: ?int, + * firstAssignmentAt?: ?int, + * firstAdminReplyAt?: ?int, + * firstCloseAt?: ?int, + * lastAssignmentAt?: ?int, + * lastAssignmentAdminReplyAt?: ?int, + * lastContactReplyAt?: ?int, + * lastAdminReplyAt?: ?int, + * lastCloseAt?: ?int, + * lastClosedById?: ?string, + * countReopens?: ?int, + * countAssignments?: ?int, + * countConversationParts?: ?int, + * assignedTeamFirstResponseTimeByTeam?: ?array, + * assignedTeamFirstResponseTimeInOfficeHours?: ?array, + * handlingTime?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->timeToAssignment = $values['timeToAssignment'] ?? null; + $this->timeToAdminReply = $values['timeToAdminReply'] ?? null; + $this->timeToFirstClose = $values['timeToFirstClose'] ?? null; + $this->timeToLastClose = $values['timeToLastClose'] ?? null; + $this->medianTimeToReply = $values['medianTimeToReply'] ?? null; + $this->firstContactReplyAt = $values['firstContactReplyAt'] ?? null; + $this->firstAssignmentAt = $values['firstAssignmentAt'] ?? null; + $this->firstAdminReplyAt = $values['firstAdminReplyAt'] ?? null; + $this->firstCloseAt = $values['firstCloseAt'] ?? null; + $this->lastAssignmentAt = $values['lastAssignmentAt'] ?? null; + $this->lastAssignmentAdminReplyAt = $values['lastAssignmentAdminReplyAt'] ?? null; + $this->lastContactReplyAt = $values['lastContactReplyAt'] ?? null; + $this->lastAdminReplyAt = $values['lastAdminReplyAt'] ?? null; + $this->lastCloseAt = $values['lastCloseAt'] ?? null; + $this->lastClosedById = $values['lastClosedById'] ?? null; + $this->countReopens = $values['countReopens'] ?? null; + $this->countAssignments = $values['countAssignments'] ?? null; + $this->countConversationParts = $values['countConversationParts'] ?? null; + $this->assignedTeamFirstResponseTimeByTeam = $values['assignedTeamFirstResponseTimeByTeam'] ?? null; + $this->assignedTeamFirstResponseTimeInOfficeHours = $values['assignedTeamFirstResponseTimeInOfficeHours'] ?? null; + $this->handlingTime = $values['handlingTime'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToAssignment(): ?int + { + return $this->timeToAssignment; + } + + /** + * @param ?int $value + */ + public function setTimeToAssignment(?int $value = null): self + { + $this->timeToAssignment = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToAdminReply(): ?int + { + return $this->timeToAdminReply; + } + + /** + * @param ?int $value + */ + public function setTimeToAdminReply(?int $value = null): self + { + $this->timeToAdminReply = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToFirstClose(): ?int + { + return $this->timeToFirstClose; + } + + /** + * @param ?int $value + */ + public function setTimeToFirstClose(?int $value = null): self + { + $this->timeToFirstClose = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTimeToLastClose(): ?int + { + return $this->timeToLastClose; + } + + /** + * @param ?int $value + */ + public function setTimeToLastClose(?int $value = null): self + { + $this->timeToLastClose = $value; + return $this; + } + + /** + * @return ?int + */ + public function getMedianTimeToReply(): ?int + { + return $this->medianTimeToReply; + } + + /** + * @param ?int $value + */ + public function setMedianTimeToReply(?int $value = null): self + { + $this->medianTimeToReply = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstContactReplyAt(): ?int + { + return $this->firstContactReplyAt; + } + + /** + * @param ?int $value + */ + public function setFirstContactReplyAt(?int $value = null): self + { + $this->firstContactReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstAssignmentAt(): ?int + { + return $this->firstAssignmentAt; + } + + /** + * @param ?int $value + */ + public function setFirstAssignmentAt(?int $value = null): self + { + $this->firstAssignmentAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstAdminReplyAt(): ?int + { + return $this->firstAdminReplyAt; + } + + /** + * @param ?int $value + */ + public function setFirstAdminReplyAt(?int $value = null): self + { + $this->firstAdminReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstCloseAt(): ?int + { + return $this->firstCloseAt; + } + + /** + * @param ?int $value + */ + public function setFirstCloseAt(?int $value = null): self + { + $this->firstCloseAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastAssignmentAt(): ?int + { + return $this->lastAssignmentAt; + } + + /** + * @param ?int $value + */ + public function setLastAssignmentAt(?int $value = null): self + { + $this->lastAssignmentAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastAssignmentAdminReplyAt(): ?int + { + return $this->lastAssignmentAdminReplyAt; + } + + /** + * @param ?int $value + */ + public function setLastAssignmentAdminReplyAt(?int $value = null): self + { + $this->lastAssignmentAdminReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastContactReplyAt(): ?int + { + return $this->lastContactReplyAt; + } + + /** + * @param ?int $value + */ + public function setLastContactReplyAt(?int $value = null): self + { + $this->lastContactReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastAdminReplyAt(): ?int + { + return $this->lastAdminReplyAt; + } + + /** + * @param ?int $value + */ + public function setLastAdminReplyAt(?int $value = null): self + { + $this->lastAdminReplyAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLastCloseAt(): ?int + { + return $this->lastCloseAt; + } + + /** + * @param ?int $value + */ + public function setLastCloseAt(?int $value = null): self + { + $this->lastCloseAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLastClosedById(): ?string + { + return $this->lastClosedById; + } + + /** + * @param ?string $value + */ + public function setLastClosedById(?string $value = null): self + { + $this->lastClosedById = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCountReopens(): ?int + { + return $this->countReopens; + } + + /** + * @param ?int $value + */ + public function setCountReopens(?int $value = null): self + { + $this->countReopens = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCountAssignments(): ?int + { + return $this->countAssignments; + } + + /** + * @param ?int $value + */ + public function setCountAssignments(?int $value = null): self + { + $this->countAssignments = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCountConversationParts(): ?int + { + return $this->countConversationParts; + } + + /** + * @param ?int $value + */ + public function setCountConversationParts(?int $value = null): self + { + $this->countConversationParts = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAssignedTeamFirstResponseTimeByTeam(): ?array + { + return $this->assignedTeamFirstResponseTimeByTeam; + } + + /** + * @param ?array $value + */ + public function setAssignedTeamFirstResponseTimeByTeam(?array $value = null): self + { + $this->assignedTeamFirstResponseTimeByTeam = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAssignedTeamFirstResponseTimeInOfficeHours(): ?array + { + return $this->assignedTeamFirstResponseTimeInOfficeHours; + } + + /** + * @param ?array $value + */ + public function setAssignedTeamFirstResponseTimeInOfficeHours(?array $value = null): self + { + $this->assignedTeamFirstResponseTimeInOfficeHours = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHandlingTime(): ?int + { + return $this->handlingTime; + } + + /** + * @param ?int $value + */ + public function setHandlingTime(?int $value = null): self + { + $this->handlingTime = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ConversationTeammates.php b/src/Unstable/Types/ConversationTeammates.php new file mode 100644 index 00000000..ddb5154c --- /dev/null +++ b/src/Unstable/Types/ConversationTeammates.php @@ -0,0 +1,80 @@ + $teammates The list of teammates who participated in the conversation (wrote at least one conversation part). + */ + #[JsonProperty('teammates'), ArrayType([Reference::class])] + private ?array $teammates; + + /** + * @param array{ + * type?: ?string, + * teammates?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->teammates = $values['teammates'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTeammates(): ?array + { + return $this->teammates; + } + + /** + * @param ?array $value + */ + public function setTeammates(?array $value = null): self + { + $this->teammates = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CreateOrUpdateTagRequest.php b/src/Unstable/Types/CreateOrUpdateTagRequest.php new file mode 100644 index 00000000..eb5f8215 --- /dev/null +++ b/src/Unstable/Types/CreateOrUpdateTagRequest.php @@ -0,0 +1,79 @@ +name = $values['name']; + $this->id = $values['id'] ?? null; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CreateTicketRequestAssignment.php b/src/Unstable/Types/CreateTicketRequestAssignment.php new file mode 100644 index 00000000..aae0cceb --- /dev/null +++ b/src/Unstable/Types/CreateTicketRequestAssignment.php @@ -0,0 +1,76 @@ +adminAssigneeId = $values['adminAssigneeId'] ?? null; + $this->teamAssigneeId = $values['teamAssigneeId'] ?? null; + } + + /** + * @return ?string + */ + public function getAdminAssigneeId(): ?string + { + return $this->adminAssigneeId; + } + + /** + * @param ?string $value + */ + public function setAdminAssigneeId(?string $value = null): self + { + $this->adminAssigneeId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTeamAssigneeId(): ?string + { + return $this->teamAssigneeId; + } + + /** + * @param ?string $value + */ + public function setTeamAssigneeId(?string $value = null): self + { + $this->teamAssigneeId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CreateTicketRequestBody.php b/src/Unstable/Types/CreateTicketRequestBody.php new file mode 100644 index 00000000..1cc0c982 --- /dev/null +++ b/src/Unstable/Types/CreateTicketRequestBody.php @@ -0,0 +1,203 @@ + $contacts The list of contacts (users or leads) affected by this ticket. Currently only one is allowed + */ + #[JsonProperty('contacts'), ArrayType([new Union(CreateTicketRequestContactsItemId::class, CreateTicketRequestContactsItemExternalId::class, CreateTicketRequestContactsItemEmail::class)])] + private array $contacts; + + /** + * The ID of the conversation you want to link to the ticket. Here are the valid ways of linking two tickets: + * - conversation | back-office ticket + * - customer tickets | non-shared back-office ticket + * - conversation | tracker ticket + * - customer ticket | tracker ticket + * + * @var ?string $conversationToLinkId + */ + #[JsonProperty('conversation_to_link_id')] + private ?string $conversationToLinkId; + + /** + * @var ?string $companyId The ID of the company that the ticket is associated with. The unique identifier for the company which is given by Intercom + */ + #[JsonProperty('company_id')] + private ?string $companyId; + + /** + * @var ?int $createdAt The time the ticket was created. If not provided, the current time will be used. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?CreateTicketRequestAssignment $assignment + */ + #[JsonProperty('assignment')] + private ?CreateTicketRequestAssignment $assignment; + + /** + * @param array{ + * ticketTypeId: string, + * contacts: array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )>, + * conversationToLinkId?: ?string, + * companyId?: ?string, + * createdAt?: ?int, + * assignment?: ?CreateTicketRequestAssignment, + * } $values + */ + public function __construct( + array $values, + ) { + $this->ticketTypeId = $values['ticketTypeId']; + $this->contacts = $values['contacts']; + $this->conversationToLinkId = $values['conversationToLinkId'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->assignment = $values['assignment'] ?? null; + } + + /** + * @return string + */ + public function getTicketTypeId(): string + { + return $this->ticketTypeId; + } + + /** + * @param string $value + */ + public function setTicketTypeId(string $value): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> + */ + public function getContacts(): array + { + return $this->contacts; + } + + /** + * @param array<( + * CreateTicketRequestContactsItemId + * |CreateTicketRequestContactsItemExternalId + * |CreateTicketRequestContactsItemEmail + * )> $value + */ + public function setContacts(array $value): self + { + $this->contacts = $value; + return $this; + } + + /** + * @return ?string + */ + public function getConversationToLinkId(): ?string + { + return $this->conversationToLinkId; + } + + /** + * @param ?string $value + */ + public function setConversationToLinkId(?string $value = null): self + { + $this->conversationToLinkId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?CreateTicketRequestAssignment + */ + public function getAssignment(): ?CreateTicketRequestAssignment + { + return $this->assignment; + } + + /** + * @param ?CreateTicketRequestAssignment $value + */ + public function setAssignment(?CreateTicketRequestAssignment $value = null): self + { + $this->assignment = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CreateTicketRequestContactsItemEmail.php b/src/Unstable/Types/CreateTicketRequestContactsItemEmail.php new file mode 100644 index 00000000..4464d340 --- /dev/null +++ b/src/Unstable/Types/CreateTicketRequestContactsItemEmail.php @@ -0,0 +1,51 @@ +email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CreateTicketRequestContactsItemExternalId.php b/src/Unstable/Types/CreateTicketRequestContactsItemExternalId.php new file mode 100644 index 00000000..93055e02 --- /dev/null +++ b/src/Unstable/Types/CreateTicketRequestContactsItemExternalId.php @@ -0,0 +1,51 @@ +externalId = $values['externalId']; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CreateTicketRequestContactsItemId.php b/src/Unstable/Types/CreateTicketRequestContactsItemId.php new file mode 100644 index 00000000..a190eacd --- /dev/null +++ b/src/Unstable/Types/CreateTicketRequestContactsItemId.php @@ -0,0 +1,51 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CursorPages.php b/src/Unstable/Types/CursorPages.php new file mode 100644 index 00000000..817d3c1f --- /dev/null +++ b/src/Unstable/Types/CursorPages.php @@ -0,0 +1,155 @@ +type = $values['type'] ?? null; + $this->page = $values['page'] ?? null; + $this->next = $values['next'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->totalPages = $values['totalPages'] ?? null; + } + + /** + * @return ?'pages' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'pages' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?StartingAfterPaging + */ + public function getNext(): ?StartingAfterPaging + { + return $this->next; + } + + /** + * @param ?StartingAfterPaging $value + */ + public function setNext(?StartingAfterPaging $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalPages(): ?int + { + return $this->totalPages; + } + + /** + * @param ?int $value + */ + public function setTotalPages(?int $value = null): self + { + $this->totalPages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomActionFinished.php b/src/Unstable/Types/CustomActionFinished.php new file mode 100644 index 00000000..3b4c761d --- /dev/null +++ b/src/Unstable/Types/CustomActionFinished.php @@ -0,0 +1,54 @@ +custom_action_finished. + */ +class CustomActionFinished extends JsonSerializableType +{ + /** + * @var ?CustomActionFinishedAction $action + */ + #[JsonProperty('action')] + private ?CustomActionFinishedAction $action; + + /** + * @param array{ + * action?: ?CustomActionFinishedAction, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->action = $values['action'] ?? null; + } + + /** + * @return ?CustomActionFinishedAction + */ + public function getAction(): ?CustomActionFinishedAction + { + return $this->action; + } + + /** + * @param ?CustomActionFinishedAction $value + */ + public function setAction(?CustomActionFinishedAction $value = null): self + { + $this->action = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomActionFinishedAction.php b/src/Unstable/Types/CustomActionFinishedAction.php new file mode 100644 index 00000000..7770a041 --- /dev/null +++ b/src/Unstable/Types/CustomActionFinishedAction.php @@ -0,0 +1,76 @@ + $result Status of the action + */ + #[JsonProperty('result')] + private ?string $result; + + /** + * @param array{ + * name?: ?string, + * result?: ?value-of, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->name = $values['name'] ?? null; + $this->result = $values['result'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getResult(): ?string + { + return $this->result; + } + + /** + * @param ?value-of $value + */ + public function setResult(?string $value = null): self + { + $this->result = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomActionFinishedActionResult.php b/src/Unstable/Types/CustomActionFinishedActionResult.php new file mode 100644 index 00000000..0252bc6a --- /dev/null +++ b/src/Unstable/Types/CustomActionFinishedActionResult.php @@ -0,0 +1,9 @@ +custom_action_started. + */ +class CustomActionStarted extends JsonSerializableType +{ + /** + * @var ?CustomActionStartedAction $action + */ + #[JsonProperty('action')] + private ?CustomActionStartedAction $action; + + /** + * @param array{ + * action?: ?CustomActionStartedAction, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->action = $values['action'] ?? null; + } + + /** + * @return ?CustomActionStartedAction + */ + public function getAction(): ?CustomActionStartedAction + { + return $this->action; + } + + /** + * @param ?CustomActionStartedAction $value + */ + public function setAction(?CustomActionStartedAction $value = null): self + { + $this->action = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomActionStartedAction.php b/src/Unstable/Types/CustomActionStartedAction.php new file mode 100644 index 00000000..b21c521e --- /dev/null +++ b/src/Unstable/Types/CustomActionStartedAction.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomChannelAttribute.php b/src/Unstable/Types/CustomChannelAttribute.php new file mode 100644 index 00000000..9d8a2d34 --- /dev/null +++ b/src/Unstable/Types/CustomChannelAttribute.php @@ -0,0 +1,76 @@ +id = $values['id']; + $this->value = $values['value']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getValue(): string + { + return $this->value; + } + + /** + * @param string $value + */ + public function setValue(string $value): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomChannelBaseEvent.php b/src/Unstable/Types/CustomChannelBaseEvent.php new file mode 100644 index 00000000..d0825032 --- /dev/null +++ b/src/Unstable/Types/CustomChannelBaseEvent.php @@ -0,0 +1,101 @@ +eventId = $values['eventId']; + $this->externalConversationId = $values['externalConversationId']; + $this->contact = $values['contact']; + } + + /** + * @return string + */ + public function getEventId(): string + { + return $this->eventId; + } + + /** + * @param string $value + */ + public function setEventId(string $value): self + { + $this->eventId = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalConversationId(): string + { + return $this->externalConversationId; + } + + /** + * @param string $value + */ + public function setExternalConversationId(string $value): self + { + $this->externalConversationId = $value; + return $this; + } + + /** + * @return CustomChannelContact + */ + public function getContact(): CustomChannelContact + { + return $this->contact; + } + + /** + * @param CustomChannelContact $value + */ + public function setContact(CustomChannelContact $value): self + { + $this->contact = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomChannelContact.php b/src/Unstable/Types/CustomChannelContact.php new file mode 100644 index 00000000..714e2b3b --- /dev/null +++ b/src/Unstable/Types/CustomChannelContact.php @@ -0,0 +1,126 @@ + $type Type of contact, must be "user" or "lead". + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $externalId External identifier for the contact. Intercom will take care of the mapping of your external_id with our internal ones so you don't have to worry about it. + */ + #[JsonProperty('external_id')] + private string $externalId; + + /** + * @var ?string $name Name of the contact. Required for user type. + */ + #[JsonProperty('name')] + private ?string $name; + + /** + * @var ?string $email Email address of the contact. Required for user type. + */ + #[JsonProperty('email')] + private ?string $email; + + /** + * @param array{ + * type: value-of, + * externalId: string, + * name?: ?string, + * email?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->externalId = $values['externalId']; + $this->name = $values['name'] ?? null; + $this->email = $values['email'] ?? null; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalId(): string + { + return $this->externalId; + } + + /** + * @param string $value + */ + public function setExternalId(string $value): self + { + $this->externalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomChannelContactType.php b/src/Unstable/Types/CustomChannelContactType.php new file mode 100644 index 00000000..20987ce0 --- /dev/null +++ b/src/Unstable/Types/CustomChannelContactType.php @@ -0,0 +1,9 @@ +externalConversationId = $values['externalConversationId']; + $this->conversationId = $values['conversationId']; + $this->externalContactId = $values['externalContactId']; + $this->contactId = $values['contactId']; + } + + /** + * @return string + */ + public function getExternalConversationId(): string + { + return $this->externalConversationId; + } + + /** + * @param string $value + */ + public function setExternalConversationId(string $value): self + { + $this->externalConversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getExternalContactId(): string + { + return $this->externalContactId; + } + + /** + * @param string $value + */ + public function setExternalContactId(string $value): self + { + $this->externalContactId = $value; + return $this; + } + + /** + * @return string + */ + public function getContactId(): string + { + return $this->contactId; + } + + /** + * @param string $value + */ + public function setContactId(string $value): self + { + $this->contactId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomObjectInstanceDeleted.php b/src/Unstable/Types/CustomObjectInstanceDeleted.php new file mode 100644 index 00000000..383da161 --- /dev/null +++ b/src/Unstable/Types/CustomObjectInstanceDeleted.php @@ -0,0 +1,104 @@ +object = $values['object'] ?? null; + $this->id = $values['id'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?string $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomObjectInstanceList.php b/src/Unstable/Types/CustomObjectInstanceList.php new file mode 100644 index 00000000..056978c4 --- /dev/null +++ b/src/Unstable/Types/CustomObjectInstanceList.php @@ -0,0 +1,82 @@ + $instances The list of associated custom object instances for a given reference attribute on the parent object. + */ + #[JsonProperty('instances'), ArrayType([new Union(CustomObjectInstance::class, 'null')])] + private ?array $instances; + + /** + * @param array{ + * type?: ?string, + * instances?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->instances = $values['instances'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getInstances(): ?array + { + return $this->instances; + } + + /** + * @param ?array $value + */ + public function setInstances(?array $value = null): self + { + $this->instances = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomerRequestEmail.php b/src/Unstable/Types/CustomerRequestEmail.php new file mode 100644 index 00000000..0d966030 --- /dev/null +++ b/src/Unstable/Types/CustomerRequestEmail.php @@ -0,0 +1,51 @@ +email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomerRequestIntercomUserId.php b/src/Unstable/Types/CustomerRequestIntercomUserId.php new file mode 100644 index 00000000..e0eda056 --- /dev/null +++ b/src/Unstable/Types/CustomerRequestIntercomUserId.php @@ -0,0 +1,51 @@ +intercomUserId = $values['intercomUserId']; + } + + /** + * @return string + */ + public function getIntercomUserId(): string + { + return $this->intercomUserId; + } + + /** + * @param string $value + */ + public function setIntercomUserId(string $value): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/CustomerRequestUserId.php b/src/Unstable/Types/CustomerRequestUserId.php new file mode 100644 index 00000000..390fc075 --- /dev/null +++ b/src/Unstable/Types/CustomerRequestUserId.php @@ -0,0 +1,51 @@ +userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DataAttributeList.php b/src/Unstable/Types/DataAttributeList.php new file mode 100644 index 00000000..6be5d63b --- /dev/null +++ b/src/Unstable/Types/DataAttributeList.php @@ -0,0 +1,81 @@ + $data A list of data attributes + */ + #[JsonProperty('data'), ArrayType([DataAttribute::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DataEventList.php b/src/Unstable/Types/DataEventList.php new file mode 100644 index 00000000..f2fa5a8d --- /dev/null +++ b/src/Unstable/Types/DataEventList.php @@ -0,0 +1,106 @@ + $events A list of data events + */ + #[JsonProperty('events'), ArrayType([DataEvent::class])] + private ?array $events; + + /** + * @var ?DataEventListPages $pages Pagination + */ + #[JsonProperty('pages')] + private ?DataEventListPages $pages; + + /** + * @param array{ + * type?: ?'event.list', + * events?: ?array, + * pages?: ?DataEventListPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->events = $values['events'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'event.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'event.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getEvents(): ?array + { + return $this->events; + } + + /** + * @param ?array $value + */ + public function setEvents(?array $value = null): self + { + $this->events = $value; + return $this; + } + + /** + * @return ?DataEventListPages + */ + public function getPages(): ?DataEventListPages + { + return $this->pages; + } + + /** + * @param ?DataEventListPages $value + */ + public function setPages(?DataEventListPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DataEventListPages.php b/src/Unstable/Types/DataEventListPages.php new file mode 100644 index 00000000..49d9b991 --- /dev/null +++ b/src/Unstable/Types/DataEventListPages.php @@ -0,0 +1,79 @@ +next = $values['next'] ?? null; + $this->since = $values['since'] ?? null; + } + + /** + * @return ?string + */ + public function getNext(): ?string + { + return $this->next; + } + + /** + * @param ?string $value + */ + public function setNext(?string $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSince(): ?string + { + return $this->since; + } + + /** + * @param ?string $value + */ + public function setSince(?string $value = null): self + { + $this->since = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DataEventSummary.php b/src/Unstable/Types/DataEventSummary.php new file mode 100644 index 00000000..804bc3bd --- /dev/null +++ b/src/Unstable/Types/DataEventSummary.php @@ -0,0 +1,156 @@ + $events A summary of data events + */ + #[JsonProperty('events'), ArrayType([new Union(DataEventSummaryItem::class, 'null')])] + private ?array $events; + + /** + * @param array{ + * type?: ?'event.summary', + * email?: ?string, + * intercomUserId?: ?string, + * userId?: ?string, + * events?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->email = $values['email'] ?? null; + $this->intercomUserId = $values['intercomUserId'] ?? null; + $this->userId = $values['userId'] ?? null; + $this->events = $values['events'] ?? null; + } + + /** + * @return ?'event.summary' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'event.summary' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIntercomUserId(): ?string + { + return $this->intercomUserId; + } + + /** + * @param ?string $value + */ + public function setIntercomUserId(?string $value = null): self + { + $this->intercomUserId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?array + */ + public function getEvents(): ?array + { + return $this->events; + } + + /** + * @param ?array $value + */ + public function setEvents(?array $value = null): self + { + $this->events = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DataEventSummaryItem.php b/src/Unstable/Types/DataEventSummaryItem.php new file mode 100644 index 00000000..fb79e2ed --- /dev/null +++ b/src/Unstable/Types/DataEventSummaryItem.php @@ -0,0 +1,154 @@ +name = $values['name'] ?? null; + $this->first = $values['first'] ?? null; + $this->last = $values['last'] ?? null; + $this->count = $values['count'] ?? null; + $this->description = $values['description'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getFirst(): ?string + { + return $this->first; + } + + /** + * @param ?string $value + */ + public function setFirst(?string $value = null): self + { + $this->first = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLast(): ?string + { + return $this->last; + } + + /** + * @param ?string $value + */ + public function setLast(?string $value = null): self + { + $this->last = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCount(): ?int + { + return $this->count; + } + + /** + * @param ?int $value + */ + public function setCount(?int $value = null): self + { + $this->count = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DataExportCsv.php b/src/Unstable/Types/DataExportCsv.php new file mode 100644 index 00000000..0052578a --- /dev/null +++ b/src/Unstable/Types/DataExportCsv.php @@ -0,0 +1,679 @@ +userId = $values['userId'] ?? null; + $this->userExternalId = $values['userExternalId'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->email = $values['email'] ?? null; + $this->name = $values['name'] ?? null; + $this->rulesetId = $values['rulesetId'] ?? null; + $this->contentId = $values['contentId'] ?? null; + $this->contentType = $values['contentType'] ?? null; + $this->contentTitle = $values['contentTitle'] ?? null; + $this->rulesetVersionId = $values['rulesetVersionId'] ?? null; + $this->receiptId = $values['receiptId'] ?? null; + $this->receivedAt = $values['receivedAt'] ?? null; + $this->seriesId = $values['seriesId'] ?? null; + $this->seriesTitle = $values['seriesTitle'] ?? null; + $this->nodeId = $values['nodeId'] ?? null; + $this->firstReply = $values['firstReply'] ?? null; + $this->firstCompletion = $values['firstCompletion'] ?? null; + $this->firstSeriesCompletion = $values['firstSeriesCompletion'] ?? null; + $this->firstSeriesDisengagement = $values['firstSeriesDisengagement'] ?? null; + $this->firstSeriesExit = $values['firstSeriesExit'] ?? null; + $this->firstGoalSuccess = $values['firstGoalSuccess'] ?? null; + $this->firstOpen = $values['firstOpen'] ?? null; + $this->firstClick = $values['firstClick'] ?? null; + $this->firstDismisall = $values['firstDismisall'] ?? null; + $this->firstUnsubscribe = $values['firstUnsubscribe'] ?? null; + $this->firstHardBounce = $values['firstHardBounce'] ?? null; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserExternalId(): ?string + { + return $this->userExternalId; + } + + /** + * @param ?string $value + */ + public function setUserExternalId(?string $value = null): self + { + $this->userExternalId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRulesetId(): ?string + { + return $this->rulesetId; + } + + /** + * @param ?string $value + */ + public function setRulesetId(?string $value = null): self + { + $this->rulesetId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContentId(): ?string + { + return $this->contentId; + } + + /** + * @param ?string $value + */ + public function setContentId(?string $value = null): self + { + $this->contentId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContentType(): ?string + { + return $this->contentType; + } + + /** + * @param ?string $value + */ + public function setContentType(?string $value = null): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContentTitle(): ?string + { + return $this->contentTitle; + } + + /** + * @param ?string $value + */ + public function setContentTitle(?string $value = null): self + { + $this->contentTitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRulesetVersionId(): ?string + { + return $this->rulesetVersionId; + } + + /** + * @param ?string $value + */ + public function setRulesetVersionId(?string $value = null): self + { + $this->rulesetVersionId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getReceiptId(): ?string + { + return $this->receiptId; + } + + /** + * @param ?string $value + */ + public function setReceiptId(?string $value = null): self + { + $this->receiptId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getReceivedAt(): ?int + { + return $this->receivedAt; + } + + /** + * @param ?int $value + */ + public function setReceivedAt(?int $value = null): self + { + $this->receivedAt = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSeriesId(): ?string + { + return $this->seriesId; + } + + /** + * @param ?string $value + */ + public function setSeriesId(?string $value = null): self + { + $this->seriesId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSeriesTitle(): ?string + { + return $this->seriesTitle; + } + + /** + * @param ?string $value + */ + public function setSeriesTitle(?string $value = null): self + { + $this->seriesTitle = $value; + return $this; + } + + /** + * @return ?string + */ + public function getNodeId(): ?string + { + return $this->nodeId; + } + + /** + * @param ?string $value + */ + public function setNodeId(?string $value = null): self + { + $this->nodeId = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstReply(): ?int + { + return $this->firstReply; + } + + /** + * @param ?int $value + */ + public function setFirstReply(?int $value = null): self + { + $this->firstReply = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstCompletion(): ?int + { + return $this->firstCompletion; + } + + /** + * @param ?int $value + */ + public function setFirstCompletion(?int $value = null): self + { + $this->firstCompletion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstSeriesCompletion(): ?int + { + return $this->firstSeriesCompletion; + } + + /** + * @param ?int $value + */ + public function setFirstSeriesCompletion(?int $value = null): self + { + $this->firstSeriesCompletion = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstSeriesDisengagement(): ?int + { + return $this->firstSeriesDisengagement; + } + + /** + * @param ?int $value + */ + public function setFirstSeriesDisengagement(?int $value = null): self + { + $this->firstSeriesDisengagement = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstSeriesExit(): ?int + { + return $this->firstSeriesExit; + } + + /** + * @param ?int $value + */ + public function setFirstSeriesExit(?int $value = null): self + { + $this->firstSeriesExit = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstGoalSuccess(): ?int + { + return $this->firstGoalSuccess; + } + + /** + * @param ?int $value + */ + public function setFirstGoalSuccess(?int $value = null): self + { + $this->firstGoalSuccess = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstOpen(): ?int + { + return $this->firstOpen; + } + + /** + * @param ?int $value + */ + public function setFirstOpen(?int $value = null): self + { + $this->firstOpen = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstClick(): ?int + { + return $this->firstClick; + } + + /** + * @param ?int $value + */ + public function setFirstClick(?int $value = null): self + { + $this->firstClick = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstDismisall(): ?int + { + return $this->firstDismisall; + } + + /** + * @param ?int $value + */ + public function setFirstDismisall(?int $value = null): self + { + $this->firstDismisall = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstUnsubscribe(): ?int + { + return $this->firstUnsubscribe; + } + + /** + * @param ?int $value + */ + public function setFirstUnsubscribe(?int $value = null): self + { + $this->firstUnsubscribe = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFirstHardBounce(): ?int + { + return $this->firstHardBounce; + } + + /** + * @param ?int $value + */ + public function setFirstHardBounce(?int $value = null): self + { + $this->firstHardBounce = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DeletedArticleObject.php b/src/Unstable/Types/DeletedArticleObject.php new file mode 100644 index 00000000..27cc40c2 --- /dev/null +++ b/src/Unstable/Types/DeletedArticleObject.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->object = $values['object'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'article' + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?'article' $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DeletedCollectionObject.php b/src/Unstable/Types/DeletedCollectionObject.php new file mode 100644 index 00000000..eeca73a4 --- /dev/null +++ b/src/Unstable/Types/DeletedCollectionObject.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->object = $values['object'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'collection' + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?'collection' $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DeletedCompanyObject.php b/src/Unstable/Types/DeletedCompanyObject.php new file mode 100644 index 00000000..d2e5c840 --- /dev/null +++ b/src/Unstable/Types/DeletedCompanyObject.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->object = $values['object'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'company' + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?'company' $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/DeletedObject.php b/src/Unstable/Types/DeletedObject.php new file mode 100644 index 00000000..745c7474 --- /dev/null +++ b/src/Unstable/Types/DeletedObject.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->object = $values['object'] ?? null; + $this->deleted = $values['deleted'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'news-item' + */ + public function getObject(): ?string + { + return $this->object; + } + + /** + * @param ?'news-item' $value + */ + public function setObject(?string $value = null): self + { + $this->object = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeleted(): ?bool + { + return $this->deleted; + } + + /** + * @param ?bool $value + */ + public function setDeleted(?bool $value = null): self + { + $this->deleted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/EmailAddressHeader.php b/src/Unstable/Types/EmailAddressHeader.php new file mode 100644 index 00000000..aae9bf68 --- /dev/null +++ b/src/Unstable/Types/EmailAddressHeader.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->emailAddress = $values['emailAddress'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmailAddress(): ?string + { + return $this->emailAddress; + } + + /** + * @param ?string $value + */ + public function setEmailAddress(?string $value = null): self + { + $this->emailAddress = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/EmailMessageMetadata.php b/src/Unstable/Types/EmailMessageMetadata.php new file mode 100644 index 00000000..bd3d457a --- /dev/null +++ b/src/Unstable/Types/EmailMessageMetadata.php @@ -0,0 +1,80 @@ + $emailAddressHeaders A list of an email address headers. + */ + #[JsonProperty('email_address_headers'), ArrayType([EmailAddressHeader::class])] + private ?array $emailAddressHeaders; + + /** + * @param array{ + * subject?: ?string, + * emailAddressHeaders?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->subject = $values['subject'] ?? null; + $this->emailAddressHeaders = $values['emailAddressHeaders'] ?? null; + } + + /** + * @return ?string + */ + public function getSubject(): ?string + { + return $this->subject; + } + + /** + * @param ?string $value + */ + public function setSubject(?string $value = null): self + { + $this->subject = $value; + return $this; + } + + /** + * @return ?array + */ + public function getEmailAddressHeaders(): ?array + { + return $this->emailAddressHeaders; + } + + /** + * @param ?array $value + */ + public function setEmailAddressHeaders(?array $value = null): self + { + $this->emailAddressHeaders = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/Error.php b/src/Unstable/Types/Error.php new file mode 100644 index 00000000..896c7306 --- /dev/null +++ b/src/Unstable/Types/Error.php @@ -0,0 +1,105 @@ + $errors An array of one or more error objects + */ + #[JsonProperty('errors'), ArrayType([ErrorErrorsItem::class])] + private array $errors; + + /** + * @param array{ + * type: string, + * errors: array, + * requestId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->requestId = $values['requestId'] ?? null; + $this->errors = $values['errors']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRequestId(): ?string + { + return $this->requestId; + } + + /** + * @param ?string $value + */ + public function setRequestId(?string $value = null): self + { + $this->requestId = $value; + return $this; + } + + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * @param array $value + */ + public function setErrors(array $value): self + { + $this->errors = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/ErrorErrorsItem.php b/src/Unstable/Types/ErrorErrorsItem.php new file mode 100644 index 00000000..3856aa30 --- /dev/null +++ b/src/Unstable/Types/ErrorErrorsItem.php @@ -0,0 +1,101 @@ +code = $values['code']; + $this->message = $values['message'] ?? null; + $this->field = $values['field'] ?? null; + } + + /** + * @return string + */ + public function getCode(): string + { + return $this->code; + } + + /** + * @param string $value + */ + public function setCode(string $value): self + { + $this->code = $value; + return $this; + } + + /** + * @return ?string + */ + public function getMessage(): ?string + { + return $this->message; + } + + /** + * @param ?string $value + */ + public function setMessage(?string $value = null): self + { + $this->message = $value; + return $this; + } + + /** + * @return ?string + */ + public function getField(): ?string + { + return $this->field; + } + + /** + * @param ?string $value + */ + public function setField(?string $value = null): self + { + $this->field = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/FileAttribute.php b/src/Unstable/Types/FileAttribute.php new file mode 100644 index 00000000..78aa6c2c --- /dev/null +++ b/src/Unstable/Types/FileAttribute.php @@ -0,0 +1,204 @@ +type = $values['type'] ?? null; + $this->name = $values['name'] ?? null; + $this->url = $values['url'] ?? null; + $this->contentType = $values['contentType'] ?? null; + $this->filesize = $values['filesize'] ?? null; + $this->width = $values['width'] ?? null; + $this->height = $values['height'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContentType(): ?string + { + return $this->contentType; + } + + /** + * @param ?string $value + */ + public function setContentType(?string $value = null): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFilesize(): ?int + { + return $this->filesize; + } + + /** + * @param ?int $value + */ + public function setFilesize(?int $value = null): self + { + $this->filesize = $value; + return $this; + } + + /** + * @return ?int + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * @param ?int $value + */ + public function setWidth(?int $value = null): self + { + $this->width = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * @param ?int $value + */ + public function setHeight(?int $value = null): self + { + $this->height = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/GroupContent.php b/src/Unstable/Types/GroupContent.php new file mode 100644 index 00000000..0de13d13 --- /dev/null +++ b/src/Unstable/Types/GroupContent.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/GroupTranslatedContent.php b/src/Unstable/Types/GroupTranslatedContent.php new file mode 100644 index 00000000..3ac4865b --- /dev/null +++ b/src/Unstable/Types/GroupTranslatedContent.php @@ -0,0 +1,979 @@ +type = $values['type'] ?? null; + $this->ar = $values['ar'] ?? null; + $this->bg = $values['bg'] ?? null; + $this->bs = $values['bs'] ?? null; + $this->ca = $values['ca'] ?? null; + $this->cs = $values['cs'] ?? null; + $this->da = $values['da'] ?? null; + $this->de = $values['de'] ?? null; + $this->el = $values['el'] ?? null; + $this->en = $values['en'] ?? null; + $this->es = $values['es'] ?? null; + $this->et = $values['et'] ?? null; + $this->fi = $values['fi'] ?? null; + $this->fr = $values['fr'] ?? null; + $this->he = $values['he'] ?? null; + $this->hr = $values['hr'] ?? null; + $this->hu = $values['hu'] ?? null; + $this->id = $values['id'] ?? null; + $this->it = $values['it'] ?? null; + $this->ja = $values['ja'] ?? null; + $this->ko = $values['ko'] ?? null; + $this->lt = $values['lt'] ?? null; + $this->lv = $values['lv'] ?? null; + $this->mn = $values['mn'] ?? null; + $this->nb = $values['nb'] ?? null; + $this->nl = $values['nl'] ?? null; + $this->pl = $values['pl'] ?? null; + $this->pt = $values['pt'] ?? null; + $this->ro = $values['ro'] ?? null; + $this->ru = $values['ru'] ?? null; + $this->sl = $values['sl'] ?? null; + $this->sr = $values['sr'] ?? null; + $this->sv = $values['sv'] ?? null; + $this->tr = $values['tr'] ?? null; + $this->vi = $values['vi'] ?? null; + $this->ptBr = $values['ptBr'] ?? null; + $this->zhCn = $values['zhCn'] ?? null; + $this->zhTw = $values['zhTw'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getAr(): ?GroupContent + { + return $this->ar; + } + + /** + * @param ?GroupContent $value + */ + public function setAr(?GroupContent $value = null): self + { + $this->ar = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getBg(): ?GroupContent + { + return $this->bg; + } + + /** + * @param ?GroupContent $value + */ + public function setBg(?GroupContent $value = null): self + { + $this->bg = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getBs(): ?GroupContent + { + return $this->bs; + } + + /** + * @param ?GroupContent $value + */ + public function setBs(?GroupContent $value = null): self + { + $this->bs = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getCa(): ?GroupContent + { + return $this->ca; + } + + /** + * @param ?GroupContent $value + */ + public function setCa(?GroupContent $value = null): self + { + $this->ca = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getCs(): ?GroupContent + { + return $this->cs; + } + + /** + * @param ?GroupContent $value + */ + public function setCs(?GroupContent $value = null): self + { + $this->cs = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getDa(): ?GroupContent + { + return $this->da; + } + + /** + * @param ?GroupContent $value + */ + public function setDa(?GroupContent $value = null): self + { + $this->da = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getDe(): ?GroupContent + { + return $this->de; + } + + /** + * @param ?GroupContent $value + */ + public function setDe(?GroupContent $value = null): self + { + $this->de = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEl(): ?GroupContent + { + return $this->el; + } + + /** + * @param ?GroupContent $value + */ + public function setEl(?GroupContent $value = null): self + { + $this->el = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEn(): ?GroupContent + { + return $this->en; + } + + /** + * @param ?GroupContent $value + */ + public function setEn(?GroupContent $value = null): self + { + $this->en = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEs(): ?GroupContent + { + return $this->es; + } + + /** + * @param ?GroupContent $value + */ + public function setEs(?GroupContent $value = null): self + { + $this->es = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getEt(): ?GroupContent + { + return $this->et; + } + + /** + * @param ?GroupContent $value + */ + public function setEt(?GroupContent $value = null): self + { + $this->et = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getFi(): ?GroupContent + { + return $this->fi; + } + + /** + * @param ?GroupContent $value + */ + public function setFi(?GroupContent $value = null): self + { + $this->fi = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getFr(): ?GroupContent + { + return $this->fr; + } + + /** + * @param ?GroupContent $value + */ + public function setFr(?GroupContent $value = null): self + { + $this->fr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getHe(): ?GroupContent + { + return $this->he; + } + + /** + * @param ?GroupContent $value + */ + public function setHe(?GroupContent $value = null): self + { + $this->he = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getHr(): ?GroupContent + { + return $this->hr; + } + + /** + * @param ?GroupContent $value + */ + public function setHr(?GroupContent $value = null): self + { + $this->hr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getHu(): ?GroupContent + { + return $this->hu; + } + + /** + * @param ?GroupContent $value + */ + public function setHu(?GroupContent $value = null): self + { + $this->hu = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getId(): ?GroupContent + { + return $this->id; + } + + /** + * @param ?GroupContent $value + */ + public function setId(?GroupContent $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getIt(): ?GroupContent + { + return $this->it; + } + + /** + * @param ?GroupContent $value + */ + public function setIt(?GroupContent $value = null): self + { + $this->it = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getJa(): ?GroupContent + { + return $this->ja; + } + + /** + * @param ?GroupContent $value + */ + public function setJa(?GroupContent $value = null): self + { + $this->ja = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getKo(): ?GroupContent + { + return $this->ko; + } + + /** + * @param ?GroupContent $value + */ + public function setKo(?GroupContent $value = null): self + { + $this->ko = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getLt(): ?GroupContent + { + return $this->lt; + } + + /** + * @param ?GroupContent $value + */ + public function setLt(?GroupContent $value = null): self + { + $this->lt = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getLv(): ?GroupContent + { + return $this->lv; + } + + /** + * @param ?GroupContent $value + */ + public function setLv(?GroupContent $value = null): self + { + $this->lv = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getMn(): ?GroupContent + { + return $this->mn; + } + + /** + * @param ?GroupContent $value + */ + public function setMn(?GroupContent $value = null): self + { + $this->mn = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getNb(): ?GroupContent + { + return $this->nb; + } + + /** + * @param ?GroupContent $value + */ + public function setNb(?GroupContent $value = null): self + { + $this->nb = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getNl(): ?GroupContent + { + return $this->nl; + } + + /** + * @param ?GroupContent $value + */ + public function setNl(?GroupContent $value = null): self + { + $this->nl = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getPl(): ?GroupContent + { + return $this->pl; + } + + /** + * @param ?GroupContent $value + */ + public function setPl(?GroupContent $value = null): self + { + $this->pl = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getPt(): ?GroupContent + { + return $this->pt; + } + + /** + * @param ?GroupContent $value + */ + public function setPt(?GroupContent $value = null): self + { + $this->pt = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getRo(): ?GroupContent + { + return $this->ro; + } + + /** + * @param ?GroupContent $value + */ + public function setRo(?GroupContent $value = null): self + { + $this->ro = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getRu(): ?GroupContent + { + return $this->ru; + } + + /** + * @param ?GroupContent $value + */ + public function setRu(?GroupContent $value = null): self + { + $this->ru = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getSl(): ?GroupContent + { + return $this->sl; + } + + /** + * @param ?GroupContent $value + */ + public function setSl(?GroupContent $value = null): self + { + $this->sl = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getSr(): ?GroupContent + { + return $this->sr; + } + + /** + * @param ?GroupContent $value + */ + public function setSr(?GroupContent $value = null): self + { + $this->sr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getSv(): ?GroupContent + { + return $this->sv; + } + + /** + * @param ?GroupContent $value + */ + public function setSv(?GroupContent $value = null): self + { + $this->sv = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getTr(): ?GroupContent + { + return $this->tr; + } + + /** + * @param ?GroupContent $value + */ + public function setTr(?GroupContent $value = null): self + { + $this->tr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getVi(): ?GroupContent + { + return $this->vi; + } + + /** + * @param ?GroupContent $value + */ + public function setVi(?GroupContent $value = null): self + { + $this->vi = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getPtBr(): ?GroupContent + { + return $this->ptBr; + } + + /** + * @param ?GroupContent $value + */ + public function setPtBr(?GroupContent $value = null): self + { + $this->ptBr = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getZhCn(): ?GroupContent + { + return $this->zhCn; + } + + /** + * @param ?GroupContent $value + */ + public function setZhCn(?GroupContent $value = null): self + { + $this->zhCn = $value; + return $this; + } + + /** + * @return ?GroupContent + */ + public function getZhTw(): ?GroupContent + { + return $this->zhTw; + } + + /** + * @param ?GroupContent $value + */ + public function setZhTw(?GroupContent $value = null): self + { + $this->zhTw = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/IntercomVersion.php b/src/Unstable/Types/IntercomVersion.php new file mode 100644 index 00000000..77ad8985 --- /dev/null +++ b/src/Unstable/Types/IntercomVersion.php @@ -0,0 +1,25 @@ + $type ticket or conversation + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $id The ID of the linked object + */ + #[JsonProperty('id')] + private ?string $id; + + /** + * @var ?string $category Category of the Linked Ticket Object. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @param array{ + * type?: ?value-of, + * id?: ?string, + * category?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->category = $values['category'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?string $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/LinkedObjectList.php b/src/Unstable/Types/LinkedObjectList.php new file mode 100644 index 00000000..cd63d41d --- /dev/null +++ b/src/Unstable/Types/LinkedObjectList.php @@ -0,0 +1,130 @@ + $data An array containing the linked conversations and linked tickets. + */ + #[JsonProperty('data'), ArrayType([LinkedObject::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * totalCount?: ?int, + * hasMore?: ?bool, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->hasMore = $values['hasMore'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasMore(): ?bool + { + return $this->hasMore; + } + + /** + * @param ?bool $value + */ + public function setHasMore(?bool $value = null): self + { + $this->hasMore = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/LinkedObjectType.php b/src/Unstable/Types/LinkedObjectType.php new file mode 100644 index 00000000..dc21d8ba --- /dev/null +++ b/src/Unstable/Types/LinkedObjectType.php @@ -0,0 +1,9 @@ + $operator An operator to allow boolean inspection between multiple fields. + */ + #[JsonProperty('operator')] + private ?string $operator; + + /** + * @var ( + * array + * |array + * )|null $value + */ + #[JsonProperty('value'), Union([MultipleFilterSearchRequest::class], [SingleFilterSearchRequest::class], 'null')] + private array|null $value; + + /** + * @param array{ + * operator?: ?value-of, + * value?: ( + * array + * |array + * )|null, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->operator = $values['operator'] ?? null; + $this->value = $values['value'] ?? null; + } + + /** + * @return ?value-of + */ + public function getOperator(): ?string + { + return $this->operator; + } + + /** + * @param ?value-of $value + */ + public function setOperator(?string $value = null): self + { + $this->operator = $value; + return $this; + } + + /** + * @return ( + * array + * |array + * )|null + */ + public function getValue(): array|null + { + return $this->value; + } + + /** + * @param ( + * array + * |array + * )|null $value + */ + public function setValue(array|null $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/MultipleFilterSearchRequestOperator.php b/src/Unstable/Types/MultipleFilterSearchRequestOperator.php new file mode 100644 index 00000000..1b3b3b8d --- /dev/null +++ b/src/Unstable/Types/MultipleFilterSearchRequestOperator.php @@ -0,0 +1,9 @@ + $state News items will not be visible to your users in the assigned newsfeeds until they are set live. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?bool $deliverSilently When set to `true`, the news item will appear in the messenger newsfeed without showing a notification badge. + */ + #[JsonProperty('deliver_silently')] + private ?bool $deliverSilently; + + /** + * @var ?array $labels Label names displayed to users to categorize the news item. + */ + #[JsonProperty('labels'), ArrayType(['string'])] + private ?array $labels; + + /** + * @var ?array $reactions Ordered list of emoji reactions to the news item. When empty, reactions are disabled. + */ + #[JsonProperty('reactions'), ArrayType([new Union('string', 'null')])] + private ?array $reactions; + + /** + * @var ?array $newsfeedAssignments A list of newsfeed_assignments to assign to the specified newsfeed. + */ + #[JsonProperty('newsfeed_assignments'), ArrayType([NewsfeedAssignment::class])] + private ?array $newsfeedAssignments; + + /** + * @param array{ + * title: string, + * senderId: int, + * body?: ?string, + * state?: ?value-of, + * deliverSilently?: ?bool, + * labels?: ?array, + * reactions?: ?array, + * newsfeedAssignments?: ?array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->title = $values['title']; + $this->body = $values['body'] ?? null; + $this->senderId = $values['senderId']; + $this->state = $values['state'] ?? null; + $this->deliverSilently = $values['deliverSilently'] ?? null; + $this->labels = $values['labels'] ?? null; + $this->reactions = $values['reactions'] ?? null; + $this->newsfeedAssignments = $values['newsfeedAssignments'] ?? null; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @param string $value + */ + public function setTitle(string $value): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return int + */ + public function getSenderId(): int + { + return $this->senderId; + } + + /** + * @param int $value + */ + public function setSenderId(int $value): self + { + $this->senderId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDeliverSilently(): ?bool + { + return $this->deliverSilently; + } + + /** + * @param ?bool $value + */ + public function setDeliverSilently(?bool $value = null): self + { + $this->deliverSilently = $value; + return $this; + } + + /** + * @return ?array + */ + public function getLabels(): ?array + { + return $this->labels; + } + + /** + * @param ?array $value + */ + public function setLabels(?array $value = null): self + { + $this->labels = $value; + return $this; + } + + /** + * @return ?array + */ + public function getReactions(): ?array + { + return $this->reactions; + } + + /** + * @param ?array $value + */ + public function setReactions(?array $value = null): self + { + $this->reactions = $value; + return $this; + } + + /** + * @return ?array + */ + public function getNewsfeedAssignments(): ?array + { + return $this->newsfeedAssignments; + } + + /** + * @param ?array $value + */ + public function setNewsfeedAssignments(?array $value = null): self + { + $this->newsfeedAssignments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/NewsItemRequestState.php b/src/Unstable/Types/NewsItemRequestState.php new file mode 100644 index 00000000..1def6ffd --- /dev/null +++ b/src/Unstable/Types/NewsItemRequestState.php @@ -0,0 +1,9 @@ + $errors An array of one or more error objects + */ + #[JsonProperty('errors'), ArrayType([NotFoundErrorBodyErrorsItem::class])] + private array $errors; + + /** + * @param array{ + * type: string, + * errors: array, + * requestId?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->requestId = $values['requestId'] ?? null; + $this->errors = $values['errors']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRequestId(): ?string + { + return $this->requestId; + } + + /** + * @param ?string $value + */ + public function setRequestId(?string $value = null): self + { + $this->requestId = $value; + return $this; + } + + /** + * @return array + */ + public function getErrors(): array + { + return $this->errors; + } + + /** + * @param array $value + */ + public function setErrors(array $value): self + { + $this->errors = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/NotFoundErrorBodyErrorsItem.php b/src/Unstable/Types/NotFoundErrorBodyErrorsItem.php new file mode 100644 index 00000000..cdd1d01f --- /dev/null +++ b/src/Unstable/Types/NotFoundErrorBodyErrorsItem.php @@ -0,0 +1,76 @@ +code = $values['code']; + $this->message = $values['message'] ?? null; + } + + /** + * @return string + */ + public function getCode(): string + { + return $this->code; + } + + /** + * @param string $value + */ + public function setCode(string $value): self + { + $this->code = $value; + return $this; + } + + /** + * @return ?string + */ + public function getMessage(): ?string + { + return $this->message; + } + + /** + * @param ?string $value + */ + public function setMessage(?string $value = null): self + { + $this->message = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/NoteList.php b/src/Unstable/Types/NoteList.php new file mode 100644 index 00000000..0e45435f --- /dev/null +++ b/src/Unstable/Types/NoteList.php @@ -0,0 +1,131 @@ + $data An array of notes. + */ + #[JsonProperty('data'), ArrayType([Note::class])] + private ?array $data; + + /** + * @var ?int $totalCount A count of the total number of notes. + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type?: ?string, + * data?: ?array, + * totalCount?: ?int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/OpenConversationRequest.php b/src/Unstable/Types/OpenConversationRequest.php new file mode 100644 index 00000000..8cc8a0b0 --- /dev/null +++ b/src/Unstable/Types/OpenConversationRequest.php @@ -0,0 +1,54 @@ +adminId = $values['adminId']; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/OperatorWorkflowEvent.php b/src/Unstable/Types/OperatorWorkflowEvent.php new file mode 100644 index 00000000..ac4d073a --- /dev/null +++ b/src/Unstable/Types/OperatorWorkflowEvent.php @@ -0,0 +1,79 @@ +operator_workflow_event. + */ +class OperatorWorkflowEvent extends JsonSerializableType +{ + /** + * @var ?OperatorWorkflowEventWorkflow $workflow + */ + #[JsonProperty('workflow')] + private ?OperatorWorkflowEventWorkflow $workflow; + + /** + * @var ?OperatorWorkflowEventEvent $event + */ + #[JsonProperty('event')] + private ?OperatorWorkflowEventEvent $event; + + /** + * @param array{ + * workflow?: ?OperatorWorkflowEventWorkflow, + * event?: ?OperatorWorkflowEventEvent, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->workflow = $values['workflow'] ?? null; + $this->event = $values['event'] ?? null; + } + + /** + * @return ?OperatorWorkflowEventWorkflow + */ + public function getWorkflow(): ?OperatorWorkflowEventWorkflow + { + return $this->workflow; + } + + /** + * @param ?OperatorWorkflowEventWorkflow $value + */ + public function setWorkflow(?OperatorWorkflowEventWorkflow $value = null): self + { + $this->workflow = $value; + return $this; + } + + /** + * @return ?OperatorWorkflowEventEvent + */ + public function getEvent(): ?OperatorWorkflowEventEvent + { + return $this->event; + } + + /** + * @param ?OperatorWorkflowEventEvent $value + */ + public function setEvent(?OperatorWorkflowEventEvent $value = null): self + { + $this->event = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/OperatorWorkflowEventEvent.php b/src/Unstable/Types/OperatorWorkflowEventEvent.php new file mode 100644 index 00000000..564312ef --- /dev/null +++ b/src/Unstable/Types/OperatorWorkflowEventEvent.php @@ -0,0 +1,76 @@ +type = $values['type'] ?? null; + $this->result = $values['result'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getResult(): ?string + { + return $this->result; + } + + /** + * @param ?string $value + */ + public function setResult(?string $value = null): self + { + $this->result = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/OperatorWorkflowEventWorkflow.php b/src/Unstable/Types/OperatorWorkflowEventWorkflow.php new file mode 100644 index 00000000..1ddb45de --- /dev/null +++ b/src/Unstable/Types/OperatorWorkflowEventWorkflow.php @@ -0,0 +1,51 @@ +name = $values['name'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/PagesLink.php b/src/Unstable/Types/PagesLink.php new file mode 100644 index 00000000..34a945e8 --- /dev/null +++ b/src/Unstable/Types/PagesLink.php @@ -0,0 +1,156 @@ +type = $values['type'] ?? null; + $this->page = $values['page'] ?? null; + $this->next = $values['next'] ?? null; + $this->perPage = $values['perPage'] ?? null; + $this->totalPages = $values['totalPages'] ?? null; + } + + /** + * @return ?'pages' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'pages' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPage(): ?int + { + return $this->page; + } + + /** + * @param ?int $value + */ + public function setPage(?int $value = null): self + { + $this->page = $value; + return $this; + } + + /** + * @return ?string + */ + public function getNext(): ?string + { + return $this->next; + } + + /** + * @param ?string $value + */ + public function setNext(?string $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalPages(): ?int + { + return $this->totalPages; + } + + /** + * @param ?int $value + */ + public function setTotalPages(?int $value = null): self + { + $this->totalPages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/PaginatedResponse.php b/src/Unstable/Types/PaginatedResponse.php new file mode 100644 index 00000000..3cf8fbdb --- /dev/null +++ b/src/Unstable/Types/PaginatedResponse.php @@ -0,0 +1,130 @@ + $type The type of object + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @var ?int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?array $data An array of Objects + */ + #[JsonProperty('data'), ArrayType([PaginatedResponseDataItem::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?value-of, + * pages?: ?CursorPages, + * totalCount?: ?int, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->pages = $values['pages'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/PaginatedResponseDataItem.php b/src/Unstable/Types/PaginatedResponseDataItem.php new file mode 100644 index 00000000..6663e2a4 --- /dev/null +++ b/src/Unstable/Types/PaginatedResponseDataItem.php @@ -0,0 +1,235 @@ +type = $values['type']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'news-item' + * |'newsfeed' + * |'_unknown' + * ) + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return ( + * NewsItem + * |Newsfeed + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param NewsItem $newsItem + * @return PaginatedResponseDataItem + */ + public static function newsItem(NewsItem $newsItem): PaginatedResponseDataItem + { + return new PaginatedResponseDataItem([ + 'type' => 'news-item', + 'value' => $newsItem, + ]); + } + + /** + * @param Newsfeed $newsfeed + * @return PaginatedResponseDataItem + */ + public static function newsfeed(Newsfeed $newsfeed): PaginatedResponseDataItem + { + return new PaginatedResponseDataItem([ + 'type' => 'newsfeed', + 'value' => $newsfeed, + ]); + } + + /** + * @return bool + */ + public function isNewsItem(): bool + { + return $this->value instanceof NewsItem && $this->type === 'news-item'; + } + + /** + * @return NewsItem + */ + public function asNewsItem(): NewsItem + { + if (!($this->value instanceof NewsItem && $this->type === 'news-item')) { + throw new Exception( + "Expected news-item; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isNewsfeed(): bool + { + return $this->value instanceof Newsfeed && $this->type === 'newsfeed'; + } + + /** + * @return Newsfeed + */ + public function asNewsfeed(): Newsfeed + { + if (!($this->value instanceof Newsfeed && $this->type === 'newsfeed')) { + throw new Exception( + "Expected newsfeed; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['type'] = $this->type; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->type) { + case 'news-item': + $value = $this->asNewsItem()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'newsfeed': + $value = $this->asNewsfeed()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('type', $data)) { + throw new Exception( + "JSON data is missing property 'type'", + ); + } + $type = $data['type']; + if (!(is_string($type))) { + throw new Exception( + "Expected property 'type' in JSON data to be string, instead received " . get_debug_type($data['type']), + ); + } + + $args['type'] = $type; + switch ($type) { + case 'news-item': + $args['value'] = NewsItem::jsonDeserialize($data); + break; + case 'newsfeed': + $args['value'] = Newsfeed::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['type'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Unstable/Types/PaginatedResponseType.php b/src/Unstable/Types/PaginatedResponseType.php new file mode 100644 index 00000000..81640380 --- /dev/null +++ b/src/Unstable/Types/PaginatedResponseType.php @@ -0,0 +1,9 @@ +type = $values['type'] ?? null; + $this->name = $values['name'] ?? null; + $this->url = $values['url'] ?? null; + $this->contentType = $values['contentType'] ?? null; + $this->filesize = $values['filesize'] ?? null; + $this->width = $values['width'] ?? null; + $this->height = $values['height'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContentType(): ?string + { + return $this->contentType; + } + + /** + * @param ?string $value + */ + public function setContentType(?string $value = null): self + { + $this->contentType = $value; + return $this; + } + + /** + * @return ?int + */ + public function getFilesize(): ?int + { + return $this->filesize; + } + + /** + * @param ?int $value + */ + public function setFilesize(?int $value = null): self + { + $this->filesize = $value; + return $this; + } + + /** + * @return ?int + */ + public function getWidth(): ?int + { + return $this->width; + } + + /** + * @param ?int $value + */ + public function setWidth(?int $value = null): self + { + $this->width = $value; + return $this; + } + + /** + * @return ?int + */ + public function getHeight(): ?int + { + return $this->height; + } + + /** + * @param ?int $value + */ + public function setHeight(?int $value = null): self + { + $this->height = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/PhoneSwitch.php b/src/Unstable/Types/PhoneSwitch.php new file mode 100644 index 00000000..a3f24921 --- /dev/null +++ b/src/Unstable/Types/PhoneSwitch.php @@ -0,0 +1,79 @@ +type = $values['type'] ?? null; + $this->phone = $values['phone'] ?? null; + } + + /** + * @return ?'phone_call_redirect' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'phone_call_redirect' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/QuickReplyOption.php b/src/Unstable/Types/QuickReplyOption.php new file mode 100644 index 00000000..2c59861e --- /dev/null +++ b/src/Unstable/Types/QuickReplyOption.php @@ -0,0 +1,76 @@ +text = $values['text']; + $this->uuid = $values['uuid']; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @param string $value + */ + public function setText(string $value): self + { + $this->text = $value; + return $this; + } + + /** + * @return string + */ + public function getUuid(): string + { + return $this->uuid; + } + + /** + * @param string $value + */ + public function setUuid(string $value): self + { + $this->uuid = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/Recipient.php b/src/Unstable/Types/Recipient.php new file mode 100644 index 00000000..3632630d --- /dev/null +++ b/src/Unstable/Types/Recipient.php @@ -0,0 +1,79 @@ + $type The role associated to the contact - `user` or `lead`. + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var string $id The identifier for the contact which is given by Intercom. + */ + #[JsonProperty('id')] + private string $id; + + /** + * @param array{ + * type: value-of, + * id: string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->id = $values['id']; + } + + /** + * @return value-of + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param value-of $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/RecipientType.php b/src/Unstable/Types/RecipientType.php new file mode 100644 index 00000000..0302a524 --- /dev/null +++ b/src/Unstable/Types/RecipientType.php @@ -0,0 +1,9 @@ +type = $values['type']; + $this->value = $values['value']; + } + + /** + * @return ( + * 'conversation_part' + * |'source' + * |'_unknown' + * ) + */ + public function getType(): string + { + return $this->type; + } + + /** + * @return ( + * RedactConversationRequestConversationPart + * |RedactConversationRequestSource + * |mixed + * ) + */ + public function getValue(): mixed + { + return $this->value; + } + + /** + * @param RedactConversationRequestConversationPart $conversationPart + * @return RedactConversationRequest + */ + public static function conversationPart(RedactConversationRequestConversationPart $conversationPart): RedactConversationRequest + { + return new RedactConversationRequest([ + 'type' => 'conversation_part', + 'value' => $conversationPart, + ]); + } + + /** + * @param RedactConversationRequestSource $source + * @return RedactConversationRequest + */ + public static function source(RedactConversationRequestSource $source): RedactConversationRequest + { + return new RedactConversationRequest([ + 'type' => 'source', + 'value' => $source, + ]); + } + + /** + * @return bool + */ + public function isConversationPart(): bool + { + return $this->value instanceof RedactConversationRequestConversationPart && $this->type === 'conversation_part'; + } + + /** + * @return RedactConversationRequestConversationPart + */ + public function asConversationPart(): RedactConversationRequestConversationPart + { + if (!($this->value instanceof RedactConversationRequestConversationPart && $this->type === 'conversation_part')) { + throw new Exception( + "Expected conversation_part; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return bool + */ + public function isSource(): bool + { + return $this->value instanceof RedactConversationRequestSource && $this->type === 'source'; + } + + /** + * @return RedactConversationRequestSource + */ + public function asSource(): RedactConversationRequestSource + { + if (!($this->value instanceof RedactConversationRequestSource && $this->type === 'source')) { + throw new Exception( + "Expected source; got " . $this->type . " with value of type " . get_debug_type($this->value), + ); + } + + return $this->value; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } + + /** + * @return array + */ + public function jsonSerialize(): array + { + $result = []; + $result['type'] = $this->type; + + $base = parent::jsonSerialize(); + $result = array_merge($base, $result); + + switch ($this->type) { + case 'conversation_part': + $value = $this->asConversationPart()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case 'source': + $value = $this->asSource()->jsonSerialize(); + $result = array_merge($value, $result); + break; + case '_unknown': + default: + if (is_null($this->value)) { + break; + } + if ($this->value instanceof JsonSerializableType) { + $value = $this->value->jsonSerialize(); + $result = array_merge($value, $result); + } elseif (is_array($this->value)) { + $result = array_merge($this->value, $result); + } + } + + return $result; + } + + /** + * @param string $json + */ + public static function fromJson(string $json): static + { + $decodedJson = JsonDecoder::decode($json); + if (!is_array($decodedJson)) { + throw new Exception("Unexpected non-array decoded type: " . gettype($decodedJson)); + } + return self::jsonDeserialize($decodedJson); + } + + /** + * @param array $data + */ + public static function jsonDeserialize(array $data): static + { + $args = []; + if (!array_key_exists('type', $data)) { + throw new Exception( + "JSON data is missing property 'type'", + ); + } + $type = $data['type']; + if (!(is_string($type))) { + throw new Exception( + "Expected property 'type' in JSON data to be string, instead received " . get_debug_type($data['type']), + ); + } + + $args['type'] = $type; + switch ($type) { + case 'conversation_part': + $args['value'] = RedactConversationRequestConversationPart::jsonDeserialize($data); + break; + case 'source': + $args['value'] = RedactConversationRequestSource::jsonDeserialize($data); + break; + case '_unknown': + default: + $args['type'] = '_unknown'; + $args['value'] = $data; + } + + // @phpstan-ignore-next-line + return new static($args); + } +} diff --git a/src/Unstable/Types/RedactConversationRequestConversationPart.php b/src/Unstable/Types/RedactConversationRequestConversationPart.php new file mode 100644 index 00000000..07c0fc9a --- /dev/null +++ b/src/Unstable/Types/RedactConversationRequestConversationPart.php @@ -0,0 +1,79 @@ +conversationId = $values['conversationId']; + $this->conversationPartId = $values['conversationPartId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getConversationPartId(): string + { + return $this->conversationPartId; + } + + /** + * @param string $value + */ + public function setConversationPartId(string $value): self + { + $this->conversationPartId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/RedactConversationRequestSource.php b/src/Unstable/Types/RedactConversationRequestSource.php new file mode 100644 index 00000000..fae7f81a --- /dev/null +++ b/src/Unstable/Types/RedactConversationRequestSource.php @@ -0,0 +1,79 @@ +conversationId = $values['conversationId']; + $this->sourceId = $values['sourceId']; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return string + */ + public function getSourceId(): string + { + return $this->sourceId; + } + + /** + * @param string $value + */ + public function setSourceId(string $value): self + { + $this->sourceId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/Reference.php b/src/Unstable/Types/Reference.php new file mode 100644 index 00000000..a49061f1 --- /dev/null +++ b/src/Unstable/Types/Reference.php @@ -0,0 +1,79 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SearchRequest.php b/src/Unstable/Types/SearchRequest.php new file mode 100644 index 00000000..8dc37b08 --- /dev/null +++ b/src/Unstable/Types/SearchRequest.php @@ -0,0 +1,92 @@ +query = $values['query']; + $this->pagination = $values['pagination'] ?? null; + } + + /** + * @return ( + * SingleFilterSearchRequest + * |MultipleFilterSearchRequest + * ) + */ + public function getQuery(): SingleFilterSearchRequest|MultipleFilterSearchRequest + { + return $this->query; + } + + /** + * @param ( + * SingleFilterSearchRequest + * |MultipleFilterSearchRequest + * ) $value + */ + public function setQuery(SingleFilterSearchRequest|MultipleFilterSearchRequest $value): self + { + $this->query = $value; + return $this; + } + + /** + * @return ?StartingAfterPaging + */ + public function getPagination(): ?StartingAfterPaging + { + return $this->pagination; + } + + /** + * @param ?StartingAfterPaging $value + */ + public function setPagination(?StartingAfterPaging $value = null): self + { + $this->pagination = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SegmentList.php b/src/Unstable/Types/SegmentList.php new file mode 100644 index 00000000..beffdc17 --- /dev/null +++ b/src/Unstable/Types/SegmentList.php @@ -0,0 +1,106 @@ + $segments A list of Segment objects + */ + #[JsonProperty('segments'), ArrayType([Segment::class])] + private ?array $segments; + + /** + * @var ?array $pages A pagination object, which may be empty, indicating no further pages to fetch. + */ + #[JsonProperty('pages'), ArrayType(['string' => 'mixed'])] + private ?array $pages; + + /** + * @param array{ + * type?: ?'segment.list', + * segments?: ?array, + * pages?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->segments = $values['segments'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'segment.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'segment.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSegments(): ?array + { + return $this->segments; + } + + /** + * @param ?array $value + */ + public function setSegments(?array $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return ?array + */ + public function getPages(): ?array + { + return $this->pages; + } + + /** + * @param ?array $value + */ + public function setPages(?array $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SingleFilterSearchRequest.php b/src/Unstable/Types/SingleFilterSearchRequest.php new file mode 100644 index 00000000..3e8983ba --- /dev/null +++ b/src/Unstable/Types/SingleFilterSearchRequest.php @@ -0,0 +1,133 @@ + $operator The accepted operators you can use to define how you want to search for the value. + */ + #[JsonProperty('operator')] + private ?string $operator; + + /** + * @var ( + * string + * |int + * |array<( + * string + * |int + * )> + * )|null $value The value that you want to search on. + */ + #[JsonProperty('value'), Union('string', 'integer', [new Union('string', 'integer')], 'null')] + private string|int|array|null $value; + + /** + * @param array{ + * field?: ?string, + * operator?: ?value-of, + * value?: ( + * string + * |int + * |array<( + * string + * |int + * )> + * )|null, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->field = $values['field'] ?? null; + $this->operator = $values['operator'] ?? null; + $this->value = $values['value'] ?? null; + } + + /** + * @return ?string + */ + public function getField(): ?string + { + return $this->field; + } + + /** + * @param ?string $value + */ + public function setField(?string $value = null): self + { + $this->field = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getOperator(): ?string + { + return $this->operator; + } + + /** + * @param ?value-of $value + */ + public function setOperator(?string $value = null): self + { + $this->operator = $value; + return $this; + } + + /** + * @return ( + * string + * |int + * |array<( + * string + * |int + * )> + * )|null + */ + public function getValue(): string|int|array|null + { + return $this->value; + } + + /** + * @param ( + * string + * |int + * |array<( + * string + * |int + * )> + * )|null $value + */ + public function setValue(string|int|array|null $value = null): self + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SingleFilterSearchRequestOperator.php b/src/Unstable/Types/SingleFilterSearchRequestOperator.php new file mode 100644 index 00000000..9da071db --- /dev/null +++ b/src/Unstable/Types/SingleFilterSearchRequestOperator.php @@ -0,0 +1,13 @@ +"; +} diff --git a/src/Unstable/Types/SlaApplied.php b/src/Unstable/Types/SlaApplied.php new file mode 100644 index 00000000..00992a62 --- /dev/null +++ b/src/Unstable/Types/SlaApplied.php @@ -0,0 +1,110 @@ + $slaStatus + */ + #[JsonProperty('sla_status')] + private ?string $slaStatus; + + /** + * @param array{ + * type?: ?string, + * slaName?: ?string, + * slaStatus?: ?value-of, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->slaName = $values['slaName'] ?? null; + $this->slaStatus = $values['slaStatus'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getSlaName(): ?string + { + return $this->slaName; + } + + /** + * @param ?string $value + */ + public function setSlaName(?string $value = null): self + { + $this->slaName = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getSlaStatus(): ?string + { + return $this->slaStatus; + } + + /** + * @param ?value-of $value + */ + public function setSlaStatus(?string $value = null): self + { + $this->slaStatus = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SlaAppliedSlaStatus.php b/src/Unstable/Types/SlaAppliedSlaStatus.php new file mode 100644 index 00000000..fc7deeba --- /dev/null +++ b/src/Unstable/Types/SlaAppliedSlaStatus.php @@ -0,0 +1,11 @@ +adminId = $values['adminId']; + $this->snoozedUntil = $values['snoozedUntil']; + } + + /** + * @return string + */ + public function getAdminId(): string + { + return $this->adminId; + } + + /** + * @param string $value + */ + public function setAdminId(string $value): self + { + $this->adminId = $value; + return $this; + } + + /** + * @return int + */ + public function getSnoozedUntil(): int + { + return $this->snoozedUntil; + } + + /** + * @param int $value + */ + public function setSnoozedUntil(int $value): self + { + $this->snoozedUntil = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SocialProfile.php b/src/Unstable/Types/SocialProfile.php new file mode 100644 index 00000000..d4c2fa47 --- /dev/null +++ b/src/Unstable/Types/SocialProfile.php @@ -0,0 +1,104 @@ +type = $values['type'] ?? null; + $this->name = $values['name'] ?? null; + $this->url = $values['url'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUrl(): ?string + { + return $this->url; + } + + /** + * @param ?string $value + */ + public function setUrl(?string $value = null): self + { + $this->url = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/StartingAfterPaging.php b/src/Unstable/Types/StartingAfterPaging.php new file mode 100644 index 00000000..95088542 --- /dev/null +++ b/src/Unstable/Types/StartingAfterPaging.php @@ -0,0 +1,76 @@ +perPage = $values['perPage'] ?? null; + $this->startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return ?int + */ + public function getPerPage(): ?int + { + return $this->perPage; + } + + /** + * @param ?int $value + */ + public function setPerPage(?int $value = null): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/SubscriptionTypeList.php b/src/Unstable/Types/SubscriptionTypeList.php new file mode 100644 index 00000000..702db284 --- /dev/null +++ b/src/Unstable/Types/SubscriptionTypeList.php @@ -0,0 +1,81 @@ + $data A list of subscription type objects associated with the workspace . + */ + #[JsonProperty('data'), ArrayType([SubscriptionType::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TagCompanyRequest.php b/src/Unstable/Types/TagCompanyRequest.php new file mode 100644 index 00000000..55f69920 --- /dev/null +++ b/src/Unstable/Types/TagCompanyRequest.php @@ -0,0 +1,80 @@ + $companies The id or company_id of the company can be passed as input parameters. + */ + #[JsonProperty('companies'), ArrayType([TagCompanyRequestCompaniesItem::class])] + private array $companies; + + /** + * @param array{ + * name: string, + * companies: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->companies = $values['companies']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getCompanies(): array + { + return $this->companies; + } + + /** + * @param array $value + */ + public function setCompanies(array $value): self + { + $this->companies = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TagCompanyRequestCompaniesItem.php b/src/Unstable/Types/TagCompanyRequestCompaniesItem.php new file mode 100644 index 00000000..82cb3fc5 --- /dev/null +++ b/src/Unstable/Types/TagCompanyRequestCompaniesItem.php @@ -0,0 +1,76 @@ +id = $values['id'] ?? null; + $this->companyId = $values['companyId'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TagList.php b/src/Unstable/Types/TagList.php new file mode 100644 index 00000000..092cba57 --- /dev/null +++ b/src/Unstable/Types/TagList.php @@ -0,0 +1,81 @@ + $data A list of tags objects associated with the workspace . + */ + #[JsonProperty('data'), ArrayType([Tag::class])] + private ?array $data; + + /** + * @param array{ + * type?: ?'list', + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?'list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TagMultipleUsersRequest.php b/src/Unstable/Types/TagMultipleUsersRequest.php new file mode 100644 index 00000000..9fdc8cba --- /dev/null +++ b/src/Unstable/Types/TagMultipleUsersRequest.php @@ -0,0 +1,80 @@ + $users + */ + #[JsonProperty('users'), ArrayType([TagMultipleUsersRequestUsersItem::class])] + private array $users; + + /** + * @param array{ + * name: string, + * users: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->users = $values['users']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getUsers(): array + { + return $this->users; + } + + /** + * @param array $value + */ + public function setUsers(array $value): self + { + $this->users = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TagMultipleUsersRequestUsersItem.php b/src/Unstable/Types/TagMultipleUsersRequestUsersItem.php new file mode 100644 index 00000000..c35c0a53 --- /dev/null +++ b/src/Unstable/Types/TagMultipleUsersRequestUsersItem.php @@ -0,0 +1,51 @@ +id = $values['id'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/Tags.php b/src/Unstable/Types/Tags.php new file mode 100644 index 00000000..64aef7eb --- /dev/null +++ b/src/Unstable/Types/Tags.php @@ -0,0 +1,81 @@ + $tags A list of tags objects associated with the conversation. + */ + #[JsonProperty('tags'), ArrayType([Tag::class])] + private ?array $tags; + + /** + * @param array{ + * type?: ?'tag.list', + * tags?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->tags = $values['tags'] ?? null; + } + + /** + * @return ?'tag.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTags(): ?array + { + return $this->tags; + } + + /** + * @param ?array $value + */ + public function setTags(?array $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TeamList.php b/src/Unstable/Types/TeamList.php new file mode 100644 index 00000000..2973ba2a --- /dev/null +++ b/src/Unstable/Types/TeamList.php @@ -0,0 +1,81 @@ + $teams A list of team objects + */ + #[JsonProperty('teams'), ArrayType([Team::class])] + private ?array $teams; + + /** + * @param array{ + * type?: ?'team.list', + * teams?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->teams = $values['teams'] ?? null; + } + + /** + * @return ?'team.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'team.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTeams(): ?array + { + return $this->teams; + } + + /** + * @param ?array $value + */ + public function setTeams(?array $value = null): self + { + $this->teams = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TeamPriorityLevel.php b/src/Unstable/Types/TeamPriorityLevel.php new file mode 100644 index 00000000..8a7ee6b9 --- /dev/null +++ b/src/Unstable/Types/TeamPriorityLevel.php @@ -0,0 +1,80 @@ + $primaryTeamIds The primary team ids for the team + */ + #[JsonProperty('primary_team_ids'), ArrayType(['integer'])] + private ?array $primaryTeamIds; + + /** + * @var ?array $secondaryTeamIds The secondary team ids for the team + */ + #[JsonProperty('secondary_team_ids'), ArrayType(['integer'])] + private ?array $secondaryTeamIds; + + /** + * @param array{ + * primaryTeamIds?: ?array, + * secondaryTeamIds?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->primaryTeamIds = $values['primaryTeamIds'] ?? null; + $this->secondaryTeamIds = $values['secondaryTeamIds'] ?? null; + } + + /** + * @return ?array + */ + public function getPrimaryTeamIds(): ?array + { + return $this->primaryTeamIds; + } + + /** + * @param ?array $value + */ + public function setPrimaryTeamIds(?array $value = null): self + { + $this->primaryTeamIds = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSecondaryTeamIds(): ?array + { + return $this->secondaryTeamIds; + } + + /** + * @param ?array $value + */ + public function setSecondaryTeamIds(?array $value = null): self + { + $this->secondaryTeamIds = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketList.php b/src/Unstable/Types/TicketList.php new file mode 100644 index 00000000..250a1f1c --- /dev/null +++ b/src/Unstable/Types/TicketList.php @@ -0,0 +1,132 @@ + $tickets The list of ticket objects + */ + #[JsonProperty('tickets'), ArrayType([new Union(Ticket::class, 'null')])] + private ?array $tickets; + + /** + * @var ?int $totalCount A count of the total number of objects. + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @var ?CursorPages $pages + */ + #[JsonProperty('pages')] + private ?CursorPages $pages; + + /** + * @param array{ + * type?: ?'ticket.list', + * tickets?: ?array, + * totalCount?: ?int, + * pages?: ?CursorPages, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->tickets = $values['tickets'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + $this->pages = $values['pages'] ?? null; + } + + /** + * @return ?'ticket.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'ticket.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTickets(): ?array + { + return $this->tickets; + } + + /** + * @param ?array $value + */ + public function setTickets(?array $value = null): self + { + $this->tickets = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return ?CursorPages + */ + public function getPages(): ?CursorPages + { + return $this->pages; + } + + /** + * @param ?CursorPages $value + */ + public function setPages(?CursorPages $value = null): self + { + $this->pages = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketPartAuthor.php b/src/Unstable/Types/TicketPartAuthor.php new file mode 100644 index 00000000..d555ed50 --- /dev/null +++ b/src/Unstable/Types/TicketPartAuthor.php @@ -0,0 +1,129 @@ + $type The type of the author + */ + #[JsonProperty('type')] + private ?string $type; + + /** + * @var ?string $id The id of the author + */ + #[JsonProperty('id')] + private ?string $id; + + /** + * @var ?string $name The name of the author + */ + #[JsonProperty('name')] + private ?string $name; + + /** + * @var ?string $email The email of the author + */ + #[JsonProperty('email')] + private ?string $email; + + /** + * @param array{ + * type?: ?value-of, + * id?: ?string, + * name?: ?string, + * email?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + $this->email = $values['email'] ?? null; + } + + /** + * @return ?value-of + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?value-of $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketPartAuthorType.php b/src/Unstable/Types/TicketPartAuthorType.php new file mode 100644 index 00000000..6538e892 --- /dev/null +++ b/src/Unstable/Types/TicketPartAuthorType.php @@ -0,0 +1,11 @@ + $ticketParts A list of Ticket Part objects for each ticket. There is a limit of 500 parts. + */ + #[JsonProperty('ticket_parts'), ArrayType([TicketPart::class])] + private ?array $ticketParts; + + /** + * @var ?int $totalCount + */ + #[JsonProperty('total_count')] + private ?int $totalCount; + + /** + * @param array{ + * type?: ?'ticket_part.list', + * ticketParts?: ?array, + * totalCount?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->ticketParts = $values['ticketParts'] ?? null; + $this->totalCount = $values['totalCount'] ?? null; + } + + /** + * @return ?'ticket_part.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'ticket_part.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTicketParts(): ?array + { + return $this->ticketParts; + } + + /** + * @param ?array $value + */ + public function setTicketParts(?array $value = null): self + { + $this->ticketParts = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTotalCount(): ?int + { + return $this->totalCount; + } + + /** + * @param ?int $value + */ + public function setTotalCount(?int $value = null): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketReply.php b/src/Unstable/Types/TicketReply.php new file mode 100644 index 00000000..9b485cb3 --- /dev/null +++ b/src/Unstable/Types/TicketReply.php @@ -0,0 +1,255 @@ + $partType Type of the part + */ + #[JsonProperty('part_type')] + private ?string $partType; + + /** + * @var ?string $body The message body, which may contain HTML. + */ + #[JsonProperty('body')] + private ?string $body; + + /** + * @var ?int $createdAt The time the note was created. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The last time the note was updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @var ?TicketPartAuthor $author + */ + #[JsonProperty('author')] + private ?TicketPartAuthor $author; + + /** + * @var ?array $attachments A list of attachments for the part. + */ + #[JsonProperty('attachments'), ArrayType([PartAttachment::class])] + private ?array $attachments; + + /** + * @var ?bool $redacted Whether or not the ticket part has been redacted. + */ + #[JsonProperty('redacted')] + private ?bool $redacted; + + /** + * @param array{ + * type?: ?'ticket_part', + * id?: ?string, + * partType?: ?value-of, + * body?: ?string, + * createdAt?: ?int, + * updatedAt?: ?int, + * author?: ?TicketPartAuthor, + * attachments?: ?array, + * redacted?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->partType = $values['partType'] ?? null; + $this->body = $values['body'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->author = $values['author'] ?? null; + $this->attachments = $values['attachments'] ?? null; + $this->redacted = $values['redacted'] ?? null; + } + + /** + * @return ?'ticket_part' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'ticket_part' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getPartType(): ?string + { + return $this->partType; + } + + /** + * @param ?value-of $value + */ + public function setPartType(?string $value = null): self + { + $this->partType = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?TicketPartAuthor + */ + public function getAuthor(): ?TicketPartAuthor + { + return $this->author; + } + + /** + * @param ?TicketPartAuthor $value + */ + public function setAuthor(?TicketPartAuthor $value = null): self + { + $this->author = $value; + return $this; + } + + /** + * @return ?array + */ + public function getAttachments(): ?array + { + return $this->attachments; + } + + /** + * @param ?array $value + */ + public function setAttachments(?array $value = null): self + { + $this->attachments = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRedacted(): ?bool + { + return $this->redacted; + } + + /** + * @param ?bool $value + */ + public function setRedacted(?bool $value = null): self + { + $this->redacted = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketReplyPartType.php b/src/Unstable/Types/TicketReplyPartType.php new file mode 100644 index 00000000..c7330f31 --- /dev/null +++ b/src/Unstable/Types/TicketReplyPartType.php @@ -0,0 +1,10 @@ + $data A list of ticket states associated with a given ticket type. + */ + #[JsonProperty('data'), ArrayType([new Union(TicketStateDetailed::class, 'null')])] + private ?array $data; + + /** + * @param array{ + * type?: ?string, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketTypeAttribute.php b/src/Unstable/Types/TicketTypeAttribute.php new file mode 100644 index 00000000..cb64800f --- /dev/null +++ b/src/Unstable/Types/TicketTypeAttribute.php @@ -0,0 +1,455 @@ + $inputOptions Input options for the attribute + */ + #[JsonProperty('input_options'), ArrayType(['string' => 'mixed'])] + private ?array $inputOptions; + + /** + * @var ?int $order The order of the attribute against other attributes + */ + #[JsonProperty('order')] + private ?int $order; + + /** + * @var ?bool $requiredToCreate Whether the attribute is required or not for teammates. + */ + #[JsonProperty('required_to_create')] + private ?bool $requiredToCreate; + + /** + * @var ?bool $requiredToCreateForContacts Whether the attribute is required or not for contacts. + */ + #[JsonProperty('required_to_create_for_contacts')] + private ?bool $requiredToCreateForContacts; + + /** + * @var ?bool $visibleOnCreate Whether the attribute is visible or not to teammates. + */ + #[JsonProperty('visible_on_create')] + private ?bool $visibleOnCreate; + + /** + * @var ?bool $visibleToContacts Whether the attribute is visible or not to contacts. + */ + #[JsonProperty('visible_to_contacts')] + private ?bool $visibleToContacts; + + /** + * @var ?bool $default Whether the attribute is built in or not. + */ + #[JsonProperty('default')] + private ?bool $default; + + /** + * @var ?int $ticketTypeId The id of the ticket type that the attribute belongs to. + */ + #[JsonProperty('ticket_type_id')] + private ?int $ticketTypeId; + + /** + * @var ?bool $archived Whether the ticket type attribute is archived or not. + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?int $createdAt The date and time the ticket type attribute was created. + */ + #[JsonProperty('created_at')] + private ?int $createdAt; + + /** + * @var ?int $updatedAt The date and time the ticket type attribute was last updated. + */ + #[JsonProperty('updated_at')] + private ?int $updatedAt; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * workspaceId?: ?string, + * name?: ?string, + * description?: ?string, + * dataType?: ?string, + * inputOptions?: ?array, + * order?: ?int, + * requiredToCreate?: ?bool, + * requiredToCreateForContacts?: ?bool, + * visibleOnCreate?: ?bool, + * visibleToContacts?: ?bool, + * default?: ?bool, + * ticketTypeId?: ?int, + * archived?: ?bool, + * createdAt?: ?int, + * updatedAt?: ?int, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->workspaceId = $values['workspaceId'] ?? null; + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->dataType = $values['dataType'] ?? null; + $this->inputOptions = $values['inputOptions'] ?? null; + $this->order = $values['order'] ?? null; + $this->requiredToCreate = $values['requiredToCreate'] ?? null; + $this->requiredToCreateForContacts = $values['requiredToCreateForContacts'] ?? null; + $this->visibleOnCreate = $values['visibleOnCreate'] ?? null; + $this->visibleToContacts = $values['visibleToContacts'] ?? null; + $this->default = $values['default'] ?? null; + $this->ticketTypeId = $values['ticketTypeId'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getWorkspaceId(): ?string + { + return $this->workspaceId; + } + + /** + * @param ?string $value + */ + public function setWorkspaceId(?string $value = null): self + { + $this->workspaceId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDataType(): ?string + { + return $this->dataType; + } + + /** + * @param ?string $value + */ + public function setDataType(?string $value = null): self + { + $this->dataType = $value; + return $this; + } + + /** + * @return ?array + */ + public function getInputOptions(): ?array + { + return $this->inputOptions; + } + + /** + * @param ?array $value + */ + public function setInputOptions(?array $value = null): self + { + $this->inputOptions = $value; + return $this; + } + + /** + * @return ?int + */ + public function getOrder(): ?int + { + return $this->order; + } + + /** + * @param ?int $value + */ + public function setOrder(?int $value = null): self + { + $this->order = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreate(): ?bool + { + return $this->requiredToCreate; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreate(?bool $value = null): self + { + $this->requiredToCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getRequiredToCreateForContacts(): ?bool + { + return $this->requiredToCreateForContacts; + } + + /** + * @param ?bool $value + */ + public function setRequiredToCreateForContacts(?bool $value = null): self + { + $this->requiredToCreateForContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleOnCreate(): ?bool + { + return $this->visibleOnCreate; + } + + /** + * @param ?bool $value + */ + public function setVisibleOnCreate(?bool $value = null): self + { + $this->visibleOnCreate = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getVisibleToContacts(): ?bool + { + return $this->visibleToContacts; + } + + /** + * @param ?bool $value + */ + public function setVisibleToContacts(?bool $value = null): self + { + $this->visibleToContacts = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDefault(): ?bool + { + return $this->default; + } + + /** + * @param ?bool $value + */ + public function setDefault(?bool $value = null): self + { + $this->default = $value; + return $this; + } + + /** + * @return ?int + */ + public function getTicketTypeId(): ?int + { + return $this->ticketTypeId; + } + + /** + * @param ?int $value + */ + public function setTicketTypeId(?int $value = null): self + { + $this->ticketTypeId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketTypeAttributeList.php b/src/Unstable/Types/TicketTypeAttributeList.php new file mode 100644 index 00000000..4f4df327 --- /dev/null +++ b/src/Unstable/Types/TicketTypeAttributeList.php @@ -0,0 +1,81 @@ + $ticketTypeAttributes A list of ticket type attributes associated with a given ticket type. + */ + #[JsonProperty('ticket_type_attributes'), ArrayType([new Union(TicketTypeAttribute::class, 'null')])] + private ?array $ticketTypeAttributes; + + /** + * @param array{ + * type?: ?string, + * ticketTypeAttributes?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->ticketTypeAttributes = $values['ticketTypeAttributes'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTicketTypeAttributes(): ?array + { + return $this->ticketTypeAttributes; + } + + /** + * @param ?array $value + */ + public function setTicketTypeAttributes(?array $value = null): self + { + $this->ticketTypeAttributes = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/TicketTypeList.php b/src/Unstable/Types/TicketTypeList.php new file mode 100644 index 00000000..5870660c --- /dev/null +++ b/src/Unstable/Types/TicketTypeList.php @@ -0,0 +1,82 @@ + $data A list of ticket_types associated with a given workspace. + */ + #[JsonProperty('data'), ArrayType([new Union(TicketType::class, 'null')])] + private ?array $data; + + /** + * @param array{ + * type?: ?string, + * data?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->data = $values['data'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getData(): ?array + { + return $this->data; + } + + /** + * @param ?array $value + */ + public function setData(?array $value = null): self + { + $this->data = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/Translation.php b/src/Unstable/Types/Translation.php new file mode 100644 index 00000000..ac5d892b --- /dev/null +++ b/src/Unstable/Types/Translation.php @@ -0,0 +1,104 @@ +name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->locale = $values['locale'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getLocale(): ?string + { + return $this->locale; + } + + /** + * @param ?string $value + */ + public function setLocale(?string $value = null): self + { + $this->locale = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/UntagCompanyRequest.php b/src/Unstable/Types/UntagCompanyRequest.php new file mode 100644 index 00000000..8f087713 --- /dev/null +++ b/src/Unstable/Types/UntagCompanyRequest.php @@ -0,0 +1,80 @@ + $companies The id or company_id of the company can be passed as input parameters. + */ + #[JsonProperty('companies'), ArrayType([UntagCompanyRequestCompaniesItem::class])] + private array $companies; + + /** + * @param array{ + * name: string, + * companies: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->companies = $values['companies']; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $value + */ + public function setName(string $value): self + { + $this->name = $value; + return $this; + } + + /** + * @return array + */ + public function getCompanies(): array + { + return $this->companies; + } + + /** + * @param array $value + */ + public function setCompanies(array $value): self + { + $this->companies = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/UntagCompanyRequestCompaniesItem.php b/src/Unstable/Types/UntagCompanyRequestCompaniesItem.php new file mode 100644 index 00000000..a24ceca4 --- /dev/null +++ b/src/Unstable/Types/UntagCompanyRequestCompaniesItem.php @@ -0,0 +1,101 @@ +id = $values['id'] ?? null; + $this->companyId = $values['companyId'] ?? null; + $this->untag = $values['untag'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCompanyId(): ?string + { + return $this->companyId; + } + + /** + * @param ?string $value + */ + public function setCompanyId(?string $value = null): self + { + $this->companyId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUntag(): ?bool + { + return $this->untag; + } + + /** + * @param ?bool $value + */ + public function setUntag(?bool $value = null): self + { + $this->untag = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/UpdateArticleRequestBody.php b/src/Unstable/Types/UpdateArticleRequestBody.php new file mode 100644 index 00000000..26163678 --- /dev/null +++ b/src/Unstable/Types/UpdateArticleRequestBody.php @@ -0,0 +1,229 @@ + $state Whether the article will be `published` or will be a `draft`. Defaults to draft. For multilingual articles, this will be the state of the default language's content. + */ + #[JsonProperty('state')] + private ?string $state; + + /** + * @var ?string $parentId The id of the article's parent collection or section. An article without this field stands alone. + */ + #[JsonProperty('parent_id')] + private ?string $parentId; + + /** + * @var ?string $parentType The type of parent, which can either be a `collection` or `section`. + */ + #[JsonProperty('parent_type')] + private ?string $parentType; + + /** + * @var ?ArticleTranslatedContent $translatedContent + */ + #[JsonProperty('translated_content')] + private ?ArticleTranslatedContent $translatedContent; + + /** + * @param array{ + * title?: ?string, + * description?: ?string, + * body?: ?string, + * authorId?: ?int, + * state?: ?value-of, + * parentId?: ?string, + * parentType?: ?string, + * translatedContent?: ?ArticleTranslatedContent, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->title = $values['title'] ?? null; + $this->description = $values['description'] ?? null; + $this->body = $values['body'] ?? null; + $this->authorId = $values['authorId'] ?? null; + $this->state = $values['state'] ?? null; + $this->parentId = $values['parentId'] ?? null; + $this->parentType = $values['parentType'] ?? null; + $this->translatedContent = $values['translatedContent'] ?? null; + } + + /** + * @return ?string + */ + public function getTitle(): ?string + { + return $this->title; + } + + /** + * @param ?string $value + */ + public function setTitle(?string $value = null): self + { + $this->title = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?string + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param ?string $value + */ + public function setBody(?string $value = null): self + { + $this->body = $value; + return $this; + } + + /** + * @return ?int + */ + public function getAuthorId(): ?int + { + return $this->authorId; + } + + /** + * @param ?int $value + */ + public function setAuthorId(?int $value = null): self + { + $this->authorId = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getState(): ?string + { + return $this->state; + } + + /** + * @param ?value-of $value + */ + public function setState(?string $value = null): self + { + $this->state = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentId(): ?string + { + return $this->parentId; + } + + /** + * @param ?string $value + */ + public function setParentId(?string $value = null): self + { + $this->parentId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getParentType(): ?string + { + return $this->parentType; + } + + /** + * @param ?string $value + */ + public function setParentType(?string $value = null): self + { + $this->parentType = $value; + return $this; + } + + /** + * @return ?ArticleTranslatedContent + */ + public function getTranslatedContent(): ?ArticleTranslatedContent + { + return $this->translatedContent; + } + + /** + * @param ?ArticleTranslatedContent $value + */ + public function setTranslatedContent(?ArticleTranslatedContent $value = null): self + { + $this->translatedContent = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/UpdateArticleRequestState.php b/src/Unstable/Types/UpdateArticleRequestState.php new file mode 100644 index 00000000..dde3e8d8 --- /dev/null +++ b/src/Unstable/Types/UpdateArticleRequestState.php @@ -0,0 +1,9 @@ + $category Category of the Ticket Type. + */ + #[JsonProperty('category')] + private ?string $category; + + /** + * @var ?string $icon The icon of the ticket type. + */ + #[JsonProperty('icon')] + private ?string $icon; + + /** + * @var ?bool $archived The archived status of the ticket type. + */ + #[JsonProperty('archived')] + private ?bool $archived; + + /** + * @var ?bool $isInternal Whether the tickets associated with this ticket type are intended for internal use only or will be shared with customers. This is currently a limited attribute. + */ + #[JsonProperty('is_internal')] + private ?bool $isInternal; + + /** + * @param array{ + * name?: ?string, + * description?: ?string, + * category?: ?value-of, + * icon?: ?string, + * archived?: ?bool, + * isInternal?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->name = $values['name'] ?? null; + $this->description = $values['description'] ?? null; + $this->category = $values['category'] ?? null; + $this->icon = $values['icon'] ?? null; + $this->archived = $values['archived'] ?? null; + $this->isInternal = $values['isInternal'] ?? null; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getDescription(): ?string + { + return $this->description; + } + + /** + * @param ?string $value + */ + public function setDescription(?string $value = null): self + { + $this->description = $value; + return $this; + } + + /** + * @return ?value-of + */ + public function getCategory(): ?string + { + return $this->category; + } + + /** + * @param ?value-of $value + */ + public function setCategory(?string $value = null): self + { + $this->category = $value; + return $this; + } + + /** + * @return ?string + */ + public function getIcon(): ?string + { + return $this->icon; + } + + /** + * @param ?string $value + */ + public function setIcon(?string $value = null): self + { + $this->icon = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getArchived(): ?bool + { + return $this->archived; + } + + /** + * @param ?bool $value + */ + public function setArchived(?bool $value = null): self + { + $this->archived = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getIsInternal(): ?bool + { + return $this->isInternal; + } + + /** + * @param ?bool $value + */ + public function setIsInternal(?bool $value = null): self + { + $this->isInternal = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/UpdateTicketTypeRequestCategory.php b/src/Unstable/Types/UpdateTicketTypeRequestCategory.php new file mode 100644 index 00000000..afab4ff0 --- /dev/null +++ b/src/Unstable/Types/UpdateTicketTypeRequestCategory.php @@ -0,0 +1,10 @@ + $customAttributes The custom attributes you have set on the Visitor. + */ + #[JsonProperty('custom_attributes'), ArrayType(['string' => 'string'])] + private ?array $customAttributes; + + /** + * @var ?string $referrer The referer of the visitor. + */ + #[JsonProperty('referrer')] + private ?string $referrer; + + /** + * @var ?string $utmCampaign The utm_campaign of the visitor. + */ + #[JsonProperty('utm_campaign')] + private ?string $utmCampaign; + + /** + * @var ?string $utmContent The utm_content of the visitor. + */ + #[JsonProperty('utm_content')] + private ?string $utmContent; + + /** + * @var ?string $utmMedium The utm_medium of the visitor. + */ + #[JsonProperty('utm_medium')] + private ?string $utmMedium; + + /** + * @var ?string $utmSource The utm_source of the visitor. + */ + #[JsonProperty('utm_source')] + private ?string $utmSource; + + /** + * @var ?string $utmTerm The utm_term of the visitor. + */ + #[JsonProperty('utm_term')] + private ?string $utmTerm; + + /** + * @var ?bool $doNotTrack Identifies if this visitor has do not track enabled. + */ + #[JsonProperty('do_not_track')] + private ?bool $doNotTrack; + + /** + * @param array{ + * type?: ?string, + * id?: ?string, + * userId?: ?string, + * anonymous?: ?bool, + * email?: ?string, + * phone?: ?string, + * name?: ?string, + * pseudonym?: ?string, + * avatar?: ?VisitorAvatar, + * appId?: ?string, + * companies?: ?VisitorCompanies, + * locationData?: ?VisitorLocationData, + * lasRequestAt?: ?int, + * createdAt?: ?int, + * remoteCreatedAt?: ?int, + * signedUpAt?: ?int, + * updatedAt?: ?int, + * sessionCount?: ?int, + * socialProfiles?: ?VisitorSocialProfiles, + * ownerId?: ?string, + * unsubscribedFromEmails?: ?bool, + * markedEmailAsSpam?: ?bool, + * hasHardBounced?: ?bool, + * tags?: ?VisitorTags, + * segments?: ?VisitorSegments, + * customAttributes?: ?array, + * referrer?: ?string, + * utmCampaign?: ?string, + * utmContent?: ?string, + * utmMedium?: ?string, + * utmSource?: ?string, + * utmTerm?: ?string, + * doNotTrack?: ?bool, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->userId = $values['userId'] ?? null; + $this->anonymous = $values['anonymous'] ?? null; + $this->email = $values['email'] ?? null; + $this->phone = $values['phone'] ?? null; + $this->name = $values['name'] ?? null; + $this->pseudonym = $values['pseudonym'] ?? null; + $this->avatar = $values['avatar'] ?? null; + $this->appId = $values['appId'] ?? null; + $this->companies = $values['companies'] ?? null; + $this->locationData = $values['locationData'] ?? null; + $this->lasRequestAt = $values['lasRequestAt'] ?? null; + $this->createdAt = $values['createdAt'] ?? null; + $this->remoteCreatedAt = $values['remoteCreatedAt'] ?? null; + $this->signedUpAt = $values['signedUpAt'] ?? null; + $this->updatedAt = $values['updatedAt'] ?? null; + $this->sessionCount = $values['sessionCount'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + $this->ownerId = $values['ownerId'] ?? null; + $this->unsubscribedFromEmails = $values['unsubscribedFromEmails'] ?? null; + $this->markedEmailAsSpam = $values['markedEmailAsSpam'] ?? null; + $this->hasHardBounced = $values['hasHardBounced'] ?? null; + $this->tags = $values['tags'] ?? null; + $this->segments = $values['segments'] ?? null; + $this->customAttributes = $values['customAttributes'] ?? null; + $this->referrer = $values['referrer'] ?? null; + $this->utmCampaign = $values['utmCampaign'] ?? null; + $this->utmContent = $values['utmContent'] ?? null; + $this->utmMedium = $values['utmMedium'] ?? null; + $this->utmSource = $values['utmSource'] ?? null; + $this->utmTerm = $values['utmTerm'] ?? null; + $this->doNotTrack = $values['doNotTrack'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getAnonymous(): ?bool + { + return $this->anonymous; + } + + /** + * @param ?bool $value + */ + public function setAnonymous(?bool $value = null): self + { + $this->anonymous = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPhone(): ?string + { + return $this->phone; + } + + /** + * @param ?string $value + */ + public function setPhone(?string $value = null): self + { + $this->phone = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPseudonym(): ?string + { + return $this->pseudonym; + } + + /** + * @param ?string $value + */ + public function setPseudonym(?string $value = null): self + { + $this->pseudonym = $value; + return $this; + } + + /** + * @return ?VisitorAvatar + */ + public function getAvatar(): ?VisitorAvatar + { + return $this->avatar; + } + + /** + * @param ?VisitorAvatar $value + */ + public function setAvatar(?VisitorAvatar $value = null): self + { + $this->avatar = $value; + return $this; + } + + /** + * @return ?string + */ + public function getAppId(): ?string + { + return $this->appId; + } + + /** + * @param ?string $value + */ + public function setAppId(?string $value = null): self + { + $this->appId = $value; + return $this; + } + + /** + * @return ?VisitorCompanies + */ + public function getCompanies(): ?VisitorCompanies + { + return $this->companies; + } + + /** + * @param ?VisitorCompanies $value + */ + public function setCompanies(?VisitorCompanies $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return ?VisitorLocationData + */ + public function getLocationData(): ?VisitorLocationData + { + return $this->locationData; + } + + /** + * @param ?VisitorLocationData $value + */ + public function setLocationData(?VisitorLocationData $value = null): self + { + $this->locationData = $value; + return $this; + } + + /** + * @return ?int + */ + public function getLasRequestAt(): ?int + { + return $this->lasRequestAt; + } + + /** + * @param ?int $value + */ + public function setLasRequestAt(?int $value = null): self + { + $this->lasRequestAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getCreatedAt(): ?int + { + return $this->createdAt; + } + + /** + * @param ?int $value + */ + public function setCreatedAt(?int $value = null): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getRemoteCreatedAt(): ?int + { + return $this->remoteCreatedAt; + } + + /** + * @param ?int $value + */ + public function setRemoteCreatedAt(?int $value = null): self + { + $this->remoteCreatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSignedUpAt(): ?int + { + return $this->signedUpAt; + } + + /** + * @param ?int $value + */ + public function setSignedUpAt(?int $value = null): self + { + $this->signedUpAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getUpdatedAt(): ?int + { + return $this->updatedAt; + } + + /** + * @param ?int $value + */ + public function setUpdatedAt(?int $value = null): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return ?int + */ + public function getSessionCount(): ?int + { + return $this->sessionCount; + } + + /** + * @param ?int $value + */ + public function setSessionCount(?int $value = null): self + { + $this->sessionCount = $value; + return $this; + } + + /** + * @return ?VisitorSocialProfiles + */ + public function getSocialProfiles(): ?VisitorSocialProfiles + { + return $this->socialProfiles; + } + + /** + * @param ?VisitorSocialProfiles $value + */ + public function setSocialProfiles(?VisitorSocialProfiles $value = null): self + { + $this->socialProfiles = $value; + return $this; + } + + /** + * @return ?string + */ + public function getOwnerId(): ?string + { + return $this->ownerId; + } + + /** + * @param ?string $value + */ + public function setOwnerId(?string $value = null): self + { + $this->ownerId = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getUnsubscribedFromEmails(): ?bool + { + return $this->unsubscribedFromEmails; + } + + /** + * @param ?bool $value + */ + public function setUnsubscribedFromEmails(?bool $value = null): self + { + $this->unsubscribedFromEmails = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getMarkedEmailAsSpam(): ?bool + { + return $this->markedEmailAsSpam; + } + + /** + * @param ?bool $value + */ + public function setMarkedEmailAsSpam(?bool $value = null): self + { + $this->markedEmailAsSpam = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getHasHardBounced(): ?bool + { + return $this->hasHardBounced; + } + + /** + * @param ?bool $value + */ + public function setHasHardBounced(?bool $value = null): self + { + $this->hasHardBounced = $value; + return $this; + } + + /** + * @return ?VisitorTags + */ + public function getTags(): ?VisitorTags + { + return $this->tags; + } + + /** + * @param ?VisitorTags $value + */ + public function setTags(?VisitorTags $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return ?VisitorSegments + */ + public function getSegments(): ?VisitorSegments + { + return $this->segments; + } + + /** + * @param ?VisitorSegments $value + */ + public function setSegments(?VisitorSegments $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCustomAttributes(): ?array + { + return $this->customAttributes; + } + + /** + * @param ?array $value + */ + public function setCustomAttributes(?array $value = null): self + { + $this->customAttributes = $value; + return $this; + } + + /** + * @return ?string + */ + public function getReferrer(): ?string + { + return $this->referrer; + } + + /** + * @param ?string $value + */ + public function setReferrer(?string $value = null): self + { + $this->referrer = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmCampaign(): ?string + { + return $this->utmCampaign; + } + + /** + * @param ?string $value + */ + public function setUtmCampaign(?string $value = null): self + { + $this->utmCampaign = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmContent(): ?string + { + return $this->utmContent; + } + + /** + * @param ?string $value + */ + public function setUtmContent(?string $value = null): self + { + $this->utmContent = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmMedium(): ?string + { + return $this->utmMedium; + } + + /** + * @param ?string $value + */ + public function setUtmMedium(?string $value = null): self + { + $this->utmMedium = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmSource(): ?string + { + return $this->utmSource; + } + + /** + * @param ?string $value + */ + public function setUtmSource(?string $value = null): self + { + $this->utmSource = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUtmTerm(): ?string + { + return $this->utmTerm; + } + + /** + * @param ?string $value + */ + public function setUtmTerm(?string $value = null): self + { + $this->utmTerm = $value; + return $this; + } + + /** + * @return ?bool + */ + public function getDoNotTrack(): ?bool + { + return $this->doNotTrack; + } + + /** + * @param ?bool $value + */ + public function setDoNotTrack(?bool $value = null): self + { + $this->doNotTrack = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorAvatar.php b/src/Unstable/Types/VisitorAvatar.php new file mode 100644 index 00000000..f1d4cdc3 --- /dev/null +++ b/src/Unstable/Types/VisitorAvatar.php @@ -0,0 +1,76 @@ +type = $values['type'] ?? null; + $this->imageUrl = $values['imageUrl'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getImageUrl(): ?string + { + return $this->imageUrl; + } + + /** + * @param ?string $value + */ + public function setImageUrl(?string $value = null): self + { + $this->imageUrl = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorCompanies.php b/src/Unstable/Types/VisitorCompanies.php new file mode 100644 index 00000000..870866d3 --- /dev/null +++ b/src/Unstable/Types/VisitorCompanies.php @@ -0,0 +1,78 @@ + $companies + */ + #[JsonProperty('companies'), ArrayType([Company::class])] + private ?array $companies; + + /** + * @param array{ + * type?: ?'company.list', + * companies?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->companies = $values['companies'] ?? null; + } + + /** + * @return ?'company.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'company.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getCompanies(): ?array + { + return $this->companies; + } + + /** + * @param ?array $value + */ + public function setCompanies(?array $value = null): self + { + $this->companies = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorDeletedObject.php b/src/Unstable/Types/VisitorDeletedObject.php new file mode 100644 index 00000000..f49bebbc --- /dev/null +++ b/src/Unstable/Types/VisitorDeletedObject.php @@ -0,0 +1,104 @@ +id = $values['id'] ?? null; + $this->type = $values['type'] ?? null; + $this->userId = $values['userId'] ?? null; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?'visitor' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'visitor' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getUserId(): ?string + { + return $this->userId; + } + + /** + * @param ?string $value + */ + public function setUserId(?string $value = null): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorLocationData.php b/src/Unstable/Types/VisitorLocationData.php new file mode 100644 index 00000000..845943f8 --- /dev/null +++ b/src/Unstable/Types/VisitorLocationData.php @@ -0,0 +1,226 @@ +type = $values['type'] ?? null; + $this->cityName = $values['cityName'] ?? null; + $this->continentCode = $values['continentCode'] ?? null; + $this->countryCode = $values['countryCode'] ?? null; + $this->countryName = $values['countryName'] ?? null; + $this->postalCode = $values['postalCode'] ?? null; + $this->regionName = $values['regionName'] ?? null; + $this->timezone = $values['timezone'] ?? null; + } + + /** + * @return ?string + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?string $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCityName(): ?string + { + return $this->cityName; + } + + /** + * @param ?string $value + */ + public function setCityName(?string $value = null): self + { + $this->cityName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getContinentCode(): ?string + { + return $this->continentCode; + } + + /** + * @param ?string $value + */ + public function setContinentCode(?string $value = null): self + { + $this->continentCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCountryCode(): ?string + { + return $this->countryCode; + } + + /** + * @param ?string $value + */ + public function setCountryCode(?string $value = null): self + { + $this->countryCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getCountryName(): ?string + { + return $this->countryName; + } + + /** + * @param ?string $value + */ + public function setCountryName(?string $value = null): self + { + $this->countryName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getPostalCode(): ?string + { + return $this->postalCode; + } + + /** + * @param ?string $value + */ + public function setPostalCode(?string $value = null): self + { + $this->postalCode = $value; + return $this; + } + + /** + * @return ?string + */ + public function getRegionName(): ?string + { + return $this->regionName; + } + + /** + * @param ?string $value + */ + public function setRegionName(?string $value = null): self + { + $this->regionName = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTimezone(): ?string + { + return $this->timezone; + } + + /** + * @param ?string $value + */ + public function setTimezone(?string $value = null): self + { + $this->timezone = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorSegments.php b/src/Unstable/Types/VisitorSegments.php new file mode 100644 index 00000000..9041847d --- /dev/null +++ b/src/Unstable/Types/VisitorSegments.php @@ -0,0 +1,77 @@ + $segments + */ + #[JsonProperty('segments'), ArrayType(['string'])] + private ?array $segments; + + /** + * @param array{ + * type?: ?'segment.list', + * segments?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->segments = $values['segments'] ?? null; + } + + /** + * @return ?'segment.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'segment.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSegments(): ?array + { + return $this->segments; + } + + /** + * @param ?array $value + */ + public function setSegments(?array $value = null): self + { + $this->segments = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorSocialProfiles.php b/src/Unstable/Types/VisitorSocialProfiles.php new file mode 100644 index 00000000..cf957f6b --- /dev/null +++ b/src/Unstable/Types/VisitorSocialProfiles.php @@ -0,0 +1,77 @@ + $socialProfiles + */ + #[JsonProperty('social_profiles'), ArrayType(['string'])] + private ?array $socialProfiles; + + /** + * @param array{ + * type?: ?'social_profile.list', + * socialProfiles?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->socialProfiles = $values['socialProfiles'] ?? null; + } + + /** + * @return ?'social_profile.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'social_profile.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getSocialProfiles(): ?array + { + return $this->socialProfiles; + } + + /** + * @param ?array $value + */ + public function setSocialProfiles(?array $value = null): self + { + $this->socialProfiles = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorTags.php b/src/Unstable/Types/VisitorTags.php new file mode 100644 index 00000000..6dae5924 --- /dev/null +++ b/src/Unstable/Types/VisitorTags.php @@ -0,0 +1,77 @@ + $tags + */ + #[JsonProperty('tags'), ArrayType([VisitorTagsTagsItem::class])] + private ?array $tags; + + /** + * @param array{ + * type?: ?'tag.list', + * tags?: ?array, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->type = $values['type'] ?? null; + $this->tags = $values['tags'] ?? null; + } + + /** + * @return ?'tag.list' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag.list' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?array + */ + public function getTags(): ?array + { + return $this->tags; + } + + /** + * @param ?array $value + */ + public function setTags(?array $value = null): self + { + $this->tags = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/VisitorTagsTagsItem.php b/src/Unstable/Types/VisitorTagsTagsItem.php new file mode 100644 index 00000000..cdff8661 --- /dev/null +++ b/src/Unstable/Types/VisitorTagsTagsItem.php @@ -0,0 +1,101 @@ +type = $values['type'] ?? null; + $this->id = $values['id'] ?? null; + $this->name = $values['name'] ?? null; + } + + /** + * @return ?'tag' + */ + public function getType(): ?string + { + return $this->type; + } + + /** + * @param ?'tag' $value + */ + public function setType(?string $value = null): self + { + $this->type = $value; + return $this; + } + + /** + * @return ?string + */ + public function getId(): ?string + { + return $this->id; + } + + /** + * @param ?string $value + */ + public function setId(?string $value = null): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * @param ?string $value + */ + public function setName(?string $value = null): self + { + $this->name = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/WhatsappMessageStatusList.php b/src/Unstable/Types/WhatsappMessageStatusList.php new file mode 100644 index 00000000..2f4dcbda --- /dev/null +++ b/src/Unstable/Types/WhatsappMessageStatusList.php @@ -0,0 +1,152 @@ + $events + */ + #[JsonProperty('events'), ArrayType([WhatsappMessageStatusListEventsItem::class])] + private array $events; + + /** + * @param array{ + * type: 'list', + * rulesetId: string, + * pages: WhatsappMessageStatusListPages, + * totalCount: int, + * events: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->type = $values['type']; + $this->rulesetId = $values['rulesetId']; + $this->pages = $values['pages']; + $this->totalCount = $values['totalCount']; + $this->events = $values['events']; + } + + /** + * @return 'list' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'list' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return string + */ + public function getRulesetId(): string + { + return $this->rulesetId; + } + + /** + * @param string $value + */ + public function setRulesetId(string $value): self + { + $this->rulesetId = $value; + return $this; + } + + /** + * @return WhatsappMessageStatusListPages + */ + public function getPages(): WhatsappMessageStatusListPages + { + return $this->pages; + } + + /** + * @param WhatsappMessageStatusListPages $value + */ + public function setPages(WhatsappMessageStatusListPages $value): self + { + $this->pages = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalCount(): int + { + return $this->totalCount; + } + + /** + * @param int $value + */ + public function setTotalCount(int $value): self + { + $this->totalCount = $value; + return $this; + } + + /** + * @return array + */ + public function getEvents(): array + { + return $this->events; + } + + /** + * @param array $value + */ + public function setEvents(array $value): self + { + $this->events = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/WhatsappMessageStatusListEventsItem.php b/src/Unstable/Types/WhatsappMessageStatusListEventsItem.php new file mode 100644 index 00000000..045a9ae4 --- /dev/null +++ b/src/Unstable/Types/WhatsappMessageStatusListEventsItem.php @@ -0,0 +1,226 @@ + $status Current status of the message + */ + #[JsonProperty('status')] + private string $status; + + /** + * @var 'broadcast_outbound' $type Event type + */ + #[JsonProperty('type')] + private string $type; + + /** + * @var int $createdAt Creation timestamp + */ + #[JsonProperty('created_at')] + private int $createdAt; + + /** + * @var int $updatedAt Last update timestamp + */ + #[JsonProperty('updated_at')] + private int $updatedAt; + + /** + * @var string $whatsappMessageId WhatsApp's message identifier + */ + #[JsonProperty('whatsapp_message_id')] + private string $whatsappMessageId; + + /** + * @var ?string $templateName Name of the WhatsApp template used + */ + #[JsonProperty('template_name')] + private ?string $templateName; + + /** + * @param array{ + * id: string, + * conversationId: string, + * status: value-of, + * type: 'broadcast_outbound', + * createdAt: int, + * updatedAt: int, + * whatsappMessageId: string, + * templateName?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->id = $values['id']; + $this->conversationId = $values['conversationId']; + $this->status = $values['status']; + $this->type = $values['type']; + $this->createdAt = $values['createdAt']; + $this->updatedAt = $values['updatedAt']; + $this->whatsappMessageId = $values['whatsappMessageId']; + $this->templateName = $values['templateName'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function getConversationId(): string + { + return $this->conversationId; + } + + /** + * @param string $value + */ + public function setConversationId(string $value): self + { + $this->conversationId = $value; + return $this; + } + + /** + * @return value-of + */ + public function getStatus(): string + { + return $this->status; + } + + /** + * @param value-of $value + */ + public function setStatus(string $value): self + { + $this->status = $value; + return $this; + } + + /** + * @return 'broadcast_outbound' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'broadcast_outbound' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->createdAt; + } + + /** + * @param int $value + */ + public function setCreatedAt(int $value): self + { + $this->createdAt = $value; + return $this; + } + + /** + * @return int + */ + public function getUpdatedAt(): int + { + return $this->updatedAt; + } + + /** + * @param int $value + */ + public function setUpdatedAt(int $value): self + { + $this->updatedAt = $value; + return $this; + } + + /** + * @return string + */ + public function getWhatsappMessageId(): string + { + return $this->whatsappMessageId; + } + + /** + * @param string $value + */ + public function setWhatsappMessageId(string $value): self + { + $this->whatsappMessageId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getTemplateName(): ?string + { + return $this->templateName; + } + + /** + * @param ?string $value + */ + public function setTemplateName(?string $value = null): self + { + $this->templateName = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/WhatsappMessageStatusListEventsItemStatus.php b/src/Unstable/Types/WhatsappMessageStatusListEventsItemStatus.php new file mode 100644 index 00000000..d5c094df --- /dev/null +++ b/src/Unstable/Types/WhatsappMessageStatusListEventsItemStatus.php @@ -0,0 +1,11 @@ +type = $values['type']; + $this->perPage = $values['perPage']; + $this->totalPages = $values['totalPages']; + $this->next = $values['next'] ?? null; + } + + /** + * @return 'pages' + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param 'pages' $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return int + */ + public function getPerPage(): int + { + return $this->perPage; + } + + /** + * @param int $value + */ + public function setPerPage(int $value): self + { + $this->perPage = $value; + return $this; + } + + /** + * @return int + */ + public function getTotalPages(): int + { + return $this->totalPages; + } + + /** + * @param int $value + */ + public function setTotalPages(int $value): self + { + $this->totalPages = $value; + return $this; + } + + /** + * @return ?WhatsappMessageStatusListPagesNext + */ + public function getNext(): ?WhatsappMessageStatusListPagesNext + { + return $this->next; + } + + /** + * @param ?WhatsappMessageStatusListPagesNext $value + */ + public function setNext(?WhatsappMessageStatusListPagesNext $value = null): self + { + $this->next = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/Types/WhatsappMessageStatusListPagesNext.php b/src/Unstable/Types/WhatsappMessageStatusListPagesNext.php new file mode 100644 index 00000000..89dd449a --- /dev/null +++ b/src/Unstable/Types/WhatsappMessageStatusListPagesNext.php @@ -0,0 +1,54 @@ +startingAfter = $values['startingAfter'] ?? null; + } + + /** + * @return ?string + */ + public function getStartingAfter(): ?string + { + return $this->startingAfter; + } + + /** + * @param ?string $value + */ + public function setStartingAfter(?string $value = null): self + { + $this->startingAfter = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Unstable/UnstableClient.php b/src/Unstable/UnstableClient.php new file mode 100644 index 00000000..7923ea8a --- /dev/null +++ b/src/Unstable/UnstableClient.php @@ -0,0 +1,246 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + $this->admins = new AdminsClient($this->client, $this->options); + $this->aiContent = new AiContentClient($this->client, $this->options); + $this->articles = new ArticlesClient($this->client, $this->options); + $this->awayStatusReasons = new AwayStatusReasonsClient($this->client, $this->options); + $this->export = new ExportClient($this->client, $this->options); + $this->helpCenter = new HelpCenterClient($this->client, $this->options); + $this->companies = new CompaniesClient($this->client, $this->options); + $this->contacts = new ContactsClient($this->client, $this->options); + $this->notes = new NotesClient($this->client, $this->options); + $this->subscriptionTypes = new SubscriptionTypesClient($this->client, $this->options); + $this->tags = new TagsClient($this->client, $this->options); + $this->conversations = new ConversationsClient($this->client, $this->options); + $this->customChannelEvents = new CustomChannelEventsClient($this->client, $this->options); + $this->customObjectInstances = new CustomObjectInstancesClient($this->client, $this->options); + $this->dataAttributes = new DataAttributesClient($this->client, $this->options); + $this->dataEvents = new DataEventsClient($this->client, $this->options); + $this->dataExport = new DataExportClient($this->client, $this->options); + $this->jobs = new JobsClient($this->client, $this->options); + $this->macros = new MacrosClient($this->client, $this->options); + $this->messages = new MessagesClient($this->client, $this->options); + $this->news = new NewsClient($this->client, $this->options); + $this->segments = new SegmentsClient($this->client, $this->options); + $this->switch_ = new SwitchClient($this->client, $this->options); + $this->teams = new TeamsClient($this->client, $this->options); + $this->ticketStates = new TicketStatesClient($this->client, $this->options); + $this->ticketTypeAttributes = new TicketTypeAttributesClient($this->client, $this->options); + $this->ticketTypes = new TicketTypesClient($this->client, $this->options); + $this->tickets = new TicketsClient($this->client, $this->options); + $this->visitors = new VisitorsClient($this->client, $this->options); + } +} diff --git a/src/Unstable/Visitors/Requests/ConvertVisitorRequest.php b/src/Unstable/Visitors/Requests/ConvertVisitorRequest.php new file mode 100644 index 00000000..c866dea7 --- /dev/null +++ b/src/Unstable/Visitors/Requests/ConvertVisitorRequest.php @@ -0,0 +1,93 @@ +type = $values['type']; + $this->user = $values['user']; + $this->visitor = $values['visitor']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return mixed + */ + public function getUser(): mixed + { + return $this->user; + } + + /** + * @param mixed $value + */ + public function setUser(mixed $value): self + { + $this->user = $value; + return $this; + } + + /** + * @return mixed + */ + public function getVisitor(): mixed + { + return $this->visitor; + } + + /** + * @param mixed $value + */ + public function setVisitor(mixed $value): self + { + $this->visitor = $value; + return $this; + } +} diff --git a/src/Unstable/Visitors/Requests/RetrieveVisitorWithUserIdRequest.php b/src/Unstable/Visitors/Requests/RetrieveVisitorWithUserIdRequest.php new file mode 100644 index 00000000..3fb07738 --- /dev/null +++ b/src/Unstable/Visitors/Requests/RetrieveVisitorWithUserIdRequest.php @@ -0,0 +1,41 @@ +userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } +} diff --git a/src/Unstable/Visitors/VisitorsClient.php b/src/Unstable/Visitors/VisitorsClient.php new file mode 100644 index 00000000..a152e168 --- /dev/null +++ b/src/Unstable/Visitors/VisitorsClient.php @@ -0,0 +1,239 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch the details of a single visitor. + * + * @param RetrieveVisitorWithUserIdRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Visitor + * @throws IntercomException + * @throws IntercomApiException + */ + public function retrieveVisitorWithUserId(RetrieveVisitorWithUserIdRequest $request, ?array $options = null): ?Visitor + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['user_id'] = $request->getUserId(); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "visitors", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Visitor::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Sending a PUT request to `/visitors` will result in an update of an existing Visitor. + * + * **Option 1.** You can update a visitor by passing in the `user_id` of the visitor in the Request body. + * + * **Option 2.** You can update a visitor by passing in the `id` of the visitor in the Request body. + * + * @param mixed $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return ?Visitor + * @throws IntercomException + * @throws IntercomApiException + */ + public function updateVisitor(mixed $request, ?array $options = null): ?Visitor + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "visitors", + method: HttpMethod::PUT, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + if (empty($json)) { + return null; + } + return Visitor::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can merge a Visitor to a Contact of role type `lead` or `user`. + * + * > 📘 What happens upon a visitor being converted? + * > + * > If the User exists, then the Visitor will be merged into it, the Visitor deleted and the User returned. If the User does not exist, the Visitor will be converted to a User, with the User identifiers replacing it's Visitor identifiers. + * + * @param ConvertVisitorRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Contact + * @throws IntercomException + * @throws IntercomApiException + */ + public function convertVisitor(ConvertVisitorRequest $request, ?array $options = null): Contact + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "visitors/convert", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Contact::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/src/Utils/File.php b/src/Utils/File.php new file mode 100644 index 00000000..2cf8934d --- /dev/null +++ b/src/Utils/File.php @@ -0,0 +1,125 @@ +filename = $filename; + $this->contentType = $contentType; + $this->stream = $stream; + } + + /** + * Creates a File instance from a filepath. + * + * @param string $filepath + * @param ?string $filename + * @param ?string $contentType + * @return File + * @throws Exception + */ + public static function createFromFilepath( + string $filepath, + ?string $filename = null, + ?string $contentType = null, + ): File { + $resource = fopen($filepath, 'r'); + if (!$resource) { + throw new Exception("Unable to open file $filepath"); + } + $stream = Utils::streamFor($resource); + if (!$stream->isReadable()) { + throw new Exception("File $filepath is not readable"); + } + return new self( + stream: $stream, + filename: $filename ?? basename($filepath), + contentType: $contentType, + ); + } + + /** + * Creates a File instance from a string. + * + * @param string $content + * @param ?string $filename + * @param ?string $contentType + * @return File + */ + public static function createFromString( + string $content, + ?string $filename, + ?string $contentType = null, + ): File { + return new self( + stream: Utils::streamFor($content), + filename: $filename, + contentType: $contentType, + ); + } + + /** + * Maps this File into a multipart form data part. + * + * @param string $name The name of the multipart form data part. + * @param ?string $contentType Overrides the Content-Type associated with the file, if any. + * @return MultipartFormDataPart + */ + public function toMultipartFormDataPart(string $name, ?string $contentType = null): MultipartFormDataPart + { + $contentType ??= $this->contentType; + $headers = $contentType != null + ? ['Content-Type' => $contentType] + : null; + + return new MultipartFormDataPart( + name: $name, + value: $this->stream, + filename: $this->filename, + headers: $headers, + ); + } + + /** + * Closes the file stream. + */ + public function close(): void + { + $this->stream->close(); + } + + /** + * Destructor to ensure stream is closed. + */ + public function __destruct() + { + $this->close(); + } +} diff --git a/src/Visitors/Requests/FindVisitorRequest.php b/src/Visitors/Requests/FindVisitorRequest.php new file mode 100644 index 00000000..7f24c15a --- /dev/null +++ b/src/Visitors/Requests/FindVisitorRequest.php @@ -0,0 +1,41 @@ +userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } +} diff --git a/src/Visitors/Requests/MergeVisitorToContactRequest.php b/src/Visitors/Requests/MergeVisitorToContactRequest.php new file mode 100644 index 00000000..14745cfe --- /dev/null +++ b/src/Visitors/Requests/MergeVisitorToContactRequest.php @@ -0,0 +1,127 @@ +type = $values['type']; + $this->user = $values['user']; + $this->visitor = $values['visitor']; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $value + */ + public function setType(string $value): self + { + $this->type = $value; + return $this; + } + + /** + * @return ( + * UserWithId + * |UserWithUserId + * ) + */ + public function getUser(): UserWithId|UserWithUserId + { + return $this->user; + } + + /** + * @param ( + * UserWithId + * |UserWithUserId + * ) $value + */ + public function setUser(UserWithId|UserWithUserId $value): self + { + $this->user = $value; + return $this; + } + + /** + * @return ( + * VisitorWithId + * |VisitorWithUserId + * |VisitorWithEmail + * ) + */ + public function getVisitor(): VisitorWithId|VisitorWithUserId|VisitorWithEmail + { + return $this->visitor; + } + + /** + * @param ( + * VisitorWithId + * |VisitorWithUserId + * |VisitorWithEmail + * ) $value + */ + public function setVisitor(VisitorWithId|VisitorWithUserId|VisitorWithEmail $value): self + { + $this->visitor = $value; + return $this; + } +} diff --git a/src/Visitors/Types/UserWithId.php b/src/Visitors/Types/UserWithId.php new file mode 100644 index 00000000..af681c5f --- /dev/null +++ b/src/Visitors/Types/UserWithId.php @@ -0,0 +1,76 @@ +id = $values['id']; + $this->email = $values['email'] ?? null; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Visitors/Types/UserWithUserId.php b/src/Visitors/Types/UserWithUserId.php new file mode 100644 index 00000000..f50a584b --- /dev/null +++ b/src/Visitors/Types/UserWithUserId.php @@ -0,0 +1,76 @@ +userId = $values['userId']; + $this->email = $values['email'] ?? null; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return ?string + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param ?string $value + */ + public function setEmail(?string $value = null): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Visitors/Types/VisitorWithEmail.php b/src/Visitors/Types/VisitorWithEmail.php new file mode 100644 index 00000000..6965286e --- /dev/null +++ b/src/Visitors/Types/VisitorWithEmail.php @@ -0,0 +1,51 @@ +email = $values['email']; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $value + */ + public function setEmail(string $value): self + { + $this->email = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Visitors/Types/VisitorWithId.php b/src/Visitors/Types/VisitorWithId.php new file mode 100644 index 00000000..72aca340 --- /dev/null +++ b/src/Visitors/Types/VisitorWithId.php @@ -0,0 +1,51 @@ +id = $values['id']; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $value + */ + public function setId(string $value): self + { + $this->id = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Visitors/Types/VisitorWithUserId.php b/src/Visitors/Types/VisitorWithUserId.php new file mode 100644 index 00000000..484af008 --- /dev/null +++ b/src/Visitors/Types/VisitorWithUserId.php @@ -0,0 +1,51 @@ +userId = $values['userId']; + } + + /** + * @return string + */ + public function getUserId(): string + { + return $this->userId; + } + + /** + * @param string $value + */ + public function setUserId(string $value): self + { + $this->userId = $value; + return $this; + } + + /** + * @return string + */ + public function __toString(): string + { + return $this->toJson(); + } +} diff --git a/src/Visitors/VisitorsClient.php b/src/Visitors/VisitorsClient.php new file mode 100644 index 00000000..8ec76f0e --- /dev/null +++ b/src/Visitors/VisitorsClient.php @@ -0,0 +1,240 @@ +, + * } $options + */ + private array $options; + + /** + * @var RawClient $client + */ + private RawClient $client; + + /** + * @param RawClient $client + * @param ?array{ + * baseUrl?: string, + * client?: ClientInterface, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * } $options + */ + public function __construct( + RawClient $client, + ?array $options = null, + ) { + $this->client = $client; + $this->options = $options ?? []; + } + + /** + * You can fetch the details of a single visitor. + * + * @param FindVisitorRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Visitor + * @throws IntercomException + * @throws IntercomApiException + */ + public function find(FindVisitorRequest $request, ?array $options = null): Visitor + { + $options = array_merge($this->options, $options ?? []); + $query = []; + $query['user_id'] = $request->getUserId(); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "visitors", + method: HttpMethod::GET, + query: $query, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Visitor::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * Sending a PUT request to `/visitors` will result in an update of an existing Visitor. + * + * **Option 1.** You can update a visitor by passing in the `user_id` of the visitor in the Request body. + * + * **Option 2.** You can update a visitor by passing in the `id` of the visitor in the Request body. + * + * @param ( + * UpdateVisitorRequestWithId + * |UpdateVisitorRequestWithUserId + * ) $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Visitor + * @throws IntercomException + * @throws IntercomApiException + */ + public function update(UpdateVisitorRequestWithId|UpdateVisitorRequestWithUserId $request, ?array $options = null): Visitor + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "visitors", + method: HttpMethod::PUT, + body: JsonSerializer::serializeUnion($request, new Union(UpdateVisitorRequestWithId::class, UpdateVisitorRequestWithUserId::class)), + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Visitor::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } + + /** + * You can merge a Visitor to a Contact of role type `lead` or `user`. + * + * > 📘 What happens upon a visitor being converted? + * > + * > If the User exists, then the Visitor will be merged into it, the Visitor deleted and the User returned. If the User does not exist, the Visitor will be converted to a User, with the User identifiers replacing it's Visitor identifiers. + * + * @param MergeVisitorToContactRequest $request + * @param ?array{ + * baseUrl?: string, + * maxRetries?: int, + * timeout?: float, + * headers?: array, + * queryParameters?: array, + * bodyProperties?: array, + * } $options + * @return Contact + * @throws IntercomException + * @throws IntercomApiException + */ + public function mergeToContact(MergeVisitorToContactRequest $request, ?array $options = null): Contact + { + $options = array_merge($this->options, $options ?? []); + try { + $response = $this->client->sendRequest( + new JsonApiRequest( + baseUrl: $options['baseUrl'] ?? $this->client->options['baseUrl'] ?? Environments::UsProduction->value, + path: "visitors/convert", + method: HttpMethod::POST, + body: $request, + ), + $options, + ); + $statusCode = $response->getStatusCode(); + if ($statusCode >= 200 && $statusCode < 400) { + $json = $response->getBody()->getContents(); + return Contact::fromJson($json); + } + } catch (JsonException $e) { + throw new IntercomException(message: "Failed to deserialize response: {$e->getMessage()}", previous: $e); + } catch (RequestException $e) { + $response = $e->getResponse(); + if ($response === null) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: "API request failed", + statusCode: $response->getStatusCode(), + body: $response->getBody()->getContents(), + ); + } catch (ClientExceptionInterface $e) { + throw new IntercomException(message: $e->getMessage(), previous: $e); + } + throw new IntercomApiException( + message: 'API request failed', + statusCode: $statusCode, + body: $response->getBody()->getContents(), + ); + } +} diff --git a/tests/Core/Client/RawClientTest.php b/tests/Core/Client/RawClientTest.php new file mode 100644 index 00000000..7c677d28 --- /dev/null +++ b/tests/Core/Client/RawClientTest.php @@ -0,0 +1,444 @@ +name = $values['name']; + } + + /** + * @return string + */ + public function getName(): ?string + { + return $this->name; + } +} + +class RawClientTest extends TestCase +{ + private string $baseUrl = 'https://api.example.com'; + private MockHandler $mockHandler; + private RawClient $rawClient; + + protected function setUp(): void + { + $this->mockHandler = new MockHandler(); + $handlerStack = HandlerStack::create($this->mockHandler); + // since the client is constructed manually, we need to add the retry middleware manually + $handlerStack->push(RetryMiddleware::create([ + 'maxRetries' => 0, + 'baseDelay' => 0, + ])); + $client = new Client(['handler' => $handlerStack]); + $this->rawClient = new RawClient(['client' => $client]); + } + + /** + * @throws ClientExceptionInterface + */ + public function testHeaders(): void + { + $this->mockHandler->append(new Response(200)); + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET, + ['X-Custom-Header' => 'TestValue'] + ); + + $this->rawClient->sendRequest($request); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals('TestValue', $lastRequest->getHeaderLine('X-Custom-Header')); + } + + /** + * @throws ClientExceptionInterface + */ + public function testQueryParameters(): void + { + $this->mockHandler->append(new Response(200)); + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET, + [], + ['param1' => 'value1', 'param2' => ['a', 'b'], 'param3' => 'true'] + ); + + $this->rawClient->sendRequest($request); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals( + 'https://api.example.com/test?param1=value1¶m2=a¶m2=b¶m3=true', + (string)$lastRequest->getUri() + ); + } + + /** + * @throws ClientExceptionInterface + */ + public function testJsonBody(): void + { + $this->mockHandler->append(new Response(200)); + + $body = ['key' => 'value']; + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + [], + [], + $body + ); + + $this->rawClient->sendRequest($request); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals(json_encode($body), (string)$lastRequest->getBody()); + } + + public function testAdditionalHeaders(): void + { + $this->mockHandler->append(new Response(200)); + + $body = new JsonRequest([ + 'name' => 'john.doe' + ]); + $headers = [ + 'X-API-Version' => '1.0.0', + ]; + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + $headers, + [], + $body + ); + + $this->rawClient->sendRequest( + $request, + options: [ + 'headers' => [ + 'X-Tenancy' => 'test' + ] + ] + ); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals('1.0.0', $lastRequest->getHeaderLine('X-API-Version')); + $this->assertEquals('test', $lastRequest->getHeaderLine('X-Tenancy')); + } + + public function testOverrideAdditionalHeaders(): void + { + $this->mockHandler->append(new Response(200)); + + $body = new JsonRequest([ + 'name' => 'john.doe' + ]); + $headers = [ + 'X-API-Version' => '1.0.0', + ]; + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + $headers, + [], + $body + ); + + $this->rawClient->sendRequest( + $request, + options: [ + 'headers' => [ + 'X-API-Version' => '2.0.0' + ] + ] + ); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals('2.0.0', $lastRequest->getHeaderLine('X-API-Version')); + } + + public function testAdditionalBodyProperties(): void + { + $this->mockHandler->append(new Response(200)); + + $body = new JsonRequest([ + 'name' => 'john.doe' + ]); + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + [], + [], + $body + ); + + $this->rawClient->sendRequest( + $request, + options: [ + 'bodyProperties' => [ + 'age' => 42 + ] + ] + ); + + $expectedJson = [ + 'name' => 'john.doe', + 'age' => 42 + ]; + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals(json_encode($expectedJson), (string)$lastRequest->getBody()); + } + + public function testOverrideAdditionalBodyProperties(): void + { + $this->mockHandler->append(new Response(200)); + + $body = [ + 'name' => 'john.doe' + ]; + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + [], + [], + $body + ); + + $this->rawClient->sendRequest( + $request, + options: [ + 'bodyProperties' => [ + 'name' => 'jane.doe' + ] + ] + ); + + $expectedJson = [ + 'name' => 'jane.doe', + ]; + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals(json_encode($expectedJson), (string)$lastRequest->getBody()); + } + + public function testAdditionalQueryParameters(): void + { + $this->mockHandler->append(new Response(200)); + + $query = ['key' => 'value']; + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + [], + $query, + [] + ); + + $this->rawClient->sendRequest( + $request, + options: [ + 'queryParameters' => [ + 'extra' => 42 + ] + ] + ); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals('key=value&extra=42', $lastRequest->getUri()->getQuery()); + } + + public function testOverrideQueryParameters(): void + { + $this->mockHandler->append(new Response(200)); + + $query = ['key' => 'invalid']; + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::POST, + [], + $query, + [] + ); + + $this->rawClient->sendRequest( + $request, + options: [ + 'queryParameters' => [ + 'key' => 'value' + ] + ] + ); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals('application/json', $lastRequest->getHeaderLine('Content-Type')); + $this->assertEquals('key=value', $lastRequest->getUri()->getQuery()); + } + + public function testDefaultRetries(): void + { + $this->mockHandler->append(new Response(500)); + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET + ); + + try { + $this->rawClient->sendRequest($request); + $this->fail("Request should've failed but succeeded."); + } catch (ClientExceptionInterface) { + } + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals(0, $this->mockHandler->count()); + } + + /** + * @throws ClientExceptionInterface + */ + public function testExplicitRetriesSuccess(): void + { + $this->mockHandler->append(new Response(500), new Response(500), new Response(200)); + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET + ); + + $this->rawClient->sendRequest($request, ['maxRetries' => 2]); + + $lastRequest = $this->mockHandler->getLastRequest(); + assert($lastRequest instanceof RequestInterface); + $this->assertEquals(0, $this->mockHandler->count()); + } + + public function testExplicitRetriesFailure(): void + { + $this->mockHandler->append(new Response(500), new Response(500), new Response(500)); + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET + ); + + try { + $this->rawClient->sendRequest($request, ['maxRetries' => 2]); + $this->fail("Request should've failed but succeeded."); + } catch (ClientExceptionInterface) { + } + + $this->assertEquals(0, $this->mockHandler->count()); + } + + /** + * @throws ClientExceptionInterface + */ + public function testShouldRetryOnStatusCodes(): void + { + $this->mockHandler->append( + new Response(408), + new Response(429), + new Response(500), + new Response(501), + new Response(502), + new Response(503), + new Response(504), + new Response(505), + new Response(599), + new Response(200), + ); + $countOfErrorRequests = $this->mockHandler->count() - 1; + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET + ); + + $this->rawClient->sendRequest($request, ['maxRetries' => $countOfErrorRequests]); + + $this->assertEquals(0, $this->mockHandler->count()); + } + + public function testShouldFailOn400Response(): void + { + $this->mockHandler->append(new Response(400), new Response(200)); + + $request = new JsonApiRequest( + $this->baseUrl, + '/test', + HttpMethod::GET + ); + + try { + $this->rawClient->sendRequest($request, ['maxRetries' => 2]); + $this->fail("Request should've failed but succeeded."); + } catch (ClientExceptionInterface) { + } + + $this->assertEquals(1, $this->mockHandler->count()); + } +} diff --git a/tests/Core/Json/AdditionalPropertiesTest.php b/tests/Core/Json/AdditionalPropertiesTest.php new file mode 100644 index 00000000..8e33e98c --- /dev/null +++ b/tests/Core/Json/AdditionalPropertiesTest.php @@ -0,0 +1,76 @@ +name; + } + + /** + * @return string|null + */ + public function getEmail(): ?string + { + return $this->email; + } + + /** + * @param array{ + * name: string, + * email?: string|null, + * } $values + */ + public function __construct( + array $values, + ) { + $this->name = $values['name']; + $this->email = $values['email'] ?? null; + } +} + +class AdditionalPropertiesTest extends TestCase +{ + public function testExtraProperties(): void + { + $expectedJson = json_encode( + [ + 'name' => 'john.doe', + 'email' => 'john.doe@example.com', + 'age' => 42 + ], + JSON_THROW_ON_ERROR + ); + + $person = Person::fromJson($expectedJson); + $this->assertEquals('john.doe', $person->getName()); + $this->assertEquals('john.doe@example.com', $person->getEmail()); + $this->assertEquals( + [ + 'age' => 42 + ], + $person->getAdditionalProperties(), + ); + } +} diff --git a/tests/Core/Json/DateArrayTest.php b/tests/Core/Json/DateArrayTest.php new file mode 100644 index 00000000..50613d29 --- /dev/null +++ b/tests/Core/Json/DateArrayTest.php @@ -0,0 +1,54 @@ +dates = $values['dates']; + } +} + +class DateArrayTest extends TestCase +{ + public function testDateTimeInArrays(): void + { + $expectedJson = json_encode( + [ + 'dates' => ['2023-01-01', '2023-02-01', '2023-03-01'] + ], + JSON_THROW_ON_ERROR + ); + + $object = DateArray::fromJson($expectedJson); + $this->assertInstanceOf(DateTime::class, $object->dates[0], 'dates[0] should be a DateTime instance.'); + $this->assertEquals('2023-01-01', $object->dates[0]->format('Y-m-d'), 'dates[0] should have the correct date.'); + $this->assertInstanceOf(DateTime::class, $object->dates[1], 'dates[1] should be a DateTime instance.'); + $this->assertEquals('2023-02-01', $object->dates[1]->format('Y-m-d'), 'dates[1] should have the correct date.'); + $this->assertInstanceOf(DateTime::class, $object->dates[2], 'dates[2] should be a DateTime instance.'); + $this->assertEquals('2023-03-01', $object->dates[2]->format('Y-m-d'), 'dates[2] should have the correct date.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for dates array.'); + } +} diff --git a/tests/Core/Json/EmptyArrayTest.php b/tests/Core/Json/EmptyArrayTest.php new file mode 100644 index 00000000..e4680fd9 --- /dev/null +++ b/tests/Core/Json/EmptyArrayTest.php @@ -0,0 +1,71 @@ + $emptyMapArray + */ + #[JsonProperty('empty_map_array')] + #[ArrayType(['integer' => new Union('string', 'null')])] + public array $emptyMapArray; + + /** + * @var array $emptyDatesArray + */ + #[ArrayType([new Union('date', 'null')])] + #[JsonProperty('empty_dates_array')] + public array $emptyDatesArray; + + /** + * @param array{ + * emptyStringArray: string[], + * emptyMapArray: array, + * emptyDatesArray: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->emptyStringArray = $values['emptyStringArray']; + $this->emptyMapArray = $values['emptyMapArray']; + $this->emptyDatesArray = $values['emptyDatesArray']; + } +} + +class EmptyArrayTest extends TestCase +{ + public function testEmptyArray(): void + { + $expectedJson = json_encode( + [ + 'empty_string_array' => [], + 'empty_map_array' => [], + 'empty_dates_array' => [] + ], + JSON_THROW_ON_ERROR + ); + + $object = EmptyArray::fromJson($expectedJson); + $this->assertEmpty($object->emptyStringArray, 'empty_string_array should be empty.'); + $this->assertEmpty($object->emptyMapArray, 'empty_map_array should be empty.'); + $this->assertEmpty($object->emptyDatesArray, 'empty_dates_array should be empty.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for EmptyArraysType.'); + } +} diff --git a/tests/Core/Json/EnumTest.php b/tests/Core/Json/EnumTest.php new file mode 100644 index 00000000..d38e59a1 --- /dev/null +++ b/tests/Core/Json/EnumTest.php @@ -0,0 +1,76 @@ +value; + } +} + +class ShapeType extends JsonSerializableType +{ + /** + * @var Shape $shape + */ + #[JsonProperty('shape')] + public Shape $shape; + + /** + * @var Shape[] $shapes + */ + #[ArrayType([Shape::class])] + #[JsonProperty('shapes')] + public array $shapes; + + /** + * @param Shape $shape + * @param Shape[] $shapes + */ + public function __construct( + Shape $shape, + array $shapes, + ) { + $this->shape = $shape; + $this->shapes = $shapes; + } +} + +class EnumTest extends TestCase +{ + public function testEnumSerialization(): void + { + $object = new ShapeType( + Shape::Circle, + [Shape::Square, Shape::Circle, Shape::Triangle] + ); + + $expectedJson = json_encode([ + 'shape' => 'CIRCLE', + 'shapes' => ['SQUARE', 'CIRCLE', 'TRIANGLE'] + ], JSON_THROW_ON_ERROR); + + $actualJson = $object->toJson(); + + $this->assertJsonStringEqualsJsonString( + $expectedJson, + $actualJson, + 'Serialized JSON does not match expected JSON for shape and shapes properties.' + ); + } +} diff --git a/tests/Core/Json/ExhaustiveTest.php b/tests/Core/Json/ExhaustiveTest.php new file mode 100644 index 00000000..19c84250 --- /dev/null +++ b/tests/Core/Json/ExhaustiveTest.php @@ -0,0 +1,197 @@ +nestedProperty = $values['nestedProperty']; + } +} + +class Type extends JsonSerializableType +{ + /** + * @var Nested nestedType + */ + #[JsonProperty('nested_type')] + public Nested $nestedType; /** + + * @var string $simpleProperty + */ + #[JsonProperty('simple_property')] + public string $simpleProperty; + + /** + * @var DateTime $dateProperty + */ + #[Date(Date::TYPE_DATE)] + #[JsonProperty('date_property')] + public DateTime $dateProperty; + + /** + * @var DateTime $datetimeProperty + */ + #[Date(Date::TYPE_DATETIME)] + #[JsonProperty('datetime_property')] + public DateTime $datetimeProperty; + + /** + * @var array $stringArray + */ + #[ArrayType(['string'])] + #[JsonProperty('string_array')] + public array $stringArray; + + /** + * @var array $mapProperty + */ + #[ArrayType(['string' => 'integer'])] + #[JsonProperty('map_property')] + public array $mapProperty; + + /** + * @var array $objectArray + */ + #[ArrayType(['integer' => new Union(Nested::class, 'null')])] + #[JsonProperty('object_array')] + public array $objectArray; + + /** + * @var array> $nestedArray + */ + #[ArrayType(['integer' => ['integer' => new Union('string', 'null')]])] + #[JsonProperty('nested_array')] + public array $nestedArray; + + /** + * @var array $datesArray + */ + #[ArrayType([new Union('date', 'null')])] + #[JsonProperty('dates_array')] + public array $datesArray; + + /** + * @var string|null $nullableProperty + */ + #[JsonProperty('nullable_property')] + public ?string $nullableProperty; + + /** + * @param array{ + * nestedType: Nested, + * simpleProperty: string, + * dateProperty: DateTime, + * datetimeProperty: DateTime, + * stringArray: array, + * mapProperty: array, + * objectArray: array, + * nestedArray: array>, + * datesArray: array, + * nullableProperty?: string|null, + * } $values + */ + public function __construct( + array $values, + ) { + $this->nestedType = $values['nestedType']; + $this->simpleProperty = $values['simpleProperty']; + $this->dateProperty = $values['dateProperty']; + $this->datetimeProperty = $values['datetimeProperty']; + $this->stringArray = $values['stringArray']; + $this->mapProperty = $values['mapProperty']; + $this->objectArray = $values['objectArray']; + $this->nestedArray = $values['nestedArray']; + $this->datesArray = $values['datesArray']; + $this->nullableProperty = $values['nullableProperty'] ?? null; + } +} + +class ExhaustiveTest extends TestCase +{ + /** + * Test serialization and deserialization of all types in Type. + */ + public function testExhaustive(): void + { + $expectedJson = json_encode( + [ + 'nested_type' => ['nested_property' => '1995-07-20'], + 'simple_property' => 'Test String', + // Omit 'nullable_property' to test null serialization + 'date_property' => '2023-01-01', + 'datetime_property' => '2023-01-01T12:34:56+00:00', + 'string_array' => ['one', 'two', 'three'], + 'map_property' => ['key1' => 1, 'key2' => 2], + 'object_array' => [ + 1 => ['nested_property' => '2021-07-20'], + 2 => null, // Testing nullable objects in array + ], + 'nested_array' => [ + 1 => [1 => 'value1', 2 => null], // Testing nullable strings in nested array + 2 => [3 => 'value3', 4 => 'value4'] + ], + 'dates_array' => ['2023-01-01', null, '2023-03-01'] // Testing nullable dates in array> + ], + JSON_THROW_ON_ERROR + ); + + $object = Type::fromJson($expectedJson); + + // Check that nullable property is null and not included in JSON + $this->assertNull($object->nullableProperty, 'Nullable property should be null.'); + + // Check date properties + $this->assertInstanceOf(DateTime::class, $object->dateProperty, 'date_property should be a DateTime instance.'); + $this->assertEquals('2023-01-01', $object->dateProperty->format('Y-m-d'), 'date_property should have the correct date.'); + $this->assertInstanceOf(DateTime::class, $object->datetimeProperty, 'datetime_property should be a DateTime instance.'); + $this->assertEquals('2023-01-01 12:34:56', $object->datetimeProperty->format('Y-m-d H:i:s'), 'datetime_property should have the correct datetime.'); + + // Check scalar arrays + $this->assertEquals(['one', 'two', 'three'], $object->stringArray, 'string_array should match the original data.'); + $this->assertEquals(['key1' => 1, 'key2' => 2], $object->mapProperty, 'map_property should match the original data.'); + + // Check object array with nullable elements + $this->assertInstanceOf(Nested::class, $object->objectArray[1], 'object_array[1] should be an instance of TestNestedType1.'); + $this->assertEquals('2021-07-20', $object->objectArray[1]->nestedProperty->format('Y-m-d'), 'object_array[1]->nestedProperty should match the original data.'); + $this->assertNull($object->objectArray[2], 'object_array[2] should be null.'); + + // Check nested array with nullable strings + $this->assertEquals('value1', $object->nestedArray[1][1], 'nested_array[1][1] should match the original data.'); + $this->assertNull($object->nestedArray[1][2], 'nested_array[1][2] should be null.'); + $this->assertEquals('value3', $object->nestedArray[2][3], 'nested_array[2][3] should match the original data.'); + $this->assertEquals('value4', $object->nestedArray[2][4], 'nested_array[2][4] should match the original data.'); + + // Check dates array with nullable DateTime objects + $this->assertInstanceOf(DateTime::class, $object->datesArray[0], 'dates_array[0] should be a DateTime instance.'); + $this->assertEquals('2023-01-01', $object->datesArray[0]->format('Y-m-d'), 'dates_array[0] should have the correct date.'); + $this->assertNull($object->datesArray[1], 'dates_array[1] should be null.'); + $this->assertInstanceOf(DateTime::class, $object->datesArray[2], 'dates_array[2] should be a DateTime instance.'); + $this->assertEquals('2023-03-01', $object->datesArray[2]->format('Y-m-d'), 'dates_array[2] should have the correct date.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'The serialized JSON does not match the original JSON.'); + } +} diff --git a/tests/Core/Json/InvalidTest.php b/tests/Core/Json/InvalidTest.php new file mode 100644 index 00000000..7630e3f7 --- /dev/null +++ b/tests/Core/Json/InvalidTest.php @@ -0,0 +1,42 @@ +integerProperty = $values['integerProperty']; + } +} + +class InvalidTest extends TestCase +{ + public function testInvalidJsonThrowsException(): void + { + $this->expectException(\TypeError::class); + $json = json_encode( + [ + 'integer_property' => 'not_an_integer' + ], + JSON_THROW_ON_ERROR + ); + Invalid::fromJson($json); + } +} diff --git a/tests/Core/Json/NestedUnionArrayTest.php b/tests/Core/Json/NestedUnionArrayTest.php new file mode 100644 index 00000000..f6570f6a --- /dev/null +++ b/tests/Core/Json/NestedUnionArrayTest.php @@ -0,0 +1,89 @@ +nestedProperty = $values['nestedProperty']; + } +} + +class NestedUnionArray extends JsonSerializableType +{ + /** + * @var array> $nestedArray + */ + #[ArrayType(['integer' => ['integer' => new Union(UnionObject::class, 'null', 'date')]])] + #[JsonProperty('nested_array')] + public array $nestedArray; + + /** + * @param array{ + * nestedArray: array>, + * } $values + */ + public function __construct( + array $values, + ) { + $this->nestedArray = $values['nestedArray']; + } +} + +class NestedUnionArrayTest extends TestCase +{ + public function testNestedUnionArray(): void + { + $expectedJson = json_encode( + [ + 'nested_array' => [ + 1 => [ + 1 => ['nested_property' => 'Nested One'], + 2 => null, + 4 => '2023-01-02' + ], + 2 => [ + 5 => ['nested_property' => 'Nested Two'], + 7 => '2023-02-02' + ] + ] + ], + JSON_THROW_ON_ERROR + ); + + $object = NestedUnionArray::fromJson($expectedJson); + $this->assertInstanceOf(UnionObject::class, $object->nestedArray[1][1], 'nested_array[1][1] should be an instance of Object.'); + $this->assertEquals('Nested One', $object->nestedArray[1][1]->nestedProperty, 'nested_array[1][1]->nestedProperty should match the original data.'); + $this->assertNull($object->nestedArray[1][2], 'nested_array[1][2] should be null.'); + $this->assertInstanceOf(DateTime::class, $object->nestedArray[1][4], 'nested_array[1][4] should be a DateTime instance.'); + $this->assertEquals('2023-01-02T00:00:00+00:00', $object->nestedArray[1][4]->format(Constant::DateTimeFormat), 'nested_array[1][4] should have the correct datetime.'); + $this->assertInstanceOf(UnionObject::class, $object->nestedArray[2][5], 'nested_array[2][5] should be an instance of Object.'); + $this->assertEquals('Nested Two', $object->nestedArray[2][5]->nestedProperty, 'nested_array[2][5]->nestedProperty should match the original data.'); + $this->assertInstanceOf(DateTime::class, $object->nestedArray[2][7], 'nested_array[1][4] should be a DateTime instance.'); + $this->assertEquals('2023-02-02', $object->nestedArray[2][7]->format('Y-m-d'), 'nested_array[1][4] should have the correct date.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for nested_array.'); + } +} diff --git a/tests/Core/Json/NullPropertyTest.php b/tests/Core/Json/NullPropertyTest.php new file mode 100644 index 00000000..1656b1ba --- /dev/null +++ b/tests/Core/Json/NullPropertyTest.php @@ -0,0 +1,53 @@ +nonNullProperty = $values['nonNullProperty']; + $this->nullProperty = $values['nullProperty'] ?? null; + } +} + +class NullPropertyTest extends TestCase +{ + public function testNullPropertiesAreOmitted(): void + { + $object = new NullProperty( + [ + "nonNullProperty" => "Test String", + "nullProperty" => null + ] + ); + + $serialized = $object->jsonSerialize(); + $this->assertArrayHasKey('non_null_property', $serialized, 'non_null_property should be present in the serialized JSON.'); + $this->assertArrayNotHasKey('null_property', $serialized, 'null_property should be omitted from the serialized JSON.'); + $this->assertEquals('Test String', $serialized['non_null_property'], 'non_null_property should have the correct value.'); + } +} diff --git a/tests/Core/Json/NullableArrayTest.php b/tests/Core/Json/NullableArrayTest.php new file mode 100644 index 00000000..9b3a1192 --- /dev/null +++ b/tests/Core/Json/NullableArrayTest.php @@ -0,0 +1,49 @@ + $nullableStringArray + */ + #[ArrayType([new Union('string', 'null')])] + #[JsonProperty('nullable_string_array')] + public array $nullableStringArray; + + /** + * @param array{ + * nullableStringArray: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->nullableStringArray = $values['nullableStringArray']; + } +} + +class NullableArrayTest extends TestCase +{ + public function testNullableArray(): void + { + $expectedJson = json_encode( + [ + 'nullable_string_array' => ['one', null, 'three'] + ], + JSON_THROW_ON_ERROR + ); + + $object = NullableArray::fromJson($expectedJson); + $this->assertEquals(['one', null, 'three'], $object->nullableStringArray, 'nullable_string_array should match the original data.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for nullable_string_array.'); + } +} diff --git a/tests/Core/Json/ScalarTest.php b/tests/Core/Json/ScalarTest.php new file mode 100644 index 00000000..ae30aace --- /dev/null +++ b/tests/Core/Json/ScalarTest.php @@ -0,0 +1,116 @@ + $intFloatArray + */ + #[ArrayType([new Union('integer', 'float')])] + #[JsonProperty('int_float_array')] + public array $intFloatArray; + + /** + * @var array $floatArray + */ + #[ArrayType(['float'])] + #[JsonProperty('float_array')] + public array $floatArray; + + /** + * @var bool|null $nullableBooleanProperty + */ + #[JsonProperty('nullable_boolean_property')] + public ?bool $nullableBooleanProperty; + + /** + * @param array{ + * integerProperty: int, + * floatProperty: float, + * otherFloatProperty: float, + * booleanProperty: bool, + * stringProperty: string, + * intFloatArray: array, + * floatArray: array, + * nullableBooleanProperty?: bool|null, + * } $values + */ + public function __construct( + array $values, + ) { + $this->integerProperty = $values['integerProperty']; + $this->floatProperty = $values['floatProperty']; + $this->otherFloatProperty = $values['otherFloatProperty']; + $this->booleanProperty = $values['booleanProperty']; + $this->stringProperty = $values['stringProperty']; + $this->intFloatArray = $values['intFloatArray']; + $this->floatArray = $values['floatArray']; + $this->nullableBooleanProperty = $values['nullableBooleanProperty'] ?? null; + } +} + +class ScalarTest extends TestCase +{ + public function testAllScalarTypesIncludingFloat(): void + { + $expectedJson = json_encode( + [ + 'integer_property' => 42, + 'float_property' => 3.14159, + 'other_float_property' => 3, + 'boolean_property' => true, + 'string_property' => 'Hello, World!', + 'int_float_array' => [1, 2.5, 3, 4.75], + 'float_array' => [1, 2, 3, 4] // Ensure we handle "integer-looking" floats + ], + JSON_THROW_ON_ERROR + ); + + $object = Scalar::fromJson($expectedJson); + $this->assertEquals(42, $object->integerProperty, 'integer_property should be 42.'); + $this->assertEquals(3.14159, $object->floatProperty, 'float_property should be 3.14159.'); + $this->assertTrue($object->booleanProperty, 'boolean_property should be true.'); + $this->assertEquals('Hello, World!', $object->stringProperty, 'string_property should be "Hello, World!".'); + $this->assertNull($object->nullableBooleanProperty, 'nullable_boolean_property should be null.'); + $this->assertEquals([1, 2.5, 3, 4.75], $object->intFloatArray, 'int_float_array should match the original data.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for ScalarTypesTest.'); + } +} diff --git a/tests/Core/Json/TraitTest.php b/tests/Core/Json/TraitTest.php new file mode 100644 index 00000000..df149de6 --- /dev/null +++ b/tests/Core/Json/TraitTest.php @@ -0,0 +1,60 @@ +integerProperty = $values['integerProperty']; + $this->stringProperty = $values['stringProperty']; + } +} + +class TraitTest extends TestCase +{ + public function testTraitPropertyAndString(): void + { + $expectedJson = json_encode( + [ + 'integer_property' => 42, + 'string_property' => 'Hello, World!', + ], + JSON_THROW_ON_ERROR + ); + + $object = TypeWithTrait::fromJson($expectedJson); + $this->assertEquals(42, $object->integerProperty, 'integer_property should be 42.'); + $this->assertEquals('Hello, World!', $object->stringProperty, 'string_property should be "Hello, World!".'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for ScalarTypesTestWithTrait.'); + } +} diff --git a/tests/Core/Json/UnionArrayTest.php b/tests/Core/Json/UnionArrayTest.php new file mode 100644 index 00000000..e3676e07 --- /dev/null +++ b/tests/Core/Json/UnionArrayTest.php @@ -0,0 +1,57 @@ + $mixedDates + */ + #[ArrayType(['integer' => new Union('datetime', 'string', 'null')])] + #[JsonProperty('mixed_dates')] + public array $mixedDates; + + /** + * @param array{ + * mixedDates: array, + * } $values + */ + public function __construct( + array $values, + ) { + $this->mixedDates = $values['mixedDates']; + } +} + +class UnionArrayTest extends TestCase +{ + public function testUnionArray(): void + { + $expectedJson = json_encode( + [ + 'mixed_dates' => [ + 1 => '2023-01-01T12:00:00+00:00', + 2 => null, + 3 => 'Some String' + ] + ], + JSON_THROW_ON_ERROR + ); + + $object = UnionArray::fromJson($expectedJson); + $this->assertInstanceOf(DateTime::class, $object->mixedDates[1], 'mixed_dates[1] should be a DateTime instance.'); + $this->assertEquals('2023-01-01 12:00:00', $object->mixedDates[1]->format('Y-m-d H:i:s'), 'mixed_dates[1] should have the correct datetime.'); + $this->assertNull($object->mixedDates[2], 'mixed_dates[2] should be null.'); + $this->assertEquals('Some String', $object->mixedDates[3], 'mixed_dates[3] should be "Some String".'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match original JSON for mixed_dates.'); + } +} diff --git a/tests/Core/Json/UnionPropertyTest.php b/tests/Core/Json/UnionPropertyTest.php new file mode 100644 index 00000000..1fafd95f --- /dev/null +++ b/tests/Core/Json/UnionPropertyTest.php @@ -0,0 +1,115 @@ + 'integer'], UnionProperty::class)] + #[JsonProperty('complexUnion')] + public mixed $complexUnion; + + /** + * @param array{ + * complexUnion: string|int|null|array|UnionProperty + * } $values + */ + public function __construct( + array $values, + ) { + $this->complexUnion = $values['complexUnion']; + } +} + +class UnionPropertyTest extends TestCase +{ + public function testWithMapOfIntToInt(): void + { + $expectedJson = json_encode( + [ + 'complexUnion' => [1 => 100, 2 => 200] + ], + JSON_THROW_ON_ERROR + ); + + $object = UnionProperty::fromJson($expectedJson); + $this->assertIsArray($object->complexUnion, 'complexUnion should be an array.'); + $this->assertEquals([1 => 100, 2 => 200], $object->complexUnion, 'complexUnion should match the original map of int => int.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match the original JSON.'); + } + + public function testWithNestedUnionPropertyType(): void + { + $expectedJson = json_encode( + [ + 'complexUnion' => new UnionProperty( + [ + 'complexUnion' => 'Nested String' + ] + ) + ], + JSON_THROW_ON_ERROR + ); + + $object = UnionProperty::fromJson($expectedJson); + $this->assertInstanceOf(UnionProperty::class, $object->complexUnion, 'complexUnion should be an instance of UnionPropertyType.'); + $this->assertEquals('Nested String', $object->complexUnion->complexUnion, 'Nested complexUnion should match the original value.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match the original JSON.'); + } + + public function testWithNull(): void + { + $expectedJson = json_encode( + [], + JSON_THROW_ON_ERROR + ); + + $object = UnionProperty::fromJson($expectedJson); + $this->assertNull($object->complexUnion, 'complexUnion should be null.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match the original JSON.'); + } + + public function testWithInteger(): void + { + $expectedJson = json_encode( + [ + 'complexUnion' => 42 + ], + JSON_THROW_ON_ERROR + ); + + $object = UnionProperty::fromJson($expectedJson); + $this->assertIsInt($object->complexUnion, 'complexUnion should be an integer.'); + $this->assertEquals(42, $object->complexUnion, 'complexUnion should match the original integer.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match the original JSON.'); + } + + public function testWithString(): void + { + $expectedJson = json_encode( + [ + 'complexUnion' => 'Some String' + ], + JSON_THROW_ON_ERROR + ); + + $object = UnionProperty::fromJson($expectedJson); + $this->assertIsString($object->complexUnion, 'complexUnion should be a string.'); + $this->assertEquals('Some String', $object->complexUnion, 'complexUnion should match the original string.'); + + $actualJson = $object->toJson(); + $this->assertJsonStringEqualsJsonString($expectedJson, $actualJson, 'Serialized JSON does not match the original JSON.'); + } +} diff --git a/tests/Core/Pagination/CreateRequestWithDefaultsTest.php b/tests/Core/Pagination/CreateRequestWithDefaultsTest.php new file mode 100644 index 00000000..c3ef9009 --- /dev/null +++ b/tests/Core/Pagination/CreateRequestWithDefaultsTest.php @@ -0,0 +1,131 @@ +pagination = $values['pagination'] ?? null; + $this->query = $values['query']; + } +} + +class StartingAfterPaging +{ + /** + * @var int $perPage + */ + public int $perPage; + + /** + * @var ?string $startingAfter + */ + public ?string $startingAfter; + + /** + * @param array{ + * perPage: int, + * startingAfter?: ?string, + * } $values + */ + public function __construct( + array $values, + ) { + $this->perPage = $values['perPage']; + $this->startingAfter = $values['startingAfter'] ?? null; + } +} + +class SingleFilterSearchRequest +{ + /** + * @var ?string $field + */ + public ?string $field; + + /** + * @var ?string $operator + */ + public ?string $operator; + + /** + * @var ?string $value + */ + public ?string $value; + + /** + * @param array{ + * field?: ?string, + * operator?: ?string, + * value?: ?string, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->field = $values['field'] ?? null; + $this->operator = $values['operator'] ?? null; + $this->value = $values['value'] ?? null; + } +} + +class MultipleFilterSearchRequest +{ + /** + * @var ?string $operator + */ + public ?string $operator; + + /** + * @var array|array|null $value + */ + public array|null $value; + + /** + * @param array{ + * operator?: ?string, + * value?: array|array|null, + * } $values + */ + public function __construct( + array $values = [], + ) { + $this->operator = $values['operator'] ?? null; + $this->value = $values['value'] ?? null; + } +} + +class CreateRequestWithDefaultsTest extends TestCase +{ + public function testCreateInstanceWithDefaults(): void + { + $instance = PaginationHelper::createRequestWithDefaults(SearchRequest::class); + $this->assertInstanceOf(SearchRequest::class, $instance); + $this->assertNull($instance->pagination); + $this->assertInstanceOf(SingleFilterSearchRequest::class, $instance->query); + $this->assertNull($instance->query->field); + $this->assertNull($instance->query->operator); + $this->assertNull($instance->query->value); + } +} diff --git a/tests/Core/Pagination/CursorPagerTest/CursorPagerTest.php b/tests/Core/Pagination/CursorPagerTest/CursorPagerTest.php new file mode 100644 index 00000000..5530891f --- /dev/null +++ b/tests/Core/Pagination/CursorPagerTest/CursorPagerTest.php @@ -0,0 +1,132 @@ +cursor = $cursor; + } +} + +class Response +{ + /** + * @var ?array + */ + public ?array $items; + + public ?ResponseCursor $next; + + /** + * @param ?array $items + * @param ?ResponseCursor $next + */ + public function __construct(?array $items, ?ResponseCursor $next) + { + $this->items = $items; + $this->next = $next; + } +} + +class ResponseCursor +{ + public ?string $cursor; + + /** + * @param ?string $cursor + */ + public function __construct(?string $cursor) + { + $this->cursor = $cursor; + } +} + +class CursorPagerTest extends TestCase +{ + private const CURSOR1 = null; + private const CURSOR2 = '00000000-0000-0000-0000-000000000001'; + private const CURSOR3 = '00000000-0000-0000-0000-000000000002'; + private ?string $cursorCopy; + + public function testCursorPager(): void + { + $pager = $this->createPager(); + $this->assertPager($pager); + } + + /** + * @return CursorPager + */ + private function createPager(): CursorPager + { + $request = new Request(self::CURSOR1); + $responses = new ArrayIterator([ + new Response(['item1', 'item2'], new ResponseCursor(self::CURSOR2)), + new Response(['item1'], new ResponseCursor(self::CURSOR3)), + new Response([], null), + ]); + + $this->cursorCopy = self::CURSOR1; + + return new CursorPager( + $request, + function (Request $request) use ($responses) { + $response = $responses->current(); + $responses->next(); + return $response; + }, + function (Request $request, ?string $cursor) { + $request->cursor = $cursor; + $this->cursorCopy = $cursor; + }, + fn (Response $response) => $response->next->cursor ?? null, + fn (Response $response) => $response->items ?? [] + ); + } + + /** + * @param Pager $pager + * @return void + */ + private function assertPager(Pager $pager): void + { + /** @var Generator> $pages */ + $pages = $pager->getPages(); + + // first page + /** @var Page $page */ + $page = $pages->current(); + $this->assertCount(2, $page->getItems()); + $this->assertEquals(self::CURSOR1, $this->cursorCopy); + + // second page + $pages->next(); + $page = $pages->current(); + $this->assertCount(1, $page->getItems()); + $this->assertEquals(self::CURSOR2, $this->cursorCopy); + + // third page + $pages->next(); + $page = $pages->current(); + $this->assertCount(0, $page->getItems()); + $this->assertEquals(self::CURSOR3, $this->cursorCopy); + + // no more pages + $pages->next(); + $this->assertNull($pages->current()); + } +} diff --git a/tests/Core/Pagination/DeepSetAccessorsTest.php b/tests/Core/Pagination/DeepSetAccessorsTest.php new file mode 100644 index 00000000..295f02ba --- /dev/null +++ b/tests/Core/Pagination/DeepSetAccessorsTest.php @@ -0,0 +1,101 @@ +level1; + } + + /** + * @param ?array{ + * level1?: ?Level1ObjectAccessors, + * } $data + */ + public function __construct(?array $data = []) + { + $this->level1 = $data['level1'] ?? null; + } +} + +class Level1ObjectAccessors +{ + private ?Level2ObjectAccessors $level2; + + public function getLevel2(): ?Level2ObjectAccessors + { + return $this->level2; + } + + /** + * @param ?array{ + * level2?: ?Level2ObjectAccessors, + * } $data + */ + public function __construct(?array $data = []) + { + $this->level2 = $data['level2'] ?? null; + } +} + +class Level2ObjectAccessors +{ + private ?string $level3; + + /** + * @return string|null + */ + public function getLevel3(): ?string + { + return $this->level3; + } + + /** + * @param ?array{ + * level3?: ?string, + * } $data + */ + public function __construct(?array $data = []) + { + $this->level3 = $data['level3'] ?? null; + } +} + +class DeepSetAccessorsTest extends TestCase +{ + public function testSetNestedPropertyWithNull(): void + { + $object = new RootObjectAccessors(); + + $this->assertNull($object->getLevel1()); + + PaginationHelper::setDeep($object, ['level1', 'level2', 'level3'], 'testValue'); + + $this->assertEquals('testValue', $object->getLevel1()?->getLevel2()?->getLevel3()); + } + + public function testSetNestedProperty(): void + { + $object = new RootObjectAccessors([ + "level1" => new Level1ObjectAccessors([ + "level2" => new Level2ObjectAccessors([ + "level3" => null + ]) + ]) + ]); + + $this->assertNull($object->getLevel1()?->getLevel2()?->getLevel3()); + + PaginationHelper::setDeep($object, ['level1', 'level2', 'level3'], 'testValue'); + + $this->assertEquals('testValue', $object->getLevel1()?->getLevel2()?->getLevel3()); + } + +} diff --git a/tests/Core/Pagination/DeepSetTest.php b/tests/Core/Pagination/DeepSetTest.php new file mode 100644 index 00000000..98b6abff --- /dev/null +++ b/tests/Core/Pagination/DeepSetTest.php @@ -0,0 +1,83 @@ +level1 = $data['level1'] ?? null; + } +} + +class Level1Object +{ + public ?Level2Object $level2; + + /** + * @param ?array{ + * level2?: ?Level2Object, + * } $data + */ + public function __construct(?array $data = []) + { + $this->level2 = $data['level2'] ?? null; + } +} + +class Level2Object +{ + public ?string $level3; + + /** + * @param ?array{ + * level3?: ?string, + * } $data + */ + public function __construct(?array $data = []) + { + $this->level3 = $data['level3'] ?? null; + } +} + +class DeepSetTest extends TestCase +{ + public function testSetNestedPropertyWithNull(): void + { + $object = new RootObject(); + + $this->assertNull($object->level1); + + PaginationHelper::setDeep($object, ['level1', 'level2', 'level3'], 'testValue'); + + $this->assertEquals('testValue', $object->level1?->level2?->level3); + } + + public function testSetNestedProperty(): void + { + $object = new RootObject([ + "level1" => new Level1Object([ + "level2" => new Level2Object([ + "level3" => null + ]) + ]) + ]); + + $this->assertNull($object->level1?->level2?->level3); + + PaginationHelper::setDeep($object, ['level1', 'level2', 'level3'], 'testValue'); + + $this->assertEquals('testValue', $object->level1?->level2?->level3); + } + +} diff --git a/tests/Core/Pagination/GeneratorPagerTest/GeneratorPagerTest.php b/tests/Core/Pagination/GeneratorPagerTest/GeneratorPagerTest.php new file mode 100644 index 00000000..cd24f84a --- /dev/null +++ b/tests/Core/Pagination/GeneratorPagerTest/GeneratorPagerTest.php @@ -0,0 +1,130 @@ +page = $page; + } +} + +class Response +{ + public Data $data; + + public function __construct(Data $data) + { + $this->data = $data; + } +} + +class Data +{ + /** + * @var string[] + */ + public array $items; + + /** + * @param string[] $items + */ + public function __construct(array $items) + { + $this->items = $items; + } +} + +class GeneratorPagerTest extends TestCase +{ + public function testPagerItemsIteration(): void + { + $pager = $this->createPager(); + $this->assertPagerItems($pager); + } + + public function testPagerPagesIteration(): void + { + $pager = $this->createPager(); + $this->assertPagerPages($pager); + } + + /** + * @return Pager + */ + private function createPager(): Pager + { + $responses = new ArrayIterator([ + new Response(new Data(['item1', 'item2'])), + new Response(new Data(['item3'])), + new Response(new Data([])), + ]); + + return new class ($responses) extends Pager { + /** + * @var ArrayIterator + */ + private ArrayIterator $responses; + + /** + * @param ArrayIterator $responses + */ + public function __construct(ArrayIterator $responses) + { + $this->responses = $responses; + } + + /** + * @return Generator> + */ + public function getPages(): Generator + { + while ($this->responses->valid()) { + $response = $this->responses->current(); + $this->responses->next(); + yield new Page($response->data->items); + } + } + }; + } + + /** + * @param Pager $pager + * @return void + */ + private function assertPagerItems(Pager $pager): void + { + $items = []; + foreach ($pager as $item) { + $items[] = $item; + } + $this->assertCount(3, $items); + $this->assertEquals(['item1', 'item2', 'item3'], $items); + } + + /** + * @param Pager $pager + * @return void + */ + private function assertPagerPages(Pager $pager): void + { + $pages = []; + foreach ($pager->getPages() as $page) { + $pages[] = $page; + } + $pageCounter = count($pages); + $itemCounter = array_reduce($pages, fn ($carry, $page) => $carry + count($page->getItems()), 0); + + $this->assertEquals(3, $pageCounter); + $this->assertEquals(3, $itemCounter); + } +} diff --git a/tests/Core/Pagination/HasNextPageOffsetPagerTest/HasNextPageOffsetPagerTest.php b/tests/Core/Pagination/HasNextPageOffsetPagerTest/HasNextPageOffsetPagerTest.php new file mode 100644 index 00000000..5a771d86 --- /dev/null +++ b/tests/Core/Pagination/HasNextPageOffsetPagerTest/HasNextPageOffsetPagerTest.php @@ -0,0 +1,110 @@ +pagination = $pagination; + } +} + +class Pagination +{ + public int $page; + + public function __construct(int $page) + { + $this->page = $page; + } +} + +class Response +{ + public Data $data; + public bool $hasNext; + + public function __construct(Data $data, bool $hasNext) + { + $this->data = $data; + $this->hasNext = $hasNext; + } +} + +class Data +{ + /** + * @var string[] + */ + public array $items; + + /** + * @param string[] $items + */ + public function __construct(array $items) + { + $this->items = $items; + } +} + +class HasNextPageOffsetPagerTest extends TestCase +{ + public function testOffsetPagerWithHasNextPage(): void + { + $pager = $this->createPager(); + $this->assertPager($pager); + } + + /** + * @return OffsetPager + */ + private function createPager(): OffsetPager + { + $responses = new ArrayIterator([ + new Response(new Data(['item1', 'item2']), true), + new Response(new Data(['item3', 'item4']), true), + new Response(new Data(['item5']), false), + ]); + + return new OffsetPager( + new Request(new Pagination(1)), + function (Request $request) use ($responses) { + $response = $responses->current(); + $responses->next(); + return $response; + }, + fn (Request $request) => $request->pagination?->page ?? 0, + function (Request $request, int $offset) { + if ($request->pagination === null) { + $request->pagination = new Pagination(0); + } + $request->pagination->page = $offset; + }, + null, + fn (Response $response) => $response->data->items, + fn (Response $response) => $response->hasNext + ); + } + + /** + * @param Pager $pager + * @return void + */ + private function assertPager(Pager $pager): void + { + $pages = iterator_to_array($pager->getPages()); + $pageCounter = count($pages); + $itemCounter = array_reduce($pages, fn ($carry, $page) => $carry + count($page->getItems()), 0); + + $this->assertEquals(3, $pageCounter); + $this->assertEquals(5, $itemCounter); + } +} diff --git a/tests/Core/Pagination/IntOffsetPagerTest/IntOffsetPagerTest.php b/tests/Core/Pagination/IntOffsetPagerTest/IntOffsetPagerTest.php new file mode 100644 index 00000000..e0e3dec8 --- /dev/null +++ b/tests/Core/Pagination/IntOffsetPagerTest/IntOffsetPagerTest.php @@ -0,0 +1,108 @@ +pagination = $pagination; + } +} + +class Pagination +{ + public int $page; + + public function __construct(int $page) + { + $this->page = $page; + } +} + +class Response +{ + public Data $data; + + public function __construct(Data $data) + { + $this->data = $data; + } +} + +class Data +{ + /** + * @var string[] + */ + public array $items; + + /** + * @param string[] $items + */ + public function __construct(array $items) + { + $this->items = $items; + } +} + +class IntOffsetPagerTest extends TestCase +{ + public function testOffsetPagerWithPage(): void + { + $pager = $this->createPager(); + $this->assertPager($pager); + } + + /** + * @return OffsetPager + */ + private function createPager(): OffsetPager + { + $responses = new ArrayIterator([ + new Response(new Data(['item1', 'item2'])), + new Response(new Data(['item3'])), + new Response(new Data([])), + ]); + + return new OffsetPager( + new Request(new Pagination(1)), + function (Request $request) use ($responses) { + $response = $responses->current(); + $responses->next(); + return $response; + }, + fn (Request $request) => $request->pagination?->page ?? 0, + function (Request $request, int $offset) { + if ($request->pagination === null) { + $request->pagination = new Pagination(0); + } + $request->pagination->page = $offset; + }, + null, + fn (Response $response) => $response->data->items, + null + ); + } + + /** + * @param Pager $pager + * @return void + */ + private function assertPager(Pager $pager): void + { + $pages = iterator_to_array($pager->getPages()); + $pageCounter = count($pages); + $itemCounter = array_reduce($pages, fn ($carry, $page) => $carry + count($page->getItems()), 0); + + $this->assertEquals(3, $pageCounter); + $this->assertEquals(3, $itemCounter); + } +} diff --git a/tests/Core/Pagination/StepOffsetPagerTest/StepOffsetPagerTest.php b/tests/Core/Pagination/StepOffsetPagerTest/StepOffsetPagerTest.php new file mode 100644 index 00000000..1d3d916b --- /dev/null +++ b/tests/Core/Pagination/StepOffsetPagerTest/StepOffsetPagerTest.php @@ -0,0 +1,131 @@ +pagination = $pagination; + } +} + +class Pagination +{ + public int $itemOffset; + public int $pageSize; + + public function __construct(int $itemOffset, int $pageSize) + { + $this->itemOffset = $itemOffset; + $this->pageSize = $pageSize; + } +} + +class Response +{ + public Data $data; + + public function __construct(Data $data) + { + $this->data = $data; + } +} + +class Data +{ + /** + * @var string[] + */ + public array $items; + + /** + * @param string[] $items + */ + public function __construct(array $items) + { + $this->items = $items; + } +} + +class StepOffsetPagerTest extends TestCase +{ + private Pagination $paginationCopy; + + public function testOffsetPagerWithStep(): void + { + $pager = $this->createPager(); + $this->assertPager($pager); + } + + /** + * @return OffsetPager + */ + private function createPager(): OffsetPager + { + $responses = new ArrayIterator([ + new Response(new Data(['item1', 'item2'])), + new Response(new Data(['item3'])), + new Response(new Data([])), + ]); + + $this->paginationCopy = new Pagination(0, 2); + + return new OffsetPager( + new Request($this->paginationCopy), + function (Request $request) use ($responses) { + $response = $responses->current(); + $responses->next(); + return $response; + }, + fn (Request $request) => $request->pagination?->itemOffset ?? 0, + function (Request $request, int $offset) { + if ($request->pagination === null) { + $request->pagination = new Pagination(0, 2); + } + $request->pagination->itemOffset = $offset; + $this->paginationCopy = $request->pagination; + }, + fn (Request $request) => $request->pagination?->pageSize, + fn (Response $response) => $response->data->items, + null + ); + } + + /** + * @param Pager $pager + * @return void + */ + private function assertPager(Pager $pager): void + { + $pages = $pager->getPages(); + + // first page + $page = $pages->current(); + $this->assertCount(2, $page->getItems()); + $this->assertEquals(0, $this->paginationCopy->itemOffset); + + // second page + $pages->next(); + $page = $pages->current(); + $this->assertCount(1, $page->getItems()); + $this->assertEquals(2, $this->paginationCopy->itemOffset); + + // third page + $pages->next(); + $page = $pages->current(); + $this->assertCount(0, $page->getItems()); + $this->assertEquals(3, $this->paginationCopy->itemOffset); + + // no more pages + $pages->next(); + $this->assertNull($pages->current()); + } +} diff --git a/tests/IntercomAdminsTest.php b/tests/IntercomAdminsTest.php deleted file mode 100644 index 89137993..00000000 --- a/tests/IntercomAdminsTest.php +++ /dev/null @@ -1,30 +0,0 @@ -client->method('get')->willReturn('foo'); - - $users = new IntercomAdmins($this->client); - $this->assertSame('foo', $users->getAdmins()); - } - - public function testAdminsGet() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomAdmins($this->client); - $this->assertSame('foo', $users->getAdmin(1)); - } - - public function testAdminsGetPath() - { - $users = new IntercomAdmins($this->client); - $this->assertSame('admins/1', $users->adminPath(1)); - } -} diff --git a/tests/IntercomBulkTest.php b/tests/IntercomBulkTest.php deleted file mode 100644 index 97de766c..00000000 --- a/tests/IntercomBulkTest.php +++ /dev/null @@ -1,24 +0,0 @@ -client->method('post')->will($this->returnArgument(0)); - - $bulk = new IntercomBulk($this->client); - $this->assertSame('bulk/users', $bulk->users([])); - } - - public function testBulkEvents() - { - $this->client->method('post')->will($this->returnArgument(0)); - - $bulk = new IntercomBulk($this->client); - $this->assertSame('bulk/events', $bulk->events([])); - } -} diff --git a/tests/IntercomClientTest.php b/tests/IntercomClientTest.php deleted file mode 100644 index f5a244c4..00000000 --- a/tests/IntercomClientTest.php +++ /dev/null @@ -1,157 +0,0 @@ -addResponse( - new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") - ); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - - foreach ($httpClient->getRequests() as $request) { - $basic = $request->getHeaders()['Authorization'][0]; - $this->assertSame("Basic dTpw", $basic); - } - } - - public function testClientWithExtraHeaders() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") - ); - - $client = new IntercomClient('u', 'p', ['Custom-Header' => 'value']); - $client->setHttpClient($httpClient); - - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - - foreach ($httpClient->getRequests() as $request) { - $headers = $request->getHeaders(); - $this->assertSame('application/json', $headers['Accept'][0]); - $this->assertSame('application/json', $headers['Content-Type'][0]); - $this->assertSame('value', $headers['Custom-Header'][0]); - } - } - - public function testClientErrorHandling() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(404) - ); - $httpClient = new PluginClient($httpClient, [new ErrorPlugin()]); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $this->expectException(Exception::class); - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - } - - public function testServerErrorHandling() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(500) - ); - $httpClient = new PluginClient($httpClient, [new ErrorPlugin()]); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $this->expectException(Exception::class); - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - } - - public function testPaginationHelper() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") - ); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $pages = new stdClass; - $pages->next = 'https://foo.com'; - - $client->nextPage($pages); - - foreach ($httpClient->getRequests() as $request) { - $host = $request->getUri()->getHost(); - $this->assertSame("foo.com", $host); - } - } - - public function testRateLimitDetails() - { - date_default_timezone_set('UTC'); - $time = time() + 7; - - $httpClient = new Client(); - $httpClient->addResponse( - new Response( - 200, - [ - 'X-RateLimit-Limit' => '83', - 'X-RateLimit-Remaining' => '2', - 'X-RateLimit-Reset' => $time - ], - "{\"foo\":\"bar\"}" - ) - ); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - - $rateLimitDetails = $client->getRateLimitDetails(); - $this->assertIsArray($rateLimitDetails); - $this->assertArrayHasKey('limit', $rateLimitDetails); - $this->assertArrayHasKey('remaining', $rateLimitDetails); - $this->assertArrayHasKey('reset_at', $rateLimitDetails); - $this->assertSame(83, $rateLimitDetails['limit']); - $this->assertSame(2, $rateLimitDetails['remaining']); - $this->assertSame( - (new DateTimeImmutable)->setTimestamp($time)->getTimestamp(), - $rateLimitDetails['reset_at']->getTimestamp() - ); - } -} diff --git a/tests/IntercomCompaniesTest.php b/tests/IntercomCompaniesTest.php deleted file mode 100644 index 7c3bd1d9..00000000 --- a/tests/IntercomCompaniesTest.php +++ /dev/null @@ -1,60 +0,0 @@ -client->method('post')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->create([])); - } - - public function testCompanyUpdate() - { - $this->client->method('post')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->update([])); - } - - public function testCompanyGet() - { - $this->client->method('get')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->getCompanies([])); - } - - public function testCompanyPath() - { - $users = new IntercomCompanies($this->client); - $this->assertSame('companies/foo', $users->companyPath("foo")); - } - - public function testCompanyGetById() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomCompanies($this->client); - $this->assertSame('foo', $users->getCompany("foo")); - } - - public function testCompanyGetUsers() - { - $this->client->method('get')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->getCompanyUsers("foo")); - } - - public function testCompanyUsersPath() - { - $users = new IntercomCompanies($this->client); - $this->assertSame('companies/foo/users', $users->companyUsersPath("foo")); - } -} diff --git a/tests/IntercomContactsTest.php b/tests/IntercomContactsTest.php deleted file mode 100644 index 9d1578d5..00000000 --- a/tests/IntercomContactsTest.php +++ /dev/null @@ -1,82 +0,0 @@ -client->method('post')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->create([])); - } - - public function testContactUpdate() - { - $this->client->method('put')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->update('', [])); - } - - public function testContactsGet() - { - $this->client->method('get')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->getContacts([])); - } - - public function testContactGet() - { - $this->client->method('get')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->getContact("123")); - } - - public function testContactDelete() - { - $this->client->method('delete')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->deleteContact('')); - } - - public function testContactSearch() - { - $this->client->method('post')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->search([])); - } - - public function testContactNextSearch() - { - $this->client->method('nextSearchPage')->willReturn('foo'); - $query = []; - $pages = new stdClass; - $pages->per_page = "10"; - $pages->next = new stdClass; - $pages->next->starting_after = "abc"; - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->nextSearch([], $pages)); - } - - public function testConversationNextCursor() - { - $this->client->method('nextCursorPage')->willReturn('foo'); - $query = []; - $pages = new stdClass; - $pages->next = new stdClass; - $pages->next->starting_after = "abc"; - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->nextCursor($pages)); - } -} diff --git a/tests/IntercomConversationsTest.php b/tests/IntercomConversationsTest.php deleted file mode 100644 index 00c8f9ea..00000000 --- a/tests/IntercomConversationsTest.php +++ /dev/null @@ -1,74 +0,0 @@ -client->method('post')->willReturn('foo'); - - $conversations = new IntercomConversations($this->client); - $this->assertSame('foo', $conversations->create([])); - } - - public function testConversationsList() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomConversations($this->client); - $this->assertSame('foo', $users->getConversations([])); - } - - public function testConversationPath() - { - $users = new IntercomConversations($this->client); - $this->assertSame('conversations/foo', $users->conversationPath("foo")); - } - - public function testGetConversation() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomConversations($this->client); - $this->assertSame('foo', $users->getConversation("foo")); - } - - public function testConversationSearch() - { - $this->client->method('post')->willReturn('foo'); - - $conversations = new IntercomConversations($this->client); - $this->assertSame('foo', $conversations->search([])); - } - - public function testConversationNextSearch() - { - $this->client->method('nextSearchPage')->willReturn('foo'); - $query = []; - $pages = new stdClass; - $pages->per_page = "10"; - $pages->next = new stdClass; - $pages->next->starting_after = "abc"; - - $conversations = new IntercomConversations($this->client); - $this->assertSame('foo', $conversations->nextSearch([], $pages)); - } - - public function testConversationReplyPath() - { - $users = new IntercomConversations($this->client); - $this->assertSame('conversations/foo/reply', $users->conversationReplyPath("foo")); - } - - public function testReplyToConversation() - { - $this->client->method('post')->willReturn('foo'); - - $users = new IntercomConversations($this->client); - $this->assertSame('foo', $users->replyToConversation("bar", [])); - } -} diff --git a/tests/IntercomCountsTest.php b/tests/IntercomCountsTest.php deleted file mode 100644 index 6ef9a1ae..00000000 --- a/tests/IntercomCountsTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->method('get')->willReturn('foo'); - - $counts = new IntercomCounts($this->client); - $this->assertSame('foo', $counts->getCounts([])); - } -} diff --git a/tests/IntercomEventsTest.php b/tests/IntercomEventsTest.php deleted file mode 100644 index d3d9d035..00000000 --- a/tests/IntercomEventsTest.php +++ /dev/null @@ -1,24 +0,0 @@ -client->method('post')->willReturn('foo'); - - $users = new IntercomEvents($this->client); - $this->assertSame('foo', $users->create([])); - } - - public function testEventsGet() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomEvents($this->client); - $this->assertSame('foo', $users->getEvents([])); - } -} diff --git a/tests/IntercomLeadsTest.php b/tests/IntercomLeadsTest.php deleted file mode 100644 index 092b8799..00000000 --- a/tests/IntercomLeadsTest.php +++ /dev/null @@ -1,71 +0,0 @@ -client->method('post')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->create([])); - } - - public function testLeadUpdate() - { - $this->client->method('post')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->update([])); - } - - public function testLeadsList() - { - $this->client->method('get')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->getLeads([])); - } - - public function testLeadPath() - { - - $leads = new IntercomLeads($this->client); - $this->assertSame("contacts/foo", $leads->leadPath("foo")); - } - - public function testLeadsGet() - { - $this->client->method('get')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->getLead("bar")); - } - - public function testLeadsConvert() - { - $this->client->method('post')->will($this->returnArgument(0)); - - $leads = new IntercomLeads($this->client); - $this->assertSame('contacts/convert', $leads->convertLead([])); - } - - public function testLeadsDelete() - { - $this->client->method('delete')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->deleteLead("bar")); - } - - public function testLeadsScroll() - { - $this->client->method('get')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->scrollLeads([])); - } -} diff --git a/tests/IntercomMessagesTest.php b/tests/IntercomMessagesTest.php deleted file mode 100644 index 2e92fdfd..00000000 --- a/tests/IntercomMessagesTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->method('post')->willReturn('foo'); - - $messages = new IntercomMessages($this->client); - $this->assertSame('foo', $messages->create([])); - } -} diff --git a/tests/IntercomNotesTest.php b/tests/IntercomNotesTest.php deleted file mode 100644 index 5ce61234..00000000 --- a/tests/IntercomNotesTest.php +++ /dev/null @@ -1,32 +0,0 @@ -client->method('post')->willReturn('foo'); - - $notes = new IntercomNotes($this->client); - $this->assertSame('foo', $notes->create([])); - } - - public function testNotesList() - { - $this->client->method('get')->willReturn('foo'); - - $notes = new IntercomNotes($this->client); - $this->assertSame('foo', $notes->getNotes([])); - } - - public function testNotesGet() - { - $this->client->method('get')->will($this->returnArgument(0)); - - $notes = new IntercomNotes($this->client); - $this->assertSame('notes/foo', $notes->getNote("foo")); - } -} diff --git a/tests/IntercomSegmentsTest.php b/tests/IntercomSegmentsTest.php deleted file mode 100644 index 6110e846..00000000 --- a/tests/IntercomSegmentsTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->method('get')->willReturn('foo'); - - $segments = new IntercomSegments($this->client); - $this->assertSame('foo', $segments->getSegments()); - } -} diff --git a/tests/IntercomTagsTest.php b/tests/IntercomTagsTest.php deleted file mode 100644 index bc79bf35..00000000 --- a/tests/IntercomTagsTest.php +++ /dev/null @@ -1,24 +0,0 @@ -client->method('post')->willReturn('foo'); - - $tags = new IntercomTags($this->client); - $this->assertSame('foo', $tags->tag([])); - } - - public function testTagsList() - { - $this->client->method('get')->willReturn('foo'); - - $tags = new IntercomTags($this->client); - $this->assertSame('foo', $tags->getTags()); - } -} diff --git a/tests/IntercomTeamsTest.php b/tests/IntercomTeamsTest.php deleted file mode 100644 index 2385cb9a..00000000 --- a/tests/IntercomTeamsTest.php +++ /dev/null @@ -1,30 +0,0 @@ -client->method('get')->willReturn('foo'); - - $teams = new IntercomTeams($this->client); - $this->assertSame('foo', $teams->getTeams()); - } - - public function testTeamsGet() - { - $this->client->method('get')->willReturn('foo'); - - $teams = new IntercomTeams($this->client); - $this->assertSame('foo', $teams->getTeam(1)); - } - - public function testTeamsGetPath() - { - $teams = new IntercomTeams($this->client); - $this->assertSame('teams/1', $teams->teamPath(1)); - } -} diff --git a/tests/IntercomUsersTest.php b/tests/IntercomUsersTest.php deleted file mode 100644 index ec9aa9e6..00000000 --- a/tests/IntercomUsersTest.php +++ /dev/null @@ -1,56 +0,0 @@ -client->method('post')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->create([])); - } - - public function testUserUpdate() - { - $this->client->method('post')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->update([])); - } - - public function testUserGet() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->getUsers([])); - } - - public function testArchiveUser() - { - $this->client->method('delete')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->archiveUser('')); - } - - public function testDeleteUser() - { - $this->client->method('delete')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->deleteUser('')); - } - - public function testPermanentlyDeleteUser() - { - $this->client->method('post')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->permanentlyDeleteUser('')); - } -} diff --git a/tests/IntercomVisitorsTest.php b/tests/IntercomVisitorsTest.php deleted file mode 100644 index 26fd0196..00000000 --- a/tests/IntercomVisitorsTest.php +++ /dev/null @@ -1,47 +0,0 @@ -client->method('put')->willReturn('foo'); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('foo', $visitors->update([])); - } - - public function testVisitorPath() - { - $visitors = new IntercomVisitors($this->client); - $this->assertSame("visitors/foo", $visitors->visitorPath("foo")); - } - - public function testVisitorsGet() - { - $this->client->method('get')->willReturn('foo'); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('foo', $visitors->getVisitor("bar")); - } - - public function testVisitorsConvert() - { - - $this->client->method('post')->will($this->returnArgument(0)); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('visitors/convert', $visitors->convertVisitor([])); - } - - public function testVisitorsDelete() - { - $this->client->method('delete')->willReturn('foo'); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('foo', $visitors->deleteVisitor("bar")); - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php deleted file mode 100644 index 061b7613..00000000 --- a/tests/TestCase.php +++ /dev/null @@ -1,21 +0,0 @@ -client = $this->getMockBuilder(IntercomClient::class)->disableOriginalConstructor()->getMock(); - } -}