azure.communication.chat package

class azure.communication.chat.ChatClient(endpoint: str, credential: CommunicationTokenCredential, **kwargs: Any)[source]

A client to interact with the AzureCommunicationService Chat gateway.

This client provides operations to create chat thread, delete chat thread, get chat thread client by thread id, list chat threads.

Parameters
  • endpoint (str) – The endpoint of the Azure Communication resource.

  • credential (CommunicationTokenCredential) – The credentials with which to authenticate.

Example:

Creating the ChatClient from a URL and token.
from azure.communication.chat import ChatClient, CommunicationTokenCredential

# set `endpoint` to an existing ACS endpoint
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))
close()None[source]
create_chat_thread(topic: str, **kwargs: Any)CreateChatThreadResult[source]

Creates a chat thread.

Parameters

topic (str) – Required. The thread topic.

Keyword Arguments
  • thread_participants (List[ChatParticipant]) – Optional. Participants to be added to the thread.

  • idempotency_token (str) – Optional. If specified, the client directs that the request is repeatable; that is, the client can make the request multiple times with the same Idempotency_Token and get back an appropriate response without the server executing the request multiple times. The value of the Idempotency_Token is an opaque string representing a client-generated, globally unique for all time, identifier for the request. If not specified, a new unique id would be generated.

Returns

CreateChatThreadResult

Return type

CreateChatThreadResult

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Creating a new chat thread.
from datetime import datetime

from azure.communication.chat import(
    ChatClient,
    ChatParticipant,
    CommunicationUserIdentifier,
    CommunicationTokenCredential
)

# set `endpoint` to an existing ACS endpoint
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))

topic = "test topic"
participants = [ChatParticipant(
    identifier=user,
    display_name='name',
    share_history_time=datetime.utcnow()
)]

# creates a new chat_thread everytime
create_chat_thread_result = chat_client.create_chat_thread(topic, thread_participants=participants)

# creates a new chat_thread if not exists
idempotency_token = 'b66d6031-fdcc-41df-8306-e524c9f226b8' # unique identifier
create_chat_thread_result_w_repeatability_id = chat_client.create_chat_thread(
    topic,
    thread_participants=participants,
    idempotency_token=idempotency_token
)
delete_chat_thread(thread_id: str, **kwargs: Any)None[source]

Deletes a chat thread.

Parameters

thread_id (str) – Required. Thread id to delete.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Deleting a chat thread.
from azure.communication.chat import ChatClient, CommunicationTokenCredential

# set `endpoint` to an existing ACS endpoint
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))

# set `thread_id` to an existing chat thread id
chat_client.delete_chat_thread(thread_id)
get_chat_thread_client(thread_id: str, **kwargs: Any)ChatThreadClient[source]

Get ChatThreadClient by providing a thread_id.

Parameters

thread_id (str) – Required. The thread id.

Returns

ChatThreadClient

Return type

ChatThreadClient

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Retrieving the ChatThreadClient from an existing chat thread id.
from azure.communication.chat import ChatClient, CommunicationTokenCredential

# set `endpoint` to an existing ACS endpoint
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))

# set `thread_id` to an existing chat thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id)
list_chat_threads(**kwargs)ItemPaged[ChatThreadItem][source]

Gets the list of chat threads of a user.

Keyword Arguments
  • results_per_page (int) – The maximum number of chat threads returned per page.

  • start_time (datetime) – The earliest point in time to get chat threads up to.

Returns

An iterator like instance of ChatThreadItem

Return type

ItemPaged[ChatThreadItem]

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Listing chat threads.
from azure.communication.chat import ChatClient, CommunicationTokenCredential
from datetime import datetime, timedelta

# set `endpoint` to an existing ACS endpoint
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))
start_time = datetime.utcnow() - timedelta(days=2)
chat_threads = chat_client.list_chat_threads(results_per_page=5, start_time=start_time)

print("list_threads succeeded with results_per_page is 5, and were created since 2 days ago.")
for chat_thread_item_page in chat_threads.by_page():
    for chat_thread_item in chat_thread_item_page:
        print("thread id:", chat_thread_item.id)
