Skip to content
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ intercom.conversations.reply(id: conversation.id, type: 'admin', admin_id: '123'
# User (identified by email) replies with a comment and attachment
intercom.conversations.reply(id: conversation.id, type: 'user', email: '[email protected]', message_type: 'comment', body: 'foo', attachment_urls: ['http://www.example.com/attachment.jpg'])

#reply to a user's last conversation
intercom.conversations.reply_to_last(type: 'user', body: 'Thanks again', message_type: 'comment', user_id: '12345', admin_id: '123')

# Open
intercom.conversations.open(id: conversation.id, admin_id: '123')

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

# Admin reply to last conversation
intercom.conversations.reply_to_last(intercom_user_id: '5678', type: 'admin', admin_id: '123', message_type: 'comment', body: 'bar')

# User reply to last conversation
intercom.conversations.reply_to_last(intercom_user_id: '5678', type: 'user', message_type: 'comment', body: 'bar')

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

Expand Down
6 changes: 6 additions & 0 deletions lib/intercom/service/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def reply(reply_data)
collection_class.new.from_response(response)
end

def reply_to_last(reply_data)
collection_name = Utils.resource_class_to_collection_name(collection_class)
response = @client.post("/#{collection_name}/last/reply", reply_data)
collection_class.new.from_response(response)
end

def open(reply_data)
reply reply_data.merge(message_type: 'open', type: 'admin')
end
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/intercom/conversation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
client.conversations.reply(id: '147', type: 'user', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', attachment_urls: ["http://www.example.com/attachment.jpg"])
end

it 'sends a reply to a users last conversation from an admin' do
client.expects(:post).with('/conversations/last/reply', { type: 'admin', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', admin_id: '123' }).returns(test_conversation)
client.conversations.reply_to_last(type: 'admin', body: 'Thanks again', message_type: 'comment', user_id: 'ac4', admin_id: '123')
end

it 'opens a conversation' do
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'open', conversation_id: '147', admin_id: '123'}).returns(test_conversation)
client.conversations.open(id: '147', admin_id: '123')
Expand Down