Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,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
10 changes: 10 additions & 0 deletions spec/unit/intercom/conversation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
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 'user replies to last conversation' do
client.expects(:post).with('/conversations/last/reply', { type: 'user', body: 'Thanks again', message_type: 'comment', user_id: 'ac4' }).returns(test_conversation)
client.conversations.reply_to_last(type: 'user', body: 'Thanks again', message_type: 'comment', user_id: 'ac4')
end

it 'admin replies to last conversation' 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