From 4a68002c0e3b926b1b0d7ac676de85c784a23f88 Mon Sep 17 00:00:00 2001 From: Oleg Pesok Date: Tue, 21 Nov 2017 13:49:22 -0800 Subject: [PATCH 1/6] Add reply last conversation to api https://developers.intercom.com/v2.0/reference#replying-to-users-last-conversation --- intercom/service/conversation.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/intercom/service/conversation.py b/intercom/service/conversation.py index 61f143a7..922a2e4b 100644 --- a/intercom/service/conversation.py +++ b/intercom/service/conversation.py @@ -27,10 +27,18 @@ def resource_url(self, _id): """Return the URL for the specified resource in this collection.""" return "/%s/%s/reply" % (self.collection, _id) + def last_resource_url(self): + """Return the URL for the specified resource in this collection.""" + return "/%s/last/reply" % (self.collection,) + def reply(self, **reply_data): """Reply to a message.""" return self.__reply(reply_data) + def reply_last(self, **reply_data): + """Reply to a message.""" + return self.__reply_last(reply_data) + def assign(self, **reply_data): """Assign a conversation to a user.""" reply_data['type'] = 'admin' @@ -61,3 +69,8 @@ def __reply(self, reply_data): reply_data['conversation_id'] = _id response = self.client.post(self.resource_url(_id), reply_data) return self.collection_class().from_response(response) + + def __reply_last(self, reply_data): + """Send requests to the resource handler.""" + response = self.client.post(self.last_resource_url(), reply_data) + return self.collection_class().from_response(response) From 1f26eb47b0c1ebb7c214a3e2fdff9bf451cecef2 Mon Sep 17 00:00:00 2001 From: reshavsingla Date: Mon, 21 Dec 2020 14:59:56 -0800 Subject: [PATCH 2/6] tag conversation in intercom --- intercom/service/conversation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/intercom/service/conversation.py b/intercom/service/conversation.py index 922a2e4b..f89756c4 100644 --- a/intercom/service/conversation.py +++ b/intercom/service/conversation.py @@ -31,6 +31,10 @@ def last_resource_url(self): """Return the URL for the specified resource in this collection.""" return "/%s/last/reply" % (self.collection,) + def tag_resource_url(self, _id): + """Return the URL for the specified resource in this collection.""" + return "/%s/%s/tags" % (self.collection, _id) + def reply(self, **reply_data): """Reply to a message.""" return self.__reply(reply_data) @@ -74,3 +78,9 @@ def __reply_last(self, reply_data): """Send requests to the resource handler.""" response = self.client.post(self.last_resource_url(), reply_data) return self.collection_class().from_response(response) + + def tag(self, tag_data): + """Send requests to the tag resource handler.""" + _id = tag_data.pop('conversation_id') + response = self.client.post(self.tag_resource_url(_id), tag_data) + return self.collection_class().from_response(response) From 3315fadcebb5fe3a6853ad0b65f42beb2f71bbd6 Mon Sep 17 00:00:00 2001 From: reshavsingla Date: Mon, 1 Feb 2021 12:08:56 -0800 Subject: [PATCH 3/6] add support to query team --- intercom/service/team.py | 10 ++++++++++ intercom/team.py | 7 +++++++ 2 files changed, 17 insertions(+) create mode 100644 intercom/service/team.py create mode 100644 intercom/team.py diff --git a/intercom/service/team.py b/intercom/service/team.py new file mode 100644 index 00000000..2bfe7a5c --- /dev/null +++ b/intercom/service/team.py @@ -0,0 +1,10 @@ +from intercom import team +from intercom.api_operations.all import All +from intercom.service.base_service import BaseService + + +class Team(BaseService, All): + + @property + def collection_class(self): + return team.Team diff --git a/intercom/team.py b/intercom/team.py new file mode 100644 index 00000000..3cf40fa1 --- /dev/null +++ b/intercom/team.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +from intercom.traits.api_resource import Resource + + +class Team(Resource): + pass From 47bb3a64453a4defc99636dd9678616aeee3e28f Mon Sep 17 00:00:00 2001 From: reshavsingla Date: Mon, 1 Feb 2021 12:14:30 -0800 Subject: [PATCH 4/6] expose team --- intercom/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/intercom/client.py b/intercom/client.py index ce37617b..5ddb9334 100644 --- a/intercom/client.py +++ b/intercom/client.py @@ -80,6 +80,11 @@ def jobs(self): from intercom.service import job return job.Job(self) + @property + def teams(self): + from intercom.service import team + return team.Team(self) + def _execute_request(self, request, params): result = request.execute(self.base_url, self._auth, params) self.rate_limit_details = request.rate_limit_details From 849f1b90c714db4402b0262ed78f4bf9e727cdd6 Mon Sep 17 00:00:00 2001 From: Reshav Date: Thu, 6 May 2021 12:34:52 -0700 Subject: [PATCH 5/6] Conversations: Add search functionality for conversations (#3) * WIP * fix * fix --- intercom/collection_proxy.py | 12 +++++++++--- intercom/extended_api_operations/search.py | 21 +++++++++++++++++++++ intercom/service/conversation.py | 3 ++- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 intercom/extended_api_operations/search.py diff --git a/intercom/collection_proxy.py b/intercom/collection_proxy.py index 2b419f30..de9631b8 100644 --- a/intercom/collection_proxy.py +++ b/intercom/collection_proxy.py @@ -9,7 +9,7 @@ class CollectionProxy(six.Iterator): def __init__( self, client, collection_cls, collection, - finder_url, finder_params={}): + finder_url, finder_params={}, is_post_request=False): self.client = client @@ -37,6 +37,9 @@ def __init__( # a link to the next page of results self.next_page = None + # is this a post request + self.is_post_request = is_post_request + def __iter__(self): return self @@ -77,8 +80,11 @@ def get_page(self, url, params={}): # if there is no url stop iterating if url is None: raise StopIteration + if self.is_post_request: + response = self.client.post(url, params) + else: + response = self.client.get(url, params) - response = self.client.get(url, params) if response is None: raise HttpError('Http Error - No response entity returned') @@ -98,6 +104,6 @@ def paging_info_present(self, response): def extract_next_link(self, response): if self.paging_info_present(response): paging_info = response["pages"] - if paging_info["next"]: + if "next" in paging_info and paging_info["next"]: next_parsed = six.moves.urllib.parse.urlparse(paging_info["next"]) return '{}?{}'.format(next_parsed.path, next_parsed.query) diff --git a/intercom/extended_api_operations/search.py b/intercom/extended_api_operations/search.py new file mode 100644 index 00000000..e04d4362 --- /dev/null +++ b/intercom/extended_api_operations/search.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +"""Operation to search instances of a particular resource.""" + +from intercom import utils +from intercom.collection_proxy import CollectionProxy + + +class Search(object): + """A mixin that provides `search` functionality.""" + + proxy_class = CollectionProxy + + def search(self, **params): + """Search instances of the resource based on the supplied parameters.""" + collection = utils.resource_class_to_collection_name( + self.collection_class) + search_url = "/%s/search" % (collection) + finder_params = params + return self.proxy_class( + self.client, self.collection_class, collection, + search_url, finder_params, is_post_request=True) diff --git a/intercom/service/conversation.py b/intercom/service/conversation.py index f89756c4..a35cef47 100644 --- a/intercom/service/conversation.py +++ b/intercom/service/conversation.py @@ -7,10 +7,11 @@ from intercom.api_operations.find_all import FindAll from intercom.api_operations.load import Load from intercom.api_operations.save import Save +from intercom.extended_api_operations.search import Search from intercom.service.base_service import BaseService -class Conversation(BaseService, Find, FindAll, Save, Load): +class Conversation(BaseService, Find, FindAll, Save, Search, Load): """Service class for Conversations.""" @property From 51d7fed4cd8acbf2a3c0231c136995c23b845c2b Mon Sep 17 00:00:00 2001 From: Moosa Baquie Date: Mon, 7 Mar 2022 12:23:34 -0800 Subject: [PATCH 6/6] added snooze support --- intercom/service/conversation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/intercom/service/conversation.py b/intercom/service/conversation.py index a35cef47..66a1f676 100644 --- a/intercom/service/conversation.py +++ b/intercom/service/conversation.py @@ -62,6 +62,12 @@ def close(self, **reply_data): reply_data['message_type'] = 'close' return self.__reply(reply_data) + def snooze(self, **reply_data): + """Snooze the conversation until the passed in `snoozed_until` time""" + reply_data['type'] = 'admin' + reply_data['message_type'] = 'snoozed' + return self.__reply(reply_data) + def mark_read(self, _id): """Mark a conversation as read.""" data = {'read': True}