빠른 시작: 전화 번호 가져오기 및 관리

Important

SMS와 PSTN 기능은 사용하는 전화 번호와 Azure 청구 주소에 따라 결정되는 운영 국가/지역에 따라 다릅니다. 자세한 내용은 구독 자격 설명서를 참조하세요.

Important

대량 주문이 필요하거나 원하는 전화 번호를 사용할 수 없는 경우 이 페이지를 방문하여 추가 지원을 받으세요.

필수 조건

전화 번호 받기

번호 프로비저닝을 시작하려면 Azure Portal에서 Communication Services 리소스로 이동합니다.

Communication Services 리소스의 기본 페이지를 보여 주는 스크린샷

사용 가능한 전화 번호 검색

리소스 메뉴에서 전화 번호 블레이드로 이동합니다.

Communication Services 리소스의 전화 페이지를 보여 주는 스크린샷

가져오기 단추를 눌러 마법사를 시작합니다. 전화 번호 블레이드의 마법사는 시나리오에 가장 적합한 전화 번호를 선택하는 데 도움이 되는 일련의 질문을 안내합니다.

먼저 전화 번호를 프로비저닝하려는 국가/지역을 선택해야 합니다. 국가/지역이 선택되면 요구 사항에 가장 적합한 사용 사례를 선택해야 합니다.

전화 번호 가져오기 보기를 보여 주는 스크린샷

전화 번호 기능 선택

전화 번호 구성은 다음 두 단계로 구분됩니다.

  1. 전화 번호 유형 선택
  2. 전화 번호 기능 선택

현지수신자 부담의 두 가지 전화번호 유형 중에서 선택할 수 있습니다. 전화 번호 유형이 선택되면 기능을 선택할 수 있습니다.

이 예에서는 전화 걸기SMS 보내기 및 받기 기능이 있는 수신자 부담 번호 유형을 선택했습니다.

기능 선택 보기를 보여 주는 스크린샷.

여기서 페이지 맨 아래에 있는 다음: 번호 단추를 클릭하여 프로비저닝할 전화 번호를 사용자 지정합니다.

전화 번호 사용자 지정

전화 번호 페이지에서 프로비저닝하려는 전화 번호를 사용자 지정합니다.

[번호 선택] 페이지를 보여주는 스크린샷

참고 항목

이 빠른 시작에서는 무료 전화 번호 유형의 사용자 지정 흐름을 보여 줍니다. 현지 번호 유형을 선택한 경우 환경이 약간 다를 수 있지만 최종 결과는 동일합니다.

사용 가능한 지역 코드 목록에서 지역 코드를 선택하고, 프로비저닝하려는 수량을 입력한 다음, 검색을 클릭하여 선택한 요구 사항을 충족하는 전화 번호를 찾습니다. 요구 사항을 충족하는 전화 번호가 해당 월간 비용과 함께 표시됩니다.

예약된 번호가 있는 숫자 선택 페이지를 보여 주는 스크린샷

참고 항목

가용성은 선택한 전화 번호 유형, 위치 및 기능에 따라 달라집니다. 번호는 트랜잭션이 만료되기 전까지 짧은 시간 동안 예약됩니다. 트랜잭션이 만료되면 번호를 다시 선택해야 합니다.

구매 요약 정보를 살펴보고 주문을 넣으려면 페이지 맨 아래에 있는 다음: 요약 단추를 클릭합니다.

전화 번호 구매

요약 페이지에서 번호 유형, 기능, 전화 번호 및 전화 번호를 프로비저닝하는 데 소요되는 총 월간 비용을 검토합니다.

참고 항목

표시된 가격은 선택한 전화 번호를 사용자에게 임대하는 비용을 포함하는 월별 정기 요금입니다. 전화를 걸거나 받을 때 발생하는 종량제 비용은 이 보기에 포함되지 않습니다. 가격표는 여기서 확인할 수 있습니다. 이러한 비용은 번호 유형과 전화를 건 대상에 따라 다릅니다. 예를 들어, 시애틀 지역 번호에서 뉴욕 지역 번호로 전화를 걸 때 분당 요금과 같은 번호에서 영국 핸드폰 번호로 전화를 걸 때 분당 요금이 서로 다를 수 있습니다.

마지막으로, 페이지 아래쪽에서 주문을 클릭하여 확인합니다.

번호 유형, 기능, 전화 번호, 총 월간 비용이 표시된 요약 페이지를 보여주는 스크린샷

Azure Portal에서 전화 번호 찾기

Azure Portal에서 Azure Communication Services 리소스로 이동합니다.

Communication Services 리소스의 기본 페이지를 보여 주는 스크린샷

메뉴에서 [전화 번호] 블레이드를 선택하여 전화 번호를 관리합니다.

Communication Services 리소스의 전화 번호 페이지를 보여 주는 스크린샷

참고 항목

프로비저닝된 번호가 이 페이지에 표시될 때까지 몇 분 정도 걸릴 수 있습니다.

전화 번호 기능 업데이트

전화 번호 페이지에서 구성할 전화 번호를 선택할 수 있습니다.

