Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact & Conversation Tagging / Articles / Messages #314

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a5d433
Added Contacts & Messages endpoints
Mar 10, 2020
12cf8ae
Fixed URLs for messages
Mar 10, 2020
42b9d6a
Fixes for messages end point
Mar 10, 2020
19a20b3
Conversation Search
Mar 17, 2020
8f34502
Companies
Apr 16, 2020
0d972de
Contact Attributes
Apr 21, 2020
b0a1b61
Contacts Search
Apr 22, 2020
2b613bd
fixed contact update method
Apr 27, 2020
cbb6bab
Contact update fix
Apr 27, 2020
d52084e
Added Articles
Jun 3, 2020
c752909
Update IntercomArticles.php
Jun 3, 2020
966ab4a
Added tag options for contacts
Jun 16, 2020
3adef45
Contact tag fix
Jun 16, 2020
c73965c
Added Contacts & Messages endpoints
Mar 10, 2020
9a1fdea
Fixed URLs for messages
Mar 10, 2020
074574f
Fixes for messages end point
Mar 10, 2020
217e059
Conversation Search
Mar 17, 2020
64a24e5
Companies
Apr 16, 2020
ef7029e
Contact Attributes
Apr 21, 2020
ddda8f6
Contacts Search
Apr 22, 2020
760ffca
fixed contact update method
Apr 27, 2020
494c770
Contact update fix
Apr 27, 2020
7c5bc59
Added Articles
Jun 3, 2020
5a1d17f
Update IntercomArticles.php
Jun 3, 2020
52a8dab
Added tag options for contacts
Jun 16, 2020
f748109
Contact tag fix
Jun 16, 2020
eaa8f78
Update IntercomContacts.php
Sep 2, 2020
de1ed0d
Added Contact Tagging
Sep 2, 2020
fd620d1
Updated Doc URLs
Sep 2, 2020
e8fc1be
Various changes
Sep 2, 2020
027baf1
Fixes for pull/314
Sep 10, 2020
484a7d8
Update IntercomClient.php
MCKLtech Oct 3, 2020
14f8bfa
Update IntercomClient.php
MCKLtech Oct 3, 2020
af555c6
Update IntercomContacts.php
MCKLtech Oct 20, 2020
d5ca224
Added Data Attribute End Points
Feb 24, 2021
2bd694d
Update IntercomContacts.php
Apr 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" => "<p>This is the body in html</p>", "author_id" => 1]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to split this into multiple lines:

Suggested change
$client->articles->create(["title" => "How To Use the Intercom API", "description" => "A quick guide to the universe of the Intercom API", "body" => "<p>This is the body in html</p>", "author_id" => 1]);
$client->articles->create([
"title" => "How To Use the Intercom API",
"description" => "A quick guide to the universe of the Intercom API",
"body" => "<p>This is the body in html</p>",
"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" => "<p>This is the body in html</p>");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here 😃

Suggested change
$client->articles->update("123456", ["title" => "How To Use the Intercom API", "description" => "A quick guide to the universe of the Intercom API", "body" => "<p>This is the body in html</p>");
$client->articles->update(
"123456",
[
"title" => "How To Use the Intercom API",
"description" => "A quick guide to the universe of the Intercom API",
"body" => "<p>This is the body in html</p>",
]
);


/** Delete an Article */
$client->articles->deleteArticle("123456");

/** List Articles */
$client->articles->getArticles();
```


## Rate Limits

Expand Down
88 changes: 88 additions & 0 deletions src/IntercomArticles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Intercom;

use Http\Client\Exception;
use stdClass;

class IntercomArticles extends IntercomResource
{
/**
* Creates an Article.
*
* @see https://developers.intercom.com/intercom-api-reference/v0/reference#create-an-article
* @param array $options
* @return stdClass
* @throws Exception
*/
public function create(array $options)
{
return $this->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(string $id, array $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 string $id
* @param array $options
* @return stdClass
*/
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.
*
* @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;
}
}
17 changes: 12 additions & 5 deletions src/IntercomClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ class IntercomClient
*/
public $users;

/**
* @var IntercomContacts $contacts
*/
public $contacts;

/**
* @var IntercomCustomers $customers
*/
//public $customers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is work in progress, but wanted to add a reminder that this and its initializer are commented out 😄


/**
* @var IntercomEvents $events
*/
Expand All @@ -68,11 +78,6 @@ class IntercomClient
*/
public $companies;

/**
* @var IntercomContacts $contacts
*/
public $contacts;

/**
* @var IntercomMessages $messages
*/
Expand Down Expand Up @@ -144,13 +149,15 @@ 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);
$this->conversations = new IntercomConversations($this);
$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);
Expand Down
2 changes: 1 addition & 1 deletion src/IntercomCompanies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
51 changes: 48 additions & 3 deletions src/IntercomContacts.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Intercom;

use Http\Client\Exception;
Expand All @@ -21,17 +20,18 @@ public function create(array $options)
}

/**
* Updates a Contact.
* Updates an existing Contact
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems these lines are a bit off 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops. Fixing

*
* @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);
}

Expand All @@ -43,6 +43,7 @@ public function update(string $id, array $options)
* @return stdClass
* @throws Exception
*/

public function getContacts(array $options = [])
{
return $this->client->get('contacts', $options);
Expand All @@ -57,6 +58,7 @@ public function getContacts(array $options = [])
* @return stdClass
* @throws Exception
*/

public function getContact(string $id, array $options = [])
{
$path = $this->contactPath($id);
Expand All @@ -78,6 +80,38 @@ 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#tag-contact
* @param string $id
* @param string $tagId
* @return stdClass
* @throws Exception
*/
public function addTag(string $id, string $tagId)
{
$path = $this->contactTagsPath($id);

return $this->client->post($path, ['id' => $tagId]);
}

/**
* 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 $tagId
* @return stdClass
* @throws Exception
*/
public function removeTag(string $id, string $tagId)
{
$path = $this->contactTagsPath($id);

return $this->client->delete($path, ['id' => $tagId]);
}

/**
* Returns list of Contacts that match search query.
*
Expand Down Expand Up @@ -130,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';
}
}
34 changes: 34 additions & 0 deletions src/IntercomConversations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
41 changes: 41 additions & 0 deletions src/IntercomMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,45 @@ public function create($options)
{
return $this->client->post("messages", $options);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message export feature is on the Unstable version at the moment and is subject to changes, so I am not sure if we want to add something not stable to the SDK 🤔 @mmartinic @murtron what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We actually use it in a production system at the moment hence why we built it.

Move to a beta branch or something?

/**
* 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("export/messages/data", $options);
}

/**
* Retrieves Export Job Status
*
* @see https://developers.intercom.com/intercom-api-reference/reference#checking-the-status-of-the-job
* @param string $job_identifier
* @return stdClass
* @throws Exception
*/
public function retrieveExportStatus($job_identifier)
{
return $this->client->get("export/messages/data/" . $job_identifier, []);
}

/**
* Retrieves Export Job Data
*
* Important: The Intercom Client Accept Header must be application/octet-stream
*
* @see https://developers.intercom.com/intercom-api-reference/reference#downloading-the-data
* @param string $job_identifier
* @return stdClass
* @throws Exception
*/
public function retrieveExportData($job_identifier)
{
return $this->client->get("download/messages/data/" . $job_identifier, []);
}
}