@talkjs/core 1.8.3 → 1.9.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.
@@ -1358,29 +1358,38 @@ export declare interface MessageRef {
1358
1358
  * Get a reference to a specific emoji reaction on this message
1359
1359
  *
1360
1360
  * @remarks
1361
- * If you call `.reaction` with an invalid emoji, it will still succeed and you will still get a `ReactionRef`.
1361
+ * If you call `.reactions` with an invalid emoji, it will still succeed and you will still get a `ReactionRef`.
1362
1362
  * However, the TalkJS server will reject any calls that use an invalid emoji.
1363
1363
  *
1364
- * Calling this method multiple times with the same emoji reuses the same {@link ReactionRef} object.
1365
- *
1366
- * In the future, this will also be used to fetch a full list of people who used that specific reaction on the message.
1364
+ * Calling this method multiple times with the same emoji reuses the same {@link ReactionsRef} object.
1367
1365
  *
1368
1366
  * @example Reacting to the message with a Unicode emoji
1369
1367
  * ```ts
1370
- * MessageRef.reaction("🚀").add()
1368
+ * MessageRef.reactions("🚀").add()
1371
1369
  * ```
1372
1370
  *
1373
1371
  * @example Removing your custom emoji reaction from the message
1374
1372
  * ```ts
1375
- * MessageRef.reaction(":cat-roomba:").remove()
1373
+ * MessageRef.reactions(":cat-roomba:").remove()
1374
+ * ```
1375
+ *
1376
+ * @example Subscribing to the list of users who reacted with a specific emoji
1377
+ * ```ts
1378
+ * MessageRef.reactions("🚀").subscribe(snapshots => console.log(snapshots))
1376
1379
  * ```
1377
1380
  *
1378
1381
  * @param emoji - The emoji for the reaction you want to reference. a single Unicode emoji like "🚀" or a custom emoji like ":cat_roomba:". Custom emoji can be up to 50 characters long.
1379
- * @returns A {@link ReactionRef} for the reaction with that emoji on this message
1382
+ * @returns A {@link ReactionsRef} for the reactions with that emoji on this message
1380
1383
  * @throws If the emoji is not a string or is an empty string
1381
1384
  * @public
1382
1385
  */
1383
- reaction(emoji: string): ReactionRef;
1386
+ reactions(emoji: string): ReactionsRef;
1387
+ /**
1388
+ * Get a reference to a specific emoji reaction on this message
1389
+ *
1390
+ * @deprecated This has been renamed to {@link MessageRef.reactions}. For back-compat, this method will continue to be available as an alias.
1391
+ */
1392
+ reaction(emoji: string): ReactionsRef;
1384
1393
  /**
1385
1394
  * Fetches a snapshot of the message.
1386
1395
  *
@@ -1515,17 +1524,21 @@ export declare interface MessageSnapshot {
1515
1524
  */
1516
1525
  readonly referencedMessage: ReferencedMessageSnapshot | null;
1517
1526
  /**
1518
- * Where this message originated from:
1527
+ * Specifies how this message was created.
1528
+ *
1529
+ * - "rest" = Message sent normally, via one of the UI components, the Data API, or the REST API
1519
1530
  *
1520
- * - "web" = Message sent via the UI or via {@link ConversationBuilder.sendMessage}
1531
+ * - "import" = Message sent via the admin REST API's "import messages" endpoint
1521
1532
  *
1522
- * - "rest" = Message sent via the REST API's "send message" endpoint or {@link ConversationRef.send}
1533
+ * - "email" = Message sent as a reply to an email notification
1523
1534
  *
1524
- * - "import" = Message sent via the REST API's "import messages" endpoint
1535
+ * - "web" = Message sent using a classic SDK
1525
1536
  *
1526
- * - "email" = Message sent by replying to an email notification
1537
+ * To track more detailed information about where a message comes from, such as browser vs mobile app, use message custom data.
1538
+ *
1539
+ * The "rest" and "web" values are confusingly named. This is for historical reasons and to maintain backwards compatibility.
1527
1540
  */
1528
- readonly origin: "web" | "rest" | "import" | "email";
1541
+ readonly origin: "rest" | "import" | "email" | "web";
1529
1542
  /**
1530
1543
  * The contents of the message, as a plain text string without any formatting or attachments.
1531
1544
  * Useful for showing in a conversation list or in notifications.
@@ -1536,12 +1549,13 @@ export declare interface MessageSnapshot {
1536
1549
  */
1537
1550
  readonly content: ContentBlock[];
1538
1551
  /**
1539
- * All the emoji reactions that have been added to this message.
1552
+ * A summary of the emoji reactions that have been added to this message.
1540
1553
  *
1541
1554
  * @remarks
1542
- * There can be up to 50 different reactions on each message.
1555
+ * Each message can have up to 50 unique emoji used for reactions.
1556
+ * They are sorted in the order they were first added to the message, starting with the oldest.
1543
1557
  */
1544
- readonly reactions: ReactionSnapshot[];
1558
+ readonly reactions: ReactionsSummarySnapshot[];
1545
1559
  }
