@talkjs/core 1.0.0 → 1.1.0
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/README.md +11 -1
- package/dist/talkSession.cjs +1 -1
- package/dist/talkSession.d.ts +370 -58
- package/dist/talkSession.js +453 -353
- package/package.json +5 -4
package/dist/talkSession.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export declare interface AudioBlock {
|
|
|
84
84
|
duration?: number;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
declare interface AudioFileMetadata {
|
|
87
|
+
export declare interface AudioFileMetadata {
|
|
88
88
|
/**
|
|
89
89
|
* The name of the file including extension.
|
|
90
90
|
*/
|
|
@@ -114,11 +114,11 @@ declare interface AudioFileMetadata {
|
|
|
114
114
|
*
|
|
115
115
|
* This means that the following AutoLink is valid:
|
|
116
116
|
*
|
|
117
|
-
* ```
|
|
117
|
+
* ```json
|
|
118
118
|
* {
|
|
119
119
|
* type: "autoLink",
|
|
120
120
|
* text: "talkjs.com"
|
|
121
|
-
* url: "https://talkjs.com/docs/Reference/
|
|
121
|
+
* url: "https://talkjs.com/docs/Reference/JavaScript_Data_API/Message_Content/#AutoLinkNode"
|
|
122
122
|
* }
|
|
123
123
|
* ```
|
|
124
124
|
*
|
|
@@ -218,8 +218,8 @@ export declare interface ConversationActiveState {
|
|
|
218
218
|
* References the conversation with a given conversation ID, from the perspective of the current user.
|
|
219
219
|
*
|
|
220
220
|
* @remarks
|
|
221
|
-
* Used in all
|
|
222
|
-
* Created via {@link Session.conversation}.
|
|
221
|
+
* Used in all Data API operations affecting that conversation, such as fetching or updating conversation attributes.
|
|
222
|
+
* Created via {@link Session.conversation|Session.conversation()}.
|
|
223
223
|
*
|
|
224
224
|
* @public
|
|
225
225
|
*/
|
|
@@ -234,13 +234,41 @@ export declare interface ConversationRef {
|
|
|
234
234
|
/**
|
|
235
235
|
* Get a reference to a participant in this conversation
|
|
236
236
|
*
|
|
237
|
-
* @
|
|
237
|
+
* @remarks
|
|
238
|
+
* Note that `Participant` is not the same as `User`.
|
|
239
|
+
* A `Participant` represents a user's settings related to a specific conversation.
|
|
240
|
+
*
|
|
241
|
+
* Calling {@link ConversationRef.createIfNotExists|ConversationRef.createIfNotExists} or {@link ConversationRef.set|ConversationRef.set} will automatically add the current user as a participant.
|
|
242
|
+
*
|
|
243
|
+
* @example To add "Alice" to the conversation "Cats"
|
|
244
|
+
* ```ts
|
|
245
|
+
* session.conversation("Cats").participant("Alice").createIfNotExists();
|
|
246
|
+
* ```
|
|
247
|
+
*
|
|
248
|
+
* The user "Alice" must exist before you do this.
|
|
249
|
+
*
|
|
250
|
+
* @example To remove "Alice" from the conversation "Cats"
|
|
251
|
+
* ```ts
|
|
252
|
+
* session.conversation("Cats").participant("Alice").delete();
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* The user "Alice" will still exist after you do this. This deletes the participant, not the user.
|
|
256
|
+
*
|
|
257
|
+
* @param user - Specifies which participant in the conversation you want to reference. Either the user's ID, or a reference to that user.
|
|
258
|
+
* @returns A {@linkcode ParticipantRef} for that user's participation in this conversation
|
|
259
|
+
* @public
|
|
238
260
|
*/
|
|
239
261
|
participant(user: string | UserRef): ParticipantRef;
|
|
240
262
|
/**
|
|
241
263
|
* Get a reference to a message in this conversation
|
|
242
264
|
*
|
|
243
|
-
* @
|
|
265
|
+
* @remarks
|
|
266
|
+
* Use this if you need to fetch, delete, or edit a specific message in this conversation, and you know its message ID.
|
|
267
|
+
* To fetch the most recent messages in this conversation, use {@link ConversationRef.subscribeMessages} instead.
|
|
268
|
+
*
|
|
269
|
+
* @param id - The ID of the user that you want to reference
|
|
270
|
+
* @returns A {@linkcode UserRef} for the user with that ID
|
|
271
|
+
* @public
|
|
244
272
|
*/
|
|
245
273
|
message(id: string): MessageRef;
|
|
246
274
|
/**
|
|
@@ -260,7 +288,7 @@ export declare interface ConversationRef {
|
|
|
260
288
|
* You are added as a participant if you are not already a participant in the conversation.
|
|
261
289
|
*
|
|
262
290
|
* @returns A promise that resolves when the operation completes.
|
|
263
|
-
* When client-side conversation syncing is disabled, you
|
|
291
|
+
* When client-side conversation syncing is disabled, you must already be a participant and you cannot set anything except the `notify` property.
|
|
264
292
|
* Everything else requires client-side conversation syncing to be enabled, and will cause the promise to reject.
|
|
265
293
|
*/
|
|
266
294
|
set(params: SetConversationParams): Promise<void>;
|
|
@@ -289,6 +317,54 @@ export declare interface ConversationRef {
|
|
|
289
317
|
/**
|
|
290
318
|
* Sends a message in the conversation
|
|
291
319
|
*
|
|
320
|
+
* @example Send a simple message with markup (bold in this example)
|
|
321
|
+
* ```ts
|
|
322
|
+
* conversationRef.send("*Hello*");
|
|
323
|
+
* ```
|
|
324
|
+
*
|
|
325
|
+
* @example Reply to a message and set custom message data
|
|
326
|
+
* ```ts
|
|
327
|
+
* conversationRef.send({
|
|
328
|
+
* text: "Agreed",
|
|
329
|
+
* referencedMessageId: "...",
|
|
330
|
+
* custom: { priority: "HIGH" }
|
|
331
|
+
* });
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* @example Send pre-formatted text with {@link TextBlock}
|
|
335
|
+
* ```ts
|
|
336
|
+
* conversationRef.send({
|
|
337
|
+
* content: [{
|
|
338
|
+
* type: "text",
|
|
339
|
+
* children: [{
|
|
340
|
+
* type: "bold",
|
|
341
|
+
* children: ["Hello"]
|
|
342
|
+
* }]
|
|
343
|
+
* }]
|
|
344
|
+
* });
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* @example Send a file with {@link SendFileBlock}
|
|
348
|
+
* ```ts
|
|
349
|
+
* // `file` is a File object from `<input type="file">`
|
|
350
|
+
* const fileToken = await session.uploadImage(
|
|
351
|
+
* file, { filename: file.name, width: 640, height: 480 }
|
|
352
|
+
* );
|
|
353
|
+
*
|
|
354
|
+
* conversationRef.send({
|
|
355
|
+
* content: [{ type: "file", fileToken }]
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* @example Send a location with {@link LocationBlock}
|
|
360
|
+
* ```ts
|
|
361
|
+
* // You can get the user's location with the browser's geolocation API
|
|
362
|
+
* const [latitude, longitude] = [42.43, -83.99];
|
|
363
|
+
* conversationRef.send({
|
|
364
|
+
* content: [{ type: "location", latitude, longitude }]
|
|
365
|
+
* });
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
292
368
|
* @returns A promise that resolves with a reference to the newly created message. The promise will reject if you do not have permission to send the message.
|
|
293
369
|
*/
|
|
294
370
|
send(params: string | SendTextMessageParams | SendMessageParams): Promise<MessageRef>;
|
|
@@ -310,11 +386,64 @@ export declare interface ConversationRef {
|
|
|
310
386
|
*
|
|
311
387
|
* @remarks
|
|
312
388
|
* Whenever `Subscription.state.type` is "active" and something about the conversation changes, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
|
|
313
|
-
* This includes changes to nested data. As an extreme example, `onSnapshot` would be called
|
|
389
|
+
* This includes changes to nested data. As an extreme example, `onSnapshot` would be called when `snapshot.lastMessage.referencedMessage.sender.name` changes.
|
|
314
390
|
*
|
|
315
391
|
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
316
392
|
*/
|
|
317
393
|
subscribe(onSnapshot?: (snapshot: ConversationSnapshot | null) => void): ConversationSubscription;
|
|
394
|
+
/**
|
|
395
|
+
* Subscribes to the typing status of the conversation.
|
|
396
|
+
*
|
|
397
|
+
* @remarks
|
|
398
|
+
* Whenever `Subscription.state.type` is "active" and the typing status changes, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
|
|
399
|
+
* This includes changes to nested data, such as when a user who is typing changes their name.
|
|
400
|
+
*
|
|
401
|
+
* The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
|
|
402
|
+
*
|
|
403
|
+
* Note that if there are "many" people typing and another person starts to type, `onSnapshot` will not be called.
|
|
404
|
+
* This is because your existing {@link ManyTypingSnapshot} is still valid and did not change when the new person started to type.
|
|
405
|
+
*/
|
|
406
|
+
subscribeTyping(onSnapshot?: (snapshot: TypingSnapshot | null) => void): TypingSubscription;
|
|
407
|
+
/**
|
|
408
|
+
* Marks the current user as typing in this conversation for 10 seconds.
|
|
409
|
+
*
|
|
410
|
+
* @remarks
|
|
411
|
+
* This means that other users will see a typing indicator in the UI, from the current user.
|
|
412
|
+
*
|
|
413
|
+
* The user will automatically stop typing after 10 seconds. You cannot manually mark a user as "not typing".
|
|
414
|
+
* Users are also considered "not typing" when they send a message, even if that message was sent from a different tab or using the REST API.
|
|
415
|
+
*
|
|
416
|
+
* To keep the typing indicator visible for longer, call this function again to reset the 10s timer.
|
|
417
|
+
*
|
|
418
|
+
* @example Example implementation
|
|
419
|
+
* ```ts
|
|
420
|
+
* let lastMarkedAsTyping = 0;
|
|
421
|
+
*
|
|
422
|
+
* inputElement.addEventListener("change", event => {
|
|
423
|
+
* const text = event.target.value;
|
|
424
|
+
*
|
|
425
|
+
* // Deleting your draft never counts as typing
|
|
426
|
+
* if (text.length === 0) {
|
|
427
|
+
* return;
|
|
428
|
+
* }
|
|
429
|
+
*
|
|
430
|
+
* const now = Date.now();
|
|
431
|
+
*
|
|
432
|
+
* // Don't mark as typing more than once every 5s
|
|
433
|
+
* if (now - lastMarkedAsTyping > 5000) {
|
|
434
|
+
* lastMarkedAsTyping = now;
|
|
435
|
+
* convRef.markAsTyping();
|
|
436
|
+
* }
|
|
437
|
+
* });
|
|
438
|
+
*
|
|
439
|
+
* // When you send a message, you are no longer considered typing
|
|
440
|
+
* // So we need to send markAsTyping as soon as you type something
|
|
441
|
+
* function onSendMessage() {
|
|
442
|
+
* lastMarkedAsTyping = 0;
|
|
443
|
+
* }
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
markAsTyping(): Promise<void>;
|
|
318
447
|
}
|
|
319
448
|
|
|
320
449
|
/**
|
|
@@ -333,11 +462,11 @@ export declare interface ConversationSnapshot {
|
|
|
333
462
|
*/
|
|
334
463
|
id: string;
|
|
335
464
|
/**
|
|
336
|
-
* Contains the conversation subject if
|
|
465
|
+
* Contains the conversation subject, or `null` if the conversation does not have a subject specified.
|
|
337
466
|
*/
|
|
338
467
|
subject: string | null;
|
|
339
468
|
/**
|
|
340
|
-
* Contains the URL of a photo
|
|
469
|
+
* Contains the URL of a photo to represent the topic of the conversation or `null` if the conversation does not have a photo specified.
|
|
341
470
|
*/
|
|
342
471
|
photoUrl: string | null;
|
|
343
472
|
/**
|
|
@@ -643,6 +772,27 @@ export declare interface ErrorState {
|
|
|
643
772
|
error: Error;
|
|
644
773
|
}
|
|
645
774
|
|
|
775
|
+
/**
|
|
776
|
+
* The {@link TypingSnapshot} variant used when only a few people are typing.
|
|
777
|
+
*/
|
|
778
|
+
export declare interface FewTypingSnapshot {
|
|
779
|
+
/**
|
|
780
|
+
* Check this to differentiate between FewTypingSnapshot (`false`) and ManyTypingSnapshot (`true`).
|
|
781
|
+
*
|
|
782
|
+
* @remarks
|
|
783
|
+
* When `false`, you can see the list of users who are typing in the `users` property.
|
|
784
|
+
*/
|
|
785
|
+
many: false;
|
|
786
|
+
/**
|
|
787
|
+
* The users who are currently typing in this conversation.
|
|
788
|
+
*
|
|
789
|
+
* @remarks
|
|
790
|
+
* The list is in chronological order, starting with the users who have been typing the longest.
|
|
791
|
+
* The current user is never contained in the list, only other users.
|
|
792
|
+
*/
|
|
793
|
+
users: UserSnapshot[];
|
|
794
|
+
}
|
|
795
|
+
|
|
646
796
|
/**
|
|
647
797
|
* A file attachment received in a message's content.
|
|
648
798
|
*
|
|
@@ -671,35 +821,34 @@ export declare type FileBlock = VideoBlock | ImageBlock | AudioBlock | VoiceBloc
|
|
|
671
821
|
*
|
|
672
822
|
* @remarks
|
|
673
823
|
* You cannot create a FileToken yourself. Get a file token by uploading your file to TalkJS with {@link Session.uploadFile}, or one of the subtype-specific variants like {@link Session.uploadImage}.
|
|
824
|
+
* Alternatively, take a file token from an existing {@link FileBlock} to re-send an attachment you received, without having to download and re-upload the file.
|
|
825
|
+
* You can also upload files using the {@link https://talkjs.com/docs/Reference/REST_API/Messages/#1-upload-a-file| REST API}.
|
|
826
|
+
* This system ensures that all files must be uploaded to TalkJS before being sent to users, limiting the risk of malware.
|
|
674
827
|
*
|
|
675
|
-
*
|
|
828
|
+
* Passed in {@link SendFileBlock} when you send a message containing a file attachment.
|
|
676
829
|
*
|
|
677
|
-
*
|
|
830
|
+
* We may change the FileToken format in the future.
|
|
831
|
+
* Do not store old file tokens for future use, as these may stop working.
|
|
832
|
+
*
|
|
833
|
+
* @example Using a file input
|
|
834
|
+
* ```ts
|
|
678
835
|
* // From `<input type="file">`
|
|
679
836
|
* const file: File = fileInputElement.files[0];
|
|
680
837
|
* const myFileToken = await session.uploadFile(file, { filename: file.name });
|
|
681
|
-
* ```
|
|
682
|
-
*
|
|
683
|
-
* Alternatively, take a file token from an existing {@link FileBlock} to re-send an attachment you received, without having to download and re-upload the file.
|
|
684
838
|
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
* Passed in {@link SendFileBlock} when you send a message containing a file attachment:
|
|
688
|
-
*
|
|
689
|
-
* ```
|
|
690
|
-
* const block: SendFileBlock = {
|
|
839
|
+
* const block = {
|
|
691
840
|
* type: 'file',
|
|
692
841
|
* fileToken: myFileToken,
|
|
693
842
|
* };
|
|
694
|
-
*
|
|
695
|
-
* const convRef = session.conversation('example_conversation_id');
|
|
696
|
-
* convRef.send({ content: [block] });
|
|
843
|
+
* session.conversation('example_conversation_id').send({ content: [block] });
|
|
697
844
|
* ```
|
|
698
845
|
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
846
|
+
* @example Re-sending a file from a previous message
|
|
847
|
+
* ```ts
|
|
848
|
+
* session.conversation('example_conversation_id').send({
|
|
849
|
+
* content: previousMessageSnapshot.content
|
|
850
|
+
* });
|
|
851
|
+
* ```
|
|
703
852
|
*
|
|
704
853
|
* @public
|
|
705
854
|
*/
|
|
@@ -715,7 +864,7 @@ export declare type FileToken = string & {
|
|
|
715
864
|
*
|
|
716
865
|
* Instead, treat GenericFileBlock as the default. For example:
|
|
717
866
|
*
|
|
718
|
-
* ```
|
|
867
|
+
* ```ts
|
|
719
868
|
* if (block.subtype === "video") {
|
|
720
869
|
* handleVideoBlock(block);
|
|
721
870
|
* } else if (block.subtype === "image") {
|
|
@@ -755,7 +904,7 @@ export declare interface GenericFileBlock {
|
|
|
755
904
|
filename: string;
|
|
756
905
|
}
|
|
757
906
|
|
|
758
|
-
declare interface GenericFileMetadata {
|
|
907
|
+
export declare interface GenericFileMetadata {
|
|
759
908
|
/**
|
|
760
909
|
* The name of the file including extension.
|
|
761
910
|
*/
|
|
@@ -763,7 +912,7 @@ declare interface GenericFileMetadata {
|
|
|
763
912
|
}
|
|
764
913
|
|
|
765
914
|
/**
|
|
766
|
-
* Returns a TalkSession
|
|
915
|
+
* Returns a TalkSession for the specified App ID and User ID.
|
|
767
916
|
*
|
|
768
917
|
* @remarks
|
|
769
918
|
* Backed by a registry, so calling this function twice with the same app and user returns the same session object both times.
|
|
@@ -816,7 +965,7 @@ export declare interface ImageBlock {
|
|
|
816
965
|
height?: number;
|
|
817
966
|
}
|
|
818
967
|
|
|
819
|
-
declare interface ImageFileMetadata {
|
|
968
|
+
export declare interface ImageFileMetadata {
|
|
820
969
|
/**
|
|
821
970
|
* The name of the file including extension.
|
|
822
971
|
*/
|
|
@@ -879,6 +1028,20 @@ export declare interface LocationBlock {
|
|
|
879
1028
|
longitude: number;
|
|
880
1029
|
}
|
|
881
1030
|
|
|
1031
|
+
/**
|
|
1032
|
+
* The {@link TypingSnapshot} variant used when many people are typing.
|
|
1033
|
+
*/
|
|
1034
|
+
export declare interface ManyTypingSnapshot {
|
|
1035
|
+
/**
|
|
1036
|
+
* Check this to differentiate between FewTypingSnapshot (`false`) and ManyTypingSnapshot (`true`).
|
|
1037
|
+
*
|
|
1038
|
+
* @remarks
|
|
1039
|
+
* When `true`, you do not receive a list of users who are typing.
|
|
1040
|
+
* You should show a message like "several people are typing" instead.
|
|
1041
|
+
*/
|
|
1042
|
+
many: true;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
882
1045
|
/**
|
|
883
1046
|
* A node in a {@link TextBlock} that renders its children with a specific style.
|
|
884
1047
|
*
|
|
@@ -931,7 +1094,7 @@ export declare interface MessageActiveState {
|
|
|
931
1094
|
latestSnapshot: MessageSnapshot[] | null;
|
|
932
1095
|
/**
|
|
933
1096
|
* True if `latestSnapshot` contains all messages in the conversation.
|
|
934
|
-
* Use
|
|
1097
|
+
* Use {@link MessageSubscription.loadMore} to load more.
|
|
935
1098
|
*/
|
|
936
1099
|
loadedAll: boolean;
|
|
937
1100
|
}
|
|
@@ -940,8 +1103,8 @@ export declare interface MessageActiveState {
|
|
|
940
1103
|
* References the message with a given message ID.
|
|
941
1104
|
*
|
|
942
1105
|
* @remarks
|
|
943
|
-
* Used in all
|
|
944
|
-
* Created via {@link ConversationRef.message}.
|
|
1106
|
+
* Used in all Data API operations affecting that message, such as fetching or editing the message attributes, or deleting the message.
|
|
1107
|
+
* Created via {@link ConversationRef.message} and {@link ConversationRef.send}.
|
|
945
1108
|
*
|
|
946
1109
|
* @public
|
|
947
1110
|
*/
|
|
@@ -964,7 +1127,7 @@ export declare interface MessageRef {
|
|
|
964
1127
|
* Fetches a snapshot of the message.
|
|
965
1128
|
*
|
|
966
1129
|
* @remarks
|
|
967
|
-
* Supports {@link https://talkjs.com/docs/Reference/
|
|
1130
|
+
* Supports {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/Performance/#cached-fetch | Cached Fetch}
|
|
968
1131
|
*
|
|
969
1132
|
* @returns A snapshot of the message's attributes, or null if the message doesn't exist, the conversation doesn't exist, or you're not a participant in the conversation.
|
|
970
1133
|
*/
|
|
@@ -1068,7 +1231,7 @@ export declare interface MessageSnapshot {
|
|
|
1068
1231
|
* The subscription is 'windowed'. It includes all messages since a certain point in time.
|
|
1069
1232
|
* By default, you subscribe to the 30 most recent messages, and any new messages are sent after you subscribe.
|
|
1070
1233
|
*
|
|
1071
|
-
* You can expand this window by calling
|
|
1234
|
+
* You can expand this window by calling {@link MessageSubscription.loadMore}, which extends the window further into the past.
|
|
1072
1235
|
*
|
|
1073
1236
|
* @public
|
|
1074
1237
|
*/
|
|
@@ -1115,7 +1278,7 @@ export declare interface MessageSubscription {
|
|
|
1115
1278
|
* @param count - The number of additional messages to load. Must be between 1 and 100
|
|
1116
1279
|
* @returns A promise that resolves once the additional messages have loaded
|
|
1117
1280
|
*/
|
|
1118
|
-
loadMore
|
|
1281
|
+
loadMore(count?: number): Promise<void>;
|
|
1119
1282
|
/**
|
|
1120
1283
|
* Unsubscribe from this resource and stop receiving updates.
|
|
1121
1284
|
*
|
|
@@ -1129,7 +1292,7 @@ export declare interface MessageSubscription {
|
|
|
1129
1292
|
* References a given user's participation in a conversation.
|
|
1130
1293
|
*
|
|
1131
1294
|
* @remarks
|
|
1132
|
-
* Used in all
|
|
1295
|
+
* Used in all Data API operations affecting that participant, such as joining/leaving a conversation, or setting their access.
|
|
1133
1296
|
* Created via {@link ConversationRef.participant}.
|
|
1134
1297
|
*
|
|
1135
1298
|
* @public
|
|
@@ -1162,10 +1325,10 @@ export declare interface ParticipantRef {
|
|
|
1162
1325
|
* Sets properties of this participant. If the user is not already a participant in the conversation, they will be added.
|
|
1163
1326
|
*
|
|
1164
1327
|
* @remarks
|
|
1165
|
-
* Supports {@link https://talkjs.com/docs/Reference/
|
|
1328
|
+
* Supports {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/Performance/#automatic-batching | Automatic Batching}
|
|
1166
1329
|
*
|
|
1167
1330
|
* @returns A promise that resolves when the operation completes.
|
|
1168
|
-
* When client-side conversation syncing is disabled, you
|
|
1331
|
+
* When client-side conversation syncing is disabled, you must already be a participant and you cannot set anything except the `notify` property.
|
|
1169
1332
|
* Everything else requires client-side conversation syncing to be enabled, and will cause the promise to reject.
|
|
1170
1333
|
*/
|
|
1171
1334
|
set(params: SetParticipantParams): Promise<void>;
|
|
@@ -1173,10 +1336,10 @@ export declare interface ParticipantRef {
|
|
|
1173
1336
|
* Edits properties of a pre-existing participant. If the user is not already a participant in the conversation, the promise will reject.
|
|
1174
1337
|
*
|
|
1175
1338
|
* @remarks
|
|
1176
|
-
* Supports {@link https://talkjs.com/docs/Reference/
|
|
1339
|
+
* Supports {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/Performance/#automatic-batching | Automatic Batching}
|
|
1177
1340
|
*
|
|
1178
1341
|
* @returns A promise that resolves when the operation completes.
|
|
1179
|
-
* When client-side conversation syncing is disabled, you
|
|
1342
|
+
* When client-side conversation syncing is disabled, you must already be a participant and you cannot set anything except the `notify` property.
|
|
1180
1343
|
* Everything else requires client-side conversation syncing to be enabled, and will cause the promise to reject.
|
|
1181
1344
|
*/
|
|
1182
1345
|
edit(params: SetParticipantParams): Promise<void>;
|
|
@@ -1186,7 +1349,7 @@ export declare interface ParticipantRef {
|
|
|
1186
1349
|
* @remarks
|
|
1187
1350
|
* If the participant already exists, this operation is still considered successful and the promise will still resolve.
|
|
1188
1351
|
*
|
|
1189
|
-
* Supports {@link https://talkjs.com/docs/Reference/
|
|
1352
|
+
* Supports {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/Performance/#automatic-batching | Automatic Batching}
|
|
1190
1353
|
*
|
|
1191
1354
|
* @returns A promise that resolves when the operation completes. The promise will reject if client-side conversation syncing is disabled and the user is not already a participant.
|
|
1192
1355
|
*/
|
|
@@ -1297,9 +1460,9 @@ export declare interface ReferencedMessageSnapshot {
|
|
|
1297
1460
|
/**
|
|
1298
1461
|
* Where this message originated from:
|
|
1299
1462
|
*
|
|
1300
|
-
* - "web" = Message sent via the UI or via
|
|
1463
|
+
* - "web" = Message sent via the UI or via {@link ConversationBuilder.sendMessage}
|
|
1301
1464
|
*
|
|
1302
|
-
* - "rest" = Message sent via the REST API's "send message" endpoint
|
|
1465
|
+
* - "rest" = Message sent via the REST API's "send message" endpoint or {@link ConversationRef.send}
|
|
1303
1466
|
*
|
|
1304
1467
|
* - "import" = Message sent via the REST API's "import messages" endpoint
|
|
1305
1468
|
*
|
|
@@ -1330,7 +1493,7 @@ export declare function registerPolyfills({ WebSocket }: {
|
|
|
1330
1493
|
* `SendContentBlock` is a subset of `ContentBlock`.
|
|
1331
1494
|
* This means that you can re-send the `content` from an existing message without any issues:
|
|
1332
1495
|
*
|
|
1333
|
-
* ```
|
|
1496
|
+
* ```ts
|
|
1334
1497
|
* const existingMessage: MessageSnapshot = ...;
|
|
1335
1498
|
*
|
|
1336
1499
|
* const convRef = session.conversation('example_conversation_id');
|
|
@@ -1352,7 +1515,7 @@ export declare type SendContentBlock = TextBlock | SendFileBlock | LocationBlock
|
|
|
1352
1515
|
* The `SendFileBlock` interface is a subset of the `FileBlock` interface.
|
|
1353
1516
|
* If you have an existing `FileBlock` received in a message, you can re-use that block to re-send the same attachment:
|
|
1354
1517
|
*
|
|
1355
|
-
* ```
|
|
1518
|
+
* ```ts
|
|
1356
1519
|
* const existingFileBlock = ...;
|
|
1357
1520
|
* const imageToShare = existingFileBlock.content[0] as ImageBlock
|
|
1358
1521
|
*
|
|
@@ -1397,6 +1560,8 @@ export declare interface SendMessageParams {
|
|
|
1397
1560
|
*
|
|
1398
1561
|
* @remarks
|
|
1399
1562
|
* By default users do not have permission to send {@link LinkNode}, {@link ActionLinkNode}, or {@link ActionButtonNode}, as they can be used to trick the recipient.
|
|
1563
|
+
*
|
|
1564
|
+
* Currently, each message can only contain a single {@link SendContentBlock}.
|
|
1400
1565
|
*/
|
|
1401
1566
|
content: [SendContentBlock];
|
|
1402
1567
|
}
|
|
@@ -1579,6 +1744,10 @@ export declare interface TalkSession {
|
|
|
1579
1744
|
* @remarks
|
|
1580
1745
|
* This is immutable. If you want to connect as a different user,
|
|
1581
1746
|
* call `getTalkSession` again to get a new session.
|
|
1747
|
+
*
|
|
1748
|
+
* Equivalent to calling `Session.user` with the current user's ID.
|
|
1749
|
+
*
|
|
1750
|
+
* @see {@link Session.user} which lets you get a reference to any user.
|
|
1582
1751
|
*/
|
|
1583
1752
|
readonly currentUser: UserRef;
|
|
1584
1753
|
/**
|
|
@@ -1597,6 +1766,27 @@ export declare interface TalkSession {
|
|
|
1597
1766
|
/**
|
|
1598
1767
|
* Get a reference to a user
|
|
1599
1768
|
*
|
|
1769
|
+
* @remarks
|
|
1770
|
+
* This is the entry-point for all operations that affect a user globally, such as editing their name.
|
|
1771
|
+
* For operations related to a user's participation in a conversation, do: `session.conversation(<convId>).participant(<userId>)`
|
|
1772
|
+
*
|
|
1773
|
+
* @see {@link Session.currentUser} which is a short-hand for `session.user(session.me.id)`.
|
|
1774
|
+
*
|
|
1775
|
+
* @example Initialising a user
|
|
1776
|
+
* ```
|
|
1777
|
+
* const userRef = session.user("test");
|
|
1778
|
+
* userRef.createIfNotExists({ name: "Alice" });
|
|
1779
|
+
* ```
|
|
1780
|
+
*
|
|
1781
|
+
* @example Subscribing to changes
|
|
1782
|
+
* ```
|
|
1783
|
+
* const userRef = session.user("test");
|
|
1784
|
+
* const sub = userRef.subscribe(snapshot => console.log(snapshot));
|
|
1785
|
+
* await sub.connected;
|
|
1786
|
+
*
|
|
1787
|
+
* // Changing the user's name emits a snapshot and triggers the `console.log`
|
|
1788
|
+
* await userRef.set({ name: "Bob" });
|
|
1789
|
+
*
|
|
1600
1790
|
* @param id - The ID of the user that you want to reference
|
|
1601
1791
|
* @returns A {@linkcode UserRef} for the user with that ID
|
|
1602
1792
|
* @public
|
|
@@ -1605,6 +1795,30 @@ export declare interface TalkSession {
|
|
|
1605
1795
|
/**
|
|
1606
1796
|
* Get a reference to a conversation
|
|
1607
1797
|
*
|
|
1798
|
+
* @remarks
|
|
1799
|
+
* This is the entry-point for all conversation-related operations.
|
|
1800
|
+
* This includes operations affecting conversation attributes, but also anything related to messages and participants.
|
|
1801
|
+
*
|
|
1802
|
+
* @example Ensure that the conversation exists and you are a participant
|
|
1803
|
+
* ```
|
|
1804
|
+
* session.conversation("test").createIfNotExists();
|
|
1805
|
+
* ```
|
|
1806
|
+
*
|
|
1807
|
+
* @example Set the conversation's subject
|
|
1808
|
+
* ```
|
|
1809
|
+
* session.conversation("test").set({ subject: "Power tools" });
|
|
1810
|
+
* ```
|
|
1811
|
+
*
|
|
1812
|
+
* @example Stop receiving notifications for this conversation
|
|
1813
|
+
* ```
|
|
1814
|
+
* session.conversation("test").set({ notify: false });
|
|
1815
|
+
* ```
|
|
1816
|
+
*
|
|
1817
|
+
* @example Send a message
|
|
1818
|
+
* ```
|
|
1819
|
+
* session.conversation("test").send("Hello");
|
|
1820
|
+
* ```
|
|
1821
|
+
*
|
|
1608
1822
|
* @param id - The ID of the conversation that you want to reference
|
|
1609
1823
|
* @returns A {@linkcode ConversationRef} for the conversation with that ID
|
|
1610
1824
|
* @public
|
|
@@ -1692,7 +1906,7 @@ export declare interface TalkSessionOptions {
|
|
|
1692
1906
|
*
|
|
1693
1907
|
* Then this would become a Text Block with the structure:
|
|
1694
1908
|
*
|
|
1695
|
-
* ```
|
|
1909
|
+
* ```json
|
|
1696
1910
|
* {
|
|
1697
1911
|
* type: "text",
|
|
1698
1912
|
* children: [
|
|
@@ -1730,7 +1944,7 @@ export declare interface TextBlock {
|
|
|
1730
1944
|
* The simplest `TextNode` is a plain text string.
|
|
1731
1945
|
* Using "hello" as an example message, the `TextBlock` would be:
|
|
1732
1946
|
*
|
|
1733
|
-
* ```
|
|
1947
|
+
* ```ts
|
|
1734
1948
|
* {
|
|
1735
1949
|
* type: 'text';
|
|
1736
1950
|
* children: ['hello'];
|
|
@@ -1739,7 +1953,7 @@ export declare interface TextBlock {
|
|
|
1739
1953
|
*
|
|
1740
1954
|
* Other than plain text, there are many different kinds of node which render some text in a specific way or with certain formatting.
|
|
1741
1955
|
*
|
|
1742
|
-
* ```
|
|
1956
|
+
* ```ts
|
|
1743
1957
|
* type TextNode =
|
|
1744
1958
|
* | string
|
|
1745
1959
|
* | MarkupNode
|
|
@@ -1761,6 +1975,106 @@ export declare interface TextBlock {
|
|
|
1761
1975
|
*/
|
|
1762
1976
|
export declare type TextNode = string | MarkupNode | BulletListNode | BulletPointNode | CodeSpanNode | LinkNode | AutoLinkNode | ActionLinkNode | ActionButtonNode | CustomEmojiNode | MentionNode;
|
|
1763
1977
|
|
|
1978
|
+
/**
|
|
1979
|
+
* The state of a typing subscription when it is actively listening for changes
|
|
1980
|
+
*
|
|
1981
|
+
* @public
|
|
1982
|
+
*/
|
|
1983
|
+
export declare interface TypingActiveState {
|
|
1984
|
+
type: "active";
|
|
1985
|
+
/**
|
|
1986
|
+
* The most recently received typing indicator snapshot, or `null` if you are not a participant in the conversation (including when the conversation does not exist).
|
|
1987
|
+
*/
|
|
1988
|
+
latestSnapshot: TypingSnapshot | null;
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* A snapshot of the typing indicators in a conversation at a given moment in time.
|
|
1993
|
+
* Will be either {@link FewTypingSnapshot} when only a few people are typing, or {@link ManyTypingSnapshot} when many people are typing.
|
|
1994
|
+
*
|
|
1995
|
+
* @remarks
|
|
1996
|
+
* Currently {@link FewTypingSnapshot} is used when there are 5 or less people typing in the conversation, and {@link ManyTypingSnapshot} is used when more than 5 people are typing.
|
|
1997
|
+
* This limit may change in the future, which will not be considered a breaking change.
|
|
1998
|
+
*
|
|
1999
|
+
* @example Converting a TypingSnapshot to text
|
|
2000
|
+
* ```ts
|
|
2001
|
+
* function formatTyping(snapshot: TypingSnapshot): string {
|
|
2002
|
+
* if (snapshot.many) {
|
|
2003
|
+
* return "Several people are typing";
|
|
2004
|
+
* }
|
|
2005
|
+
*
|
|
2006
|
+
* const names = snapshot.users.map(user => user.name);
|
|
2007
|
+
*
|
|
2008
|
+
* if (names.length === 0) {
|
|
2009
|
+
* return "";
|
|
2010
|
+
* }
|
|
2011
|
+
*
|
|
2012
|
+
* if (names.length === 1) {
|
|
2013
|
+
* return names[0] + " is typing";
|
|
2014
|
+
* }
|
|
2015
|
+
*
|
|
2016
|
+
* if (names.length === 2) {
|
|
2017
|
+
* return names.join(" and ") + " are typing";
|
|
2018
|
+
* }
|
|
2019
|
+
*
|
|
2020
|
+
* // Prefix last name with "and "
|
|
2021
|
+
* names.push("and " + names.pop());
|
|
2022
|
+
* return names.join(", ") + " are typing";
|
|
2023
|
+
* }
|
|
2024
|
+
* ```
|
|
2025
|
+
*/
|
|
2026
|
+
export declare type TypingSnapshot = FewTypingSnapshot | ManyTypingSnapshot;
|
|
2027
|
+
|
|
2028
|
+
/**
|
|
2029
|
+
* A subscription to the typing status in a specific conversation
|
|
2030
|
+
*
|
|
2031
|
+
* @remarks
|
|
2032
|
+
* Get a TypingSubscription by calling {@link ConversationRef.subscribeTyping}.
|
|
2033
|
+
*
|
|
2034
|
+
* When there are "many" people typing (meaning you received {@link ManyTypingSnapshot}), the next update you receive will be {@link FewTypingSnapshot} once enough people stop typing.
|
|
2035
|
+
* Until then, your {@link ManyTypingSnapshot} is still valid and doesn not need to changed, so `onSnapshot` will not be called.
|
|
2036
|
+
*
|
|
2037
|
+
* @public
|
|
2038
|
+
*/
|
|
2039
|
+
export declare interface TypingSubscription {
|
|
2040
|
+
/**
|
|
2041
|
+
* The current state of the subscription
|
|
2042
|
+
*
|
|
2043
|
+
* @remarks
|
|
2044
|
+
* An object with the following fields:
|
|
2045
|
+
*
|
|
2046
|
+
* `type` is one of "pending", "active", "unsubscribed", or "error".
|
|
2047
|
+
*
|
|
2048
|
+
* When `type` is "active", includes `latestSnapshot: TypingSnapshot | null`. It is the current state of the typing indicators, or null if you're not a participant in the conversation
|
|
2049
|
+
*
|
|
2050
|
+
* When `type` is "error", includes the `error: Error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
|
|
2051
|
+
*/
|
|
2052
|
+
state: PendingState | TypingActiveState | UnsubscribedState | ErrorState;
|
|
2053
|
+
/**
|
|
2054
|
+
* Resolves when the subscription starts receiving updates from the server.
|
|
2055
|
+
*
|
|
2056
|
+
* @remarks
|
|
2057
|
+
* Wait for this promise if you want to perform some action as soon as the subscription is active.
|
|
2058
|
+
*
|
|
2059
|
+
* The promise rejects if the subscription is terminated before it connects.
|
|
2060
|
+
*/
|
|
2061
|
+
connected: Promise<TypingActiveState>;
|
|
2062
|
+
/**
|
|
2063
|
+
* Resolves when the subscription permanently stops receiving updates from the server.
|
|
2064
|
+
*
|
|
2065
|
+
* @remarks
|
|
2066
|
+
* This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
|
|
2067
|
+
*/
|
|
2068
|
+
terminated: Promise<UnsubscribedState | ErrorState>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Unsubscribe from this resource and stop receiving updates.
|
|
2071
|
+
*
|
|
2072
|
+
* @remarks
|
|
2073
|
+
* If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
|
|
2074
|
+
*/
|
|
2075
|
+
unsubscribe(): void;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
1764
2078
|
/**
|
|
1765
2079
|
* The state of a subscription after you have manually unsubscribed
|
|
1766
2080
|
*
|
|
@@ -1787,7 +2101,7 @@ export declare interface UserActiveState {
|
|
|
1787
2101
|
* References the user with a given user ID.
|
|
1788
2102
|
*
|
|
1789
2103
|
* @remarks
|
|
1790
|
-
* Used in all
|
|
2104
|
+
* Used in all Data API operations affecting that user, such as creating the user, fetching or updating user data, or adding a user to a conversation.
|
|
1791
2105
|
* Created via {@link Session.user}.
|
|
1792
2106
|
*
|
|
1793
2107
|
* @public
|
|
@@ -1808,7 +2122,7 @@ export declare interface UserRef {
|
|
|
1808
2122
|
* Fetching a user snapshot doesn't require any permissions. You can read the public information of any user.
|
|
1809
2123
|
* Private information, such as email addresses and phone numbers, aren't included in the response.
|
|
1810
2124
|
*
|
|
1811
|
-
* Supports {@link https://talkjs.com/docs/Reference/
|
|
2125
|
+
* Supports {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/Performance/#automatic-batching | Automatic Batching} and {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/Performance/#cached-fetch | Cached Fetch}
|
|
1812
2126
|
*
|
|
1813
2127
|
* @returns A snapshot of the user's public attributes, or null if the user doesn't exist.
|
|
1814
2128
|
*/
|
|
@@ -1837,8 +2151,6 @@ export declare interface UserRef {
|
|
|
1837
2151
|
* @remarks
|
|
1838
2152
|
* Whenever `Subscription.state.type` is "active" and the user is created or their attributes change, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
|
|
1839
2153
|
*
|
|
1840
|
-
* Supports {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#subscription-sharing | Subscription Sharing} and {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#debounced-unsubscribe | Debounced Unsubscribe}
|
|
1841
|
-
*
|
|
1842
2154
|
* @returns A subscription to the user
|
|
1843
2155
|
*/
|
|
1844
2156
|
subscribe(onSnapshot?: (event: UserSnapshot | null) => void): UserSubscription;
|
|
@@ -1978,7 +2290,7 @@ export declare interface VideoBlock {
|
|
|
1978
2290
|
duration?: number;
|
|
1979
2291
|
}
|
|
1980
2292
|
|
|
1981
|
-
declare interface VideoFileMetadata {
|
|
2293
|
+
export declare interface VideoFileMetadata {
|
|
1982
2294
|
/**
|
|
1983
2295
|
* The name of the file including extension.
|
|
1984
2296
|
*/
|
|
@@ -2041,7 +2353,7 @@ export declare interface VoiceBlock {
|
|
|
2041
2353
|
duration?: number;
|
|
2042
2354
|
}
|
|
2043
2355
|
|
|
2044
|
-
declare interface VoiceRecordingFileMetadata {
|
|
2356
|
+
export declare interface VoiceRecordingFileMetadata {
|
|
2045
2357
|
/**
|
|
2046
2358
|
* The name of the file including extension.
|
|
2047
2359
|
*/
|