Skip to content

Commit

Permalink
CodeGen from PR 31549 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
Merge 50539e19ceda97ccea7684e2e4479dadd112b8da into d477c7caa09bf82e22c419be0a99d170552b5892
  • Loading branch information
SDKAuto committed Nov 20, 2024
1 parent d8b5771 commit ec941af
Show file tree
Hide file tree
Showing 90 changed files with 2,005 additions and 3,939 deletions.
9 changes: 5 additions & 4 deletions common/config/rush/pnpm-lock.yaml

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

52 changes: 9 additions & 43 deletions sdk/communication/communication-messages-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,15 @@
# Release History

## 2.0.1 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes

## 2.0.0 (2024-10-23)


## 3.0.0-beta.1 (2024-11-20)
Compared with version 2.0.0

### Features Added

- Added ImageNotificationContent to send image messgae.
- Added DocumentNotificationContent to send document message.
- Added VideoNotificationContent to send video message.
- Added AudioNotificationContent to send audio message.
- Deprecated MediaNotificationContent.
- Added Interface PagedAsyncIterableIterator
- Added Interface PageSettings

### Breaking Changes

- MediaNotificationContent interface kind field is update with value "image_v0" from "image".

## 1.0.1 (2024-03-07)

Using MessagesServiceClient:

- Send WhatsApp messages.
- Get Template List.
- Download media file from WhatsApp server for incoming media message.

### Other Changes

- Fixed CI pipeline to publish MS doc.

## 1.0.0 (2024-02-29)

### Features Added

This is the initial release of the @azure-rest version of Azure Communication Messages Services.

Using MessagesServiceClient:

- Send WhatsApp messages.
- Get Template List.
- Download media file from WhatsApp server for incoming media message.
- Removed function overload "function createClient(connectionString: string, options?: ClientOptions): MessagesServiceClient;"
- Removed Type Alias PagedMessageTemplateItemOutput

21 changes: 21 additions & 0 deletions sdk/communication/communication-messages-rest/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
218 changes: 17 additions & 201 deletions sdk/communication/communication-messages-rest/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Azure CommunicationMessages REST client library for JavaScript

This package contains a JavaScript SDK for Azure Communication Messages Services.
Azure Communication Messages Service

**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**

Key links:

- [Quick Start][azure_communication_messaging_qs]
- [Package (NPM)](https://www.npmjs.com/package/@azure-rest/communication-messages)
- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure-rest/communication-messages?view=azure-node-preview)

## Getting started

### Currently supported environments

- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
- LTS versions of Node.js

### Prerequisites

