@azure/communication-chat 1.5.0 → 1.6.0-beta.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.
@@ -0,0 +1,186 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { AbortError } from "@azure/abort-controller";
4
+ import { RestError, createHttpHeaders, } from "@azure/core-rest-pipeline";
5
+ // Temporary workaround with local copy of XhrHttpClient
6
+ function isNodeReadableStream(body) {
7
+ return body && typeof body.pipe === "function";
8
+ }
9
+ /**
10
+ * Checks if the body is a Blob or Blob-like
11
+ * @internal
12
+ */
13
+ export function isBlob(body) {
14
+ // File objects count as a type of Blob, so we want to use instanceof explicitly
15
+ return (typeof Blob === "function" || typeof Blob === "object") && body instanceof Blob;
16
+ }
17
+ /**
18
+ * Checks if the body is a ReadableStream supported by browsers
19
+ * @internal
20
+ */
21
+ export function isReadableStream(body) {
22
+ return Boolean(body &&
23
+ typeof body.getReader === "function" &&
24
+ typeof body.tee === "function");
25
+ }
26
+ /**
27
+ * A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.
28
+ * @internal
29
+ */
30
+ class XhrHttpClient {
31
+ /**
32
+ * Makes a request over an underlying transport layer and returns the response.
33
+ * @param request - The request to be made.
34
+ */
35
+ async sendRequest(request) {
36
+ var _a;
37
+ const url = new URL(request.url);
38
+ const isInsecure = url.protocol !== "https:";
39
+ if (isInsecure && !request.allowInsecureConnection) {
40
+ throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
41
+ }
42
+ const xhr = new XMLHttpRequest();
43
+ if (request.proxySettings) {
44
+ throw new Error("HTTP proxy is not supported in browser environment");
45
+ }
46
+ const abortSignal = request.abortSignal;
47
+ if (abortSignal) {
48
+ if (abortSignal.aborted) {
49
+ throw new AbortError("The operation was aborted.");
50
+ }
51
+ const listener = () => {
52
+ xhr.abort();
53
+ };
54
+ abortSignal.addEventListener("abort", listener);
55
+ xhr.addEventListener("readystatechange", () => {
56
+ if (xhr.readyState === XMLHttpRequest.DONE) {
57
+ abortSignal.removeEventListener("abort", listener);
58
+ }
59
+ });
60
+ }
61
+ addProgressListener(xhr.upload, request.onUploadProgress);
62
+ addProgressListener(xhr, request.onDownloadProgress);
63
+ xhr.open(request.method, request.url);
64
+ xhr.timeout = request.timeout;
65
+ xhr.withCredentials = request.withCredentials;
66
+ for (const [name, value] of request.headers) {
67
+ xhr.setRequestHeader(name, value);
68
+ }
69
+ xhr.responseType = ((_a = request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.size) ? "blob" : "text";
70
+ const body = typeof request.body === "function" ? request.body() : request.body;
71
+ if (isNodeReadableStream(body) || isReadableStream(body)) {
72
+ throw new Error("Streams are not supported by xhrHttpClient.");
73
+ }
74
+ xhr.send(body === undefined ? null : body);
75
+ if (xhr.responseType === "blob") {
76
+ return new Promise((resolve, reject) => {
77
+ handleBlobResponse(xhr, request, resolve, reject);
78
+ rejectOnTerminalEvent(request, xhr, reject);
79
+ });
80
+ }
81
+ else {
82
+ return new Promise(function (resolve, reject) {
83
+ xhr.addEventListener("load", () => resolve({
84
+ request,
85
+ status: xhr.status,
86
+ headers: parseHeaders(xhr),
87
+ bodyAsText: xhr.responseText,
88
+ }));
89
+ rejectOnTerminalEvent(request, xhr, reject);
90
+ });
91
+ }
92
+ }
93
+ }
94
+ function handleBlobResponse(xhr, request, res, rej) {
95
+ xhr.addEventListener("readystatechange", () => {
96
+ var _a, _b;
97
+ // Resolve as soon as headers are loaded
98
+ if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
99
+ if (
100
+ // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
101
+ ((_a = request.streamResponseStatusCodes) === null || _a === void 0 ? void 0 : _a.has(Number.POSITIVE_INFINITY)) ||
102
+ ((_b = request.streamResponseStatusCodes) === null || _b === void 0 ? void 0 : _b.has(xhr.status))) {
103
+ const blobBody = new Promise((resolve, reject) => {
104
+ xhr.addEventListener("load", () => {
105
+ resolve(xhr.response);
106
+ });
107
+ rejectOnTerminalEvent(request, xhr, reject);
108
+ });
109
+ res({
110
+ request,
111
+ status: xhr.status,
112
+ headers: parseHeaders(xhr),
113
+ blobBody,
114
+ });
115
+ }
116
+ else {
117
+ xhr.addEventListener("load", () => {
118
+ // xhr.response is of Blob type if the request is sent with xhr.responseType === "blob"
119
+ // but the status code is not one of the stream response status codes,
120
+ // so treat it as text and convert from Blob to text
121
+ if (xhr.response) {
122
+ xhr.response
123
+ .text()
124
+ .then((text) => {
125
+ res({
126
+ request: request,
127
+ status: xhr.status,
128
+ headers: parseHeaders(xhr),
129
+ bodyAsText: text,
130
+ });
131
+ return;
132
+ })
133
+ .catch((e) => {
134
+ rej(e);
135
+ });
136
+ }
137
+ else {
138
+ res({
139
+ request,
140
+ status: xhr.status,
141
+ headers: parseHeaders(xhr),
142
+ });
143
+ }
144
+ });
145
+ }
146
+ }
147
+ });
148
+ }
149
+ function addProgressListener(xhr, listener) {
150
+ if (listener) {
151
+ xhr.addEventListener("progress", (rawEvent) => listener({
152
+ loadedBytes: rawEvent.loaded,
153
+ }));
154
+ }
155
+ }
156
+ function parseHeaders(xhr) {
157
+ const responseHeaders = createHttpHeaders();
158
+ const headerLines = xhr
159
+ .getAllResponseHeaders()
160
+ .trim()
161
+ .split(/[\r\n]+/);
162
+ for (const line of headerLines) {
163
+ const index = line.indexOf(":");
164
+ const headerName = line.slice(0, index);
165
+ const headerValue = line.slice(index + 2);
166
+ responseHeaders.set(headerName, headerValue);
167
+ }
168
+ return responseHeaders;
169
+ }
170
+ function rejectOnTerminalEvent(request, xhr, reject) {
171
+ xhr.addEventListener("error", () => reject(new RestError(`Failed to send request to ${request.url}`, {
172
+ code: RestError.REQUEST_SEND_ERROR,
173
+ request,
174
+ })));
175
+ const abortError = new AbortError("The operation was aborted.");
176
+ xhr.addEventListener("abort", () => reject(abortError));
177
+ xhr.addEventListener("timeout", () => reject(abortError));
178
+ }
179
+ /**
180
+ * Create a new HttpClient instance for the browser environment.
181
+ * @internal
182
+ */
183
+ export function createXhrHttpClient() {
184
+ return new XhrHttpClient();
185
+ }
186
+ //# sourceMappingURL=xhrHttpClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhrHttpClient.js","sourceRoot":"","sources":["../../src/xhrHttpClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAML,SAAS,EACT,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AAEnC,wDAAwD;AACxD,SAAS,oBAAoB,CAAC,IAAS;IACrC,OAAO,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,IAAa;IAClC,gFAAgF;IAChF,OAAO,CAAC,OAAO,IAAI,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,YAAY,IAAI,CAAC;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,OAAO,OAAO,CACZ,IAAI;QACF,OAAQ,IAAuB,CAAC,SAAS,KAAK,UAAU;QACxD,OAAQ,IAAuB,CAAC,GAAG,KAAK,UAAU,CACrD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,aAAa;IACjB;;;OAGG;IACI,KAAK,CAAC,WAAW,CAAC,OAAwB;;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAE7C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,CAAC,GAAG,0CAA0C,CAAC,CAAC;QAC9F,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O,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,qBAAqB,CAC5B,OAAwB,EACxB,GAAmB,EACnB,MAA0B;IAE1B,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CACjC,MAAM,CACJ,IAAI,SAAS,CAAC,6BAA6B,OAAO,CAAC,GAAG,EAAE,EAAE;QACxD,IAAI,EAAE,SAAS,CAAC,kBAAkB;QAClC,OAAO;KACR,CAAC,CACH,CACF,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAC;IAChE,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACxD,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError } from \"@azure/abort-controller\";\nimport {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n TransferProgressEvent,\n HttpHeaders,\n RestError,\n createHttpHeaders,\n} from \"@azure/core-rest-pipeline\";\n\n// Temporary workaround with local copy of XhrHttpClient\nfunction isNodeReadableStream(body: any): body is NodeJS.ReadableStream {\n return body && typeof body.pipe === \"function\";\n}\n\n/**\n * Checks if the body is a Blob or Blob-like\n * @internal\n */\nexport function isBlob(body: unknown): body is Blob {\n // File objects count as a type of Blob, so we want to use instanceof explicitly\n return (typeof Blob === \"function\" || typeof Blob === \"object\") && body instanceof Blob;\n}\n\n/**\n * Checks if the body is a ReadableStream supported by browsers\n * @internal\n */\nexport function isReadableStream(body: unknown): body is ReadableStream {\n return Boolean(\n body &&\n typeof (body as ReadableStream).getReader === \"function\" &&\n typeof (body as ReadableStream).tee === \"function\",\n );\n}\n\n/**\n * A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.\n * @internal\n */\nclass XhrHttpClient implements HttpClient {\n /**\n * Makes a request over an underlying transport layer and returns the response.\n * @param request - The request to be made.\n */\n public async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n const url = new URL(request.url);\n const isInsecure = url.protocol !== \"https:\";\n\n if (isInsecure && !request.allowInsecureConnection) {\n throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);\n }\n\n const xhr = new XMLHttpRequest();\n\n if (request.proxySettings) {\n throw new Error(\"HTTP proxy is not supported in browser environment\");\n }\n\n const abortSignal = request.abortSignal;\n if (abortSignal) {\n if (abortSignal.aborted) {\n throw new AbortError(\"The operation was aborted.\");\n }\n\n const listener = (): void => {\n xhr.abort();\n };\n abortSignal.addEventListener(\"abort\", listener);\n xhr.addEventListener(\"readystatechange\", () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n abortSignal.removeEventListener(\"abort\", listener);\n }\n });\n }\n\n addProgressListener(xhr.upload, request.onUploadProgress);\n addProgressListener(xhr, request.onDownloadProgress);\n\n xhr.open(request.method, request.url);\n xhr.timeout = request.timeout;\n xhr.withCredentials = request.withCredentials;\n for (const [name, value] of request.headers) {\n xhr.setRequestHeader(name, value);\n }\n\n xhr.responseType = request.streamResponseStatusCodes?.size ? \"blob\" : \"text\";\n\n const body = typeof request.body === \"function\" ? request.body() : request.body;\n if (isNodeReadableStream(body) || isReadableStream(body)) {\n throw new Error(\"Streams are not supported by xhrHttpClient.\");\n }\n\n xhr.send(body === undefined ? null : body);\n\n if (xhr.responseType === \"blob\") {\n return new Promise((resolve, reject) => {\n handleBlobResponse(xhr, request, resolve, reject);\n rejectOnTerminalEvent(request, xhr, reject);\n });\n } else {\n return new Promise(function (resolve, reject) {\n xhr.addEventListener(\"load\", () =>\n resolve({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: xhr.responseText,\n }),\n );\n rejectOnTerminalEvent(request, xhr, reject);\n });\n }\n }\n}\n\nfunction handleBlobResponse(\n xhr: XMLHttpRequest,\n request: PipelineRequest,\n res: (value: PipelineResponse | PromiseLike<PipelineResponse>) => void,\n rej: (reason?: any) => void,\n): void {\n xhr.addEventListener(\"readystatechange\", () => {\n // Resolve as soon as headers are loaded\n if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {\n if (\n // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code\n request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) ||\n request.streamResponseStatusCodes?.has(xhr.status)\n ) {\n const blobBody = new Promise<Blob>((resolve, reject) => {\n xhr.addEventListener(\"load\", () => {\n resolve(xhr.response);\n });\n rejectOnTerminalEvent(request, xhr, reject);\n });\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n blobBody,\n });\n } else {\n xhr.addEventListener(\"load\", () => {\n // xhr.response is of Blob type if the request is sent with xhr.responseType === \"blob\"\n // but the status code is not one of the stream response status codes,\n // so treat it as text and convert from Blob to text\n if (xhr.response) {\n xhr.response\n .text()\n .then((text: string) => {\n res({\n request: request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: text,\n });\n return;\n })\n .catch((e: any) => {\n rej(e);\n });\n } else {\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n });\n }\n });\n }\n }\n });\n}\n\nfunction addProgressListener(\n xhr: XMLHttpRequestEventTarget,\n listener?: (progress: TransferProgressEvent) => void,\n): void {\n if (listener) {\n xhr.addEventListener(\"progress\", (rawEvent) =>\n listener({\n loadedBytes: rawEvent.loaded,\n }),\n );\n }\n}\n\nfunction parseHeaders(xhr: XMLHttpRequest): HttpHeaders {\n const responseHeaders = createHttpHeaders();\n const headerLines = xhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/);\n for (const line of headerLines) {\n const index = line.indexOf(\":\");\n const headerName = line.slice(0, index);\n const headerValue = line.slice(index + 2);\n responseHeaders.set(headerName, headerValue);\n }\n return responseHeaders;\n}\n\nfunction rejectOnTerminalEvent(\n request: PipelineRequest,\n xhr: XMLHttpRequest,\n reject: (err: any) => void,\n): void {\n xhr.addEventListener(\"error\", () =>\n reject(\n new RestError(`Failed to send request to ${request.url}`, {\n code: RestError.REQUEST_SEND_ERROR,\n request,\n }),\n ),\n );\n const abortError = new AbortError(\"The operation was aborted.\");\n xhr.addEventListener(\"abort\", () => reject(abortError));\n xhr.addEventListener(\"timeout\", () => reject(abortError));\n}\n\n/**\n * Create a new HttpClient instance for the browser environment.\n * @internal\n */\nexport function createXhrHttpClient(): HttpClient {\n return new XhrHttpClient();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/communication-chat",
3
- "version": "1.5.0",
3
+ "version": "1.6.0-beta.1",
4
4
  "description": "Azure client library for Azure Communication Chat services",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
