Skip to content

Commit e4434a1

Browse files
authored
Merge pull request #269135 from ericasp16/add-number-format-to-public-preview-quickstarts
Add number format to public preview quickstarts
2 parents bb08614 + df6815f commit e4434a1

File tree

5 files changed

+184
-87
lines changed

5 files changed

+184
-87
lines changed

articles/communication-services/quickstarts/telephony/includes/number-lookup-java.md

Lines changed: 63 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Get started with the Phone Numbers client library for Java to look up operator information for phone numbers, which can be used to determine whether and how to communicate with that phone number. Follow these steps to install the package and look up operator information about a phone number.
1+
Get started with the Phone Numbers client library for Java to look up operator information for phone numbers, which can be used to determine whether and how to communicate with that phone number. Follow these steps to install the package and look up operator information about a phone number.
22

33
> [!NOTE]
4-
> Find the code for this quickstart on [GitHub](https://github.com/Azure/communication-preview/tree/master/samples/NumberLookup).
4+
> Find the code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/LookupNumber).
55
66
## Prerequisites
77

@@ -29,7 +29,7 @@ mvn archetype:generate -DgroupId=com.communication.lookup.quickstart -DartifactI
2929
The 'generate' task creates a directory with the same name as the `artifactId`. Under this directory, the src/main/java directory contains the project source code, the `src/test/java directory` contains the test source, and the `pom.xml` file is the project's Project Object Model, or POM.
3030

3131
### Connect to dev package feed
32-
The public preview version of the SDK is published to a dev package feed. To connect to the dev feed, open the **pom.xml** file in your text editor and add the dev repo to **both** your pom.xml's `<repositories>` and `<distributionManagement>` sections
32+
The public preview version of the SDK is published to a dev package feed. To connect to the dev feed, open the **pom.xml** file in your text editor and add the dev repo to **both** your pom.xml's `<repositories>` and `<distributionManagement>` sections that you can add if they don't already exist.
3333

3434
```xml
3535
<repository>
@@ -44,7 +44,7 @@ The public preview version of the SDK is published to a dev package feed. To con
4444
</repository>
4545
```
4646

47-
Add or edit the `settings.xml` file in `${user.home}/.m2`
47+
You may need to add or edit the `settings.xml` file in `${user.home}/.m2`
4848

4949
```xml
5050
<server>
@@ -54,7 +54,7 @@ Add or edit the `settings.xml` file in `${user.home}/.m2`
5454
</server>
5555
```
5656