기능 업데이트 페이지를 보여 주는 스크린샷

사용 가능한 옵션에서 기능을 선택한 다음, 저장을 클릭하여 선택 항목을 적용합니다.

전화 번호 해제

숫자 페이지에서 전화 번호를 해제할 수 있습니다.

릴리스 전화 번호 페이지를 보여 주는 스크린샷.

해제할 전화 번호를 선택한 다음, 해제 단추를 클릭합니다.

Important

Azure Communication Services의 이 기능은 현재 미리 보기 상태입니다.

미리 보기 API 및 SDK는 서비스 수준 계약 없이 제공됩니다. 프로덕션 워크로드에는 사용하지 않는 것이 좋습니다. 일부 기능은 지원되지 않거나 기능이 제한될 수 있습니다.

자세한 내용은 Microsoft Azure 미리 보기에 대한 보충 사용 약관을 검토하세요.

Azure Communication Services는 전화 번호를 구매하기 위한 새로운 사용자 환경을 도입하고 있습니다. 이 환경은 현재 플라이트 중이며 Azure Portal에서 전화 번호를 구매할 때 이 환경을 소개할 수 있습니다. 이 환경에 대한 피드백이 있는 경우 Azure Portal 확장의 피드백 제공 단추를 통해 제공하는 것을 주저하지 마세요.

필수 조건

전화 번호 구매

  1. Azure Portal에서 Communication Service 리소스로 이동합니다.

    Communication Services 리소스의 기본 페이지를 보여 주는 스크린샷

  2. Communication Services 리소스 개요의 왼쪽 메뉴에서 “전화 번호” 옵션을 선택합니다.

    Communication Services 리소스의 전화 번호 페이지를 보여 주는 스크린샷

  3. 페이지 왼쪽 위에서 가져오기를 선택하여 전화 번호를 구입합니다. 이 옵션을 선택하면 쇼핑 마법사가 시작됩니다.

    전화 번호 쇼핑 카트 검색 마법사를 보여 주는 스크린샷.

  4. 전화 번호를 프로비전할 국가/지역을 선택합니다. 국가 가용성은 Azure 구독의 청구 위치를 기반으로 합니다. 각 국가에 사용할 수 있는 숫자에 대한 자세한 내용은 여기에서 확인할 수 있습니다. 다음으로 숫자 유형을 선택합니다. 현지수신자 부담의 두 가지 전화번호 유형 중에서 선택할 수 있습니다.

  5. 검색을 선택하여 선택한 조건에 맞는 숫자를 끌어올 수 있습니다. 다음을 포함하여 요구 사항에 맞는 숫자를 검색할 수 있는 다양한 필터가 있습니다.

    • 사용 사례: A2P(애플리케이션) 또는 P2P(인간 에이전트)에서 호출하는 데 이 번호를 사용하는지 여부입니다.
    • 통화: 전화 번호에 대해 원하는 통화 기능(전화 걸기 및/또는 통화 수신)을 결정하기 위한 것입니다.
    • SMS: 전화 번호에 대해 원하는 SMS 기능(SMS 메시지 보내기 및/또는 수신)을 결정하기 위한 것입니다.
    • 사용자 지정: 사용자 지정 필터를 추가하여 전화 번호의 특정 접두사 또는 숫자 집합을 가져올 수도 있습니다.

    사용 가능한 전화 번호가 있는 전화 번호 구매 페이지를 보여 주는 스크린샷

  6. 선택한 전화 번호 또는 번호를 찾으면 카트에 추가를 선택하여 전화 통신 카트에 번호를 저장합니다. 이 번호는 카트가 자동으로 지워지기 전에 16분 동안 보관됩니다.

    카트에 두 개의 전화 번호가 있는 전화 번호 쇼핑 카트를 보여 주는 스크린샷.

    참고 항목

    표시된 가격은 선택한 전화 번호를 사용자에게 임대하는 비용을 포함하는 월별 정기 요금입니다. 전화를 걸거나 받을 때 발생하는 종량제 비용은 이 보기에 포함되지 않습니다. 가격표는 여기서 확인할 수 있습니다. 이러한 비용은 번호 유형과 전화를 건 대상에 따라 다릅니다. 예를 들어, 시애틀 지역 번호에서 뉴욕 지역 번호로 전화를 걸 때 분당 요금과 같은 번호에서 영국 핸드폰 번호로 전화를 걸 때 분당 요금이 서로 다를 수 있습니다.

  7. 다음을 선택하여 구매를 검토합니다. 구매를 완료하려면 지금 구매를 선택합니다.

    검토하고 구매할 전화 번호 2개 스크린샷

  8. 구매한 번호는 전화 번호 페이지에서 다시 찾을 수 있습니다. 숫자가 프로비전되는 데 몇 분 정도 걸릴 수 있습니다.

    새로 구입한 전화 번호가 빨간색 테두리로 상자로 표시된 전화 번호 페이지의 스크린샷

전화 번호 기능 업데이트

전화 번호 페이지에서 구성할 전화 번호를 선택할 수 있습니다.

