@talkjs/core 0.0.5 → 1.0.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.
@@ -0,0 +1,2055 @@
1
+ /**
2
+ * A node in a {@link TextBlock} that renders its children as a clickable {@link https://talkjs.com/docs/Features/Customizations/Action_Buttons_Links/ | action button} which triggers a custom action.
3
+ *
4
+ * @remarks
5
+ * By default, users do not have permission to send messages containing action buttons as they can be used maliciously to trick others into invoking custom actions.
6
+ * For example, a user could send an "accept offer" action button, but disguise it as "view offer".
7
+ *
8
+ * @public
9
+ */
10
+ export declare interface ActionButtonNode {
11
+ type: "actionButton";
12
+ /**
13
+ * The name of the custom action to invoke when the button is clicked.
14
+ */
15
+ action: string;
16
+ /**
17
+ * The parameters to pass to the custom action when the button is clicked.
18
+ */
19
+ params: Record<string, string>;
20
+ children: TextNode[];
21
+ }
22
+
23
+ /**
24
+ * A node in a {@link TextBlock} that renders its children as a clickable {@link https://talkjs.com/docs/Features/Customizations/Action_Buttons_Links/ | action link} which triggers a custom action.
25
+ *
26
+ * @remarks
27
+ * By default, users do not have permission to send messages containing `ActionLinkNode` as it can be used maliciously to trick others into invoking custom actions.
28
+ * For example, a user could send an "accept offer" action link, but disguise it as a link to a website.
29
+ *
30
+ * @public
31
+ */
32
+ export declare interface ActionLinkNode {
33
+ type: "actionLink";
34
+ /**
35
+ * The name of the custom action to invoke when the link is clicked.
36
+ */
37
+ action: string;
38
+ /**
39
+ * The parameters to pass to the custom action when the link is clicked.
40
+ */
41
+ params: Record<string, string>;
42
+ children: TextNode[];
43
+ }
44
+
45
+ /**
46
+ * A FileBlock variant for an audio attachment, with additional audio-specific metadata.
47
+ *
48
+ * @remarks
49
+ * You can identify this variant by checking for `subtype: "audio"`.
50
+ *
51
+ * The same file could be uploaded as either an audio block, or as a {@link VoiceBlock}.
52
+ * The same data will be available either way, but they will be rendered differently in the UI.
53
+ *
54
+ * Includes metadata about the duration of the audio file in seconds, where available.
55
+ *
56
+ * Audio files that you upload with the TalkJS UI will include the duration as long as the sender's browser can preview the file.
57
+ * Audio files that you upload with the REST API or {@link Session.uploadAudio} will include the duration if you specified it when uploading.
58
+ * Audio files attached in a reply to an email notification will not include the duration.
59
+ *
60
+ * @public
61
+ */
62
+ export declare interface AudioBlock {
63
+ type: "file";
64
+ subtype: "audio";
65
+ /**
66
+ * An encoded identifier for this file. Use in {@link SendFileBlock} to send this file in another message.
67
+ */
68
+ fileToken: FileToken;
69
+ /**
70
+ * The URL where you can fetch the file
71
+ */
72
+ url: string;
73
+ /**
74
+ * The size of the file in bytes
75
+ */
76
+ size: number;
77
+ /**
78
+ * The name of the audio file, including file extension
79
+ */
80
+ filename: string;
81
+ /**
82
+ * The duration of the audio in seconds, if known
83
+ */
84
+ duration?: number;
85
+ }
86
+
87
+ declare interface AudioFileMetadata {
88
+ /**
89
+ * The name of the file including extension.
90
+ */
91
+ filename: string;
92
+ /**
93
+ * The duration of the audio file in seconds, if known.
94
+ */
95
+ duration?: number;
96
+ }
97
+
98
+ /**
99
+ * A node in a {@link TextBlock} that renders `text` as a link (HTML `<a>`).
100
+ *
101
+ * @remarks
102
+ * Used when user-typed text is turned into a link automatically.
103
+ *
104
+ * Unlike {@link LinkNode}, users do have permission to send AutoLinkNodes by default, because the `text` and `url` properties must match.
105
+ * Specifically:
106
+ *
107
+ * - If `text` is an email, `url` must contain a `mailto:` link to the same email address
108
+ *
109
+ * - If `text` is a phone number, `url` must contain a `tel:` link to the same phone number
110
+ *
111
+ * - If `text` is a website, the domain name including subdomains must be the same in both `text` and `url`.
112
+ * If `text` includes a protocol (such as `https`), path (/page), query string (?page=true), or url fragment (#title), they must be the same in `url`.
113
+ * If `text` does not specify a protocol, `url` must use either `https` or `http`.
114
+ *
115
+ * This means that the following AutoLink is valid:
116
+ *
117
+ * ```
118
+ * {
119
+ * type: "autoLink",
120
+ * text: "talkjs.com"
121
+ * url: "https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#AutoLinkNode"
122
+ * }
123
+ * ```
124
+ *
125
+ * That link will appear as `talkjs.com` and link you to the specific section of the documentation that explains how AutoLinkNodes work.
126
+ *
127
+ * These rules ensure that the user knows what link they are clicking, and prevents AutoLinkNode being used for phishing.
128
+ * If you try to send a message containing an AutoLink that breaks these rules, the request will be rejected.
129
+ *
130
+ * @public
131
+ */
132
+ export declare interface AutoLinkNode {
133
+ type: "autoLink";
134
+ /**
135
+ * The URL to open when a user clicks this node.
136
+ */
137
+ url: string;
138
+ /**
139
+ * The text to display in the link.
140
+ */
141
+ text: string;
142
+ }
143
+
144
+ /**
145
+ * A node in a {@link TextBlock} that adds indentation for a bullet-point list around its children (HTML `<ul>`).
146
+ *
147
+ * @remarks
148
+ * Used when users send a bullet-point list by starting lines of their message with `-` or `*`.
149
+ *
150
+ * @public
151
+ */
152
+ export declare interface BulletListNode {
153
+ type: "bulletList";
154
+ children: TextNode[];
155
+ }
156
+
157
+ /**
158
+ * A node in a {@link TextBlock} that renders its children with a bullet-point (HTML `<li>`).
159
+ *
160
+ * @remarks
161
+ * Used when users start a line of their message with `-` or `*`.
162
+ *
163
+ * @public
164
+ */
165
+ export declare interface BulletPointNode {
166
+ type: "bulletPoint";
167
+ children: TextNode[];
168
+ }
169
+
170
+ /**
171
+ * A node in a {@link TextBlock} that renders `text` in an inline code span (HTML `<code>`).
172
+ *
173
+ * @remarks
174
+ * Used when a user types ```text```.
175
+ *
176
+ * @public
177
+ */
178
+ export declare interface CodeSpanNode {
179
+ type: "codeSpan";
180
+ text: string;
181
+ }
182
+
183
+ /**
184
+ * The content of a message is structured as a list of content blocks.
185
+ *
186
+ * @remarks
187
+ * Currently, each message can only have one content block, but this will change in the future.
188
+ * This will not be considered a breaking change, so your code should assume there can be multiple content blocks.
189
+ *
190
+ * These blocks are rendered in order, top-to-bottom.
191
+ *
192
+ * Currently the available Content Block types are:
193
+ *
194
+ * - `type: "text"` ({@link TextBlock})
195
+ *
196
+ * - `type: "file"` ({@link FileBlock})
197
+ *
198
+ * - `type: "location"` ({@link LocationBlock})
199
+ *
200
+ * @public
201
+ */
202
+ export declare type ContentBlock = TextBlock | FileBlock | LocationBlock;
203
+
204
+ /**
205
+ * The state of a conversation subscription when it is actively listening for changes
206
+ *
207
+ * @public
208
+ */
209
+ export declare interface ConversationActiveState {
210
+ type: "active";
211
+ /**
212
+ * The most recently received snapshot for the conversation, or `null` if you are not a participant in the conversation (including when the conversation does not exist).
213
+ */
214
+ latestSnapshot: ConversationSnapshot | null;
215
+ }
216
+
217
+ /**
218
+ * References the conversation with a given conversation ID, from the perspective of the current user.
219
+ *
220
+ * @remarks
221
+ * Used in all Realtime API operations affecting that conversation, such as fetching or updating conversation attributes.
222
+ * Created via {@link Session.conversation}.
223
+ *
224
+ * @public
225
+ */
226
+ export declare interface ConversationRef {
227
+ /**
228
+ * The ID of the referenced conversation.
229
+ *
230
+ * @remarks
231
+ * Immutable: if you want to reference a different conversation, get a new ConversationRef instead.
232
+ */
233
+ readonly id: string;
234
+ /**
235
+ * Get a reference to a participant in this conversation
236
+ *
237
+ * @param user - the user's ID or a reference to the user
238
+ */
239
+ participant(user: string | UserRef): ParticipantRef;
240
+ /**
241
+ * Get a reference to a message in this conversation
242
+ *
243
+ * @param user - the message ID
244
+ */
245
+ message(id: string): MessageRef;
246
+ /**
247
+ * Fetches a snapshot of the conversation.
248
+ *
249
+ * @remarks
250
+ * This contains all of the information related to the conversation and the current user's participation in the conversation.
251
+ *
252
+ * @returns A snapshot of the current user's view of the conversation, or null if the current user is not a participant (including if the conversation doesn't exist).
253
+ */
254
+ get(): Promise<ConversationSnapshot | null>;
255
+ /**
256
+ * Sets properties of this conversation and your participation in it.
257
+ *
258
+ * @remarks
259
+ * The conversation is created if a conversation with this ID doesn't already exist.
260
+ * You are added as a participant if you are not already a participant in the conversation.
261
+ *
262
+ * @returns A promise that resolves when the operation completes.
263
+ * When client-side conversation syncing is disabled, you may only set your `notify` property, when you are already a participant.
264
+ * Everything else requires client-side conversation syncing to be enabled, and will cause the promise to reject.
265
+ */
266
+ set(params: SetConversationParams): Promise<void>;
267
+ /**
268
+ * Creates this conversation if it does not already exist.
269
+ * Adds you as a participant in this conversation, if you are not already a participant.
270
+ *
271
+ * @remarks
272
+ * If the conversation already exists or you are already a participant, this operation is still considered successful and the promise will still resolve.
273
+ *
274
+ * @returns A promise that resolves when the operation completes. The promise rejects if you are not already a participant and client-side conversation syncing is disabled.
275
+ */
276
+ createIfNotExists(params?: CreateConversationParams): Promise<void>;
277
+ /**
278
+ * Marks the conversation as read.
279
+ *
280
+ * @returns A promise that resolves when the operation completes. The promise rejects if you are not a participant in the conversation.
281
+ */
282
+ markAsRead(): Promise<void>;
283
+ /**
284
+ * Marks the conversation as unread.
285
+ *
286
+ * @returns A promise that resolves when the operation completes. The promise rejects if you are not a participant in the conversation.
287
+ */
288
+ markAsUnread(): Promise<void>;
289
+ /**
290
+ * Sends a message in the conversation
291
+ *
292
+ * @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
+ */
294
+ send(params: string | SendTextMessageParams | SendMessageParams): Promise<MessageRef>;
295
+ /**
296
+ * Subscribes to the messages in the conversation.
297
+ *
298
+ * @remarks
299
+ * Initially, you will be subscribed to the 30 most recent messages and any new messages.
300
+ * Call `loadMore` to load additional older messages.
301
+ *
302
+ * Whenever `Subscription.state.type` is "active" and a message is sent, edited, deleted, or you load more messages, `onSnapshot` will fire and `Subscription.state.latestSnapshot` will be updated.
303
+ * `loadedAll` is true when the snapshot contains all the messages in the conversation.
304
+ *
305
+ * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
306
+ */
307
+ subscribeMessages(onSnapshot?: (snapshot: MessageSnapshot[] | null, loadedAll: boolean) => void): MessageSubscription;
308
+ /**
309
+ * Subscribes to the conversation.
310
+ *
311
+ * @remarks
312
+ * 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 if `snapshot.lastMessage.referencedMessage.sender.name` changes.
314
+ *
315
+ * The snapshot is null if you are not a participant in the conversation (including when the conversation doesn't exist)
316
+ */
317
+ subscribe(onSnapshot?: (snapshot: ConversationSnapshot | null) => void): ConversationSubscription;
318
+ }
319
+
320
+ /**
321
+ * A snapshot of a conversation's attributes at a given moment in time.
322
+ *
323
+ * @remarks
324
+ * Also includes information about the current user's view of that conversation, such as whether or not notifications are enabled.
325
+ *
326
+ * Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
327
+ *
328
+ * @public
329
+ */
330
+ export declare interface ConversationSnapshot {
331
+ /**
332
+ * The ID of the conversation
333
+ */
334
+ id: string;
335
+ /**
336
+ * Contains the conversation subject if it was set using {@link ConversationBuilder.subject}.
337
+ */
338
+ subject: string | null;
339
+ /**
340
+ * Contains the URL of a photo was set using {@link ConversationBuilder.subject}.
341
+ */
342
+ photoUrl: string | null;
343
+ /**
344
+ * One or more welcome messages that will display to the user as a SystemMessage
345
+ */
346
+ welcomeMessages: string[];
347
+ /**
348
+ * Custom metadata you have set on the conversation
349
+ */
350
+ custom: Record<string, string>;
351
+ /**
352
+ * The date that the conversation was created, as a unix timestamp in milliseconds.
353
+ */
354
+ createdAt: number;
355
+ /**
356
+ * The date that the current user joined the conversation, as a unix timestamp in milliseconds.
357
+ */
358
+ joinedAt: number;
359
+ /**
360
+ * The last message sent in this conversation, or null if no messages have been sent.
361
+ */
362
+ lastMessage: MessageSnapshot | null;
363
+ /**
364
+ * The number of messages in this conversation that the current user hasn't read.
365
+ */
366
+ unreadMessageCount: number;
367
+ /**
368
+ * Timestamp of when the current user read a message
369
+ */
370
+ readUntil: number;
371
+ /**
372
+ * Whether the conversation should be considered unread.
373
+ *
374
+ * @remarks
375
+ * This can be true even when `unreadMessageCount` is zero, if the user has manually marked the conversation as unread.
376
+ */
377
+ isUnread: boolean;
378
+ /**
379
+ * The current user's permission level in this conversation.
380
+ */
381
+ access: "Read" | "ReadWrite";
382
+ /**
383
+ * The current user's notification settings for this conversation.
384
+ *
385
+ * @remarks
386
+ * `false` means no notifications, `true` means notifications for all messages, and `"MentionsOnly"` means that the user will only be notified when they are mentioned with an `@`.
387
+ */
388
+ notify: boolean | "MentionsOnly";
389
+ }
390
+
391
+ /**
392
+ * A subscription to a specific conversation.
393
+ *
394
+ * @remarks
395
+ * Get a ConversationSubscription by calling {@link ConversationRef.subscribe}
396
+ *
397
+ * @public
398
+ */
399
+ export declare interface ConversationSubscription {
400
+ /**
401
+ * The current state of the subscription
402
+ *
403
+ * @remarks
404
+ * An object with the following fields:
405
+ *
406
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
407
+ *
408
+ * When `type` is "active", includes `latestSnapshot: ConversationSnapshot | null`, the current state of the conversation.
409
+ * `latestSnapshot` is `null` when you are not a participant or the conversation does not exist.
410
+ *
411
+ * When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
412
+ */
413
+ state: PendingState | ConversationActiveState | UnsubscribedState | ErrorState;
414
+ /**
415
+ * Resolves when the subscription starts receiving updates from the server.
416
+ */
417
+ connected: Promise<ConversationActiveState>;
418
+ /**
419
+ * Resolves when the subscription permanently stops receiving updates from the server.
420
+ *
421
+ * @remarks
422
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
423
+ */
424
+ terminated: Promise<UnsubscribedState | ErrorState>;
425
+ /**
426
+ * Unsubscribe from this resource and stop receiving updates.
427
+ *
428
+ * @remarks
429
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
430
+ */
431
+ unsubscribe(): void;
432
+ }
433
+
434
+ /**
435
+ * Parameters you can pass to {@link ConversationRef.createIfNotExists}.
436
+ *
437
+ * Properties that are `undefined` will be set to the default.
438
+ *
439
+ * @public
440
+ */
441
+ export declare interface CreateConversationParams {
442
+ /**
443
+ * The conversation subject to display in the chat header.
444
+ * Default = no subject, list participant names instead.
445
+ */
446
+ subject?: string;
447
+ /**
448
+ * The URL for the conversation photo to display in the chat header.
449
+ * Default = no photo, show a placeholder image.
450
+ */
451
+ photoUrl?: string;
452
+ /**
453
+ * System messages which are sent at the beginning of a conversation.
454
+ * Default = no messages.
455
+ */
456
+ welcomeMessages?: string[];
457
+ /**
458
+ * Custom metadata you have set on the conversation.
459
+ * This value acts as a patch. Remove specific properties by setting them to `null`.
460
+ * Default = no custom metadata
461
+ */
462
+ custom?: Record<string, string>;
463
+ /**
464
+ * Your access to the conversation.
465
+ * Default = "ReadWrite" access.
466
+ */
467
+ access?: "Read" | "ReadWrite";
468
+ /**
469
+ * Your notification settings.
470
+ * Default = `true`
471
+ */
472
+ notify?: boolean | "MentionsOnly";
473
+ }
474
+
475
+ /**
476
+ * Parameters you can pass to {@link ParticipantRef.createIfNotExists}.
477
+ *
478
+ * @remarks
479
+ * Properties that are `undefined` will be set to the default.
480
+ *
481
+ * @public
482
+ */
483
+ export declare interface CreateParticipantParams {
484
+ /**
485
+ * The level of access the participant should have in the conversation.
486
+ * Default = "ReadWrite" access.
487
+ */
488
+ access?: "ReadWrite" | "Read";
489
+ /**
490
+ * When the participant should be notified about new messages in this conversation.
491
+ * Default = `true`
492
+ *
493
+ * @remarks
494
+ * `false` means no notifications, `true` means notifications for all messages, and `"MentionsOnly"` means that the user will only be notified when they are mentioned with an `@`.
495
+ */
496
+ notify?: boolean | "MentionsOnly";
497
+ }
498
+
499
+ /**
500
+ * Parameters you can pass to {@link UserRef.createIfNotExists}.
501
+ *
502
+ * @remarks
503
+ * Properties that are `undefined` will be set to the default.
504
+ *
505
+ * @public
506
+ */
507
+ export declare interface CreateUserParams {
508
+ /**
509
+ * The user's name which is displayed on the TalkJS UI
510
+ */
511
+ name: string;
512
+ /**
513
+ * Custom metadata you have set on the user.
514
+ * Default = no custom metadata
515
+ */
516
+ custom?: Record<string, string>;
517
+ /**
518
+ * An {@link https://www.w3.org/International/articles/language-tags/ | IETF language tag}.
519
+ * See the {@link https://talkjs.com/docs/Features/Language_Support/Localization.html | localization documentation}
520
+ * Default = the locale selected on the dashboard
521
+ */
522
+ locale?: string;
523
+ /**
524
+ * An optional URL to a photo that is displayed as the user's avatar.
525
+ * Default = no photo
526
+ */
527
+ photoUrl?: string;
528
+ /**
529
+ * TalkJS supports multiple sets of settings, called "roles". These allow you to change the behavior of TalkJS for different users.
530
+ * You have full control over which user gets which configuration.
531
+ * Default = the `default` role
532
+ */
533
+ role?: string;
534
+ /**
535
+ * The default message a person sees when starting a chat with this user.
536
+ * Default = no welcome message
537
+ */
538
+ welcomeMessage?: string;
539
+ /**
540
+ * A single email address or an array of email addresses associated with the user.
541
+ * Default = no email addresses
542
+ */
543
+ email?: string | string[];
544
+ /**
545
+ * A single phone number or an array of phone numbers associated with the user.
546
+ * Default = no phone numbers
547
+ */
548
+ phone?: string | string[];
549
+ /**
550
+ * An object of push registration tokens to use when notifying this user.
551
+ *
552
+ * Keys in the object have the format `'provider:token_id'`,
553
+ * where `provider` is either `"fcm"` for Android (Firebase Cloud Messaging),
554
+ * or `"apns"` for iOS (Apple Push Notification Service).
555
+ *
556
+ * Default = no push registration tokens
557
+ */
558
+ pushTokens?: Record<string, true>;
559
+ }
560
+
561
+ /**
562
+ * A node in a {@link TextBlock} that is used for {@link https://talkjs.com/docs/Features/Message_Features/Emoji_Reactions/#custom-emojis | custom emoji}.
563
+ *
564
+ * @public
565
+ */
566
+ export declare interface CustomEmojiNode {
567
+ type: "customEmoji";
568
+ /**
569
+ * The name of the custom emoji to show.
570
+ */
571
+ text: string;
572
+ }
573
+
574
+ /**
575
+ * Parameters you can pass to {@link MessageRef.edit}.
576
+ *
577
+ * @remarks
578
+ * Properties that are `undefined` will not be changed.
579
+ * To clear / reset a property to the default, pass `null`.
580
+ *
581
+ * This is the more advanced method for editing a message. It gives you full control over the message content.
582
+ * You can decide exactly how a text message should be formatted, edit an attachment, or even turn a text message into a location.
583
+ *
584
+ * @public
585
+ */
586
+ export declare interface EditMessageParams {
587
+ /**
588
+ * Custom metadata you have set on the message.
589
+ * This value acts as a patch. Remove specific properties by setting them to `null`.
590
+ * Default = no custom metadata
591
+ */
592
+ custom?: Record<string, string | null> | null;
593
+ /**
594
+ * The new content for the message.
595
+ *
596
+ * @remarks
597
+ * Any value provided here will overwrite the existing message content.
598
+ *
599
+ * 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.
600
+ */
601
+ content?: [SendContentBlock];
602
+ }
603
+
604
+ /**
605
+ * Parameters you can pass to {@link MessageRef.edit}.
606
+ *
607
+ * @remarks
608
+ * Properties that are `undefined` will not be changed.
609
+ * To clear / reset a property to the default, pass `null`.
610
+ *
611
+ * This is a simpler version of {@link EditMessageParams} that only supports setting the message content to text.
612
+ *
613
+ * @public
614
+ */
615
+ export declare interface EditTextMessageParams {
616
+ /**
617
+ * Custom metadata you have set on the message.
618
+ * This value acts as a patch. Remove specific properties by setting them to `null`.
619
+ * Default = no custom metadata
620
+ */
621
+ custom?: Record<string, string | null> | null;
622
+ /**
623
+ * The new text to set in the message body.
624
+ *
625
+ * @remarks
626
+ * This is parsed the same way as the text entered in the message field. For example, `*hi*` will appear as `hi` in bold.
627
+ *
628
+ * See the {@link https://talkjs.com/docs/Features/Message_Features/Formatting/ | message formatting documentation} for more details.
629
+ */
630
+ text?: string;
631
+ }
632
+
633
+ /**
634
+ * The state of a subscription after it encounters an unrecoverable error
635
+ *
636
+ * @public
637
+ */
638
+ export declare interface ErrorState {
639
+ type: "error";
640
+ /**
641
+ * The error that caused the subscription to be terminated
642
+ */
643
+ error: Error;
644
+ }
645
+
646
+ /**
647
+ * A file attachment received in a message's content.
648
+ *
649
+ * @remarks
650
+ * All `FileBlock` variants contain `url`, `size`, and `fileToken`.
651
+ * Some file blocks have additional metadata, in which case they will have the `subtype` property set.
652
+ *
653
+ * Currently the available FileBlock subtypes are:
654
+ *
655
+ * - No `subtype` set ({@link GenericFileBlock})
656
+ *
657
+ * - `subtype: "video"` ({@link VideoBlock})
658
+ *
659
+ * - `subtype: "image"` ({@link ImageBlock})
660
+ *
661
+ * - `subtype: "audio"` ({@link AudioBlock})
662
+ *
663
+ * - `subtype: "voice"` ({@link VoiceBlock})
664
+ *
665
+ * @public
666
+ */
667
+ export declare type FileBlock = VideoBlock | ImageBlock | AudioBlock | VoiceBlock | GenericFileBlock;
668
+
669
+ /**
670
+ * A token representing a file uploaded to TalkJS.
671
+ *
672
+ * @remarks
673
+ * 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}.
674
+ *
675
+ * For example:
676
+ *
677
+ * ```
678
+ * // From `<input type="file">`
679
+ * const file: File = fileInputElement.files[0];
680
+ * 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
+ *
685
+ * You can also upload files using the {@link https://talkjs.com/docs/Reference/REST_API/Messages/#1-upload-a-file| REST API}.
686
+ *
687
+ * Passed in {@link SendFileBlock} when you send a message containing a file attachment:
688
+ *
689
+ * ```
690
+ * const block: SendFileBlock = {
691
+ * type: 'file',
692
+ * fileToken: myFileToken,
693
+ * };
694
+ *
695
+ * const convRef = session.conversation('example_conversation_id');
696
+ * convRef.send({ content: [block] });
697
+ * ```
698
+ *
699
+ * We may change the FileToken format in the future.
700
+ * Do not store old file tokens for future use, as these may stop working.
701
+ *
702
+ * This system ensures that all files must be uploaded to TalkJS before being sent to users, limiting the risk of malware.
703
+ *
704
+ * @public
705
+ */
706
+ export declare type FileToken = string & {
707
+ __tag: Record<"TalkJS Encoded File Token", true>;
708
+ };
709
+
710
+ /**
711
+ * The most basic FileBlock variant, used whenever there is no additional metadata for a file.
712
+ *
713
+ * @remarks
714
+ * Do not try to check for `subtype === undefined` directly, as this will break when we add new FileBlock variants in the future.
715
+ *
716
+ * Instead, treat GenericFileBlock as the default. For example:
717
+ *
718
+ * ```
719
+ * if (block.subtype === "video") {
720
+ * handleVideoBlock(block);
721
+ * } else if (block.subtype === "image") {
722
+ * handleImageBlock(block);
723
+ * } else if (block.subtype === "audio") {
724
+ * handleAudioBlock(block);
725
+ * } else if (block.subtype === "voice") {
726
+ * handleVoiceBlock(block);
727
+ * } else {
728
+ * handleGenericFileBlock(block);
729
+ * }
730
+ * ```
731
+ *
732
+ * @public
733
+ */
734
+ export declare interface GenericFileBlock {
735
+ type: "file";
736
+ /**
737
+ * Never set for generic file blocks.
738
+ */
739
+ subtype?: undefined;
740
+ /**
741
+ * An encoded identifier for this file. Use in {@link SendFileBlock} to send this file in another message.
742
+ */
743
+ fileToken: FileToken;
744
+ /**
745
+ * The URL where you can fetch the file
746
+ */
747
+ url: string;
748
+ /**
749
+ * The size of the file in bytes
750
+ */
751
+ size: number;
752
+ /**
753
+ * The name of the file, including file extension
754
+ */
755
+ filename: string;
756
+ }
757
+
758
+ declare interface GenericFileMetadata {
759
+ /**
760
+ * The name of the file including extension.
761
+ */
762
+ filename: string;
763
+ }
764
+
765
+ /**
766
+ * Returns a TalkSession option for the specified App ID and User ID.
767
+ *
768
+ * @remarks
769
+ * Backed by a registry, so calling this function twice with the same app and user returns the same session object both times.
770
+ * A new session will be created if the old one encountered an error or got garbage collected.
771
+ *
772
+ * The `token` and `tokenFetcher` properties are ignored if there is already a session for that user in the registry.
773
+ */
774
+ export declare function getTalkSession(options: TalkSessionOptions): TalkSession;
775
+
776
+ /**
777
+ * A FileBlock variant for an image attachment, with additional image-specific metadata.
778
+ *
779
+ * @remarks
780
+ * You can identify this variant by checking for `subtype: "image"`.
781
+ *
782
+ * Includes metadata about the height and width of the image in pixels, where available.
783
+ *
784
+ * Images that you upload with the TalkJS UI will include the image dimensions as long as the sender's browser can preview the file.
785
+ * Images that you upload with the REST API or {@link Session.uploadImage} will include the dimensions if you specified them when uploading.
786
+ * Image attached in a reply to an email notification will not include the dimensions.
787
+ *
788
+ * @public
789
+ */
790
+ export declare interface ImageBlock {
791
+ type: "file";
792
+ subtype: "image";
793
+ /**
794
+ * An encoded identifier for this file. Use in {@link SendFileBlock} to send this image in another message.
795
+ */
796
+ fileToken: FileToken;
797
+ /**
798
+ * The URL where you can fetch the file.
799
+ */
800
+ url: string;
801
+ /**
802
+ * The size of the file in bytes.
803
+ */
804
+ size: number;
805
+ /**
806
+ * The name of the image file, including file extension.
807
+ */
808
+ filename: string;
809
+ /**
810
+ * The width of the image in pixels, if known.
811
+ */
812
+ width?: number;
813
+ /**
814
+ * The height of the image in pixels, if known.
815
+ */
816
+ height?: number;
817
+ }
818
+
819
+ declare interface ImageFileMetadata {
820
+ /**
821
+ * The name of the file including extension.
822
+ */
823
+ filename: string;
824
+ /**
825
+ * The width of the image in pixels, if known.
826
+ */
827
+ width?: number;
828
+ /**
829
+ * The height of the image in pixels, if known.
830
+ */
831
+ height?: number;
832
+ }
833
+
834
+ /**
835
+ * A node in a {@link TextBlock} that renders its children as a clickable link (HTML `<a>`).
836
+ *
837
+ * @remarks
838
+ * By default, users do not have permission to send messages containing `LinkNode` as it can be used to maliciously hide the true destination of a link.
839
+ *
840
+ * @public
841
+ */
842
+ export declare interface LinkNode {
843
+ type: "link";
844
+ /**
845
+ * The URL to open when the node is clicked.
846
+ */
847
+ url: string;
848
+ children: TextNode[];
849
+ }
850
+
851
+ /**
852
+ * A block showing a location in the world, typically because a user shared their location in the chat.
853
+ *
854
+ * @remarks
855
+ * In the TalkJS UI, location blocks are rendered as a link to Google Maps, with the map pin showing at the specified coordinate.
856
+ * A thumbnail shows the surrounding area on the map.
857
+ *
858
+ * @public
859
+ */
860
+ export declare interface LocationBlock {
861
+ type: "location";
862
+ /**
863
+ * The north-south coordinate of the location.
864
+ *
865
+ * @remarks
866
+ * Usually listed first in a pair of coordinates.
867
+ *
868
+ * Must be a number between -90 and 90
869
+ */
870
+ latitude: number;
871
+ /**
872
+ * The east-west coordinate of the location.
873
+ *
874
+ * @remarks
875
+ * Usually listed second in a pair of coordinates.
876
+ *
877
+ * Must be a number between -180 and 180
878
+ */
879
+ longitude: number;
880
+ }
881
+
882
+ /**
883
+ * A node in a {@link TextBlock} that renders its children with a specific style.
884
+ *
885
+ * @public
886
+ */
887
+ export declare interface MarkupNode {
888
+ /**
889
+ * The kind of formatting to apply when rendering the children
890
+ *
891
+ * - `type: "bold"` is used when users type `*text*` and is rendered with HTML `<strong>`
892
+ *
893
+ * - `type: "italic"` is used when users type `_text_` and is rendered with HTML `<em>`
894
+ *
895
+ * - `type: "strikethrough"` is used when users type `~text~` and is rendered with HTML `<s>`
896
+ */
897
+ type: "bold" | "italic" | "strikethrough";
898
+ children: TextNode[];
899
+ }
900
+
901
+ /**
902
+ * A node in a {@link TextBlock} that is used when a user is {@link https://talkjs.com/docs/Features/Message_Features/Mentions/ | mentioned}.
903
+ *
904
+ * @remarks
905
+ * Used when a user types `@name` and selects the user they want to mention.
906
+ *
907
+ * @public
908
+ */
909
+ export declare interface MentionNode {
910
+ type: "mention";
911
+ /**
912
+ * The ID of the user who is mentioned.
913
+ */
914
+ id: string;
915
+ /**
916
+ * The name of the user who is mentioned.
917
+ */
918
+ text: string;
919
+ }
920
+
921
+ /**
922
+ * The state of a messages subscription when it is actively listening for changes
923
+ *
924
+ * @public
925
+ */
926
+ export declare interface MessageActiveState {
927
+ type: "active";
928
+ /**
929
+ * The most recently received snapshot for the user, or `null` if the user does not exist yet.
930
+ */
931
+ latestSnapshot: MessageSnapshot[] | null;
932
+ /**
933
+ * True if `latestSnapshot` contains all messages in the conversation.
934
+ * Use `MessageSubscription.loadMore` to load more.
935
+ */
936
+ loadedAll: boolean;
937
+ }
938
+
939
+ /**
940
+ * References the message with a given message ID.
941
+ *
942
+ * @remarks
943
+ * Used in all Realtime API operations affecting that message, such as fetching or editing the message attributes, or deleting the message.
944
+ * Created via {@link ConversationRef.message}.
945
+ *
946
+ * @public
947
+ */
948
+ export declare interface MessageRef {
949
+ /**
950
+ * The ID of the referenced message.
951
+ *
952
+ * @remarks
953
+ * Immutable: if you want to reference a different message, get a new MessageRef instead.
954
+ */
955
+ readonly id: string;
956
+ /**
957
+ * The ID of the conversation that the referenced message belongs to.
958
+ *
959
+ * @remarks
960
+ * Immutable: if you want to reference a message from a different conversation, get a new MessageRef from that conversation.
961
+ */
962
+ readonly conversationId: string;
963
+ /**
964
+ * Fetches a snapshot of the message.
965
+ *
966
+ * @remarks
967
+ * Supports {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#cached-fetch | Cached Fetch}
968
+ *
969
+ * @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
+ */
971
+ get(): Promise<MessageSnapshot | null>;
972
+ /**
973
+ * Edits this message.
974
+ *
975
+ * @returns A promise that resolves when the operation completes. The promise will reject if the request is invalid, the message doesn't exist, or you do not have permission to edit that message.
976
+ */
977
+ edit(params: string | EditTextMessageParams | EditMessageParams): Promise<void>;
978
+ /**
979
+ * Deletes this message, or does nothing if they are already not a participant.
980
+ *
981
+ * @remarks
982
+ * Deleting a nonexistent message is treated as success, and the promise will resolve.
983
+ *
984
+ * @returns A promise that resolves when the operation completes. This promise will reject if you are not a participant in the conversation or if your role does not give you permission to delete this message.
985
+ */
986
+ delete(): Promise<void>;
987
+ }
988
+
989
+ /**
990
+ * A snapshot of a message's attributes at a given moment in time.
991
+ *
992
+ * @remarks
993
+ * Automatically expanded to include a snapshot of the user that sent the message, and a snapshot of the referenced message, if this message is a reply.
994
+ *
995
+ * Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
996
+ *
997
+ * @public
998
+ */
999
+ export declare interface MessageSnapshot {
1000
+ /**
1001
+ * The unique ID that is used to identify the message in TalkJS
1002
+ */
1003
+ id: string;
1004
+ /**
1005
+ * Whether this message was "from a user" or a general system message without a specific sender.
1006
+ *
1007
+ * The `sender` property is always present for "UserMessage" messages and never present for "SystemMessage" messages.
1008
+ */
1009
+ type: "UserMessage" | "SystemMessage";
1010
+ /**
1011
+ * A snapshot of the user who sent the message, or null if it is a system message.
1012
+ * The user's attributes may have been updated since they sent the message, in which case this snapshot contains the updated data.
1013
+ * It is not a historical snapshot.
1014
+ */
1015
+ sender: UserSnapshot | null;
1016
+ /**
1017
+ * Custom metadata you have set on the message
1018
+ */
1019
+ custom: Record<string, string>;
1020
+ /**
1021
+ * Time at which the message was sent, as a unix timestamp in milliseconds
1022
+ */
1023
+ createdAt: number;
1024
+ /**
1025
+ * Time at which the message was last edited, as a unix timestamp in milliseconds.
1026
+ * `null` if the message has never been edited.
1027
+ */
1028
+ editedAt: number | null;
1029
+ /**
1030
+ * A snapshot of the message that this message is a reply to, or null if this message is not a reply.
1031
+ *
1032
+ * @remarks
1033
+ * Only UserMessages can reference other messages.
1034
+ * The referenced message snapshot does not have a `referencedMessage` field.
1035
+ * Instead, it has `referencedMessageId`.
1036
+ * This prevents TalkJS fetching an unlimited number of messages in a long chain of replies.
1037
+ */
1038
+ referencedMessage: ReferencedMessageSnapshot | null;
1039
+ /**
1040
+ * Where this message originated from:
1041
+ *
1042
+ * - "web" = Message sent via the UI or via {@link ConversationBuilder.sendMessage}
1043
+ *
1044
+ * - "rest" = Message sent via the REST API's "send message" endpoint or {@link ConversationRef.send}
1045
+ *
1046
+ * - "import" = Message sent via the REST API's "import messages" endpoint
1047
+ *
1048
+ * - "email" = Message sent by replying to an email notification
1049
+ */
1050
+ origin: "web" | "rest" | "import" | "email";
1051
+ /**
1052
+ * The contents of the message, as a plain text string without any formatting or attachments.
1053
+ * Useful for showing in a conversation list or in notifications.
1054
+ */
1055
+ plaintext: string;
1056
+ /**
1057
+ * The main body of the message, as a list of blocks that are rendered top-to-bottom.
1058
+ */
1059
+ content: ContentBlock[];
1060
+ }
1061
+
1062
+ /**
1063
+ * A subscription to the messages in a specific conversation.
1064
+ *
1065
+ * @remarks
1066
+ * Get a MessageSubscription by calling {@link ConversationRef.subscribeMessages}
1067
+ *
1068
+ * The subscription is 'windowed'. It includes all messages since a certain point in time.
1069
+ * By default, you subscribe to the 30 most recent messages, and any new messages are sent after you subscribe.
1070
+ *
1071
+ * You can expand this window by calling `loadMore`, which extends the window further into the past.
1072
+ *
1073
+ * @public
1074
+ */
1075
+ export declare interface MessageSubscription {
1076
+ /**
1077
+ * The current state of the subscription
1078
+ *
1079
+ * @remarks
1080
+ * An object with the following fields:
1081
+ *
1082
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
1083
+ *
1084
+ * When `type` is "active", includes `latestSnapshot` and `loadedAll`.
1085
+ *
1086
+ * - `latestSnapshot: MessageSnapshot[] | null` the current state of the messages in the window, or null if you're not a participant in the conversation
1087
+ *
1088
+ * - `loadedAll: boolean` true when `latestSnapshot` contains all the messages in the conversation
1089
+ *
1090
+ * When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
1091
+ */
1092
+ state: PendingState | MessageActiveState | UnsubscribedState | ErrorState;
1093
+ /**
1094
+ * Resolves when the subscription starts receiving updates from the server.
1095
+ *
1096
+ * @remarks
1097
+ * Wait for this promise if you want to perform some action as soon as the subscription is active.
1098
+ *
1099
+ * The promise rejects if the subscription is terminated before it connects.
1100
+ */
1101
+ connected: Promise<MessageActiveState>;
1102
+ /**
1103
+ * Resolves when the subscription permanently stops receiving updates from the server.
1104
+ *
1105
+ * @remarks
1106
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
1107
+ */
1108
+ terminated: Promise<UnsubscribedState | ErrorState>;
1109
+ /**
1110
+ * Expand the window to include older messages
1111
+ *
1112
+ * @remarks
1113
+ * Calling `loadMore` multiple times in parallel will still only load one page of messages.
1114
+ *
1115
+ * @param count - The number of additional messages to load. Must be between 1 and 100
1116
+ * @returns A promise that resolves once the additional messages have loaded
1117
+ */
1118
+ loadMore: (count?: number) => Promise<void>;
1119
+ /**
1120
+ * Unsubscribe from this resource and stop receiving updates.
1121
+ *
1122
+ * @remarks
1123
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
1124
+ */
1125
+ unsubscribe(): void;
1126
+ }
1127
+
1128
+ /**
1129
+ * References a given user's participation in a conversation.
1130
+ *
1131
+ * @remarks
1132
+ * Used in all Realtime API operations affecting that participant, such as joining/leaving a conversation, or setting their access.
1133
+ * Created via {@link ConversationRef.participant}.
1134
+ *
1135
+ * @public
1136
+ */
1137
+ export declare interface ParticipantRef {
1138
+ /**
1139
+ * The ID of the user who is participating.
1140
+ *
1141
+ * @remarks
1142
+ * Immutable: if you want to reference a different participant, get a new ParticipantRef instead.
1143
+ */
1144
+ readonly userId: string;
1145
+ /**
1146
+ * The ID of the conversation the user is participating in.
1147
+ *
1148
+ * @remarks
1149
+ * Immutable: if you want to reference the user in a different conversation, get a new ParticipantRef instead.
1150
+ */
1151
+ readonly conversationId: string;
1152
+ /**
1153
+ * Fetches a snapshot of the participant.
1154
+ *
1155
+ * @remarks
1156
+ * This contains all of the participant's public information.
1157
+ *
1158
+ * @returns A snapshot of the participant's attributes, or null if the user is not a participant. The promise will reject if you are not a participant and try to read information about someone else.
1159
+ */
1160
+ get(): Promise<ParticipantSnapshot | null>;
1161
+ /**
1162
+ * Sets properties of this participant. If the user is not already a participant in the conversation, they will be added.
1163
+ *
1164
+ * @remarks
1165
+ * Supports {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#automatic-batching | Automatic Batching}
1166
+ *
1167
+ * @returns A promise that resolves when the operation completes.
1168
+ * When client-side conversation syncing is disabled, you may only set your `notify` property, when you are already a participant.
1169
+ * Everything else requires client-side conversation syncing to be enabled, and will cause the promise to reject.
1170
+ */
1171
+ set(params: SetParticipantParams): Promise<void>;
1172
+ /**
1173
+ * Edits properties of a pre-existing participant. If the user is not already a participant in the conversation, the promise will reject.
1174
+ *
1175
+ * @remarks
1176
+ * Supports {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#automatic-batching | Automatic Batching}
1177
+ *
1178
+ * @returns A promise that resolves when the operation completes.
1179
+ * When client-side conversation syncing is disabled, you may only set your `notify` property, when you are already a participant.
1180
+ * Everything else requires client-side conversation syncing to be enabled, and will cause the promise to reject.
1181
+ */
1182
+ edit(params: SetParticipantParams): Promise<void>;
1183
+ /**
1184
+ * Adds the user as a participant, or does nothing if they are already a participant.
1185
+ *
1186
+ * @remarks
1187
+ * If the participant already exists, this operation is still considered successful and the promise will still resolve.
1188
+ *
1189
+ * Supports {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#automatic-batching | Automatic Batching}
1190
+ *
1191
+ * @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
+ */
1193
+ createIfNotExists(params?: CreateParticipantParams): Promise<void>;
1194
+ /**
1195
+ * Removes the user as a participant, or does nothing if they are already not a participant.
1196
+ *
1197
+ * @remarks
1198
+ * Deleting a nonexistent participant is treated as success, and the promise will resolve.
1199
+ *
1200
+ * @returns A promise that resolves when the operation completes. This promise will reject if client-side conversation syncing is disabled.
1201
+ */
1202
+ delete(): Promise<void>;
1203
+ }
1204
+
1205
+ /**
1206
+ * A snapshot of a participant's attributes at a given moment in time.
1207
+ *
1208
+ * @remarks
1209
+ * Automatically expanded to include a snapshot of the user who is a participant.
1210
+ *
1211
+ * Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
1212
+ *
1213
+ * @public
1214
+ */
1215
+ export declare interface ParticipantSnapshot {
1216
+ /**
1217
+ * The user who this participant snapshot is referring to
1218
+ */
1219
+ user: UserSnapshot;
1220
+ /**
1221
+ * The level of access this participant has in the conversation.
1222
+ */
1223
+ access: "ReadWrite" | "Read";
1224
+ /**
1225
+ * When the participant will be notified about new messages in this conversation.
1226
+ *
1227
+ * @remarks
1228
+ * `false` means no notifications, `true` means notifications for all messages, and `"MentionsOnly"` means that the user will only be notified when they are mentioned with an `@`.
1229
+ */
1230
+ notify: boolean | "MentionsOnly";
1231
+ /**
1232
+ * The date that this user joined the conversation, as a unix timestamp in milliseconds.
1233
+ */
1234
+ joinedAt: number;
1235
+ }
1236
+
1237
+ /**
1238
+ * The state of a subscription before it has connected to the server
1239
+ *
1240
+ * @public
1241
+ */
1242
+ export declare interface PendingState {
1243
+ type: "pending";
1244
+ }
1245
+
1246
+ /**
1247
+ * A snapshot of a message's attributes at a given moment in time, used in {@link MessageSnapshot.referencedMessage}.
1248
+ *
1249
+ * @remarks
1250
+ * Automatically expanded to include a snapshot of the user that sent the message.
1251
+ * Since this is a snapshot of a referenced message, its referenced message is not automatically expanded, to prevent fetching an unlimited number of messages in a long chain of replies.
1252
+ * Instead, contains the `referencedMessageId` field.
1253
+ *
1254
+ * Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
1255
+ *
1256
+ * @public
1257
+ */
1258
+ export declare interface ReferencedMessageSnapshot {
1259
+ /**
1260
+ * The unique ID that is used to identify the message in TalkJS
1261
+ */
1262
+ id: string;
1263
+ /**
1264
+ * Referenced messages are always "UserMessage" because you cannot reply to a system message.
1265
+ */
1266
+ type: "UserMessage";
1267
+ /**
1268
+ * A snapshot of the user who sent the message.
1269
+ * The user's attributes may have been updated since they sent the message, in which case this snapshot contains the updated data.
1270
+ * It is not a historical snapshot.
1271
+ *
1272
+ * @remarks
1273
+ * Guaranteed to be set, unlike in MessageSnapshot, because you cannot reference a SystemMessage
1274
+ */
1275
+ sender: UserSnapshot;
1276
+ /**
1277
+ * Custom metadata you have set on the message
1278
+ */
1279
+ custom: Record<string, string>;
1280
+ /**
1281
+ * Time at which the message was sent, as a unix timestamp in milliseconds
1282
+ */
1283
+ createdAt: number;
1284
+ /**
1285
+ * Time at which the message was last edited, as a unix timestamp in milliseconds.
1286
+ * `null` if the message has never been edited.
1287
+ */
1288
+ editedAt: number | null;
1289
+ /**
1290
+ * The ID of the message that this message is a reply to, or null if this message is not a reply.
1291
+ *
1292
+ * @remarks
1293
+ * Since this is a snapshot of a referenced message, we do not automatically expand its referenced message.
1294
+ * The ID of its referenced message is provided here instead.
1295
+ */
1296
+ referencedMessageId: string | null;
1297
+ /**
1298
+ * Where this message originated from:
1299
+ *
1300
+ * - "web" = Message sent via the UI or via `ConversationBuilder.sendMessage`
1301
+ *
1302
+ * - "rest" = Message sent via the REST API's "send message" endpoint
1303
+ *
1304
+ * - "import" = Message sent via the REST API's "import messages" endpoint
1305
+ *
1306
+ * - "email" = Message sent by replying to an email notification
1307
+ */
1308
+ origin: "web" | "rest" | "import" | "email";
1309
+ /**
1310
+ * The contents of the message, as a plain text string without any formatting or attachments.
1311
+ * Useful for showing in a conversation list or in notifications.
1312
+ */
1313
+ plaintext: string;
1314
+ /**
1315
+ * The main body of the message, as a list of blocks that are rendered top-to-bottom.
1316
+ */
1317
+ content: ContentBlock[];
1318
+ }
1319
+
1320
+ export declare function registerPolyfills({ WebSocket }: {
1321
+ WebSocket: object;
1322
+ }): void;
1323
+
1324
+ /**
1325
+ * The version of {@link ContentBlock} that is used when sending or editing messages.
1326
+ *
1327
+ * @remarks
1328
+ * This is the same as {@link ContentBlock} except it uses {@link SendFileBlock} instead of {@link FileBlock}
1329
+ *
1330
+ * `SendContentBlock` is a subset of `ContentBlock`.
1331
+ * This means that you can re-send the `content` from an existing message without any issues:
1332
+ *
1333
+ * ```
1334
+ * const existingMessage: MessageSnapshot = ...;
1335
+ *
1336
+ * const convRef = session.conversation('example_conversation_id');
1337
+ * convRef.send({ content: existingMessage.content });
1338
+ * ```
1339
+ *
1340
+ * @public
1341
+ */
1342
+ export declare type SendContentBlock = TextBlock | SendFileBlock | LocationBlock;
1343
+
1344
+ /**
1345
+ * The version of {@link FileBlock} that is used when sending or editing messages.
1346
+ *
1347
+ * @remarks
1348
+ * When a user receives the message you send with `SendFileBlock`, this block will have turned into one of the {@link FileBlock} variants.
1349
+ *
1350
+ * For information on how to obtain a file token, see {@link FileToken}.
1351
+ *
1352
+ * The `SendFileBlock` interface is a subset of the `FileBlock` interface.
1353
+ * If you have an existing `FileBlock` received in a message, you can re-use that block to re-send the same attachment:
1354
+ *
1355
+ * ```
1356
+ * const existingFileBlock = ...;
1357
+ * const imageToShare = existingFileBlock.content[0] as ImageBlock
1358
+ *
1359
+ * const convRef = session.conversation('example_conversation_id');
1360
+ * convRef.send({ content: [imageToShare] });
1361
+ * ```
1362
+ *
1363
+ * @public
1364
+ */
1365
+ export declare interface SendFileBlock {
1366
+ type: "file";
1367
+ /**
1368
+ * The encoded identifier for the file, obtained by uploading a file with {@link Session.sendFile}, or taken from another message.
1369
+ */
1370
+ fileToken: FileToken;
1371
+ }
1372
+
1373
+ /**
1374
+ * Parameters you can pass to {@link ConversationRef.send}.
1375
+ *
1376
+ * @remarks
1377
+ * Properties that are `undefined` will be set to the default.
1378
+ *
1379
+ * This is the more advanced method for editing a message, giving full control over the message content.
1380
+ * You can decide exactly how a text message should be formatted, edit an attachment, or even turn a text message into a location.
1381
+ *
1382
+ * @public
1383
+ */
1384
+ export declare interface SendMessageParams {
1385
+ /**
1386
+ * Custom metadata you have set on the user.
1387
+ * Default = no custom metadata
1388
+ */
1389
+ custom?: Record<string, string>;
1390
+ /**
1391
+ * The message that you are replying to.
1392
+ * Default = not a reply
1393
+ */
1394
+ referencedMessage?: string | MessageRef;
1395
+ /**
1396
+ * The most important part of the message, either some text, a file attachment, or a location.
1397
+ *
1398
+ * @remarks
1399
+ * 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.
1400
+ */
1401
+ content: [SendContentBlock];
1402
+ }
1403
+
1404
+ /**
1405
+ * Parameters you can pass to {@link ConversationRef.send}.
1406
+ *
1407
+ * @remarks
1408
+ * Properties that are `undefined` will be set to the default.
1409
+ *
1410
+ * This is a simpler version of {@link SendMessageParams} that only supports text messages.
1411
+ *
1412
+ * @public
1413
+ */
1414
+ export declare interface SendTextMessageParams {
1415
+ /**
1416
+ * Custom metadata you have set on the user.
1417
+ * Default = no custom metadata
1418
+ */
1419
+ custom?: Record<string, string>;
1420
+ /**
1421
+ * The message that you are replying to.
1422
+ * Default = not a reply
1423
+ */
1424
+ referencedMessage?: string | MessageRef;
1425
+ /**
1426
+ * The text to send in the message.
1427
+ *
1428
+ * @remarks
1429
+ * This is parsed the same way as the text entered in the message field. For example, `*hi*` will appear as `hi` in bold.
1430
+ *
1431
+ * See the {@link https://talkjs.com/docs/Features/Message_Features/Formatting/ | message formatting documentation} for more details.
1432
+ */
1433
+ text: string;
1434
+ }
1435
+
1436
+ /**
1437
+ * Parameters you can pass to {@link ConversationRef.set}.
1438
+ *
1439
+ * Properties that are `undefined` will not be changed.
1440
+ * To clear / reset a property to the default, pass `null`.
1441
+ *
1442
+ * @public
1443
+ */
1444
+ export declare interface SetConversationParams {
1445
+ /**
1446
+ * The conversation subject to display in the chat header.
1447
+ * Default = no subject, list participant names instead.
1448
+ */
1449
+ subject?: string | null;
1450
+ /**
1451
+ * The URL for the conversation photo to display in the chat header.
1452
+ * Default = no photo, show a placeholder image.
1453
+ */
1454
+ photoUrl?: string | null;
1455
+ /**
1456
+ * System messages which are sent at the beginning of a conversation.
1457
+ * Default = no messages.
1458
+ */
1459
+ welcomeMessages?: string[] | null;
1460
+ /**
1461
+ * Custom metadata you have set on the conversation.
1462
+ * This value acts as a patch. Remove specific properties by setting them to `null`.
1463
+ * Default = no custom metadata
1464
+ */
1465
+ custom?: Record<string, string | null> | null;
1466
+ /**
1467
+ * Your access to the conversation.
1468
+ * Default = "ReadWrite" access.
1469
+ */
1470
+ access?: "Read" | "ReadWrite" | null;
1471
+ /**
1472
+ * Your notification settings.
1473
+ * Default = `true`
1474
+ */
1475
+ notify?: boolean | "MentionsOnly" | null;
1476
+ }
1477
+
1478
+ /**
1479
+ * Parameters you can pass to {@link ParticipantRef.set} or {@link ParticipantRef.edit}.
1480
+ *
1481
+ * @remarks
1482
+ * Properties that are `undefined` will not be changed.
1483
+ * To clear / reset a property to the default, pass `null`.
1484
+ *
1485
+ * @public
1486
+ */
1487
+ export declare interface SetParticipantParams {
1488
+ /**
1489
+ * The level of access the participant should have in the conversation.
1490
+ * Default = "ReadWrite" access.
1491
+ */
1492
+ access?: "ReadWrite" | "Read" | null;
1493
+ /**
1494
+ * When the participant should be notified about new messages in this conversation.
1495
+ * Default = `ReadWrite` access.
1496
+ *
1497
+ * @remarks
1498
+ * `false` means no notifications, `true` means notifications for all messages, and `"MentionsOnly"` means that the user will only be notified when they are mentioned with an `@`.
1499
+ */
1500
+ notify?: boolean | "MentionsOnly" | null;
1501
+ }
1502
+
1503
+ /**
1504
+ * Parameters you can pass to {@link UserRef.set}.
1505
+ *
1506
+ * @remarks
1507
+ * Properties that are `undefined` will not be changed.
1508
+ * To clear / reset a property to the default, pass `null`.
1509
+ *
1510
+ * @public
1511
+ */
1512
+ export declare interface SetUserParams {
1513
+ /**
1514
+ * The user's name which will be displayed on the TalkJS UI
1515
+ */
1516
+ name?: string;
1517
+ /**
1518
+ * Custom metadata you have set on the user.
1519
+ * This value acts as a patch. Remove specific properties by setting them to `null`.
1520
+ * Default = no custom metadata
1521
+ */
1522
+ custom?: Record<string, string | null> | null;
1523
+ /**
1524
+ * An {@link https://www.w3.org/International/articles/language-tags/ | IETF language tag}.
1525
+ * See the {@link https://talkjs.com/docs/Features/Language_Support/Localization.html | localization documentation}
1526
+ * Default = the locale selected on the dashboard
1527
+ */
1528
+ locale?: string;
1529
+ /**
1530
+ * An optional URL to a photo which will be displayed as the user's avatar.
1531
+ * Default = no photo
1532
+ */
1533
+ photoUrl?: string | null;
1534
+ /**
1535
+ * TalkJS supports multiple sets of settings, called "roles". These allow you to change the behavior of TalkJS for different users.
1536
+ * You have full control over which user gets which configuration.
1537
+ * Default = the `default` role
1538
+ */
1539
+ role?: string | null;
1540
+ /**
1541
+ * The default message a person sees when starting a chat with this user.
1542
+ * Default = no welcome message
1543
+ */
1544
+ welcomeMessage?: string | null;
1545
+ /**
1546
+ * A single email address or an array of email addresses associated with the user.
1547
+ * Default = no email addresses
1548
+ */
1549
+ email?: string | string[] | null;
1550
+ /**
1551
+ * A single phone number or an array of phone numbers associated with the user.
1552
+ * Default = no phone numbers
1553
+ */
1554
+ phone?: string | string[] | null;
1555
+ /**
1556
+ * An object of push registration tokens to use when notifying this user.
1557
+ *
1558
+ * Keys in the object have the format `'provider:token_id'`,
1559
+ * where `provider` is either `"fcm"` for Android (Firebase Cloud Messaging),
1560
+ * or `"apns"` for iOS (Apple Push Notification Service).
1561
+ *
1562
+ * The value for each key can either be `true` to register the device for push notifications, or `null` to unregister that device.
1563
+ *
1564
+ * Setting pushTokens to null unregisters all the previously registered devices.
1565
+ *
1566
+ * Default = no push tokens
1567
+ */
1568
+ pushTokens?: Record<string, true | null> | null;
1569
+ }
1570
+
1571
+ export declare type Subscription = {
1572
+ unsubscribe: () => void;
1573
+ };
1574
+
1575
+ export declare interface TalkSession {
1576
+ /**
1577
+ * A reference to the user this session is connected as
1578
+ *
1579
+ * @remarks
1580
+ * This is immutable. If you want to connect as a different user,
1581
+ * call `getTalkSession` again to get a new session.
1582
+ */
1583
+ readonly currentUser: UserRef;
1584
+ /**
1585
+ * Subscribe to unrecoverable errors on the session.
1586
+ *
1587
+ * @remarks
1588
+ * For example, the handler will be called if your authentication token
1589
+ * expires and can't be refreshed, or if you try to connect with an invalid app ID.
1590
+ *
1591
+ * The handler will only be called at most once.
1592
+ *
1593
+ * Returns a subscription with a `.unsubscribe` method.
1594
+ * Call this unsubscribe method when you no longer need to be notified about errors on the session.
1595
+ */
1596
+ onError(handler: (error: Error) => void): Subscription;
1597
+ /**
1598
+ * Get a reference to a user
1599
+ *
1600
+ * @param id - The ID of the user that you want to reference
1601
+ * @returns A {@linkcode UserRef} for the user with that ID
1602
+ * @public
1603
+ */
1604
+ user(id: string): UserRef;
1605
+ /**
1606
+ * Get a reference to a conversation
1607
+ *
1608
+ * @param id - The ID of the conversation that you want to reference
1609
+ * @returns A {@linkcode ConversationRef} for the conversation with that ID
1610
+ * @public
1611
+ */
1612
+ conversation(id: string): ConversationRef;
1613
+ /**
1614
+ * Upload a generic file without any additional metadata.
1615
+ *
1616
+ * @remarks
1617
+ * This function does not send any message, it only uploads the file and returns a file token.
1618
+ * To send the file in a message, pass the file token in a {@linkcode SendFileBlock} when calling {@linkcode ConversationRef.send}.
1619
+ *
1620
+ * {@link https://talkjs.com/docs/Reference/Concepts/Message_Content/#sending-message-content | See the documentation} for more information about sending files in messages.
1621
+ *
1622
+ * If the file is a video, image, audio file, or voice recording, use one of the other functions like {@linkcode uploadImage} instead.
1623
+ *
1624
+ * @param data The binary file data. Usually a {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/File | File}.
1625
+ * @param metadata Information about the file
1626
+ * @returns A file token that can be used to send the file in a message.
1627
+ */
1628
+ uploadFile(data: Blob, metadata: GenericFileMetadata): Promise<FileToken>;
1629
+ /**
1630
+ * Upload an image with image-specific metadata.
1631
+ *
1632
+ * @remarks
1633
+ * This is a variant of {@linkcode uploadFile} used for images.
1634
+ *
1635
+ * @param data The binary image data. Usually a {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/File | File}.
1636
+ * @param metadata Information about the image.
1637
+ * @returns A file token that can be used to send the image in a message.
1638
+ */
1639
+ uploadImage(data: Blob, metadata: ImageFileMetadata): Promise<FileToken>;
1640
+ /**
1641
+ * Upload a video with video-specific metadata.
1642
+ *
1643
+ * @remarks
1644
+ * This is a variant of {@linkcode uploadFile} used for videos.
1645
+ *
1646
+ * @param data The binary video data. Usually a {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/File | File}.
1647
+ * @param metadata Information about the video.
1648
+ * @returns A file token that can be used to send the video in a message.
1649
+ */
1650
+ uploadVideo(data: Blob, metadata: VideoFileMetadata): Promise<FileToken>;
1651
+ /**
1652
+ * Upload an audio file with audio-specific metadata.
1653
+ *
1654
+ * @remarks
1655
+ * This is a variant of {@linkcode uploadFile} used for audio files.
1656
+ *
1657
+ * @param data The binary audio data. Usually a {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/File | File}.
1658
+ * @param metadata Information about the audio file.
1659
+ * @returns A file token that can be used to send the audio file in a message.
1660
+ */
1661
+ uploadAudio(data: Blob, metadata: AudioFileMetadata): Promise<FileToken>;
1662
+ /**
1663
+ * Upload a voice recording with voice-specific metadata.
1664
+ *
1665
+ * @remarks
1666
+ * This is a variant of {@linkcode uploadFile} used for voice recordings.
1667
+ *
1668
+ * @param data The binary audio data. Usually a {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/File | File}.
1669
+ * @param metadata Information about the voice recording.
1670
+ * @returns A file token that can be used to send the audio file in a message.
1671
+ */
1672
+ uploadVoice(data: Blob, metadata: VoiceRecordingFileMetadata): Promise<FileToken>;
1673
+ }
1674
+
1675
+ export declare interface TalkSessionOptions {
1676
+ appId: string;
1677
+ userId: string;
1678
+ token?: string;
1679
+ tokenFetcher?: () => string | Promise<string>;
1680
+ }
1681
+
1682
+ /**
1683
+ * A block of formatted text in a message's content.
1684
+ *
1685
+ * @remarks
1686
+ * Each TextBlock is a tree of {@link TextNode} children describing the structure of some formatted text.
1687
+ * Each child is either a plain text string, or a `node` representing some text with additional formatting.
1688
+ *
1689
+ * For example, if the user typed:
1690
+ *
1691
+ * > *This first bit* is bold, and *_the second bit_* is bold and italics
1692
+ *
1693
+ * Then this would become a Text Block with the structure:
1694
+ *
1695
+ * ```
1696
+ * {
1697
+ * type: "text",
1698
+ * children: [
1699
+ * {
1700
+ * type: "text",
1701
+ * children: [
1702
+ * { type: "bold", children: ["This first bit"] },
1703
+ * " is bold, and ",
1704
+ * {
1705
+ * children: [
1706
+ * { type: "italic", children: ["the second bit"] }
1707
+ * ],
1708
+ * type: "bold",
1709
+ * },
1710
+ * " is bold and italics",
1711
+ * ],
1712
+ * },
1713
+ * ],
1714
+ * }
1715
+ * ```
1716
+ *
1717
+ * Rather than relying the automatic message parsing, you can also specify the `TextBlock` directly using {@link ConversationRef.send} with {@link SendMessageParams}.
1718
+ *
1719
+ * @public
1720
+ */
1721
+ export declare interface TextBlock {
1722
+ type: "text";
1723
+ children: TextNode[];
1724
+ }
1725
+
1726
+ /**
1727
+ * Any node that can exist inside a {@link TextBlock}.
1728
+ *
1729
+ * @remarks
1730
+ * The simplest `TextNode` is a plain text string.
1731
+ * Using "hello" as an example message, the `TextBlock` would be:
1732
+ *
1733
+ * ```typescript
1734
+ * {
1735
+ * type: 'text';
1736
+ * children: ['hello'];
1737
+ * }
1738
+ * ```
1739
+ *
1740
+ * Other than plain text, there are many different kinds of node which render some text in a specific way or with certain formatting.
1741
+ *
1742
+ * ```
1743
+ * type TextNode =
1744
+ * | string
1745
+ * | MarkupNode
1746
+ * | BulletListNode
1747
+ * | BulletPointNode
1748
+ * | CodeSpanNode
1749
+ * | LinkNode
1750
+ * | AutoLinkNode
1751
+ * | ActionLinkNode
1752
+ * | ActionButtonNode
1753
+ * | CustomEmojiNode
1754
+ * | MentionNode;
1755
+ * ```
1756
+ *
1757
+ * If the text node is not a plain string, it will have a `type` field indicating what kind of node it is, and either a property `text: string` or a property `children: TextNode[]`.
1758
+ * This will be true for all nodes added in the future as well.
1759
+ *
1760
+ * @public
1761
+ */
1762
+ export declare type TextNode = string | MarkupNode | BulletListNode | BulletPointNode | CodeSpanNode | LinkNode | AutoLinkNode | ActionLinkNode | ActionButtonNode | CustomEmojiNode | MentionNode;
1763
+
1764
+ /**
1765
+ * The state of a subscription after you have manually unsubscribed
1766
+ *
1767
+ * @public
1768
+ */
1769
+ export declare interface UnsubscribedState {
1770
+ type: "unsubscribed";
1771
+ }
1772
+
1773
+ /**
1774
+ * The state of a user subscription when it is actively listening for changes
1775
+ *
1776
+ * @public
1777
+ */
1778
+ export declare interface UserActiveState {
1779
+ type: "active";
1780
+ /**
1781
+ * The most recently received snapshot for the user, or `null` if the user does not exist yet.
1782
+ */
1783
+ latestSnapshot: UserSnapshot | null;
1784
+ }
1785
+
1786
+ /**
1787
+ * References the user with a given user ID.
1788
+ *
1789
+ * @remarks
1790
+ * Used in all Realtime API operations affecting that user, such as creating the user, fetching or updating user data, or adding a user to a conversation.
1791
+ * Created via {@link Session.user}.
1792
+ *
1793
+ * @public
1794
+ */
1795
+ export declare interface UserRef {
1796
+ /**
1797
+ * The ID of the referenced user.
1798
+ *
1799
+ * @remarks
1800
+ * Immutable: if you want to reference a different user, get a new UserRef instead.
1801
+ */
1802
+ readonly id: string;
1803
+ /**
1804
+ * Fetches a snapshot of the user.
1805
+ *
1806
+ * @remarks
1807
+ * This contains all of a user's public information.
1808
+ * Fetching a user snapshot doesn't require any permissions. You can read the public information of any user.
1809
+ * Private information, such as email addresses and phone numbers, aren't included in the response.
1810
+ *
1811
+ * Supports {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#automatic-batching | Automatic Batching} and {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/Realtime_API/#cached-fetch | Cached Fetch}
1812
+ *
1813
+ * @returns A snapshot of the user's public attributes, or null if the user doesn't exist.
1814
+ */
1815
+ get(): Promise<UserSnapshot | null>;
1816
+ /**
1817
+ * Sets properties of this user. The user is created if a user with this ID doesn't already exist.
1818
+ *
1819
+ * @remarks
1820
+ * `name` is required when creating a user. The promise will reject if you don't provide a `name` and the user does not exist yet.
1821
+ *
1822
+ * @returns A promise that resolves when the operation completes. The promise will reject if the request is invalid or if client-side user syncing is disabled.
1823
+ */
1824
+ set(params: SetUserParams): Promise<void>;
1825
+ /**
1826
+ * Creates a user with this ID, or does nothing if a user with this ID already exists.
1827
+ *
1828
+ * @remarks
1829
+ * If the user already exists, this operation is still considered successful and the promise will still resolve.
1830
+ *
1831
+ * @returns A promise that resolves when the operation completes. The promise will reject if client-side user syncing is disabled and the user does not already exist.
1832
+ */
1833
+ createIfNotExists(params: CreateUserParams): Promise<void>;
1834
+ /**
1835
+ * Subscribe to this user's state.
1836
+ *
1837
+ * @remarks
1838
+ * 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
+ *
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
+ * @returns A subscription to the user
1843
+ */
1844
+ subscribe(onSnapshot?: (event: UserSnapshot | null) => void): UserSubscription;
1845
+ }
1846
+
1847
+ /**
1848
+ * A snapshot of a user's attributes at a given moment in time.
1849
+ *
1850
+ * @remarks
1851
+ * Users also have private information, such as email addresses and phone numbers, but these are only exposed on the {@link https://talkjs.com/docs/Reference/REST_API/Getting_Started/Introduction/ | REST API}.
1852
+ *
1853
+ * Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when `oldSnapshot !== newSnapshot`.
1854
+ *
1855
+ * @public
1856
+ */
1857
+ export declare interface UserSnapshot {
1858
+ /**
1859
+ * The unique ID that is used to identify the user in TalkJS
1860
+ */
1861
+ id: string;
1862
+ /**
1863
+ * The user's name, which is displayed on the TalkJS UI
1864
+ */
1865
+ name: string;
1866
+ /**
1867
+ * Custom metadata you have set on the user
1868
+ */
1869
+ custom: Record<string, string>;
1870
+ /**
1871
+ * An {@link https://www.w3.org/International/articles/language-tags/ | IETF language tag}.
1872
+ * For more information, see: {@link https://talkjs.com/docs/Features/Language_Support/Localization.html | Localization}.
1873
+ *
1874
+ * When `locale` is null, the app's default locale will be used
1875
+ */
1876
+ locale: string | null;
1877
+ /**
1878
+ * An optional URL to a photo that is displayed as the user's avatar
1879
+ */
1880
+ photoUrl: string | null;
1881
+ /**
1882
+ * TalkJS supports multiple sets of settings for users, called "roles". Roles allow you to change the behavior of TalkJS for different users.
1883
+ * You have full control over which user gets which configuration.
1884
+ */
1885
+ role: string;
1886
+ /**
1887
+ * The default message a person sees when starting a chat with this user
1888
+ */
1889
+ welcomeMessage: string | null;
1890
+ }
1891
+
1892
+ /**
1893
+ * A subscription to a specific user
1894
+ *
1895
+ * @remarks
1896
+ * Get a UserSubscription by calling {@link UserRef.subscribe}
1897
+ *
1898
+ * @public
1899
+ */
1900
+ export declare interface UserSubscription {
1901
+ /**
1902
+ * The current state of the subscription
1903
+ *
1904
+ * @remarks
1905
+ * An object with the following fields:
1906
+ *
1907
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
1908
+ *
1909
+ * When `type` is "active", includes `latestSnapshot: UserSnapshot | null`. It is the current state of the user, or null if they don't exist.
1910
+ *
1911
+ * When `type` is "error", includes the `error: Error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
1912
+ */
1913
+ state: PendingState | UserActiveState | UnsubscribedState | ErrorState;
1914
+ /**
1915
+ * Resolves when the subscription starts receiving updates from the server.
1916
+ */
1917
+ connected: Promise<UserActiveState>;
1918
+ /**
1919
+ * Resolves when the subscription permanently stops receiving updates from the server.
1920
+ *
1921
+ * @remarks
1922
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
1923
+ */
1924
+ terminated: Promise<UnsubscribedState | ErrorState>;
1925
+ /**
1926
+ * Unsubscribe from this resource and stop receiving updates.
1927
+ *
1928
+ * @remarks
1929
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
1930
+ */
1931
+ unsubscribe(): void;
1932
+ }
1933
+
1934
+ /**
1935
+ * A FileBlock variant for a video attachment, with additional video-specific metadata.
1936
+ *
1937
+ * @remarks
1938
+ * You can identify this variant by checking for `subtype: "video"`.
1939
+ *
1940
+ * Includes metadata about the height and width of the video in pixels, and the duration of the video in seconds, where available.
1941
+ *
1942
+ * Videos that you upload with the TalkJS UI will include the dimensions and duration as long as the sender's browser can preview the file.
1943
+ * Videos that you upload with the REST API or {@link Session.uploadVideo} will include this metadata if you specified it when uploading.
1944
+ * Videos attached in a reply to an email notification will not include any metadata.
1945
+ *
1946
+ * @public
1947
+ */
1948
+ export declare interface VideoBlock {
1949
+ type: "file";
1950
+ subtype: "video";
1951
+ /**
1952
+ * An encoded identifier for this file. Use in {@link SendFileBlock} to send this video in another message.
1953
+ */
1954
+ fileToken: FileToken;
1955
+ /**
1956
+ * The URL where you can fetch the file.
1957
+ */
1958
+ url: string;
1959
+ /**
1960
+ * The size of the file in bytes.
1961
+ */
1962
+ size: number;
1963
+ /**
1964
+ * The name of the video file, including file extension.
1965
+ */
1966
+ filename: string;
1967
+ /**
1968
+ * The width of the video in pixels, if known.
1969
+ */
1970
+ width?: number;
1971
+ /**
1972
+ * The height of the video in pixels, if known.
1973
+ */
1974
+ height?: number;
1975
+ /**
1976
+ * The duration of the video in seconds, if known.
1977
+ */
1978
+ duration?: number;
1979
+ }
1980
+
1981
+ declare interface VideoFileMetadata {
1982
+ /**
1983
+ * The name of the file including extension.
1984
+ */
1985
+ filename: string;
1986
+ /**
1987
+ * The width of the video in pixels, if known.
1988
+ */
1989
+ width?: number;
1990
+ /**
1991
+ * The height of the video in pixels, if known.
1992
+ */
1993
+ height?: number;
1994
+ /**
1995
+ * The duration of the video in seconds, if known.
1996
+ */
1997
+ duration?: number;
1998
+ }
1999
+
2000
+ /**
2001
+ * A FileBlock variant for a voice recording attachment, with additional voice-recording-specific metadata.
2002
+ *
2003
+ * @remarks
2004
+ * You can identify this variant by checking for `subtype: "voice"`.
2005
+ *
2006
+ * The same file could be uploaded as either a voice block, or as an {@link AudioBlock}.
2007
+ * The same data will be available either way, but they will be rendered differently in the UI.
2008
+ *
2009
+ * Includes metadata about the duration of the recording in seconds, where available.
2010
+ *
2011
+ * Voice recordings done in the TalkJS UI will always include the duration.
2012
+ * Voice recording that you upload with the REST API or {@link Session.uploadVoice} will include this metadata if you specified it when uploading.
2013
+ *
2014
+ * Voice recordings will never be taken from a reply to an email notification.
2015
+ * Any attached audio file will become an {@link AudioBlock} instead of a voice block.
2016
+ *
2017
+ * @public
2018
+ */
2019
+ export declare interface VoiceBlock {
2020
+ type: "file";
2021
+ subtype: "voice";
2022
+ /**
2023
+ * An encoded identifier for this file. Use in {@link SendFileBlock} to send this voice recording in another message.
2024
+ */
2025
+ fileToken: FileToken;
2026
+ /**
2027
+ * The URL where you can fetch the file
2028
+ */
2029
+ url: string;
2030
+ /**
2031
+ * The size of the file in bytes
2032
+ */
2033
+ size: number;
2034
+ /**
2035
+ * The name of the file, including file extension
2036
+ */
2037
+ filename: string;
2038
+ /**
2039
+ * The duration of the voice recording in seconds, if known
2040
+ */
2041
+ duration?: number;
2042
+ }
2043
+
2044
+ declare interface VoiceRecordingFileMetadata {
2045
+ /**
2046
+ * The name of the file including extension.
2047
+ */
2048
+ filename: string;
2049
+ /**
2050
+ * The duration of the recording in seconds, if known.
2051
+ */
2052
+ duration?: number;
2053
+ }
2054
+
2055
+ export { }