class azure.communication.chat.ChatError(*, code: str, message: str, **kwargs)[source]

The Communication Services error.

Variables are only populated by the server, and will be ignored when sending a request.

All required parameters must be populated in order to send to Azure.

Parameters
  • code (str) – Required. The error code.

  • message (str) – Required. The error message.

Variables
  • target (str) – The error target.

  • details (list[ChatError]) – Further details about specific errors that led to this error.

  • inner_error (ChatError) – The inner error if any.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list

class azure.communication.chat.ChatMessage(**kwargs: Any)[source]

Chat message.

Variables are only populated by the server, and will be ignored when sending a request.

Variables
  • id (str) – The id of the chat message. This id is server generated.

  • type – Type of the chat message. Possible values include: “text”, “html”, “topicUpdated”, “participantAdded”, “participantRemoved”.

  • sequence_id – Sequence of the chat message in the conversation.

  • version (str) – Version of the chat message.

  • content – Content of the chat message.

  • sender_display_name – The display name of the chat message sender. This property is used to populate sender name for push notifications.

  • created_on – The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ.

  • sender – The chat message sender.

  • deleted_on – The timestamp when the chat message was deleted. The timestamp is in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ.

  • edited_on – The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ.

  • metadata – Message metadata.

class azure.communication.chat.ChatMessageContent(**kwargs: Any)[source]

Content of a chat message.

Variables
  • message – Chat message content for messages of types text or html.

  • topic – Chat message content for messages of type topicUpdated.

  • participants – Chat message content for messages of types participantAdded or participantRemoved.

  • initiator – Chat message content for messages of types participantAdded or participantRemoved.

class azure.communication.chat.ChatMessageReadReceipt(**kwargs: Any)[source]

A chat message read receipt indicates the time a chat message was read by a recipient.

Variables are only populated by the server, and will be ignored when sending a request.

Variables
  • sender (CommunicationIdentifier) – Read receipt sender.

  • chat_message_id (str) – Id for the chat message that has been read. This id is generated by the server.

  • read_on (datetime) – Read receipt timestamp. The timestamp is in ISO8601 format: yyyy-MM- ddTHH:mm:ssZ.

class azure.communication.chat.ChatMessageType(value)[source]

The chat message type.

HTML = 'html'
PARTICIPANT_ADDED = 'participantAdded'
PARTICIPANT_REMOVED = 'participantRemoved'
TEXT = 'text'
TOPIC_UPDATED = 'topicUpdated'
class azure.communication.chat.ChatParticipant(**kwargs: Any)[source]

A participant of the chat thread.

All required parameters must be populated in order to send to Azure.

Variables
  • identifier – Required. The communication identifier.

  • display_name – Display name for the chat thread participant.

  • share_history_time – Time from which the chat history is shared with the participant. The timestamp is in ISO8601 format: yyyy-MM-ddTHH:mm:ssZ.

class azure.communication.chat.ChatThreadClient(endpoint: str, credential: CommunicationTokenCredential, thread_id: str, **kwargs: Any)[source]

A client to interact with the AzureCommunicationService Chat gateway. Instances of this class is normally retrieved by ChatClient.get_chat_thread_client()

This client provides operations to add participant(s) to chat thread, remove participant from chat thread, send message, delete message, update message, send typing notifications, send and list read receipt

Variables

thread_id (str) – Chat thread id.

Parameters
  • endpoint (str) – The endpoint of the Azure Communication resource.

  • credential (CommunicationTokenCredential) – The credentials with which to authenticate. The value contains a User Access Token

  • thread_id (str) – The unique thread id.

Example:

