Skip to content

Commit ebf4c12

Browse files
committed
Add rough implementation of conversation replies
1 parent 2585a28 commit ebf4c12

File tree

6 files changed

+28
-234
lines changed

6 files changed

+28
-234
lines changed

intercom_python_sdk/apis/articles/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
@response_handler(catch_api_error)
38-
class ArticlesAPI(APIBase):
38+
class ArticlesAPI(APIBase): # type: ignore
3939
URI = "/articles/"
4040

4141
@returns(ArticleSchema) # type: ignore
@@ -51,7 +51,7 @@ def get_by_id(self, article_id: Union[str, int]):
5151
"""
5252

5353
@returns(ArticleSchema) # type: ignore
54-
@json
54+
@json # type: ignore
5555
@post("")
5656
def create(self, data: Body(type=ArticleSchema)): # type: ignore
5757

@@ -78,7 +78,7 @@ def delete_by_id(self, article_id: Union[str, int]):
7878

7979
@returns(ArticleListSchema) # type: ignore
8080
@get("")
81-
def __list_all(self, page: Query('page'), per_page: Query('per_page') = 50): # noqa # type: ignore
81+
def __list_all(self, page: Query('page'), per_page: Query('per_page') = 50) -> ArticleList: # noqa # type: ignore
8282
""" List all Articles. """
8383

8484
def list_all(self, page: int = 1, per_page: int = 50) -> ArticleList:
@@ -92,7 +92,7 @@ def list_all(self, page: int = 1, per_page: int = 50) -> ArticleList:
9292
ArticleList: A list of Articles.
9393
"""
9494

95-
article_list = self.__list_all(page=page, per_page=per_page)
95+
article_list: ArticleList = self.__list_all(page=page, per_page=per_page)
9696
while page < article_list.pages['total_pages']:
9797
page += 1
9898
new_page = self.__list_all(page=page, per_page=per_page)
@@ -102,7 +102,7 @@ def list_all(self, page: int = 1, per_page: int = 50) -> ArticleList:
102102
return article_list
103103

104104
@returns(ArticleSchema) # type: ignore
105-
@json
105+
@json # type: ignore
106106
@put("{article_id}")
107107
def update_by_id(self, article_id: Union[str, int], data: Body(type=ArticleSchema)): # type: ignore
108108
""" Update an Article by ID.

intercom_python_sdk/apis/articles/models.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ class Article(ModelBase):
5555
See the `ArticleSchema` class.
5656
"""
5757
def __init__(self, *args, **kwargs):
58-
self.__type = kwargs.get('type', 'article')
59-
self.__workspace_id = kwargs.get('workspace_id', '')
60-
self.__title = kwargs.get('title', '')
61-
self.__description = kwargs.get('description', '')
62-
self.__body = kwargs.get('body', '')
63-
self.__author_id = kwargs.get('author_id', None)
64-
self.__state = kwargs.get('state', '')
65-
self.__created_at = kwargs.get('created_at', None)
66-
self.__updated_at = kwargs.get('updated_at', None)
67-
self.__url = kwargs.get('url', '')
68-
self.__parent_id = kwargs.get('parent_id', None)
69-
self.__parent_type = kwargs.get('parent_type', '')
70-
self.__default_locale = kwargs.get('default_locale', '')
58+
self.__type: str = kwargs.get('type', 'article')
59+
self.__workspace_id: str = kwargs.get('workspace_id', '')
60+
self.__title: str = kwargs.get('title', '')
61+
self.__description: str = kwargs.get('description', '')
62+
self.__body: str = kwargs.get('body', '')
63+
self.__author_id: int = kwargs.get('author_id', int())
64+
self.__state: str = kwargs.get('state', '')
65+
self.__created_at: int = kwargs.get('created_at', int())
66+
self.__updated_at: int = kwargs.get('updated_at', int())
67+
self.__url: str = kwargs.get('url', '')
68+
self.__parent_id: int = kwargs.get('parent_id', int())
69+
self.__parent_type: str = kwargs.get('parent_type', '')
70+
self.__default_locale: str = kwargs.get('default_locale', '')
7171
self.__statistics = kwargs.get('statistics', None)
72-
self.__id = kwargs.get('id', None)
73-
self.__translated_content = kwargs.get('translated_content', {})
72+
self.__id: int = kwargs.get('id', int())
73+
self.__translated_content: dict = kwargs.get('translated_content', {})
7474

