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] Add SDK for recipient verification (verified recipients) #25112

Merged
merged 25 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6d6730b
verififed recipients sdk
classBabacar-msft Mar 6, 2023
8284058
Readme and samples
classBabacar-msft Mar 6, 2023
5abc771
rush lock
classBabacar-msft Mar 6, 2023
127c597
Merge branch 'main' into bndoye/verified_recipients_sdk
classBabacar-msft Mar 7, 2023
95ab1d2
updated package.json dependency
classBabacar-msft Mar 7, 2023
1f2ca65
updating readme
classBabacar-msft Mar 7, 2023
73e18af
changelog added
classBabacar-msft Mar 7, 2023
ded2a50
Code coverage and documentation
classBabacar-msft Mar 7, 2023
fb1444f
changing environment variables and samples
classBabacar-msft Mar 7, 2023
ad18306
cleaning up readme
classBabacar-msft Mar 8, 2023
87f1c16
adding comments to client
classBabacar-msft Mar 8, 2023
29529c2
PR comments: outdated rush package
classBabacar-msft Mar 8, 2023
d281560
PR documentation changes
classBabacar-msft Mar 8, 2023
b1fb47b
Merge branch 'main' into bndoye/verified_recipients_sdk
classBabacar-msft Mar 9, 2023
5e8dad2
moved folder
classBabacar-msft Mar 9, 2023
e376b30
Test configuration
classBabacar-msft Mar 9, 2023
923b916
recordings
classBabacar-msft Mar 10, 2023
7762e77
api extractor and changelog
classBabacar-msft Mar 10, 2023
e3e0871
tests
classBabacar-msft Mar 10, 2023
4c29b55
Root package.json
classBabacar-msft Mar 10, 2023
40f1096
Code samples
classBabacar-msft Mar 10, 2023
117d8af
Autorest logic
classBabacar-msft Mar 10, 2023
ab3aca5
Merge branch 'bndoye/verified_recipients_sdk' of github.com:classBaba…
classBabacar-msft Mar 10, 2023
dfbca71
updating recordings and beta version
classBabacar-msft Mar 10, 2023
25872d5
Self PR: Just fixing some pieces of documentation
classBabacar-msft Mar 10, 2023
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
55 changes: 55 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@
"projectFolder": "sdk/communication/communication-short-codes",
"versionPolicyName": "client"
},
{
"packageName": "@azure-tools/communication-verified-recipients",
"projectFolder": "sdk/communication/communication-verified-recipients",
"versionPolicyName": "client"
},
{
"packageName": "@azure-tools/communication-alpha-ids",
"projectFolder": "sdk/communication/communication-alpha-ids",
Expand Down
2 changes: 2 additions & 0 deletions sdk/communication/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ extends:
safeName: azurecommunicationjobrouter
- name: azure-tools-communication-toll-free-verification
safeName: azuretoolscommunicationtollfreeverification
- name: azure-tools-communication-verified-recipients
safeName: azuretoolscommunicationverifiedrecipients
classBabacar-msft marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release History

## 1.0.0-beta.5 (Unreleased)
classBabacar-msft marked this conversation as resolved.
Show resolved Hide resolved

### Features Added

### Other Changes
192 changes: 192 additions & 0 deletions sdk/communication/communication-verified-recipients/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
Verification README

# Azure Communication Verified Recipients client library for JavaScript
classBabacar-msft marked this conversation as resolved.
Show resolved Hide resolved

The Verified Recipient library allows users to verify numbers for send messages or calling.
classBabacar-msft marked this conversation as resolved.
Show resolved Hide resolved

## Getting started

### Prerequisites

- An [Azure subscription][azure_sub].
- An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal], the [Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli].

### Installing

```bash
npm install @azure-tools/communication-verified-recipients
classBabacar-msft marked this conversation as resolved.
Show resolved Hide resolved
```

### Browser support

#### JavaScript Bundle

To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).

## Key concepts

## Examples

## Authentication

To create a client object to access the Communication Services API, you will need a `connection string` or the `endpoint` of your Communication Services resource and a `credential`. The Verified Recipient client can use either Azure Active Directory credentials or an API key credential to authenticate.

You can get a key and/or connection string from your Communication Services resource in the [Azure Portal][azure_portal]. You can also find the endpoint for your Communication Services resource in the [Azure Portal][azure_portal].

Once you have a key, you can authenticate the `VerifiedRecipientClient` with any of the following methods:

### Using a connection string

