@cmnd-ai/chatbot-react 1.1.0 → 1.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.
Files changed (2) hide show
  1. package/Readme.md +109 -0
  2. package/package.json +1 -1
package/Readme.md ADDED
@@ -0,0 +1,109 @@
1
+ ## @cmnd-ai/chatbot-react
2
+
3
+ This npm package provides a customizable chatbot component for use in web applications, designed specifically for Node.js environments.
4
+
5
+ ### Installation
6
+
7
+ You can install the `@cmnd-ai/chatbot-react` from npm using npm or yarn:
8
+
9
+ ```bash
10
+ npm install @cmnd-ai/chatbot-react
11
+ ```
12
+
13
+ ### With yarn
14
+
15
+ ```bash
16
+ yarn add @cmnd-ai/chatbot-react
17
+ ```
18
+
19
+ ### Example implementation
20
+
21
+ ```javascript
22
+ import { ChatProvider, CmndChatBot } from "@cmnd-ai/chatbot-react";
23
+ import { useEffect } from "react";
24
+
25
+ const components = {
26
+ messages({ props }) {
27
+ const messages = props.chats.data?.messages || [];
28
+
29
+ useEffect(() => {
30
+ const comp = document.querySelector(`#lastItemId`);
31
+ if (!comp) return;
32
+
33
+ setTimeout(() => {
34
+ comp.scrollIntoView({
35
+ behavior: "smooth",
36
+ block: "end", // Scroll to the bottom of the container
37
+ });
38
+ }, 500);
39
+ }, [messages.length]);
40
+
41
+ const getchild = () => {
42
+ if (props.chats.error) {
43
+ return <h1>Error</h1>;
44
+ }
45
+ if (!props.chats.data?.messages?.length)
46
+ return <h1>Ask me a question</h1>;
47
+
48
+ return (
49
+ <div>
50
+ {messages.map((eachMessage, msgIndex) => (
51
+ <div
52
+ key={eachMessage.id}
53
+ id={msgIndex === messages.length - 1 ? "lastItemId" : undefined}
54
+ >
55
+ {eachMessage.message + ""}
56
+ </div>
57
+ ))}
58
+ </div>
59
+ );
60
+ };
61
+
62
+ return <div style={{ flexGrow: 1 }}>{getchild()}</div>;
63
+ },
64
+ userInputBox({ props }) {
65
+ return (
66
+ <div
67
+ style={{
68
+ display: "flex",
69
+ gap: "1rem",
70
+ }}
71
+ >
72
+ <input
73
+ style={{
74
+ flexGrow: 1,
75
+ }}
76
+ type="text"
77
+ value={props.userInputData.textValue}
78
+ onChange={(e) => props.userInputData.setTextValue(e.target.value)}
79
+ placeholder="Type here"
80
+ disabled={props.userInputData.isSending}
81
+ />
82
+ <button
83
+ onClick={props.userInputData.submitMessage}
84
+ disabled={props.userInputData.isSending}
85
+ >
86
+ {props.userInputData.isSending ? "Sending..." : "Send"}
87
+ </button>
88
+ </div>
89
+ );
90
+ },
91
+ error({ props }) {
92
+ return <div>Error: {props.chats.error + ""}</div>;
93
+ },
94
+ };
95
+
96
+ function App() {
97
+ return (
98
+ <div>
99
+ <ChatProvider apiKey="xxxxx" chatbotId={1} organizationId={1}>
100
+ {(params) => <CmndChatBot {...params} components={components} />}
101
+ </ChatProvider>
102
+ </div>
103
+ );
104
+ }
105
+
106
+ export default App;
107
+ ```
108
+
109
+ You can find an example implementation from Github [here](https://github.com/CyprusCodes/cmnd-react-chatbot-example.git)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmnd-ai/chatbot-react",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "dist/index.js",
5
5
  "description": "",
6
6
  "files": [