기능 업데이트 페이지를 보여 주는 스크린샷

사용 가능한 옵션에서 기능을 선택한 다음 저장을 선택하여 선택 항목을 적용합니다.

전화 번호 해제

숫자 페이지에서 전화 번호를 해제할 수 있습니다.

릴리스 전화 번호 페이지를 보여 주는 스크린샷.

해제할 전화 번호를 선택한 다음 릴리스 단추를 선택합니다.

필수 조건

설정

확장 추가

az extension 명령을 사용하여 Azure CLI에 대한 Azure Communication Services 확장을 추가합니다.

az extension add --name communication

Azure CLI에 로그인

Azure CLI에 로그인해야 합니다. 터미널에서 az login 명령을 실행하고 자격 증명을 제공하여 로그인할 수 있습니다.

작업

구매한 전화 번호 목록

다음 명령을 실행하여 구매한 전화 번호를 모두 검색합니다.

az communication phonenumber list --connection-string "<yourConnectionString>"

코드에서 다음을 대체합니다.

  • <yourConnectionString>을 연결 문자열로 바꿉니다.

구매한 전화 번호 세부 정보 가져오기

다음 명령을 실행하여 구매한 전화 번호에 대한 전화 번호 세부 정보를 가져옵니다.

az communication phonenumber show --phonenumber <purchasedPhoneNumber> --connection-string "<yourConnectionString>"

코드에서 다음과 같이 바꿉니다.

  • <purchasedPhoneNumber>를 Communication Services 리소스와 연결된 전화번호로 바꿉니다.
  • <yourConnectionString>을 연결 문자열로 바꿉니다.

참고 항목

Azure CLI 옵션은 전화 번호를 나열하고 표시하는 기능만 제공합니다. 전화 번호 검색, 구매, 편집 또는 해제와 같은 다른 작업은 지원하지 않습니다.

(선택 사항) 연결 문자열을 전달하지 않고 Azure CLI 전화 번호 작업 사용

--connection_string을 사용하여 연결 문자열을 전달하지 않고도 Azure CLI 전화 번호 작업을 사용하도록 AZURE_COMMUNICATION_CONNECTION_STRING 환경 변수를 구성할 수 있습니다. 환경 변수를 구성하려면 콘솔 창을 열고 아래 탭에서 운영 체제를 선택합니다. <yourConnectionString>을 실제 연결 문자열로 바꿉니다.

콘솔 창을 열고 다음 명령을 입력합니다.

setx AZURE_COMMUNICATION_CONNECTION_STRING "<yourConnectionString>"

환경 변수를 추가한 후에는 콘솔 창을 포함하여 실행 중인 프로그램 중에서 환경 변수를 읽어야 하는 프로그램을 다시 시작해야 할 수도 있습니다. 예를 들어 편집기로 Visual Studio를 사용하는 경우 Visual Studio를 다시 시작한 후 예제를 실행합니다.

참고 항목

GitHub에서 이 빠른 시작에 대한 최종 코드 칮기

필수 조건

필수 구성 요소 확인

  • 터미널 또는 명령 창에서 dotnet 명령을 실행하여 .NET 클라이언트 라이브러리가 설치되어 있는지 확인합니다.

설정

새 C# 애플리케이션 만들기

콘솔 창(예: cmd, PowerShell 또는 Bash)에서 dotnet new 명령을 사용하여 PhoneNumbersQuickstart라는 새 콘솔 앱을 만듭니다. 이 명령은 Program.cs라는 원본 파일 하나만 들어 있는 간단한 "Hello World" C# 프로젝트를 만듭니다.

dotnet new console -o PhoneNumbersQuickstart

디렉터리를 새로 만든 앱 폴더로 변경하고 dotnet build 명령을 사용하여 애플리케이션을 컴파일합니다.

cd PhoneNumbersQuickstart
dotnet build

패키지 설치

애플리케이션 디렉터리에 있는 동안 dotnet add package 명령을 사용하여 .NET 패키지용 Azure Communication PhoneNumbers 클라이언트 라이브러리를 설치합니다.

dotnet add package Azure.Communication.PhoneNumbers --version 1.0.0

Program.cs의 맨 위에 using 지시어를 추가하여 네임스페이스를 포함합니다.

using System;
using System.Linq;
using System.Threading.Tasks;
using Azure.Communication.PhoneNumbers;

Main 함수 시그니처를 비동기화하도록 업데이트합니다.

static async Task Main(string[] args)
{
  ...
}

클라이언트 인증

전화 번호 클라이언트는 Azure Portal의 Azure Communication Services 리소스에서 가져온 연결 문자열을 사용하여 인증할 수 있습니다.

// Get a connection string to our Azure Communication Services resource.
var connectionString = "<connection_string>";
var client = new PhoneNumbersClient(connectionString);

전화 번호 클라이언트는 Microsoft Entra 인증을 사용하여 인증하는 옵션도 있습니다. 이 옵션을 사용하는 경우 인증을 위해 AZURE_CLIENT_SECRET, AZURE_CLIENT_IDAZURE_TENANT_ID 환경 변수를 설정해야 합니다.

