From 3ed96b2922c17d92689e5cb2fc6a75993a7c9f43 Mon Sep 17 00:00:00 2001 From: Bob Long Date: Thu, 30 Jul 2015 11:05:05 +0100 Subject: [PATCH] Add interface support for opens, closes, and assignments --- README.md | 6 +++++ intercom/extended_api_operations/reply.py | 18 ++++++++++++++ tests/integration/test_conversations.py | 29 ++++++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bbf4aab..70ffb2b7 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,12 @@ conversation.reply( conversation.reply( type='admin', email='bob@example.com', message_type='comment', body='bar') +# Admin (identified by id) opens a conversation +conversation.open_conversation(admin_id=7) +# Admin (identified by id) closes a conversation +conversation.close_conversation(admin_id=7) +# Admin (identified by id) assigns a conversation to an assignee +conversation.assign(assignee_id=8, admin_id=7) # MARKING A CONVERSATION AS READ conversation.read = True diff --git a/intercom/extended_api_operations/reply.py b/intercom/extended_api_operations/reply.py index db836d0d..30ff089c 100644 --- a/intercom/extended_api_operations/reply.py +++ b/intercom/extended_api_operations/reply.py @@ -6,6 +6,24 @@ class Reply(object): def reply(self, **reply_data): + return self.__reply(reply_data) + + def close_conversation(self, **reply_data): + reply_data['type'] = 'admin' + reply_data['message_type'] = 'close' + return self.__reply(reply_data) + + def open_conversation(self, **reply_data): + reply_data['type'] = 'admin' + reply_data['message_type'] = 'open' + return self.__reply(reply_data) + + def assign(self, **reply_data): + reply_data['type'] = 'admin' + reply_data['message_type'] = 'assignment' + return self.__reply(reply_data) + + def __reply(self, reply_data): from intercom import Intercom collection = utils.resource_class_to_collection_name(self.__class__) url = "/%s/%s/reply" % (collection, self.id) diff --git a/tests/integration/test_conversations.py b/tests/integration/test_conversations.py index 8adeae64..0a5655cb 100644 --- a/tests/integration/test_conversations.py +++ b/tests/integration/test_conversations.py @@ -110,7 +110,8 @@ def test_conversation_parts(self): # There is a part_type self.assertIsNotNone(part.part_type) # There is a body - self.assertIsNotNone(part.body) + if not part.part_type == 'assignment': + self.assertIsNotNone(part.body) def test_reply(self): # REPLYING TO CONVERSATIONS @@ -127,6 +128,32 @@ def test_reply(self): conversation = Conversation.find(id=self.admin_conv.id) self.assertEqual(num_parts + 2, len(conversation.conversation_parts)) + def test_open(self): + # OPENING CONVERSATIONS + conversation = Conversation.find(id=self.admin_conv.id) + conversation.close_conversation(admin_id=self.admin.id, body='Closing message') + self.assertFalse(conversation.open) + conversation.open_conversation(admin_id=self.admin.id, body='Opening message') + conversation = Conversation.find(id=self.admin_conv.id) + self.assertTrue(conversation.open) + + def test_close(self): + # CLOSING CONVERSATIONS + conversation = Conversation.find(id=self.admin_conv.id) + self.assertTrue(conversation.open) + conversation.close_conversation(admin_id=self.admin.id, body='Closing message') + conversation = Conversation.find(id=self.admin_conv.id) + self.assertFalse(conversation.open) + + def test_assignment(self): + # ASSIGNING CONVERSATIONS + conversation = Conversation.find(id=self.admin_conv.id) + num_parts = len(conversation.conversation_parts) + conversation.assign(assignee_id=self.admin.id, admin_id=self.admin.id) + conversation = Conversation.find(id=self.admin_conv.id) + self.assertEqual(num_parts + 1, len(conversation.conversation_parts)) + self.assertEqual("assignment", conversation.conversation_parts[-1].part_type) + def test_mark_read(self): # MARKING A CONVERSATION AS READ conversation = Conversation.find(id=self.admin_conv.id)