diff --git a/README.md b/README.md index 724917de..1443e86a 100644 --- a/README.md +++ b/README.md @@ -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: 'joe@example.com', 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') @@ -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') diff --git a/lib/intercom/service/conversation.rb b/lib/intercom/service/conversation.rb index 40049576..95c4bd2c 100644 --- a/lib/intercom/service/conversation.rb +++ b/lib/intercom/service/conversation.rb @@ -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 diff --git a/spec/unit/intercom/conversation_spec.rb b/spec/unit/intercom/conversation_spec.rb index 037ac2bc..0f0c74cf 100644 --- a/spec/unit/intercom/conversation_spec.rb +++ b/spec/unit/intercom/conversation_spec.rb @@ -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')