// Get an endpoint to our Azure Communication Services resource.
var endpoint = new Uri("<endpoint_url>");
TokenCredential tokenCredential = new DefaultAzureCredential();
client = new PhoneNumbersClient(endpoint, tokenCredential);

전화번호 관리

사용 가능한 전화 번호 검색

전화 번호를 구매하려면 먼저 사용 가능한 전화 번호를 검색해야 합니다. 전화 번호를 검색하려면 지역 번호, 할당 유형, 전화 번호 기능, 전화 번호 유형 및 수량을 제공합니다. 수신자 부담 전화 번호 형식의 경우 지역 코드 제공은 선택 사항입니다.

var capabilities = new PhoneNumberCapabilities(calling:PhoneNumberCapabilityType.None, sms:PhoneNumberCapabilityType.Outbound);
var searchOptions = new PhoneNumberSearchOptions { AreaCode = "833", Quantity = 1 };

var searchOperation = await client.StartSearchAvailablePhoneNumbersAsync("US", PhoneNumberType.TollFree, PhoneNumberAssignmentType.Application, capabilities, searchOptions);
await searchOperation.WaitForCompletionAsync();

전화 번호 구매

전화 번호 검색의 결과는 PhoneNumberSearchResult입니다. 여기에는 검색 시 숫자를 얻기 위해 번호 구매 API에 전달할 수 있는 SearchId가 포함됩니다. 전화 번호 구매 API를 호출하면 Azure 계정에 요금이 부과됩니다.

var purchaseOperation = await client.StartPurchasePhoneNumbersAsync(searchOperation.Value.SearchId);
await purchaseOperation.WaitForCompletionResponseAsync();

전화 번호 가져오기

번호 구매 후에 클라이언트에서 검색할 수 있습니다.

var getPhoneNumberResponse = await client.GetPurchasedPhoneNumberAsync("+14255550123");
Console.WriteLine($"Phone number: {getPhoneNumberResponse.Value.PhoneNumber}, country code: {getPhoneNumberResponse.Value.CountryCode}");

구매한 전화 번호를 모두 검색할 수도 있습니다.

var purchasedPhoneNumbers = client.GetPurchasedPhoneNumbersAsync();
await foreach (var purchasedPhoneNumber in purchasedPhoneNumbers)
{
    Console.WriteLine($"Phone number: {purchasedPhoneNumber.PhoneNumber}, country code: {purchasedPhoneNumber.CountryCode}");
}

전화 번호 기능 업데이트

구매한 번호를 사용하면 기능을 업데이트할 수 있습니다.

var updateCapabilitiesOperation = await client.StartUpdateCapabilitiesAsync("+14255550123", calling: PhoneNumberCapabilityType.Outbound, sms: PhoneNumberCapabilityType.InboundOutbound);
await updateCapabilitiesOperation.WaitForCompletionAsync();

전화 번호 해제

구매한 전화 번호를 해제할 수 있습니다.

var releaseOperation = await client.StartReleasePhoneNumberAsync("+14255550123");
await releaseOperation.WaitForCompletionResponseAsync();

코드 실행

dotnet run 명령을 사용하여 애플리케이션 디렉터리에서 애플리케이션을 실행합니다.

dotnet run

예제 코드

샘플 앱은 GitHub에서 다운로드할 수 있습니다.

참고 항목

GitHub에서 이 빠른 시작에 대한 최종 코드 칮기

필수 조건

설정

새 Java 애플리케이션 만들기

터미널 또는 명령 창을 엽니다. Java 애플리케이션을 만들 디렉터리로 이동합니다. 아래 명령을 실행하여 maven-archetype-quickstart 템플릿에서 Java 프로젝트를 생성합니다.

mvn archetype:generate -DgroupId=com.communication.quickstart -DartifactId=communication-quickstart -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

'생성' 작업에서 artifactId와 동일한 이름으로 디렉터리를 만들었습니다. 이 디렉터리 아래에서 src/main/java 디렉터리는 프로젝트 소스 코드를 포함하고, src/test/java directory는 테스트 원본을 포함하고, pom.xml 파일은 프로젝트의 프로젝트 개체 모델 또는 POM입니다.

패키지 설치

텍스트 편집기에서 pom.xml 파일을 엽니다. 종속성 그룹에 다음 종속성 요소를 추가합니다.

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-communication-common</artifactId>
    <version>1.0.0</version>
</dependency>

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-communication-phonenumbers</artifactId>
    <version>1.0.0</version>
</dependency>

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.2.3</version>
</dependency>

앱 프레임워크 설정

프로젝트 디렉터리에서 다음을 수행합니다.

  1. /src/main/java/com/communication/quickstart 디렉터리로 이동합니다.
  2. 편집기에서 App.java 파일을 엽니다.
  3. System.out.println("Hello world!"); 문 바꾸기
  4. import 지시문 추가

시작하려면 다음 코드를 사용합니다.

