Skip to content

Commit 3f8c927

Browse files
committed
Merge pull request #183 from intercom/jo/assign-reply-open
wip assign open close
2 parents 82339f4 + 9eeab74 commit 3f8c927

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,23 @@ conversation.conversation_parts[1].body
175175
# REPLYING TO CONVERSATIONS
176176
# User (identified by email) replies with a comment
177177
intercom.conversations.reply(:id => conversation.id, :type => 'user', :email => 'joe@example.com', :message_type => 'comment', :body => 'foo')
178-
# Admin (identified by email) replies with a comment
179-
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :email => 'bob@example.com', :message_type => 'comment', :body => 'bar')
178+
# Admin (identified by id) replies with a comment
179+
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :admin_id => '123', :message_type => 'comment', :body => 'bar')
180+
181+
# Open
182+
intercom.conversations.open(id: conversation.id, admin_id: '123')
183+
184+
# Close
185+
intercom.conversations.close(id: conversation.id, admin_id: '123')
186+
187+
# Assign
188+
intercom.conversations.assign(id: conversation.id, admin_id: '123', assignee_id: '124')
189+
190+
# Reply and Open
191+
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :admin_id => '123', :message_type => 'open', :body => 'bar')
192+
193+
# Reply and Close
194+
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :admin_id => '123', :message_type => 'close', :body => 'bar')
180195

181196
# ASSIGNING CONVERSATIONS TO ADMINS
182197
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :assignee_id => assignee_admin.id, :admin_id => admin.id, :message_type => 'assignment')

lib/intercom/service/conversation.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ def reply(reply_data)
2626
response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(:conversation_id => id))
2727
collection_class.new.from_response(response)
2828
end
29+
30+
def open(reply_data)
31+
reply reply_data.merge(message_type: 'open', type: 'admin')
32+
end
33+
34+
def close(reply_data)
35+
reply reply_data.merge(message_type: 'close', type: 'admin')
36+
end
37+
38+
def assign(reply_data)
39+
assignee_id = reply_data.fetch(:assignee_id) { fail 'assignee_id is required' }
40+
reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id, type: 'admin')
41+
end
2942
end
3043
end
3144
end

spec/unit/intercom/conversation_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
client.conversations.reply(id: '147', type: 'user', body: 'Thanks again', message_type: 'comment', user_id: 'ac4')
1919
end
2020

21+
it 'opens a conversation' do
22+
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'open', conversation_id: '147', admin_id: '123'}).returns(test_conversation)
23+
client.conversations.open(id: '147', admin_id: '123')
24+
end
25+
26+
it 'closes a conversation' do
27+
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'close', conversation_id: '147', admin_id: '123'}).returns(test_conversation)
28+
client.conversations.close(id: '147', admin_id: '123')
29+
end
30+
31+
it 'assigns a conversation' do
32+
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'assignment', conversation_id: '147', admin_id: '123', assignee_id: '124'}).returns(test_conversation)
33+
client.conversations.assign(id: '147', admin_id: '123', assignee_id: '124')
34+
end
35+
2136
# it "creates a subscription" do
2237
# client.expects(:post).with("/subscriptions", {'url' => "http://example.com", 'topics' => ["user.created"]}).returns(test_subscription)
2338
# subscription = client.subscriptions.create(:url => "http://example.com", :topics => ["user.created"])

0 commit comments

Comments
 (0)