Skip to content

Commit 9eeab74

Browse files
committed
Change to new interface
1 parent b7a5e12 commit 9eeab74

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +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 => '[email protected]', :message_type => 'comment', :body => 'foo')
178-
# Admin (identified by email) replies with a comment
179-
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :email => '[email protected]', :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')
180180

181-
# Reply and Open
182-
intercom.conversations.reply_and_open(:id => conversation.id, :type => 'admin', :email => '[email protected]', :message_type => 'note', :body => 'foo')
181+
# Open
182+
intercom.conversations.open(id: conversation.id, admin_id: '123')
183183

184-
# Reply and Close
185-
intercom.conversations.reply_and_close(:id => conversation.id, :type => 'admin', :email => '[email protected]', :message_type => 'note', :body => 'foo')
184+
# Close
185+
intercom.conversations.close(id: conversation.id, admin_id: '123')
186186

187-
# Reply and Assign
188-
intercom.conversations.reply_and_assign({:id => conversation.id, :type => 'admin', :email => '[email protected]', :message_type => 'note', :body => 'foo'}, assignee_id: admin.id)
187+
# Assign
188+
intercom.conversations.assign(id: conversation.id, admin_id: '123', assignee_id: '124')
189189

190-
# Assign without reply
191-
intercom.conversations.assign({:id => conversation.id }, assignee_id: admin.id)
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')
192195

193196
# MARKING A CONVERSATION AS READ
194197
intercom.conversations.mark_read(conversation.id)

lib/intercom/service/conversation.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,18 @@ def reply(reply_data)
2727
collection_class.new.from_response(response)
2828
end
2929

30-
def reply_and_open(reply_data)
31-
reply reply_data.merge(change_state: 'open')
30+
def open(reply_data)
31+
reply reply_data.merge(message_type: 'open', type: 'admin')
3232
end
3333

34-
def reply_and_close(reply_data)
35-
reply reply_data.merge(change_state: 'close')
34+
def close(reply_data)
35+
reply reply_data.merge(message_type: 'close', type: 'admin')
3636
end
3737

38-
def reply_and_assign(reply_data, assignee_id:)
39-
reply reply_data.merge(assignee_id: assignee_id)
40-
end
41-
42-
def assign(reply_data, assignee_id:)
43-
reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id)
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')
4441
end
42+
end
4543
end
4644
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)