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 cc71b24321901ed5ad5b0ba135b8d36644893ace into 552b4dd311f90f4a7b2f7adf45461d7a8774a1cc
  • Loading branch information
SDKAuto committed Dec 9, 2024
1 parent 03bdd2e commit 39df56f
Show file tree
Hide file tree
Showing 90 changed files with 1,996 additions and 3,938 deletions.
3 changes: 2 additions & 1 deletion 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-12-09)
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: 16 additions & 202 deletions sdk/communication/communication-messages-rest/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# 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]
- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest)
- [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 +28,17 @@ 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";

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

## Send a Template Message with WhatsApp Channel
### Create and authenticate a `MessagesServiceClient`

`Note: Business always starts the conversation with a template message.`
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.

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");
}
```
To authenticate with AAD, you must first `npm` install [`@azure/identity`](https://www.npmjs.com/package/@azure/identity)

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.

## Troubleshooting

Expand All @@ -214,28 +53,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 @@
}
}
}
}
}
6 changes: 0 additions & 6 deletions sdk/communication/communication-messages-rest/assets.json

This file was deleted.

14 changes: 9 additions & 5 deletions sdk/communication/communication-messages-rest/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import azsdkEslint from "@azure/eslint-plugin-azure-sdk";

export default azsdkEslint.config([
export default [
...azsdkEslint.configs.recommended,
{
rules: {
"@azure/azure-sdk/ts-modules-only-named": "warn",
"@azure/azure-sdk/ts-apiextractor-json-types": "warn",
"@azure/azure-sdk/ts-package-json-types": "warn",
"@azure/azure-sdk/ts-package-json-engine-is-present": "warn",
"tsdoc/syntax": "warn",
},
},
]);
"@azure/azure-sdk/ts-package-json-module": "off",
"@azure/azure-sdk/ts-package-json-files-required": "off",
"@azure/azure-sdk/ts-package-json-main-is-cjs": "off",
"tsdoc/syntax": "warn"
}
}
];
Loading

0 comments on commit 39df56f

Please sign in to comment.