import com.azure.communication.phonenumbers.*;
import com.azure.communication.phonenumbers.models.*;
import com.azure.core.http.rest.*;
import com.azure.core.util.Context;
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.PollResponse;
import com.azure.core.util.polling.SyncPoller;
import com.azure.identity.*;
import java.io.*;

public class App
{
    public static void main( String[] args ) throws IOException
    {
        System.out.println("Azure Communication Services - Phone Numbers Quickstart");
        // Quickstart code goes here
    }
}

전화 번호 클라이언트 인증

Microsoft Entra 인증을 사용하도록 PhoneNumberClientBuilder가 활성화되어 있습니다.

// You can find your endpoint and access key from your resource in the Azure portal
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";

PhoneNumbersClient phoneNumberClient = new PhoneNumbersClientBuilder()
    .endpoint(endpoint)
    .credential(new DefaultAzureCredentialBuilder().build())
    .buildClient();

또는 통신 리소스의 엔드포인트 및 액세스 키를 사용하여 인증할 수도 있습니다.

// You can find your connection string from your resource in the Azure portal
String connectionString = "endpoint=https://<RESOURCE_NAME>.communication.azure.com/;accesskey=<ACCESS_KEY>";

PhoneNumbersClient phoneNumberClient = new PhoneNumbersClientBuilder()
    .connectionString(connectionString)
    .buildClient();

전화 번호 관리

사용 가능한 전화 번호 검색

전화 번호를 구매하려면 먼저 사용 가능한 전화 번호를 검색해야 합니다. 전화 번호를 검색하려면 지역 번호, 할당 유형, 전화 번호 기능, 전화 번호 유형 및 수량을 제공합니다. 수신자 부담 전화 번호 형식의 경우 지역 코드 제공은 선택 사항입니다.

 PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities()
    .setCalling(PhoneNumberCapabilityType.INBOUND)
    .setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND);
PhoneNumberSearchOptions searchOptions = new PhoneNumberSearchOptions().setAreaCode("833").setQuantity(1);

SyncPoller<PhoneNumberOperation, PhoneNumberSearchResult> poller = phoneNumberClient
    .beginSearchAvailablePhoneNumbers("US", PhoneNumberType.TOLL_FREE, PhoneNumberAssignmentType.APPLICATION, capabilities, searchOptions, Context.NONE);
PollResponse<PhoneNumberOperation> response = poller.waitForCompletion();
String searchId = "";

if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
    PhoneNumberSearchResult searchResult = poller.getFinalResult();
    searchId = searchResult.getSearchId();
    System.out.println("Searched phone numbers: " + searchResult.getPhoneNumbers());
    System.out.println("Search expires by: " + searchResult.getSearchExpiresBy());
    System.out.println("Phone number costs:" + searchResult.getCost().getAmount());
}

전화 번호 구매

전화 번호 검색의 결과는 PhoneNumberSearchResult입니다. 여기에는 검색 시 숫자를 얻기 위해 번호 구매 API에 전달할 수 있는 searchId가 포함됩니다. 전화 번호 구매 API를 호출하면 Azure 계정에 요금이 부과됩니다.

PollResponse<PhoneNumberOperation> purchaseResponse = phoneNumberClient.beginPurchasePhoneNumbers(searchId, Context.NONE).waitForCompletion();
System.out.println("Purchase phone numbers operation is: " + purchaseResponse.getStatus());

전화 번호 가져오기

번호 구매 후에 클라이언트에서 검색할 수 있습니다.

PurchasedPhoneNumber phoneNumber = phoneNumberClient.getPurchasedPhoneNumber("+14255550123");
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());

구매한 전화 번호를 모두 검색할 수도 있습니다.

PagedIterable<PurchasedPhoneNumber> phoneNumbers = phoneNumberClient.listPurchasedPhoneNumbers(Context.NONE);
PurchasedPhoneNumber phoneNumber = phoneNumbers.iterator().next();
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());

전화 번호 기능 업데이트

구매한 번호를 사용하면 기능을 업데이트할 수 있습니다.

PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities();
capabilities
    .setCalling(PhoneNumberCapabilityType.INBOUND)
    .setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND);

SyncPoller<PhoneNumberOperation, PurchasedPhoneNumber> poller = phoneNumberClient.beginUpdatePhoneNumberCapabilities("+18001234567", capabilities, Context.NONE);
PollResponse<PhoneNumberOperation> response = poller.waitForCompletion();
if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
    PurchasedPhoneNumber phoneNumber = poller.getFinalResult();
    System.out.println("Phone Number Calling capabilities: " + phoneNumber.getCapabilities().getCalling()); //Phone Number Calling capabilities: inbound
    System.out.println("Phone Number SMS capabilities: " + phoneNumber.getCapabilities().getSms()); //Phone Number SMS capabilities: inbound+outbound
}

전화 번호 해제

구매한 전화 번호를 해제할 수 있습니다.

PollResponse<PhoneNumberOperation> releaseResponse =
    phoneNumberClient.beginReleasePhoneNumber("+14255550123", Context.NONE).waitForCompletion();
System.out.println("Release phone number operation is: " + releaseResponse.getStatus());

코드 실행

