Skip to content

Commit dffd960

Browse files
authored
Merge pull request #517 from WaKeMaTTa/conversation-add-remove-nested-contact
[feature] Conversation : Add/remove nested resource 'contact'
2 parents fb84544 + 5e25a20 commit dffd960

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

README.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Resources this API supports:
6161
https://api.intercom.io/counts
6262
https://api.intercom.io/subscriptions
6363
https://api.intercom.io/jobs
64-
64+
6565

6666
### Examples
6767

@@ -99,7 +99,7 @@ contacts = intercom.contacts.search(
9999
}
100100
)
101101
contacts.each {|c| p c.email}
102-
# For full detail on possible queries, please refer to the API documentation:
102+
# For full detail on possible queries, please refer to the API documentation:
103103
# https://developers.intercom.com/intercom-api-reference/reference
104104

105105
# Merge a lead into an existing user
@@ -191,7 +191,7 @@ intercom.data_attributes.save(attribute)
191191
attribute.archived = true
192192
intercom.data_attributes.save(attribute)
193193

194-
# Find all customer attributes including archived
194+
# Find all customer attributes including archived
195195
customer_attributes_incl_archived = intercom.data_attributes.find_all({"model": "contact", "include_archived": true})
196196
customer_attributes_incl_archived.each { |attr| p attribute.name }
197197
```
@@ -321,7 +321,7 @@ conversation.statistics.time_to_admin_reply
321321
conversation.statistics.last_assignment_at
322322

323323
# Get information on the sla applied to a conversation
324-
conversation.sla_applied.sla_name
324+
conversation.sla_applied.sla_name
325325

326326
# REPLYING TO CONVERSATIONS
327327
# User (identified by email) replies with a comment
@@ -370,9 +370,9 @@ intercom.conversations.mark_read(conversation.id)
370370
intercom.conversations.run_assignment_rules(conversation.id)
371371

372372
# Search for conversations
373-
# For full detail on possible queries, please refer to the API documentation:
374-
# https://developers.intercom.com/intercom-api-reference/reference
375-
373+
# For full detail on possible queries, please refer to the API documentation:
374+
# https://developers.intercom.com/intercom-api-reference/reference
375+
376376
# Search for open conversations sorted by the created_at date
377377
conversations = intercom.conversations.search(
378378
query: {
@@ -386,18 +386,23 @@ conversations = intercom.conversations.search(
386386
conversations.each {|c| p c.id}
387387

388388
# Tagging for conversations
389-
tag = intercom.tags.find(id: "2")
389+
tag = intercom.tags.find(id: "2")
390390
conversation = intercom.conversations.find(id: "1")
391391

392392
# An Admin ID is required to add or remove tag on a conversation
393-
admin = intercom.admins.find(id: "1")
393+
admin = intercom.admins.find(id: "1")
394394

395395
# Add a tag to a conversation
396396
conversation.add_tag(id: tag.id, admin_id: admin.id)
397397

398398
# Remove a tag from a conversation
399399
conversation.remove_tag(id: tag.id, admin_id: admin.id)
400-
400+
401+
# Add a contact to a conversation
402+
conversation.add_contact(admin_id: admin.id, customer: { intercom_user_id: contact.id })
403+
404+
# Remove a contact from a conversation
405+
conversation.remove_contact(id: contact.id, admin_id: admin.id)
401406
```
402407

403408
#### Full loading of an embedded entity

lib/intercom/conversation.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class Conversation
77
include ApiOperations::NestedResource
88

99
nested_resource_methods :tag, operations: %i[add delete]
10+
nested_resource_methods :contact, operations: %i[add delete], path: :customers
1011
end
1112
end

spec/unit/intercom/conversation_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,31 @@
8181
client.expects(:delete).with("/conversations/1/tags/1", { "id": tag.id }).returns(nil)
8282
_(proc { conversation.remove_tag({ "id": tag.id }) }).must_raise Intercom::HttpError
8383
end
84+
85+
describe 'contacts' do
86+
let(:response) do
87+
{
88+
customers: [
89+
{ type: test_contact['type'], id: test_contact['id'] }
90+
]
91+
}
92+
end
93+
94+
it 'adds a contact to a conversation' do
95+
client.expects(:post)
96+
.with("/conversations/1/customers",
97+
{ admin_id: test_admin['id'], customer: { intercom_user_id: test_contact['id'] } })
98+
.returns(response.to_hash)
99+
conversation.add_contact(admin_id: test_admin['id'], customer: { intercom_user_id: test_contact['id'] })
100+
end
101+
102+
it 'removes a contact from a conversation' do
103+
client.expects(:delete)
104+
.with("/conversations/1/customers/aaaaaaaaaaaaaaaaaaaaaaaa",
105+
{ id: 'aaaaaaaaaaaaaaaaaaaaaaaa', admin_id: '1234' })
106+
.returns(response.to_hash)
107+
conversation.remove_contact(id: test_contact['id'], admin_id: test_admin['id'])
108+
end
109+
end
84110
end
85111
end

0 commit comments

Comments
 (0)