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 1 commit
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
12 changes: 6 additions & 6 deletions src/IntercomArticles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function create(array $options)
{
return $this->client->post("articles", $options);
}

/**
* Gets a single Article based on the Article ID.
*
Expand All @@ -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);
Expand All @@ -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.
*
Expand Down
33 changes: 20 additions & 13 deletions src/IntercomContacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Expand Down Expand Up @@ -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);
Expand All @@ -89,31 +85,31 @@ 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]);
}

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

/**
Expand Down Expand Up @@ -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';
}
}