@@ -64,7 +64,7 @@
64
64
  "dependencies": {
65
65
  "@azure/abort-controller": "^1.0.0",
66
66
  "@azure/communication-common": "^2.3.1",
67
- "@azure/communication-signaling": "1.0.0-beta.26",
67
+ "@azure/communication-signaling": "1.0.0-beta.23",
68
68
  "@azure/core-auth": "^1.3.0",
69
69
  "@azure/core-client": "^1.3.0",
70
70
  "@azure/core-paging": "^1.1.1",
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  /// <reference lib="esnext.asynciterable" />
2
3
 
3
4
  import { ChatMessageDeletedEvent } from '@azure/communication-signaling';
@@ -52,7 +53,7 @@ export declare interface ChatAttachment {
52
53
  previewUrl?: string;
53
54
  }
54
55
 
55
- /** Defines values for AttachmentType. */
56
+ /** Type of Supported Attachments. */
56
57
  export declare type ChatAttachmentType = "image" | "file" | "unknown";
57
58
 
58
59
  /**
@@ -314,10 +315,10 @@ export declare interface ChatMessageContent {
314
315
  topic?: string;
315
316
  /** Chat message content for messages of types participantAdded or participantRemoved. */
316
317
  participants?: ChatParticipant[];
317
- /** Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model must be interpreted as a union: Apart from rawId, at most one further property may be set. */
318
- initiator?: CommunicationIdentifierKind;
319
318
  /** List of attachments for this message */
320
319
  attachments?: ChatAttachment[];
320
+ /** Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model must be interpreted as a union: Apart from rawId, at most one further property may be set. */
321
+ initiator?: CommunicationIdentifierKind;
321
322
  }
