@azure/communication-chat 1.5.0-beta.2 → 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.
- package/dist/index.js +785 -63
- package/dist/index.js.map +1 -1
- package/dist-esm/src/chatClient.js +5 -4
- package/dist-esm/src/chatClient.js.map +1 -1
- package/dist-esm/src/chatThreadClient.js +81 -10
- package/dist-esm/src/chatThreadClient.js.map +1 -1
- package/dist-esm/src/generated/src/chatApiClient.js +2 -2
- package/dist-esm/src/generated/src/chatApiClient.js.map +1 -1
- package/dist-esm/src/generated/src/models/index.js +10 -0
- package/dist-esm/src/generated/src/models/index.js.map +1 -1
- package/dist-esm/src/generated/src/models/mappers.js +265 -41
- package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
- package/dist-esm/src/generated/src/models/parameters.js +73 -1
- package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
- package/dist-esm/src/generated/src/operations/chatThread.js +98 -0
- package/dist-esm/src/generated/src/operations/chatThread.js.map +1 -1
- package/dist-esm/src/generated/src/operationsInterfaces/chatThread.js.map +1 -1
- package/dist-esm/src/generated/src/tracing.js +1 -1
- package/dist-esm/src/generated/src/tracing.js.map +1 -1
- package/dist-esm/src/models/mappers.js +68 -5
- package/dist-esm/src/models/mappers.js.map +1 -1
- package/dist-esm/src/models/models.js.map +1 -1
- package/dist-esm/src/models/options.js.map +1 -1
- package/dist-esm/src/xhrHttpClient.js +186 -0
- package/dist-esm/src/xhrHttpClient.js.map +1 -0
- package/package.json +3 -3
- package/types/communication-chat.d.ts +86 -1
|
@@ -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,uCA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I,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.
|
|
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",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"prettier": "@azure/eslint-plugin-azure-sdk/prettier.json",
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@azure/abort-controller": "^1.0.0",
|
|
66
|
-
"@azure/communication-common": "^2.
|
|
66
|
+
"@azure/communication-common": "^2.3.1",
|
|
67
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",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"c8": "^9.1.0",
|
|
109
109
|
"rimraf": "^5.0.5",
|
|
110
110
|
"sinon": "^17.0.0",
|
|
111
|
-
"typescript": "~5.
|
|
111
|
+
"typescript": "~5.4.5",
|
|
112
112
|
"util": "^0.12.1",
|
|
113
113
|
"ts-node": "^10.0.0",
|
|
114
114
|
"esm": "^3.2.18"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
/// <reference lib="esnext.asynciterable" />
|
|
2
3
|
|
|
3
4
|
import { ChatMessageDeletedEvent } from '@azure/communication-signaling';
|
|
@@ -351,6 +352,9 @@ export declare interface ChatParticipant {
|
|
|
351
352
|
metadata?: Record<string, string>;
|
|
352
353
|
}
|
|
353
354
|
|
|
355
|
+
/** Data retention policy for auto deletion. */
|
|
356
|
+
export declare type ChatRetentionPolicy = ThreadCreationDateRetentionPolicy | NoneRetentionPolicy;
|
|
357
|
+
|
|
354
358
|
/**
|
|
355
359
|
* The client to do chat operations
|
|
356
360
|
*/
|
|
@@ -362,6 +366,7 @@ export declare class ChatThreadClient {
|
|
|
362
366
|
readonly threadId: string;
|
|
363
367
|
private readonly tokenCredential;
|
|
364
368
|
private readonly client;
|
|
369
|
+
private readonly xhrClient?;
|
|
365
370
|
private timeOfLastTypingRequest;
|
|
366
371
|
constructor(endpoint: string, threadId: string, credential: CommunicationTokenCredential, options?: ChatThreadClientOptions);
|
|
367
372
|
/**
|
|
@@ -457,6 +462,34 @@ export declare class ChatThreadClient {
|
|
|
457
462
|
*/
|
|
458
463
|
listReadReceipts(options?: ListReadReceiptsOptions): PagedAsyncIterableIterator<ChatMessageReadReceipt>;
|
|
459
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;
|
|
460
493
|
}
|
|
461
494
|
|
|
462
495
|
/**
|
|
@@ -498,6 +531,8 @@ export declare interface ChatThreadProperties {
|
|
|
498
531
|
deletedOn?: Date;
|
|
499
532
|
/** metadata */
|
|
500
533
|
metadata?: Record<string, string>;
|
|
534
|
+
/** Data retention policy for auto deletion. */
|
|
535
|
+
retentionPolicy?: ChatRetentionPolicy;
|
|
501
536
|
}
|
|
502
537
|
|
|
503
538
|
export { ChatThreadPropertiesUpdatedEvent }
|
|
@@ -512,6 +547,8 @@ export declare interface CreateChatThreadOptions extends OperationOptions {
|
|
|
512
547
|
idempotencyToken?: string;
|
|
513
548
|
/** metadata */
|
|
514
549
|
metadata?: Record<string, string>;
|
|
550
|
+
/** Data retention policy for auto deletion. */
|
|
551
|
+
retentionPolicy?: ChatRetentionPolicy;
|
|
515
552
|
}
|
|
516
553
|
|
|
517
554
|
/** Request payload for creating a chat thread. */
|
|
@@ -536,6 +573,11 @@ export declare interface CreateChatThreadResult {
|
|
|
536
573
|
*/
|
|
537
574
|
export declare type DeleteChatThreadOptions = OperationOptions;
|
|
538
575
|
|
|
576
|
+
/**
|
|
577
|
+
* Options to delete a chat image.
|
|
578
|
+
*/
|
|
579
|
+
export declare type DeleteImageOptions = OperationOptions;
|
|
580
|
+
|
|
539
581
|
/**
|
|
540
582
|
* Options to delete a chat message.
|
|
541
583
|
*/
|
|
@@ -582,6 +624,12 @@ export declare type ListParticipantsOptions = RestListParticipantsOptions;
|
|
|
582
624
|
*/
|
|
583
625
|
export declare type ListReadReceiptsOptions = RestListReadReceiptsOptions;
|
|
584
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
|
+
|
|
585
633
|
export { ParticipantsAddedEvent }
|
|
586
634
|
|
|
587
635
|
export { ParticipantsRemovedEvent }
|
|
@@ -605,7 +653,7 @@ export declare interface RestListChatThreadsOptions extends coreClient.Operation
|
|
|
605
653
|
export declare interface RestListMessagesOptions extends coreClient.OperationOptions {
|
|
606
654
|
/** The maximum number of messages to be returned per page. */
|
|
607
655
|
maxPageSize?: number;
|
|
608
|
-
/** The earliest point in time to get messages
|
|
656
|
+
/** The earliest point in time to get messages after. The timestamp should be in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */
|
|
609
657
|
startTime?: Date;
|
|
610
658
|
}
|
|
611
659
|
|
|
@@ -641,6 +689,8 @@ export declare interface SendMessageOptions extends OperationOptions {
|
|
|
641
689
|
type?: ChatMessageType;
|
|
642
690
|
/** Message metadata. */
|
|
643
691
|
metadata?: Record<string, string>;
|
|
692
|
+
/** Message attachments. */
|
|
693
|
+
attachments?: ChatAttachment[];
|
|
644
694
|
}
|
|
645
695
|
|
|
646
696
|
/** Details of the message to send. */
|
|
@@ -668,6 +718,14 @@ export declare interface SendTypingNotificationOptions extends OperationOptions
|
|
|
668
718
|
senderDisplayName?: string;
|
|
669
719
|
}
|
|
670
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
|
+
|
|
671
729
|
export { TypingIndicatorReceivedEvent }
|
|
672
730
|
|
|
673
731
|
/**
|
|
@@ -678,6 +736,8 @@ export declare interface UpdateChatThreadPropertiesOptions extends OperationOpti
|
|
|
678
736
|
topic?: string;
|
|
679
737
|
/** Thread metadata. */
|
|
680
738
|
metadata?: Record<string, string>;
|
|
739
|
+
/** Data retention policy for auto deletion. */
|
|
740
|
+
retentionPolicy?: ChatRetentionPolicy;
|
|
681
741
|
}
|
|
682
742
|
|
|
683
743
|
/**
|
|
@@ -688,6 +748,8 @@ export declare interface UpdateMessageOptions extends OperationOptions {
|
|
|
688
748
|
content?: string;
|
|
689
749
|
/** Message metadata. */
|
|
690
750
|
metadata?: Record<string, string>;
|
|
751
|
+
/** Message attachments. */
|
|
752
|
+
attachments?: ChatAttachment[];
|
|
691
753
|
}
|
|
692
754
|
|
|
693
755
|
/**
|
|
@@ -696,4 +758,27 @@ export declare interface UpdateMessageOptions extends OperationOptions {
|
|
|
696
758
|
export declare interface UpdateTopicOptions extends OperationOptions {
|
|
697
759
|
}
|
|
698
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
|
+
|
|
699
784
|
export { }
|