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

Communication chat preview4 #16905

Merged
merged 16 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -4,18 +4,18 @@
from ._generated.models import (
SendChatMessageResult,
ChatThreadInfo,
ChatMessageType
ChatMessageType,
CreateChatThreadResult,
AddChatParticipantsResult
)
from ._shared.user_credential import CommunicationTokenCredential
from ._shared.user_token_refresh_options import CommunicationTokenRefreshOptions

from ._models import (
ChatThreadParticipant,
ChatMessage,
ChatThread,
ChatMessageReadReceipt,
ChatMessageContent
)
from ._shared.models import CommunicationUserIdentifier

__all__ = [
'ChatClient',
Expand All @@ -26,10 +26,9 @@
'SendChatMessageResult',
'ChatThread',
'ChatThreadInfo',
'CommunicationTokenCredential',
'CommunicationTokenRefreshOptions',
'CommunicationUserIdentifier',
'ChatThreadParticipant',
'ChatMessageType'
'ChatMessageType',
'CreateChatThreadResult',
'AddChatParticipantsResult'
]
__version__ = VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def create_chat_thread(
repeatability_request_id=None, # type: Optional[str]
**kwargs # type: Any
):
# type: (...) -> ChatThreadClient
# type: (...) -> CreateChatThreadResult
"""Creates a chat thread.

:param topic: Required. The thread topic.
Expand All @@ -137,8 +137,8 @@ def create_chat_thread(
representing a client-generated, globally unique for all time, identifier for the request. If not
specified, a new unique id would be generated.
:type repeatability_request_id: str
:return: ChatThreadClient
:rtype: ~azure.communication.chat.ChatThreadClient
:return: CreateChatThreadResult
:rtype: ~azure.communication.chat.CreateChatThreadResult
:raises: ~azure.core.exceptions.HttpResponseError, ValueError

.. admonition:: Example:
Expand All @@ -148,7 +148,7 @@ def create_chat_thread(
:end-before: [END create_thread]
:language: python
:dedent: 8
:caption: Creating ChatThreadClient by creating a new chat thread.
:caption: Creating ChatThread by creating a new chat thread.
"""
if not topic:
raise ValueError("topic cannot be None.")
Expand All @@ -174,13 +174,8 @@ def create_chat_thread(
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=thread_id,
**kwargs
)

return create_chat_thread_result

@distributed_trace
def get_chat_thread(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
ChatMessageReadReceipt
)

from ._utils import _to_utc_datetime # pylint: disable=unused-import
from ._utils import _to_utc_datetime, CommunicationUserIdentifierConverter # pylint: disable=unused-import
from ._version import SDK_MONIKER