322
323
 
323
324
  export { ChatMessageDeletedEvent }
@@ -347,8 +348,13 @@ export declare interface ChatParticipant {
347
348
  displayName?: string;
348
349
  /** Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */
349
350
  shareHistoryTime?: Date;
351
+ /** metadata */
352
+ metadata?: Record<string, string>;
350
353
  }
351
354
 
355
+ /** Data retention policy for auto deletion. */
356
+ export declare type ChatRetentionPolicy = ThreadCreationDateRetentionPolicy | NoneRetentionPolicy;
357
+
352
358
  /**
353
359
  * The client to do chat operations
354
360
  */
@@ -360,6 +366,7 @@ export declare class ChatThreadClient {
360
366
  readonly threadId: string;
361
367
  private readonly tokenCredential;
362
368
  private readonly client;
369
+ private readonly xhrClient?;
363
370
  private timeOfLastTypingRequest;
364
371
  constructor(endpoint: string, threadId: string, credential: CommunicationTokenCredential, options?: ChatThreadClientOptions);
365
372
  /**
@@ -374,6 +381,11 @@ export declare class ChatThreadClient {
374
381
  * @param options - Operation options.
375
382
  */
376
383
  updateTopic(topic: string, options?: UpdateTopicOptions): Promise<void>;
384
+ /**
385
+ * Updates a thread's properties.
386
+ * @param options - Operation options.
387
+ */
388
+ updateProperties(options?: UpdateChatThreadPropertiesOptions): Promise<void>;
377
389
  /**
378
390
  * Sends a chat message to a thread identified by threadId.
379
391
  * Returns the id of the created message.
@@ -450,6 +462,34 @@ export declare class ChatThreadClient {
450
462
  */
451
463
  listReadReceipts(options?: ListReadReceiptsOptions): PagedAsyncIterableIterator<ChatMessageReadReceipt>;
452
464
  private canPostTypingNotification;
465
+ /**
466
+ * Uploads an chat image to a thread identified by threadId.
467
+ * Allowed image types "jpg", "png", "gif", "heic", "webp".
468
+ * Returns the id of the uploaded image.
469
+ * @param image - Request for uploading an image.
470
+ * @param imageFilename - The image's file name with file extension.
471
+ * @param options - Operation options.
472
+ */
473
+ uploadImage(image: ArrayBuffer | Blob, imageFilename: string, options?: UploadImageOptions): Promise<UploadChatImageResult>;
474
+ /**
475
+ * Uploads an chat image stream to a thread identified by threadId.
476
+ * Allowed image types "jpg", "png", "gif", "heic", "webp".
477
+ * Returns the id of the uploaded image.
478
+ * @param image - Request for uploading an image.
479
+ * @param imageFileName - The image's file name with file extension.
480
+ * @param imageBytesLength - The image's file length in bytes.
481
+ * @param options - Operation options.
482
+ */
483
+ uploadImage(image: ReadableStream<Uint8Array> | NodeJS.ReadableStream, imageFileName: string, imageBytesLength: number, options?: UploadImageStreamOptions): Promise<UploadChatImageResult>;
484
+ /**
485
+ * Deletes an image identified by threadId and imageId
486
+ * @param imageId - The image id of the image.
487
+ * @param options - Operation options.
488
+ */
489
+ deleteImage(imageId: string, options?: DeleteImageOptions): Promise<void>;
490
+ private supportsReadableStream;
491
+ private getArrayBufferFromReadableStream;
492
+ private getArrayBufferFromBlob;
453
493
  }
