Skip to content

Commit 38fee00

Browse files
luoshibenmmartinic
authored andcommitted
add missing conversations calls (#186)
* Update IntercomConversations, add missing route support Add support for replying to user's last conversation and also marking a conversation as read * update IntercomClient, add put support Add HTTP PUT method support to IntercomClient * update README with new conversations methods update README with usage examples on replyToLastConversation() and markConversationAsRead() * formatting fix * add createMessage to IntercomConversations implement message creation and make IntercomConversations interface backwards compatible with previous versions of intercom/intercom-php * remove createMessage on IntercomConversations duplicate functionality; createMessage exists on IntercomMessages * Update IntercomUsers.php
1 parent 8e56d7c commit 38fee00

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@ $client->conversations->replyToConversation("5678", [
209209
"type" => "user",
210210
"message_type" => "comment"
211211
]);
212+
213+
//Reply to a user's last conversation
214+
// See more options here: https://developers.intercom.com/reference#replying-to-users-last-conversation
215+
$client->conversations->replyToLastConversation([
216+
"email" => "[email protected]",
217+
"body" => "Thanks :)",
218+
"type" => "user",
219+
"message_type" => "comment"
220+
]);
221+
222+
// Mark a conversation as read
223+
// See API documentation here: https://developers.intercom.io/reference#marking-a-conversation-as-read
224+
$client->conversations->markConversationAsRead("7890");
212225
```
213226

214227
## Counts

src/IntercomClient.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ public function post($endpoint, $json)
110110
]);
111111
return $this->handleResponse($response);
112112
}
113+
114+
/**
115+
* Sends PUT request to Intercom API.
116+
* @param string $endpoint
117+
* @param string $json
118+
* @return mixed
119+
* @throws \GuzzleHttp\Exception\GuzzleException
120+
*/
121+
public function put($endpoint, $json)
122+
{
123+
$response = $this->http_client->request('PUT', "https://api.intercom.io/$endpoint", [
124+
'json' => $json,
125+
'auth' => $this->getAuth(),
126+
'headers' => [
127+
'Accept' => 'application/json'
128+
]
129+
]);
130+
return $this->handleResponse($response);
131+
}
113132

114133
/**
115134
* Sends DELETE request to Intercom API.

src/IntercomConversations.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct($client)
2525
*/
2626
public function getConversations($options)
2727
{
28-
return $this->client->get("conversations", $options);
28+
return $this->client->get('conversations', $options);
2929
}
3030

3131
/**
@@ -52,15 +52,40 @@ public function replyToConversation($id, $options) {
5252
$path = $this->conversationReplyPath($id);
5353
return $this->client->post($path, $options);
5454
}
55-
55+
56+
/**
57+
* Creates Conversation Reply to last conversation. (no need to specify Conversation ID.)
58+
* @see https://developers.intercom.io/reference#replying-to-users-last-conversation
59+
* @param array $options
60+
* @return mixed
61+
* @throws \GuzzleHttp\Exception\GuzzleException
62+
*/
63+
public function replyToLastConversation($options) {
64+
$path = 'conversations/last/reply';
65+
return $this->client->post($path, $options);
66+
}
67+
68+
/**
69+
* Marks a Conversation as read based on the given Conversation ID.
70+
* @see https://developers.intercom.io/reference#marking-a-conversation-as-read
71+
* @param string $id
72+
* @return mixed
73+
* @throws \GuzzleHttp\Exception\GuzzleException
74+
*/
75+
public function markConversationAsRead($id) {
76+
$path = $this->conversationPath($id);
77+
$data = ['read' => true];
78+
return $this->client->put($path, $data);
79+
}
80+
5681
/**
5782
* Returns endpoint path to Conversation with given ID.
5883
* @param string $id
5984
* @return string
6085
*/
6186
public function conversationPath($id)
6287
{
63-
return "conversations/" . $id;
88+
return 'conversations/' . $id;
6489
}
6590

6691
/**
@@ -70,6 +95,6 @@ public function conversationPath($id)
7095
*/
7196
public function conversationReplyPath($id)
7297
{
73-
return "conversations/" . $id . "/reply";
98+
return 'conversations/' . $id . '/reply';
7499
}
75100
}

src/IntercomUsers.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,43 @@ public function create($options)
3737
*/
3838
public function getUsers($options)
3939
{
40-
return $this->client->get("users", $options);
40+
return $this->client->get('users', $options);
4141
}
4242

43+
/**
44+
* Gets a single User based on the Intercom ID.
45+
* @see https://developers.intercom.com/reference#view-a-user
46+
* @param integer $id
47+
* @param array $options
48+
* @return mixed
49+
* @throws \GuzzleHttp\Exception\GuzzleException
50+
*/
4351
public function getUser($id, $options = [])
4452
{
4553
$path = $this->userPath($id);
4654
return $this->client->get($path, $options);
4755
}
56+
57+
/**
58+
* Gets a list of Users through the user scroll API.
59+
* @see https://developers.intercom.com/reference#iterating-over-all-users
60+
* @param array $options
61+
* @return mixed
62+
* @throws \GuzzleHttp\Exception\GuzzleException
63+
*/
64+
public function scrollUsers($options = [])
65+
{
66+
return $this->client->get('users/scroll', $options);
67+
}
4868

69+
/**
70+
* Deletes a single User based on the Intercom ID.
71+
* @see https://developers.intercom.com/reference#delete-a-user
72+
* @param integer $id
73+
* @param array $options
74+
* @return mixed
75+
* @throws \GuzzleHttp\Exception\GuzzleException
76+
*/
4977
public function deleteUser($id, $options = [])
5078
{
5179
$path = $this->userPath($id);
@@ -54,6 +82,6 @@ public function deleteUser($id, $options = [])
5482

5583
public function userPath($id)
5684
{
57-
return "users/" . $id;
85+
return 'users/' . $id;
5886
}
5987
}

0 commit comments

Comments
 (0)