1546
1560
 
1547
1561
  /**
@@ -1597,9 +1611,9 @@ export declare interface MessageSubscription {
1597
1611
  * Expand the window to include older messages
1598
1612
  *
1599
1613
  * @remarks
1600
- * The `count` parameter is relative to the current number of loaded participants.
1614
+ * The `count` parameter is relative to the current number of loaded messages.
1601
1615
  * If you call `loadMore(5)` and then call `loadMore(10)` immediately afterwards (without awaiting the promise),
1602
- * then only 10 additional participants will be loaded, not 15.
1616
+ * then only 10 additional messages will be loaded, not 15.
1603
1617
  *
1604
1618
  * Avoid calling `.loadMore` in a loop until you have loaded all messages.
1605
1619
  * If you do need to call loadMore in a loop, make sure you set an upper bound (e.g. 1000) on the number of messages, where the loop will exit.
@@ -1801,9 +1815,9 @@ export declare interface ParticipantSubscription {
1801
1815
  * Expand the window to include older participants
1802
1816
  *
1803
1817
  * @remarks
1804
- * The `count` parameter is relative to the current number of loaded messages.
1818
+ * The `count` parameter is relative to the current number of loaded participants.
1805
1819
  * If you call `loadMore(5)` and then call `loadMore(10)` immediately afterwards (without awaiting the promise),
1806
- * then only 10 additional messages will be loaded, not 15.
1820
+ * then only 10 additional participants will be loaded, not 15.
1807
1821
  *
1808
1822
  * Avoid calling `.loadMore` in a loop until you have loaded all participants.
1809
1823
  * If you do need to call loadMore in a loop, make sure you set a small upper bound (e.g. 100) on the number of participants, where the loop will exit.
@@ -1831,17 +1845,54 @@ export declare interface PendingState {
1831
1845
  }
1832
1846
 
1833
1847
  /**
1834
- * References a specific emoji reaction on a message.
1848
+ * References all the reactions on a message using a specific emoji.
1849
+ *
1850
+ * @deprecated This has been renamed to {@link ReactionsRef}. For back-compat, this will continue to be available as an alias.
1851
+ *
1852
+ * @public
1853
+ */
1854
+ export declare type ReactionRef = ReactionsRef;
1855
+
1856
+ /**
1857
+ * The state of a user reaction list subscription when it is actively listening for changes
1858
+ *
1859
+ * @public
1860
+ */
1861
+ export declare interface ReactionsActiveState {
1862
+ readonly type: "active";
1863
+ /**
1864
+ * The most recently received snapshot for the participants, or `null` if you are not a participant in that conversation.
1865
+ */
1866
+ readonly latestSnapshot: SingleReactionSnapshot[] | null;
1867
+ /**
1868
+ * True if `latestSnapshot` contains all users who used this reaction.
1869
+ * Use {@link ReactionsSubscription.loadMore} to load more.
1870
+ */
1871
+ readonly loadedAll: boolean;
1872
+ }
1873
+
1874
+ /**
1875
+ * A summary of the reactions to a message using a specific emoji.
1876
+ *
1877
+ * @deprecated This has been renamed to {@link ReactionsSummarySnapshot}. For back-compat, this will continue to be available as an alias.
1878
+ *
1879
+ * @public
1880
+ */
1881
+ export declare type ReactionSnapshot = ReactionsSummarySnapshot;
1882
+
1883
+ /**
1884
+ * References all the reactions on a message using a specific emoji.
1835
1885
  *
1836
1886
  * @remarks
1837
- * Used in all Data API operations affecting that emoji reaction, such as adding or removing the reaction.
1838
- * Created via {@link MessageRef.reaction}.
1887
+ * Used in all Data API operations affecting reactions with this emoji.
1888
+ * This includes mutating *your* reaction with `.add` and `.remove`, as well as fetching information about the aggregate state using `getFirstReactions` and `.subscribe`.
1889
+ * Created via {@link MessageRef.reactions}.
1839
1890
  *
1840
1891
  * @public
1841
1892
  */