- You must have an [Azure subscription][azure_sub] to use this package.
- 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].
- See [how to register whatsapp business account & create a channel][register_whatsapp_business_account] for registering whatsapp channel to your Communication Services resource.
- You must have an [Azure subscription](https://azure.microsoft.com/free/) to use this package.

### Install the `@azure-rest/communication-messages` package

Expand All @@ -26,180 +27,20 @@ Install the Azure CommunicationMessages REST client REST client library for Java
npm install @azure-rest/communication-messages
```

## Authentication

You can get a key and/or connection string from your Communication Services resource in [Azure Portal][azure_portal]. Once you have a key, you may authenticate with any of the following methods:

### Using a connection string

```typescript
import MessageClient, { MessagesServiceClient } from "@azure-rest/communication-messages";

const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
const client:MessagesServiceClient = MessageClient(connectionString);
```

### Using `AzureKeyCredential`

```typescript
import { AzureKeyCredential } from "@azure/core-auth";
import MessageClient, { MessagesServiceClient } from "@azure-rest/communication-messages";

const endpoint = "https://<resource-name>.communication.azure.com";
const credential = new AzureKeyCredential("<Base64-Encoded-Key>");
const client:MessagesServiceClient = MessageClient(endpoint, credential);
```

### Using Azure Active Directory managed identity

Client API key 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 provides more details and samples to get you started.
AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables are needed to create a DefaultAzureCredential object.

```typescript
import { DefaultAzureCredential } from "@azure/identity";
import MessageClient, { MessagesServiceClient } from "@azure-rest/communication-messages";
### Create and authenticate a `MessagesServiceClient`

const endpoint = "https://<resource-name>.communication.azure.com";
const credential = new DefaultAzureCredential();
const client:MessagesServiceClient = MessageClient(endpoint, credential);
```
To use an [Azure Active Directory (AAD) token credential](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token),
provide an instance of the desired credential type obtained from the
[@azure/identity](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) library.

## Send a Template Message with WhatsApp Channel
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)

`Note: Business always starts the conversation with a template message.`

To send an Template Message, you need add template to your WhatsApp Bussiness Account. For more detail on WhatsApp Template, refer [Create and Manage Templates][create-manage-whatsapp-template]. In below example, we are using

```
Template Name: sample_issue_resolution
Template Language: en_US
Template Body: "Hi {{1}}, were we able to solve the issue that you were facing?"
With Quick Action Button (Yes, No)
```

```typescript
const nameValue:MessageTemplateValue = {
kind: "text",
name: "name",
text: "Arif"
};

const yesAction: MessageTemplateValue = {
kind: "quickAction",
name: "Yes",
payload: "Yes"
};

const noAction: MessageTemplateValue = {
kind: "quickAction",
name: "No",
payload: "No"
};

const templateBindings:MessageTemplateBindings = {
kind: "whatsApp",
body: [
{
refValue: "name"
}
],
buttons: [
{
subType: "quickReply",
refValue: "Yes"
},
{
subType: "quickReply",
refValue: "No"
}
]
};

const template:MessageTemplate = {
name: "sample_issue_resolution",
language: "en_US",
bindings: templateBindings,
values: [nameValue, yesAction, noAction]
};

const result = await client.path("/messages/notifications:send").post({
contentType: "application/json",
body: {
channelRegistrationId: "<Channel_Registration_Id>",
to: ["<to-phone-number-1>"],
kind: "template",
template: template
}
});
if (result.status === "202") {
const response:Send202Response = result as Send202Response;
response.body.receipts.forEach((receipt) => {
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
});
} else {
throw new Error("Failed to send message");
}
```

## Send a Text Message with WhatsApp Channel

`Note: Business can't start a conversation with a text message. It needs to be user initiated.`

```typescript
const result = await client.path("/messages/notifications:send").post({
contentType: "application/json",
body: {
channelRegistrationId: "<Channel_Registration_Id>",
to: ["<to-phone-number-1>"],
kind: "text",
content: "Hello World!!"
}
});

if (result.status === "202") {
const response:Send202Response = result as Send202Response;
response.body.receipts.forEach((receipt) => {
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
});
} else {
throw new Error("Failed to send message");
}
```

## Send a Media Message with WhatsApp Channel

`Note: Business can't start a conversation with a media message. It needs to be user initiated.`

```typescript
const result = await client.path("/messages/notifications:send").post({
contentType: "application/json",
body: {
channelRegistrationId: "<Channel_Registration_Id>",
to: ["<to-phone-number-1>"],
kind: "image",
mediaUri: "https://<your-media-image-file>"
}
});

if (result.status === "202") {
const response:Send202Response = result as Send202Response;
response.body.receipts.forEach((receipt) => {
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
});
} else {
throw new Error("Failed to send message");
}
```
After setup, you can choose which type of [credential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#credentials) from `@azure/identity` to use.
As an example, [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential)
can be used to authenticate the client.

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET

## Troubleshooting

Expand All @@ -214,28 +55,3 @@ setLogLevel("info");
```

For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).

## Next steps

Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/communication-messages-rest/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_communication_messaging_qs]: https://learn.microsoft.com/azure/communication-services/concepts/advanced-messaging/whatsapp/whatsapp-overview
[register_whatsapp_business_account]: https://learn.microsoft.com/azure/communication-services/quickstarts/advanced-messaging/whatsapp/connect-whatsapp-business-account
[create-manage-whatsapp-template]: https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-sms%2FREADME.png)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "dist/esm/index.d.ts",
"mainEntryPointFilePath": "./dist/esm/index.d.ts",
"docModel": {
"enabled": true
},
Expand All @@ -11,7 +11,7 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "dist/communication-messages.d.ts"
"publicTrimmedFilePath": "./types/communication-messages.d.ts"
},
"messages": {
"tsdocMessageReporting": {
Expand All @@ -28,4 +28,4 @@
}
}
}
}
}
Loading

0 comments on commit ec941af

Please sign in to comment.