PhoneNumbersClient class

用來與 Azure 通訊服務電話號碼管理互動的用戶端類別。

建構函式

PhoneNumbersClient(string, KeyCredential, PhoneNumbersClientOptions)

使用 Azure KeyCredential 初始化 PhoneNumberAdministrationClient 類別的新實例。

PhoneNumbersClient(string, PhoneNumbersClientOptions)

使用連接字串,初始化 PhoneNumberAdministrationClient 類別的新實例。

PhoneNumbersClient(string, TokenCredential, PhoneNumbersClientOptions)

使用 TokenCredential 初始化 PhoneNumberAdministrationClient 類別的新實例。

方法

beginPurchasePhoneNumbers(string, BeginPurchasePhoneNumbersOptions)

開始在與指定標識符相關聯的搜尋中購買電話號碼。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  SearchAvailablePhoneNumbersRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const searchRequest: SearchAvailablePhoneNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
  assignmentType: "application",
  capabilities: {
    sms: "outbound",
    calling: "none",
  },
  quantity: 1,
};

const searchPoller = await client.beginSearchAvailablePhoneNumbers(searchRequest);

// The search is underway. Wait to receive searchId.
const { searchId, phoneNumbers } = await searchPoller.pollUntilDone();

const purchasePoller = await client.beginPurchasePhoneNumbers(searchId);

// Purchase is underway.
await purchasePoller.pollUntilDone();
console.log(`Successfully purchased ${phoneNumbers[0]}`);
beginReleasePhoneNumber(string, BeginReleasePhoneNumberOptions)

開始發行已購買的電話號碼。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const phoneNumberToRelease = "<phone-number-to-release>";

const releasePoller = await client.beginReleasePhoneNumber(phoneNumberToRelease);

// Release is underway.
await releasePoller.pollUntilDone();
console.log("Successfully release phone number.");
beginReservationPurchase(string, BeginReservationPurchaseOptions)

開始在與指定標識符相關聯的搜尋中購買電話號碼。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const reservationId = "<reservation-id>";

const purchasePoller = await client.beginReservationPurchase(reservationId);

// Purchase is underway.
const purchaseResult = await purchasePoller.pollUntilDone();
console.log(`Successfully purchased phone numbers in reservation: ${reservationId}`);

使用給定的ID開始購買預留中的電話號碼。

beginSearchAvailablePhoneNumbers(SearchAvailablePhoneNumbersRequest, BeginSearchAvailablePhoneNumbersOptions)

根據名稱或分區代碼等一些條件約束,開始搜尋電話號碼。 找到的電話號碼會保留到您取消、購買或保留到期為止。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  SearchAvailablePhoneNumbersRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const searchRequest: SearchAvailablePhoneNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
  assignmentType: "application",
  capabilities: {
    sms: "outbound",
    calling: "none",
  },
  quantity: 1,
};

const searchPoller = await client.beginSearchAvailablePhoneNumbers(searchRequest);

// The search is underway. Wait to receive searchId.
const searchResults = await searchPoller.pollUntilDone();
console.log(`Found phone number: ${searchResults.phoneNumbers[0]}`);
console.log(`searchId: ${searchResults.searchId}`);
beginUpdatePhoneNumberCapabilities(string, PhoneNumberCapabilitiesRequest, BeginUpdatePhoneNumberCapabilitiesOptions)

啟動已購買電話號碼功能的更新。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  PhoneNumberCapabilitiesRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const phoneNumberToUpdate = "<phone-number-to-update>";

// This will update phone number to send and receive sms, but only send calls.
const updateRequest: PhoneNumberCapabilitiesRequest = {
  sms: "inbound+outbound",
  calling: "outbound",
};

const updatePoller = await client.beginUpdatePhoneNumberCapabilities(
  phoneNumberToUpdate,
  updateRequest,
);

// Update is underway.
const { capabilities } = await updatePoller.pollUntilDone();
console.log(`These are the update capabilities: ${capabilities}`);
browseAvailablePhoneNumbers(BrowseAvailableNumbersRequest, BrowseAvailableNumbersOptions)

