-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[communication]-[sms] Fix opt out remove action (#32298)
### Packages impacted by this PR communication-sms ### Issues associated with this PR ### Describe the problem that is addressed by this PR Fix the error in optOut.remove method ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
- Loading branch information
1 parent
2aa1f31
commit 3366272
Showing
7 changed files
with
185 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
sdk/communication/communication-sms/samples/v1/typescript/src/optOutAdd.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://<resource-name>.communication.azure.com/;<access-key>"; | ||
|
||
// create new client | ||
const client = new SmsClient(connectionString); | ||
|
||
// construct send parameters | ||
const from = process.env.FROM_PHONE_NUMBER || process.env.AZURE_PHONE_NUMBER || "<from-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 = ["<to-phone-number-1>", "<to-phone-number-2>"]; | ||
} | ||
|
||
// 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); | ||
}); |
57 changes: 57 additions & 0 deletions
57
sdk/communication/communication-sms/samples/v1/typescript/src/optOutCheck.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://<resource-name>.communication.azure.com/;<access-key>"; | ||
|
||
// create new client | ||
const client = new SmsClient(connectionString); | ||
|
||
// construct send parameters | ||
const from = process.env.FROM_PHONE_NUMBER || process.env.AZURE_PHONE_NUMBER || "<from-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 = ["<to-phone-number-1>", "<to-phone-number-2>"]; | ||
} | ||
|
||
// 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); | ||
}); |
57 changes: 57 additions & 0 deletions
57
sdk/communication/communication-sms/samples/v1/typescript/src/optOutRemove.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://<resource-name>.communication.azure.com/;<access-key>"; | ||
|
||
// create new client | ||
const client = new SmsClient(connectionString); | ||
|
||
// construct send parameters | ||
const from = process.env.FROM_PHONE_NUMBER || process.env.AZURE_PHONE_NUMBER || "<from-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 = ["<to-phone-number-1>", "<to-phone-number-2>"]; | ||
} | ||
|
||
// 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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters