Skip to content

Commit

Permalink
Add rough implementation of conversation replies
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRy4n committed Nov 2, 2023
1 parent 2585a28 commit ebf4c12
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 234 deletions.
10 changes: 5 additions & 5 deletions intercom_python_sdk/apis/articles/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


@response_handler(catch_api_error)
class ArticlesAPI(APIBase):
class ArticlesAPI(APIBase): # type: ignore
URI = "/articles/"

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

@returns(ArticleSchema) # type: ignore
@json
@json # type: ignore
@post("")
def create(self, data: Body(type=ArticleSchema)): # type: ignore

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

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

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

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

@returns(ArticleSchema) # type: ignore
@json
@json # type: ignore
@put("{article_id}")
def update_by_id(self, article_id: Union[str, int], data: Body(type=ArticleSchema)): # type: ignore
""" Update an Article by ID.
Expand Down
34 changes: 18 additions & 16 deletions intercom_python_sdk/apis/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ class Article(ModelBase):
See the `ArticleSchema` class.
"""
def __init__(self, *args, **kwargs):
self.__type = kwargs.get('type', 'article')
self.__workspace_id = kwargs.get('workspace_id', '')
self.__title = kwargs.get('title', '')
self.__description = kwargs.get('description', '')
self.__body = kwargs.get('body', '')
self.__author_id = kwargs.get('author_id', None)
self.__state = kwargs.get('state', '')
self.__created_at = kwargs.get('created_at', None)
self.__updated_at = kwargs.get('updated_at', None)
self.__url = kwargs.get('url', '')
self.__parent_id = kwargs.get('parent_id', None)
self.__parent_type = kwargs.get('parent_type', '')
self.__default_locale = kwargs.get('default_locale', '')
self.__type: str = kwargs.get('type', 'article')
self.__workspace_id: str = kwargs.get('workspace_id', '')
self.__title: str = kwargs.get('title', '')
self.__description: str = kwargs.get('description', '')
self.__body: str = kwargs.get('body', '')
self.__author_id: int = kwargs.get('author_id', int())
self.__state: str = kwargs.get('state', '')
self.__created_at: int = kwargs.get('created_at', int())
self.__updated_at: int = kwargs.get('updated_at', int())
self.__url: str = kwargs.get('url', '')
self.__parent_id: int = kwargs.get('parent_id', int())
self.__parent_type: str = kwargs.get('parent_type', '')
self.__default_locale: str = kwargs.get('default_locale', '')
self.__statistics = kwargs.get('statistics', None)
self.__id = kwargs.get('id', None)
self.__translated_content = kwargs.get('translated_content', {})
self.__id: int = kwargs.get('id', int())
self.__translated_content: dict = kwargs.get('translated_content', {})

# Properties
@property
Expand Down Expand Up @@ -434,7 +434,9 @@ def update(self) -> 'Article':
"""
data = a_schemas.ArticleSchema().dump(self)
schema = a_schemas.ArticleSchema().load(data)
self.api_client.update_by_id(self.id, schema)
self.api_client.update_by_id(self.id, schema) # type: ignore

return self


class ArticleList(ModelBase):
Expand Down
33 changes: 2 additions & 31 deletions intercom_python_sdk/apis/conversation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@

# From Current API




# Intercom Python SDK
from ...core.api_base import APIBase
from ...core.errors import catch_api_error


@response_handler(catch_api_error)
class ConversationAPI(APIBase):
class ConversationAPI(APIBase): # type: ignore
URI = "/conversations/"


@json
@json # type: ignore
@post("{conversation_id}/reply")
def reply_to_conversation(self, conversation_id: str, payload: Body): #type: ignore
""" Reply to a Conversation.
Expand All @@ -47,28 +43,3 @@ def reply_to_conversation(self, conversation_id: str, payload: Body): #type: ign
Conversation: The Conversation with the given ID.
"""








"""
USAGE
intercom.conversation.reply_to_conversation(
ConversationID,{
"message_type": "comment",
"type": "admin",
"admin_id": ID,
"body": "MESSAGE"
}
)
"""







179 changes: 2 additions & 177 deletions intercom_python_sdk/apis/conversation/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,190 +11,14 @@
- [1] https://developers.intercom.com/docs/references/rest-api/api.intercom.io/Conversations/conversation/
"""