1842
- export declare interface ReactionRef {
1893
+ export declare interface ReactionsRef {
1843
1894
  /**
1844
- * Which emoji the reaction is using.
1895
+ * Which emoji the reactions use.
1845
1896
  *
1846
1897
  * @remarks
1847
1898
  * Either a single Unicode emoji, or the name of a custom emoji with a colon at the start and end.
@@ -1861,36 +1912,127 @@ export declare interface ReactionRef {
1861
1912
  * The ID of the message that this is a reaction to.
1862
1913
  *
1863
1914
  * @remarks
1864
- * Immutable: if you want to react to a different message, get a new ReactionRef instead.
1915
+ * Immutable: if you want reactions for a different message, get a new ReactionRef instead.
1865
1916
  */
1866
1917
  readonly messageId: string;
1867
1918
  /**
1868
1919
  * The ID of the conversation the message belongs to.
1869
1920
  *
1870
1921
  * @remarks
1871
- * Immutable: if you want to reference a message from a different conversation, get a new MessageRef from that conversation and call `.reaction` on that MessageRef.
1922
+ * Immutable: if you want reactions for a message in a different conversation, get a new MessageRef from that conversation and call `.reactions` on that MessageRef.
1872
1923
  */
1873
1924
  readonly conversationId: string;
1874
1925
  /**
1875
- * Adds this emoji reaction onto the message, from the current user.
1926
+ * React with this emoji reaction, as the current user.
1876
1927
  *
1877
- * @returns A promise that resolves when the operation completes. The promise will reject if the request is invalid, the message doesn't exist, there are already 50 different reactions on this message, or if you do not have permission to use emoji reactions on that message.
1928
+ * @returns A promise that resolves when the operation completes. The promise will reject if the request is invalid, the message doesn't exist, there are already 50 different reactions on this message, or if you do not have permission to use emoji reactions on that message. The promise will resolve with no effect if you have already reacted with this emoji.
1878
1929
  */
1879
1930
  add(): Promise<void>;
1880
1931
  /**
1881
- * Removes this emoji reaction from the message, from the current user.
1932
+ * Un-react with this emoji reaction, as the current user.
1882
1933
  *
1883
- * @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 use emoji reactions on that message.
1934
+ * @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 use emoji reactions on that message. The promise will resolve with no effect if you have not reacted with this emoji.
1884
1935
  */
1885
1936
  remove(): Promise<void>;
1937
+ /**
1938
+ * Lists the first 10 users who added this reaction to the message.
1939
+ *
1940
+ * @remarks
1941
+ * If more than 10 users added this reaction to the message, only the first 10 users will be returned.
1942
+ *
1943
+ * To load more than 10 users, and to get real-time updates when users add or remove reactions, use {@link subscribe} instead.
1944
+ *
1945
+ * @returns The first 10 users, or `null` if the message doesn't exist or is inaccessible to you.
1946
+ */
1947
+ getFirstReactions(): Promise<SingleReactionSnapshot[] | null>;
1948
+ /**
1949
+ * Subscribe to the list of users who have added this reaction to the message
1950
+ */
1951
+ subscribe(onSnapshot?: (snapshot: SingleReactionSnapshot[] | null, loadedAll: boolean) => void): ReactionsSubscription;
1952
+ }
1953
+
1954
+ /**
1955
+ * A subscription to the users who have reacted with a specific emoji on a specific message.
1956
+ *
1957
+ * @remarks
1958
+ * Get a ReactionsSubscription by calling {@link ReactionsRef.subscribe}
1959
+ *
1960
+ * The subscription is 'windowed'. It includes all reactions up to a certain point in time.
1961
+ * By default, you subscribe to the 10 oldest reactions.
1962
+ *
1963
+ * You can expand this window to load newer reactions by calling {@link ReactionsSubscription.loadMore}, which extends the window further into the future.
1964
+ *
1965
+ * Remember to `.unsubscribe` the subscription once you are done with it.
1966
+ *
1967
+ * @public
1968
+ */
1969
+ export declare interface ReactionsSubscription {
1970
+ /**
1971
+ * The current state of the subscription
1972
+ *
1973
+ * @remarks
1974
+ * An object with the following fields:
1975
+ *
1976
+ * `type` is one of "pending", "active", "unsubscribed", or "error".
1977
+ *
1978
+ * When `type` is "active", includes `latestSnapshot` and `loadedAll`.
1979
+ *
1980
+ * - `latestSnapshot: SingleReactionSnapshot[] | null` the current state of who used this reaction, or null if the message does not exist, or if you're not a participant in the conversation
1981
+ *
1982
+ * - `loadedAll: boolean` true when `latestSnapshot` contains all the users who added this reaction to the message
1983
+ *
1984
+ * When `type` is "error", includes the `error` field. It is a JS `Error` object explaining what caused the subscription to be terminated.
1985
+ */
1986
+ state: PendingState | ReactionsActiveState | UnsubscribedState | ErrorState;
1987
+ /**
1988
+ * Resolves when the subscription starts receiving updates from the server.
1989
+ *
1990
+ * @remarks
1991
+ * Wait for this promise if you want to perform some action as soon as the subscription is active.
1992
+ *
1993
+ * The promise rejects if the subscription is terminated before it connects.
1994
+ */
1995
+ readonly connected: Promise<ReactionsActiveState>;
1996
+ /**
1997
+ * Resolves when the subscription permanently stops receiving updates from the server.
1998
+ *
1999
+ * @remarks
2000
+ * This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
2001
+ */
2002
+ readonly terminated: Promise<UnsubscribedState | ErrorState>;
2003
+ /**
2004
+ * Expand the window to include people who added the reaction later
2005
+ *
2006
+ * @remarks
2007
+ * The `count` parameter is relative to the current number of loaded users.
2008
+ * If you call `loadMore(5)` and then call `loadMore(10)` immediately afterwards (without awaiting the promise),
2009
+ * then only 10 additional users will be loaded, not 15.
2010
+ *
2011
+ * Avoid calling `.loadMore` in a loop until you have loaded all users.
2012
+ * If you do need to call loadMore in a loop, make sure you set an upper bound (e.g. 1000) on the number of users, where the loop will exit.
2013
+ *
2014
+ * @param count - The number of additional users to load. Must be between 1 and 100. Default 30.
2015
+ * @returns A promise that resolves once the additional users have loaded
2016
+ */
2017
+ loadMore(count?: number): Promise<void>;
2018
+ /**
2019
+ * Unsubscribe from this resource and stop receiving updates.
2020
+ *
2021
+ * @remarks
2022
+ * If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
2023
+ */
2024
+ unsubscribe(): void;
1886
2025
  }
1887
2026
 
1888
2027
  /**
1889
- * A summary of a single emoji reaction on a message.
2028
+ * A summary of the reactions to a message using a specific emoji.
2029
+ *
2030
+ * @remarks
2031
+ * To see who reacted with a given emoji, or to add a reaction yourself, get a {@link ReactionsRef} using {@link MessageRef.reactions}.
1890
2032
  *
1891
2033
  * @public
1892
2034
  */
1893
- export declare interface ReactionSnapshot {
2035
+ export declare interface ReactionsSummarySnapshot {
1894
2036
  /**
1895
2037
  * Which emoji the users reacted with.
1896
2038
  *
@@ -1913,7 +2055,7 @@ export declare interface ReactionSnapshot {
1913
2055
  * const sent = "👍"
1914
2056
  *
1915
2057
  * // React with thumbs up,
1916
- * await message.reaction(emoji).add()
2058
+ * await message.reactions(emoji).add()
1917
2059
  *
1918
2060
  * // Fetch the reaction
1919
2061
  * const snapshot = await message.get();
@@ -1992,17 +2134,21 @@ export declare interface ReferencedMessageSnapshot {
1992
2134
  */
1993
2135
  readonly referencedMessageId: string | null;
1994
2136
  /**
1995
- * Where this message originated from:
2137
+ * Specifies how this message was created.
1996
2138
  *
1997
- * - "web" = Message sent via the UI or via {@link ConversationBuilder.sendMessage}
2139
+ * - "rest" = Message sent normally, via one of the UI components, the Data API, or the REST API
1998
2140
  *
1999
- * - "rest" = Message sent via the REST API's "send message" endpoint or {@link ConversationRef.send}
2141
+ * - "import" = Message sent via the admin REST API's "import messages" endpoint
2000
2142
  *
2001
- * - "import" = Message sent via the REST API's "import messages" endpoint
2143
+ * - "email" = Message sent as a reply to an email notification
2002
2144
  *
2003
- * - "email" = Message sent by replying to an email notification
2145
+ * - "web" = Message sent using a classic SDK
2146
+ *
2147
+ * To track more detailed information about where a message comes from, such as browser vs mobile app, use message custom data.
2148
+ *
2149
+ * The "rest" and "web" values are confusingly named. This is for historical reasons and to maintain backwards compatibility.
2004
2150
  */
2005
- readonly origin: "web" | "rest" | "import" | "email";
2151
+ readonly origin: "rest" | "import" | "email" | "web";
2006
2152
  /**
2007
2153
  * The contents of the message, as a plain text string without any formatting or attachments.
2008
2154
  * Useful for showing in a conversation list or in notifications.
@@ -2015,7 +2161,7 @@ export declare interface ReferencedMessageSnapshot {
2015
2161
  /**
2016
2162
  * All the emoji reactions that have been added to this message.
2017
2163
  */
2018
- readonly reactions: ReactionSnapshot[];
2164
+ readonly reactions: ReactionsSummarySnapshot[];
2019
2165
  }
2020
2166
 
2021
2167
  export declare function registerPolyfills({ WebSocket }: {
@@ -2354,6 +2500,25 @@ export declare interface SingleParticipantSubscription {
2354
2500
  unsubscribe(): void;
2355
2501
  }
2356
2502
 
2503
+ /**
2504
+ * A snapshot of a user's reaction to a message.
2505
+ *
2506
+ * @remarks
2507
+ * Returned from {@link ReactionsRef.getFirstReactions} and {@link ReactionsRef.subscribe}
2508
+ *
2509
+ * @public
2510
+ */
2511
+ export declare interface SingleReactionSnapshot {
2512
+ /**
2513
+ * Which user added the reaction
2514
+ */
2515
+ readonly user: UserSnapshot;
2516
+ /**
2517
+ * The timestamp of when the user added this reaction to the message
2518
+ */
2519
+ readonly createdAt: number;
2520
+ }
2521
+
2357
2522
  export declare type Subscription = {
2358
2523
  unsubscribe: () => void;
2359
2524
  };
@@ -2706,7 +2871,7 @@ export declare interface TalkSessionOptions {
2706
2871
  * }
2707
2872
  * ```
2708
2873
  *
2709
- * Rather than relying the automatic message parsing, you can also specify the `TextBlock` directly using {@link ConversationRef.send} with {@link SendMessageParams}.
2874
+ * Rather than relying on the automatic message parsing, you can also specify the `TextBlock` directly using {@link ConversationRef.send} with {@link SendMessageParams}.
2710
2875
  *
2711
2876
  * @public
2712
2877
  */
@@ -3083,8 +3248,16 @@ export declare interface UserSnapshot {
3083
3248
  * The default message a person sees when starting a chat with this user
3084
3249
  *
3085
3250
  * @remarks
3086
- * Welcome messages are rendered in the UI as messages, but they are not real messages.
3087
- * This means they do not appear when you list messages using the REST API or JS Data API, and you cannot reply or react to them.
3251
+ * Welcome messages are rendered in the UI as messages, but they are not real
3252
+ * messages. This means they do not appear when you list messages using the
3253
+ * REST API or JS Data API, and you cannot reply or react to them.
3254
+ *
3255
+ * Note: User welcome messages are only supported by the Classic SDKs, and in
3256
+ * the Components-based SDKs, this field is ignored. To show welcome messages
3257
+ * in the Components-based SDK, see
3258
+ * {@link https://talkjs.com/docs/Guides/React/Welcome_Messages/ | Welcome Messages}.
3259
+ *
3260
+ * @deprecated
3088
3261
  */
3089
3262
  readonly welcomeMessage: string | null;
3090
3263
  }
@@ -3211,7 +3384,7 @@ export declare interface VideoFileMetadata {
3211
3384
  * Includes metadata about the duration of the recording in seconds, where available.
3212
3385
  *
3213
3386
  * Voice recordings done in the TalkJS UI will always include the duration.
3214
- * Voice recording that you upload with the REST API or {@link Session.uploadVoice} will include this metadata if you specified it when uploading.
3387
+ * Voice recordings that you upload with the REST API or {@link Session.uploadVoice} will include this metadata if you specified it when uploading.
3215
3388
  *
3216
3389
  * Voice recordings will never be taken from a reply to an email notification.
3217
3390
  * Any attached audio file will become an {@link AudioBlock} instead of a voice block.