Skip to content

Commit 92ab978

Browse files
theandrewykimchoran
authored andcommitted
Hahmed snooze conversation (#384)
* Snooze conversation * make recommended changes make suggested changes
1 parent 8040bfd commit 92ab978

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ intercom.conversations.close(id: conversation.id, admin_id: '123')
230230
# Assign
231231
intercom.conversations.assign(id: conversation.id, admin_id: '123', assignee_id: '124')
232232

233+
# Snooze
234+
intercom.conversations.snooze(id: conversation.id, admin_id: '123', snoozed_until: 9999999999)
235+
233236
# Reply and Open
234237
intercom.conversations.reply(id: conversation.id, type: 'admin', admin_id: '123', message_type: 'open', body: 'bar')
235238

lib/intercom/service/conversation.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ def close(reply_data)
3737
reply reply_data.merge(message_type: 'close', type: 'admin')
3838
end
3939

40+
def snooze(reply_data)
41+
snoozed_until = reply_data.fetch(:snoozed_until) { fail 'snoozed_until field is required' }
42+
reply reply_data.merge(message_type: 'snoozed', type: 'admin')
43+
end
44+
4045
def assign(reply_data)
4146
assignee_id = reply_data.fetch(:assignee_id) { fail 'assignee_id is required' }
4247
reply reply_data.merge(message_type: 'assignment', assignee_id: assignee_id, type: 'admin')

spec/spec_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'minitest/autorun'
33
require 'mocha/setup'
44
require 'webmock'
5+
require 'time'
56
include WebMock::API
67

78
def test_user(email="[email protected]")
@@ -625,6 +626,10 @@ def test_event_list
625626
}
626627
end
627628

629+
def tomorrow
630+
(DateTime.now.to_time + 1).to_i
631+
end
632+
628633
def page_of_events(include_next_link=false)
629634
{
630635
"type" => "event.list",

spec/unit/intercom/conversation_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
client.conversations.assign(id: '147', admin_id: '123', assignee_id: '124')
4444
end
4545

46+
it 'snoozes a conversation' do
47+
client.expects(:post).with('/conversations/147/reply', { type: 'admin', message_type: 'snoozed', conversation_id: '147', admin_id: '123', snoozed_until: tomorrow}).returns(test_conversation)
48+
client.conversations.snooze(id: '147', admin_id: '123', snoozed_until: tomorrow)
49+
end
50+
4651
# it "creates a subscription" do
4752
# client.expects(:post).with("/subscriptions", {'url' => "http://example.com", 'topics' => ["user.created"]}).returns(test_subscription)
4853
# subscription = client.subscriptions.create(:url => "http://example.com", :topics => ["user.created"])

0 commit comments

Comments
 (0)