From 8a5d4334880a1d46ba4507237c01e07cea2e87e7 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 10 Mar 2020 10:56:53 -0400 Subject: [PATCH 01/35] Added Contacts & Messages endpoints --- src/IntercomClient.php | 6 +++ src/IntercomContacts.php | 88 ++++++++++++++++++++++++++++++++++++++++ src/IntercomMessages.php | 41 +++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 src/IntercomContacts.php diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 253f21c..1e85ccd 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -56,6 +56,11 @@ class IntercomClient */ public $users; + /** + * @var IntercomContacts $contacts + */ + public $contacts; + /** * @var IntercomCustomers $customers */ @@ -136,6 +141,7 @@ class IntercomClient public function __construct(string $appIdOrToken, string $password = null, array $extraRequestHeaders = []) { $this->users = new IntercomUsers($this); + $this->contacts = new IntercomContacts($this); $this->customers = new IntercomCustomers($this); $this->events = new IntercomEvents($this); $this->companies = new IntercomCompanies($this); diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php new file mode 100644 index 0000000..2d9ed2e --- /dev/null +++ b/src/IntercomContacts.php @@ -0,0 +1,88 @@ +client->post("contacts", $options); + } + + /** + * Updates an existing Contact + * + * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update(array $options) + { + return $this->put($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($id, $options = []) + { + $path = $this->contactPath($id); + return $this->client->get($path, $options); + } + + /** + * 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); + } + + /** + * @param string $id + * @return string + */ + public function contactPath(string $id) + { + return 'contacts/' . $id; + } +} diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php index d4d9665..d3ddb85 100644 --- a/src/IntercomMessages.php +++ b/src/IntercomMessages.php @@ -19,4 +19,45 @@ public function create($options) { return $this->client->post("messages", $options); } + + /** + * Creates Message Export Job + * + * @see https://developers.intercom.com/intercom-api-reference/reference#creating-an-export-job + * @param array $options + * @return stdClass + * @throws Exception + */ + public function createExport($options) + { + return $this->client->post("messages/data", $options); + } + + /** + * Retrieves Export Job Status + * + * @see https://developers.intercom.com/intercom-api-reference/reference#checking-the-status-of-the-job + * @param array $options + * @return stdClass + * @throws Exception + */ + public function retrieveExportStatus($options) + { + return $this->client->get("messages/data", $options); + } + + /** + * Retrieves Export Job Data + * + * Important: Intercom Clinet Accept Header must be application/octet-stream + * + * @see https://developers.intercom.com/intercom-api-reference/reference#downloading-the-data + * @param array $options + * @return stdClass + * @throws Exception + */ + public function retrieveExportData($options) + { + return $this->client->get("messages/data", $options); + } } From 12cf8ae336f1c25ad1bd426687f276c17108631a Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 10 Mar 2020 11:26:55 -0400 Subject: [PATCH 02/35] Fixed URLs for messages --- src/IntercomMessages.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php index d3ddb85..348e25e 100644 --- a/src/IntercomMessages.php +++ b/src/IntercomMessages.php @@ -30,7 +30,7 @@ public function create($options) */ public function createExport($options) { - return $this->client->post("messages/data", $options); + return $this->client->post("export/messages/data", $options); } /** @@ -43,7 +43,7 @@ public function createExport($options) */ public function retrieveExportStatus($options) { - return $this->client->get("messages/data", $options); + return $this->client->get("export/messages/data", $options); } /** @@ -58,6 +58,6 @@ public function retrieveExportStatus($options) */ public function retrieveExportData($options) { - return $this->client->get("messages/data", $options); + return $this->client->get("download/messages/data", $options); } } From 42b9d6a4d49ca0a9b61f47bb3f16b7282a733606 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 10 Mar 2020 12:41:49 -0400 Subject: [PATCH 03/35] Fixes for messages end point --- src/IntercomMessages.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php index 348e25e..fd028e5 100644 --- a/src/IntercomMessages.php +++ b/src/IntercomMessages.php @@ -37,27 +37,27 @@ public function createExport($options) * Retrieves Export Job Status * * @see https://developers.intercom.com/intercom-api-reference/reference#checking-the-status-of-the-job - * @param array $options + * @param string $job_identifier * @return stdClass * @throws Exception */ - public function retrieveExportStatus($options) + public function retrieveExportStatus($job_identifier) { - return $this->client->get("export/messages/data", $options); + return $this->client->get("export/messages/data/" . $job_identifier, []); } /** * Retrieves Export Job Data * - * Important: Intercom Clinet Accept Header must be application/octet-stream + * Important: The Intercom Client Accept Header must be application/octet-stream * * @see https://developers.intercom.com/intercom-api-reference/reference#downloading-the-data - * @param array $options + * @param string $job_identifier * @return stdClass * @throws Exception */ - public function retrieveExportData($options) + public function retrieveExportData($job_identifier) { - return $this->client->get("download/messages/data", $options); + return $this->client->get("download/messages/data/" . $job_identifier, []); } } From 19a20b369e9ae70645ef42fdf2325f2fa586edb1 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 17 Mar 2020 10:42:57 -0400 Subject: [PATCH 04/35] Conversation Search --- src/IntercomConversations.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/IntercomConversations.php b/src/IntercomConversations.php index fccee15..b2b908b 100644 --- a/src/IntercomConversations.php +++ b/src/IntercomConversations.php @@ -100,4 +100,18 @@ public function conversationReplyPath($id) { return 'conversations/' . $id . '/reply'; } + + /** + * Returns the results of a conversation search + * + * @param array $query + * @return stdClass + * @throws Exception + */ + + public function search($query) { + + $path = 'conversations/search'; + return $this->client->post($path, $query); + } } From 8f34502056a7e56351713d37632904552a828b32 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Thu, 16 Apr 2020 16:22:19 -0400 Subject: [PATCH 05/35] Companies --- src/IntercomCompanies.php | 2 +- src/IntercomConversations.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/IntercomCompanies.php b/src/IntercomCompanies.php index acae9ed..4965f7d 100644 --- a/src/IntercomCompanies.php +++ b/src/IntercomCompanies.php @@ -41,7 +41,7 @@ public function update($options) * @return stdClass * @throws Exception */ - public function getCompanies($options) + public function getCompanies($options = []) { return $this->client->get("companies", $options); } diff --git a/src/IntercomConversations.php b/src/IntercomConversations.php index b2b908b..7470fce 100644 --- a/src/IntercomConversations.php +++ b/src/IntercomConversations.php @@ -110,7 +110,6 @@ public function conversationReplyPath($id) */ public function search($query) { - $path = 'conversations/search'; return $this->client->post($path, $query); } From 0d972de5f4cc2b455918b0813b13c475bb7cf3dd Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 21 Apr 2020 15:35:08 -0400 Subject: [PATCH 06/35] Contact Attributes --- src/IntercomContacts.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 2d9ed2e..ca56834 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -61,6 +61,22 @@ public function getContact($id, $options = []) $path = $this->contactPath($id); return $this->client->get($path, $options); } + + /** + * Gets all data attributes for contacts + * + * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getContactAttributes($options = []) + { + $options = array_merge($options, ["model" => "contact"]); + + return $this->client->get('data_attributes', $options); + } /** * Deletes a single Contact based on the Intercom ID. From b0a1b616cf0167d96decface3a6a91e9483e2423 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 22 Apr 2020 15:15:03 -0400 Subject: [PATCH 07/35] Contacts Search --- src/IntercomContacts.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index ca56834..f075b0c 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -66,7 +66,6 @@ public function getContact($id, $options = []) * Gets all data attributes for contacts * * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact - * @param string $id * @param array $options * @return stdClass * @throws Exception @@ -77,6 +76,19 @@ public function getContactAttributes($options = []) return $this->client->get('data_attributes', $options); } + + /** + * Searches for contacts + * + * @see https://developers.intercom.com/intercom-api-reference/reference#search-for-contact + * @param array $options + * @return stdClass + * @throws Exception + */ + public function searchContacts($options = []) + { + return $this->client->post('contacts/search', $options); + } /** * Deletes a single Contact based on the Intercom ID. From 2b613bdfdf63fd4de5c1243b504ead6cfbb9f90a Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Mon, 27 Apr 2020 15:55:43 -0400 Subject: [PATCH 08/35] fixed contact update method --- src/IntercomContacts.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index f075b0c..d48aef8 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -29,9 +29,10 @@ public function create(array $options) * @return stdClass * @throws Exception */ - public function update(array $options) + public function update($id, $options = []) { - return $this->put($options); + $path = $this->contactPath($id); + return $this->put($path, $options); } /** From cbb6babcc9ff830de6aa3040e258667229d17a8c Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Mon, 27 Apr 2020 16:05:46 -0400 Subject: [PATCH 09/35] Contact update fix --- src/IntercomContacts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index d48aef8..d6c951a 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -32,7 +32,7 @@ public function create(array $options) public function update($id, $options = []) { $path = $this->contactPath($id); - return $this->put($path, $options); + return $this->client->put($path, $options); } /** From d52084e3c3034cb6a474c19c606ce52ed45eaae2 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 3 Jun 2020 08:54:18 -0400 Subject: [PATCH 10/35] Added Articles --- src/IntercomArticles.php | 88 ++++++++++++++++++++++++++++++++++++++++ src/IntercomClient.php | 1 + 2 files changed, 89 insertions(+) create mode 100644 src/IntercomArticles.php diff --git a/src/IntercomArticles.php b/src/IntercomArticles.php new file mode 100644 index 0000000..008b29e --- /dev/null +++ b/src/IntercomArticles.php @@ -0,0 +1,88 @@ +client->post("articles", $options); + } + + /** + * Gets a single Article based on the Article ID. + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#retrieve-an-article + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getArticle($id, $options = []) + { + $path = $this->articlePath($id); + return $this->client->get($path, $options); + } + + /** + * Updates an existing Article + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#update-an-article + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update($id, $options = []) + { + $path = $this->articlePath($id); + return $this->client->put($path, $options); + } + + /** + * Deletes a single article based on the Article ID. + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#delete-an-article + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function deleteArticle(string $id, array $options = []) + { + $path = $this->articlePath($id); + return $this->client->delete($path, $options); + } + + /** + * Lists Articles. + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#list-all-articles + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getArticles(array $options) + { + return $this->client->get('articles', $options); + } + + /** + * @param string $id + * @return string + */ + public function articlePath(string $id) + { + return 'articles/' . $id; + } +} diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 1e85ccd..01938d3 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -150,6 +150,7 @@ public function __construct(string $appIdOrToken, string $password = null, array $this->leads = new IntercomLeads($this); $this->visitors = new IntercomVisitors($this); $this->admins = new IntercomAdmins($this); + $this->articles = new IntercomArticles($this); $this->tags = new IntercomTags($this); $this->segments = new IntercomSegments($this); $this->counts = new IntercomCounts($this); From c75290970a173ad8cd5a5295e92f7e1a8621cb61 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 3 Jun 2020 16:17:04 -0400 Subject: [PATCH 11/35] Update IntercomArticles.php --- src/IntercomArticles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntercomArticles.php b/src/IntercomArticles.php index 008b29e..fc754bc 100644 --- a/src/IntercomArticles.php +++ b/src/IntercomArticles.php @@ -72,7 +72,7 @@ public function deleteArticle(string $id, array $options = []) * @return stdClass * @throws Exception */ - public function getArticles(array $options) + public function getArticles(array $options = []) { return $this->client->get('articles', $options); } From 966ab4a635f5eb758046211bcf6c4ca73ecd48a5 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 16 Jun 2020 14:10:12 -0400 Subject: [PATCH 12/35] Added tag options for contacts --- src/IntercomContacts.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index d6c951a..43595c7 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -105,6 +105,38 @@ public function deleteContact(string $id, array $options = []) $path = $this->contactPath($id); return $this->client->delete($path, $options); } + + /** + * Applys a tag to a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function addTag(string $id, string $tag_id) + { + $path = $this->contactPath($id); + + return $this->client->post($path.'/tag', ['id' => $tag_id]); + } + + /** + * Removes a tag from a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function removeTag(string $id, string $tag_id) + { + $path = $this->contactPath($id); + + return $this->client->delete($path.'/tag', ['id' => $tag_id]); + } /** * @param string $id From 3adef45b1b56bdfb7e54254ea21288144cacc82a Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 16 Jun 2020 14:20:03 -0400 Subject: [PATCH 13/35] Contact tag fix --- src/IntercomContacts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 43595c7..a715c0c 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -119,7 +119,7 @@ public function addTag(string $id, string $tag_id) { $path = $this->contactPath($id); - return $this->client->post($path.'/tag', ['id' => $tag_id]); + return $this->client->post($path.'/tags', ['id' => $tag_id]); } /** @@ -135,7 +135,7 @@ public function removeTag(string $id, string $tag_id) { $path = $this->contactPath($id); - return $this->client->delete($path.'/tag', ['id' => $tag_id]); + return $this->client->delete($path.'/tags', ['id' => $tag_id]); } /** From c73965c4c7425385f39781c7849eebe769a44aa6 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 10 Mar 2020 10:56:53 -0400 Subject: [PATCH 14/35] Added Contacts & Messages endpoints --- src/IntercomClient.php | 11 +++++++++++ src/IntercomContacts.php | 10 +++++++--- src/IntercomMessages.php | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/IntercomClient.php b/src/IntercomClient.php index f9532e8..bf3be78 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -58,6 +58,16 @@ class IntercomClient */ public $users; + /** + * @var IntercomContacts $contacts + */ + public $contacts; + + /** + * @var IntercomCustomers $customers + */ + public $customers; + /** * @var IntercomEvents $events */ @@ -144,6 +154,7 @@ public function __construct(string $appIdOrToken, string $password = null, array { $this->users = new IntercomUsers($this); $this->contacts = new IntercomContacts($this); + $this->customers = new IntercomCustomers($this); $this->events = new IntercomEvents($this); $this->companies = new IntercomCompanies($this); $this->messages = new IntercomMessages($this); diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 7cfc073..c4fef2e 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -1,5 +1,4 @@ contactPath($id); return $this->client->put($path, $options); - } /** * Lists Contacts. @@ -43,6 +45,7 @@ public function update(string $id, array $options) * @return stdClass * @throws Exception */ + public function getContacts(array $options = []) { return $this->client->get('contacts', $options); @@ -57,7 +60,8 @@ public function getContacts(array $options = []) * @return stdClass * @throws Exception */ - public function getContact(string $id, array $options = []) + + public function getContact($id, $options = []) { $path = $this->contactPath($id); return $this->client->get($path, $options); diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php index d4d9665..d3ddb85 100644 --- a/src/IntercomMessages.php +++ b/src/IntercomMessages.php @@ -19,4 +19,45 @@ public function create($options) { return $this->client->post("messages", $options); } + + /** + * Creates Message Export Job + * + * @see https://developers.intercom.com/intercom-api-reference/reference#creating-an-export-job + * @param array $options + * @return stdClass + * @throws Exception + */ + public function createExport($options) + { + return $this->client->post("messages/data", $options); + } + + /** + * Retrieves Export Job Status + * + * @see https://developers.intercom.com/intercom-api-reference/reference#checking-the-status-of-the-job + * @param array $options + * @return stdClass + * @throws Exception + */ + public function retrieveExportStatus($options) + { + return $this->client->get("messages/data", $options); + } + + /** + * Retrieves Export Job Data + * + * Important: Intercom Clinet Accept Header must be application/octet-stream + * + * @see https://developers.intercom.com/intercom-api-reference/reference#downloading-the-data + * @param array $options + * @return stdClass + * @throws Exception + */ + public function retrieveExportData($options) + { + return $this->client->get("messages/data", $options); + } } From 9a1fdeadae19920d9621c4ea23b0c02c67b58ad5 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 10 Mar 2020 11:26:55 -0400 Subject: [PATCH 15/35] Fixed URLs for messages --- src/IntercomMessages.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php index d3ddb85..348e25e 100644 --- a/src/IntercomMessages.php +++ b/src/IntercomMessages.php @@ -30,7 +30,7 @@ public function create($options) */ public function createExport($options) { - return $this->client->post("messages/data", $options); + return $this->client->post("export/messages/data", $options); } /** @@ -43,7 +43,7 @@ public function createExport($options) */ public function retrieveExportStatus($options) { - return $this->client->get("messages/data", $options); + return $this->client->get("export/messages/data", $options); } /** @@ -58,6 +58,6 @@ public function retrieveExportStatus($options) */ public function retrieveExportData($options) { - return $this->client->get("messages/data", $options); + return $this->client->get("download/messages/data", $options); } } From 074574ffa31d410a44ff5caaecbf96a30f3dc50c Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 10 Mar 2020 12:41:49 -0400 Subject: [PATCH 16/35] Fixes for messages end point --- src/IntercomMessages.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/IntercomMessages.php b/src/IntercomMessages.php index 348e25e..fd028e5 100644 --- a/src/IntercomMessages.php +++ b/src/IntercomMessages.php @@ -37,27 +37,27 @@ public function createExport($options) * Retrieves Export Job Status * * @see https://developers.intercom.com/intercom-api-reference/reference#checking-the-status-of-the-job - * @param array $options + * @param string $job_identifier * @return stdClass * @throws Exception */ - public function retrieveExportStatus($options) + public function retrieveExportStatus($job_identifier) { - return $this->client->get("export/messages/data", $options); + return $this->client->get("export/messages/data/" . $job_identifier, []); } /** * Retrieves Export Job Data * - * Important: Intercom Clinet Accept Header must be application/octet-stream + * Important: The Intercom Client Accept Header must be application/octet-stream * * @see https://developers.intercom.com/intercom-api-reference/reference#downloading-the-data - * @param array $options + * @param string $job_identifier * @return stdClass * @throws Exception */ - public function retrieveExportData($options) + public function retrieveExportData($job_identifier) { - return $this->client->get("download/messages/data", $options); + return $this->client->get("download/messages/data/" . $job_identifier, []); } } From 217e059b04891b229e88a5e293d8329925d9f3c4 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 17 Mar 2020 10:42:57 -0400 Subject: [PATCH 17/35] Conversation Search --- src/IntercomConversations.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/IntercomConversations.php b/src/IntercomConversations.php index 801cb37..05c5ad5 100644 --- a/src/IntercomConversations.php +++ b/src/IntercomConversations.php @@ -129,4 +129,18 @@ public function conversationReplyPath($id) { return 'conversations/' . $id . '/reply'; } + + /** + * Returns the results of a conversation search + * + * @param array $query + * @return stdClass + * @throws Exception + */ + + public function search($query) { + + $path = 'conversations/search'; + return $this->client->post($path, $query); + } } From 64a24e59177a4a78b432a58d8544606e089ed4b4 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Thu, 16 Apr 2020 16:22:19 -0400 Subject: [PATCH 18/35] Companies --- src/IntercomCompanies.php | 2 +- src/IntercomConversations.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/IntercomCompanies.php b/src/IntercomCompanies.php index e3256ad..c6404e4 100644 --- a/src/IntercomCompanies.php +++ b/src/IntercomCompanies.php @@ -74,7 +74,7 @@ public function detachContact(string $contactId, string $companyId, array $optio * @return stdClass * @throws Exception */ - public function getCompanies($options) + public function getCompanies($options = []) { return $this->client->get("companies", $options); } diff --git a/src/IntercomConversations.php b/src/IntercomConversations.php index 05c5ad5..845f39f 100644 --- a/src/IntercomConversations.php +++ b/src/IntercomConversations.php @@ -139,7 +139,6 @@ public function conversationReplyPath($id) */ public function search($query) { - $path = 'conversations/search'; return $this->client->post($path, $query); } From ef7029ed31d4195dd13acf675d5f4c19ff11eeae Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 21 Apr 2020 15:35:08 -0400 Subject: [PATCH 19/35] Contact Attributes --- src/IntercomContacts.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index c4fef2e..56b9a2a 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -66,6 +66,22 @@ public function getContact($id, $options = []) $path = $this->contactPath($id); return $this->client->get($path, $options); } + + /** + * Gets all data attributes for contacts + * + * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getContactAttributes($options = []) + { + $options = array_merge($options, ["model" => "contact"]); + + return $this->client->get('data_attributes', $options); + } /** * Permenently Deletes a single Contact based on the Intercom ID. From ddda8f640be86f4463faaf996eb6e0e4d76919f9 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 22 Apr 2020 15:15:03 -0400 Subject: [PATCH 20/35] Contacts Search --- src/IntercomContacts.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 56b9a2a..37bdcac 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -71,7 +71,6 @@ public function getContact($id, $options = []) * Gets all data attributes for contacts * * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact - * @param string $id * @param array $options * @return stdClass * @throws Exception @@ -82,6 +81,19 @@ public function getContactAttributes($options = []) return $this->client->get('data_attributes', $options); } + + /** + * Searches for contacts + * + * @see https://developers.intercom.com/intercom-api-reference/reference#search-for-contact + * @param array $options + * @return stdClass + * @throws Exception + */ + public function searchContacts($options = []) + { + return $this->client->post('contacts/search', $options); + } /** * Permenently Deletes a single Contact based on the Intercom ID. From 760ffcabe0bfdecf12f2d0f3bb41658363ea27c6 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Mon, 27 Apr 2020 15:55:43 -0400 Subject: [PATCH 21/35] fixed contact update method --- src/IntercomContacts.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 37bdcac..05fc8df 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -31,11 +31,19 @@ public function create(array $options) * @return stdClass * @throws Exception */ +<<<<<<< HEAD public function update(string $id, array $options) { $path = $this->contactPath($id); return $this->client->put($path, $options); +======= + public function update($id, $options = []) + { + $path = $this->contactPath($id); + return $this->put($path, $options); + } +>>>>>>> fixed contact update method /** * Lists Contacts. From 494c770d5078d6538e8fe390c55ffd613fd06724 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Mon, 27 Apr 2020 16:05:46 -0400 Subject: [PATCH 22/35] Contact update fix --- src/IntercomContacts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 05fc8df..aa79821 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -41,7 +41,7 @@ public function update(string $id, array $options) public function update($id, $options = []) { $path = $this->contactPath($id); - return $this->put($path, $options); + return $this->client->put($path, $options); } >>>>>>> fixed contact update method From 7c5bc593deec952b660e230b312f6bcccef684a7 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 3 Jun 2020 08:54:18 -0400 Subject: [PATCH 23/35] Added Articles --- src/IntercomArticles.php | 88 ++++++++++++++++++++++++++++++++++++++++ src/IntercomClient.php | 1 + 2 files changed, 89 insertions(+) create mode 100644 src/IntercomArticles.php diff --git a/src/IntercomArticles.php b/src/IntercomArticles.php new file mode 100644 index 0000000..008b29e --- /dev/null +++ b/src/IntercomArticles.php @@ -0,0 +1,88 @@ +client->post("articles", $options); + } + + /** + * Gets a single Article based on the Article ID. + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#retrieve-an-article + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getArticle($id, $options = []) + { + $path = $this->articlePath($id); + return $this->client->get($path, $options); + } + + /** + * Updates an existing Article + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#update-an-article + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update($id, $options = []) + { + $path = $this->articlePath($id); + return $this->client->put($path, $options); + } + + /** + * Deletes a single article based on the Article ID. + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#delete-an-article + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function deleteArticle(string $id, array $options = []) + { + $path = $this->articlePath($id); + return $this->client->delete($path, $options); + } + + /** + * Lists Articles. + * + * @see https://developers.intercom.com/intercom-api-reference/v0/reference#list-all-articles + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getArticles(array $options) + { + return $this->client->get('articles', $options); + } + + /** + * @param string $id + * @return string + */ + public function articlePath(string $id) + { + return 'articles/' . $id; + } +} diff --git a/src/IntercomClient.php b/src/IntercomClient.php index bf3be78..8d2690e 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -162,6 +162,7 @@ public function __construct(string $appIdOrToken, string $password = null, array $this->leads = new IntercomLeads($this); $this->visitors = new IntercomVisitors($this); $this->admins = new IntercomAdmins($this); + $this->articles = new IntercomArticles($this); $this->tags = new IntercomTags($this); $this->segments = new IntercomSegments($this); $this->counts = new IntercomCounts($this); From 5a1d17f704e5d0818ec6d50996a621f645227514 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 3 Jun 2020 16:17:04 -0400 Subject: [PATCH 24/35] Update IntercomArticles.php --- src/IntercomArticles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntercomArticles.php b/src/IntercomArticles.php index 008b29e..fc754bc 100644 --- a/src/IntercomArticles.php +++ b/src/IntercomArticles.php @@ -72,7 +72,7 @@ public function deleteArticle(string $id, array $options = []) * @return stdClass * @throws Exception */ - public function getArticles(array $options) + public function getArticles(array $options = []) { return $this->client->get('articles', $options); } From 52a8dabee9af43bb233723e648424bb2c033b121 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 16 Jun 2020 14:10:12 -0400 Subject: [PATCH 25/35] Added tag options for contacts --- src/IntercomContacts.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index aa79821..8eab0c8 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -117,6 +117,38 @@ public function deleteContact(string $id, array $options = []) $path = $this->contactPath($id); return $this->client->delete($path, $options); } + + /** + * Applys a tag to a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function addTag(string $id, string $tag_id) + { + $path = $this->contactPath($id); + + return $this->client->post($path.'/tag', ['id' => $tag_id]); + } + + /** + * Removes a tag from a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function removeTag(string $id, string $tag_id) + { + $path = $this->contactPath($id); + + return $this->client->delete($path.'/tag', ['id' => $tag_id]); + } /** * Returns list of Contacts that match search query. From f74810980ea04e0a15561b1c35d25f92cf685a40 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 16 Jun 2020 14:20:03 -0400 Subject: [PATCH 26/35] Contact tag fix --- src/IntercomContacts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 8eab0c8..7a2296f 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -131,7 +131,7 @@ public function addTag(string $id, string $tag_id) { $path = $this->contactPath($id); - return $this->client->post($path.'/tag', ['id' => $tag_id]); + return $this->client->post($path.'/tags', ['id' => $tag_id]); } /** @@ -147,7 +147,7 @@ public function removeTag(string $id, string $tag_id) { $path = $this->contactPath($id); - return $this->client->delete($path.'/tag', ['id' => $tag_id]); + return $this->client->delete($path.'/tags', ['id' => $tag_id]); } /** From de1ed0da7ebd82b79d45553feeb5d14d0a4baed2 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 2 Sep 2020 11:13:48 -0400 Subject: [PATCH 27/35] Added Contact Tagging --- src/IntercomContacts.php | 116 +++++++++------------------------------ 1 file changed, 26 insertions(+), 90 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 7de1f19..52afd6f 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -1,9 +1,4 @@ >>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a namespace Intercom; use Http\Client\Exception; @@ -25,13 +20,10 @@ public function create(array $options) } /** -<<<<<<< HEAD * Updates a Contact. * * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact * @param string $id -======= ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a * Updates an existing Contact * * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact @@ -39,25 +31,11 @@ public function create(array $options) * @return stdClass * @throws Exception */ -<<<<<<< HEAD -<<<<<<< HEAD public function update(string $id, array $options) { $path = $this->contactPath($id); return $this->client->put($path, $options); -======= -======= ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a - public function update($id, $options = []) - { - $path = $this->contactPath($id); - return $this->client->put($path, $options); - } -<<<<<<< HEAD ->>>>>>> fixed contact update method -======= ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a /** * Lists Contacts. @@ -67,12 +45,8 @@ public function update($id, $options = []) * @return stdClass * @throws Exception */ -<<<<<<< HEAD public function getContacts(array $options = []) -======= - public function getContacts(array $options) ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a { return $this->client->get('contacts', $options); } @@ -86,50 +60,15 @@ public function getContacts(array $options) * @return stdClass * @throws Exception */ -<<<<<<< HEAD -======= ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a public function getContact($id, $options = []) { $path = $this->contactPath($id); return $this->client->get($path, $options); } - - /** - * Gets all data attributes for contacts - * - * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact - * @param array $options - * @return stdClass - * @throws Exception - */ - public function getContactAttributes($options = []) - { - $options = array_merge($options, ["model" => "contact"]); - - return $this->client->get('data_attributes', $options); - } - - /** - * Searches for contacts - * - * @see https://developers.intercom.com/intercom-api-reference/reference#search-for-contact - * @param array $options - * @return stdClass - * @throws Exception - */ - public function searchContacts($options = []) - { - return $this->client->post('contacts/search', $options); - } /** -<<<<<<< HEAD * Permenently Deletes a single Contact based on the Intercom ID. -======= - * Deletes a single Contact based on the Intercom ID. ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a * * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact * @param string $id @@ -142,41 +81,40 @@ public function deleteContact(string $id, array $options = []) $path = $this->contactPath($id); return $this->client->delete($path, $options); } - - /** - * Applys a tag to a Contact based on the provided Tag ID - * - * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact - * @param string $id - * @param string $tag_id - * @return stdClass - * @throws Exception - */ - public function addTag(string $id, string $tag_id) - { + + /** + * Applys a tag to a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function addTag(string $id, string $tag_id) + { $path = $this->contactPath($id); - + return $this->client->post($path.'/tags', ['id' => $tag_id]); - } - - /** - * Removes a tag from a Contact based on the provided Tag ID - * - * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact - * @param string $id - * @param string $tag_id - * @return stdClass - * @throws Exception - */ - public function removeTag(string $id, string $tag_id) + } + + /** + * Removes a tag from a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function removeTag(string $id, string $tag_id) { $path = $this->contactPath($id); - + return $this->client->delete($path.'/tags', ['id' => $tag_id]); } /** -<<<<<<< HEAD * Returns list of Contacts that match search query. * * @see https://developers.intercom.com/reference#search-for-contacts @@ -221,8 +159,6 @@ public function nextCursor($pages) } /** -======= ->>>>>>> 3adef45b1b56bdfb7e54254ea21288144cacc82a * @param string $id * @return string */ From fd620d15d1bd68ffc70400911329ad78b41e4516 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 2 Sep 2020 11:21:41 -0400 Subject: [PATCH 28/35] Updated Doc URLs --- src/IntercomContacts.php | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 52afd6f..de3b1ba 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -82,32 +82,32 @@ public function deleteContact(string $id, array $options = []) return $this->client->delete($path, $options); } - /** - * Applys a tag to a Contact based on the provided Tag ID - * - * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact - * @param string $id - * @param string $tag_id - * @return stdClass - * @throws Exception - */ - public function addTag(string $id, string $tag_id) - { + /** + * Applys a tag to a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#tag-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function addTag(string $id, string $tag_id) + { $path = $this->contactPath($id); return $this->client->post($path.'/tags', ['id' => $tag_id]); - } - - /** - * Removes a tag from a Contact based on the provided Tag ID - * - * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact - * @param string $id - * @param string $tag_id - * @return stdClass - * @throws Exception - */ - public function removeTag(string $id, string $tag_id) + } + + /** + * Removes a tag from a Contact based on the provided Tag ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#untag-contact + * @param string $id + * @param string $tag_id + * @return stdClass + * @throws Exception + */ + public function removeTag(string $id, string $tag_id) { $path = $this->contactPath($id); From e8fc1be646a481e7a2de69fc94953d919dbcad58 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 2 Sep 2020 11:28:29 -0400 Subject: [PATCH 29/35] Various changes - Added Conversation Tagging - Minor bug fixes --- src/IntercomContacts.php | 2 ++ src/IntercomConversations.php | 47 +++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index de3b1ba..d9fdedf 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -35,7 +35,9 @@ public function create(array $options) public function update(string $id, array $options) { $path = $this->contactPath($id); + return $this->client->put($path, $options); + } /** * Lists Contacts. diff --git a/src/IntercomConversations.php b/src/IntercomConversations.php index 845f39f..2a70be6 100644 --- a/src/IntercomConversations.php +++ b/src/IntercomConversations.php @@ -108,6 +108,40 @@ public function markConversationAsRead($id) return $this->client->put($path, $data); } + /** + * Adds a tag to a Conversation based on the provided Tag and Admin ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#attach-a-tag-to-a-conversation + * @param string $id + * @param string $tagId + * @param string $adminId + * @return stdClass + */ + + public function addTag($id, $tagId, $adminId) { + + $path = $this->conversationPath($id); + + return $this->client->post($path.'/tags', ['id' => $tagId, 'admin' => $adminId]); + } + + /** + * Removes a tag to a Conversation based on the provided Tag and Admin ID + * + * @see https://developers.intercom.com/intercom-api-reference/reference#attach-a-tag-to-a-conversation + * @param string $id + * @param string $tagId + * @param string $adminId + * @return stdClass + */ + + public function removeTag($id, $tagId) { + + $path = $this->conversationPath($id); + + return $this->client->delete($path.'/tags', ['id' => $tagId]); + } + /** * Returns endpoint path to Conversation with given ID. * @@ -129,17 +163,4 @@ public function conversationReplyPath($id) { return 'conversations/' . $id . '/reply'; } - - /** - * Returns the results of a conversation search - * - * @param array $query - * @return stdClass - * @throws Exception - */ - - public function search($query) { - $path = 'conversations/search'; - return $this->client->post($path, $query); - } } From 027baf1eb05ecf613d2bbb6e699b6efc0dbf3ff8 Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Thu, 10 Sep 2020 15:06:59 -0400 Subject: [PATCH 30/35] Fixes for pull/314 - Updated Readme (Contacts & Articles) - Fixed strong typing - Various fixes as per pull/314 --- README.md | 25 +++++++++++++++++++++++++ src/IntercomArticles.php | 12 ++++++------ src/IntercomContacts.php | 33 ++++++++++++++++++++------------- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7acab69..abc4884 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,12 @@ $client->contacts->nextSearch($query, $response->pages); /** List all contacts */ $client->contacts->getContacts([]); + +/** Tag a Contact */ +$client->contacts->addTag("570680a8a1bcbca8a90001b9", "2084335"); + +/** Remove a Tag from a Contact */ +$client->contacts->removeTag("570680a8a1bcbca8a90001b9", "2084335"); ``` ## Users @@ -489,6 +495,25 @@ $client->teams->getTeams(); $client->teams->getTeam("1188"); ``` +## Articles + +```php +/** Create an Article */ +$client->articles->create(["title" => "How To Use the Intercom API", "description" => "A quick guide to the universe of the Intercom API", "body" => "

