@dialtribe/chat-client 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as react from 'react';
2
+ import { ReactNode } from 'react';
2
3
 
3
4
  /**
4
5
  * Minimal observable store: an immutable snapshot plus change listeners. Shaped
@@ -94,6 +95,57 @@ interface DmParticipant {
94
95
  avatarUrl: string | null;
95
96
  status: DmMemberStatus;
96
97
  }
98
+ /** Another Dialtribe-identity site a person uses (mini-profile "Also on"). */
99
+ interface ProfileSite {
100
+ appId: string;
101
+ siteName: string;
102
+ iconUrl: string | null;
103
+ /** Their profile there, else the site itself, else null. */
104
+ url: string | null;
105
+ }
106
+ /**
107
+ * A person's mini-profile (GET /api/public/v1/chat/profiles/:userId), for apps
108
+ * on Dialtribe identity. In the fallback for other apps it is built from what
109
+ * chat already knows (name and avatar), with no handle, bio or sites.
110
+ */
111
+ interface DialtribeProfile {
112
+ userId: string;
113
+ name: string;
114
+ handle: string | null;
115
+ avatarUrl: string | null;
116
+ bio: string | null;
117
+ /** This site's profile page, when it has one. */
118
+ current: {
119
+ appId: string;
120
+ siteName: string;
121
+ profileUrl: string;
122
+ } | null;
123
+ apps: ProfileSite[];
124
+ /** Whether a new conversation would be allowed. */
125
+ canMessage: boolean;
126
+ }
127
+ /** Someone you can start a conversation with (people search, recent contacts). */
128
+ interface PersonSummary {
129
+ userId: string;
130
+ name: string;
131
+ handle: string | null;
132
+ avatarUrl: string | null;
133
+ }
134
+ /** Result of starting a group: who was added, and who couldn't be (their DMs are closed). */
135
+ interface GroupCreateResult {
136
+ roomId: string;
137
+ added: string[];
138
+ refused: string[];
139
+ }
140
+ /** getProfile: "not_supported" when the app isn't on Dialtribe identity, "hidden" when the profile isn't visible. */
141
+ type ProfileLookup = {
142
+ status: "ok";
143
+ profile: DialtribeProfile;
144
+ } | {
145
+ status: "not_supported";
146
+ } | {
147
+ status: "hidden";
148
+ };
97
149
  /** One row of the signed-in user's DM inbox, from their perspective. */
