@chatbotkit/react 0.8.0 โ†’ 1.1.5

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
@@ -4,72 +4,39 @@
4
4
 
5
5
  # ChatBotKit React SDK
6
6
 
7
- Welcome to the ChatBotKit React SDK. This SDK is a React solution for building conversational AI chatbots with ease. With [ChatBotKit](https://chatbotkit.com), you can quickly develop and deploy chatbots that can interact with users in natural language.
8
-
9
- ## React SDK Features
10
-
11
- - **Easy setup** - The ChatBotKit React SDK is easy to install and set up. You can have your first chatbot up and running in minutes.
12
- - **No styles** - ChatBotKit React SDK does not enforce any styles. You can easily style your applications just the way you want them.
13
- - **Modern** - A modern SDK with built-in support for CommonJS, ECMAScript Modules, async/await, streams and much more.
14
- - **Customizable** - You can easily customize the chatbot's behavior and responses to fit your specific use case.
15
-
16
- ## ChatBotKit Features
17
-
18
- - ๐Ÿ—จ **Chat History**: Easily review and reference previous conversations with your bots, ensuring that it has all the information it needs.
19
- - ๐Ÿ’พ **Custom Datasets**: Manage and organize the data that your chat bots use to respond to user input with bespoke datasets.
20
- - ๐ŸŽฌ **Media File Importing**: Import MP3, MP4, MPEG, WAV and many other media files directly into your your chatbot datasets
21
- - ๐ŸŒ **Widget Integration**: Embed ChatBotKit chatbots directly on any website using advanced customization options and theming.
22
- - ๐Ÿ’ฌ **Slack Bot Integration**: Create and deploy wide-range of Slack bot integrations with just a few click.
23
- - ๐ŸŽฎ **Discord Bot Integration**: Create and deploy wide-range of Discord chat bot with just a few click.
24
- - ๐Ÿ“ฑ **WhatsApp Bot Integration**: Connect with your audience instantly on the worldโ€™s most popular AI bot platform.
25
- - ๐Ÿ—บ **Sitemap Integration**: Automatically ingest website content into a searchable knowledge base for your chatbot to reference.
26
- - ๐Ÿค– **GPT-3.5 Support**: State-of-the-art language models to power your conversations.
27
- - ๐Ÿš€ **GPT-4 Support**: The latest and best language model now can power all chatbots.
28
- - ๐ŸŽฅ **Streaming**: You can turn on and off streaming capabilities for your chatbots.
29
- - ๐ŸŽจ **Widget Themes**: Customize the appearance of your chatbot widget with different themes to match your website branding or personal preferences.
30
- - ๐Ÿ’ก **ChatGPT Extended**: Create your own own ChatGPT bot on variety of skills and domain-specific knowledge.
31
- - ๐Ÿ”„ **Multiple AI Models**: Leverage diverse models from various AI providers to enhance performance and accuracy.
32
- - ๐Ÿ”’ **Data Security**: Ensuring the security of user data, with robust measures in place to protect against unauthorized access.
33
- - ๐Ÿ•ต **Focus on Privacy**: Get strong privacy controls out of the box. Privide confindence that your customers' data is being handled responsibly.
34
- - ๐Ÿšซ **Content Moderation**: All messages are automatically scanned for abusive content and automatically flagged by the system.
35
- - ๐Ÿ” **Semantic Search**: Your chat bot can provide more relevant and accurate responses.
36
- - โš™๏ธ **AI Playgrounds**: Interactive environments that provide a safe and controlled space to experiment, explore, and learn.
37
- - โš’๏ธ **No-Code Platform**: Easily build, customize and deploy chatbots without needing to write any code.
38
- - ๐Ÿ’ต **Simple Pricing**: Our pricing is straightforward and easy to understand, with no hidden fees or surprises.
39
- - ๐Ÿ“ฑ **App Platform**: Our platform provides capabilities for building and deploying chatbots for a wide range of applications.
40
- - ๐Ÿ”ง **Extreme Customization**: Customize your chatbots' responses and behavior based on variety of preferences.
41
- - ๐ŸŒŸ **Expanding Feature Set**: We are constantly adding new features to so you can always stay up-to-date with the latest AI capabilities.
7
+ Welcome to the ChatBotKit React SDK! This SDK is your go-to React solution for creating conversational AI chatbots with ease. Leveraging the power of [ChatBotKit](https://chatbotkit.com), this SDK enables the rapid development and deployment of chatbots capable of natural language interactions.
42
8
 
43
9
  ## Getting Started
44
10
 
45
- To get started with ChatBotKit, follow these simple steps:
11
+ Embark on your ChatBotKit journey with these easy steps:
46
12
 
47
- 1. Install the SDK using npm: `npm install @chatbotkit/react`.
48
- 2. Use the SDK to setup or interact with your chatbot.
13
+ 1. **Installation**: Add the SDK to your React project:
14
+ ```bash
15
+ npm install @chatbotkit/react
16
+ ```
17
+ 2. **Implementation**: Utilize the SDK to build or manage your chatbot.
49
18
 
50
- Here is a simple example for the next.js framework. Within the body of our component we invoke the `useConversationManager` React Hook which setups a simple utility to manage the conversation flow.
19
+ ### A Basic Example for Next.js
51
20
 
52
- ```js
21
+ Here's a straightforward example using the `useConversationManager` React Hook to manage conversation flow within a Next.js application:
22
+
23
+ ```javascript
53
24
  import { AutoTextarea, useConversationManager } from '@chatbotkit/react'
54
25
 
55
- export default function Home() {
26
+ export default function Index() {
56
27
  const {
57
28
  conversationId,
58
29
  setConversationId,
59
-
60
30
  token,
61
31
  setToken,
62
-
63
32
  text,
64
33
  setText,
65
-
66
34
  messages,
67
-
68
35
  thinking,
69
-
70
- interact,
36
+ submit,
71
37
  } = useConversationManager({ stream: true })
72
38
 
39
+ // Function to create a new chat session
73
40
  async function createSession() {
74
41
  const response = await fetch(`/api/session/create`)
75
42
 
@@ -83,54 +50,58 @@ export default function Home() {
83
50
  setToken(token)
84
51
  }
85
52
 
53
+ // Handle text submission
86
54
  function handleOnKeyDown(event) {
87
55
  if (event.keyCode === 13) {
88
56
  event.preventDefault()
89
57
 
90
- interact()
58
+ submit()
91
59
  }
92
60
  }
93
61
 
62
+ // Render chat interface
94
63
  return (
95
- <div>
64
+ <div style={{ fontFamily: 'monospace', padding: '10px' }}>
96
65
  {conversationId && token ? (
97
66
  <>
98
- <div>
99
- {messages.map(({ id, type, text }) => {
100
- switch (type) {
101
- case 'user':
102
- return <div key={id}>user: {text}</div>
103
-
104
- case 'bot':
105
- return <div key={id}>bot: {text}</div>
106
- }
107
- })}
108
- {thinking ? <div key="thinking">bot: thinking...</div> : null}
109
- </div>
67
+ {messages.map(({ id, type, text }) => (
68
+ <div key={id}>
69
+ <strong>{type}:</strong> {text}
70
+ </div>
71
+ ))}
72
+ {thinking && (
73
+ <div key="thinking">
74
+ <strong>bot:</strong> thinking...
75
+ </div>
76
+ )}
110
77
  <AutoTextarea
111
78
  value={text}
112
- onChange={(e) => setText(event.target.value)}
79
+ onChange={(e) => setText(e.target.value)}
113
80
  onKeyDown={handleOnKeyDown}
81
+ placeholder="Type something..."
82
+ style={{
83
+ border: 0,
84
+ outline: 'none',
85
+ resize: 'none',
86
+ width: '100%',
87
+ marginTop: '10px',
88
+ }}
114
89
  />
115
90
  </>
116
91
  ) : (
117
- <button onClick={() => createSession()}>Start Chat</button>
92
+ <button onClick={createSession}>Start Chat</button>
118
93
  )}
119
94
  </div>
120
95
  )
121
96
  }
122
97
  ```
123
98
 
124
- ## Examples
125
-
126
- You can find a wide-range of examples at [here](https://github.com/chatbotkit/node-sdk/tree/main/examples).
99
+ Discover a complete example with advanced features [here](https://github.com/chatbotkit/node-sdk/tree/main/examples/nextjs/basic-chat).
127
100
 
128
101
  ## Documentation
129
102
 
130
- For detailed documentation on available types, please refer to the [type documentation](https://github.com/chatbotkit/node-sdk/blob/main/docs/react/modules.md).
131
-
132
- Checkout the [ChatBotKit Documentation](https://chatbotkit.com/docs/react-sdk) for more information about the platform.
103
+ For a comprehensive understanding of the ChatBotKit React SDK, including detailed insights into its capabilities and configuration for various environments, please visit our [official documentation page](https://chatbotkit.github.io/node-sdk/modules/_chatbotkit_react.html).
133
104
 
134
105
  ## Contributing
135
106
 
136
- If you find a bug or would like to contribute to the ChatBotKit SDK, please open an issue or submit a pull request on the [official GitHub repository](https://github.com/chatbotkit/node-sdk).
107
+ 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).
@@ -1,90 +1,56 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-ts-comment */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
2
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.AutoScrollAnchor = void 0;
28
- const react_1 = __importStar(require("react"));
3
+ exports.AutoScroller = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
29
7
  function AutoScrollAnchor() {
30
- return react_1.default.createElement("div", { className: "auto-scroll-anchor ![height:1px]" });
8
+ return (0, jsx_runtime_1.jsx)("div", { className: "auto-scroll-anchor", style: { height: '1px' } });
31
9
  }
32
- exports.AutoScrollAnchor = AutoScrollAnchor;
33
- /**
34
- * @param {{
35
- * anchor?: 'top'|'bottom',
36
- * childList?: boolean,
37
- * subtree?: boolean,
38
- * block?: 'start'|'end',
39
- * delay?: number,
40
- * [name: string]: any
41
- * }} props
42
- */
43
- function AutoScroller({ anchor = 'bottom', childList = true, subtree = false, block = 'end', delay = 3000, disabled, children, ...props }) {
44
- const rootRef = (0, react_1.useRef)();
10
+ function AutoScroller(props) {
11
+ const { anchor = 'bottom', childList = true, subtree = false, block = 'end', delay = 3000, disabled, children, ...rest } = props || {};
12
+ const rootRef = ((0, react_1.useRef)());
45
13
  (0, react_1.useEffect)(() => {
14
+ var _a;
46
15
  if (disabled) {
47
16
  return;
48
17
  }
49
18
  let visible = false;
50
19
  let pause = false;
51
- let timeout = 0;
20
+ let timeout;
52
21
  const io = new IntersectionObserver((entries) => {
53
22
  if (pause) {
54
23
  return;
55
24
  }
56
25
  visible = entries.some((entry) => entry.isIntersecting);
57
26
  });
58
- // @ts-ignore
59
- io.observe(rootRef.current?.querySelector('.auto-scroll-anchor'));
27
+ const anchor = (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.auto-scroll-anchor');
28
+ if (anchor) {
29
+ io.observe(anchor);
30
+ }
60
31
  const mo = new MutationObserver(() => {
32
+ var _a, _b;
61
33
  if (!visible) {
62
34
  return;
63
35
  }
64
36
  pause = true;
65
- rootRef.current
66
- // @ts-ignore
67
- ?.querySelector('.auto-scroll-anchor')
68
- ?.scrollIntoView({ behavior: 'smooth', block });
37
+ (_b = (_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.auto-scroll-anchor')) === null || _b === void 0 ? void 0 : _b.scrollIntoView({ behavior: 'smooth', block });
69
38
  clearTimeout(timeout);
70
- // @ts-ignore
71
39
  timeout = setTimeout(() => {
72
40
  visible = true;
73
41
  pause = false;
74
42
  }, delay);
75
43
  });
76
- // @ts-ignore
77
- mo.observe(rootRef.current, { childList, subtree });
44
+ const root = rootRef.current;
45
+ if (root) {
46
+ mo.observe(root, { childList, subtree });
47
+ }
78
48
  return () => {
79
49
  io.disconnect();
80
50
  mo.disconnect();
81
51
  };
82
52
  }, [disabled]);
83
- return (
84
- // @ts-ignore
85
- react_1.default.createElement("div", { ref: rootRef, ...props },
86
- anchor === 'top' ? react_1.default.createElement(AutoScrollAnchor, { key: "top" }) : null,
87
- children,
88
- anchor === 'bottom' ? react_1.default.createElement(AutoScrollAnchor, { key: "bottom" }) : null));
53
+ return ((0, jsx_runtime_1.jsxs)("div", { ref: rootRef, ...rest, children: [anchor === 'top' ? (0, jsx_runtime_1.jsx)(AutoScrollAnchor, {}, "top") : null, children, anchor === 'bottom' ? (0, jsx_runtime_1.jsx)(AutoScrollAnchor, {}, "bottom") : null] }));
89
54
  }
55
+ exports.AutoScroller = AutoScroller;
90
56
  exports.default = AutoScroller;
@@ -1,20 +1,9 @@
1
- export function AutoScrollAnchor(): React.JSX.Element;
2
- /**
3
- * @param {{
4
- * anchor?: 'top'|'bottom',
5
- * childList?: boolean,
6
- * subtree?: boolean,
7
- * block?: 'start'|'end',
8
- * delay?: number,
9
- * [name: string]: any
10
- * }} props
11
- */
12
- export default function AutoScroller({ anchor, childList, subtree, block, delay, disabled, children, ...props }: {
1
+ export function AutoScroller(props?: {
13
2
  [name: string]: any;
14
3
  anchor?: "top" | "bottom" | undefined;
15
4
  childList?: boolean | undefined;
16
5
  subtree?: boolean | undefined;
17
- block?: "end" | "start" | undefined;
6
+ block?: "start" | "end" | undefined;
18
7
  delay?: number | undefined;
19
- }): React.JSX.Element;
20
- import React from 'react';
8
+ } | undefined): import("react/jsx-runtime").JSX.Element;
9
+ export default AutoScroller;
@@ -1,23 +1,11 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/ban-ts-comment */
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
2
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const react_1 = __importDefault(require("react"));
8
- /**
9
- * @typedef {(event: React.ChangeEvent<HTMLTextAreaElement>) => any} onInputFn
10
- *
11
- * @param {{
12
- * onInput?: onInputFn?,
13
- * [name: string]: any
14
- * }} [props]
15
- */
16
- // @ts-ignore
17
- function AutoTextarea({ onInput, ...props } = {}) {
18
- /**
19
- * @param {React.ChangeEvent<HTMLTextAreaElement>} event
20
- */
3
+ exports.AutoTextarea = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importDefault(require("react"));
7
+ function AutoTextarea(props) {
8
+ const { onInput, ...rest } = props || {};
21
9
  function handleOnInput(event) {
22
10
  const adjustment = `calc(${[event.target.style.paddingTop, event.target.style.paddingBottom]
23
11
  .filter((f) => f)
@@ -28,6 +16,7 @@ function AutoTextarea({ onInput, ...props } = {}) {
28
16
  onInput(event);
29
17
  }
30
18
  }
31
- return react_1.default.createElement("textarea", { ...props, rows: 1, onInput: handleOnInput });
19
+ return (0, jsx_runtime_1.jsx)("textarea", { ...rest, rows: 1, onInput: handleOnInput });
32
20
  }
21
+ exports.AutoTextarea = AutoTextarea;
33
22
  exports.default = AutoTextarea;
@@ -1,14 +1,7 @@
1
- /**
2
- * @typedef {(event: React.ChangeEvent<HTMLTextAreaElement>) => any} onInputFn
3
- *
4
- * @param {{
5
- * onInput?: onInputFn?,
6
- * [name: string]: any
7
- * }} [props]
8
- */
9
- export default function AutoTextarea({ onInput, ...props }?: {
1
+ export function AutoTextarea(props?: {
10
2
  [name: string]: any;
11
3
  onInput?: onInputFn | null | undefined;
12
- } | undefined): React.JSX.Element;
4
+ } | undefined): import("react/jsx-runtime").JSX.Element;
5
+ export default AutoTextarea;
13
6
  export type onInputFn = (event: React.ChangeEvent<HTMLTextAreaElement>) => any;
14
7
  import React from 'react';