流覽要購買的可用電話號碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  BrowseAvailableNumbersRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const browseAvailableNumberRequest: BrowseAvailableNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
};
const browseAvailableNumbers = await client.browseAvailablePhoneNumbers(
  browseAvailableNumberRequest,
  {
    capabilities: {
      calling: "outbound",
    },
    assignmentType: "application",
  },
);
for (const phoneNumber of browseAvailableNumbers.phoneNumbers) {
  console.log("Found phone number: ", phoneNumber.phoneNumber);
}

流覽可用的電話號碼

createOrUpdateReservation(CreateOrUpdateReservationRequest, CreateOrUpdateReservationOptions)

使用指定的標識碼,從保留新增和移除電話號碼。 回應將會是保留的更新狀態。 電話號碼可以藉由將電話號碼包含在承載中來保留。 如果某個數字已經在保留中,則會予以忽略。 若要移除電話號碼,請將它明確設定為要求承載中的 Null。 此作業是等冪的。 如果已有相同標識碼的保留,則會更新它,否則會建立新的保留。 只能更新具有「作用中」狀態的保留。 更新保留會將保留的到期時間延長至上次變更后的 15 分鐘,最多從建立時間起 2 小時。 部分成功是可能的,在此情況下,回應會有 207 狀態代碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  BrowseAvailableNumbersRequest,
  AvailablePhoneNumber,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const browseAvailableNumberRequest: BrowseAvailableNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
};

const browseAvailableNumbers = await client.browseAvailablePhoneNumbers(
  browseAvailableNumberRequest,
  {
    capabilities: {
      calling: "outbound",
    },
    assignmentType: "application",
  },
);
const phoneNumbers = browseAvailableNumbers.phoneNumbers;
const phoneNumbersList = [phoneNumbers[0], phoneNumbers[1]];
const reservationResponse = await client.createOrUpdateReservation(
  {
    reservationId: "reservationId",
  },
  {
    add: phoneNumbersList,
  },
);
const numbersWithError: AvailablePhoneNumber[] = [];
for (const number of Object.values(reservationResponse.phoneNumbers || {})) {
  if (number != null && number.status === "error") {
    numbersWithError.push(number);
  }
}
if (numbersWithError.length > 0) {
  console.log("Errors occurred during reservation");
} else {
  console.log("Reservation operation completed without errors.");
}

創建或更新預留。

deleteReservation(string, DeleteReservationOptions)

按預訂的ID刪除預訂。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const reservationId = "<reservation-id>";
await client.deleteReservation(reservationId);

console.log(`Reservation with ID ${reservationId} has been deleted.`);

刪除預留。

getPurchasedPhoneNumber(string, OperationOptions)

取得已購買電話號碼的詳細數據。 包括電話號碼、成本、國家/地區代碼等。

getReservation(string, GetReservationOptions)

擷取具有指定標識符的保留,包括與其相關聯的所有電話號碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const reservationId = "<reservation-id>";
const reservationResponse = await client.getReservation(reservationId);

console.log(`Phone numbers in reservation: ${reservationResponse.phoneNumbers}`);

獲取預訂。

listAvailableCountries(ListAvailableCountriesOptions)

反覆運算可用的國家/地區。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const country of client.listAvailableCountries()) {
  console.log("country: ", country.localizedName);
}

列出所有可用的國家/地區。

listAvailableGeographicAreaCodes(string, ListGeographicAreaCodesOptions)

反覆運算可用的地理區域代碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const areaCodeItem of client.listAvailableGeographicAreaCodes("US")) {
  console.log("area code: ", areaCodeItem.areaCode);
}

列出所有可用的地理區域代碼。

listAvailableLocalities(string, ListLocalitiesOptions)

反覆運算可用的地區。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const locality of client.listAvailableLocalities("US")) {
  console.log("locality: ", locality.localizedName);
}

列出所有可用的地區。

listAvailableMobileAreaCodes(string, ListMobileAreaCodesOptions)

