diff --git a/certified-connectors/Azure Communication Services Email/apiDefinition.swagger.json b/certified-connectors/Azure Communication Services Email/apiDefinition.swagger.json index 3b29f48595..981897723a 100644 --- a/certified-connectors/Azure Communication Services Email/apiDefinition.swagger.json +++ b/certified-connectors/Azure Communication Services Email/apiDefinition.swagger.json @@ -3,7 +3,7 @@ "info": { "title": "Azure Communication Email", "description": "Connector to send Email using the domains linked to the Azure Communication Services in your subscription.", - "version": "1.0", + "version": "2.0", "x-ms-api-annotation": { "status": "Production" }, @@ -15,15 +15,26 @@ }, "host": "api.contoso.com", "basePath": "/", - "schemes": ["https"], - "consumes": ["application/json"], - "produces": ["application/json"], + "schemes": [ + "https" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "paths": { "/emails:send": { "post": { - "summary": "Send email (Preview)", - "description": "Sends an email message to one or more recipients.", + "summary": "Send email (Preview) - DEPRECATED", + "description": "Sends an email message to one or more recipients - DEPRECATED", "operationId": "SendEmail", + "deprecated": true, + "x-ms-api-annotation": { + "family": "SendEmail", + "revision": 1 + }, "parameters": [ { "$ref": "#/parameters/PreviewApiVersion" @@ -52,7 +63,19 @@ "minItems": 1, "maxItems": 100, "items": { - "$ref": "#/definitions/EmailAddress" + "type": "object", + "description": "An object representing the To email address.", + "properties": { + "email": { + "title": "Email (To)", + "type": "string", + "description": "The email address of main recipient.", + "x-ms-visibility": "important" + } + }, + "required": [ + "email" + ] }, "x-ms-visibility": "important" }, @@ -61,7 +84,19 @@ "title": "CC", "description": "Email CC recipients.", "items": { - "$ref": "#/definitions/EmailAddress" + "type": "object", + "description": "An object representing the CC email address.", + "properties": { + "email": { + "type": "string", + "title": "Email (CC)", + "description": "The email address of additional recipient.", + "x-ms-visibility": "important" + } + }, + "required": [ + "email" + ] }, "x-ms-visibility": "advanced" }, @@ -70,7 +105,19 @@ "title": "BCC", "description": "Email BCC recipients.", "items": { - "$ref": "#/definitions/EmailAddress" + "type": "object", + "description": "An object representing the BCC email address.", + "properties": { + "email": { + "type": "string", + "title": "Email (BCC)", + "description": "The email address of additional recipient who is invisible in the email chain.", + "x-ms-visibility": "important" + } + }, + "required": [ + "email" + ] }, "x-ms-visibility": "advanced" } @@ -80,33 +127,26 @@ ] }, "content": { - "type": "object", - "description": "Content.", - "properties": { - "subject": { - "type": "string", - "title": "Subject", - "description": "Specify the subject of the email.", - "x-ms-visibility": "important" - }, - "html": { - "format": "html", - "type": "string", - "title": "Body", - "description": "Specify the body of the email.", - "x-ms-visibility": "important" - } - }, - "required": [ - "subject" - ] + "$ref": "#/definitions/ContentDetails" }, "replyTo": { "type": "array", "title": "Reply To", "description": "Email addresses where recipients' replies will be sent to.", "items": { - "$ref": "#/definitions/EmailAddress" + "type": "object", + "description": "An object representing the Reply To email address.", + "properties": { + "email": { + "type": "string", + "title": "Email (Reply To)", + "description": "The email address where recipients' replies will be sent to.", + "x-ms-visibility": "important" + } + }, + "required": [ + "email" + ] }, "x-ms-visibility": "advanced" }, @@ -185,11 +225,222 @@ } } }, + "/emails:sendGAVersion": { + "post": { + "summary": "Send email", + "description": "Sends an email message to one or more recipients.", + "operationId": "SendEmailGAVersion", + "deprecated": false, + "x-ms-api-annotation": { + "family": "SendEmail", + "revision": 2 + }, + "parameters": [ + { + "$ref": "#/parameters/ApiVersionParameter" + }, + { + "name": "emailMessage", + "in": "body", + "required": true, + "schema": { + "type": "object", + "properties": { + "senderAddress": { + "type": "string", + "title": "From", + "description": "The sender email address from a verified domain.11", + "x-ms-visibility": "important" + }, + "importance": { + "type": "string", + "title": "Importance", + "enum": [ "High", "Normal", "Low" ], + "default": "Normal", + "x-ms-visibility": "important" + }, + "recipients": { + "type": "object", + "description": "Recipients for the email.", + "properties": { + "to": { + "type": "array", + "title": "To", + "description": "Email To recipients.", + "minItems": 1, + "maxItems": 100, + "items": { + "type": "object", + "description": "An object representing the To email address.", + "properties": { + "address": { + "title": "Email (To)", + "type": "string", + "description": "The email address of main recipient.", + "x-ms-visibility": "important" + } + }, + "required": [ + "address" + ] + }, + "x-ms-visibility": "important" + }, + "CC": { + "type": "array", + "title": "CC", + "description": "Email CC recipients.", + "items": { + "type": "object", + "description": "An object representing the CC email address.", + "properties": { + "address": { + "type": "string", + "title": "Email (CC)", + "description": "The email address of additional recipient.", + "x-ms-visibility": "important" + } + }, + "required": [ + "address" + ] + }, + "x-ms-visibility": "advanced" + }, + "bCC": { + "type": "array", + "title": "BCC", + "description": "Email BCC recipients.", + "items": { + "type": "object", + "description": "An object representing the BCC email address.", + "properties": { + "address": { + "type": "string", + "title": "Email (BCC)", + "description": "The email address of additional recipient who is invisible in the email chain.", + "x-ms-visibility": "important" + } + }, + "required": [ + "address" + ] + }, + "x-ms-visibility": "advanced" + } + }, + "required": [ + "to" + ] + }, + "content": { + "$ref": "#/definitions/ContentDetails" + }, + "replyTo": { + "type": "array", + "title": "Reply To", + "description": "Email addresses where recipients' replies will be sent to.", + "items": { + "type": "object", + "description": "An object representing the Reply To email address.", + "properties": { + "address": { + "type": "string", + "title": "Email (Reply To)", + "description": "The email address where recipients' replies will be sent to.", + "x-ms-visibility": "important" + } + }, + "required": [ + "address" + ] + }, + "x-ms-visibility": "advanced" + }, + "attachments": { + "type": "array", + "title": "Attachments", + "description": "List of attachments.", + "x-ms-visibility": "advanced", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "title": "Name", + "description": "Attachment name with extension.", + "x-ms-visibility": "important" + }, + "contentType": { + "type": "string", + "title": "Type", + "description": "The type of attachment file." + }, + "contentInBase64": { + "format": "byte", + "type": "string", + "title": "Content", + "description": "Attachment content.", + "x-ms-visibility": "important" + } + }, + "required": [ + "name", + "contentType", + "contentInBase64" + ] + } + }, + "headers": { + "description": "Custom headers to be passed.", + "type": "array", + "title": "Header", + "x-ms-client-name": "CustomHeaders", + "items": { + "$ref": "#/definitions/EmailCustomHeader" + } + }, + "userEngagementTrackingDisabled": { + "type": "boolean", + "title": "Disable User Engagement Tracking", + "description": "Indicates whether user engagement tracking should be disabled for this request if the resource-level user engagement tracking setting was already enabled in the control plane.", + "x-ms-visibility": "advanced" + } + }, + "required": [ + "senderAddress", + "recipients", + "content" + ] + } + } + ], + "responses": { + "202": { + "description": "Accepted.", + "headers": { + "x-ms-request-id": { + "type": "string", + "x-ms-summary": "Message ID" + } + }, + "schema": { + "$ref": "#/definitions/EmailSendResult" + } + } + } + } + }, "/emails/{messageId}/status": { "get": { - "summary": "Get email message status (Preview)", - "description": "Gets the status of an email message sent previously.", + "summary": "Get email message status (Preview) - DEPRECATED", + "description": "Gets the status of an email message sent previously - DEPRECATED", "operationId": "GetMessageStatus", + "deprecated": true, + "x-ms-api-annotation": { + "family": "GetMessageStatus", + "revision": 1 + }, "parameters": [ { "$ref": "#/parameters/PreviewApiVersion" @@ -224,26 +475,53 @@ } } } - } - }, - "definitions": { - "EmailAddress": { - "type": "object", - "description": "An object representing the email address.", - "properties": { - "email": { - "type": "string", - "title": "Email", - "description": "Email address.", - "x-ms-visibility": "important" + }, + "/emails/operations/{operationId}": { + "get": { + "summary": "Get email message status", + "description": "Gets the status of an email message sent previously.", + "operationId": "GetMessageStatusGAVersion", + "deprecated": false, + "x-ms-api-annotation": { + "family": "GetMessageStatus", + "revision": 2 + }, + "parameters": [ + { + "$ref": "#/parameters/ApiVersionParameter" + }, + { + "name": "operationId", + "in": "path", + "required": true, + "type": "string", + "x-ms-summary": "Operation ID", + "x-ms-url-encoding": "single", + "x-ms-visibility": "important", + "description": "Operation ID from a previous call to send email." + } + ], + "responses": { + "200": { + "description": "Success.", + "schema": { + "$ref": "#/definitions/EmailSendResult" + } + } } - }, - "required": [ - "email" - ] + } } }, "parameters": { + "ApiVersionParameter": { + "name": "api-version", + "in": "query", + "required": true, + "type": "string", + "default": "2023-03-31", + "description": "Version of API to invoke.", + "x-ms-visibility": "internal" + }, "PreviewApiVersion": { "name": "api-version", "in": "query", @@ -254,6 +532,147 @@ "x-ms-visibility": "internal" } }, + "definitions": { + "ErrorDetail": { + "type": "object", + "description": "The error detail.", + "properties": { + "code": { + "readOnly": true, + "type": "string", + "description": "The error code." + }, + "message": { + "readOnly": true, + "type": "string", + "description": "The error message." + }, + "target": { + "readOnly": true, + "type": "string", + "description": "The error target." + }, + "details": { + "readOnly": true, + "type": "array", + "items": { + "$ref": "#/definitions/ErrorDetail" + }, + "x-ms-identifiers": [], + "description": "The error details." + }, + "additionalInfo": { + "readOnly": true, + "type": "array", + "items": { + "$ref": "#/definitions/ErrorAdditionalInfo" + }, + "x-ms-identifiers": [], + "description": "The error additional info." + } + } + }, + "ErrorAdditionalInfo": { + "type": "object", + "properties": { + "type": { + "readOnly": true, + "type": "string", + "description": "The additional info type." + }, + "info": { + "readOnly": true, + "type": "object", + "description": "The additional info." + } + }, + "description": "The resource management error additional info." + }, + "ErrorResponse": { + "type": "object", + "title": "Error response", + "description": "Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData error response format.).", + "properties": { + "error": { + "description": "The error object.", + "$ref": "#/definitions/ErrorDetail" + } + } + }, + "EmailSendResult": { + "description": "Status of the long running operation", + "required": [ + "id", + "status" + ], + "type": "object", + "properties": { + "id": { + "description": "The unique id of the operation. Use a UUID.", + "type": "string" + }, + "status": { + "description": "Status of operation.", + "enum": [ + "NotStarted", + "Running", + "Succeeded", + "Failed", + "Canceled" + ], + "type": "string", + "x-ms-enum": { + "name": "EmailSendStatus", + "modelAsString": true + } + }, + "error": { + "description": "Error details when status is a non-success terminal state.", + "$ref": "#/definitions/ErrorDetail" + } + } + }, + "EmailCustomHeader": { + "description": "Custom header for email.", + "type": "object", + "required": [ + "name", + "value" + ], + "properties": { + "name": { + "description": "Enter key.", + "type": "string" + }, + "value": { + "description": "Enter value.", + "type": "string" + } + } + }, + "ContentDetails": { + "type": "object", + "description": "Content.", + "properties": { + "subject": { + "type": "string", + "title": "Subject", + "description": "Specify the subject of the email.", + "x-ms-visibility": "important" + }, + "html": { + "format": "html", + "type": "string", + "title": "Body", + "description": "Specify the body of the email.", + "x-ms-visibility": "important" + } + }, + "required": [ + "subject" + ] + } + }, "responses": {}, "securityDefinitions": { "api_key": { @@ -279,4 +698,4 @@ "propertyValue": "Communication" } ] -} \ No newline at end of file +} diff --git a/certified-connectors/Azure Communication Services Email/script.csx b/certified-connectors/Azure Communication Services Email/script.csx index af8b672267..e2b24faf28 100644 --- a/certified-connectors/Azure Communication Services Email/script.csx +++ b/certified-connectors/Azure Communication Services Email/script.csx @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. using System; @@ -14,21 +14,23 @@ public class Script : ScriptBase public override async Task ExecuteAsync() { // Check if the operation ID matches what is specified in the OpenAPI definition of the connector - if (Context.OperationId == "SendEmail") + if (Context.OperationId == "SendEmail" || Context.OperationId == "SendEmailGAVersion") { AddRepeatabilityHeadersToRequest(); - await PrepareRequestEmailAttachments(); + await PrepareRequestEmailAttachmentsAndHeaders(); } string[] operationIds = { "SendEmail", - "GetMessageStatus" + "GetMessageStatus", + "SendEmailGAVersion", + "GetMessageStatusGAVersion" }; if (Array.Exists(operationIds, opId => opId == Context.OperationId)) { await PrepareRequestWithEndpointAndHMAC(); return await Context.SendAsync(Context.Request, CancellationToken) - .ConfigureAwait(continueOnCapturedContext: false); + .ConfigureAwait(continueOnCapturedContext: false); } // Handle an invalid operation ID @@ -46,7 +48,7 @@ public class Script : ScriptBase Context.Request.Headers.TryAddWithoutValidation("repeatability-request-id", requestId); } - public async Task PrepareRequestEmailAttachments() + public async Task PrepareRequestEmailAttachmentsAndHeaders() { var requestContentAsString = await Context.Request.Content.ReadAsStringAsync(); var requestContentAsJson = JObject.Parse(requestContentAsString); @@ -61,6 +63,52 @@ public class Script : ScriptBase } } + if (Context.OperationId == "SendEmailGAVersion") + { + if (requestContentAsJson.ContainsKey("headers") || requestContentAsJson.ContainsKey("importance")) + { + var updatedHeader = string.Empty; + if (requestContentAsJson.ContainsKey("importance")) + { + var importanceValue = "4"; + if ((string)requestContentAsJson["importance"] == "High") + { + importanceValue = "2"; + } + else if ((string)requestContentAsJson["importance"] == "Normal") + { + importanceValue = "3"; + } + + updatedHeader = "{" + "\"x-priority\":\"" + importanceValue + "\""; + } + + if (requestContentAsJson.ContainsKey("headers")) + { + foreach (JObject jObject in requestContentAsJson["headers"]) + { + if (updatedHeader != string.Empty) + { + updatedHeader = updatedHeader + ","; + } + else + { + updatedHeader = "{"; + } + + updatedHeader = updatedHeader + "\"" + jObject["name"] + "\":\"" + jObject["value"] + "\""; + } + } + + updatedHeader = updatedHeader + "}"; + requestContentAsJson.Remove("headers"); + requestContentAsJson.Add("headers", JObject.Parse(updatedHeader)); + } + + var builderUri = new UriBuilder(Context.Request.RequestUri.ToString().Replace("sendGAVersion", "send")); + Context.Request.RequestUri = builderUri.Uri; + } + var body = requestContentAsJson.ToString(); Context.Request.Content = CreateJsonContent(body); }