@azure-rest/communication-messages 2.0.1-alpha.20250122.2 → 2.0.1-alpha.20250127.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +47 -34
  2. package/package.json +14 -14
package/README.md CHANGED
@@ -32,22 +32,22 @@ You can get a key and/or connection string from your Communication Services reso
32
32
 
33
33
  ### Using a connection string
34
34
 
35
- ```typescript
36
- import MessageClient, { MessagesServiceClient } from "@azure-rest/communication-messages";
35
+ ```ts snippet:ReadmeSampleCreateClient_ConnectionString
36
+ import MessageClient from "@azure-rest/communication-messages";
37
37
 
38
38
  const connectionString = `endpoint=https://<resource-name>.communication.azure.com/;accessKey=<Base64-Encoded-Key>`;
39
- const client: MessagesServiceClient = MessageClient(connectionString);
39
+ const client = MessageClient(connectionString);
40
40
  ```
41
41
 
42
42
  ### Using `AzureKeyCredential`
43
43
 
44
- ```typescript
44
+ ```ts snippet:ReadmeSampleCreateClient_KeyCredential
45
45
  import { AzureKeyCredential } from "@azure/core-auth";
46
- import MessageClient, { MessagesServiceClient } from "@azure-rest/communication-messages";
46
+ import MessageClient from "@azure-rest/communication-messages";
47
47
 
48
48
  const endpoint = "https://<resource-name>.communication.azure.com";
49
49
  const credential = new AzureKeyCredential("<Base64-Encoded-Key>");
50
- const client: MessagesServiceClient = MessageClient(endpoint, credential);
50
+ const client = MessageClient(endpoint, credential);
51
51
  ```
52
52
 
53
53
  ### Using Azure Active Directory managed identity
@@ -61,13 +61,13 @@ npm install @azure/identity
61
61
  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.
62
62
  AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables are needed to create a DefaultAzureCredential object.
63
63
 
64
- ```typescript
64
+ ```ts snippet:ReadmeSampleCreateClient_DefaultAzureCredential
65
65
  import { DefaultAzureCredential } from "@azure/identity";
66
- import MessageClient, { MessagesServiceClient } from "@azure-rest/communication-messages";
66
+ import MessageClient from "@azure-rest/communication-messages";
67
67
 
68
68
  const endpoint = "https://<resource-name>.communication.azure.com";
69
69
  const credential = new DefaultAzureCredential();
70
- const client: MessagesServiceClient = MessageClient(endpoint, credential);
70
+ const client = MessageClient(endpoint, credential);
71
71
  ```
72
72
 
73
73
  ## Send a Template Message with WhatsApp Channel
@@ -86,26 +86,33 @@ To send an Template Message, you need add template to your WhatsApp Bussiness Ac
86
86
 
87
87
  ```
88
88
 
89
- ```typescript
90
- const nameValue: MessageTemplateValue = {
89
+ ```ts snippet:ReadmeSampleSendTemplateMessage
90
+ import { DefaultAzureCredential } from "@azure/identity";
91
+ import MessageClient, { isUnexpected } from "@azure-rest/communication-messages";
92
+
93
+ const endpoint = "https://<resource-name>.communication.azure.com";
94
+ const credential = new DefaultAzureCredential();
95
+ const client = MessageClient(endpoint, credential);
96
+
97
+ const nameValue = {
91
98
  kind: "text",
92
99
  name: "name",
93
100
  text: "Arif",
94
101
  };
95
102
 