迭代可用的移動區號。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const areaCodeItem of client.listAvailableMobileAreaCodes("IE")) {
  console.log("area code: ", areaCodeItem.areaCode);
}

列出所有可用的行動區號。

listAvailableOfferings(string, ListOfferingsOptions)

反覆運算可用的供應專案。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const offering of client.listAvailableOfferings("US")) {
  console.log("phone number type: ", offering.phoneNumberType);
  console.log("cost: ", offering.cost.amount);
}

列出所有可用的供應專案。

listAvailableTollFreeAreaCodes(string, ListTollFreeAreaCodesOptions)

反覆運算可用的區域代碼 Toll-Free。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const areaCodeItem of client.listAvailableTollFreeAreaCodes("US")) {
  console.log("area code: ", areaCodeItem.areaCode);
}

列出所有可用的區域代碼 Toll-Free。

listPurchasedPhoneNumbers(ListPurchasedPhoneNumbersOptions)

反覆運算已購買的電話號碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const phoneNumbers = client.listPurchasedPhoneNumbers();

for await (const phoneNumber of phoneNumbers) {
  console.log(`The id is the same as the phone number: ${phoneNumber.id}`);
  console.log(`Phone number type is ${phoneNumber.phoneNumberType}`);
}

列出所有已購買的電話號碼。

listReservations(ListReservationOptions)

反覆運算所有電話號碼預留。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const reservation of client.listReservations()) {
  console.log(`Reservation id: ${reservation.id}`);
}

列出所有電話號碼預留。 請注意,保留不會填入與其相關聯的電話號碼。

searchOperatorInformation(string[], SearchOperatorInformationOptions)

搜尋有關指定電話號碼的作員資訊。

建構函式詳細資料

PhoneNumbersClient(string, KeyCredential, PhoneNumbersClientOptions)

使用 Azure KeyCredential 初始化 PhoneNumberAdministrationClient 類別的新實例。

new PhoneNumbersClient(url: string, credential: KeyCredential, options?: PhoneNumbersClientOptions)

參數

url

string

