Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[communication] update release phone numbers sample #13147

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
]);
DominikMe marked this conversation as resolved.
Show resolved Hide resolved
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