454
494
 
455
495
  /**
@@ -489,6 +529,10 @@ export declare interface ChatThreadProperties {
489
529
  readonly createdBy?: CommunicationIdentifierKind;
490
530
  /** The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */
491
531
  deletedOn?: Date;
532
+ /** metadata */
533
+ metadata?: Record<string, string>;
534
+ /** Data retention policy for auto deletion. */
535
+ retentionPolicy?: ChatRetentionPolicy;
492
536
  }
493
537
 
494
538
  export { ChatThreadPropertiesUpdatedEvent }
@@ -501,6 +545,10 @@ export declare interface CreateChatThreadOptions extends OperationOptions {
501
545
  participants?: ChatParticipant[];
502
546
  /** If specified, the client directs that the request is repeatable; that is, that the client can make the request multiple times with the same Idempotency-Token and get back an appropriate response without the server executing the request multiple times. The value of the Idempotency-Token is an opaque string representing a client-generated, globally unique for all time, identifier for the request. It is recommended to use version 4 (random) UUIDs. */
503
547
  idempotencyToken?: string;
548
+ /** metadata */
549
+ metadata?: Record<string, string>;
550
+ /** Data retention policy for auto deletion. */
551
+ retentionPolicy?: ChatRetentionPolicy;
504
552
  }