pom.xml 파일이 포함된 디렉터리로 이동한 후 다음 mvn 명령을 사용하여 프로젝트를 컴파일합니다.

mvn compile

그런 다음, 패키지를 빌드합니다.

mvn package

다음 mvn 명령을 실행하여 앱을 실행합니다.

mvn exec:java -Dexec.mainClass="com.communication.quickstart.App" -Dexec.cleanupDaemonThreads=false

앱의 출력은 완료된 각 작업을 설명합니다.

Azure Communication Services - Phone Numbers Quickstart

Searched phone numbers: [+18001234567]

Purchase phone numbers operation is: SUCCESSFULLY_COMPLETED

Phone Number Country Code: US

Phone Number Calling capabilities: inbound

Phone Number SMS capabilities: inbound

Release phone number operation is: SUCCESSFULLY_COMPLETED

참고 항목

GitHub에서 이 빠른 시작에 대한 최종 코드 칮기

필수 조건

설정

새 Python 애플리케이션 만들기

터미널 또는 명령 창을 열어 앱에 대한 새 디렉터리를 만든 다음, 해당 디렉터리로 이동합니다.

mkdir phone-numbers-quickstart && cd phone-numbers-quickstart

텍스트 편집기를 사용하여 phone_numbers_sample.py라고 하는 파일을 프로젝트 루트 디렉터리에 만들고 다음 코드를 추가합니다. 다음 섹션에서 나머지 빠른 시작 코드를 추가합니다.

import os
from azure.communication.phonenumbers import PhoneNumbersClient

try:
   print('Azure Communication Services - Phone Numbers Quickstart')
   # Quickstart code goes here
except Exception as ex:
   print('Exception:')
   print(ex)

패키지 설치

애플리케이션 디렉터리에 있는 동안 pip install 명령을 사용하여 Python 패키지용 Azure Communication Services 관리 클라이언트 라이브러리를 설치합니다.

pip install azure-communication-phonenumbers

전화 번호 클라이언트 인증

PhoneNumbersClient를 사용하도록 설정하여 Microsoft Entra 인증을 사용할 수 있습니다. DefaultAzureCredential 개체를 사용하면 가장 손쉽게 Microsoft Entra ID를 시작할 수 있으며 pip install 명령을 사용하여 설치할 수 있습니다.

pip install azure-identity

DefaultAzureCredential 개체를 만들려면 등록된 Microsoft Entra 애플리케이션에서 AZURE_CLIENT_ID, AZURE_CLIENT_SECRETAZURE_TENANT_ID가 해당 값을 사용하여 환경 변수로 이미 등록되어 있어야 합니다.

환경 변수를 가져오는 방법을 빠르게 확인하려면 CLI에서 서비스 주체 설정 빠른 시작을 따를 수 있습니다.

azure-identity 라이브러리를 설치했으면 클라이언트를 계속 인증할 수 있습니다.

import os
from azure.communication.phonenumbers import PhoneNumbersClient
from azure.identity import DefaultAzureCredential

# You can find your endpoint from your resource in the Azure portal
endpoint = 'https://<RESOURCE_NAME>.communication.azure.com'
try:
    print('Azure Communication Services - Phone Numbers Quickstart')
    credential = DefaultAzureCredential()
    phone_numbers_client = PhoneNumbersClient(endpoint, credential)
except Exception as ex:
    print('Exception:')
    print(ex)

또는 통신 리소스의 엔드포인트 및 액세스 키를 사용하여 인증할 수도 있습니다.

import os
from azure.communication.phonenumbers import PhoneNumbersClient

# You can find your connection string from your resource in the Azure portal
connection_string = 'https://<RESOURCE_NAME>.communication.azure.com/;accesskey=<YOUR_ACCESS_KEY>'
try:
    print('Azure Communication Services - Phone Numbers Quickstart')
    phone_numbers_client = PhoneNumbersClient.from_connection_string(connection_string)
except Exception as ex:
    print('Exception:')
    print(ex)

함수

PhoneNumbersClient가 인증된 후에는 수행할 수 있는 다른 함수에서 작업을 시작할 수 있습니다.

사용 가능한 전화 번호 검색

전화 번호를 구매하려면 먼저 사용 가능한 전화 번호를 검색해야 합니다. 전화 번호를 검색하려면 지역 번호, 할당 유형, 전화 번호 기능, 전화 번호 유형 및 수량(기본 수량은 1로 설정됨)을 제공합니다. 수신자 부담 전화 번호 형식의 경우 지역 코드 제공은 선택 사항입니다.

import os
from azure.communication.phonenumbers import PhoneNumbersClient, PhoneNumberCapabilityType, PhoneNumberAssignmentType, PhoneNumberType, PhoneNumberCapabilities
from azure.identity import DefaultAzureCredential