Creating the ChatThreadClient.
from datetime import datetime
from azure.communication.chat import (
    ChatClient,
    ChatParticipant,
    CommunicationUserIdentifier,
    CommunicationTokenCredential
)
# retrieve `token` using CommunicationIdentityClient.get_token method
# set `endpoint` to ACS service endpoint
# create `user` using CommunicationIdentityClient.create_user method for new users;
# else for existing users set `user` = CommunicationUserIdentifier(some_user_id)
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))
topic = "test topic"
participants = [ChatParticipant(
    identifier=user,
    display_name='name',
    share_history_time=datetime.utcnow()
)]
create_chat_thread_result = chat_client.create_chat_thread(topic, thread_participants=participants)
chat_thread_client = chat_client.get_chat_thread_client(create_chat_thread_result.chat_thread.id)
add_participants(thread_participants: List[ChatParticipant], **kwargs: Any)List[Tuple[ChatParticipant, ChatError]][source]

Adds thread participants to a thread. If participants already exist, no change occurs.

If all participants are added successfully, then an empty list is returned; otherwise, a list of tuple(chat_thread_participant, chat_error) is returned, of failed participants and its respective error

Parameters

thread_participants (List[ChatParticipant]) – Thread participants to be added to the thread.

Returns

List[Tuple[ChatParticipant, ChatError]]

Return type

List[Tuple[ChatParticipant, ChatError]]

Raises

~azure.core.exceptions.HttpResponseError

Example:

Adding participants to chat thread.
from azure.communication.chat import ChatParticipant
from datetime import datetime

def decide_to_retry(error):
    """
    Custom logic to decide whether to retry to add or not
    """
    return True

# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

# create `user` using CommunicationIdentityClient.create_user method for new users;
# else for existing users set `user` = CommunicationUserIdentifier(some_user_id)
new_participant = ChatParticipant(
    identifier=user,
    display_name='name',
    share_history_time=datetime.utcnow())

# create list containing one or more participants
thread_participants = [new_participant]
result = chat_thread_client.add_participants(thread_participants)

# list of participants which were unsuccessful to be added to chat thread
retry = [p for p, e in result if decide_to_retry(e)]
if retry:
    chat_thread_client.add_participants(retry)
close()None[source]
delete_message(message_id: str, **kwargs: Any)None[source]

Deletes a message.

Parameters

message_id (str) – Required. The message id.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Deleting a message.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

# set `message_id` to an existing message id
chat_thread_client.delete_message(message_id)
get_message(message_id: str, **kwargs: Any)ChatMessage[source]

Gets a message by id.

Parameters

message_id (str) – Required. The message id.

Returns

ChatMessage

Return type

ChatMessage

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Retrieving a message by message id.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

# set `message_id` to an existing message id
chat_message = chat_thread_client.get_message(message_id)

print("Message received: ChatMessage: content=", chat_message.content.message, ", id=", chat_message.id)
get_properties(**kwargs: Any)ChatThreadProperties[source]

Gets the properties of the chat thread.

Returns

ChatThreadProperties

Return type

ChatThreadProperties

Raises

~azure.core.exceptions.HttpResponseError

Example:

Retrieving chat thread properties by chat thread id.
from azure.communication.chat import ChatClient, CommunicationTokenCredential

# set `endpoint` to an existing ACS endpoint
chat_client = ChatClient(endpoint, CommunicationTokenCredential(token))
chat_thread_client = chat_client.get_chat_thread_client(thread_id)
chat_thread_properties = chat_thread_client.get_properties()
print('Expected Thread Id: ', thread_id, ' Actual Value: ', chat_thread_properties.id)
list_messages(**kwargs: Any)ItemPaged[ChatMessage][source]

Gets a list of messages from a thread.

Keyword Arguments
  • results_per_page (int) – The maximum number of messages to be returned per page.

  • start_time (datetime) – The earliest point in time to get messages up to.

The timestamp should be in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ. :return: An iterator like instance of ChatMessage :rtype: ~azure.core.paging.ItemPaged[~azure.communication.chat.ChatMessage] :raises: ~azure.core.exceptions.HttpResponseError, ValueError

Example:

Listing messages of a chat thread.
from datetime import datetime, timedelta

# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

start_time = datetime.utcnow() - timedelta(days=1)
chat_messages = chat_thread_client.list_messages(results_per_page=1, start_time=start_time)

