UNPKG

n8n-widget-bot

Version:

Lightweight and customizable n8n AI chatbot widget

343 lines (273 loc) β€’ 9.2 kB
# n8n Widget Bot πŸ€– 가볍고 μ‚¬μš©μž μ •μ˜ κ°€λŠ₯ν•œ n8n AI 챗봇 μœ„μ ― 라이브러리 A lightweight and customizable n8n AI chatbot widget library with zero dependencies. ![Version](https://img.shields.io/npm/v/n8n-widget-bot) ![License](https://img.shields.io/npm/l/n8n-widget-bot) ![Size](https://img.shields.io/bundlephobia/minzip/n8n-widget-bot) ## Features ✨ - πŸš€ **Zero Dependencies** - 순수 바닐라 JavaScript둜 κ΅¬ν˜„ - 🎨 **Fully Customizable** - ν…Œλ§ˆ, 색상, μœ„μΉ˜ λ“± λͺ¨λ“  것을 μ»€μŠ€ν„°λ§ˆμ΄μ§• κ°€λŠ₯ - πŸ“± **Responsive Design** - λͺ¨λ°”일과 λ°μŠ€ν¬ν†± λͺ¨λ‘ 지원 - πŸ”„ **Resizable** - 8λ°©ν–₯ λ¦¬μ‚¬μ΄μ¦ˆ 지원 - ✨ **Smooth Animations** - λΆ€λ“œλŸ¬μš΄ 타이핑 μ• λ‹ˆλ©”μ΄μ…˜ - πŸ”’ **Session Management** - μžλ™ μ„Έμ…˜ 관리 - πŸ“ **Markdown Support** - κΈ°λ³Έ λ§ˆν¬λ‹€μš΄ 문법 지원 - πŸ“Ž **File Upload** - 파일 첨뢀 κΈ°λŠ₯ 지원 (이미지, PDF, λ¬Έμ„œ λ“±) ## Installation πŸ“¦ ### CDN (μΆ”μ²œ) #### jsDelivr CDN ```html <!-- μ΅œμ‹  버전 --> <script src="https://cdn.jsdelivr.net/npm/n8n-widget-bot@latest/dist/n8n-widget-bot.min.js"></script> <!-- νŠΉμ • 버전 --> <script src="https://cdn.jsdelivr.net/npm/n8n-widget-bot@1.0.0/dist/n8n-widget-bot.min.js"></script> ``` #### unpkg CDN ```html <!-- μ΅œμ‹  버전 --> <script src="https://unpkg.com/n8n-widget-bot@latest/dist/n8n-widget-bot.min.js"></script> <!-- νŠΉμ • 버전 --> <script src="https://unpkg.com/n8n-widget-bot@1.0.0/dist/n8n-widget-bot.min.js"></script> ``` ### NPM ```bash npm install n8n-widget-bot ``` ### 직접 λ‹€μš΄λ‘œλ“œ [GitHub Releases](https://github.com/dantelabs/n8n-widget-bot/releases)μ—μ„œ μ΅œμ‹  버전을 λ‹€μš΄λ‘œλ“œν•˜μ„Έμš”. ## Quick Start πŸš€ ### κΈ°λ³Έ μ‚¬μš©λ²• (CDN) ```html <!DOCTYPE html> <html> <head> <title>n8n Widget Bot Example</title> </head> <body> <!-- Your content here --> <!-- n8n Widget Bot --> <script src="https://cdn.jsdelivr.net/npm/n8n-widget-bot@latest/dist/n8n-widget-bot.min.js"></script> <script> FloatingChatWidget.init({ apiUrl: 'YOUR_N8N_WEBHOOK_URL', title: 'AI Assistant', themeColor: '#4C4CBB', welcomeMessage: 'Hello! How can I help you today?' }); </script> </body> </html> ``` ### NPM λͺ¨λ“ˆλ‘œ μ‚¬μš© ```javascript // ES6 Module import 'n8n-widget-bot'; // CommonJS require('n8n-widget-bot'); // Initialize window.FloatingChatWidget.init({ apiUrl: 'YOUR_N8N_WEBHOOK_URL', title: 'AI Assistant' }); ``` ## Configuration Options βš™οΈ ```javascript FloatingChatWidget.init({ // Required apiUrl: 'YOUR_N8N_WEBHOOK_URL', // n8n webhook URL // Appearance themeColor: '#4C4CBB', // μ£Ό ν…Œλ§ˆ 색상 position: 'bottom-right', // 'bottom-left' or 'bottom-right' bubbleIcon: '<i class="fas fa-comments"></i>', // 버블 μ•„μ΄μ½˜ (HTML) title: 'AI Assistant', // μœ„μ ― 헀더 제λͺ© // Messages placeholder: 'Type your message...', // μž…λ ₯ ν•„λ“œ ν”Œλ ˆμ΄μŠ€ν™€λ” welcomeMessage: 'Hello! πŸ‘‹', // ν™˜μ˜ λ©”μ‹œμ§€ // Dimensions width: 350, // 초기 λ„ˆλΉ„ (px) height: 500, // 초기 높이 (px) resizable: true, // λ¦¬μ‚¬μ΄μ¦ˆ κ°€λŠ₯ μ—¬λΆ€ minWidth: 300, // μ΅œμ†Œ λ„ˆλΉ„ maxWidth: 600, // μ΅œλŒ€ λ„ˆλΉ„ minHeight: 400, // μ΅œμ†Œ 높이 maxHeight: 800, // μ΅œλŒ€ 높이 // Behavior animationDuration: 300, // μ• λ‹ˆλ©”μ΄μ…˜ 지속 μ‹œκ°„ (ms) typingSpeed: 18, // 타이핑 속도 (ms) maxMessageLength: 1000, // μ΅œλŒ€ λ©”μ‹œμ§€ 길이 // File Upload (v1.2.0+ supports multiple files) enableFileUpload: true, // 파일 μ—…λ‘œλ“œ κΈ°λŠ₯ ν™œμ„±ν™” maxFileSize: 10485760, // μ΅œλŒ€ 파일 크기 (10MB) allowedFileTypes: [ // ν—ˆμš©λœ 파일 νƒ€μž… 'image/*', // λͺ¨λ“  이미지 'application/pdf', // PDF '.doc', '.docx', // Word λ¬Έμ„œ '.txt', '.csv', '.xlsx' // ν…μŠ€νŠΈ 파일 ], // Advanced sessionId: undefined, // μ„Έμ…˜ ID (μžλ™ 생성) fontFamily: 'inherit', // 폰트 νŒ¨λ°€λ¦¬ zIndex: 9999, // z-index debug: false // 디버그 λͺ¨λ“œ }); ``` ## n8n Webhook Setup πŸ”§ n8nμ—μ„œ AI μ—μ΄μ „νŠΈμ™€ μ—°λ™ν•˜λ €λ©΄: 1. n8nμ—μ„œ μƒˆλ‘œμš΄ μ›Œν¬ν”Œλ‘œμš° 생성 2. **Webhook** λ…Έλ“œ μΆ”κ°€ - HTTP Method: POST - Path: μ›ν•˜λŠ” 경둜 μ„€μ • - Response Mode: "When last node finishes" 3. **AI Agent** λ…Έλ“œ μΆ”κ°€ 및 μ—°κ²° 4. Webhook URL을 λ³΅μ‚¬ν•˜μ—¬ `apiUrl`에 μ„€μ • ### Expected API Format (v1.2.0+) Request (New n8n webhook format - supports multiple files): ```json { "sessionId": "fcw-abc123...", "action": "sendMessage", "chatInput": "User message", "files": [ { "fileName": "document.pdf", "fileSize": "12345 bytes", "fileExtension": "pdf", "fileType": "application", "mimeType": "application/pdf", "data": "data:application/pdf;base64,..." }, { "fileName": "image.png", "fileSize": "54321 bytes", "fileExtension": "png", "fileType": "image", "mimeType": "image/png", "data": "data:image/png;base64,..." } ] } ``` Response (λ‹€μŒ 쀑 ν•˜λ‚˜): ```json { "reply": "Bot response" } // or { "output": "Bot response" } // or { "message": "Bot response" } ``` ## Advanced Usage πŸ”₯ ### Programmatic Control ```javascript // μœ„μ ― μ—΄κΈ° FloatingChatWidget.open(); // μœ„μ ― λ‹«κΈ° FloatingChatWidget.close(); // ν† κΈ€ FloatingChatWidget.toggle(); // ν”„λ‘œκ·Έλž˜λ° λ°©μ‹μœΌλ‘œ λ©”μ‹œμ§€ 전솑 FloatingChatWidget.reply('This is a bot message'); // μ»€μŠ€ν…€ λ©”μ‹œμ§€ ν•Έλ“€λŸ¬ FloatingChatWidget.onUserRequest(function(message) { // Custom handling console.log('User said:', message); // Send custom reply FloatingChatWidget.reply('Custom response'); }); ``` ### Multiple Instances μ—¬λŸ¬ 개의 μœ„μ ―μ„ μ‚¬μš©ν•˜λ €λ©΄ 각각 λ‹€λ₯Έ μ„€μ •μœΌλ‘œ μ΄ˆκΈ°ν™”: ```javascript // First widget FloatingChatWidget.init({ apiUrl: 'URL_1', position: 'bottom-right', themeColor: '#4C4CBB' }); // Note: Currently supports only one instance per page // Multi-instance support coming soon ``` ## Examples πŸ“š ### 1. λ―Έλ‹ˆλ©€ μ„€μ • ```javascript FloatingChatWidget.init({ apiUrl: 'https://your-n8n.com/webhook/chat' }); ``` ### 2. ν’€ μ»€μŠ€ν„°λ§ˆμ΄μ§• ```javascript FloatingChatWidget.init({ apiUrl: 'https://your-n8n.com/webhook/chat', themeColor: '#FF6B6B', position: 'bottom-left', title: 'πŸ€– 고객 지원', welcomeMessage: 'μ•ˆλ…•ν•˜μ„Έμš”! 무엇을 λ„μ™€λ“œλ¦΄κΉŒμš”?', placeholder: 'λ©”μ‹œμ§€λ₯Ό μž…λ ₯ν•˜μ„Έμš”...', width: 400, height: 600, resizable: false, debug: true }); ``` ### 3. 닀크 ν…Œλ§ˆ ```javascript FloatingChatWidget.init({ apiUrl: 'https://your-n8n.com/webhook/chat', themeColor: '#1a1a1a', title: 'Dark Mode Assistant', bubbleIcon: 'πŸŒ™' }); ``` ## Browser Support 🌐 - Chrome (latest) - Firefox (latest) - Safari (latest) - Edge (latest) - Mobile browsers (iOS Safari, Chrome Mobile) ## Development πŸ› οΈ ### Setup ```bash git clone https://github.com/dantelabs/n8n-widget-bot.git cd n8n-widget-bot npm install ``` ### Build ```bash npm run build # Build both normal and minified versions npm run dev # Start development server ``` ### File Structure ``` n8n-widget-bot/ β”œβ”€β”€ dist/ β”‚ β”œβ”€β”€ n8n-widget-bot.js # Full version β”‚ └── n8n-widget-bot.min.js # Minified version β”œβ”€β”€ examples/ β”‚ └── home.html # Example implementation β”œβ”€β”€ n8n-widget-bot.js # Source file β”œβ”€β”€ package.json └── README.md ``` ## Contributing 🀝 Contributions are welcome! Please feel free to submit a Pull Request. 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/AmazingFeature`) 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) 4. Push to the branch (`git push origin feature/AmazingFeature`) 5. Open a Pull Request ## License πŸ“„ MIT License - see the [LICENSE](LICENSE) file for details. ## Support πŸ’¬ - πŸ› [버그 μ‹ κ³ ν•˜κΈ°](https://github.com/dandacompany/n8n-widget-bot/issues) - πŸ’‘ [κΈ°λŠ₯ μš”μ²­ν•˜κΈ°](https://github.com/dandacompany/n8n-widget-bot/issues) - ▢️ [YouTube 채널](https://www.youtube.com/@dante-labs) - πŸ“§ [이메일 문의](mailto:datapod.k@gmail.com) ## Credits πŸ‘ Created with ❀️ by [Dante Labs](https://dante-datalab.com) --- **Note**: 이 ν”„λ‘œμ νŠΈλŠ” n8nκ³Ό κ³΅μ‹μ μœΌλ‘œ μ—°κ΄€λ˜μ–΄ μžˆμ§€ μ•ŠμŠ΅λ‹ˆλ‹€. n8n은 λ³„λ„μ˜ ν”„λ‘œμ νŠΈμž…λ‹ˆλ‹€.