98
150
  interface DmRoomSummary {
99
151
  roomId: string;
@@ -331,6 +383,12 @@ declare class InboxStore extends Store<InboxSnapshot> {
331
383
  ignoreDM(requestId: string): Promise<void>;
332
384
  closeDM(roomId: string): Promise<void>;
333
385
  reopenDM(roomId: string): Promise<void>;
386
+ /**
387
+ * Start a group with several people in one step. Each person's DM settings
388
+ * apply: those whose DMs are closed come back in `refused`. If only one
389
+ * person is left, `roomId` is your 1:1 with them.
390
+ */
391
+ createGroup(targetUserIds: string[]): Promise<GroupCreateResult>;
334
392
  /** Add someone. Returns the room to show (a new group when added to a 1:1). */
335
393
  addParticipant(roomId: string, targetUserId: string, hint?: {
336
394
  name?: string;
@@ -411,7 +469,7 @@ interface ChatClientOptions {
411
469
  /** chat-ws base URL, e.g. "https://chatws.dialtribe.com". */
412
470
  serverUrl: string;
413
471
  /**
414
- * Dialtribe API base URL for services outside chat-ws (notifications).
472
+ * Dialtribe API base URL for services outside chat-ws (notifications, profiles).
415
473
  * Defaults to "https://dialtribe.com". Uses the same session token.
416
474
  */
417
475
  apiUrl?: string;
@@ -473,6 +531,7 @@ declare class ChatClient {
473
531
  private rooms;
474
532
  private inboxStore;
475
533
  private notificationsStore;
534
+ private profiles;
476
535
  constructor(options: ChatClientOptions);
477
536
  /** Connect. Idempotent; resolves once the connection has been initiated. */
478
537
  start(): Promise<void>;
@@ -517,6 +576,16 @@ declare class ChatClient {
517
576
  method?: "GET" | "POST";
518
577
  body?: unknown;
519
578
  }): Promise<T>;
579
+ /**
580
+ * A person's mini-profile from Dialtribe, memoized per user for the life of
581
+ * the client. Network failures aren't remembered, so the next call retries.
582
+ */
583
+ getProfile(userId: string): Promise<ProfileLookup>;
584
+ /**
585
+ * People whose handle starts with `query` (2+ characters), among those you can
586
+ * reach through this app's organization. Empty for apps not on Dialtribe identity.
587
+ */
588
+ searchPeople(query: string): Promise<PersonSummary[]>;
520
589
  /** A DM action on POST /dm (see DMS.md). */
521
590
  dm<T = Record<string, unknown>>(action: string, fields?: Record<string, unknown>): Promise<T>;
522
591
  /**
@@ -542,7 +611,26 @@ type MessagesView = {
542
611
  | {
543
612
  kind: "item";
544
613
  itemId: string;
614
+ }
615
+ /**
616
+ * A person's mini-profile. Back returns to `from`. `hint` is what the click
617
+ * already knew (name, avatar), shown at once and as the fallback.
618
+ */
619
+ | {
620
+ kind: "profile";
621
+ userId: string;
622
+ from: MessagesView;
623
+ hint?: ProfileHint;
624
+ }
625
+ /** "Start new": pick people to message. Back returns to `from`. */
626
+ | {
627
+ kind: "compose";
628
+ from: MessagesView;
545
629
  };
630
+ interface ProfileHint {
631
+ name?: string;
632
+ avatarUrl?: string | null;
633
+ }
546
634
  interface MessagesUiSnapshot {
547
635
  open: boolean;
548
636
  view: MessagesView;
@@ -661,6 +749,17 @@ interface UseDialtribeMessagesReturn {
661
749
  openItem: (itemId: string) => void;
662
750
  /** Open the notifications panel (when the rail shows notifications). */
663
751
  openNotifications: () => void;
752
+ /** Show a person's mini-profile in the rail; back returns to the current view. */
753
+ openProfile: (userId: string, hint?: ProfileHint) => void;
754
+ /** From a mini-profile or the composer, go back to where it was opened. */
755
+ back: () => void;
756
+ /** Open the "Start new" composer. */
757
+ openCompose: () => void;
758
+ /**
759
+ * Start a conversation with one person (their 1:1) or several (a new group)
760
+ * and show it. For a group, `refused` lists people whose DMs are closed.
761
+ */
762
+ startConversation: (userIds: string[]) => Promise<GroupCreateResult>;
664
763
  /**
665
764
  * Start (or reopen) a DM with one of your users and show it. `hint` is only a
666
765
  * display name for someone Dialtribe hasn't seen yet. Rejects with
@@ -742,6 +841,34 @@ interface MessagesLabels {
742
841
  groupMore: (count: number) => string;
743
842
  /** Relative times: "now", "5m", "3h", "2d". */
744
843
  timeAgo: (date: Date) => string;
844
+ /** Mini-profile primary button: "View Prankcast profile" ("View profile" without a site name). */
845
+ viewSiteProfile: (site: string) => string;
846
+ /** Mini-profile: the other sites the person uses. */
847
+ alsoOn: string;
848
+ /** Mini-profile: start a conversation. */
849
+ message: string;
850
+ /** aria-label of a person's name or avatar: "View profile of {name}". */
851
+ viewProfileOf: (name: string) => string;
852
+ /** aria-label of a group conversation's title, which lists its members. */
853
+ members: string;
854
+ /** Messages header button and composer title. */
855
+ newMessage: string;
856
+ /** Composer search field placeholder. */
857
+ searchPeople: string;
858
+ /** Composer: people you've talked with, before you search. */
859
+ recent: string;
860
+ /** Composer: the search found nobody. */
861
+ noPeopleFound: string;
862
+ /** Composer: start the conversation. */
863
+ start: string;
864
+ /** Composer: some people couldn't be added ("Sam, Lee can't be messaged right now"). */
865
+ cantMessage: (names: string) => string;
866
+ /** Composer: go to the conversation after some people couldn't be added. */
867
+ openConversation: string;
868
+ /** aria-label for removing a picked person: "Remove {name}". */
869
+ removePerson: (name: string) => string;
870
+ /** Composer: starting failed for another reason (network). */
871
+ startFailed: string;
745
872
  }
746
873
  declare const DEFAULT_LABELS: MessagesLabels;
747
874
 
@@ -833,6 +960,13 @@ interface DialtribeMessagesProps {
833
960
  notifications?: boolean | {
834
961
  onOpen?: (item: NotificationItem) => boolean | void;
835
962
  };
963
+ /**
964
+ * Apps not on Dialtribe identity: your profile page for a user, shown as the
965
+ * mini-profile's primary button. Opted-in apps get theirs from Dialtribe.
966
+ */
967
+ getProfileUrl?: (userId: string) => string | null;
968
+ /** Your own buttons on a mini-profile, under Message (e.g. Block, which you push to Dialtribe). */
969
+ profileActions?: (profile: DialtribeProfile) => React.ReactNode;
836
970
  }
837
971
  /**
838
972
  * Drop-in messages rail: inbox, DM requests, conversations, and any host
@@ -849,7 +983,7 @@ interface DialtribeMessagesProps {
849
983
  * </DialtribeChatProvider>
850
984
  * ```
851
985
  */
852
- declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, notifications, }: DialtribeMessagesProps): react.JSX.Element;
986
+ declare function DialtribeMessages({ side, placement, openPlacement, items, inboxRowClose, contexts, theme, labels: labelOverrides, panelWidth, railDmLimit, mobileBreakpoint, confirm: hostConfirm, notifications, getProfileUrl, profileActions, }: DialtribeMessagesProps): react.JSX.Element;
853
987
 
854
988
  interface NotificationsPanelProps {
855
989
  labels: MessagesLabels;
@@ -868,6 +1002,43 @@ interface NotificationsPanelProps {
868
1002
  */
869
1003
  declare function NotificationsPanel({ labels, onClose, onOpen, onOpened }: NotificationsPanelProps): react.JSX.Element;
870
1004
 
1005
+ interface ProfileViewProps {
1006
+ userId: string;
1007
+ hint?: ProfileHint;
1008
+ labels: MessagesLabels;
1009
+ onBack: () => void;
1010
+ onClose: () => void;
1011
+ /** The current site's profile link was followed (same tab). */
1012
+ onNavigate: () => void;
1013
+ /** Start or open a conversation with this person. */
1014
+ onMessage: (userId: string, hint: ProfileHint) => void;
1015
+ /** Hide Message (viewing yourself, or already in your 1:1 with them). */
1016
+ hideMessage: boolean;
1017
+ /** Apps not on Dialtribe identity: the host's own profile URL for this person. */
1018
+ getProfileUrl?: (userId: string) => string | null;
1019
+ /** Host-owned buttons under Message (e.g. Block). */
1020
+ profileActions?: (profile: DialtribeProfile) => ReactNode;
1021
+ }
1022
+ /**
1023
+ * A person's mini-profile in the rail: avatar, name, handle, bio, this site's
1024
+ * profile (primary), the other Dialtribe sites they use, and Message.
1025
+ */
1026
+ declare function ProfileView({ userId, hint, labels, onBack, onClose, onNavigate, onMessage, hideMessage, getProfileUrl, profileActions, }: ProfileViewProps): react.JSX.Element;
1027
+
1028
+ interface ComposeViewProps {
1029
+ labels: MessagesLabels;
1030
+ onBack: () => void;
1031
+ onClose: () => void;
1032
+ /** Show the conversation that was started. */
1033
+ onOpenRoom: (roomId: string) => void;
1034
+ }
1035
+ /**
1036
+ * "Start new": pick one person (opens your 1:1) or several (starts a group).
1037
+ * Before you type, it lists people you've talked with; typing 2+ characters
1038
+ * searches handles.
1039
+ */
1040
+ declare function ComposeView({ labels, onBack, onClose, onOpenRoom }: ComposeViewProps): react.JSX.Element;
1041
+
871
1042
  interface AvatarProps {
872
1043
  name: string;
873
1044
  url?: string | null;
@@ -896,6 +1067,14 @@ interface ChatPanelProps {
896
1067
  emptyLabel?: string;
897
1068
  /** Input placeholder. */
898
1069
  placeholder?: string;
1070
+ /** Make authors' names and avatars buttons (e.g. to open a profile). */
1071
+ onAuthorClick?: (author: {
1072
+ userId: string;
1073
+ name: string;
1074
+ avatarUrl: string | null;
1075
+ }) => void;
1076
+ /** aria-label for an author button: "View profile of {name}". */
1077
+ authorLabel?: (name: string) => string;
899
1078
  }
900
1079
  /**
901
1080
  * Full chat panel with messages, input, pinned messages, and typing indicators.
@@ -908,13 +1087,17 @@ interface ChatPanelProps {
908
1087
  * </ChatRoomProvider>
909
1088
  * ```
910
1089
  */
911
- declare function ChatPanel({ className, showModActions, showTypingIndicators, showPinnedMessages, showHeader, showAvatars, canSend, emptyLabel, placeholder, }: ChatPanelProps): react.JSX.Element;
1090
+ declare function ChatPanel({ className, showModActions, showTypingIndicators, showPinnedMessages, showHeader, showAvatars, canSend, emptyLabel, placeholder, onAuthorClick, authorLabel, }: ChatPanelProps): react.JSX.Element;
912
1091
 
913
1092
  interface ChatMessageItemProps {
914
1093
  message: ChatMessage;
915
1094
  config: ChatRoomConfig | null;
916
1095
  /** Show the author's avatar beside the message (DM style). */
917
1096
  showAvatar?: boolean;
1097
+ /** Render the author's name and avatar as buttons that call this. */
1098
+ onAuthorClick?: () => void;
1099
+ /** aria-label for those buttons (default "View profile of {name}"). */
1100
+ authorLabel?: (name: string) => string;
918
1101
  onReply?: () => void;
919
1102
  onReact?: (messageId: string, emoji: string) => void;
920
1103
  /** Additional mod actions (feature, pin, delete, ban, kick) */
@@ -929,7 +1112,7 @@ interface ChatMessageItemProps {
929
1112
  /**
930
1113
  * Renders a single chat message with role badges, flair, reactions, and reply preview.
931
1114
  */
932
- declare function ChatMessageItem({ message, config, showAvatar, onReply, onReact, modActions, }: ChatMessageItemProps): react.JSX.Element;
1115
+ declare function ChatMessageItem({ message, config, showAvatar, onAuthorClick, authorLabel, onReply, onReact, modActions, }: ChatMessageItemProps): react.JSX.Element;
933
1116
 
934
1117
  interface ChatInputProps {
935
1118
  onSendMessage: (text: string, replyToId?: string) => void;
@@ -945,4 +1128,4 @@ interface ChatInputProps {
945
1128
  */
946
1129
  declare function ChatInput({ onSendMessage, onSendTyping, replyTo, onClearReply, disabled, placeholder, maxLength, }: ChatInputProps): react.JSX.Element;
947
1130
 
948
- export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, type ConfirmFn, type ConfirmOptions, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, type ParsedReactions, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };
1131
+ export { Avatar, type AvatarProps, ChatClient, type ChatClientOptions, type ChatErrorCode, ChatInput, type ChatInputProps, type ChatMessage, ChatMessageItem, type ChatMessageItemProps, ChatPanel, type ChatPanelProps, ChatRequestError, type ChatRoomConfig, ChatRoomProvider, type ChatRoomProviderProps, type ChatSelf, ComposeView, type ComposeViewProps, type ConfirmFn, type ConfirmOptions, type ConnectionSnapshot, type ConnectionState, DEFAULT_LABELS, DialtribeChatProvider, type DialtribeChatProviderProps, DialtribeMessages, type DialtribeMessagesProps, type DialtribeProfile, type DmMemberStatus, type DmParticipant, type DmRequestResult, type DmRoomSummary, type Flair, type GroupCreateResult, type InboxSnapshot, type MessagesContext, type MessagesLabels, type MessagesTheme, type MessagesUiSnapshot, type MessagesView, type NotificationItem, NotificationsPanel, type NotificationsPanelProps, type NotificationsSnapshot, type ParsedReactions, type PersonSummary, type ProfileHint, type ProfileLookup, type ProfileSite, ProfileView, type ProfileViewProps, type RailItem, type RichMediaConfig, type RoomEvent, type RoomInit, type RoomSnapshot, type RoomState, type TypingUser, type UseChatRoomsReturn, type UseDialtribeChatOptions, type UseDialtribeChatReturn, type UseDialtribeMessagesReturn, type UseDialtribeNotificationsReturn, type UserEvent, parseReactions, useChatClient, useChatConnection, useChatRoomContext, useChatRooms, useDialtribeChat, useDialtribeMessages, useDialtribeNotifications };