7575
# Properties
7676
@property
@@ -434,7 +434,9 @@ def update(self) -> 'Article':
434434
"""
435435
data = a_schemas.ArticleSchema().dump(self)
436436
schema = a_schemas.ArticleSchema().load(data)
437-
self.api_client.update_by_id(self.id, schema)
437+
self.api_client.update_by_id(self.id, schema) # type: ignore
438+
439+
return self
438440

439441

440442
class ArticleList(ModelBase):

intercom_python_sdk/apis/conversation/api.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@
2121

2222
# From Current API
2323

24-
25-
26-
2724
# Intercom Python SDK
2825
from ...core.api_base import APIBase
2926
from ...core.errors import catch_api_error
3027

3128

3229
@response_handler(catch_api_error)
33-
class ConversationAPI(APIBase):
30+
class ConversationAPI(APIBase): # type: ignore
3431
URI = "/conversations/"
3532

36-
37-
@json
33+
@json # type: ignore
3834
@post("{conversation_id}/reply")
3935
def reply_to_conversation(self, conversation_id: str, payload: Body): #type: ignore
4036
""" Reply to a Conversation.
@@ -47,28 +43,3 @@ def reply_to_conversation(self, conversation_id: str, payload: Body): #type: ign
4743
Conversation: The Conversation with the given ID.
4844
"""
4945

50-
51-
52-
53-
54-
55-
56-
57-
"""
58-
USAGE
59-
intercom.conversation.reply_to_conversation(
60-
ConversationID,{
61-
"message_type": "comment",
62-
"type": "admin",
63-
"admin_id": ID,
64-
"body": "MESSAGE"
65-
}
66-
)
67-
"""
68-
69-
70-
71-
72-
73-
74-

intercom_python_sdk/apis/conversation/schemas.py

Lines changed: 2 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -11,190 +11,14 @@
1111
- [1] https://developers.intercom.com/docs/references/rest-api/api.intercom.io/Conversations/conversation/
1212
"""
1313