print("list_messages succeeded with results_per_page is 1, and start time is yesterday UTC")
for chat_message_page in chat_messages.by_page():
    for chat_message in chat_message_page:
        print("ChatMessage: message=", chat_message.content.message)
list_participants(**kwargs: Any)ItemPaged[ChatParticipant][source]

Gets the participants of a thread.

Keyword Arguments
  • results_per_page (int) – The maximum number of participants to be returned per page.

  • skip (int) – Skips participants up to a specified position in response.

Returns

An iterator like instance of ChatParticipant

Return type

ItemPaged[ChatParticipant]

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Listing participants of chat thread.

# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

chat_thread_participants = chat_thread_client.list_participants()

for chat_thread_participant_page in chat_thread_participants.by_page():
    for chat_thread_participant in chat_thread_participant_page:
        print("ChatParticipant: ", chat_thread_participant)
list_read_receipts(**kwargs: Any)ItemPaged[ChatMessageReadReceipt][source]

Gets read receipts for a thread.

Keyword Arguments
  • results_per_page (int) – The maximum number of chat message read receipts to be returned per page.

  • skip (int) – Skips chat message read receipts up to a specified position in response.

Returns

An iterator like instance of ChatMessageReadReceipt

Return type

ItemPaged[ChatMessageReadReceipt]

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Listing read receipts.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

read_receipts = chat_thread_client.list_read_receipts()

for read_receipt_page in read_receipts.by_page():
    for read_receipt in read_receipt_page:
        print(read_receipt)
remove_participant(identifier: CommunicationIdentifier, **kwargs: Any)None[source]

Remove a participant from a thread.

Parameters

identifier (CommunicationIdentifier) – Required. Identifier of the thread participant to remove from the thread.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Removing participant from chat thread.
# Option 1 : Iterate through all participants, find and delete Fred Flinstone
chat_thread_participants = chat_thread_client.list_participants()

for chat_thread_participant_page in chat_thread_participants.by_page():
    for chat_thread_participant in chat_thread_participant_page:
        print("ChatParticipant: ", chat_thread_participant)
        if chat_thread_participant.identifier.properties['id'] == user1.properties['id']:
            print("Found Fred!")
            chat_thread_client.remove_participant(chat_thread_participant.identifier)
            print("Fred has been removed from the thread...")
            break

# Option 2: Directly remove Wilma Flinstone
unique_identifier = user2.properties['id'] # in real scenario the identifier would need to be retrieved from elsewhere
chat_thread_client.remove_participant(CommunicationUserIdentifier(unique_identifier))
print("Wilma has been removed from the thread...")
send_message(content: str, **kwargs: Any)SendChatMessageResult[source]

Sends a message to a thread.

Parameters

content (str) – Required. Chat message content.

Keyword Arguments
  • chat_message_type (Union[str, ChatMessageType]) – The chat message type. Possible values include: “text”, “html”. Default: ChatMessageType.TEXT

  • sender_display_name (str) – The display name of the message sender. This property is used to populate sender name for push notifications.

  • str] metadata (dict[str,) – Message metadata.

Returns

SendChatMessageResult

Return type

SendChatMessageResult

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Sending a message.
from azure.communication.chat import ChatMessageType

# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

# Scenario 1: Send message without specifying chat_message_type
send_message_result = chat_thread_client.send_message(
    "Hello! My name is Fred Flinstone",
    sender_display_name="Fred Flinstone")
send_message_result_id = send_message_result.id

# Scenario 2: Send message specifying chat_message_type
send_message_result_w_type = chat_thread_client.send_message(
    "Hello! My name is Wilma Flinstone",
    sender_display_name="Wilma Flinstone",
    chat_message_type=ChatMessageType.TEXT) # equivalent to setting chat_message_type='text'
send_message_result_w_type_id = send_message_result_w_type.id
# Verify message content
print("First Message:", chat_thread_client.get_message(send_message_result_id).content.message)
print("Second Message:", chat_thread_client.get_message(send_message_result_w_type_id).content.message)
send_read_receipt(message_id: str, **kwargs: Any)None[source]

Posts a read receipt event to a chat thread, on behalf of a user.

Parameters

message_id (str) – Required. Id of the latest message read by current user.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Sending read receipt of a chat message.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

# set `message_id` to an existing message id
chat_thread_client.send_read_receipt(message_id)
send_typing_notification(**kwargs: Any)None[source]

Posts a typing event to a thread, on behalf of a user.

Keyword Arguments

sender_display_name (str) – The display name of the typing notification sender. This property is used to populate sender name for push notifications.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Send typing notification.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

chat_thread_client.send_typing_notification()
update_message(message_id: str, content: Optional[str] = None, **kwargs: Any)None[source]

Updates a message.

Parameters
  • message_id (str) – Required. The message id.

  • content (str) – Chat message content.

Keyword Arguments

str] metadata (dict[str,) – Message metadata.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Updating an already sent message.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)

