@sarujan/s_bot_creator 1.0.1

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 (3) hide show
  1. package/README.md +96 -0
  2. package/index.js +112 -0
  3. package/package.json +17 -0
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ no-code-rag-bot
2
+
3
+ A lightweight, ready-to-use React chat widget to integrate your BotBuilder AI RAG bots into any website.
4
+
5
+ Features
6
+
7
+ 🚀 Plug & Play: Add a fully functional chat AI to your site with one line of code.
8
+
9
+ 🛠 No-Code Integration: Connects directly to your BotBuilder AI backend using your botId.
10
+
11
+ 🎨 Auto-Branding: Automatically fetches your bot's colors, name, and greeting message.
12
+
13
+ 📱 Responsive Design: Floating widget design that works perfectly on desktop and mobile.
14
+
15
+ 🏗 React Portal: Renders at the end of document.body to avoid z-index and styling conflicts.
16
+
17
+ Installation
18
+
19
+ Install the package via npm or yarn:
20
+
21
+ code
22
+ Bash
23
+ download
24
+ content_copy
25
+ expand_less
26
+ npm install no-code-rag-bot
27
+
28
+ or
29
+
30
+ code
31
+ Bash
32
+ download
33
+ content_copy
34
+ expand_less
35
+ yarn add no-code-rag-bot
36
+ Usage
37
+
38
+ Simply import the BotWidget component and place it anywhere in your React application. It will automatically anchor itself to the bottom right of the screen.
39
+
40
+ code
41
+ Jsx
42
+ download
43
+ content_copy
44
+ expand_less
45
+ import React from 'react';
46
+ import { BotWidget } from 'no-code-rag-bot';
47
+
48
+ function App() {
49
+ return (
50
+ <div className="App">
51
+ <h1>My Website</h1>
52
+ {/* Replace 'your-bot-id-here' with your actual Bot ID */}
53
+ <BotWidget botId="your-bot-id-here" />
54
+ </div>
55
+ );
56
+ }
57
+
58
+ export default App;
59
+ Props
60
+ Prop Type Required Description
61
+ botId string Yes Your unique Bot ID from the BotBuilder AI dashboard.
62
+ How it works
63
+
64
+ Initialization: On mount, the component fetches your bot's specific configuration (theme color, name, and greeting) from the API.
65
+
66
+ Chatting: When a user sends a message, it is sent to the RAG engine. The bot's response is then streamed back to the UI.
67
+
68
+ Styles: The widget uses inline styles to ensure it looks consistent regardless of your local CSS setup.
69
+
70
+ Development
71
+
72
+ If you want to contribute or modify the widget:
73
+
74
+ Clone the repository.
75
+
76
+ Install dependencies: npm install.
77
+
78
+ Run tests or build: npm run build.
79
+
80
+ License
81
+
82
+ MIT © Sarujan003
83
+
84
+ Pro-Tip for your package.json:
85
+
86
+ Since you are using React Portals, make sure your package.json has react and react-dom listed under peerDependencies so that the user's project provides the React runtime.
87
+
88
+ code
89
+ JSON
90
+ download
91
+ content_copy
92
+ expand_less
93
+ "peerDependencies": {
94
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
95
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
96
+ }
package/index.js ADDED
@@ -0,0 +1,112 @@
1
+
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+
5
+ /**
6
+ * BotBuilder AI - NPM React Component
7
+ * Fully functional with local state and message tracking.
8
+ */
9
+ export const BotWidget = ({ botId }) => {
10
+ const [isOpen, setIsOpen] = useState(false);
11
+ const [messages, setMessages] = useState([]);
12
+ const [config, setConfig] = useState(null);
13
+ const [input, setInput] = useState('');
14
+ const msgEndRef = useRef(null);
15
+
16
+ // useEffect(() => {
17
+ // // 1. Fetch config for colors and branding
18
+ // fetch(`https://api.botbuilder.ai/v1/config/${botId}`)
19
+ // .then(res => res.json())
20
+ // .then(data => {
21
+ // setConfig(data);
22
+ // setMessages([{ role: 'model', text: data.greetingMessage }]);
23
+ // });
24
+ // }, [botId]);
25
+ // Temporarily replace your useEffect fetch with this to test UI:
26
+ useEffect(() => {
27
+ setConfig({
28
+ primaryColor: '#007bff',
29
+ name: 'Test Bot',
30
+ greetingMessage: 'Hello! I am working.'
31
+ });
32
+ setMessages([{ role: 'model', text: 'Hello! I am working.' }]);
33
+ }, [botId]);
34
+
35
+ useEffect(() => {
36
+ msgEndRef.current?.scrollIntoView({ behavior: 'smooth' });
37
+ }, [messages]);
38
+
39
+ const handleSend = async (e) => {
40
+ e.preventDefault();
41
+ if (!input.trim()) return;
42
+
43
+ const userMsg = { role: 'user', text: input };
44
+ setMessages(prev => [...prev, userMsg]);
45
+ setInput('');
46
+
47
+ const res = await fetch('https://api.botbuilder.ai/v1/chat', {
48
+ method: 'POST',
49
+ headers: { 'Content-Type': 'application/json' },
50
+ body: JSON.stringify({ botId, message: input })
51
+ });
52
+ const data = await res.json();
53
+ setMessages(prev => [...prev, { role: 'model', text: data.text }]);
54
+ };
55
+
56
+ if (!config) return null;
57
+
58
+ return createPortal(
59
+ <div style={{ position: 'fixed', bottom: '20px', right: '20px', zIndex: 9999 }}>
60
+ {isOpen && (
61
+ <div style={{
62
+ width: '380px', height: '600px', background: 'white', borderRadius: '20px',
63
+ boxShadow: '0 8px 24px rgba(0,0,0,0.1)', display: 'flex', flexDirection: 'column',
64
+ marginBottom: '20px', border: '1px solid #eee', overflow: 'hidden'
65
+ }}>
66
+ <div style={{ background: config.primaryColor, color: 'white', padding: '16px', display: 'flex', justifyContent: 'space-between' }}>
67
+ <span style={{ fontWeight: 'bold' }}>{config.name}</span>
68
+ <button onClick={() => setIsOpen(false)} style={{ background: 'none', border: 'none', color: 'white', cursor: 'pointer' }}>&times;</button>
69
+ </div>
70
+
71
+ <div style={{ flex: 1, padding: '16px', overflowY: 'auto', background: '#f9fafb' }}>
72
+ {messages.map((m, i) => (
73
+ <div key={i} style={{
74
+ background: m.role === 'user' ? config.primaryColor : 'white',
75
+ color: m.role === 'user' ? 'white' : '#333',
76
+ alignSelf: m.role === 'user' ? 'flex-end' : 'flex-start',
77
+ padding: '10px 14px', borderRadius: '12px', marginBottom: '10px', fontSize: '14px',
78
+ maxWidth: '85%', border: m.role === 'user' ? 'none' : '1px solid #e5e7eb'
79
+ }}>
80
+ {m.text}
81
+ </div>
82
+ ))}
83
+ <div ref={msgEndRef} />
84
+ </div>
85
+
86
+ <form onSubmit={handleSend} style={{ padding: '16px', borderTop: '1px solid #eee', display: 'flex', gap: '8px' }}>
87
+ <input
88
+ value={input}
89
+ onChange={e => setInput(e.target.value)}
90
+ placeholder="Type a message..."
91
+ style={{ flex: 1, padding: '8px', borderRadius: '8px', border: '1px solid #ddd' }}
92
+ />
93
+ <button type="submit" style={{ background: config.primaryColor, color: 'white', border: 'none', padding: '8px 16px', borderRadius: '8px' }}>Send</button>
94
+ </form>
95
+ </div>
96
+ )}
97
+
98
+ <button
99
+ onClick={() => setIsOpen(!isOpen)}
100
+ style={{
101
+ width: '60px', height: '60px', borderRadius: '50%', background: config.primaryColor,
102
+ color: 'white', border: 'none', boxShadow: '0 4px 12px rgba(0,0,0,0.15)', cursor: 'pointer'
103
+ }}
104
+ >
105
+ {isOpen ? '↓' : '💬'}
106
+ </button>
107
+ </div>,
108
+ document.body
109
+ );
110
+ };
111
+
112
+ export default BotWidget;
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@sarujan/s_bot_creator",
3
+ "version": "1.0.1",
4
+ "description": "No code Rag bot React widget",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Sarujan003/No-code-Rag-Bot.git"
10
+ },
11
+ "author": "sarujan",
12
+ "license": "ISC",
13
+ "peerDependencies": {
14
+ "react": ">=16.8.0",
15
+ "react-dom": ">=16.8.0"
16
+ }
17
+ }