服務的端點 (例如:https://contoso.eastus.communications.azure.net

credential
KeyCredential

對象,用來驗證對服務的要求。 使用 Azure KeyCredential 或 @azure/identity 來建立認證。

options
PhoneNumbersClientOptions

自選。 設定 HTTP 管線的選項。

PhoneNumbersClient(string, PhoneNumbersClientOptions)

使用連接字串,初始化 PhoneNumberAdministrationClient 類別的新實例。

new PhoneNumbersClient(connectionString: string, options?: PhoneNumbersClientOptions)

參數

connectionString

string

聯機至 Azure 通訊服務資源的連接字串。 (例如:端點=https://contoso.eastus.communications.azure.net/;accesskey=secret)

options
PhoneNumbersClientOptions

自選。 設定 HTTP 管線的選項。

PhoneNumbersClient(string, TokenCredential, PhoneNumbersClientOptions)

使用 TokenCredential 初始化 PhoneNumberAdministrationClient 類別的新實例。

new PhoneNumbersClient(url: string, credential: TokenCredential, options?: PhoneNumbersClientOptions)

參數

url

string

服務的端點(例如:https://contoso.eastus.communications.azure.net)。

credential
TokenCredential

用來驗證服務要求的 TokenCredential。

options
PhoneNumbersClientOptions

自選。 設定 HTTP 管線的選項。

方法詳細資料

beginPurchasePhoneNumbers(string, BeginPurchasePhoneNumbersOptions)

開始在與指定標識符相關聯的搜尋中購買電話號碼。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  SearchAvailablePhoneNumbersRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const searchRequest: SearchAvailablePhoneNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
  assignmentType: "application",
  capabilities: {
    sms: "outbound",
    calling: "none",
  },
  quantity: 1,
};

const searchPoller = await client.beginSearchAvailablePhoneNumbers(searchRequest);

// The search is underway. Wait to receive searchId.
const { searchId, phoneNumbers } = await searchPoller.pollUntilDone();

const purchasePoller = await client.beginPurchasePhoneNumbers(searchId);

// Purchase is underway.
await purchasePoller.pollUntilDone();
console.log(`Successfully purchased ${phoneNumbers[0]}`);
function beginPurchasePhoneNumbers(searchId: string, options?: BeginPurchasePhoneNumbersOptions): Promise<PollerLike<PollOperationState<PurchasePhoneNumbersResult>, PurchasePhoneNumbersResult>>

參數

searchId

string

要購買之搜尋的標識碼。 從 beginSearchAvailablePhoneNumbers 傳回

options
BeginPurchasePhoneNumbersOptions

其他要求選項。

傳回

Promise<PollerLike<@azure/core-lro.PollOperationState<PurchasePhoneNumbersResult>, PurchasePhoneNumbersResult>>

beginReleasePhoneNumber(string, BeginReleasePhoneNumberOptions)

開始發行已購買的電話號碼。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const phoneNumberToRelease = "<phone-number-to-release>";

const releasePoller = await client.beginReleasePhoneNumber(phoneNumberToRelease);

// Release is underway.
await releasePoller.pollUntilDone();
console.log("Successfully release phone number.");
function beginReleasePhoneNumber(phoneNumber: string, options?: BeginReleasePhoneNumberOptions): Promise<PollerLike<PollOperationState<ReleasePhoneNumberResult>, ReleasePhoneNumberResult>>

參數

phoneNumber

string

正在發行的E.164 格式化電話號碼。 前置加號可以是 + 或編碼為 %2B。

options
BeginReleasePhoneNumberOptions

其他要求選項。

傳回

Promise<PollerLike<@azure/core-lro.PollOperationState<ReleasePhoneNumberResult>, ReleasePhoneNumberResult>>

beginReservationPurchase(string, BeginReservationPurchaseOptions)

開始在與指定標識符相關聯的搜尋中購買電話號碼。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const reservationId = "<reservation-id>";

const purchasePoller = await client.beginReservationPurchase(reservationId);

// Purchase is underway.
const purchaseResult = await purchasePoller.pollUntilDone();
console.log(`Successfully purchased phone numbers in reservation: ${reservationId}`);

使用給定的ID開始購買預留中的電話號碼。

function beginReservationPurchase(reservationId: string, options?: BeginReservationPurchaseOptions): Promise<PollerLike<PollOperationState<PurchasePhoneNumbersResult>, PurchasePhoneNumbersResult>>

參數

reservationId

string

保留的標識碼。

options
BeginReservationPurchaseOptions

其他要求選項。

傳回

Promise<PollerLike<@azure/core-lro.PollOperationState<PurchasePhoneNumbersResult>, PurchasePhoneNumbersResult>>

beginSearchAvailablePhoneNumbers(SearchAvailablePhoneNumbersRequest, BeginSearchAvailablePhoneNumbersOptions)

根據名稱或分區代碼等一些條件約束,開始搜尋電話號碼。 找到的電話號碼會保留到您取消、購買或保留到期為止。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  SearchAvailablePhoneNumbersRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const searchRequest: SearchAvailablePhoneNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
  assignmentType: "application",
  capabilities: {
    sms: "outbound",
    calling: "none",
  },
  quantity: 1,
};

const searchPoller = await client.beginSearchAvailablePhoneNumbers(searchRequest);

// The search is underway. Wait to receive searchId.
const searchResults = await searchPoller.pollUntilDone();
console.log(`Found phone number: ${searchResults.phoneNumbers[0]}`);
console.log(`searchId: ${searchResults.searchId}`);
function beginSearchAvailablePhoneNumbers(search: SearchAvailablePhoneNumbersRequest, options?: BeginSearchAvailablePhoneNumbersOptions): Promise<PollerLike<PollOperationState<PhoneNumberSearchResult>, PhoneNumberSearchResult>>

參數

search
SearchAvailablePhoneNumbersRequest

要求屬性以限制搜尋範圍。

options
BeginSearchAvailablePhoneNumbersOptions

其他要求選項。

傳回

Promise<PollerLike<@azure/core-lro.PollOperationState<PhoneNumberSearchResult>, PhoneNumberSearchResult>>

beginUpdatePhoneNumberCapabilities(string, PhoneNumberCapabilitiesRequest, BeginUpdatePhoneNumberCapabilitiesOptions)

啟動已購買電話號碼功能的更新。

此函式會傳回長時間執行的作業輪詢器,可讓您無限期等候作業完成。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  PhoneNumberCapabilitiesRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const phoneNumberToUpdate = "<phone-number-to-update>";

// This will update phone number to send and receive sms, but only send calls.
const updateRequest: PhoneNumberCapabilitiesRequest = {
  sms: "inbound+outbound",
  calling: "outbound",
};

const updatePoller = await client.beginUpdatePhoneNumberCapabilities(
  phoneNumberToUpdate,
  updateRequest,
);

// Update is underway.
const { capabilities } = await updatePoller.pollUntilDone();
console.log(`These are the update capabilities: ${capabilities}`);
function beginUpdatePhoneNumberCapabilities(phoneNumber: string, request: PhoneNumberCapabilitiesRequest, options?: BeginUpdatePhoneNumberCapabilitiesOptions): Promise<PollerLike<PollOperationState<PurchasedPhoneNumber>, PurchasedPhoneNumber>>

參數

phoneNumber

string

要更新的E.164 格式化電話號碼。 前置加號可以是 + 或編碼為 %2B。

request
PhoneNumberCapabilitiesRequest

將套用至電話號碼的更新屬性。

options
BeginUpdatePhoneNumberCapabilitiesOptions

其他要求選項。

傳回

Promise<PollerLike<@azure/core-lro.PollOperationState<PurchasedPhoneNumber>, PurchasedPhoneNumber>>

browseAvailablePhoneNumbers(BrowseAvailableNumbersRequest, BrowseAvailableNumbersOptions)

流覽要購買的可用電話號碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  BrowseAvailableNumbersRequest,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const browseAvailableNumberRequest: BrowseAvailableNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
};
const browseAvailableNumbers = await client.browseAvailablePhoneNumbers(
  browseAvailableNumberRequest,
  {
    capabilities: {
      calling: "outbound",
    },
    assignmentType: "application",
  },
);
for (const phoneNumber of browseAvailableNumbers.phoneNumbers) {
  console.log("Found phone number: ", phoneNumber.phoneNumber);
}