# set `message_id` to an existing message id
previous_content = chat_thread_client.get_message(message_id).content.message
content = "updated content"
chat_thread_client.update_message(message_id, content=content)

current_content = chat_thread_client.get_message(message_id).content.message

print("Chat Message Updated: Previous value: ", previous_content, ", Current value: ", current_content)
update_topic(topic: Optional[str] = None, **kwargs: Any)None[source]

Updates a thread’s properties.

Parameters

topic (str) – Thread topic. If topic is not specified, the update will succeed but chat thread properties will not be changed.

Returns

None

Return type

None

Raises

~azure.core.exceptions.HttpResponseError, ValueError

Example:

Updating chat thread.
# set `thread_id` to an existing thread id
chat_thread_client = chat_client.get_chat_thread_client(thread_id=thread_id)
chat_thread_properties = chat_thread_client.get_properties()
previous_topic = chat_thread_properties.topic

topic = "updated thread topic"
chat_thread_client.update_topic(topic=topic)

chat_thread_properties = chat_thread_client.get_properties()
updated_topic = chat_thread_properties.topic
print("Chat Thread Topic Update: Previous value: ", previous_topic, ", Current value: ", updated_topic)
property thread_id

Gets the thread id from the client.

Return type

str

class azure.communication.chat.ChatThreadItem(*, id: str, topic: str, deleted_on: Optional[datetime.datetime] = None, **kwargs)[source]

Summary information of a chat thread.

Variables are only populated by the server, and will be ignored when sending a request.

All required parameters must be populated in order to send to Azure.

Parameters
  • id (str) – Required. Chat thread id.

  • topic (str) – Required. Chat thread topic.

  • deleted_on (datetime) – The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ.

Variables

last_message_received_on (datetime) – The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: yyyy-MM-ddTHH:mm:ssZ.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list

class azure.communication.chat.ChatThreadProperties(**kwargs: Any)[source]

ChatThreadProperties.

Variables are only populated by the server, and will be ignored when sending a request.

Variables
  • id (str) – Chat thread id.

  • topic – Chat thread topic.

  • created_on (datetime) – The timestamp when the chat thread was created. The timestamp is in ISO8601 format: yyyy-MM-ddTHH:mm:ssZ.

  • created_by (CommunicationIdentifier) – the chat thread owner.

class azure.communication.chat.CommunicationIdentifier(*args, **kwds)[source]

Communication Identifier.

Variables
kind: Optional[str] = None
properties: Mapping[str, Any] = {}
raw_id: Optional[str] = None
class azure.communication.chat.CommunicationIdentifierKind(value)[source]

Communication Identifier Kind.

COMMUNICATION_USER = 'communication_user'
MICROSOFT_TEAMS_USER = 'microsoft_teams_user'
PHONE_NUMBER = 'phone_number'
UNKNOWN = 'unknown'
class azure.communication.chat.CommunicationTokenCredential(token, **kwargs)[source]

Credential type used for authenticating to an Azure Communication service. :param str token: The token used to authenticate to an Azure Communication service :keyword token_refresher: The token refresher to provide capacity to fetch fresh token :raises: TypeError

get_token(*scopes, **kwargs)[source]

The value of the configured token. :rtype: ~azure.core.credentials.AccessToken

