Skip to content

Commit 3ed96b2

Browse files
committed
Add interface support for opens, closes, and assignments
1 parent 6b883d7 commit 3ed96b2

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ conversation.reply(
231231
conversation.reply(
232232
type='admin', email='bob@example.com',
233233
message_type='comment', body='bar')
234+
# Admin (identified by id) opens a conversation
235+
conversation.open_conversation(admin_id=7)
236+
# Admin (identified by id) closes a conversation
237+
conversation.close_conversation(admin_id=7)
238+
# Admin (identified by id) assigns a conversation to an assignee
239+
conversation.assign(assignee_id=8, admin_id=7)
234240

235241
# MARKING A CONVERSATION AS READ
236242
conversation.read = True

intercom/extended_api_operations/reply.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
class Reply(object):
77

88
def reply(self, **reply_data):
9+
return self.__reply(reply_data)
10+
11+
def close_conversation(self, **reply_data):
12+
reply_data['type'] = 'admin'
13+
reply_data['message_type'] = 'close'
14+
return self.__reply(reply_data)
15+
16+
def open_conversation(self, **reply_data):
17+
reply_data['type'] = 'admin'
18+
reply_data['message_type'] = 'open'
19+
return self.__reply(reply_data)
20+
21+
def assign(self, **reply_data):
22+
reply_data['type'] = 'admin'
23+
reply_data['message_type'] = 'assignment'
24+
return self.__reply(reply_data)
25+
26+
def __reply(self, reply_data):
927
from intercom import Intercom
1028
collection = utils.resource_class_to_collection_name(self.__class__)
1129
url = "/%s/%s/reply" % (collection, self.id)

tests/integration/test_conversations.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def test_conversation_parts(self):
110110
# There is a part_type
111111
self.assertIsNotNone(part.part_type)
112112
# There is a body
113-
self.assertIsNotNone(part.body)
113+
if not part.part_type == 'assignment':
114+
self.assertIsNotNone(part.body)
114115

115116
def test_reply(self):
116117
# REPLYING TO CONVERSATIONS
@@ -127,6 +128,32 @@ def test_reply(self):
127128
conversation = Conversation.find(id=self.admin_conv.id)
128129
self.assertEqual(num_parts + 2, len(conversation.conversation_parts))
129130

131+
def test_open(self):
132+
# OPENING CONVERSATIONS
133+
conversation = Conversation.find(id=self.admin_conv.id)
134+
conversation.close_conversation(admin_id=self.admin.id, body='Closing message')
135+
self.assertFalse(conversation.open)
136+
conversation.open_conversation(admin_id=self.admin.id, body='Opening message')
137+
conversation = Conversation.find(id=self.admin_conv.id)
138+
self.assertTrue(conversation.open)
139+
140+
def test_close(self):
141+
# CLOSING CONVERSATIONS
142+
conversation = Conversation.find(id=self.admin_conv.id)
143+
self.assertTrue(conversation.open)
144+
conversation.close_conversation(admin_id=self.admin.id, body='Closing message')
145+
conversation = Conversation.find(id=self.admin_conv.id)
146+
self.assertFalse(conversation.open)
147+
148+
def test_assignment(self):
149+
# ASSIGNING CONVERSATIONS
150+
conversation = Conversation.find(id=self.admin_conv.id)
151+
num_parts = len(conversation.conversation_parts)
152+
conversation.assign(assignee_id=self.admin.id, admin_id=self.admin.id)
153+
conversation = Conversation.find(id=self.admin_conv.id)
154+
self.assertEqual(num_parts + 1, len(conversation.conversation_parts))
155+
self.assertEqual("assignment", conversation.conversation_parts[-1].part_type)
156+
130157
def test_mark_read(self):
131158
# MARKING A CONVERSATION AS READ
132159
conversation = Conversation.find(id=self.admin_conv.id)

0 commit comments

Comments
 (0)