diff --git a/sdk/communication/communication-sms/CHANGELOG.md b/sdk/communication/communication-sms/CHANGELOG.md index f34fe3cc195f..43d2f563c639 100644 --- a/sdk/communication/communication-sms/CHANGELOG.md +++ b/sdk/communication/communication-sms/CHANGELOG.md @@ -1,14 +1,11 @@ # Release History -## 1.2.0-beta.3 (Unreleased) - -### Features Added - -### Breaking Changes +## 1.2.0-beta.3 (2024-12-19) ### Bugs Fixed -### Other Changes +- Fixed Opt Out Remove action + ## 1.2.0-beta.2 (2024-12-10) diff --git a/sdk/communication/communication-sms/assets.json b/sdk/communication/communication-sms/assets.json index 58fc59782111..994158f9d237 100644 --- a/sdk/communication/communication-sms/assets.json +++ b/sdk/communication/communication-sms/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "js", "TagPrefix": "js/communication/communication-sms", - "Tag": "js/communication/communication-sms_128752023a" + "Tag": "js/communication/communication-sms_49df303bfc" } diff --git a/sdk/communication/communication-sms/samples/v1/typescript/README.md b/sdk/communication/communication-sms/samples/v1/typescript/README.md index 344a4ee8b510..e4a2d007829e 100644 --- a/sdk/communication/communication-sms/samples/v1/typescript/README.md +++ b/sdk/communication/communication-sms/samples/v1/typescript/README.md @@ -17,6 +17,9 @@ These sample programs show how to use the TypeScript client libraries for Azure | [sendSms.ts][sendsms] | Send an SMS message to 1 or more recipients | | [sendSmsWithOptions.ts][sendsmswithoptions] | Configure SMS options when sending a message | | [usingAadAuth.ts][usingaadauth] | Use AAD token credentials when sending a SMS message. | +| [optOutCheck.ts][optoutcheck] | Check if recipients opted out of receiving messages | +| [optOutAdd.ts][optoutadd] | Opt out recipients from receiving messages | +| [optOutRemove.ts][optoutremove] | Remove recipients from Opt Out list | ## Prerequisites @@ -78,3 +81,6 @@ Take a look at our [API Documentation][apiref] for more information about the AP [createinstance_azurecommunicationservicesaccount]: https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource [package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-sms/README.md [typescript]: https://www.typescriptlang.org/docs/home.html +[optoutcheck]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-sms/samples/v1/typescript/src/optOutCheck.ts +[optoutadd]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-sms/samples/v1/typescript/src/optOutAdd.ts +[optoutremove]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-sms/samples/v1/typescript/src/optOutRemove.ts diff --git a/sdk/communication/communication-sms/samples/v1/typescript/src/optOutAdd.ts b/sdk/communication/communication-sms/samples/v1/typescript/src/optOutAdd.ts new file mode 100644 index 000000000000..d19d810944f3 --- /dev/null +++ b/sdk/communication/communication-sms/samples/v1/typescript/src/optOutAdd.ts @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Opt out 1 or more recipients from receiving SMS messages + */ + +import { SmsClient } from "@azure/communication-sms"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("== Opt Out Add =="); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://.communication.azure.com/;"; + + // create new client + const client = new SmsClient(connectionString); + + // construct send parameters + const from = process.env.FROM_PHONE_NUMBER || process.env.AZURE_PHONE_NUMBER || ""; + let phoneNumbers: string[]; + if (process.env.TO_PHONE_NUMBERS !== undefined) { + phoneNumbers = process.env.TO_PHONE_NUMBERS.split(","); + } else if (process.env.AZURE_PHONE_NUMBER !== undefined) { + phoneNumbers = [process.env.AZURE_PHONE_NUMBER]; + } else { + phoneNumbers = ["", ""]; + } + + // send add opt out request + const optOutAddResults = await client.optOuts.add( + from, + phoneNumbers); + + // individual requests can encounter errors during sending + // use the "httpStatusCode" property to verify + for (const optOutAddResult of optOutAddResults) { + if (optOutAddResult.httpStatusCode == 200) { + console.log("Success: ", optOutAddResult); + } else { + console.error("Something went wrong when trying to send opt out add request: ", optOutAddResult); + } + } + + console.log("== Done: Opt Out Add =="); +} + +main().catch((error) => { + console.error("Encountered an error while sending opt out add request: ", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-sms/samples/v1/typescript/src/optOutCheck.ts b/sdk/communication/communication-sms/samples/v1/typescript/src/optOutCheck.ts new file mode 100644 index 000000000000..cb7d80329ea2 --- /dev/null +++ b/sdk/communication/communication-sms/samples/v1/typescript/src/optOutCheck.ts @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Check if 1 or more recipients are opted out of receiving SMS messages + */ + +import { SmsClient } from "@azure/communication-sms"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("== Opt Out Check =="); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://.communication.azure.com/;"; + + // create new client + const client = new SmsClient(connectionString); + + // construct send parameters + const from = process.env.FROM_PHONE_NUMBER || process.env.AZURE_PHONE_NUMBER || ""; + let phoneNumbers: string[]; + if (process.env.TO_PHONE_NUMBERS !== undefined) { + phoneNumbers = process.env.TO_PHONE_NUMBERS.split(","); + } else if (process.env.AZURE_PHONE_NUMBER !== undefined) { + phoneNumbers = [process.env.AZURE_PHONE_NUMBER]; + } else { + phoneNumbers = ["", ""]; + } + + // send check opt out request + const optOutCheckResults = await client.optOuts.check( + from, + phoneNumbers); + + // individual requests can encounter errors during sending + // use the "httpStatusCode" property to verify + for (const optOutCheckResult of optOutCheckResults) { + if (optOutCheckResult.httpStatusCode == 200) { + console.log("Success: ", optOutCheckResult); + } else { + console.error("Something went wrong when trying to send opt out check request: ", optOutCheckResult); + } + } + + console.log("== Done: Opt Out Check =="); +} + +main().catch((error) => { + console.error("Encountered an error while sending Opt Out Check request: ", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-sms/samples/v1/typescript/src/optOutRemove.ts b/sdk/communication/communication-sms/samples/v1/typescript/src/optOutRemove.ts new file mode 100644 index 000000000000..86dce22d3c99 --- /dev/null +++ b/sdk/communication/communication-sms/samples/v1/typescript/src/optOutRemove.ts @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Remove 1 or more recipients from Opt Out list + */ + +import { SmsClient } from "@azure/communication-sms"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +export async function main() { + console.log("== Opt Out Remove =="); + + // You will need to set this environment variable or edit the following values + const connectionString = + process.env.COMMUNICATION_SAMPLES_CONNECTION_STRING || + "endpoint=https://.communication.azure.com/;"; + + // create new client + const client = new SmsClient(connectionString); + + // construct send parameters + const from = process.env.FROM_PHONE_NUMBER || process.env.AZURE_PHONE_NUMBER || ""; + let phoneNumbers: string[]; + if (process.env.TO_PHONE_NUMBERS !== undefined) { + phoneNumbers = process.env.TO_PHONE_NUMBERS.split(","); + } else if (process.env.AZURE_PHONE_NUMBER !== undefined) { + phoneNumbers = [process.env.AZURE_PHONE_NUMBER]; + } else { + phoneNumbers = ["", ""]; + } + + // send add opt out request + const optOutRemoveResults = await client.optOuts.remove( + from, + phoneNumbers); + + // individual requests can encounter errors during sending + // use the "httpStatusCode" property to verify + for (const optOutRemoveResult of optOutRemoveResults) { + if (optOutRemoveResult.httpStatusCode == 200) { + console.log("Success: ", optOutRemoveResult); + } else { + console.error("Something went wrong when trying to send opt out remove request: ", optOutRemoveResult); + } + } + + console.log("== Done: Opt Out Remove =="); +} + +main().catch((error) => { + console.error("Encountered an error while sending opt out remove request: ", error); + process.exit(1); +}); diff --git a/sdk/communication/communication-sms/src/optOutsClient.ts b/sdk/communication/communication-sms/src/optOutsClient.ts index 53ba488551aa..10829a2f59f6 100644 --- a/sdk/communication/communication-sms/src/optOutsClient.ts +++ b/sdk/communication/communication-sms/src/optOutsClient.ts @@ -106,7 +106,10 @@ export class OptOutsClient { ): Promise { const { operationOptions } = extractOperationOptions(options); return tracingClient.withSpan("OptOuts-Remove", operationOptions, async (updatedOptions) => { - const response = await this.api.optOuts.add(generateOptOutRequest(from, to), updatedOptions); + const response = await this.api.optOuts.remove( + generateOptOutRequest(from, to), + updatedOptions, + ); return response.value.map((optOutResponseItem: OptOutResponseItem) => { return {