class azure.communication.chat.CommunicationUserIdentifier(id: str, **kwargs: Any)[source]

Represents a user in Azure Communication Service.

Variables
  • raw_id (str) – Optional raw ID of the identifier.

  • kind (str or CommunicationIdentifierKind) – The type of identifier.

  • Any] properties (Mapping[str,) –

    The properties of the identifier. The keys in this mapping include:

    • `id`(str): ID of the Communication user as returned from Azure Communication Identity.

Parameters

id (str) – ID of the Communication user as returned from Azure Communication Identity.

kind = 'communication_user'
class azure.communication.chat.CommunicationUserProperties(**kwargs)
clear()None.  Remove all items from D.
copy()a shallow copy of D
fromkeys(value=None, /)

Returns a new dict with keys from iterable and values equal to value.

get(k[, d])D[k] if k in D, else d.  d defaults to None.
items()a set-like object providing a view on D’s items
keys()a set-like object providing a view on D’s keys
pop(k[, d])v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem()(k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d])D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F)None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()an object providing a view on D’s values
id: str
class azure.communication.chat.CreateChatThreadResult(**kwargs: Any)[source]

Result of the create chat thread operation.

Variables
  • chat_thread – Chat thread.

  • errors – Errors encountered during the creation of the chat thread.

class azure.communication.chat.MicrosoftTeamsUserIdentifier(user_id: str, **kwargs: Any)[source]

Represents an identifier for a Microsoft Teams user.

Variables
  • raw_id (str) – Optional raw ID of the identifier.

  • kind (str or CommunicationIdentifierKind) – The type of identifier.

  • properties (Mapping) –

    The properties of the identifier. The keys in this mapping include:

    • `user_id`(str): The id of the Microsoft Teams user. If the user isn’t anonymous, the id is the AAD object id of the user.

    • is_anonymous (bool): Set this to true if the user is anonymous for example when joining a meeting with a share link.

    • cloud (str): Cloud environment that this identifier belongs to.

Parameters

user_id (str) – Microsoft Teams user id.

Keyword Arguments
  • is_anonymous (bool) – True if the identifier is anonymous. Default value is False.

  • cloud (str or CommunicationCloudEnvironment) – Cloud environment that the user belongs to. Default value is PUBLIC.

kind = 'microsoft_teams_user'
class azure.communication.chat.MicrosoftTeamsUserProperties(**kwargs)
clear()None.  Remove all items from D.
copy()a shallow copy of D
fromkeys(value=None, /)

Returns a new dict with keys from iterable and values equal to value.

get(k[, d])D[k] if k in D, else d.  d defaults to None.
items()a set-like object providing a view on D’s items
keys()a set-like object providing a view on D’s keys
pop(k[, d])v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem()(k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d])D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F)None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()an object providing a view on D’s values
cloud: str
is_anonymous: bool
user_id: str
class azure.communication.chat.PhoneNumberIdentifier(value: str, **kwargs: Any)[source]

Represents a phone number.

Variables
Parameters

value (str) – The phone number.

kind = 'phone_number'
class azure.communication.chat.PhoneNumberProperties(**kwargs)
clear()None.  Remove all items from D.
copy()a shallow copy of D
fromkeys(value=None, /)

Returns a new dict with keys from iterable and values equal to value.

get(k[, d])D[k] if k in D, else d.  d defaults to None.
items()a set-like object providing a view on D’s items
keys()a set-like object providing a view on D’s keys
pop(k[, d])v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem()(k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d])D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F)None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()an object providing a view on D’s values
value: str
class azure.communication.chat.SendChatMessageResult(*, id: str, **kwargs)[source]

Result of the send message operation.

All required parameters must be populated in order to send to Azure.

Parameters

id (str) – Required. A server-generated message id.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list

class azure.communication.chat.UnknownIdentifier(identifier: str)[source]

Represents an identifier of an unknown type.

It will be encountered in communications with endpoints that are not identifiable by this version of the SDK.

Variables
Parameters

identifier (str) – The ID of the identifier.

kind = 'unknown'