This is the body in html

", "author_id" => 1]); + +/** Retrieve an Article */ +$client->articles->getArticle("123456"); + +/** Update an Article */ +$client->articles->update("123456", ["title" => "How To Use the Intercom API", "description" => "A quick guide to the universe of the Intercom API", "body" => "

This is the body in html

"); + +/** Delete an Article */ +$client->articles->deleteArticle("123456"); + +/** List Articles */ +$client->articles->getArticles(); +``` + ## Rate Limits diff --git a/src/IntercomArticles.php b/src/IntercomArticles.php index fc754bc..9b8027c 100644 --- a/src/IntercomArticles.php +++ b/src/IntercomArticles.php @@ -19,7 +19,7 @@ public function create(array $options) { return $this->client->post("articles", $options); } - + /** * Gets a single Article based on the Article ID. * @@ -29,7 +29,7 @@ public function create(array $options) * @return stdClass * @throws Exception */ - public function getArticle($id, $options = []) + public function getArticle(string $id, array $options = []) { $path = $this->articlePath($id); return $this->client->get($path, $options); @@ -39,16 +39,16 @@ public function getArticle($id, $options = []) * Updates an existing Article * * @see https://developers.intercom.com/intercom-api-reference/v0/reference#update-an-article - * @param array $options + * @param string $id + * @param array $options * @return stdClass - * @throws Exception */ - public function update($id, $options = []) + public function update(string $id, array $options = []) { $path = $this->articlePath($id); return $this->client->put($path, $options); } - + /** * Deletes a single article based on the Article ID. * diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index d9fdedf..2df41ea 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -20,10 +20,6 @@ public function create(array $options) } /** - * Updates a Contact. - * - * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact - * @param string $id * Updates an existing Contact * * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact @@ -63,7 +59,7 @@ public function getContacts(array $options = []) * @throws Exception */ - public function getContact($id, $options = []) + public function getContact(string $id, array $options = []) { $path = $this->contactPath($id); return $this->client->get($path, $options); @@ -89,15 +85,15 @@ public function deleteContact(string $id, array $options = []) * * @see https://developers.intercom.com/intercom-api-reference/reference#tag-contact * @param string $id - * @param string $tag_id + * @param string $tagId * @return stdClass * @throws Exception */ - public function addTag(string $id, string $tag_id) + public function addTag(string $id, string $tagId) { - $path = $this->contactPath($id); + $path = $this->contactTagsPath($id); - return $this->client->post($path.'/tags', ['id' => $tag_id]); + return $this->client->post($path, ['id' => $tagId]); } /** @@ -105,15 +101,15 @@ public function addTag(string $id, string $tag_id) * * @see https://developers.intercom.com/intercom-api-reference/reference#untag-contact * @param string $id - * @param string $tag_id + * @param string $tagId * @return stdClass * @throws Exception */ - public function removeTag(string $id, string $tag_id) + public function removeTag(string $id, string $tagId) { - $path = $this->contactPath($id); + $path = $this->contactTagsPath($id); - return $this->client->delete($path.'/tags', ['id' => $tag_id]); + return $this->client->delete($path, ['id' => $tagId]); } /** @@ -168,4 +164,15 @@ public function contactPath(string $id) { return 'contacts/' . $id; } + + /** + * Returns the path for adding/removing a tag for a given contact + * + * @param string $id Contact ID + * @return string + */ + public function contactTagsPath(string $id) + { + return 'contacts/' . $id . '/tags'; + } } From 484a7d86df4cfcefe6a35978974ebcf652ebae24 Mon Sep 17 00:00:00 2001 From: MCKLtech Date: Sat, 3 Oct 2020 12:34:07 -0400 Subject: [PATCH 31/35] Update IntercomClient.php - Duplicated Contacts declaration --- src/IntercomClient.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 8d2690e..8fc43e4 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -78,11 +78,6 @@ class IntercomClient */ public $companies; - /** - * @var IntercomContacts $contacts - */ - public $contacts; - /** * @var IntercomMessages $messages */ From 14f8bfaac7c6306ea3278fb015261d6ad4403a84 Mon Sep 17 00:00:00 2001 From: MCKLtech Date: Sat, 3 Oct 2020 12:56:27 -0400 Subject: [PATCH 32/35] Update IntercomClient.php - Removed IntercomCustomers --- src/IntercomClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 8fc43e4..b6e39bf 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -66,7 +66,7 @@ class IntercomClient /** * @var IntercomCustomers $customers */ - public $customers; + //public $customers; /** * @var IntercomEvents $events @@ -149,7 +149,7 @@ public function __construct(string $appIdOrToken, string $password = null, array { $this->users = new IntercomUsers($this); $this->contacts = new IntercomContacts($this); - $this->customers = new IntercomCustomers($this); + //$this->customers = new IntercomCustomers($this); $this->events = new IntercomEvents($this); $this->companies = new IntercomCompanies($this); $this->messages = new IntercomMessages($this); From af555c68056fe9208c6c7dd054aad6ed42e9f304 Mon Sep 17 00:00:00 2001 From: MCKLtech Date: Tue, 20 Oct 2020 11:35:13 -0400 Subject: [PATCH 33/35] Update IntercomContacts.php - Added getAttributes to Contacts --- src/IntercomContacts.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index 2df41ea..eda7ee4 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -125,6 +125,21 @@ public function search(array $options) $path = 'contacts/search'; return $this->client->post($path, $options); } + + /** + * Gets all data attributes for the Contact model + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-data-attributes + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getAttributes($options = []) + { + $options = array_merge($options, ["model" => "contact"]); + + return $this->client->get('data_attributes', $options); + } /** * Returns next page of Contacts that match search query. From d5ca224a04e64d40acaef1644fa130ab9e86052d Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Wed, 24 Feb 2021 09:18:46 -0500 Subject: [PATCH 34/35] Added Data Attribute End Points --- src/IntercomClient.php | 11 +++--- src/IntercomDataAttributes.php | 63 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 src/IntercomDataAttributes.php diff --git a/src/IntercomClient.php b/src/IntercomClient.php index b6e39bf..3470ecb 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -63,11 +63,6 @@ class IntercomClient */ public $contacts; - /** - * @var IntercomCustomers $customers - */ - //public $customers; - /** * @var IntercomEvents $events */ @@ -78,6 +73,11 @@ class IntercomClient */ public $companies; + /** + * @var IntercomDataAttributes $dataAttributes + */ + public $dataAttributes; + /** * @var IntercomMessages $messages */ @@ -152,6 +152,7 @@ public function __construct(string $appIdOrToken, string $password = null, array //$this->customers = new IntercomCustomers($this); $this->events = new IntercomEvents($this); $this->companies = new IntercomCompanies($this); + $this->dataAttributes = new IntercomDataAttributes($this); $this->messages = new IntercomMessages($this); $this->conversations = new IntercomConversations($this); $this->leads = new IntercomLeads($this); diff --git a/src/IntercomDataAttributes.php b/src/IntercomDataAttributes.php new file mode 100644 index 0000000..28177ad --- /dev/null +++ b/src/IntercomDataAttributes.php @@ -0,0 +1,63 @@ +client->post($this->dataAttributePath(), $options); + } + + /** + * Updates a Data Attribute + * + * @see https://developers.intercom.com/intercom-api-reference/reference#update-data-attributes + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update(array $options) + { + return $this->client->put($this->dataAttributePath(), $options); + } + + /** + * List all data attributes + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-data-attributes + * @param string $model + * @param bool $include_archived + * @return stdClass + */ + public function list(string $model = 'contact', bool $include_archived = false ) + { + $options = [ + 'model' => $model, + 'include_archived' => $include_archived + ]; + + return $this->client->get($this->dataAttributePath(), $options); + } + + /** + * @param string $id + * @return string + */ + public function dataAttributePath() + { + return 'data_attributes'; + } + +} From 2bd694dd6ac04d1e5a90154e0ebb0b979bd1c15a Mon Sep 17 00:00:00 2001 From: Colin Longworth Date: Tue, 6 Apr 2021 12:30:33 -0400 Subject: [PATCH 35/35] Update IntercomContacts.php - Added Listing for Tags, Segments & Companies --- src/IntercomContacts.php | 73 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/IntercomContacts.php b/src/IntercomContacts.php index eda7ee4..2f3f4a2 100644 --- a/src/IntercomContacts.php +++ b/src/IntercomContacts.php @@ -80,6 +80,21 @@ public function deleteContact(string $id, array $options = []) return $this->client->delete($path, $options); } + /** + * List attached tags + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-tags-of-contact + * @param string $id + * @return stdClass + * @throws Exception + */ + public function tags(string $id) + { + $path = $this->contactTagsPath($id); + + return $this->client->get($path); + } + /** * Applys a tag to a Contact based on the provided Tag ID * @@ -112,6 +127,36 @@ public function removeTag(string $id, string $tagId) return $this->client->delete($path, ['id' => $tagId]); } + /** + * List attached segments + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-attached-segments + * @param string $id + * @return stdClass + * @throws Exception + */ + public function segments(string $id) + { + $path = $this->contactSegmentsPath($id); + + return $this->client->get($path); + } + + /** + * List attached companies + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-companies-of-contact + * @param string $id + * @return stdClass + * @throws Exception + */ + public function companies(string $id) + { + $path = $this->contactCompaniesPath($id); + + return $this->client->get($path); + } + /** * Returns list of Contacts that match search query. * @@ -125,7 +170,7 @@ public function search(array $options) $path = 'contacts/search'; return $this->client->post($path, $options); } - + /** * Gets all data attributes for the Contact model * @@ -181,7 +226,7 @@ public function contactPath(string $id) } /** - * Returns the path for adding/removing a tag for a given contact + * Returns the path for viewing/adding/removing a tag for a given contact * * @param string $id Contact ID * @return string @@ -190,4 +235,28 @@ public function contactTagsPath(string $id) { return 'contacts/' . $id . '/tags'; } + + /** + * Returns the path for viewing segments for a given contact + * + * @param string $id Contact ID + * @return string + */ + public function contactSegmentsPath(string $id) + { + return 'contacts/' . $id . '/segments'; + } + + /** + * Returns the path for viewing companies for a given contact + * + * @param string $id Contact ID + * @return string + */ + public function contactCompaniesPath(string $id) + { + return 'contacts/' . $id . '/companies'; + } + + }