-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from JaviCerveraIngram/CPS-22-conversation
CPS-22-conversation
- Loading branch information
Showing
8 changed files
with
335 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This file is part of the Ingram Micro Cloud Blue Connect SDK. | ||
# Copyright (c) 2019 Ingram Micro. All Rights Reserved. | ||
|
||
import datetime | ||
|
||
from typing import List | ||
|
||
from .base import BaseModel | ||
from .company import User | ||
from connect.models.schemas import ConversationMessageSchema, ConversationSchema | ||
|
||
|
||
class ConversationMessage(BaseModel): | ||
""" Message in a :py:class:`.Conversation`. """ | ||
|
||
_schema = ConversationMessageSchema() | ||
|
||
conversation = None # type: str | ||
""" (str) Primary ID of Conversation object. """ | ||
|
||
created = None # type: datetime.datetime | ||
""" (datetime.datetime) Date of the Message creation. """ | ||
|
||
creator = None # type: User | ||
""" (:py:class:`.User`) :py:class:`.User` that created the message. """ | ||
|
||
text = None # type: str | ||
""" (str) Actual message. """ | ||
|
||
|
||
class Conversation(BaseModel): | ||
""" Conversation. """ | ||
|
||
_schema = ConversationSchema() | ||
|
||
instance_id = None # type: str | ||
""" (str) The id of object based on which discussion is made, e.g. listing request. | ||
It can be any object. | ||
""" | ||
|
||
created = None # type: datetime.datetime | ||
""" (datetime.datetime) Date of the Conversation creation. """ | ||
|
||
topic = None # type: str | ||
""" (str) Conversation topic. """ | ||
|
||
messages = None # type: List[ConversationMessage] | ||
""" (List[:py:class:`.ConversationMessage`]) List of :py:class:`.ConversationMessage` | ||
objects. | ||
""" | ||
|
||
creator = None # type: User | ||
""" (:py:class:`.User`) Creator of the conversation. """ | ||
|
||
def add_message(self, message, config=None): | ||
""" Adds a message to the conversation. | ||
:param str message: Message to add. | ||
:param Config config: Configuration, or ``None`` to use the environment config (default). | ||
:return: The added message. | ||
:rtype: ConversationMessage | ||
:raises TypeError: Raised if the message cannot be deserialized. | ||
""" | ||
|
||
from connect.resources.base import ApiClient | ||
response, _ = ApiClient(config, base_path='conversations/' + self.id + '/messages')\ | ||
.post(json={'text': message}) | ||
return ConversationMessage.deserialize(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "ME-000-000-000", | ||
"conversation": "CO-000-000-000", | ||
"created": "2018-12-18T13:03:30+00:00", | ||
"creator": { | ||
"id": "UR-000-000-000", | ||
"name": "Some User" | ||
}, | ||
"text": "Hi, please see my listing request" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"id": "CO-750-033-356", | ||
"instance_id": "LST-038-662-242", | ||
"created": "2018-12-18T12:49:34+00:00", | ||
"topic": "Topic", | ||
"messages": [ | ||
{ | ||
"id": "ME-506-258-087", | ||
"conversation": "CO-750-033-356", | ||
"created": "2018-12-18T13:03:30+00:00", | ||
"creator": { | ||
"id": "UR-922-977-649", | ||
"name": "Some User" | ||
}, | ||
"text": "Hi, check out" | ||
} | ||
], | ||
"creator": { | ||
"id": "UR-922-977-649", | ||
"name": "Some User" | ||
} | ||
} |
Oops, something went wrong.