"""
{
"type": "conversation",
"id": "1295",
"title": "Conversation Title",
"created_at": 1663597223,
"updated_at": 1663597260,
"waiting_since": 1663597260,
"snoozed_until": 1663597260,
"open": true,
"state": "open",
"read": true,
"priority": "priority",
"admin_assignee_id": 0,
"team_assignee_id": "5017691",
"tags": {
"type": "tag.list",
"tags": [
{
"type": "tag",
"id": "123456",
"name": "Test tag",
"applied_at": 1663597223,
"applied_by": {
"type": "contact",
"id": "1a2b3c"
}
}
]
},
"conversation_rating": {
"rating": 5,
"remark": "",
"created_at": 1671028894,
"contact": {
"type": "contact",
"id": "5ba682d23d7cf92bef87bfd4",
"external_id": "f3b87a2e09d514c6c2e79b9a"
},
"teammate": {
"type": "contact",
"id": "1a2b3c"
}
},
"source": {
"type": "conversation",
"id": "3",
"delivered_as": "operator_initiated",
"subject": "",
"body": "<p>Hey there!</p>",
"author": {
"type": "admin",
"id": "274",
"name": "Operator",
"email": "[email protected]"
},
"attachments": [
{
"type": "upload",
"name": "example.png",
"url": "https://picsum.photos/200/300",
"content_type": "image/png",
"filesize": 100,
"width": 100,
"height": 100
}
],
"url": null,
"redacted": false
},
"contacts": {
"type": "contact.list",
"contacts": [
{
"type": "contact",
"id": "5ba682d23d7cf92bef87bfd4",
"external_id": "f3b87a2e09d514c6c2e79b9a"
}
]
},
"teammates": {
"type": "admin.list",
"teammates": [
{
"type": "contact",
"id": "1a2b3c"
}
]
},
"custom_attributes": {
"property1": "string",
"property2": "string"
},
"first_contact_reply": {
"created_at": 1663597223,
"type": "conversation",
"url": "https://developers.intercom.com/"
},
"sla_applied": {
"type": "conversation_sla_summary",
"sla_name": "",
"sla_status": "hit"
},
"statistics": {
"type": "conversation_statistics",
"time_to_assignment": 2310,
"time_to_admin_reply": 2310,
"time_to_first_close": 2310,
"time_to_last_close": 2310,
"median_time_to_reply": 2310,
"first_contact_reply_at": 1663597233,
"first_assignment_at": 1663597233,
"first_admin_reply_at": 1663597233,
"first_close_at": 1663597233,
"last_assignment_at": 1663597233,
"last_assignment_admin_reply_at": 1663597233,
"last_contact_reply_at": 1663597233,
"last_admin_reply_at": 1663597233,
"last_close_at": 1663597233,
"last_closed_by_id": "c3po",
"count_reopens": 1,
"count_assignments": 1,
"count_conversation_parts": 1
},
"conversation_parts": {
"type": "conversation_part.list",
"conversation_parts": [
{
"type": "conversation_part",
"id": "3",
"part_type": "comment",
"body": "<p>Okay!</p>",
"created_at": 1663597223,
"updated_at": 1663597260,
"notified_at": 1663597260,
"assigned_to": {
"type": "contact",
"id": "1a2b3c"
},
"author": {
"type": "admin",
"id": "274",
"name": "Operator",
"email": "[email protected]"
},
"attachments": [
{
"type": "upload",
"name": "example.png",
"url": "https://picsum.photos/200/300",
"content_type": "image/png",
"filesize": 100,
"width": 100,
"height": 100
}
],
"external_id": "abcd1234",
"redacted": false
}
],
"total_count": 2
},
"linked_objects": {
"type": "list",
"total_count": 100,
"has_more": false,
"data": [
{
"type": "ticket",
"id": "7583",
"category": "Customer"
}
]
}
}
"""
# External
import marshmallow
from marshmallow import fields

# From Current Package
from ...core.schema_base import SchemaBase


class ContactSchema(SchemaBase):
""" Schema for a contact.
Expand All @@ -211,6 +35,7 @@ class ContactSchema(SchemaBase):
def make(self, data, **kwargs):
return data


class TagSchema(SchemaBase):
""" Schema for a tag.
Expand Down
4 changes: 0 additions & 4 deletions intercom_setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages # noqa: H301

NAME = "intercom-python-sdk"
VERSION = "0.2.1-dev"
VERSION = "0.3.0-dev"
# To install the library, run the following
#
# python setup.py install
Expand Down

0 comments on commit ebf4c12

Please sign in to comment.