Skip to content

Commit ede0acd

Browse files
committed
Update Messages API
- Add the parentId parameter to the messages.list() method. - Add the messages.list_direct() API endpoint. - Update the message data model attributes.
1 parent 21f1afc commit ede0acd

File tree

2 files changed

+109
-21
lines changed

2 files changed

+109
-21
lines changed

webexteamssdk/api/messages.py

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def __init__(self, session, object_factory):
7373
self._object_factory = object_factory
7474

7575
@generator_container
76-
def list(self, roomId, mentionedPeople=None, before=None,
77-
beforeMessage=None, max=None, **request_parameters):
76+
def list(self, roomId, parentId=None, mentionedPeople=None, before=None,
77+
beforeMessage=None, max=50, **request_parameters):
7878
"""Lists messages in a room.
7979
8080
Each message will include content attachments if present.
@@ -93,6 +93,7 @@ def list(self, roomId, mentionedPeople=None, before=None,
9393
9494
Args:
9595
roomId(basestring): List messages for a room, by ID.
96+
parentId(basestring): List messages with a parent, by ID.
9697
mentionedPeople(basestring): List messages where the caller is
9798
mentioned by specifying "me" or the caller `personId`.
9899
before(basestring): List messages sent before a date and time, in
@@ -114,6 +115,7 @@ def list(self, roomId, mentionedPeople=None, before=None,
114115
115116
"""
116117
check_type(roomId, basestring)
118+
check_type(parentId, basestring, optional=True)
117119
check_type(mentionedPeople, basestring, optional=True)
118120
check_type(before, basestring, optional=True)
119121
check_type(beforeMessage, basestring, optional=True)
@@ -122,6 +124,7 @@ def list(self, roomId, mentionedPeople=None, before=None,
122124
params = dict_from_items_with_values(
123125
request_parameters,
124126
roomId=roomId,
127+
parentId=parentId,
125128
mentionedPeople=mentionedPeople,
126129
before=before,
127130
beforeMessage=beforeMessage,
@@ -135,9 +138,67 @@ def list(self, roomId, mentionedPeople=None, before=None,
135138
for item in items:
136139
yield self._object_factory(OBJECT_TYPE, item)
137140

138-
def create(self, roomId=None, toPersonId=None, toPersonEmail=None,
139-
text=None, markdown=None, files=None, attachments=None,
140-
parentId=None, **request_parameters):
141+
@generator_container
142+
def list_direct(self, personId=None, personEmail=None, parentId=None,
143+
**request_parameters):
144+
"""List all messages in a 1:1 (direct) room.
145+
146+
Use the `personId` or `personEmail` query parameter to specify the
147+
room.
148+
149+
The list API sorts the messages in descending order by creation date.
150+
151+
This method supports Webex Teams's implementation of RFC5988 Web
152+
Linking to provide pagination support. It returns a generator
153+
container that incrementally yields all messages returned by the
154+
query. The generator will automatically request additional 'pages' of
155+
responses from Webex as needed until all responses have been returned.
156+
The container makes the generator safe for reuse. A new API call will
157+
be made, using the same parameters that were specified when the
158+
generator was created, every time a new iterator is requested from the
159+
container.
160+
161+
Args:
162+
personId(basestring): List messages in a 1:1 room, by person ID.
163+
personEmail(basestring): List messages in a 1:1 room, by person
164+
email.
165+
parentId(basestring): List messages with a parent, by ID.
166+
**request_parameters: Additional request parameters (provides
167+
support for parameters that may be added in the future).
168+
169+
Returns:
170+
GeneratorContainer: A GeneratorContainer which, when iterated,
171+
yields the messages returned by the Webex Teams query.
172+
173+
Raises:
174+
TypeError: If the parameter types are incorrect.
175+
ApiError: If the Webex Teams cloud returns an error.
176+
177+
"""
178+
check_type(personId, basestring, optional=True)
179+
check_type(personEmail, basestring, optional=True)
180+
check_type(parentId, basestring, optional=True)
181+
182+
params = dict_from_items_with_values(
183+
request_parameters,
184+
personId=personId,
185+
personEmail=personEmail,
186+
parentId=parentId,
187+
)
188+
189+
# API request - get items
190+
items = self._session.get_items(
191+
API_ENDPOINT + "/direct",
192+
params=params,
193+
)
194+
195+
# Yield message objects created from the returned items JSON objects
196+
for item in items:
197+
yield self._object_factory(OBJECT_TYPE, item)
198+
199+
def create(self, roomId=None, parentId=None, toPersonId=None,
200+
toPersonEmail=None, text=None, markdown=None, files=None,
201+
attachments=None, **request_parameters):
141202
"""Post a message to a room.
142203
143204
The files parameter is a list, which accepts multiple values to allow

webexteamssdk/models/mixins/message.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ class MessageBasicPropertiesMixin(object):
4141
@property
4242
def id(self):
4343
"""The unique identifier for the message."""
44-
return self._json_data.get('id')
44+
return self._json_data.get("id")
45+
46+
@property
47+
def parentId(self):
48+
"""The unique identifier for the parent message."""
49+
return self._json_data.get("parentId")
4550

4651
@property
4752
def roomId(self):
4853
"""The room ID of the message."""
49-
return self._json_data.get('roomId')
54+
return self._json_data.get("roomId")
5055

5156
@property
5257
def roomType(self):
@@ -56,57 +61,79 @@ def roomType(self):
5661
`direct`: 1:1 room
5762
`group`: Group room
5863
"""
59-
return self._json_data.get('roomType')
64+
return self._json_data.get("roomType")
65+
66+
@property
67+
def toPersonId(self):
68+
"""The person ID of the recipient when sending a 1:1 message."""
69+
return self._json_data.get("toPersonId")
70+
71+
@property
72+
def toPersonEmail(self):
73+
"""The email address of the recipient when sending a 1:1 message."""
74+
return self._json_data.get("toPersonEmail")
6075

6176
@property
6277
def text(self):
6378
"""The message, in plain text."""
64-
return self._json_data.get('text')
79+
return self._json_data.get("text")
6580

6681
@property
6782
def markdown(self):
6883
"""The message, in Markdown format."""
69-
return self._json_data.get('markdown')
84+
return self._json_data.get("markdown")
7085

7186
@property
7287
def html(self):
73-
"""The message, in HTML format."""
74-
return self._json_data.get('html')
88+
"""The text content of the message, in HTML format.
89+
90+
This read-only property is used by the Webex Teams clients.
91+
"""
92+
return self._json_data.get("html")
7593

7694
@property
7795
def files(self):
7896
"""Public URLs for files attached to the message."""
79-
return self._json_data.get('files')
97+
return self._json_data.get("files")
8098

8199
@property
82100
def personId(self):
83101
"""The person ID of the message author."""
84-
return self._json_data.get('personId')
102+
return self._json_data.get("personId")
85103

86104
@property
87105
def personEmail(self):
88106
"""The email address of the message author."""
89-
return self._json_data.get('personEmail')
107+
return self._json_data.get("personEmail")
90108

91109
@property
92110
def mentionedPeople(self):
93111
"""People IDs for anyone mentioned in the message."""
94-
return self._json_data.get('mentionedPeople')
112+
return self._json_data.get("mentionedPeople")
95113

96114
@property
97115
def mentionedGroups(self):
98116
"""Group names for the groups mentioned in the message."""
99-
return self._json_data.get('mentionedGroups')
117+
return self._json_data.get("mentionedGroups")
100118

101119
@property
102-
def parentId(self):
103-
"""The unique identifier for the parent message."""
104-
return self._json_data.get('parentId')
120+
def attachments(self):
121+
"""Message content attachments attached to the message."""
122+
return self._json_data.get("attachments")
105123

106124
@property
107125
def created(self):
108126
"""The date and time the message was created."""
109-
created = self._json_data.get('created')
127+
created = self._json_data.get("created")
128+
if created:
129+
return WebexTeamsDateTime.strptime(created)
130+
else:
131+
return None
132+
133+
@property
134+
def updated(self):
135+
"""The date and time the message was created."""
136+
created = self._json_data.get("updated")
110137
if created:
111138
return WebexTeamsDateTime.strptime(created)
112139
else:

0 commit comments

Comments
 (0)