Skip to content

Commit 3593dc6

Browse files
committed
Reply to conversation
1 parent 2e6d12f commit 3593dc6

File tree

7 files changed

+811
-2
lines changed

7 files changed

+811
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can then access all sub-APIs through this object, like so:
2929
```python
3030

3131
cur_admin = intercom.admins.me()
32-
all_admins = intercom.admins.list_all()
32+
all_admins = intercom.admins.list_admins()
3333

3434
all_data_events = intercom.data_events.list_all()
3535
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
3+
"""
4+
5+
from . import api
6+
from . import models
7+
from . import schemas
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
# Conversation API
3+
4+
`apis/data_events/api.py`
5+
6+
This module contains the conversationAPI class, which defines a client for the conversation API.
7+
It is used to interact with the Intercom Conversation API [1] as defined in the Intercom API Reference [2].
8+
9+
---
10+
- [1] https://developers.intercom.com/docs/references/rest-api/api.intercom.io/Conversations/conversation/
11+
- [2] https://github.com/intercom/Intercom-OpenAPI
12+
"""
13+
14+
# External
15+
from uplink import (
16+
get, post,
17+
returns,
18+
response_handler,
19+
Body, Query,json
20+
)
21+
22+
# From Current API
23+
24+
25+
26+
27+
# Intercom Python SDK
28+
from ...core.api_base import APIBase
29+
from ...core.errors import catch_api_error
30+
31+
32+
@response_handler(catch_api_error)
33+
class ConversationAPI(APIBase):
34+
URI = "/conversations/"
35+
36+
37+
@json
38+
@post("{conversation_id}/reply")
39+
def reply_to_conversation(self, conversation_id: str, payload: Body): #type: ignore
40+
""" Reply to a Conversation.
41+
42+
Args:
43+
conversation_id (str): The ID of the Conversation.
44+
payload (Body): The payload of the reply.
45+
46+
Returns:
47+
Conversation: The Conversation with the given ID.
48+
"""
49+
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+
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
"""
2+
# Conversation API Models
3+
4+
`apis/Conversation/models.py`
5+
6+
This module contains models used to interact with the Intercom Conversation API [1].
7+
These models provide object oriented interfaces for the schemas defined in `apis/Conversation/schemas.py`.
8+
9+
---
10+
- [1] https://developers.intercom.com/docs/references/rest-api/api.intercom.io/Conversations/conversation/
11+
"""
12+
13+
"""
14+
{
15+
"type": "conversation",
16+
"id": "1295",
17+
"title": "Conversation Title",
18+
"created_at": 1663597223,
19+
"updated_at": 1663597260,
20+
"waiting_since": 1663597260,
21+
"snoozed_until": 1663597260,
22+
"open": true,
23+
"state": "open",
24+
"read": true,
25+
"priority": "priority",
26+
"admin_assignee_id": 0,
27+
"team_assignee_id": "5017691",
28+
"tags": {
29+
"type": "tag.list",
30+
"tags": [
31+
{
32+
"type": "tag",
33+
"id": "123456",
34+
"name": "Test tag",
35+
"applied_at": 1663597223,
36+
"applied_by": {
37+
"type": "contact",
38+
"id": "1a2b3c"
39+
}
40+
}
41+
]
42+
},
43+
"conversation_rating": {
44+
"rating": 5,
45+
"remark": "",
46+
"created_at": 1671028894,
47+
"contact": {
48+
"type": "contact",
49+
"id": "5ba682d23d7cf92bef87bfd4",
50+
"external_id": "f3b87a2e09d514c6c2e79b9a"
51+
},
52+
"teammate": {
53+
"type": "contact",
54+
"id": "1a2b3c"
55+
}
56+
},
57+
"source": {
58+
"type": "conversation",
59+
"id": "3",
60+
"delivered_as": "operator_initiated",
61+
"subject": "",
62+
"body": "<p>Hey there!</p>",
63+
"author": {
64+
"type": "admin",
65+
"id": "274",
66+
"name": "Operator",
67+
"email": "operator+abcd1234@intercom.io"
68+
},
69+
"attachments": [
70+
{
71+
"type": "upload",
72+
"name": "example.png",
73+
"url": "https://picsum.photos/200/300",
74+
"content_type": "image/png",
75+
"filesize": 100,
76+
"width": 100,
77+
"height": 100
78+
}
79+
],
80+
"url": null,
81+
"redacted": false
82+
},
83+
"contacts": {
84+
"type": "contact.list",
85+
"contacts": [
86+
{
87+
"type": "contact",
88+
"id": "5ba682d23d7cf92bef87bfd4",
89+
"external_id": "f3b87a2e09d514c6c2e79b9a"
90+
}
91+
]
92+
},
93+
"teammates": {
94+
"type": "admin.list",
95+
"teammates": [
96+
{
97+
"type": "contact",
98+
"id": "1a2b3c"
99+
}
100+
]
101+
},
102+
"custom_attributes": {
103+
"property1": "string",
104+
"property2": "string"
105+
},
106+
"first_contact_reply": {
107+
"created_at": 1663597223,
108+
"type": "conversation",
109+
"url": "https://developers.intercom.com/"
110+
},
111+
"sla_applied": {
112+
"type": "conversation_sla_summary",
113+
"sla_name": "",
114+
"sla_status": "hit"
115+
},
116+
"statistics": {
117+
"type": "conversation_statistics",
118+
"time_to_assignment": 2310,
119+
"time_to_admin_reply": 2310,
120+
"time_to_first_close": 2310,
121+
"time_to_last_close": 2310,
122+
"median_time_to_reply": 2310,
123+
"first_contact_reply_at": 1663597233,
124+
"first_assignment_at": 1663597233,
125+
"first_admin_reply_at": 1663597233,
126+
"first_close_at": 1663597233,
127+
"last_assignment_at": 1663597233,
128+
"last_assignment_admin_reply_at": 1663597233,
129+
"last_contact_reply_at": 1663597233,
130+
"last_admin_reply_at": 1663597233,
131+
"last_close_at": 1663597233,
132+
"last_closed_by_id": "c3po",
133+
"count_reopens": 1,
134+
"count_assignments": 1,
135+
"count_conversation_parts": 1
136+
},
137+
"conversation_parts": {
138+
"type": "conversation_part.list",
139+
"conversation_parts": [
140+
{
141+
"type": "conversation_part",
142+
"id": "3",
143+
"part_type": "comment",
144+
"body": "<p>Okay!</p>",
145+
"created_at": 1663597223,
146+
"updated_at": 1663597260,
147+
"notified_at": 1663597260,
148+
"assigned_to": {
149+
"type": "contact",
150+
"id": "1a2b3c"
151+
},
152+
"author": {
153+
"type": "admin",
154+
"id": "274",
155+
"name": "Operator",
156+
"email": "operator+abcd1234@intercom.io"
157+
},
158+
"attachments": [
159+
{
160+
"type": "upload",
161+
"name": "example.png",
162+
"url": "https://picsum.photos/200/300",
163+
"content_type": "image/png",
164+
"filesize": 100,
165+
"width": 100,
166+
"height": 100
167+
}
168+
],
169+
"external_id": "abcd1234",
170+
"redacted": false
171+
}
172+
],
173+
"total_count": 2
174+
},
175+
"linked_objects": {
176+
"type": "list",
177+
"total_count": 100,
178+
"has_more": false,
179+
"data": [
180+
{
181+
"type": "ticket",
182+
"id": "7583",
183+
"category": "Customer"
184+
}
185+
]
186+
}
187+
}
188+
"""
189+
190+
# External
191+
from bs4 import BeautifulSoup
192+
193+
from typing import (
194+
List,
195+
Optional,
196+
Union,
197+
TYPE_CHECKING
198+
)
199+
200+
# From Current API
201+
from . import schemas as c_schemas
202+
203+
# From Current Package
204+
from ...core.model_base import ModelBase
205+
206+
# Type Check Imports - TYPE_CHECKING is assumed True by type-checkers but is False at runtime.
207+
# See: https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING
208+
if TYPE_CHECKING:
209+
from .api import ConversationAPI
210+
211+
212+
class Conversation(ModelBase):
213+
"""
214+
Represents a Conversation.
215+
216+
Attributes:
217+
See the `ConversationSchema` definition in `apis/Conversation/schemas.py` for details.
218+
219+
Model-Specific Attributes:
220+
api_client (ConversationAPI): The API Client Instance. Injected via APIProxyInterface
221+
"""
222+
223+
def __init__(self, *args, **kwargs):
224+
self.__type: str = kwargs.get('type', '')
225+
self.__id: str = kwargs.get('id', '')
226+
self.__title: str = kwargs.get('title', '')
227+
self.__created_at: int = kwargs.get('created_at', 0)
228+
self.__updated_at: int = kwargs.get('updated_at', 0)
229+
self.__waiting_since: int = kwargs.get('waiting_since', 0)
230+
self.__snoozed_until: int = kwargs.get('snoozed_until', 0)
231+
self.__open: bool = kwargs.get('open', False)
232+
self.__state: str = kwargs.get('state', '')
233+
self.__read: bool = kwargs.get('read', False)
234+
self.__priority: str = kwargs.get('priority', '')
235+
self.__admin_assignee_id: int = kwargs.get('admin_assignee_id', 0)
236+
self.__team_assignee_id: str = kwargs.get('team_assignee_id', '')
237+
self.__tags: c_schemas.Tags = kwargs.get('tags', None)
238+
self.__conversation_rating: c_schemas.ConversationRating = kwargs.get('conversation_rating', None)
239+
self.__source: c_schemas.Source = kwargs.get('source', None)
240+
self.__contacts: c_schemas.Contacts = kwargs.get('contacts', None)
241+
self.__teammates: c_schemas.Teammates = kwargs.get('teammates', None)
242+
self.__custom_attributes: dict = kwargs.get('custom_attributes', {})
243+
self.__first_contact_reply: c_schemas.FirstContactReply = kwargs.get('first_contact_reply', None)
244+
self.__sla_applied: c_schemas.SLAApplied = kwargs.get('sla_applied', None)
245+
self.__statistics: c_schemas.Statistics = kwargs.get('statistics', None)
246+
self.__conversation_parts: c_schemas.ConversationParts = kwargs.get('conversation_parts', None)
247+
self.__linked_objects: c_schemas.LinkedObjects = kwargs.get('linked_objects', None)
248+
249+
250+
251+

0 commit comments

Comments
 (0)