Skip to content

Commit 4654e35

Browse files
yogeshmoYogesh Mohanraj
andauthored
Addressing Archboard Feedback (Azure#27607)
* Adding AAD auth * Adding AAD auth to async client * Updating swagger README * Making SDK model-less * Fixing spelling * Updating recordings * Changing "message_id" to "messageId" * Addressing PR feedback * fixing linting errors * Fixing linting error * Standardizing utils across communication libraries * Updating the send message to accept IO input * Fixing linting error * Addressing PR feedback * Fixing linting error Co-authored-by: Yogesh Mohanraj <ymohanraj@microsoft.com>
1 parent 239f34f commit 4654e35

File tree

58 files changed

+3538
-2184
lines changed

Some content is hidden

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

58 files changed

+3538
-2184
lines changed

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414
from datetime import datetime
1515
from msrest.serialization import TZ_UTC
16-
from azure.core.credentials import AccessToken
16+
from azure.core.credentials import AccessToken, AzureKeyCredential
1717

1818

1919
def _convert_datetime_to_utc_int(input_datetime):
@@ -99,7 +99,7 @@ def create_access_token(token):
9999

100100
def get_authentication_policy(
101101
endpoint, # type: str
102-
credential, # type: Union[TokenCredential, str]
102+
credential, # type: Union[TokenCredential, AzureKeyCredential, str]
103103
decode_url=False, # type: bool
104104
is_async=False, # type: bool
105105
):
@@ -109,7 +109,7 @@ def get_authentication_policy(
109109
:param endpoint: The endpoint to which we are authenticating to.
110110
:type endpoint: str
111111
:param credential: The credential we use to authenticate to the service
112-
:type credential: Union[TokenCredential, str]
112+
:type credential: Union[TokenCredential, AzureKeyCredential, str]
113113
:param isAsync: For async clients there is a need to decode the url
114114
:type bool: isAsync or str
115115
:rtype: ~azure.core.pipeline.policies.BearerTokenCredentialPolicy or
@@ -126,7 +126,7 @@ def get_authentication_policy(
126126
from azure.core.pipeline.policies import BearerTokenCredentialPolicy
127127
return BearerTokenCredentialPolicy(
128128
credential, "https://communication.azure.com//.default")
129-
if isinstance(credential, str):
129+
if isinstance(credential, (AzureKeyCredential, str)):
130130
from .._shared.policy import HMACCredentialsPolicy
131131
return HMACCredentialsPolicy(endpoint, credential, decode_url=decode_url)
132132

sdk/communication/azure-communication-email/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Added the ability specify the API version by an optional `api_version` keyword parameter.
77

88
### Breaking Changes
9+
- Made the SDK Model-less. Objects are now constructed using a dictionary instead of a model.
910

1011
### Bugs Fixed
1112

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

Lines changed: 71 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ connection_string = "endpoint=https://<resource-name>.communication.azure.com/;a
3939
client = EmailClient.from_connection_string(connection_string);
4040
```
4141

42+
Alternatively, you can also use Active Directory authentication using DefaultAzureCredential.
43+
44+
```python
45+
from azure.communication.email import EmailClient
46+
from azure.identity import DefaultAzureCredential
47+
48+
# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
49+
endpoint = "https://<resource-name>.communication.azure.com"
50+
client = EmailClient(endpoint, DefaultAzureCredential())
51+
```
52+
4253
Email clients can also be authenticated using an [AzureKeyCredential][azure-key-credential].
4354

4455
```python
@@ -55,19 +66,22 @@ client = EmailClient(endpoint, credential);
5566
To send an email message, call the `send` function from the `EmailClient`.
5667

5768
```python
58-
content = EmailContent(
59-
subject="This is the subject",
60-
plain_text="This is the body",
61-
html= "<html><h1>This is the body</h1></html>",
62-
)
63-
64-
address = EmailAddress(email="customer@domain.com", display_name="Customer Name")
65-
66-
message = EmailMessage(
67-
sender="sender@contoso.com",
68-
content=content,
69-
recipients=EmailRecipients(to=[address])
70-
)
69+
message = {
70+
"content": {
71+
"subject": "This is the subject",
72+
"plainText": "This is the body",
73+
"html": "html><h1>This is the body</h1></html>"
74+
},
75+
"recipients": {
76+
"to": [
77+
{
78+
"email": "customer@domain.com",
79+
"displayName": "Customer Name"
80+
}
81+
]
82+
},
83+
"sender": "sender@contoso.com"
84+
}
7185

7286
response = client.send(message)
7387
```
@@ -77,28 +91,29 @@ response = client.send(message)
7791
To send an email message to multiple recipients, add a object for each recipient type and an object for each recipient.
7892

7993
```python
80-
content = EmailContent(
81-
subject="This is the subject",
82-
plain_text="This is the body",
83-
html= "<html><h1>This is the body</h1></html>",
84-
)
85-
86-
recipients = EmailRecipients(
87-
to=[
88-
EmailAddress(email="customer@domain.com", display_name="Customer Name"),
89-
EmailAddress(email="customer2@domain.com", display_name="Customer Name 2"),
94+
message = {
95+
"content": {
96+
"subject": "This is the subject",
97+
"plainText": "This is the body",
98+
"html": "html><h1>This is the body</h1></html>"
99+
},
100+
"recipients": {
101+
"to": [
102+
{"email": "customer@domain.com", "displayName": "Customer Name"},
103+
{"email": "customer2@domain.com", "displayName": "Customer Name 2"}
90104
],
91-
cc=[
92-
EmailAddress(email="ccCustomer@domain.com", display_name="CC Customer Name"),
93-
EmailAddress(email="ccCustomer2@domain.com", display_name="CC Customer Name 2"),
105+
"cc": [
106+
{"email": "ccCustomer@domain.com", "displayName": "CC Customer Name"},
107+
{"email": "ccCustomer2@domain.com", "displayName": "CC Customer Name 2"}
94108
],
95-
bcc=[
96-
EmailAddress(email="bccCustomer@domain.com", display_name="BCC Customer Name"),
97-
EmailAddress(email="bccCustomer2@domain.com", display_name="BCC Customer Name 2"),
109+
"bcc": [
110+
{"email": "bccCustomer@domain.com", "displayName": "BCC Customer Name"},
111+
{"email": "bccCustomer2@domain.com", "displayName": "BCC Customer Name 2"}
98112
]
99-
)
113+
},
114+
"sender": "sender@contoso.com"
115+
}
100116

101-
message = EmailMessage(sender="sender@contoso.com", content=content, recipients=recipients)
102117
response = client.send(message)
103118
```
104119

@@ -109,42 +124,45 @@ Azure Communication Services support sending email with attachments.
109124
```python
110125
import base64
111126

112-
content = EmailContent(
113-
subject="This is the subject",
114-
plain_text="This is the body",
115-
html= "<html><h1>This is the body</h1></html>",
116-
)
117-
118-
address = EmailAddress(email="customer@domain.com", display_name="Customer Name")
119-
120127
with open("C://readme.txt", "r") as file:
121128
file_contents = file.read()
122129

123130
file_bytes_b64 = base64.b64encode(bytes(file_contents, 'utf-8'))
124131

125-
attachment = EmailAttachment(
126-
name="attachment.txt",
127-
attachment_type="txt",
128-
content_bytes_base64=file_bytes_b64.decode()
129-
)
130-
131-
message = EmailMessage(
132-
sender="sender@contoso.com",
133-
content=content,
134-
recipients=EmailRecipients(to=[address]),
135-
attachments=[attachment]
136-
)
132+
message = {
133+
"content": {
134+
"subject": "This is the subject",
135+
"plainText": "This is the body",
136+
"html": "html><h1>This is the body</h1></html>"
137+
},
138+
"recipients": {
139+
"to": [
140+
{
141+
"email": "customer@domain.com",
142+
"displayName": "Customer Name"
143+
}
144+
]
145+
},
146+
"sender": "sender@contoso.com",
147+
"attachments": [
148+
{
149+
"name": "attachment.txt",
150+
"attachmentType": "txt",
151+
"contentBytesBase64": file_bytes_b64.decode()
152+
}
153+
]
154+
}
137155

138156
response = client.send(message)
139157
```
140158

141159
### Get Email Message Status
142160

143-
The result from the `send` call contains a `message_id` which can be used to query the status of the email.
161+
The result from the `send` call contains a `messageId` which can be used to query the status of the email.
144162

145163
```python
146164
response = client.send(message)
147-
status = client.get_send_status(response.message_id)
165+
status = client.get_sent_status(response['messageId'])
148166
```
149167

150168
## Troubleshooting

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,4 @@
66

77
from ._email_client import EmailClient
88

9-
from ._generated.models import (
10-
EmailMessage,
11-
EmailCustomHeader,
12-
EmailContent,
13-
EmailImportance,
14-
EmailRecipients,
15-
EmailAddress,
16-
EmailAttachment,
17-
EmailAttachmentType,
18-
SendEmailResult,
19-
SendStatus,
20-
SendStatusResult
21-
)
22-
23-
__all__ = [
24-
'EmailClient',
25-
'EmailMessage',
26-
'EmailCustomHeader',
27-
'EmailContent',
28-
'EmailImportance',
29-
'EmailRecipients',
30-
'EmailAddress',
31-
'EmailAttachment',
32-
'EmailAttachmentType',
33-
'SendEmailResult',
34-
'SendStatus',
35-
'SendStatusResult',
36-
]
9+
__all__ = ['EmailClient']

0 commit comments

Comments
 (0)