@chatbotkit/widget 1.25.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/README.md +95 -0
- package/dist/cjs/index.cjs +4 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/v2.cjs +2 -0
- package/dist/cjs/v2.d.ts +66 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/v2.d.ts +66 -0
- package/dist/esm/v2.js +1 -0
- package/package.json +114 -0
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[](https://chatbotkit.com)
|
|
2
|
+
[](https://cbk.ai)
|
|
3
|
+
[](https://twitter.com/chatbotkit)
|
|
4
|
+
[](https://www.npmjs.com/package/@chatbotkit/widget)
|
|
5
|
+
[](mailto:support@chatbotkit.com)
|
|
6
|
+
[](https://go.cbk.ai/discord)
|
|
7
|
+
|
|
8
|
+
# ChatBotKit Widget Types
|
|
9
|
+
|
|
10
|
+
Type definitions for the ChatBotKit widget custom element. This package provides TypeScript types for interacting with the ChatBotKit widget (v2).
|
|
11
|
+
|
|
12
|
+
## What's Included
|
|
13
|
+
|
|
14
|
+
- **`ChatBotKitWidgetElementV2`**: The main widget custom element interface with all available methods and properties
|
|
15
|
+
- **`ChatBotKitGlobalObject`**: The global `window.chatbotkitWidget` object interface
|
|
16
|
+
- **`Message`**: Type for conversation messages
|
|
17
|
+
- **`FunctionDefinition`**: Type for registering custom functions with the widget
|
|
18
|
+
- **`NotificationDefinition`**: Type for widget notifications
|
|
19
|
+
- **`Contact`**: Type for contact information
|
|
20
|
+
- **`Meta`**: Type for session metadata
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @chatbotkit/widget
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Import the types directly:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import type {
|
|
34
|
+
ChatBotKitWidgetElementV2,
|
|
35
|
+
ChatBotKitGlobalObject,
|
|
36
|
+
FunctionDefinition,
|
|
37
|
+
Message,
|
|
38
|
+
} from '@chatbotkit/widget'
|
|
39
|
+
|
|
40
|
+
// Access the widget instance
|
|
41
|
+
const widget = window.chatbotkitWidget.instance
|
|
42
|
+
|
|
43
|
+
// Or wait for it to be ready
|
|
44
|
+
const widget = await window.chatbotkitWidget.instancePromise
|
|
45
|
+
|
|
46
|
+
// Register custom functions
|
|
47
|
+
const myFunction: FunctionDefinition = {
|
|
48
|
+
description: 'Get the current user name',
|
|
49
|
+
parameters: {},
|
|
50
|
+
handler: async () => {
|
|
51
|
+
return 'John Doe'
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
widget.registerFunctions({ getUserName: myFunction })
|
|
56
|
+
|
|
57
|
+
// Send a message
|
|
58
|
+
widget.sendMessage({ text: 'Hello!' })
|
|
59
|
+
|
|
60
|
+
// Listen to messages
|
|
61
|
+
console.log(widget.messages)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Using with the Widget Script
|
|
65
|
+
|
|
66
|
+
The types augment the global `Window` interface, so you can access `window.chatbotkitWidget` with full type safety:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import '@chatbotkit/widget'
|
|
70
|
+
|
|
71
|
+
// Now window.chatbotkitWidget is typed
|
|
72
|
+
window.chatbotkitWidget.instancePromise.then((widget) => {
|
|
73
|
+
widget.open = true
|
|
74
|
+
widget.sendMessage({ text: 'Hello from TypeScript!' })
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Using with React
|
|
79
|
+
|
|
80
|
+
For React integration, consider using the `@chatbotkit/react` package which includes hooks like:
|
|
81
|
+
|
|
82
|
+
- `useWidgetInstance` - Access the widget instance
|
|
83
|
+
- `useWidgetInstanceFunctions` - Register functions with the widget
|
|
84
|
+
- `useWidgetInstanceNotifications` - Manage widget notifications
|
|
85
|
+
|
|
86
|
+
## Documentation
|
|
87
|
+
|
|
88
|
+
For more information about the ChatBotKit widget, visit:
|
|
89
|
+
|
|
90
|
+
- [ChatBotKit Documentation](https://chatbotkit.com/docs)
|
|
91
|
+
- [Type Documentation](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_widget.html)
|
|
92
|
+
|
|
93
|
+
## Contributing
|
|
94
|
+
|
|
95
|
+
Found a bug or wish to contribute? We welcome your input! Please open an issue or submit a pull request on our [official GitHub repository](https://github.com/chatbotkit/node-sdk).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v2.cjs';
|
package/dist/cjs/v2.cjs
ADDED
package/dist/cjs/v2.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
id: string;
|
|
3
|
+
type: 'user' | 'bot' | 'input';
|
|
4
|
+
text: string;
|
|
5
|
+
meta?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface FunctionDefinition {
|
|
8
|
+
description: string;
|
|
9
|
+
parameters: Record<string, unknown>;
|
|
10
|
+
handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface Contact {
|
|
13
|
+
name?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
phone?: string;
|
|
16
|
+
}
|
|
17
|
+
export type Meta = Record<string, unknown>;
|
|
18
|
+
export interface NotificationDefinition {
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
export interface InitiateMessageOptions {
|
|
22
|
+
text?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SendMessageOptions {
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RenderOptions {
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface ChatBotKitWidgetElementV2 extends HTMLElement {
|
|
31
|
+
readonly ready: boolean;
|
|
32
|
+
readonly readyPromise: Promise<boolean>;
|
|
33
|
+
messages: Message[] | null;
|
|
34
|
+
functions: Record<string, FunctionDefinition | null> | null;
|
|
35
|
+
contact: Contact | null;
|
|
36
|
+
meta: Meta | null;
|
|
37
|
+
notifications: Record<string, NotificationDefinition | null>;
|
|
38
|
+
open: boolean;
|
|
39
|
+
hide(): void;
|
|
40
|
+
show(): void;
|
|
41
|
+
restartConversation(): void;
|
|
42
|
+
initiateMessage(props: InitiateMessageOptions): void;
|
|
43
|
+
sendMessage(props: SendMessageOptions): void;
|
|
44
|
+
maximize(): void;
|
|
45
|
+
minimize(): void;
|
|
46
|
+
render(props: RenderOptions): void;
|
|
47
|
+
registerFunctions(functions: Record<string, FunctionDefinition | null>): void;
|
|
48
|
+
unregisterFunctions(functions: string[]): void;
|
|
49
|
+
assignContact(props: Contact): void;
|
|
50
|
+
}
|
|
51
|
+
export interface ChatBotKitGlobalObject {
|
|
52
|
+
readonly instance: ChatBotKitWidgetElementV2 | null;
|
|
53
|
+
readonly instancePromise: Promise<ChatBotKitWidgetElementV2>;
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
interface Window {
|
|
57
|
+
chatbotkitWidget: ChatBotKitGlobalObject;
|
|
58
|
+
CHATBOTKIT_LOG_WARNING?: boolean;
|
|
59
|
+
CHATBOTKIT_WARNING_LOG?: boolean;
|
|
60
|
+
CHATBOTKIT_LOG_ERROR?: boolean;
|
|
61
|
+
CHATBOTKIT_ERROR_LOG?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface HTMLElementTagNameMap {
|
|
64
|
+
'chatbotkit-widget': ChatBotKitWidgetElementV2;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v2.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v2.js';
|
package/dist/esm/v2.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
id: string;
|
|
3
|
+
type: 'user' | 'bot' | 'input';
|
|
4
|
+
text: string;
|
|
5
|
+
meta?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface FunctionDefinition {
|
|
8
|
+
description: string;
|
|
9
|
+
parameters: Record<string, unknown>;
|
|
10
|
+
handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface Contact {
|
|
13
|
+
name?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
phone?: string;
|
|
16
|
+
}
|
|
17
|
+
export type Meta = Record<string, unknown>;
|
|
18
|
+
export interface NotificationDefinition {
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
export interface InitiateMessageOptions {
|
|
22
|
+
text?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SendMessageOptions {
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
export interface RenderOptions {
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface ChatBotKitWidgetElementV2 extends HTMLElement {
|
|
31
|
+
readonly ready: boolean;
|
|
32
|
+
readonly readyPromise: Promise<boolean>;
|
|
33
|
+
messages: Message[] | null;
|
|
34
|
+
functions: Record<string, FunctionDefinition | null> | null;
|
|
35
|
+
contact: Contact | null;
|
|
36
|
+
meta: Meta | null;
|
|
37
|
+
notifications: Record<string, NotificationDefinition | null>;
|
|
38
|
+
open: boolean;
|
|
39
|
+
hide(): void;
|
|
40
|
+
show(): void;
|
|
41
|
+
restartConversation(): void;
|
|
42
|
+
initiateMessage(props: InitiateMessageOptions): void;
|
|
43
|
+
sendMessage(props: SendMessageOptions): void;
|
|
44
|
+
maximize(): void;
|
|
45
|
+
minimize(): void;
|
|
46
|
+
render(props: RenderOptions): void;
|
|
47
|
+
registerFunctions(functions: Record<string, FunctionDefinition | null>): void;
|
|
48
|
+
unregisterFunctions(functions: string[]): void;
|
|
49
|
+
assignContact(props: Contact): void;
|
|
50
|
+
}
|
|
51
|
+
export interface ChatBotKitGlobalObject {
|
|
52
|
+
readonly instance: ChatBotKitWidgetElementV2 | null;
|
|
53
|
+
readonly instancePromise: Promise<ChatBotKitWidgetElementV2>;
|
|
54
|
+
}
|
|
55
|
+
declare global {
|
|
56
|
+
interface Window {
|
|
57
|
+
chatbotkitWidget: ChatBotKitGlobalObject;
|
|
58
|
+
CHATBOTKIT_LOG_WARNING?: boolean;
|
|
59
|
+
CHATBOTKIT_WARNING_LOG?: boolean;
|
|
60
|
+
CHATBOTKIT_LOG_ERROR?: boolean;
|
|
61
|
+
CHATBOTKIT_ERROR_LOG?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface HTMLElementTagNameMap {
|
|
64
|
+
'chatbotkit-widget': ChatBotKitWidgetElementV2;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/esm/v2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chatbotkit/widget",
|
|
3
|
+
"version": "1.25.0",
|
|
4
|
+
"description": "Type definitions for the ChatBotKit widget custom element",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20.0.0"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/chatbotkit/node-sdk.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/chatbotkit/node-sdk/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/chatbotkit/node-sdk#readme",
|
|
17
|
+
"author": "",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"widget",
|
|
20
|
+
"chatbot",
|
|
21
|
+
"chatbotkit",
|
|
22
|
+
"types",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/cjs/index.js",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/esm/index.d.ts",
|
|
31
|
+
"default": "./dist/esm/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/cjs/index.d.ts",
|
|
35
|
+
"default": "./dist/cjs/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./index": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/esm/index.d.ts",
|
|
41
|
+
"default": "./dist/esm/index.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/cjs/index.d.ts",
|
|
45
|
+
"default": "./dist/cjs/index.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./index.js": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/esm/index.d.ts",
|
|
51
|
+
"default": "./dist/esm/index.js"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/cjs/index.d.ts",
|
|
55
|
+
"default": "./dist/cjs/index.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./v2": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/esm/v2.d.ts",
|
|
61
|
+
"default": "./dist/esm/v2.js"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./dist/cjs/v2.d.ts",
|
|
65
|
+
"default": "./dist/cjs/v2.cjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"./v2.js": {
|
|
69
|
+
"import": {
|
|
70
|
+
"types": "./dist/esm/v2.d.ts",
|
|
71
|
+
"default": "./dist/esm/v2.js"
|
|
72
|
+
},
|
|
73
|
+
"require": {
|
|
74
|
+
"types": "./dist/cjs/v2.d.ts",
|
|
75
|
+
"default": "./dist/cjs/v2.cjs"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"./package.json": "./package.json"
|
|
79
|
+
},
|
|
80
|
+
"types": "./dist/cjs/index.d.ts",
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"tslib": "^2.6.2"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"npm-run-all": "^4.1.5",
|
|
86
|
+
"typedoc": "^0.28.14",
|
|
87
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
88
|
+
"typedoc-plugin-mdn-links": "^5.0.10",
|
|
89
|
+
"typescript": "^5.9"
|
|
90
|
+
},
|
|
91
|
+
"files": [
|
|
92
|
+
"dist/**"
|
|
93
|
+
],
|
|
94
|
+
"scripts": {
|
|
95
|
+
"build": "run-s build:*",
|
|
96
|
+
"build:01-cjs": "tsc -p tsconfig.cjs.json",
|
|
97
|
+
"build:01-cjs_rename": "node ../../scripts/rename-cjs.js",
|
|
98
|
+
"build:01-cjs_rewrite_cjs": "node ../../scripts/rewrite-cjs.js",
|
|
99
|
+
"build:01-cjs_rewrite_ts": "node ../../scripts/rewrite-ts.js",
|
|
100
|
+
"build:03-docs": "typedoc",
|
|
101
|
+
"build:02-esm": "tsc -p tsconfig.esm.json",
|
|
102
|
+
"build:00-exports": "node ../../scripts/create-standard-exports.js",
|
|
103
|
+
"build:00-types": "tsc -p tsconfig.types.json",
|
|
104
|
+
"check": "tsc -p tsconfig.check.json",
|
|
105
|
+
"clean": "run-p clean:*",
|
|
106
|
+
"clean:buildinfo": "rimraf *.tsbuildinfo",
|
|
107
|
+
"clean:dists": "rimraf dist",
|
|
108
|
+
"clean:exports": "run-s build:aaa_exports",
|
|
109
|
+
"clean:node_modules": "rimraf node_modules",
|
|
110
|
+
"clean:types": "rimraf types",
|
|
111
|
+
"lint": "eslint .",
|
|
112
|
+
"test": "true"
|
|
113
|
+
}
|
|
114
|
+
}
|