流覽可用的電話號碼

function browseAvailablePhoneNumbers(request: BrowseAvailableNumbersRequest, options?: BrowseAvailableNumbersOptions): Promise<PhoneNumbersBrowseResult>

參數

request
BrowseAvailableNumbersRequest

用於瀏覽可用電話號碼的請求參數。

options
BrowseAvailableNumbersOptions

其他要求選項。

傳回

createOrUpdateReservation(CreateOrUpdateReservationRequest, CreateOrUpdateReservationOptions)

使用指定的標識碼,從保留新增和移除電話號碼。 回應將會是保留的更新狀態。 電話號碼可以藉由將電話號碼包含在承載中來保留。 如果某個數字已經在保留中,則會予以忽略。 若要移除電話號碼,請將它明確設定為要求承載中的 Null。 此作業是等冪的。 如果已有相同標識碼的保留,則會更新它,否則會建立新的保留。 只能更新具有「作用中」狀態的保留。 更新保留會將保留的到期時間延長至上次變更后的 15 分鐘,最多從建立時間起 2 小時。 部分成功是可能的,在此情況下,回應會有 207 狀態代碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import {
  PhoneNumbersClient,
  BrowseAvailableNumbersRequest,
  AvailablePhoneNumber,
} from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const browseAvailableNumberRequest: BrowseAvailableNumbersRequest = {
  countryCode: "US",
  phoneNumberType: "tollFree",
};

