Skip to content
Closed
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
6 changes: 6 additions & 0 deletions sdk/communication/azure-communication-messages/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"commit": "03c105f96d40a33dd7196727818297057ec643ae",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/communication/Communication.Messages",
"@azure-tools/typespec-python": "0.39.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"CrossLanguagePackageId": "Azure.Communication.MessagesService",
"CrossLanguageDefinitionId": {
"azure.communication.messages.models.ActionBindings": "Azure.Communication.MessagesService.ActionBindings",
"azure.communication.messages.models.ActionGroup": "Azure.Communication.MessagesService.ActionGroup",
"azure.communication.messages.models.MessageContent": "Azure.Communication.MessagesService.MessageContent",
"azure.communication.messages.models.ActionGroupContent": "Azure.Communication.MessagesService.ActionGroupContent",
"azure.communication.messages.models.ActionGroupItem": "Azure.Communication.MessagesService.ActionGroupItem",
"azure.communication.messages.models.NotificationContent": "Azure.Communication.MessagesService.NotificationContent",
"azure.communication.messages.models.AudioNotificationContent": "Azure.Communication.MessagesService.AudioNotificationContent",
"azure.communication.messages.models.ButtonContent": "Azure.Communication.MessagesService.ButtonContent",
"azure.communication.messages.models.ButtonSetContent": "Azure.Communication.MessagesService.ButtonSetContent",
"azure.communication.messages.models.DocumentMessageContent": "Azure.Communication.MessagesService.DocumentMessageContent",
"azure.communication.messages.models.DocumentNotificationContent": "Azure.Communication.MessagesService.DocumentNotificationContent",
"azure.communication.messages.models.ImageMessageContent": "Azure.Communication.MessagesService.ImageMessageContent",
"azure.communication.messages.models.ImageNotificationContent": "Azure.Communication.MessagesService.ImageNotificationContent",
"azure.communication.messages.models.InteractiveMessage": "Azure.Communication.MessagesService.InteractiveMessage",
"azure.communication.messages.models.InteractiveNotificationContent": "Azure.Communication.MessagesService.InteractiveNotificationContent",
"azure.communication.messages.models.LinkContent": "Azure.Communication.MessagesService.LinkContent",
"azure.communication.messages.models.MediaNotificationContent": "Azure.Communication.MessagesService.MediaNotificationContent",
"azure.communication.messages.models.MessageReceipt": "Azure.Communication.MessagesService.MessageReceipt",
"azure.communication.messages.models.MessageTemplate": "Azure.Communication.MessagesService.MessageTemplate",
"azure.communication.messages.models.MessageTemplateBindings": "Azure.Communication.MessagesService.MessageTemplateBindings",
"azure.communication.messages.models.MessageTemplateValue": "Azure.Communication.MessagesService.MessageTemplateValue",
"azure.communication.messages.models.MessageTemplateDocument": "Azure.Communication.MessagesService.MessageTemplateDocument",
"azure.communication.messages.models.MessageTemplateImage": "Azure.Communication.MessagesService.MessageTemplateImage",
"azure.communication.messages.models.MessageTemplateItem": "Azure.Communication.MessagesService.MessageTemplateItem",
"azure.communication.messages.models.MessageTemplateLocation": "Azure.Communication.MessagesService.MessageTemplateLocation",
"azure.communication.messages.models.MessageTemplateQuickAction": "Azure.Communication.MessagesService.MessageTemplateQuickAction",
"azure.communication.messages.models.MessageTemplateText": "Azure.Communication.MessagesService.MessageTemplateText",
"azure.communication.messages.models.MessageTemplateVideo": "Azure.Communication.MessagesService.MessageTemplateVideo",
"azure.communication.messages.models.ReactionNotificationContent": "Azure.Communication.MessagesService.ReactionNotificationContent",
"azure.communication.messages.models.SendMessageResult": "Azure.Communication.MessagesService.SendMessageResult",
"azure.communication.messages.models.StickerNotificationContent": "Azure.Communication.MessagesService.StickerNotificationContent",
"azure.communication.messages.models.TemplateNotificationContent": "Azure.Communication.MessagesService.TemplateNotificationContent",
"azure.communication.messages.models.TextMessageContent": "Azure.Communication.MessagesService.TextMessageContent",
"azure.communication.messages.models.TextNotificationContent": "Azure.Communication.MessagesService.TextNotificationContent",
"azure.communication.messages.models.VideoMessageContent": "Azure.Communication.MessagesService.VideoMessageContent",
"azure.communication.messages.models.VideoNotificationContent": "Azure.Communication.MessagesService.VideoNotificationContent",
"azure.communication.messages.models.WhatsAppButtonActionBindings": "Azure.Communication.MessagesService.WhatsAppButtonActionBindings",
"azure.communication.messages.models.WhatsAppListActionBindings": "Azure.Communication.MessagesService.WhatsAppListActionBindings",
"azure.communication.messages.models.WhatsAppMessageTemplateBindings": "Azure.Communication.MessagesService.WhatsAppMessageTemplateBindings",
"azure.communication.messages.models.WhatsAppMessageTemplateBindingsButton": "Azure.Communication.MessagesService.WhatsAppMessageTemplateBindingsButton",
"azure.communication.messages.models.WhatsAppMessageTemplateBindingsComponent": "Azure.Communication.MessagesService.WhatsAppMessageTemplateBindingsComponent",
"azure.communication.messages.models.WhatsAppMessageTemplateItem": "Azure.Communication.MessagesService.WhatsAppMessageTemplateItem",
"azure.communication.messages.models.WhatsAppUrlActionBindings": "Azure.Communication.MessagesService.WhatsAppUrlActionBindings",
"azure.communication.messages.models.RepeatabilityResult": "Azure.Core.RepeatabilityResult",
"azure.communication.messages.models.CommunicationMessageKind": "Azure.Communication.MessagesService.CommunicationMessageKind",
"azure.communication.messages.models.MessageContentKind": "Azure.Communication.MessagesService.MessageContentKind",
"azure.communication.messages.models.MessageActionBindingKind": "Azure.Communication.MessagesService.MessageActionBindingKind",
"azure.communication.messages.models.MessageTemplateValueKind": "Azure.Communication.MessagesService.MessageTemplateValueKind",
"azure.communication.messages.models.MessageTemplateBindingsKind": "Azure.Communication.MessagesService.MessageTemplateBindingsKind",
"azure.communication.messages.models.WhatsAppMessageButtonSubType": "Azure.Communication.MessagesService.WhatsAppMessageButtonSubType",
"azure.communication.messages.models.MessageTemplateStatus": "Azure.Communication.MessagesService.MessageTemplateStatus",
"azure.communication.messages.models.CommunicationMessagesChannel": "Azure.Communication.MessagesService.CommunicationMessagesChannel",
"azure.communication.messages.NotificationMessagesClient.send": "Azure.Communication.MessagesService.NotificationMessagesClient.send",
"azure.communication.messages.NotificationMessagesClient.download_media": "ClientForAcsMessages.NotificationMessagesClient.downloadMedia",
"azure.communication.messages.MessageTemplateClient.list_templates": "Azure.Communication.MessagesService.MessageTemplateClient.listTemplates"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NotificationMessagesClient(NotificationMessagesClientOperationsMixin):
https://my-resource.communication.azure.com. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a token
credential type or a AzureKeyCredential type. Required.
credential type or a key credential type. Required.
:type credential: ~azure.core.credentials.TokenCredential or
~azure.core.credentials.AzureKeyCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand Down Expand Up @@ -109,7 +109,7 @@ class MessageTemplateClient(MessageTemplateClientOperationsMixin):
https://my-resource.communication.azure.com. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a token
credential type or a AzureKeyCredential type. Required.
credential type or a key credential type. Required.
:type credential: ~azure.core.credentials.TokenCredential or
~azure.core.credentials.AzureKeyCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NotificationMessagesClientConfiguration: # pylint: disable=too-many-insta
https://my-resource.communication.azure.com. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a token
credential type or a AzureKeyCredential type. Required.
credential type or a key credential type. Required.
:type credential: ~azure.core.credentials.TokenCredential or
~azure.core.credentials.AzureKeyCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand Down Expand Up @@ -83,7 +83,7 @@ class MessageTemplateClientConfiguration: # pylint: disable=too-many-instance-a
https://my-resource.communication.azure.com. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a token
credential type or a AzureKeyCredential type. Required.
credential type or a key credential type. Required.
:type credential: ~azure.core.credentials.TokenCredential or
~azure.core.credentials.AzureKeyCredential
:keyword api_version: The API version to use for this operation. Default value is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,34 @@ def __ne__(self, other: typing.Any) -> bool:
return not self.__eq__(other)

def keys(self) -> typing.KeysView[str]:
"""
:returns: a set-like object providing a view on D's keys
:rtype: ~typing.KeysView
"""
return self._data.keys()

def values(self) -> typing.ValuesView[typing.Any]:
"""
:returns: an object providing a view on D's values
:rtype: ~typing.ValuesView
"""
return self._data.values()

def items(self) -> typing.ItemsView[str, typing.Any]:
"""
:returns: set-like object providing a view on D's items
:rtype: ~typing.ItemsView
"""
return self._data.items()

def get(self, key: str, default: typing.Any = None) -> typing.Any:
"""
Get the value for key if key is in the dictionary, else default.
:param str key: The key to look up.
:param any default: The value to return if key is not in the dictionary. Defaults to None
:returns: D[k] if k in D, else d.
:rtype: any
"""
try:
return self[key]
except KeyError:
Expand All @@ -397,17 +416,38 @@ def pop(self, key: str, default: _T) -> _T: ...
def pop(self, key: str, default: typing.Any) -> typing.Any: ...

def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
"""
Removes specified key and return the corresponding value.
:param str key: The key to pop.
:param any default: The value to return if key is not in the dictionary
:returns: The value corresponding to the key.
:rtype: any
:raises KeyError: If key is not found and default is not given.
"""
if default is _UNSET:
return self._data.pop(key)
return self._data.pop(key, default)

def popitem(self) -> typing.Tuple[str, typing.Any]:
"""
Removes and returns some (key, value) pair
:returns: The (key, value) pair.
:rtype: tuple
:raises KeyError: if D is empty.
"""
return self._data.popitem()

def clear(self) -> None:
"""
Remove all items from D.
"""
self._data.clear()

def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
"""
Updates D from mapping/iterable E and F.
:param any args: Either a mapping object or an iterable of key-value pairs.
"""
self._data.update(*args, **kwargs)

@typing.overload
Expand All @@ -417,6 +457,13 @@ def setdefault(self, key: str, default: None = None) -> None: ...
def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...

def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
"""
Same as calling D.get(k, d), and setting D[k]=d if k not found
:param str key: The key to look up.
:param any default: The value to set if key is not in the dictionary
:returns: D[k] if k in D, else d.
:rtype: any
"""
if default is _UNSET:
return self._data.setdefault(key)
return self._data.setdefault(key, default)
Expand Down Expand Up @@ -910,6 +957,19 @@ def _failsafe_deserialize(
return None


def _failsafe_deserialize_xml(
deserializer: typing.Any,
value: typing.Any,
) -> typing.Any:
try:
return _deserialize_xml(deserializer, value)
except DeserializationError:
_LOGGER.warning(
"Ran into a deserialization error. Ignoring since this is failsafe deserialization", exc_info=True
)
return None


class _RestField:
def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,132 +6,9 @@
Follow our quickstart for examples: https://aka.ms/azsdk/python/dpcodegen/python/customize
"""
from typing import List, Any, Union
from urllib.parse import urlparse
from azure.core.credentials import TokenCredential, AzureKeyCredential
from ._shared.utils import parse_connection_str
from ._client import (
NotificationMessagesClient as NotificationMessagesClientGenerated,
MessageTemplateClient as MessageTemplateClientGenerated,
)
from ._shared.auth_policy_utils import get_authentication_policy
from ._api_versions import DEFAULT_VERSION
from typing import List


class NotificationMessagesClient(NotificationMessagesClientGenerated):
"""A client to interact with the AzureCommunicationService Messaging service.
This client provides operations to create and update jobs, policies and workers.
:param str endpoint:
The endpoint of the Azure Communication resource.
:param Union[TokenCredential, AsyncTokenCredential] credential:
The credentials with which to authenticate
:keyword api_version: Azure Communication Messaging API version.
Default value is "2023-11-01".
Note that overriding this default value may result in unsupported behavior.
"""

def __init__(self, endpoint: str, credential: Union[TokenCredential, AzureKeyCredential], **kwargs: Any) -> None:
if not credential:
raise ValueError("credential can not be None")

try:
if not endpoint.lower().startswith("http"):
endpoint = "https://" + endpoint
except AttributeError:
raise ValueError("Host URL must be a string") # pylint:disable=raise-missing-from

parsed_url = urlparse(endpoint.rstrip("/"))
if not parsed_url.netloc:
raise ValueError("Invalid URL: {}".format(endpoint))

self._endpoint = endpoint
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION)
self._authentication_policy = get_authentication_policy(endpoint, credential)
self._credential = credential
super().__init__(
self._endpoint,
self._credential,
authentication_policy=self._authentication_policy,
api_version=self._api_version,
**kwargs
)

@classmethod
def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "NotificationMessagesClient":
"""Create NotificationMessagesClient from a Connection String.
:param conn_str: Azure communication service connection string. Required.
:type conn_str: str
:return: instance of NotificationMessagesClient
:rtype:
~azure.communication.messages.NotificationMessagesClient
"""
endpoint, access_key = parse_connection_str(conn_str)
return cls(endpoint, AzureKeyCredential(access_key), **kwargs)


class MessageTemplateClient(MessageTemplateClientGenerated):
"""A client to interact with the AzureCommunicationService Messaging service.
This client provides Advanced Messaging.
:param str endpoint:
The endpoint of the Azure Communication resource.
:param Union[TokenCredential, AsyncTokenCredential] credential:
The credentials with which to authenticate
:keyword api_version: Azure Communication Messages API version. Default value is "2024-02-01".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str
"""

def __init__(self, endpoint: str, credential: Union[TokenCredential, AzureKeyCredential], **kwargs: Any) -> "None":
if not credential:
raise ValueError("credential can not be None")

try:
if not endpoint.lower().startswith("http"):
endpoint = "https://" + endpoint
except AttributeError:
raise ValueError("Host URL must be a string") # pylint: disable=raise-missing-from

parsed_url = urlparse(endpoint.rstrip("/"))
if not parsed_url.netloc:
raise ValueError("Invalid URL: {}".format(endpoint))

self._endpoint = endpoint
self._api_version = kwargs.pop("api_version", DEFAULT_VERSION)
self._authentication_policy = get_authentication_policy(endpoint, credential)
self._credential = credential
super().__init__(
self._endpoint,
self._credential,
authentication_policy=self._authentication_policy,
api_version=self._api_version,
**kwargs
)

@classmethod
def from_connection_string(cls, conn_str: str, **kwargs: Any) -> "MessageTemplateClient":
"""Create MessageTemplateClient from a Connection String.
:param conn_str: Azure communication service connection string. Required.
:type conn_str: str
:return: instance of MessageTemplateClient
:rtype:
~azure.communication.messages.MessageTemplateClient
"""
endpoint, access_key = parse_connection_str(conn_str)
return cls(endpoint, AzureKeyCredential(access_key), **kwargs)


__all__: List[str] = [
"NotificationMessagesClient",
"MessageTemplateClient",
] # Add all objects you want publicly available to users at this package level
__all__: List[str] = [] # Add all objects you want publicly available to users at this package level


def patch_sdk():
Expand Down
Loading