Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ACS Chat Python SDK align with swagger changes #15640

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,25 @@ def create_chat_thread(
raise ValueError("List of ChatThreadParticipant cannot be None.")

participants = [m._to_generated() for m in thread_participants] # pylint:disable=protected-access
create_thread_request = CreateChatThreadRequest(topic=topic, participants=participants)

response, create_chat_thread_result = self._client.create_chat_thread(
create_thread_request, cls=return_response, **kwargs)
if response is not None:
response_header = response.http_response.headers
if ('Azure-Acs-InvalidParticipants' in response_header.keys() and
response_header['Azure-Acs-InvalidParticipants'] is not None):
invalid_participant_and_reason_list = response_header['Azure-Acs-InvalidParticipants'].split('|')
errors = []
for invalid_participant_and_reason in invalid_participant_and_reason_list:
participant, reason = invalid_participant_and_reason.split(',', 1)
errors.append('participant ' + participant + ' failed to join thread '
+ create_chat_thread_result.id + ' return statue code ' + reason)
raise ValueError(errors)
create_thread_request = \
CreateChatThreadRequest(topic=topic, participants=participants)

create_chat_thread_result = self._client.chat.create_chat_thread(
create_thread_request, **kwargs)
if hasattr(create_chat_thread_result, 'errors') and \
create_chat_thread_result.errors is not None:
participants = \
create_chat_thread_result.errors.invalid_participants
errors = []
for participant in participants:
errors.append('participant ' + participant.target +
' failed to join thread due to: ' + participant.message)
raise RuntimeError(errors)
thread_id = create_chat_thread_result.chat_thread.id
return ChatThreadClient(
endpoint=self._endpoint,
credential=self._credential,
thread_id=create_chat_thread_result.id,
thread_id=thread_id,
**kwargs
)

Expand Down Expand Up @@ -197,7 +197,7 @@ def get_chat_thread(
if not thread_id:
raise ValueError("thread_id cannot be None.")

chat_thread = self._client.get_chat_thread(thread_id, **kwargs)
chat_thread = self._client.chat.get_chat_thread(thread_id, **kwargs)
return ChatThread._from_generated(chat_thread) # pylint:disable=protected-access

@distributed_trace
Expand Down Expand Up @@ -227,7 +227,7 @@ def list_chat_threads(
results_per_page = kwargs.pop("results_per_page", None)
start_time = kwargs.pop("start_time", None)

return self._client.list_chat_threads(
return self._client.chat.list_chat_threads(
max_page_size=results_per_page,
start_time=start_time,
**kwargs)
Expand Down Expand Up @@ -260,7 +260,7 @@ def delete_chat_thread(
if not thread_id:
raise ValueError("thread_id cannot be None.")

return self._client.delete_chat_thread(thread_id, **kwargs)
return self._client.chat.delete_chat_thread(thread_id, **kwargs)

def close(self):
# type: () -> None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def update_topic(
"""

update_topic_request = UpdateChatThreadRequest(topic=topic)
return self._client.update_chat_thread(
return self._client.chat_thread.update_chat_thread(
chat_thread_id=self._thread_id,
update_chat_thread_request=update_topic_request,
**kwargs)
Expand Down Expand Up @@ -174,7 +174,7 @@ def send_read_receipt(
raise ValueError("message_id cannot be None.")

post_read_receipt_request = SendReadReceiptRequest(chat_message_id=message_id)
return self._client.send_chat_read_receipt(
return self._client.chat_thread.send_chat_read_receipt(
self._thread_id,
send_read_receipt_request=post_read_receipt_request,
**kwargs)
Expand All @@ -201,7 +201,7 @@ def list_read_receipts(
:dedent: 8
:caption: Listing read receipts.
"""
return self._client.list_chat_read_receipts(
return self._client.chat_thread.list_chat_read_receipts(
self._thread_id,
cls=lambda objs: [ChatMessageReadReceipt._from_generated(x) for x in objs], # pylint:disable=protected-access
**kwargs)
Expand All @@ -228,7 +228,7 @@ def send_typing_notification(
:dedent: 8
:caption: Sending typing notification.
"""
return self._client.send_typing_notification(self._thread_id, **kwargs)
return self._client.chat_thread.send_typing_notification(self._thread_id, **kwargs)

@distributed_trace
def send_message(
Expand Down Expand Up @@ -271,7 +271,7 @@ def send_message(
sender_display_name=sender_display_name
)

send_chat_message_result = self._client.send_chat_message(
send_chat_message_result = self._client.chat_thread.send_chat_message(
chat_thread_id=self._thread_id,
send_chat_message_request=create_message_request,
**kwargs)
Expand Down Expand Up @@ -305,7 +305,7 @@ def get_message(
if not message_id:
raise ValueError("message_id cannot be None.")

chat_message = self._client.get_chat_message(self._thread_id, message_id, **kwargs)
chat_message = self._client.chat_thread.get_chat_message(self._thread_id, message_id, **kwargs)
return ChatMessage._from_generated(chat_message) # pylint:disable=protected-access

@distributed_trace
Expand Down Expand Up @@ -335,12 +335,13 @@ def list_messages(
results_per_page = kwargs.pop("results_per_page", None)
start_time = kwargs.pop("start_time", None)

return self._client.list_chat_messages(
a = self._client.chat_thread.list_chat_messages(
self._thread_id,
max_page_size=results_per_page,
maxpagesize=results_per_page,
start_time=start_time,
cls=lambda objs: [ChatMessage._from_generated(x) for x in objs], # pylint:disable=protected-access
**kwargs)
return a

@distributed_trace
def update_message(
Expand Down Expand Up @@ -375,7 +376,7 @@ def update_message(

update_message_request = UpdateChatMessageRequest(content=content, priority=None)

return self._client.update_chat_message(
return self._client.chat_thread.update_chat_message(
chat_thread_id=self._thread_id,
chat_message_id=message_id,
update_chat_message_request=update_message_request,
Expand Down Expand Up @@ -409,7 +410,7 @@ def delete_message(
if not message_id:
raise ValueError("message_id cannot be None.")

return self._client.delete_chat_message(
return self._client.chat_thread.delete_chat_message(
chat_thread_id=self._thread_id,
chat_message_id=message_id,
**kwargs)
Expand Down Expand Up @@ -437,7 +438,7 @@ def list_participants(
:caption: Listing participants of chat thread.
"""

return self._client.list_chat_participants(
return self._client.chat_thread.list_chat_participants(
self._thread_id,
cls=lambda objs: [ChatThreadParticipant._from_generated(x) for x in objs], # pylint:disable=protected-access
**kwargs)
Expand Down Expand Up @@ -473,7 +474,7 @@ def add_participant(
participants = [thread_participant._to_generated()] # pylint:disable=protected-access
add_thread_participants_request = AddChatParticipantsRequest(participants=participants)

return self._client.add_chat_participants(
return self._client.chat_thread.add_chat_participants(
chat_thread_id=self._thread_id,
add_chat_participants_request=add_thread_participants_request,
**kwargs)
Expand Down Expand Up @@ -509,7 +510,7 @@ def add_participants(
participants = [m._to_generated() for m in thread_participants] # pylint:disable=protected-access
add_thread_participants_request = AddChatParticipantsRequest(participants=participants)

return self._client.add_chat_participants(
return self._client.chat_thread.add_chat_participants(
chat_thread_id=self._thread_id,
add_chat_participants_request=add_thread_participants_request,
**kwargs)
Expand Down Expand Up @@ -542,7 +543,7 @@ def remove_participant(
if not user:
raise ValueError("user cannot be None.")

return self._client.remove_chat_participant(
return self._client.chat_thread.remove_chat_participant(
chat_thread_id=self._thread_id,
chat_participant_id=user.identifier,
**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
from typing import Any

from ._configuration import AzureCommunicationChatServiceConfiguration
from .operations import AzureCommunicationChatServiceOperationsMixin
from .operations import ChatThreadOperations
from .operations import ChatOperations
from . import models


class AzureCommunicationChatService(AzureCommunicationChatServiceOperationsMixin):
class AzureCommunicationChatService(object):
"""Azure Communication Chat Service.

:ivar chat_thread: ChatThreadOperations operations
:vartype chat_thread: azure.communication.chat.operations.ChatThreadOperations
:ivar chat: ChatOperations operations
:vartype chat: azure.communication.chat.operations.ChatOperations
:param endpoint: The endpoint of the Azure Communication resource.
:type endpoint: str
"""
Expand All @@ -42,6 +47,10 @@ def __init__(
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)

self.chat_thread = ChatThreadOperations(
self._client, self._config, self._serialize, self._deserialize)
self.chat = ChatOperations(
self._client, self._config, self._serialize, self._deserialize)

def close(self):
# type: () -> None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
from msrest import Deserializer, Serializer

from ._configuration import AzureCommunicationChatServiceConfiguration
from .operations import AzureCommunicationChatServiceOperationsMixin
from .operations import ChatThreadOperations
from .operations import ChatOperations
from .. import models


class AzureCommunicationChatService(AzureCommunicationChatServiceOperationsMixin):
class AzureCommunicationChatService(object):
"""Azure Communication Chat Service.

:ivar chat_thread: ChatThreadOperations operations
:vartype chat_thread: azure.communication.chat.aio.operations.ChatThreadOperations
:ivar chat: ChatOperations operations
:vartype chat: azure.communication.chat.aio.operations.ChatOperations
:param endpoint: The endpoint of the Azure Communication resource.
:type endpoint: str
"""
Expand All @@ -37,6 +42,10 @@ def __init__(
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)

self.chat_thread = ChatThreadOperations(
self._client, self._config, self._serialize, self._deserialize)
self.chat = ChatOperations(
self._client, self._config, self._serialize, self._deserialize)

async def close(self) -> None:
await self._client.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._azure_communication_chat_service_operations import AzureCommunicationChatServiceOperationsMixin
from ._chat_thread_operations import ChatThreadOperations
from ._chat_operations import ChatOperations

__all__ = [
'AzureCommunicationChatServiceOperationsMixin',
'ChatThreadOperations',
'ChatOperations',
]
Loading