tchao 0.1.2 → 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.
package/dist/npm.d.ts CHANGED
@@ -1,97 +1,134 @@
1
- type SenderType = "VISITOR" | "AGENT" | "AI" | "SYSTEM";
2
- type ConversationStatus = "OPEN" | "IN_PROGRESS" | "CLOSED";
3
- type MessageStatus = "sending" | "sent" | "failed";
4
- type WidgetPosition = "bottom-right" | "bottom-left";
5
- type WidgetStyle = "bubble" | "name_line" | "question_cta";
6
- type ThemeMode = "light" | "dark" | "system";
7
1
  type VisitorInfo = {
8
2
  name?: string;
9
3
  email?: string;
10
4
  avatar?: string;
11
5
  metadata?: Record<string, unknown>;
12
6
  };
13
- type MessageReaction = {
14
- emoji: string;
15
- userIds: string[];
16
- };
17
- type Message = {
18
- id: string;
19
- content: string;
20
- senderType: SenderType;
21
- senderId: string;
22
- screenshot?: string | null;
23
- image?: string | null;
24
- timestamp: number;
25
- status?: MessageStatus;
26
- reactions?: MessageReaction[] | null;
27
- };
28
7
  type WidgetConfig = {
29
8
  websiteId: string;
30
- apiBaseUrl: string;
9
+ position?: "bottom-right" | "bottom-left";
10
+ primaryColor?: string;
11
+ widgetStyle?: "bubble" | "name_line" | "question_cta";
12
+ themeMode?: "light" | "dark" | "system";
13
+ agentName?: string;
14
+ agentRole?: string;
15
+ agentImage?: string;
16
+ agentWelcomeMessage?: string;
17
+ hidePoweredBy?: boolean;
18
+ bubbleIcon?: string;
19
+ };
20
+ type TchaoConfig = {
21
+ websiteId: string;
22
+ host?: string;
31
23
  convexUrl?: string;
32
- position?: WidgetPosition;
24
+ position?: "bottom-right" | "bottom-left";
33
25
  primaryColor?: string;
34
- widgetStyle?: WidgetStyle;
35
- themeMode?: ThemeMode;
26
+ widgetStyle?: "bubble" | "name_line" | "question_cta";
27
+ themeMode?: "light" | "dark" | "system";
28
+ agentName?: string;
29
+ agentRole?: string;
30
+ agentImage?: string;
31
+ agentWelcomeMessage?: string;
32
+ hidePoweredBy?: boolean;
33
+ bubbleIcon?: string;
36
34
  };
