tchao 0.1.2

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/LICENSE.TXT ADDED
@@ -0,0 +1,20 @@
1
+ Licence Agreement for Now.ts, Version 1.1
2
+
3
+ This Licence Agreement ("Agreement") is made between Codelynx, LLC, the copyright holder ("Licensor") and the user ("Licensee") of the Now.ts software ("Software"), version 1.1.
4
+
5
+ Grant of Licence: Licensor hereby grants Licensee a non-exclusive, non-transferable, perpetual licence to use the Software for the purpose of developing commercial applications. Licensee is permitted to use the Software in the creation of applications that the Licensee may commercialize.
6
+
7
+ Restrictions: Licensee is expressly prohibited from modifying, distributing, sublicensing, or making available the Software to any third party. The Licensee shall not use the Software for any other purpose than as explicitly provided in this Agreement without the prior written consent of Licensor.
8
+
9
+ Ownership: The Software and all intellectual property rights therein are and shall remain the property of Licensor. The Licensee does not acquire any ownership rights to the Software under this Agreement.
10
+
11
+ No Warranty: The Software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the Licensor be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
12
+
13
+ Limitation of Liability: Licensor shall not be liable for any direct, indirect, incidental, special, consequential or exemplary damages, including but not limited to, damages for loss of profits, goodwill, use, data or other intangible losses (even if Licensor has been advised of the possibility of such damages), resulting from the Licensee's use of the Software.
14
+
15
+ Jurisdiction: This Agreement shall be governed by and construed in accordance with the laws of the United States of America, without giving effect to any principles of conflicts of law.
16
+
17
+ By using the Software, Licensee agrees to be bound by the terms of this Agreement. If Licensee does not agree to the terms of this Agreement, they must not use the Software.
18
+
19
+ Melvyn Malherbe, Codelynx LLC
20
+ 3 February 2024
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ # Tchao
2
+
3
+ JavaScript SDK for integrating the Tchao chat widget into your application.
4
+
5
+ ## Installation
6
+
7
+ ### Option 1: npm package
8
+
9
+ ```bash
10
+ npm install tchao
11
+ # or
12
+ pnpm add tchao
13
+ # or
14
+ yarn add tchao
15
+ ```
16
+
17
+ ### Option 2: Script tag
18
+
19
+ ```html
20
+ <script src="https://tchao.app/widget.js" data-website-id="your-website-id"></script>
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### npm package
26
+
27
+ ```typescript
28
+ import { Tchao } from 'tchao';
29
+
30
+ // Initialize the widget
31
+ const widget = await Tchao.init({
32
+ websiteId: 'your-website-id'
33
+ });
34
+
35
+ // Open the chat window
36
+ widget.open();
37
+ ```
38
+
39
+ ### Script tag (global object)
40
+
41
+ ```html
42
+ <script src="https://tchao.app/widget.js" data-website-id="your-website-id"></script>
43
+ <script>
44
+ // Widget auto-initializes, access via global object
45
+ window.Tchao.open();
46
+
47
+ // Listen for events
48
+ window.Tchao.on('ready', () => {
49
+ console.log('Widget ready!');
50
+ });
51
+ </script>
52
+ ```
53
+
54
+ ## API Reference
55
+
56
+ ### `Tchao.init(config)` (npm only)
57
+
58
+ Initialize the Tchao widget programmatically.
59
+
60
+ ```typescript
61
+ const widget = await Tchao.init({
62
+ websiteId: 'your-website-id', // Required
63
+ host: 'https://tchao.app' // Optional, for self-hosted instances
64
+ });
65
+ ```
66
+
67
+ Returns a `Promise<TchaoInstance>`.
68
+
69
+ ### Instance Methods
70
+
71
+ #### `widget.show()`
72
+ Show the widget launcher button.
73
+
74
+ #### `widget.hide()`
75
+ Hide the widget launcher button.
76
+
77
+ #### `widget.toggle()`
78
+ Toggle the chat window open/closed.
79
+
80
+ #### `widget.open()`
81
+ Open the chat window.
82
+
83
+ #### `widget.identify(info)`
84
+ Identify the visitor with their information.
85
+
86
+ ```typescript
87
+ widget.identify({
88
+ email: 'user@example.com',
89
+ name: 'John Doe',
90
+ avatar: 'https://example.com/avatar.jpg',
91
+ metadata: {
92
+ plan: 'pro',
93
+ userId: '12345'
94
+ }
95
+ });
96
+ ```
97
+
98
+ #### `widget.config(options)`
99
+ Update widget configuration.
100
+
101
+ ```typescript
102
+ widget.config({
103
+ position: 'bottom-left', // 'bottom-right' | 'bottom-left'
104
+ primaryColor: '#6366f1',
105
+ themeMode: 'dark' // 'light' | 'dark' | 'system'
106
+ });
107
+ ```
108
+
109
+ #### `widget.on(event, callback)`
110
+ Subscribe to widget events.
111
+
112
+ ```typescript
113
+ widget.on('message', (message) => {
114
+ console.log('New message:', message.content);
115
+ });
116
+
117
+ widget.on('open', () => {
118
+ console.log('Chat opened');
119
+ });
120
+
121
+ widget.on('close', () => {
122
+ console.log('Chat closed');
123
+ });
124
+
125
+ widget.on('ready', () => {
126
+ console.log('Widget ready');
127
+ });
128
+ ```
129
+
130
+ #### `widget.off(event, callback)`
131
+ Unsubscribe from widget events.
132
+
133
+ ```typescript
134
+ const handleMessage = (message) => console.log(message);
135
+ widget.on('message', handleMessage);
136
+ widget.off('message', handleMessage);
137
+ ```
138
+
139
+ #### `widget.destroy()` (npm only)
140
+ Clean up and remove the widget from the page.
141
+
142
+ ```typescript
143
+ widget.destroy();
144
+ ```
145
+
146
+ ## TypeScript
147
+
148
+ Full TypeScript support is included. Import types as needed:
149
+
150
+ ```typescript
151
+ import type {
152
+ TchaoConfig,
153
+ TchaoInstance,
154
+ VisitorInfo,
155
+ Message
156
+ } from 'tchao';
157
+ ```
158
+
159
+ ## License
160
+
161
+ MIT
package/dist/npm.d.mts ADDED
@@ -0,0 +1,97 @@
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
+ type VisitorInfo = {
8
+ name?: string;
9
+ email?: string;
10
+ avatar?: string;
11
+ metadata?: Record<string, unknown>;
12
+ };
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
+ type WidgetConfig = {
29
+ websiteId: string;
30
+ apiBaseUrl: string;
31
+ convexUrl?: string;
32
+ position?: WidgetPosition;
33
+ primaryColor?: string;
34
+ widgetStyle?: WidgetStyle;
35
+ themeMode?: ThemeMode;
36
+ };
37
+ type SDKEventMap = {
38
+ message: (message: Message) => void;
39
+ open: () => void;
40
+ close: () => void;
41
+ ready: () => void;
42
+ };
43
+ type SDKMethods = {
44
+ show: () => void;
45
+ hide: () => void;
46
+ toggle: () => void;
47
+ open: () => void;
48
+ 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;
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 & {
88
+ destroy: () => void;
89
+ };
90
+ type TchaoEvents = SDKEventMap;
91
+
92
+ declare function init(config: TchaoConfig): Promise<TchaoInstance>;
93
+ declare const Tchao: {
94
+ init: typeof init;
95
+ };
96
+
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 };
package/dist/npm.d.ts ADDED
@@ -0,0 +1,97 @@
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
+ type VisitorInfo = {
8
+ name?: string;
9
+ email?: string;
10
+ avatar?: string;
11
+ metadata?: Record<string, unknown>;
12
+ };
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
+ type WidgetConfig = {
29
+ websiteId: string;
30
+ apiBaseUrl: string;
31
+ convexUrl?: string;
32
+ position?: WidgetPosition;
33
+ primaryColor?: string;
34
+ widgetStyle?: WidgetStyle;
35
+ themeMode?: ThemeMode;
36
+ };
37
+ type SDKEventMap = {
38
+ message: (message: Message) => void;
39
+ open: () => void;
40
+ close: () => void;
41
+ ready: () => void;
42
+ };
43
+ type SDKMethods = {
44
+ show: () => void;
45
+ hide: () => void;
46
+ toggle: () => void;
47
+ open: () => void;
48
+ 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;
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 & {
88
+ destroy: () => void;
89
+ };
90
+ type TchaoEvents = SDKEventMap;
91
+
92
+ declare function init(config: TchaoConfig): Promise<TchaoInstance>;
93
+ declare const Tchao: {
94
+ init: typeof init;
95
+ };
96
+
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 };