Skip to content

Commit

Permalink
[communication] update release phone numbers sample (#13147)
Browse files Browse the repository at this point in the history
  • Loading branch information
0rland0Wats0n authored Jan 13, 2021
1 parent 0836431 commit c2298fd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 80 deletions.
5 changes: 0 additions & 5 deletions sdk/communication/communication-administration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,5 @@
"sinon": "^9.0.2",
"typescript": "4.1.2",
"typedoc": "0.15.0"
},
"//smokeTestConfiguration": {
"skip": [
"releasePhoneNumbers.js"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ These sample programs show how to use the JavaScript client libraries for Azure
| [issueToken.js][issuetoken] | uses the CommunicationIdentityClient to create a user and issue a token for this user |
| [revokeTokens.js][revoketokens] | uses the CommunicationIdentityClient to create a user, issue tokens for this user, and revoke these tokens |
| [purchasePhoneNumber.js][purchasephonenumber] | uses the PhoneNumberAdministrationClient to purchase a phone number |
| [releasePhoneNumbers.js][releasephonenumbers] | uses the PhoneNumberAdministrationClient to release all phone numbers that match certain criteria |
| [releasePhoneNumbers.js][releasephonenumbers] | uses the PhoneNumberAdministrationClient to release phone numbers |

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* Demonstrates how to us the PhoneNumberAdministrationClient
* to release phone numbers that have been acquired.
* to release phone numbers.
*/

const { PhoneNumberAdministrationClient } = require("@azure/communication-administration");
Expand All @@ -22,44 +22,16 @@ async function main() {
// create an instance of PhoneNumberAdministrationClient
const phoneNumberClient = new PhoneNumberAdministrationClient(connectionString);

console.log("Getting acquired phone numbers.");
// Release a phone numbers
const releasePoller = await phoneNumberClient.beginReleasePhoneNumbers([
"+14125550100",
"+14125550101"
]);
console.log("Releasing phone numbers...");

// get the list of acquired phone numbers
const phoneNumbers = await phoneNumberClient.listPhoneNumbers();
const phoneNumbersToRelease = [];
await releasePoller.pollUntilDone();

console.log("Searching for phone numbers to release.");

// get toll free phone numbers with the sms outbound (A2P) capability as their only capability
// we will release these
for await (const acquired of phoneNumbers) {
if (
acquired.acquiredCapabilities.length === 4 &&
acquired.acquiredCapabilities.includes("Azure") &&
acquired.acquiredCapabilities.includes("ThirdPartyAppAssignment") &&
acquired.acquiredCapabilities.includes("TollFree") &&
acquired.acquiredCapabilities.includes("OutboundA2PSms")
) {
phoneNumbersToRelease.push(acquired.phoneNumber);
break;
}
}

console.log(`Found ${phoneNumbersToRelease.length} phone number(s) to release.`);

if (phoneNumbersToRelease.length) {
// create release poller
const releasePoller = await phoneNumberClient.beginReleasePhoneNumbers(phoneNumbersToRelease);

console.log("Releasing phone numbers.");

// poll until phone numbers are released.
await releasePoller.pollUntilDone();

console.log("Phone numbers released successfully.");
} else {
throw new Error("Did not find any phone numbers to release.");
}
console.log("Release succeeded.");
}

main().catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ These sample programs show how to use the TypeScript client libraries for Azure
| [issueToken.ts][issuetoken] | uses the CommunicationIdentityClient to create a user and issue a token for this user |
| [revokeTokens.ts][revoketokens] | uses the CommunicationIdentityClient to create a user, issue tokens for this user, and revoke these tokens |
| [purchasePhoneNumber.ts][purchasephonenumber] | uses the PhoneNumberAdministrationClient to purchase a phone number |
| [releasePhoneNumbers.ts][releasephonenumbers] | uses the PhoneNumberAdministrationClient to release all phone numbers that match certain criteria |
| [releasePhoneNumbers.ts][releasephonenumbers] | uses the PhoneNumberAdministrationClient to release phone numbers. |

## Prerequisites

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/**
* Demonstrates how to us the PhoneNumberAdministrationClient
* to release phone numbers that have been acquired.
* to release phone numbers.
*/

import { PhoneNumberAdministrationClient } from "@azure/communication-administration";
Expand All @@ -22,43 +22,16 @@ export const main = async () => {
// create an instance of PhoneNumberAdministrationClient
const phoneNumberClient = new PhoneNumberAdministrationClient(connectionString);

console.log("Getting acquired phone numbers.");
// Release a phone numbers
const releasePoller = await phoneNumberClient.beginReleasePhoneNumbers([
"+14125550100",
"+14125550101"
]);
console.log("Releasing phone numbers...");

// get the list of acquired phone numbers
const phoneNumbers = await phoneNumberClient.listPhoneNumbers();
const phoneNumbersToRelease: string[] = [];
await releasePoller.pollUntilDone();

console.log("Searching for phone numbers to release.");

// get toll free phone numbers with the sms outbound (A2P) capability as their only capability
// we will release these
for await (const acquired of phoneNumbers) {
if (
acquired.acquiredCapabilities.length === 4 &&
acquired.acquiredCapabilities.includes("Azure") &&
acquired.acquiredCapabilities.includes("ThirdPartyAppAssignment") &&
acquired.acquiredCapabilities.includes("TollFree") &&
acquired.acquiredCapabilities.includes("OutboundA2PSms")
) {
phoneNumbersToRelease.push(acquired.phoneNumber);
}
}

console.log(`Found ${phoneNumbersToRelease.length} phone number(s) to release.`);

if (phoneNumbersToRelease.length) {
// create release poller
const releasePoller = await phoneNumberClient.beginReleasePhoneNumbers(phoneNumbersToRelease);

console.log("Releasing phone numbers.");

// poll until phone numbers are released.
await releasePoller.pollUntilDone();

console.log("Phone numbers released successfully.");
} else {
throw new Error("Did not find any phone numbers to release.");
}
console.log("Release succeeded.");
};

main().catch((error) => {
Expand Down

0 comments on commit c2298fd

Please sign in to comment.