Skip to content

Commit 7fbb67a

Browse files
theandrewykimchoran
authored andcommitted
Residently conversations last reply (#443)
* Added the missing conversation last reply action * updated readme to include * Cleanup stray comment * refactor test and update readme
1 parent fe13451 commit 7fbb67a

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ intercom.conversations.reply(id: conversation.id, type: 'admin', admin_id: '123'
224224
# User (identified by email) replies with a comment and attachment
225225
intercom.conversations.reply(id: conversation.id, type: 'user', email: '[email protected]', message_type: 'comment', body: 'foo', attachment_urls: ['http://www.example.com/attachment.jpg'])
226226

227+
#reply to a user's last conversation
228+
intercom.conversations.reply_to_last(type: 'user', body: 'Thanks again', message_type: 'comment', user_id: '12345', admin_id: '123')
229+
227230
# Open
228231
intercom.conversations.open(id: conversation.id, admin_id: '123')
229232

@@ -244,6 +247,12 @@ intercom.conversations.reply(id: conversation.id, type: 'admin', admin_id: '123'
244247
# Reply and Close
245248
intercom.conversations.reply(id: conversation.id, type: 'admin', admin_id: '123', message_type: 'close', body: 'bar')
246249

250+
# Admin reply to last conversation
251+
intercom.conversations.reply_to_last(intercom_user_id: '5678', type: 'admin', admin_id: '123', message_type: 'comment', body: 'bar')
252+
253+
# User reply to last conversation
254+
intercom.conversations.reply_to_last(intercom_user_id: '5678', type: 'user', message_type: 'comment', body: 'bar')
255+
247256
# ASSIGNING CONVERSATIONS TO ADMINS
248257
intercom.conversations.reply(id: conversation.id, type: 'admin', assignee_id: assignee_admin.id, admin_id: admin.id, message_type: 'assignment')
249258

lib/intercom/service/conversation.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def reply(reply_data)
2929
collection_class.new.from_response(response)
3030
end
3131

32+
def reply_to_last(reply_data)
33+
collection_name = Utils.resource_class_to_collection_name(collection_class)
34+
response = @client.post("/#{collection_name}/last/reply", reply_data)
35+
collection_class.new.from_response(response)
36+
end
37+
3238
def open(reply_data)
3339
reply reply_data.merge(message_type: 'open', type: 'admin')
3440
end

spec/unit/intercom/conversation_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
client.conversations.reply(id: '147', type: 'user', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', attachment_urls: ["http://www.example.com/attachment.jpg"])
2929
end
3030

31+
it 'sends a reply to a users last conversation from an admin' do
32+
client.expects(:post).with('/conversations/last/reply', { type: 'admin', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', admin_id: '123' }).returns(test_conversation)
33+
client.conversations.reply_to_last(type: 'admin', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', admin_id: '123')
34+
end
35+
3136
it 'opens a conversation' do
3237
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'open', conversation_id: '147', admin_id: '123'}).returns(test_conversation)
3338
client.conversations.open(id: '147', admin_id: '123')

0 commit comments

Comments
 (0)