tchao 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,10 @@ yarn add tchao
17
17
  ### Option 2: Script tag
18
18
 
19
19
  ```html
20
- <script src="https://tchao.app/widget.js" data-website-id="your-website-id"></script>
20
+ <script
21
+ src="https://tchao.app/widget.js"
22
+ data-website-id="your-website-id"
23
+ ></script>
21
24
  ```
22
25
 
23
26
  ## Usage
@@ -25,11 +28,11 @@ yarn add tchao
25
28
  ### npm package
26
29
 
27
30
  ```typescript
28
- import { Tchao } from 'tchao';
31
+ import { Tchao } from "tchao";
29
32
 
30
33
  // Initialize the widget
31
34
  const widget = await Tchao.init({
32
- websiteId: 'your-website-id'
35
+ websiteId: "your-website-id",
33
36
  });
34
37
 
35
38
  // Open the chat window
@@ -39,14 +42,17 @@ widget.open();
39
42
  ### Script tag (global object)
40
43
 
41
44
  ```html
42
- <script src="https://tchao.app/widget.js" data-website-id="your-website-id"></script>
45
+ <script
46
+ src="https://tchao.app/widget.js"
47
+ data-website-id="your-website-id"
48
+ ></script>
43
49
  <script>
44
50
  // Widget auto-initializes, access via global object
45
51
  window.Tchao.open();
46
52
 
47
53
  // Listen for events