505
553
 
506
554
  /** Request payload for creating a chat thread. */
@@ -525,6 +573,11 @@ export declare interface CreateChatThreadResult {
525
573
  */
526
574
  export declare type DeleteChatThreadOptions = OperationOptions;
527
575
 
576
+ /**
577
+ * Options to delete a chat image.
578
+ */
579
+ export declare type DeleteImageOptions = OperationOptions;
580
+
528
581
  /**
529
582
  * Options to delete a chat message.
530
583
  */
@@ -571,6 +624,12 @@ export declare type ListParticipantsOptions = RestListParticipantsOptions;
571
624
  */
572
625
  export declare type ListReadReceiptsOptions = RestListReadReceiptsOptions;
573
626
 
627
+ /** No thread retention policy. */
628
+ export declare interface NoneRetentionPolicy {
629
+ /** Polymorphic discriminator, which specifies the different types this object can be */
630
+ kind: "none";
631
+ }
632
+
574
633
  export { ParticipantsAddedEvent }
575
634
 
576
635
  export { ParticipantsRemovedEvent }
@@ -594,7 +653,7 @@ export declare interface RestListChatThreadsOptions extends coreClient.Operation
594
653
  export declare interface RestListMessagesOptions extends coreClient.OperationOptions {
595
654
  /** The maximum number of messages to be returned per page. */
596
655
  maxPageSize?: number;
597
- /** The earliest point in time to get messages up to. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */
656
+ /** The earliest point in time to get messages after. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */
598
657
  startTime?: Date;
599
658
  }
600
659
 
@@ -630,6 +689,8 @@ export declare interface SendMessageOptions extends OperationOptions {
630
689
  type?: ChatMessageType;
631
690
  /** Message metadata. */
632
691
  metadata?: Record<string, string>;
692
+ /** Message attachments. */
693
+ attachments?: ChatAttachment[];
633
694
  }
634
695
 
635
696
  /** Details of the message to send. */
@@ -657,8 +718,28 @@ export declare interface SendTypingNotificationOptions extends OperationOptions
657
718
  senderDisplayName?: string;
658
719
  }