const browseAvailableNumbers = await client.browseAvailablePhoneNumbers(
  browseAvailableNumberRequest,
  {
    capabilities: {
      calling: "outbound",
    },
    assignmentType: "application",
  },
);
const phoneNumbers = browseAvailableNumbers.phoneNumbers;
const phoneNumbersList = [phoneNumbers[0], phoneNumbers[1]];
const reservationResponse = await client.createOrUpdateReservation(
  {
    reservationId: "reservationId",
  },
  {
    add: phoneNumbersList,
  },
);
const numbersWithError: AvailablePhoneNumber[] = [];
for (const number of Object.values(reservationResponse.phoneNumbers || {})) {
  if (number != null && number.status === "error") {
    numbersWithError.push(number);
  }
}
if (numbersWithError.length > 0) {
  console.log("Errors occurred during reservation");
} else {
  console.log("Reservation operation completed without errors.");
}

創建或更新預留。

function createOrUpdateReservation(request: CreateOrUpdateReservationRequest, options?: CreateOrUpdateReservationOptions): Promise<PhoneNumbersReservation>

參數

request
CreateOrUpdateReservationRequest

用於創建或更新預留的請求參數。

options
CreateOrUpdateReservationOptions

選項參數。

傳回

deleteReservation(string, DeleteReservationOptions)

按預訂的ID刪除預訂。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const reservationId = "<reservation-id>";
await client.deleteReservation(reservationId);

console.log(`Reservation with ID ${reservationId} has been deleted.`);

刪除預留。

function deleteReservation(reservationId: string, options?: DeleteReservationOptions): Promise<void>

參數

reservationId

string

保留的標識碼。

options
DeleteReservationOptions

其他要求選項。

傳回

Promise<void>

getPurchasedPhoneNumber(string, OperationOptions)

取得已購買電話號碼的詳細數據。 包括電話號碼、成本、國家/地區代碼等。

function getPurchasedPhoneNumber(phoneNumber: string, options?: OperationOptions): Promise<PurchasedPhoneNumber>

參數

phoneNumber

string

正在擷取的E.164 格式化電話號碼。 前置加號可以是 + 或編碼為 %2B。

options
OperationOptions

其他要求選項。

傳回

getReservation(string, GetReservationOptions)

擷取具有指定標識符的保留,包括與其相關聯的所有電話號碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const reservationId = "<reservation-id>";
const reservationResponse = await client.getReservation(reservationId);

console.log(`Phone numbers in reservation: ${reservationResponse.phoneNumbers}`);

獲取預訂。

function getReservation(reservationId: string, options?: GetReservationOptions): Promise<PhoneNumbersReservation>

參數

reservationId

string

保留的標識碼。

options
GetReservationOptions

其他要求選項。

傳回

listAvailableCountries(ListAvailableCountriesOptions)

反覆運算可用的國家/地區。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const country of client.listAvailableCountries()) {
  console.log("country: ", country.localizedName);
}

列出所有可用的國家/地區。

function listAvailableCountries(options?: ListAvailableCountriesOptions): PagedAsyncIterableIterator<PhoneNumberCountry, PhoneNumberCountry[], PageSettings>

參數

options
ListAvailableCountriesOptions

選擇性參數。

傳回

listAvailableGeographicAreaCodes(string, ListGeographicAreaCodesOptions)

反覆運算可用的地理區域代碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const areaCodeItem of client.listAvailableGeographicAreaCodes("US")) {
  console.log("area code: ", areaCodeItem.areaCode);
}

列出所有可用的地理區域代碼。

function listAvailableGeographicAreaCodes(countryCode: string, options?: ListGeographicAreaCodesOptions): PagedAsyncIterableIterator<PhoneNumberAreaCode, PhoneNumberAreaCode[], PageSettings>

參數

countryCode

string

ISO 3166-2 國家/地區代碼。

options
ListGeographicAreaCodesOptions

選擇性參數。

傳回

listAvailableLocalities(string, ListLocalitiesOptions)

反覆運算可用的地區。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const locality of client.listAvailableLocalities("US")) {
  console.log("locality: ", locality.localizedName);
}

列出所有可用的地區。

function listAvailableLocalities(countryCode: string, options?: ListLocalitiesOptions): PagedAsyncIterableIterator<PhoneNumberLocality, PhoneNumberLocality[], PageSettings>

參數

countryCode

string