14-
"""
15-
{
16-
"type": "conversation",
17-
"id": "1295",
18-
"title": "Conversation Title",
19-
"created_at": 1663597223,
20-
"updated_at": 1663597260,
21-
"waiting_since": 1663597260,
22-
"snoozed_until": 1663597260,
23-
"open": true,
24-
"state": "open",
25-
"read": true,
26-
"priority": "priority",
27-
"admin_assignee_id": 0,
28-
"team_assignee_id": "5017691",
29-
"tags": {
30-
"type": "tag.list",
31-
"tags": [
32-
{
33-
"type": "tag",
34-
"id": "123456",
35-
"name": "Test tag",
36-
"applied_at": 1663597223,
37-
"applied_by": {
38-
"type": "contact",
39-
"id": "1a2b3c"
40-
}
41-
}
42-
]
43-
},
44-
"conversation_rating": {
45-
"rating": 5,
46-
"remark": "",
47-
"created_at": 1671028894,
48-
"contact": {
49-
"type": "contact",
50-
"id": "5ba682d23d7cf92bef87bfd4",
51-
"external_id": "f3b87a2e09d514c6c2e79b9a"
52-
},
53-
"teammate": {
54-
"type": "contact",
55-
"id": "1a2b3c"
56-
}
57-
},
58-
"source": {
59-
"type": "conversation",
60-
"id": "3",
61-
"delivered_as": "operator_initiated",
62-
"subject": "",
63-
"body": "<p>Hey there!</p>",
64-
"author": {
65-
"type": "admin",
66-
"id": "274",
67-
"name": "Operator",
68-
"email": "operator+abcd1234@intercom.io"
69-
},
70-
"attachments": [
71-
{
72-
"type": "upload",
73-
"name": "example.png",
74-
"url": "https://picsum.photos/200/300",
75-
"content_type": "image/png",
76-
"filesize": 100,
77-
"width": 100,
78-
"height": 100
79-
}
80-
],
81-
"url": null,
82-
"redacted": false
83-
},
84-
"contacts": {
85-
"type": "contact.list",
86-
"contacts": [
87-
{
88-
"type": "contact",
89-
"id": "5ba682d23d7cf92bef87bfd4",
90-
"external_id": "f3b87a2e09d514c6c2e79b9a"
91-
}
92-
]
93-
},
94-
"teammates": {
95-
"type": "admin.list",
96-
"teammates": [
97-
{
98-
"type": "contact",
99-
"id": "1a2b3c"
100-
}
101-
]
102-
},
103-
"custom_attributes": {
104-
"property1": "string",
105-
"property2": "string"
106-
},
107-
"first_contact_reply": {
108-
"created_at": 1663597223,
109-
"type": "conversation",
110-
"url": "https://developers.intercom.com/"
111-
},
112-
"sla_applied": {
113-
"type": "conversation_sla_summary",
114-
"sla_name": "",
115-
"sla_status": "hit"
116-
},
117-
"statistics": {
118-
"type": "conversation_statistics",
119-
"time_to_assignment": 2310,
120-
"time_to_admin_reply": 2310,
121-
"time_to_first_close": 2310,
122-
"time_to_last_close": 2310,
123-
"median_time_to_reply": 2310,
124-
"first_contact_reply_at": 1663597233,
125-
"first_assignment_at": 1663597233,
126-
"first_admin_reply_at": 1663597233,
127-
"first_close_at": 1663597233,
128-
"last_assignment_at": 1663597233,
129-
"last_assignment_admin_reply_at": 1663597233,
130-
"last_contact_reply_at": 1663597233,
131-
"last_admin_reply_at": 1663597233,
132-
"last_close_at": 1663597233,
133-
"last_closed_by_id": "c3po",
134-
"count_reopens": 1,
135-
"count_assignments": 1,
136-
"count_conversation_parts": 1
137-
},
138-
"conversation_parts": {
139-
"type": "conversation_part.list",
140-
"conversation_parts": [
141-
{
142-
"type": "conversation_part",
143-
"id": "3",
144-
"part_type": "comment",
145-
"body": "<p>Okay!</p>",
146-
"created_at": 1663597223,
147-
"updated_at": 1663597260,
148-
"notified_at": 1663597260,
149-
"assigned_to": {
150-
"type": "contact",
151-
"id": "1a2b3c"
152-
},
153-
"author": {
154-
"type": "admin",
155-
"id": "274",
156-
"name": "Operator",
157-
"email": "operator+abcd1234@intercom.io"
158-
},
159-
"attachments": [
160-
{
161-
"type": "upload",
162-
"name": "example.png",
163-
"url": "https://picsum.photos/200/300",
164-
"content_type": "image/png",
165-
"filesize": 100,
166-
"width": 100,
167-
"height": 100
168-
}
169-
],
170-
"external_id": "abcd1234",
171-
"redacted": false
172-
}
173-
],
174-
"total_count": 2
175-
},
176-
"linked_objects": {
177-
"type": "list",
178-
"total_count": 100,
179-
"has_more": false,
180-
"data": [
181-
{
182-
"type": "ticket",
183-
"id": "7583",
184-
"category": "Customer"
185-
}
186-
]
187-
}
188-
}
189-
190-
"""
19114
# External
19215
import marshmallow
19316
from marshmallow import fields
19417

19518
# From Current Package
19619
from ...core.schema_base import SchemaBase
19720

21+
19822
class ContactSchema(SchemaBase):
19923
""" Schema for a contact.
20024
@@ -211,6 +35,7 @@ class ContactSchema(SchemaBase):
21135
def make(self, data, **kwargs):
21236
return data
21337

38+
21439
class TagSchema(SchemaBase):
21540
""" Schema for a tag.
21641

intercom_setup.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from setuptools import setup, find_packages # noqa: H301
1010

1111
NAME = "intercom-python-sdk"
12-
VERSION = "0.2.1-dev"
12+
VERSION = "0.3.0-dev"
1313
# To install the library, run the following
1414
#
1515
# python setup.py install

0 commit comments

Comments
 (0)