# You can find your endpoint from your resource in the Azure portal
endpoint = 'https://<RESOURCE_NAME>.communication.azure.com'
try:
    print('Azure Communication Services - Phone Numbers Quickstart')
    credential = DefaultAzureCredential()
    phone_numbers_client = PhoneNumbersClient(endpoint, credential)
    capabilities = PhoneNumberCapabilities(
        calling = PhoneNumberCapabilityType.INBOUND,
        sms = PhoneNumberCapabilityType.INBOUND_OUTBOUND
    )
    search_poller = phone_numbers_client.begin_search_available_phone_numbers(
        "US",
        PhoneNumberType.TOLL_FREE,
        PhoneNumberAssignmentType.APPLICATION,
        capabilities,
        polling = True
    )
    search_result = search_poller.result()
    print ('Search id: ' + search_result.search_id)
    phone_number_list = search_result.phone_numbers
    print('Reserved phone numbers:')
    for phone_number in phone_number_list:
        print(phone_number)

except Exception as ex:
    print('Exception:')
    print(ex)

전화 번호 구매

전화 번호 검색의 결과는 PhoneNumberSearchResult입니다. 여기에는 검색 시 숫자를 얻기 위해 번호 구매 API에 전달할 수 있는 searchId가 포함됩니다. 전화 번호 구매 API를 호출하면 Azure 계정에 요금이 부과됩니다.

import os
from azure.communication.phonenumbers import (
    PhoneNumbersClient,
    PhoneNumberCapabilityType,
    PhoneNumberAssignmentType,
    PhoneNumberType,
    PhoneNumberCapabilities
)
from azure.identity import DefaultAzureCredential

# You can find your endpoint from your resource in the Azure portal
endpoint = 'https://<RESOURCE_NAME>.communication.azure.com'
try:
    print('Azure Communication Services - Phone Numbers Quickstart')
    credential = DefaultAzureCredential()
    phone_numbers_client = PhoneNumbersClient(endpoint, credential)
    capabilities = PhoneNumberCapabilities(
        calling = PhoneNumberCapabilityType.INBOUND,
        sms = PhoneNumberCapabilityType.INBOUND_OUTBOUND
    )
    search_poller = phone_numbers_client.begin_search_available_phone_numbers(
        "US",
        PhoneNumberType.TOLL_FREE,
        PhoneNumberAssignmentType.APPLICATION,
        capabilities,
        area_code="833",
        polling = True
    )
    search_result = poller.result()
    print ('Search id: ' + search_result.search_id)
    phone_number_list = search_result.phone_numbers
    print('Reserved phone numbers:')
    for phone_number in phone_number_list:
        print(phone_number)

    purchase_poller = phone_numbers_client.begin_purchase_phone_numbers(search_result.search_id, polling = True)
    purchase_poller.result()
    print("The status of the purchase operation was: " + purchase_poller.status())
except Exception as ex:
    print('Exception:')
    print(ex)

구매한 전화 번호 가져오기

번호 구매 후에 클라이언트에서 검색할 수 있습니다.

purchased_phone_number_information = phone_numbers_client.get_purchased_phone_number("+18001234567")
print('Phone number: ' + purchased_phone_number_information.phone_number)
print('Country code: ' + purchased_phone_number_information.country_code)

구매한 전화 번호를 모두 검색할 수도 있습니다.

purchased_phone_numbers = phone_numbers_client.list_purchased_phone_numbers()
print('Purchased phone numbers:')
for purchased_phone_number in purchased_phone_numbers:
    print(purchased_phone_number.phone_number)

전화 번호 기능 업데이트

이전에 구매한 전화 번호의 기능을 업데이트할 수 있습니다.

update_poller = phone_numbers_client.begin_update_phone_number_capabilities(
    "+18001234567",
    PhoneNumberCapabilityType.OUTBOUND,
    PhoneNumberCapabilityType.OUTBOUND,
    polling = True
)
update_poller.result()
print('Status of the operation: ' + update_poller.status())

전화 번호 해제

구매한 전화 번호를 해제할 수 있습니다.

release_poller = phone_numbers_client.begin_release_phone_number("+18001234567")
release_poller.result()
print('Status of the operation: ' + release_poller.status())

코드 실행

콘솔 프롬프트에서 phone_numbers_sample.py 파일이 포함된 디렉터리로 이동한 다음, 다음 Python 명령을 실행하여 앱을 실행합니다.

python phone_numbers_sample.py

참고 항목

GitHub에서 이 빠른 시작에 대한 최종 코드 칮기

필수 조건

필수 구성 요소 확인

  • 터미널 또는 명령 창에서 node --version를 실행하여 Node.js가 설치되어 있는지 확인합니다.

설정

새 Node.js 애플리케이션 만들기

먼저 터미널 또는 명령 창을 열어 앱에 대한 새 디렉터리를 만들고 해당 디렉터리로 이동합니다.

mkdir phone-numbers-quickstart && cd phone-numbers-quickstart

npm init -y를 실행하여 기본 설정으로 package.json 파일을 만듭니다.

npm init -y

방금 만든 디렉터리의 루트에 phone-numbers-quickstart.js라는 파일을 만듭니다. 다음 조각을 추가합니다.

async function main() {
    // quickstart code will here
}

main();

패키지 설치

npm install 명령을 사용하여 JavaScript용 Azure Communication Services 전화 번호 클라이언트 라이브러리를 설치합니다.