ISO 3166-2 國家/地區代碼。

options
ListLocalitiesOptions

選擇性參數。

傳回

listAvailableMobileAreaCodes(string, ListMobileAreaCodesOptions)

迭代可用的移動區號。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const areaCodeItem of client.listAvailableMobileAreaCodes("IE")) {
  console.log("area code: ", areaCodeItem.areaCode);
}

列出所有可用的行動區號。

function listAvailableMobileAreaCodes(countryCode: string, options?: ListMobileAreaCodesOptions): PagedAsyncIterableIterator<PhoneNumberAreaCode, PhoneNumberAreaCode[], PageSettings>

參數

countryCode

string

ISO 3166-2 國家/地區代碼。

options
ListMobileAreaCodesOptions

選擇性參數。

傳回

listAvailableOfferings(string, ListOfferingsOptions)

反覆運算可用的供應專案。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const offering of client.listAvailableOfferings("US")) {
  console.log("phone number type: ", offering.phoneNumberType);
  console.log("cost: ", offering.cost.amount);
}

列出所有可用的供應專案。

function listAvailableOfferings(countryCode: string, options?: ListOfferingsOptions): PagedAsyncIterableIterator<PhoneNumberOffering, PhoneNumberOffering[], PageSettings>

參數

countryCode

string

ISO 3166-2 國家/地區代碼。

options
ListOfferingsOptions

選擇性參數。

傳回

listAvailableTollFreeAreaCodes(string, ListTollFreeAreaCodesOptions)

反覆運算可用的區域代碼 Toll-Free。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const areaCodeItem of client.listAvailableTollFreeAreaCodes("US")) {
  console.log("area code: ", areaCodeItem.areaCode);
}

列出所有可用的區域代碼 Toll-Free。

function listAvailableTollFreeAreaCodes(countryCode: string, options?: ListTollFreeAreaCodesOptions): PagedAsyncIterableIterator<PhoneNumberAreaCode, PhoneNumberAreaCode[], PageSettings>

參數

countryCode

string

ISO 3166-2 國家/地區代碼。

options
ListTollFreeAreaCodesOptions

選擇性參數。

傳回

listPurchasedPhoneNumbers(ListPurchasedPhoneNumbersOptions)

反覆運算已購買的電話號碼。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

const phoneNumbers = client.listPurchasedPhoneNumbers();

for await (const phoneNumber of phoneNumbers) {
  console.log(`The id is the same as the phone number: ${phoneNumber.id}`);
  console.log(`Phone number type is ${phoneNumber.phoneNumberType}`);
}

列出所有已購買的電話號碼。

function listPurchasedPhoneNumbers(options?: ListPurchasedPhoneNumbersOptions): PagedAsyncIterableIterator<PurchasedPhoneNumber, PurchasedPhoneNumber[], PageSettings>

參數

options
ListPurchasedPhoneNumbersOptions

選擇性參數。

傳回

listReservations(ListReservationOptions)

反覆運算所有電話號碼預留。

範例用法:

import { DefaultAzureCredential } from "@azure/identity";
import { PhoneNumbersClient } from "@azure/communication-phone-numbers";

const credential = new DefaultAzureCredential();
const client = new PhoneNumbersClient("<endpoint-from-resource>", credential);

for await (const reservation of client.listReservations()) {
  console.log(`Reservation id: ${reservation.id}`);
}

列出所有電話號碼預留。 請注意,保留不會填入與其相關聯的電話號碼。

function listReservations(options?: ListReservationOptions): PagedAsyncIterableIterator<PhoneNumbersReservation, PhoneNumbersReservation[], PageSettings>

參數

options
ListReservationOptions

選擇性參數。

傳回

searchOperatorInformation(string[], SearchOperatorInformationOptions)

搜尋有關指定電話號碼的作員資訊。

function searchOperatorInformation(phoneNumbers: string[], options?: SearchOperatorInformationOptions): Promise<OperatorInformationResult>

參數

phoneNumbers

string[]

要搜尋的電話號碼。

options
SearchOperatorInformationOptions

其他要求選項。

傳回