if TYPE_CHECKING:
Expand Down Expand Up @@ -339,7 +339,8 @@ def list_messages(
"""Gets a list of messages from a thread.

:keyword int results_per_page: The maximum number of messages to be returned per page.
:keyword ~datetime.datetime start_time: The start time where the range query.
:keyword ~datetime.datetime start_time: The earliest point in time to get messages up to.
The timestamp should be in RFC3339 format: ``yyyy-MM-ddTHH:mm:ssZ``.
:keyword callable cls: A custom type or function that will be passed the direct response
:return: An iterator like instance of ChatMessage
:rtype: ~azure.core.paging.ItemPaged[~azure.communication.chat.ChatMessage]
Expand Down Expand Up @@ -478,14 +479,14 @@ def add_participant(
thread_participant, # type: ChatThreadParticipant
**kwargs # type: Any
):
# type: (...) -> None
# type: (...) -> AddChatParticipantsResult
"""Adds single thread participant to a thread. If participant already exist, no change occurs.

:param thread_participant: Required. Single thread participant to be added to the thread.
:type thread_participant: ~azure.communication.chat.ChatThreadParticipant
:keyword callable cls: A custom type or function that will be passed the direct response
:return: None, or the result of cls(response)
:rtype: None
:return: AddChatParticipantsResult, or the result of cls(response)
:rtype: ~azure.communication.chat.AddChatParticipantsResult
:raises: ~azure.core.exceptions.HttpResponseError, ValueError

.. admonition:: Example:
Expand Down Expand Up @@ -514,14 +515,14 @@ def add_participants(
thread_participants, # type: list[ChatThreadParticipant]
**kwargs # type: Any
):
# type: (...) -> None
# type: (...) -> AddChatParticipantsResult
"""Adds thread participants to a thread. If participants already exist, no change occurs.

:param thread_participants: Required. Thread participants to be added to the thread.
:type thread_participants: list[~azure.communication.chat.ChatThreadParticipant]
:keyword callable cls: A custom type or function that will be passed the direct response
:return: None, or the result of cls(response)
:rtype: None
:return: AddChatParticipantsResult, or the result of cls(response)
:rtype: ~azure.communication.chat.AddChatParticipantsResult
:raises: ~azure.core.exceptions.HttpResponseError, ValueError

.. admonition:: Example:
Expand Down Expand Up @@ -574,7 +575,7 @@ def remove_participant(

return self._client.chat_thread.remove_chat_participant(
chat_thread_id=self._thread_id,
chat_participant_id=user.identifier,
participant_communication_identifier=CommunicationUserIdentifierConverter.to_identifier_model(user),
**kwargs)

def close(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
super(AzureCommunicationChatServiceConfiguration, self).__init__(**kwargs)

self.endpoint = endpoint
self.api_version = "2020-11-01-preview3"
self.api_version = "2021-01-27-preview4"
kwargs.setdefault('sdk_moniker', 'azurecommunicationchatservice/{}'.format(VERSION))
self._configure(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
super(AzureCommunicationChatServiceConfiguration, self).__init__(**kwargs)

self.endpoint = endpoint
self.api_version = "2020-11-01-preview3"
self.api_version = "2021-01-27-preview4"
kwargs.setdefault('sdk_moniker', 'azurecommunicationchatservice/{}'.format(VERSION))
self._configure(**kwargs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ async def create_chat_thread(
:type create_chat_thread_request: ~azure.communication.chat.models.CreateChatThreadRequest
:param repeatability_request_id: If specified, the client directs that the request is
repeatable; that is, that the client can make the request multiple times with the same
Repeatability-Request-ID and get back an appropriate response without the server executing the
request multiple times. The value of the Repeatability-Request-ID is an opaque string
Repeatability-Request-Id and get back an appropriate response without the server executing the
request multiple times. The value of the Repeatability-Request-Id is an opaque string
representing a client-generated, globally unique for all time, identifier for the request. It
is recommended to use version 4 (random) UUIDs.
:type repeatability_request_id: str
Expand All @@ -75,7 +75,7 @@ async def create_chat_thread(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"

Expand All @@ -93,7 +93,7 @@ async def create_chat_thread(
# Construct headers
header_parameters = {} # type: Dict[str, Any]
if repeatability_request_id is not None:
header_parameters['repeatability-Request-ID'] = self._serialize.header("repeatability_request_id", repeatability_request_id, 'str')
header_parameters['repeatability-Request-Id'] = self._serialize.header("repeatability_request_id", repeatability_request_id, 'str')
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')

Expand Down Expand Up @@ -146,7 +146,7 @@ def list_chat_threads(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

def prepare_request(next_link=None):
Expand Down Expand Up @@ -230,7 +230,7 @@ async def get_chat_thread(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

# Construct URL
Expand Down Expand Up @@ -291,7 +291,7 @@ async def delete_chat_thread(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

# Construct URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def list_chat_read_receipts(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

def prepare_request(next_link=None):
Expand Down Expand Up @@ -162,7 +162,7 @@ async def send_chat_read_receipt(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"

Expand Down Expand Up @@ -228,7 +228,7 @@ async def send_chat_message(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"

Expand Down Expand Up @@ -301,7 +301,7 @@ def list_chat_messages(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

def prepare_request(next_link=None):
Expand Down Expand Up @@ -390,7 +390,7 @@ async def get_chat_message(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

# Construct URL
Expand Down Expand Up @@ -458,7 +458,7 @@ async def update_chat_message(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/merge-patch+json")
accept = "application/json"

Expand Down Expand Up @@ -525,7 +525,7 @@ async def delete_chat_message(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

# Construct URL
Expand Down Expand Up @@ -584,7 +584,7 @@ async def send_typing_notification(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

# Construct URL
Expand Down Expand Up @@ -648,7 +648,7 @@ def list_chat_participants(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
accept = "application/json"

def prepare_request(next_link=None):
Expand Down Expand Up @@ -711,7 +711,7 @@ async def get_next(next_link=None):
async def remove_chat_participant(
self,
chat_thread_id: str,
chat_participant_id: str,
participant_communication_identifier: "_models.CommunicationIdentifierModel",
**kwargs
) -> None:
"""Remove a participant from a thread.
Expand All @@ -720,8 +720,9 @@ async def remove_chat_participant(

:param chat_thread_id: Thread id to remove the participant from.
:type chat_thread_id: str
:param chat_participant_id: Id of the thread participant to remove from the thread.
:type chat_participant_id: str
:param participant_communication_identifier: Id of the thread participant to remove from the
thread.
:type participant_communication_identifier: ~azure.communication.chat.models.CommunicationIdentifierModel
:keyword callable cls: A custom type or function that will be passed the direct response
:return: None, or the result of cls(response)
:rtype: None
Expand All @@ -737,15 +738,15 @@ async def remove_chat_participant(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"

# Construct URL
url = self.remove_chat_participant.metadata['url'] # type: ignore
path_format_arguments = {
'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True),
'chatThreadId': self._serialize.url("chat_thread_id", chat_thread_id, 'str'),
'chatParticipantId': self._serialize.url("chat_participant_id", chat_participant_id, 'str'),
}
url = self._client.format_url(url, **path_format_arguments)

Expand All @@ -755,9 +756,13 @@ async def remove_chat_participant(

# Construct headers
header_parameters = {} # type: Dict[str, Any]
header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str')
header_parameters['Accept'] = self._serialize.header("accept", accept, 'str')

request = self._client.delete(url, query_parameters, header_parameters)
body_content_kwargs = {} # type: Dict[str, Any]
body_content = self._serialize.body(participant_communication_identifier, 'CommunicationIdentifierModel')
body_content_kwargs['content'] = body_content
request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs)
pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
response = pipeline_response.http_response

Expand All @@ -768,7 +773,7 @@ async def remove_chat_participant(
if cls:
return cls(pipeline_response, None, {})

remove_chat_participant.metadata = {'url': '/chat/threads/{chatThreadId}/participants/{chatParticipantId}'} # type: ignore
remove_chat_participant.metadata = {'url': '/chat/threads/{chatThreadId}/participants/:remove'} # type: ignore

async def add_chat_participants(
self,
Expand Down Expand Up @@ -799,7 +804,7 @@ async def add_chat_participants(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/json")
accept = "application/json"

Expand Down Expand Up @@ -868,7 +873,7 @@ async def update_chat_thread(
503: lambda response: HttpResponseError(response=response, model=self._deserialize(_models.CommunicationErrorResponse, response)),
}
error_map.update(kwargs.pop('error_map', {}))
api_version = "2020-11-01-preview3"
api_version = "2021-01-27-preview4"
content_type = kwargs.pop("content_type", "application/merge-patch+json")
accept = "application/json"

Expand Down
Loading