57-
Finally, generate a [Personal Access Token](https://dev.azure.com/azure-sdk/_details/security/tokens) with _Packaging_ read & write scopes and paste it into the `<password>` tag.
57+
You can generate a [Personal Access Token](https://dev.azure.com/azure-sdk/_details/security/tokens) with _Packaging_ read & write scopes and paste it into the `<password>` tag.
5858

5959
More detailed information and other options for connecting to the dev feed can be found [here](https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-java/connect).
6060

@@ -72,7 +72,7 @@ Add the following dependency elements to the group of dependencies in the **pom.
7272
<dependency>
7373
<groupId>com.azure</groupId>
7474
<artifactId>azure-communication-phonenumbers</artifactId>
75-
<version>1.2.0-beta.1</version>
75+
<version>1.2.0-beta.3</version>
7676
</dependency>
7777

7878
<dependency>
@@ -89,6 +89,16 @@ Add the following dependency elements to the group of dependencies in the **pom.
8989
</dependencies>
9090
```
9191

92+
Check the `properties` section to ensure your project is targeting Maven version 1.8 or above.
93+
94+
```xml
95+
<properties>
96+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
97+
<maven.compiler.source>1.8</maven.compiler.source>
98+
<maven.compiler.target>1.8</maven.compiler.target>
99+
</properties>
100+
```
101+
92102
## Code examples
93103

94104
### Set up the app framework
@@ -125,63 +135,87 @@ public class App
125135

126136
### Authenticate the client
127137

128-
## Authenticate the Phone Numbers Client
129-
130-
The `PhoneNumberClientBuilder` is enabled to use Microsoft Entra authentication. Using the `DefaultAzureCredentialBuilder` is the easiest way to get started with Microsoft Entra ID. You can acquire your resource name from an Azure Communication Services resource in the [Azure portal](https://portal.azure.com).
131-
<!-- embedme ./src/samples/java/com/azure/communication/phonenumbers/ReadmeSamples.java#L52-L62 -->
138+
The client can be authenticated using a connection string acquired from an Azure Communication Services resource in the [Azure portal](https://portal.azure.com). Using a `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable is recommended to avoid putting your connection string in plain text within your code. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string).
139+
<!-- embedme ./src/samples/java/com/azure/communication/phonenumbers/ReadmeSamples.java#L30-L41 -->
132140
```java
133-
// You can find your resource name from your resource in the Azure portal
134-
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
141+
// This code retrieves your connection string from an environment variable
142+
String connectionString = System.getenv("COMMUNICATION_SERVICES_CONNECTION_STRING");
135143

136144
PhoneNumbersClient phoneNumberClient = new PhoneNumbersClientBuilder()
137-
.endpoint(endpoint)
138-
.credential(new DefaultAzureCredentialBuilder().build())
145+
.connectionString(connectionString)
139146
.buildClient();
140147
```
141148

142-
Alternatively, the client can be authenticated using a connection string, also acquired from an Azure Communication Services resource in the [Azure portal](https://portal.azure.com). It's recommended to use a `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable to avoid putting your connection string in plain text within your code. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string).
143-
<!-- embedme ./src/samples/java/com/azure/communication/phonenumbers/ReadmeSamples.java#L30-L41 -->
149+
Alternatively, you can authenticate using Microsoft Entra authentication. Using the `DefaultAzureCredentialBuilder` is the easiest way to get started with Microsoft Entra ID. You can acquire your resource name from an Azure Communication Services resource in the [Azure portal](https://portal.azure.com).
150+
<!-- embedme ./src/samples/java/com/azure/communication/phonenumbers/ReadmeSamples.java#L52-L62 -->
144151
```java
145-
// This code retrieves your connection string from an environment variable
146-
String connectionString = System.getenv("COMMUNICATION_SERVICES_CONNECTION_STRING");
152+
// You can find your resource name from your resource in the Azure portal
153+
String endpoint = "https://<RESOURCE_NAME>.communication.azure.com";
147154

148155
PhoneNumbersClient phoneNumberClient = new PhoneNumbersClientBuilder()
149-
.connectionString(connectionString)
156+
.endpoint(endpoint)
157+
.credential(new DefaultAzureCredentialBuilder().build())
150158
.buildClient();
151159
```
152160

153-
### Look up operator information for a number
161+
### Look up phone number formatting
154162

155-
To search for a phone number's operator information, call `searchOperatorInformation` from the `PhoneNumbersClient`.
163+
To look up the national and international formatting for a number, call `searchOperatorInformation` from the `PhoneNumbersClient`.
156164

157165
```java
158166
ArrayList<String> phoneNumbers = new ArrayList<String>();
159167
phoneNumbers.add("<target-phone-number>");
160-
OperatorInformationResult result = phoneNumberClient.searchOperatorInformation(phoneNumbers);
168+
169+
// Use the free number lookup functionality to get number formatting information
170+
OperatorInformationResult formattingResult = phoneNumberClient.searchOperatorInformation(phoneNumbers);
171+
OperatorInformation formattingInfo = formattingResult.getValues().get(0);
161172
```
162173

163174
Replace `<target-phone-number>` with the phone number you're looking up, usually a number you'd like to send a message to.
164175

165176
> [!WARNING]
166177
> Provide phone numbers in E.164 international standard format, for example, +14255550123.
167178
179+
### Look up operator information for a number
180+
181+
To search for a phone number's operator information, call `searchOperatorInformationWithResponse` from the `PhoneNumbersClient`, passing `true` for the `IncludeAdditionalOperatorDetails` option.
182+
183+
```java
184+
OperatorInformationOptions options = new OperatorInformationOptions();
185+
options.setIncludeAdditionalOperatorDetails(true);
186+
Response<OperatorInformationResult> result = phoneNumberClient.searchOperatorInformationWithResponse(phoneNumbers, options, Context.NONE);
187+
OperatorInformation operatorInfo = result.getValue().getValues().get(0);
188+
```
189+
190+
> [!WARNING]
191+
> Using this functionality will incur a charge to your account.
192+
168193
### Use operator information
169194

170-
You can now use the operator information. For this quickstart guide, we can print some of the details to the console.
195+
You can now use the operator information. For this quickstart guide, we can print some of the details to the console.
196+
197+
First, we can print details about the number format.
171198

172199
```java
173-
OperatorInformation operatorInfo = result.getValues().get(0);
200+
System.out.println(formattingInfo.getPhoneNumber() + " is formatted "
201+
+ formattingInfo.getInternationalFormat() + " internationally, and "
202+
+ formattingInfo.getNationalFormat() + " nationally");
203+
```
174204

205+
Next, we can print details about the phone number and operator.
206+
207+
```java
175208
String numberType = operatorInfo.getNumberType() == null ? "unknown" : operatorInfo.getNumberType().toString();
176209
String operatorName = "an unknown operator";
177210
if (operatorInfo.getOperatorDetails()!= null && operatorInfo.getOperatorDetails().getName() != null)
178211
{
179212
operatorName = operatorInfo.getOperatorDetails().getName();
180213
}
181-
System.out.println(operatorInfo.getPhoneNumber() + " is a " + numberType + " number, operated by " + operatorName);
214+
System.out.println(operatorInfo.getPhoneNumber() + " is a " + numberType + " number, operated in "
215+
+ operatorInfo.getIsoCountryCode() + " by " + operatorName);
182216
```
183217

184-
You may also use the operator information to determine whether to send an SMS. For more information on sending an SMS, see the [SMS Quickstart](../../sms/send.md).
218+
You may also use the operator information to determine whether to send an SMS. For more information on sending an SMS, see the [SMS Quickstart](../../sms/send.md).
185219

186220
## Run the code
187221

@@ -198,12 +232,12 @@ Then, build the package.
198232
mvn package
199233
```
200234

201-
Run the following `mvn` command to execute the app.
235+
To execute the app, use the `mvn` command.
202236

203237
```console
204-
mvn exec:java -Dexec.mainClass="com.communication.lookup.quickstart.App" -Dexec.cleanupDaemonThreads=false
238+
mvn exec:java -D"exec.mainClass"="com.communication.lookup.quickstart.App" -D"exec.cleanupDaemonThreads"="false"
205239
```
206240

207241
## Sample code
208242

209-
You can download the sample app from [GitHub](https://github.com/Azure/communication-preview/tree/master/samples/NumberLookup).
243+
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-java-quickstarts/tree/main/LookupNumber).

articles/communication-services/quickstarts/telephony/includes/number-lookup-js.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
Get started with the Phone Numbers client library for JavaScript to look up operator information for phone numbers, which can be used to determine whether and how to communicate with that phone number. Follow these steps to install the package and look up operator information about a phone number.
1+
Get started with the Phone Numbers client library for JavaScript to look up operator information for phone numbers, which can be used to determine whether and how to communicate with that phone number. Follow these steps to install the package and look up operator information about a phone number.
22

33
> [!NOTE]
4-
> Find the code for this quickstart on [GitHub](https://github.com/Azure/communication-preview/tree/master/samples/NumberLookup).
4+
> Find the code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/lookup-phone-number).
55
66
## Prerequisites
77

88
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
9-
- [Node.js](https://nodejs.org/) Active LTS and Maintenance LTS versions (8.11.1 and 10.14.1 recommended).
9+
- [Node.js](https://nodejs.org/) Active LTS _(long-term support)_ and Maintenance LTS versions (8.11.1 and 10.14.1 recommended).
1010
- An active Communication Services resource and connection string. [Create a Communication Services resource](../../create-communication-resource.md).
1111

1212
### Prerequisite check
@@ -35,7 +35,7 @@ Create a file called **number-lookup-quickstart.js** in the root of the director
3535

3636
```javascript
3737
async function main() {
38-
// quickstart code will here
38+
// quickstart code will go here
3939
}
4040

4141
main();
@@ -46,7 +46,7 @@ main();
4646
Use the `npm install` command to install the Azure Communication Services Phone Numbers client library for JavaScript.
4747

4848
```console
49-
npm install @azure/[email protected].1 --save
49+
npm install @azure/[email protected].4 --save
5050
```
5151

5252
The `--save` option adds the library as a dependency in your **package.json** file.
@@ -55,9 +55,9 @@ The `--save` option adds the library as a dependency in your **package.json** fi
5555

5656
### Authenticate the client
5757

58-
Import the **PhoneNumbersClient** from the client library and instantiate it with your connection string, which can be acquired from an Azure Communication Services resource in the [Azure portal](https://portal.azure.com). It's recommended to use a `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable to avoid putting your connection string in plain text within your code. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string).
58+
Import the **PhoneNumbersClient** from the client library and instantiate it with your connection string, which can be acquired from an Azure Communication Services resource in the [Azure portal](https://portal.azure.com). Using a `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable is recommended to avoid putting your connection string in plain text within your code. Learn how to [manage your resource's connection string](../../create-communication-resource.md#store-your-connection-string).
5959

60-
Add the following code to the top of **phone-numbers-quickstart.js**:
60+
Add the following code to the top of **number-lookup-quickstart.js**:
6161

6262
```javascript
6363
const { PhoneNumbersClient } = require('@azure/communication-phone-numbers');
@@ -69,29 +69,50 @@ const connectionString = process.env['COMMUNICATION_SERVICES_CONNECTION_STRING']
6969
const phoneNumbersClient = new PhoneNumbersClient(connectionString);
7070
```
7171

72-
### Look up operator information for a number
72+
### Look up phone number formatting
7373

7474
To search for a phone number's operator information, call `searchOperatorInformation` from the `PhoneNumbersClient`.
7575

7676
```javascript
77-
let results = await phoneNumbersClient.searchOperatorInformation([ "<target-phone-number>" ]);
77+
let formattingResults = await phoneNumbersClient.searchOperatorInformation([ "<target-phone-number>" ]);
7878
```
7979

8080
Replace `<target-phone-number>` with the phone number you're looking up, usually a number you'd like to send a message to.
8181

8282
> [!WARNING]
8383
> Provide phone numbers in E.164 international standard format, for example, +14255550123.
8484
85+
### Look up operator information for a number
86+
87+
To search for a phone number's operator information, call `searchOperatorInformation` from the `PhoneNumbersClient`, passing `true` for the `includeAdditionalOperatorDetails` option.
88+
89+
```javascript
90+
let searchResults = await phoneNumbersClient.searchOperatorInformation([ "<target-phone-number>" ], { "includeAdditionalOperatorDetails": true });
91+
```
92+
93+
> [!WARNING]
94+
> Using this functionality will incur a charge to your account.
95+
8596
### Use operator information
8697

87-
You can now use the operator information. For this quickstart guide, we can print some of the details to the console.
98+
You can now use the operator information. For this quickstart guide, we can print some of the details to the console.
99+
100+
First, we can print details about the number format.
101+
102+
```javascript
103+
let formatInfo = formattingResults.values[0];
104+
console.log(formatInfo.phoneNumber + " is formatted " + formatInfo.internationalFormat + " internationally, and " + formatInfo.nationalFormat + " nationally");
105+
```
106+
107+
Next, we can print details about the phone number and operator.
88108

89109
```javascript
90-
let operatorInfo = results.values[0];
91-
console.log(operatorInfo.phoneNumber + " is a " + (operatorInfo.numberType ? operatorInfo.numberType : "unknown") + " number, operated by " + (operatorInfo.operatorDetails.name ? operatorInfo.operatorDetails.name : "an unknown operator"));
110+
let operatorInfo = searchResults.values[0];
111+
console.log(operatorInfo.phoneNumber + " is a " + (operatorInfo.numberType ? operatorInfo.numberType : "unknown") + " number, operated in "
112+
+ operatorInfo.isoCountryCode + " by " + (operatorInfo.operatorDetails.name ? operatorInfo.operatorDetails.name : "an unknown operator"));
92113
```
93114

94-
You may also use the operator information to determine whether to send an SMS. For more information on sending an SMS, see the [SMS Quickstart](../../sms/send.md).
115+
You may also use the operator information to determine whether to send an SMS. For more information on sending an SMS, see the [SMS Quickstart](../../sms/send.md).
95116

96117
## Run the code
97118

@@ -103,4 +124,4 @@ node number-lookup-quickstart.js
103124

104125
## Sample code
105126

106-
You can download the sample app from [GitHub](https://github.com/Azure/communication-preview/tree/master/samples/NumberLookup).
127+
You can download the sample app from [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/lookup-phone-number)).

0 commit comments

Comments
 (0)