659
720
 
721
+ /** Thread retention policy based on thread creation date. */
722
+ export declare interface ThreadCreationDateRetentionPolicy {
723
+ /** Polymorphic discriminator, which specifies the different types this object can be */
724
+ kind: "threadCreationDate";
725
+ /** Indicates how many days after the thread creation the thread will be deleted. */
726
+ deleteThreadAfterDays: number;
727
+ }
728
+
660
729
  export { TypingIndicatorReceivedEvent }
661
730
 
731
+ /**
732
+ * Options to update a chat thread.
733
+ */
734
+ export declare interface UpdateChatThreadPropertiesOptions extends OperationOptions {
735
+ /** Thread topic. */
736
+ topic?: string;
737
+ /** Thread metadata. */
738
+ metadata?: Record<string, string>;
739
+ /** Data retention policy for auto deletion. */
740
+ retentionPolicy?: ChatRetentionPolicy;
741
+ }
742
+
662
743
  /**
663
744
  * Options to update a chat message.
664
745
  */
@@ -667,6 +748,8 @@ export declare interface UpdateMessageOptions extends OperationOptions {
667
748
  content?: string;
668
749
  /** Message metadata. */
669
750
  metadata?: Record<string, string>;
751
+ /** Message attachments. */
752
+ attachments?: ChatAttachment[];
670
753
  }
671
754
 
672
755
  /**
@@ -675,4 +758,27 @@ export declare interface UpdateMessageOptions extends OperationOptions {
675
758
  export declare interface UpdateTopicOptions extends OperationOptions {
676
759
  }
677
760
 
761
+ /** Result payload for uploading an image. */
762
+ export declare interface UploadChatImageResult {
763
+ /** Id of the image. */
764
+ id: string;
765
+ /** The type of attachment. */
766
+ attachmentType?: ChatAttachmentType;
767
+ /** The name including file extension type of the attachment. */
768
+ name?: string;
769
+ }
770
+
771
+ /**
772
+ * Options to upload a chat image.
773
+ */
774
+ export declare interface UploadImageOptions extends OperationOptions {
775
+ /** Image blob size in bytes. */
776
+ imageBytesLength?: number;
777
+ }
778
+
779
+ /**
780
+ * Options to upload a chat image stream.
781
+ */
782
+ export declare type UploadImageStreamOptions = OperationOptions;
783
+
678
784
  export { }