Skip to content

Commit 3683f00

Browse files
sarkar-rajarshisacheunturalfturalf
authored
Communication chat preview4 (#16905)
* [Communication] Generate identifier Models from new swagger (#16735) * Add generated chat code from new swagger * Address PR Feedback * Remove CommunicationUserIdentifierModel in identity,phone number package * Check schema of the object to determine the type [preview4] (#16838) * Replace identifier with rawId * Change serilizer * Replace indentifier with rawId in test code * Sync models across modules * fix typo in serizliser * Rearrange imports * Replace rawId with raw_id * remove trailing newline Co-authored-by: turalf <[email protected]> * preview4 changes made + unit tests fixed * Chat - preview4 changes - CommunicationUserIdentifier models added - create_chat_thread - returns CreateChatThreadResult instead of ChatThreadClient - add_participant - docstring update AddChatParticipantsResult instead of None - add_participants - docstring update AddChatParticipantsResult instead of None * pylint-changes * pylint changes * Method signature changed for add_pariticipant and add_participants - add_participant - AddChatParticipantsResult -> tuple(ChatThreadParticipant, CommunicationError) - add_participants - AddChatParticipantsResult -> list(tuple(ChatThreadParticipant, CommunicationError)) - unit tests modified as per signature change - CommunicationErrorResponseConverter added to cosolidate list(ChatThreadParticipant) and list(CommunicationError) into list(tuple(ChatThreadParticipant, CommunicationError)) - e2e tests modified as per signature change * CreateChatThreadResult modified to handle partial errors in batch calls with ease - CreateChatThreadResult -> attributes changed to - chat_thread -> ChatThread (no change) - Errors -> CreateChatThreadErrors -> list(tuple(ChatThreadParticipant, CommunicationError)) - create_chat_thread -> `thread_participants` and `repeatability_request_id` changed to keyword arguments - Modify unit tests to capture method signature modifications - Modify e2e tests to capture method signature modifications * pylint-changes * pylint fixes * README.md update + pylint fixes * test recordings added * add_participant -> raises error - Update README.md with modified signature - Update samples with new method signatures - Add test to detect invalid instantiation of AccessToken - Minor documentation updates - Modify unit tests to capture method signature modifications - Modify e2e tests to capture method signature modifications * pylint fixes * cls removed from docstring + update_topic async refactored * cls removed from docstring Co-authored-by: Sam Cheung <[email protected]> Co-authored-by: turalf <[email protected]> Co-authored-by: turalf <[email protected]>
1 parent 1a60ae0 commit 3683f00

File tree

81 files changed

+5906
-3696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5906
-3696
lines changed

sdk/communication/azure-communication-chat/README.md

Lines changed: 267 additions & 100 deletions
Large diffs are not rendered by default.

sdk/communication/azure-communication-chat/azure/communication/chat/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
from ._generated.models import (
55
SendChatMessageResult,
66
ChatThreadInfo,
7-
ChatMessageType
7+
ChatMessageType,
8+
CommunicationError
89
)
9-
from ._shared.user_credential import CommunicationTokenCredential
10-
from ._shared.user_token_refresh_options import CommunicationTokenRefreshOptions
10+
1111
from ._models import (
1212
ChatThreadParticipant,
1313
ChatMessage,
1414
ChatThread,
1515
ChatMessageReadReceipt,
16-
ChatMessageContent
16+
ChatMessageContent,
17+
CreateChatThreadResult
1718
)
18-
from ._shared.models import CommunicationUserIdentifier
1919

2020
__all__ = [
2121
'ChatClient',
@@ -26,10 +26,9 @@
2626
'SendChatMessageResult',
2727
'ChatThread',
2828
'ChatThreadInfo',
29-
'CommunicationTokenCredential',
30-
'CommunicationTokenRefreshOptions',
31-
'CommunicationUserIdentifier',
3229
'ChatThreadParticipant',
33-
'ChatMessageType'
30+
'ChatMessageType',
31+
'CreateChatThreadResult',
32+
'CommunicationError'
3433
]
3534
__version__ = VERSION

sdk/communication/azure-communication-chat/azure/communication/chat/_chat_client.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
from ._generated.models import CreateChatThreadRequest
2020
from ._models import (
2121
ChatThread,
22-
ChatThreadParticipant
22+
CreateChatThreadResult
23+
)
24+
from ._utils import ( # pylint: disable=unused-import
25+
_to_utc_datetime,
26+
return_response,
27+
CommunicationErrorResponseConverter
2328
)
24-
from ._utils import _to_utc_datetime, return_response # pylint: disable=unused-import
2529
from ._version import SDK_MONIKER
2630

2731
if TYPE_CHECKING:
@@ -119,26 +123,24 @@ def get_chat_thread_client(
119123
@distributed_trace
120124
def create_chat_thread(
121125
self, topic, # type: str
122-
thread_participants, # type: list[ChatThreadParticipant]
123-
repeatability_request_id=None, # type: Optional[str]
124126
**kwargs # type: Any
125127
):
126-
# type: (...) -> ChatThreadClient
128+
# type: (...) -> CreateChatThreadResult
127129
"""Creates a chat thread.
128130
129131
:param topic: Required. The thread topic.
130132
:type topic: str
131-
:param thread_participants: Required. Participants to be added to the thread.
132-
:type thread_participants: list[~azure.communication.chat.ChatThreadParticipant]
133-
:param repeatability_request_id: If specified, the client directs that the request is
133+
:keyword thread_participants: Optional. Participants to be added to the thread.
134+
:paramtype thread_participants: list[~azure.communication.chat.ChatThreadParticipant]
135+
:keyword repeatability_request_id: Optional. If specified, the client directs that the request is
134136
repeatable; that is, that the client can make the request multiple times with the same
135137
Repeatability-Request-ID and get back an appropriate response without the server executing the
136138
request multiple times. The value of the Repeatability-Request-ID is an opaque string
137139
representing a client-generated, globally unique for all time, identifier for the request. If not
138140
specified, a new unique id would be generated.
139-
:type repeatability_request_id: str
140-
:return: ChatThreadClient
141-
:rtype: ~azure.communication.chat.ChatThreadClient
141+
:paramtype repeatability_request_id: str
142+
:return: CreateChatThreadResult
143+
:rtype: ~azure.communication.chat.CreateChatThreadResult
142144
:raises: ~azure.core.exceptions.HttpResponseError, ValueError
143145
144146
.. admonition:: Example:
@@ -148,40 +150,45 @@ def create_chat_thread(
148150
:end-before: [END create_thread]
149151
:language: python
150152
:dedent: 8
151-
:caption: Creating ChatThreadClient by creating a new chat thread.
153+
:caption: Creating ChatThread by creating a new chat thread.
152154
"""
153155
if not topic:
154156
raise ValueError("topic cannot be None.")
155-
if not thread_participants:
156-
raise ValueError("List of ChatThreadParticipant cannot be None.")
157+
158+
repeatability_request_id = kwargs.pop('repeatability_request_id', None)
157159
if repeatability_request_id is None:
158160
repeatability_request_id = str(uuid4())
159161

160-
participants = [m._to_generated() for m in thread_participants] # pylint:disable=protected-access
161-
create_thread_request = \
162-
CreateChatThreadRequest(topic=topic, participants=participants)
162+
thread_participants = kwargs.pop('thread_participants', None)
163+
participants = []
164+
if thread_participants is not None:
165+
participants = [m._to_generated() for m in thread_participants] # pylint:disable=protected-access
166+
167+
create_thread_request = CreateChatThreadRequest(topic=topic, participants=participants)
163168

164169
create_chat_thread_result = self._client.chat.create_chat_thread(
165170
create_chat_thread_request=create_thread_request,
166171
repeatability_request_id=repeatability_request_id,
167172
**kwargs)
173+
174+
errors = None
168175
if hasattr(create_chat_thread_result, 'errors') and \
169176
create_chat_thread_result.errors is not None:
170-
participants = \
171-
create_chat_thread_result.errors.invalid_participants
172-
errors = []
173-
for participant in participants:
174-
errors.append('participant ' + participant.target +
175-
' failed to join thread due to: ' + participant.message)
176-
raise RuntimeError(errors)
177-
thread_id = create_chat_thread_result.chat_thread.id
178-
return ChatThreadClient(
179-
endpoint=self._endpoint,
180-
credential=self._credential,
181-
thread_id=thread_id,
182-
**kwargs
177+
errors = CommunicationErrorResponseConverter._convert( # pylint:disable=protected-access
178+
participants=[thread_participants],
179+
communication_errors=create_chat_thread_result.errors.invalid_participants
180+
)
181+
182+
chat_thread = ChatThread._from_generated( # pylint:disable=protected-access
183+
create_chat_thread_result.chat_thread)
184+
185+
create_chat_thread_result = CreateChatThreadResult(
186+
chat_thread=chat_thread,
187+
errors=errors
183188
)
184189

190+
return create_chat_thread_result
191+
185192
@distributed_trace
186193
def get_chat_thread(
187194
self, thread_id, # type: str
@@ -192,8 +199,7 @@ def get_chat_thread(
192199
193200
:param thread_id: Required. Thread id to get.
194201
:type thread_id: str
195-
:keyword callable cls: A custom type or function that will be passed the direct response
196-
:return: ChatThread, or the result of cls(response)
202+
:return: ChatThread
197203
:rtype: ~azure.communication.chat.ChatThread
198204
:raises: ~azure.core.exceptions.HttpResponseError, ValueError
199205
@@ -254,8 +260,7 @@ def delete_chat_thread(
254260
255261
:param thread_id: Required. Thread id to delete.
256262
:type thread_id: str
257-
:keyword callable cls: A custom type or function that will be passed the direct response
258-
:return: None, or the result of cls(response)
263+
:return: None
259264
:rtype: None
260265
:raises: ~azure.core.exceptions.HttpResponseError, ValueError
261266

0 commit comments

Comments
 (0)