96
- const yesAction: MessageTemplateValue = {
103
+ const yesAction = {
97
104
  kind: "quickAction",
98
105
  name: "Yes",
99
106
  payload: "Yes",
100
107
  };
101
108
 
102
- const noAction: MessageTemplateValue = {
109
+ const noAction = {
103
110
  kind: "quickAction",
104
111
  name: "No",
105
112
  payload: "No",
106
113
  };
107
114
 
108
- const templateBindings: MessageTemplateBindings = {
115
+ const templateBindings = {
109
116
  kind: "whatsApp",
110
117
  body: [
111
118
  {
@@ -124,7 +131,7 @@ const templateBindings: MessageTemplateBindings = {
124
131
  ],
125
132
  };
126
133
 
127
- const template: MessageTemplate = {
134
+ const template = {
128
135
  name: "sample_issue_resolution",
129
136
  language: "en_US",
130
137
  bindings: templateBindings,
@@ -140,13 +147,11 @@ const result = await client.path("/messages/notifications:send").post({
140
147
  template: template,
141
148
  },
142
149
  });
143
- if (result.status === "202") {
144
- const response: Send202Response = result as Send202Response;
145
- response.body.receipts.forEach((receipt) => {
150
+
151
+ if (!isUnexpected(result)) {
152
+ result.body.receipts.forEach((receipt) => {
146
153
  console.log("Message sent to:" + receipt.to + " with message id:" + receipt.messageId);
147
154
  });
148
- } else {
149
- throw new Error("Failed to send message");
150
155
  }
151
156
  ```
152
157
 
@@ -154,7 +159,14 @@ if (result.status === "202") {
154
159
 
155
160
  `Note: Business can't start a conversation with a text message. It needs to be user initiated.`
156
161
 
157
- ```typescript
162
+ ```ts snippet:ReadmeSampleSendTextMessage
163
+ import { DefaultAzureCredential } from "@azure/identity";
164
+ import MessageClient, { isUnexpected } from "@azure-rest/communication-messages";
165
+
166
+ const endpoint = "https://<resource-name>.communication.azure.com";
167
+ const credential = new DefaultAzureCredential();
168
+ const client = MessageClient(endpoint, credential);
169
+
158
170
  const result = await client.path("/messages/notifications:send").post({
159
171
  contentType: "application/json",
160
172
  body: {
@@ -165,13 +177,10 @@ const result = await client.path("/messages/notifications:send").post({
165
177
  },
166
178
  });
167
179
 
168
- if (result.status === "202") {
169
- const response: Send202Response = result as Send202Response;
170
- response.body.receipts.forEach((receipt) => {
180
+ if (!isUnexpected(result)) {
181
+ result.body.receipts.forEach((receipt) => {
171
182
  console.log("Message sent to:" + receipt.to + " with message id:" + receipt.messageId);
172
183
  });
173
- } else {
174
- throw new Error("Failed to send message");
175
184
  }
176
185
  ```
177
186
 
@@ -179,7 +188,14 @@ if (result.status === "202") {
179
188
 
180
189
  `Note: Business can't start a conversation with a media message. It needs to be user initiated.`
181
190
 
182
- ```typescript
191
+ ```ts snippet:ReadmeSampleSendMediaMessage
192
+ import { DefaultAzureCredential } from "@azure/identity";
193
+ import MessageClient, { isUnexpected } from "@azure-rest/communication-messages";
194
+
195
+ const endpoint = "https://<resource-name>.communication.azure.com";
196
+ const credential = new DefaultAzureCredential();
197
+ const client = MessageClient(endpoint, credential);
198
+
183
199
  const result = await client.path("/messages/notifications:send").post({
184
200
  contentType: "application/json",
185
201
  body: {
@@ -190,13 +206,10 @@ const result = await client.path("/messages/notifications:send").post({
190
206
  },
191
207
  });
192
208
 
193
- if (result.status === "202") {
194
- const response: Send202Response = result as Send202Response;
195
- response.body.receipts.forEach((receipt) => {
209
+ if (!isUnexpected(result)) {
210
+ result.body.receipts.forEach((receipt) => {
196
211
  console.log("Message sent to:" + receipt.to + " with message id:" + receipt.messageId);
197
212
  });
198
- } else {
199
- throw new Error("Failed to send message");
200
213
  }
201
214
  ```
202
215
 
@@ -206,8 +219,8 @@ if (result.status === "202") {
206
219
 
207
220
  Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
208
221
 
209
- ```javascript
210
- const { setLogLevel } = require("@azure/logger");
222
+ ```ts snippet:SetLogLevel
223
+ import { setLogLevel } from "@azure/logger";
211
224
 
212
225
  setLogLevel("info");
213
226
  ```
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@azure-rest/communication-messages",
3
3
  "sdk-type": "client",
4
4
  "author": "Microsoft Corporation",
5
- "version": "2.0.1-alpha.20250122.2",
5
+ "version": "2.0.1-alpha.20250127.1",
6
6
  "description": "Azure client library for Azure Communication Messages services",
7
7
  "keywords": [
8
8
  "node",
@@ -38,7 +38,7 @@
38
38
  "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"",
39
39
  "clean": "dev-tool run vendored rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log",
40
40
  "execute:samples": "echo skipped",
41
- "extract-api": "dev-tool run vendored rimraf review && dev-tool run vendored mkdirp ./review && dev-tool run extract-api",
41
+ "extract-api": "dev-tool run vendored rimraf review && dev-tool run extract-api",
42
42
  "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"",
43
43
  "generate:client": "echo skipped",
44
44
  "integration-test": "npm run integration-test:node && npm run integration-test:browser",
@@ -53,19 +53,19 @@
53
53
  "unit-test": "npm run unit-test:node && npm run unit-test:browser",
54
54
  "unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser",
55
55
  "unit-test:node": "dev-tool run test:vitest",
56
- "update-snippets": "echo skipped"
56
+ "update-snippets": "dev-tool run update-snippets"
57
57
  },
58
58
  "sideEffects": false,
59
59
  "autoPublish": false,
60
60
  "dependencies": {
61
- "@azure-rest/core-client": "^2.3.1",
61
+ "@azure-rest/core-client": "^2.3.2",
62
62
  "@azure/communication-common": "^2.3.1",
63
- "@azure/core-auth": "^1.6.0",
64
- "@azure/core-paging": "^1.5.0",
65
- "@azure/core-rest-pipeline": "^1.12.0",
66
- "@azure/core-util": "^1.7.0",
67
- "@azure/logger": "^1.0.0",
68
- "tslib": "^2.2.0"
63
+ "@azure/core-auth": "^1.9.0",
64
+ "@azure/core-paging": "^1.6.2",
65
+ "@azure/core-rest-pipeline": "^1.18.2",
66
+ "@azure/core-util": "^1.11.0",
67
+ "@azure/logger": "^1.1.4",
68
+ "tslib": "^2.8.1"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@azure-tools/test-credential": "^2.0.0",
@@ -73,17 +73,17 @@
73
73
  "@azure-tools/test-utils-vitest": ">=1.0.0-alpha <1.0.0-alphb",
74
74
  "@azure/dev-tool": ">=1.0.0-alpha <1.0.0-alphb",
75
75
  "@azure/eslint-plugin-azure-sdk": ">=3.0.0-alpha <3.0.0-alphb",
76
- "@azure/identity": "^4.2.1",
76
+ "@azure/identity": "^4.5.0",
77
77
  "@types/node": "^18.0.0",
78
- "@vitest/browser": "^2.1.5",
79
- "@vitest/coverage-istanbul": "^2.1.5",
78
+ "@vitest/browser": "^3.0.3",
79
+ "@vitest/coverage-istanbul": "^3.0.3",
80
80
  "autorest": "latest",
81
81
  "dotenv": "^16.0.0",
82
82
  "eslint": "^9.9.0",
83
83
  "karma-source-map-support": "~1.4.0",
84
84
  "playwright": "^1.48.2",
85
85
  "typescript": "~5.7.2",
86
- "vitest": "^2.1.5"
86
+ "vitest": "^3.0.3"
87
87
  },
88
88
  "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest-rest/README.md",
89
89
  "//metadata": {