```javascript
const { VerifiedRecipientsClient } = require("@azure-tools/communication-verified-recipients");
classBabacar-msft marked this conversation as resolved.
Show resolved Hide resolved

const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
const client = new VerifiedRecipientsClient(connectionString);
```

### Using an access key with `AzureKeyCredential`

If you use a key to initialize the client you will also need to provide the appropriate endpoint. You can get this endpoint from your Communication Services resource in [Azure Portal][azure_portal]. Once you have a key and endpoint, you can authenticate with the following code:

```javascript
const { AzureKeyCredential } = require("@azure/core-auth");
const { VerifiedRecipientsClient } = require("@azure-tools/communication-verified-recipients");

const credential = new AzureKeyCredential("<key-from-resource>");
const client = new VerifiedRecipientsClient("<endpoint-from-resource>", credential);
```

### Using an Azure Active Directory Credential

Connection string authentication is used in most of the examples, but you can also authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the [`@azure/identity`][azure_identity] package:

```bash
npm install @azure/identity
```

The [`@azure/identity`][azure_identity] package provides a variety of credential types that your application can use to do this. The [README for `@azure/identity`][azure_identity_readme] provides more details and samples to get you started.

```javascript
const { DefaultAzureCredential } = require("@azure/identity");
const { VerifiedRecipientsClient } = require("@azure-tools/communication-verified-recipients");

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

## Usage

The following sections provide code snippets that cover some of the common tasks using the Azure Communication Services Verified Recipient Client. The scenarios that are covered here consist of:

- [Request phone number verification code](#request-phone-number-verification-code)
- [Verify phone number](#verify-phone-number)
- [Remove a verified number](#remove-verified-number)
- [Get verified numbers](#get-verified-numbers)

### Request phone number verification code

```typescript
import { VerifiedRecipientsClient } from "@azure-tools/communication-verified-recipients";
const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
const client = new VerifiedRecipientsClient(connectionString);

async main function() {
// body of the request
const VerificationRequest = {
identity: "+11234567890",
channel: "sms",
};

// get the verification status
var status = await client.requestVerification(VerificationRequest);
console.log(status);
}

main();
```

### Verify phone number

```typescript
import { VerifiedRecipientsClient } from "@azure-tools/communication-verified-recipients";
const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
const client = new VerifiedRecipientsClient(connectionString);

async main function() {
// id that is used to reference users phone number
const verificationId = "7e5dd7e1-5203-41ab-960e-65c1eb804fc6";

// body of the request
const VerificationRequest = {
verificationCode: "1234567",
};

// verifying your phone number
const status = await client.verifyIdentity(verificationId, VerificationRequest);
console.log(status);
}

main();
```

### Remove verified number

```typescript
import { VerifiedRecipientsClient } from "@azure-tools/communication-verified-recipients";
const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
const client = new VerifiedRecipientsClient(connectionString);

async main function() {
// id that is used to reference users phone number
const verificationId = "4d313ff0-3aeb-477e-8c15-7c9a893e8999";

// delete verification for a resource
await client.deleteVerification(verificationId);
}

main();
```

### Get verified numbers

```typescript
import { VerifiedRecipientsClient } from "@azure-tools/communication-verified-recipients";
const connectionString = "endpoint=<endpoint>;accessKey=<accessKey>";
const client = new VerifiedRecipientsClient(connectionString);

async main function() {
// get all verifications for a resource
var verifications = await client.getVerifications();

// print all verifications
for await (const verification of verifications) {
console.log(verification);
}
}

main();
```

## Troubleshooting

## Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

## Contributing

If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.

## Related projects

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)

[azure_cli]: https://docs.microsoft.com/cli/azure
[azure_sub]: https://azure.microsoft.com/free/
[azure_portal]: https://portal.azure.com
[azure_powershell]: https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity
[azure_identity_readme]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-toll-free-verification%2FREADME.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "types/src/index.d.ts",
"docModel": {
"enabled": true
},
"apiReport": {
"enabled": true,
"reportFolder": "./review"
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./types/communication-verified-recipients.d.ts"
},
"messages": {
"tsdocMessageReporting": {
"default": {
"logLevel": "none"
}
},
"extractorMessageReporting": {
"ae-forgotten-export": {
"logLevel": "error",
"addToApiReportFile": false
},
"ae-missing-release-tag": {
"logLevel": "none"
},
"ae-unresolved-link": {
"logLevel": "error"
}
}
}
}
Loading