37
- type SDKEventMap = {
35
+ type Message = {
36
+ content: string;
37
+ sender: string;
38
+ timestamp: number;
39
+ };
40
+ type TchaoEventMap = {
38
41
  message: (message: Message) => void;
39
42
  open: () => void;
40
43
  close: () => void;
41
44
  ready: () => void;
42
45
  };
43
- type SDKMethods = {
46
+ type TchaoEvent = keyof TchaoEventMap;
47
+ type TchaoInstance = {
44
48
  show: () => void;
45
49
  hide: () => void;
46
50
  toggle: () => void;
47
- open: () => void;
51
+ open: (message?: string) => void;
48
52
  identify: (info: VisitorInfo) => void;
49
- config: (opts: Partial<WidgetConfig>) => void;
50
- on: <K extends keyof SDKEventMap>(event: K, callback: SDKEventMap[K]) => void;
51
- off: <K extends keyof SDKEventMap>(event: K, callback: SDKEventMap[K]) => void;
53
+ config: () => Partial<WidgetConfig>;
54
+ on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
55
+ off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
56
+ destroy: () => void;
57
+ isReady: () => boolean;
52
58
  };
53
-
54
- declare class TchaoSDK implements SDKMethods {
55
- private readonly listeners;
56
- private showCallback;
57
- private hideCallback;
58
- private toggleCallback;
59
- private openCallback;
60
- private identifyCallback;
61
- private configCallback;
62
- setCallbacks(callbacks: {
63
- show: () => void;
64
- hide: () => void;
65
- toggle: () => void;
66
- open: () => void;
67
- identify: (info: VisitorInfo) => void;
68
- config: (opts: Partial<WidgetConfig>) => void;
69
- }): void;
70
- show(): void;
71
- hide(): void;
72
- toggle(): void;
73
- open(): void;
74
- identify(info: VisitorInfo): void;
75
- config(opts: Partial<WidgetConfig>): void;
76
- on<K extends keyof SDKEventMap>(event: K, callback: SDKEventMap[K]): void;
77
- off<K extends keyof SDKEventMap>(event: K, callback: SDKEventMap[K]): void;
78
- emit<K extends keyof SDKEventMap>(event: K, ...args: Parameters<SDKEventMap[K]>): void;
79
- }
80
-
81
- type TchaoInitConfig = {
82
- websiteId: string;
83
- host?: string;
59
+ type InternalTchaoInstance = {
60
+ show: () => void;
61
+ hide: () => void;
62
+ toggle: () => void;
63
+ open: (message?: string) => void;
64
+ identify: (info: VisitorInfo) => void;
65
+ config: () => Partial<WidgetConfig>;
66
+ on: (event: string, callback: (...args: unknown[]) => void) => void;
67
+ off: (event: string, callback: (...args: unknown[]) => void) => void;
84
68
  };
85
-
86
- type TchaoConfig = TchaoInitConfig;
87
- type TchaoInstance = SDKMethods & {
69
+ declare global {
70
+ interface Window {
71
+ Tchao?: InternalTchaoInstance;
72
+ __TCHAO_CONFIG__?: TchaoConfig;
73
+ }
74
+ }
75
+ declare function init(config: TchaoConfig): Promise<TchaoInstance>;
76
+ /**
77
+ * Safe API that works before initialization.
78
+ * Calls are queued and executed once the widget is ready.
79
+ */
80
+ declare const tchao: {
81
+ /**
82
+ * Initialize the widget. Returns a promise that resolves with the instance.
83
+ */
84
+ init: typeof init;
85
+ /**
86
+ * Show the widget launcher. Safe to call before init.
87
+ */
88
+ show: () => void;
89
+ /**
90
+ * Hide the widget launcher. Safe to call before init.
91
+ */
92
+ hide: () => void;
93
+ /**
94
+ * Toggle the chat window. Safe to call before init.
95
+ */
96
+ toggle: () => void;
97
+ /**
98
+ * Open the chat window. Safe to call before init.
99
+ */
100
+ open: (message?: string) => void;
101
+ /**
102
+ * Identify the visitor. Safe to call before init.
103
+ */
104
+ identify: (info: VisitorInfo) => void;
105
+ /**
106
+ * Get the current widget configuration.
107
+ */
108
+ config: () => Partial<WidgetConfig>;
109
+ /**
110
+ * Subscribe to widget events. Safe to call before init.
111
+ */
112
+ on: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
113
+ /**
114
+ * Unsubscribe from widget events.
115
+ */
116
+ off: <E extends TchaoEvent>(event: E, callback: TchaoEventMap[E]) => void;
117
+ /**
118
+ * Destroy the widget and clean up resources.
119
+ */
88
120
  destroy: () => void;
121
+ /**
122
+ * Check if the widget is ready.
123
+ */
124
+ isReady: () => boolean;
125
+ /**
126
+ * Get the current instance (null if not initialized).
127
+ */
128
+ getInstance: () => TchaoInstance | null;
89
129
  };
90
- type TchaoEvents = SDKEventMap;
91
-
92
- declare function init(config: TchaoConfig): Promise<TchaoInstance>;
93
130
  declare const Tchao: {
94
131
  init: typeof init;
95
132
  };
96
133
 
97
- export { type ConversationStatus, type Message, type MessageReaction, type MessageStatus, type SenderType, Tchao, type TchaoConfig, type TchaoEvents, type TchaoInstance, TchaoSDK, type ThemeMode, type VisitorInfo, type WidgetConfig, type WidgetPosition, type WidgetStyle, Tchao as default, init };
134
+ export { type Message, Tchao, type TchaoConfig, type TchaoEvent, type TchaoEventMap, type TchaoInstance, type VisitorInfo, type WidgetConfig, Tchao as default, init, tchao };