npm install @azure/communication-phone-numbers --save

--save 옵션은 라이브러리를 package.json 파일의 종속성으로 추가합니다.

클라이언트 인증

클라이언트 라이브러리에서 PhoneNumbersClient를 가져와서 연결 문자열로 인스턴스화합니다. 아래 코드는 COMMUNICATION_SERVICES_CONNECTION_STRING이라는 환경 변수에서 리소스에 대한 연결 문자열을 검색합니다. 리소스의 연결 문자열을 관리하는 방법을 알아봅니다.

phone-numbers-quickstart.js의 맨 위에 다음 코드를 추가합니다.

const { PhoneNumbersClient } = require('@azure/communication-phone-numbers');

// This code demonstrates how to fetch your connection string
// from an environment variable.
const connectionString = process.env['COMMUNICATION_SERVICES_CONNECTION_STRING'];

// Instantiate the phone numbers client
const phoneNumbersClient = new PhoneNumbersClient(connectionString);

전화번호 관리

사용 가능한 전화 번호 검색

전화 번호를 구매하려면 먼저 사용 가능한 전화 번호를 검색해야 합니다. 전화 번호를 검색하려면 지역 번호, 할당 유형, 전화 번호 기능, 전화 번호 유형 및 수량을 제공합니다. 수신자 부담 전화 번호 형식의 경우 지역 코드 제공은 선택 사항입니다.

main 함수에 다음 코드 조각을 추가합니다.

/**
 * Search for Available Phone Number
 */

// Create search request
const searchRequest = {
    countryCode: "US",
    phoneNumberType: "tollFree",
    assignmentType: "application",
    capabilities: {
      sms: "outbound",
      calling: "none"
    },
    areaCode: "833",
    quantity: 1
  };

const searchPoller = await phoneNumbersClient.beginSearchAvailablePhoneNumbers(searchRequest);

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

console.log(`Found phone number: ${phoneNumber}`);
console.log(`searchId: ${searchId}`);

전화 번호 구매

전화 번호 검색의 결과는 PhoneNumberSearchResult입니다. 여기에는 검색 시 숫자를 얻기 위해 번호 구매 API에 전달할 수 있는 searchId가 포함됩니다. 전화 번호 구매 API를 호출하면 Azure 계정에 요금이 부과됩니다.

main 함수에 다음 코드 조각을 추가합니다.

/**
 * Purchase Phone Number
 */

const purchasePoller = await phoneNumbersClient.beginPurchasePhoneNumbers(searchId);

// Purchase is underway.
await purchasePoller.pollUntilDone();
console.log(`Successfully purchased ${phoneNumber}`);

전화 번호 기능 업데이트

이제 전화 번호를 구매한 후 다음 코드를 추가하여 해당 기능을 업데이트합니다.

/**
 * Update Phone Number Capabilities
 */

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

const updatePoller = await phoneNumbersClient.beginUpdatePhoneNumberCapabilities(
  phoneNumber,
  updateRequest
);

// Update is underway.
await updatePoller.pollUntilDone();
console.log("Phone number updated successfully.");

구매한 전화 번호 가져오기

번호 구매 후에 클라이언트에서 검색할 수 있습니다. main 함수에 다음 코드를 추가하여 방금 구매한 전화 번호를 가져옵니다.

/**
 * Get Purchased Phone Number
 */

const { capabilities } = await phoneNumbersClient.getPurchasedPhoneNumber(phoneNumber);
console.log("These capabilities:", capabilities, "should be the same as these:", updateRequest, ".");

구매한 전화 번호를 모두 검색할 수도 있습니다.

const purchasedPhoneNumbers = await phoneNumbersClient.listPurchasedPhoneNumbers();

for await (const purchasedPhoneNumber of purchasedPhoneNumbers) {
  console.log(`Phone number: ${purchasedPhoneNumber.phoneNumber}, country code: ${purchasedPhoneNumber.countryCode}.`);
}

전화 번호 해제

이제 구매한 전화 번호를 해제할 수 있습니다. main 함수에 아래 코드 조각을 추가합니다.

/**
 * Release Purchased Phone Number
 */

const releasePoller = await phoneNumbersClient.beginReleasePhoneNumber(phoneNumber);

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

코드 실행

node 명령을 사용하여 phone-numbers-quickstart.js 파일에 추가한 코드를 실행합니다.

node phone-numbers-quickstart.js

문제 해결

일반적인 질문 및 문제:

  • 전화 번호가 릴리스되면 청구 주기 끝날 때까지 Azure Portal의 ACS 리소스에 전화 번호가 표시됩니다. 또한 청구 주기 끝날 때까지 재구매할 수 없습니다.

  • Communication Services 리소스가 삭제되면 해당 리소스와 연결된 전화 번호가 동시에 자동으로 해제됩니다.

다음 단계

이 빠른 시작에서는 다음을 수행하는 방법을 알아보았습니다.

  • 전화 번호 구매
  • 전화 번호 관리
  • 전화 번호 재임대
  • 무료 인증 애플리케이션 제출 (필요한 경우 참조)