48
- window.Tchao.on('ready', () => {
49
- console.log('Widget ready!');
54
+ window.Tchao.on("ready", () => {
55
+ console.log("Widget ready!");
50
56
  });
51
57
  </script>
52
58
  ```
@@ -59,8 +65,8 @@ Initialize the Tchao widget programmatically.
59
65
 
60
66
  ```typescript
61
67
  const widget = await Tchao.init({
62
- websiteId: 'your-website-id', // Required
63
- host: 'https://tchao.app' // Optional, for self-hosted instances
68
+ websiteId: "your-website-id", // Required
69
+ host: "https://tchao.app", // Optional, for self-hosted instances
64
70
  });
65
71
  ```
66
72
 
@@ -69,74 +75,83 @@ Returns a `Promise<TchaoInstance>`.
69
75
  ### Instance Methods
70
76
 
71
77
  #### `widget.show()`
78
+
72
79
  Show the widget launcher button.
73
80
 
74
81
  #### `widget.hide()`
82
+
75
83
  Hide the widget launcher button.
76
84
 
77
85
  #### `widget.toggle()`
86
+
78
87
  Toggle the chat window open/closed.
79
88
 
80
89
  #### `widget.open()`
90
+
81
91
  Open the chat window.
82
92
 
83
93
  #### `widget.identify(info)`
94
+
84
95
  Identify the visitor with their information.
85
96
 
86
97
  ```typescript
87
98
  widget.identify({
88
- email: 'user@example.com',
89
- name: 'John Doe',
90
- avatar: 'https://example.com/avatar.jpg',
99
+ email: "user@example.com",
100
+ name: "John Doe",
101
+ avatar: "https://example.com/avatar.jpg",
91
102
  metadata: {
92
- plan: 'pro',
93
- userId: '12345'
94
- }
103
+ plan: "pro",
104
+ userId: "12345",
105
+ },
95
106
  });
96
107
  ```
97
108
 
98
109
  #### `widget.config(options)`
110
+
99
111
  Update widget configuration.
100
112
 
101
113
  ```typescript
102
114
  widget.config({
103
- position: 'bottom-left', // 'bottom-right' | 'bottom-left'
104
- primaryColor: '#6366f1',
105
- themeMode: 'dark' // 'light' | 'dark' | 'system'
115
+ position: "bottom-left", // 'bottom-right' | 'bottom-left'
116
+ primaryColor: "#6366f1",
117
+ themeMode: "dark", // 'light' | 'dark' | 'system'
106
118
  });
107
119
  ```
108
120
 
109
121
  #### `widget.on(event, callback)`
122
+
110
123
  Subscribe to widget events.
111
124
 
112
125
  ```typescript
113
- widget.on('message', (message) => {
114
- console.log('New message:', message.content);
126
+ widget.on("message", (message) => {
127
+ console.log("New message:", message.content);
115
128
  });
116
129
 
117
- widget.on('open', () => {
118
- console.log('Chat opened');
130
+ widget.on("open", () => {
131
+ console.log("Chat opened");
119
132
  });
120
133
 
121
- widget.on('close', () => {
122
- console.log('Chat closed');
134
+ widget.on("close", () => {
135
+ console.log("Chat closed");
123
136
  });
124
137
 
125
- widget.on('ready', () => {
126
- console.log('Widget ready');
138
+ widget.on("ready", () => {
139
+ console.log("Widget ready");
127
140
  });
128
141
  ```
129
142
 
130
143
  #### `widget.off(event, callback)`
144
+
131
145
  Unsubscribe from widget events.
132
146
 
133
147
  ```typescript
134
148
  const handleMessage = (message) => console.log(message);
135
- widget.on('message', handleMessage);
136
- widget.off('message', handleMessage);
149
+ widget.on("message", handleMessage);
150
+ widget.off("message", handleMessage);
137
151
  ```
138
152
 
139
153
  #### `widget.destroy()` (npm only)
154
+
140
155
  Clean up and remove the widget from the page.
141
156
 
142
157
  ```typescript
@@ -148,12 +163,7 @@ widget.destroy();
148
163
  Full TypeScript support is included. Import types as needed:
149
164
 
150
165
  ```typescript
151
- import type {
152
- TchaoConfig,
153
- TchaoInstance,
154
- VisitorInfo,
155
- Message
156
- } from 'tchao';
166
+ import type { TchaoConfig, TchaoInstance, VisitorInfo, Message } from "tchao";
157
167
  ```
158
168
 
159
169
  ## License
package/dist/npm.d.mts CHANGED
@@ -1,97 +1,37 @@
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;
31
- convexUrl?: string;
32
- position?: WidgetPosition;
9
+ position?: "bottom-right" | "bottom-left";
33
10
  primaryColor?: string;
34
- widgetStyle?: WidgetStyle;
35
- themeMode?: ThemeMode;
36
11
  };
37
- type SDKEventMap = {
38
- message: (message: Message) => void;
39
- open: () => void;
40
- close: () => void;
41
- ready: () => void;
12
+ type TchaoConfig = {
13
+ websiteId: string;
14
+ host?: string;
42
15
  };
43
- type SDKMethods = {
16
+ type TchaoInstance = {
44
17
  show: () => void;
45
18
  hide: () => void;
46
19
  toggle: () => void;
47
20
  open: () => void;
48
21
  identify: (info: VisitorInfo) => void;
49
22
  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;
52
- };
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;
84
- };
85
-
86
- type TchaoConfig = TchaoInitConfig;
87
- type TchaoInstance = SDKMethods & {
23
+ on: (event: string, callback: (...args: unknown[]) => void) => void;
24
+ off: (event: string, callback: (...args: unknown[]) => void) => void;
88
25
  destroy: () => void;
89
26
  };
90
- type TchaoEvents = SDKEventMap;
91
-
27
+ declare global {
28
+ interface Window {
29
+ Tchao?: TchaoInstance;
30
+ }
31
+ }
92
32
  declare function init(config: TchaoConfig): Promise<TchaoInstance>;
93
33
  declare const Tchao: {
94
34
  init: typeof init;
95
35
  };
96
36
 
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 };
37
+ export { Tchao, type TchaoConfig, type TchaoInstance, type VisitorInfo, type WidgetConfig, Tchao as default, init };
package/dist/npm.d.ts CHANGED
@@ -1,97 +1,37 @@
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;
31
- convexUrl?: string;
32
- position?: WidgetPosition;
9
+ position?: "bottom-right" | "bottom-left";
33
10
  primaryColor?: string;
34
- widgetStyle?: WidgetStyle;
35
- themeMode?: ThemeMode;
36
11
  };
37
- type SDKEventMap = {
38
- message: (message: Message) => void;
39
- open: () => void;
40
- close: () => void;
41
- ready: () => void;
12
+ type TchaoConfig = {
13
+ websiteId: string;
14
+ host?: string;
42
15
  };
43
- type SDKMethods = {
16
+ type TchaoInstance = {
44
17
  show: () => void;
45
18
  hide: () => void;
46
19
  toggle: () => void;
47
20
  open: () => void;
48
21
  identify: (info: VisitorInfo) => void;
49
22
  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;
52
- };
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;
84
- };
85
-
86
- type TchaoConfig = TchaoInitConfig;
87
- type TchaoInstance = SDKMethods & {
23
+ on: (event: string, callback: (...args: unknown[]) => void) => void;
24
+ off: (event: string, callback: (...args: unknown[]) => void) => void;
88
25
  destroy: () => void;
89
26
  };
90
- type TchaoEvents = SDKEventMap;
91
-
27
+ declare global {
28
+ interface Window {
29
+ Tchao?: TchaoInstance;
30
+ }
31
+ }
92
32
  declare function init(config: TchaoConfig): Promise<TchaoInstance>;
93
33
  declare const Tchao: {
94
34
  init: typeof init;
95
35
  };
96
36
 
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 };
37
+ export { Tchao, type TchaoConfig, type TchaoInstance, type VisitorInfo, type WidgetConfig, Tchao as default, init };