### Example: List Selection in Chat Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md This example demonstrates how to present a list of choices to the user, prompting them to select a fruit. ```text Please choose: [{list:Select a fruit|Apple:apple|Banana:banana}] ``` -------------------------------- ### Example: Email Input in Chat Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md This example shows how to prompt the user for their email address, marking it as a required field. ```text Enter your email: [{input|Your email|required|email}] ``` -------------------------------- ### Example: Confirmation Buttons in Chat Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md This example shows how to present two buttons for user confirmation, allowing them to choose between 'Yes' and 'No'. ```text Are you sure? [{button|Yes|Yes, please!} {button|No|No, thank you!}] ``` -------------------------------- ### Example: Phone Number Input in Chat Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md This example demonstrates prompting for a phone number with a custom prefix and marking it as required. ```text Enter your phone number: [{input|Your phone number|My number is: required|phone}] ``` -------------------------------- ### startNewConversation Webhook Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt This webhook is automatically sent when the user clicks 'Start chat'. It initializes or resumes a session on the n8n side. ```APIDOC ## POST /webhook/abc123/chat ### Description Initializes or resumes a chat session on the n8n side. ### Method POST ### Endpoint /webhook/abc123/chat ### Request Body - **action** (string) - Required - Must be `loadPreviousSession`. - **sessionId** (string) - Required - The unique identifier for the chat session. - **route** (string) - Required - The route for the conversation, e.g., `general`. - **metadata** (object) - Optional - Contains information about the user and environment. - **userId** (string) - Optional - The ID of the user. - **userEmail** (string) - Optional - The email of the user. - **userLanguage** (string) - Optional - The language of the user, e.g., `en`. - **baseUrl** (string) - Optional - The base URL of the site. - **detectedLocation** (object) - Optional - Details about the user's detected location. - **city** (string) - Optional - The detected city. - **country** (string) - Optional - The detected country. - **detectedTimeZone** (string) - Optional - The user's detected time zone. - **timestamp** (string) - Optional - The timestamp of the event in ISO format. ### Request Example ```json { "action": "loadPreviousSession", "sessionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "route": "general", "metadata": { "userId": "", "userEmail": "", "userLanguage": "en", "baseUrl": "https://mysite.com", "detectedLocation": { "city": "New York", "country": "US" }, "detectedTimeZone": "America/New_York", "timestamp": "2025-06-01T12:00:00.000Z" } } ``` ### Response #### Success Response - **output** (string) - The bot's response message. - **data** (array) - An array containing output objects. - **output** (string) - The bot's response message. - **string** - A plain string response. ### Response Example ```json { "output": "Welcome back! How can I help you today?" } ``` ```json { "data": [{ "output": "Welcome back!" }] } ``` ``` Welcome back! ``` ``` -------------------------------- ### Configure Proactive Prompt Settings Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Configure a dismissible speech-bubble overlay to invite users to start a conversation after a specified delay. The prompt is hidden when the chat is open and rescheduled when the chat is closed. ```javascript window.ChatWidgetConfig = { proactivePrompt: { enabled: true, delay: 15000, // 15 seconds after page load (or after chat is closed) message: { en: "👋 Need help? Chat with us!", pt: "👋 Precisa de ajuda? Fale conosco!", es: "👋 ¿Necesitas ayuda? ¡Chatea con nosotros!", ar: "👋 هل تحتاج مساعدة؟ تحدث معنا!" } } }; // Clicking the bubble opens the chat (calls toggleChat(true)). // Clicking the × button dismisses it without opening the chat. // The prompt is hidden automatically whenever the chat is opened. // A new prompt is rescheduled each time the chat is closed. ``` -------------------------------- ### Install N8N Chat Widget via Script Tag Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Include this script in your HTML to embed the chat widget. Configure webhook, branding, and style options. ```html ``` -------------------------------- ### Render Quick Actions in DOM Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/test-objects.html Renders the parsed quick action elements (buttons, inputs, etc.) into the provided message element in the DOM. Includes basic styling and event handling setup for buttons. ```javascript // --- RENDER QUICK ACTIONS (with Validation Logic) --- function renderQuickActions(messageElement, quickActions) { if (!quickActions || !quickActions.hasQuickActions) return; // Handle buttons console.log("Rendering quick actions:", quickActions); const mainContainer = document.createElement('div'); mainContainer.style.marginTop = '15px'; // Add space below message text let hasRenderedAction = false; // Render buttons if (quickActions.buttons && quickActions.buttons.length > 0) { const buttonContainer = document.createElement('div'); buttonContainer.className = 'quick-action-container'; quickActions.buttons.forEach(button => { const btn = document.createElement('button'); btn.className = 'quick-action-button'; if (button.type === 'external') btn.className += ' external'; btn.textContent = button.text; btn.dataset.action = button.action; btn.dataset.type = button.type || 'normal'; btn.textContent = button.text; // Set text content first // Add external link icon if needed if (button.type === 'external') { // btn.className += ' external'; // Class is already added based on initial check // Create SVG icon for external link const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); icon.setAttribute('viewBox', '0 0 24 24'); icon.setAttribute('width', '14'); // Use specific dimensions for the small icon icon.setAttribute('height', '14'); icon.style.marginLeft = '6px'; // Add some space between text and icon icon.style.verticalAlign = 'middle'; // Align icon nicely with text icon.setAttribute('fill', 'none'); icon.setAttribute('str ``` -------------------------------- ### Quick Action Button Format Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Format quick action buttons. The text inside the curly braces is the button label, and the message after the pipe is what gets sent when clicked. ```markdown [{button:Yes, please|I want to subscribe to the newsletter}] ``` -------------------------------- ### Webhook Payload: startNewConversation Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Sent when a user starts a chat to initialize or resume a session. The response can be a JSON object with 'output', a JSON object with 'data' containing 'output', or a plain string. ```json // POST https://your-n8n.com/webhook/abc123/chat // Content-Type: application/json { "action": "loadPreviousSession", "sessionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "route": "general", "metadata": { "userId": "", "userEmail": "", "userLanguage": "en", "baseUrl": "https://mysite.com", "detectedLocation": { "city": "New York", "country": "US" }, "detectedTimeZone": "America/New_York", "timestamp": "2025-06-01T12:00:00.000Z" } } // Expected n8n response (any of these formats are accepted): // 1. { "output": "Welcome back! How can I help you today?" } // 2. { "data": [{ "output": "Welcome back!" }] } // 3. "Welcome back!" (plain string) ``` -------------------------------- ### Configure Skip Welcome Screen Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Set to true to bypass the initial welcome screen and directly open the chat interface. ```javascript skipWelcomeScreen: false // Optional, default: false. Set to true to skip the initial screen and go directly to the chat interface. ``` -------------------------------- ### Initialize Metadata Fields Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/demo.html Sets placeholders and pre-fills input fields for metadata overrides, including detected language and base URL. Handles timezone detection. ```javascript function initializeMetadataFields() { // --- Get detected values --- const url = window.location.href; const langMatch = url.match(/\/(\[a-z\]{2})(?:\|-\_\)(\[a-z\]{2}))?\/?(?:\?|#|$)/i); const detectedLang = langMatch ? langMatch\[0\].replace(/\s/g, '').toLowerCase() : (navigator.language || navigator.userLanguage || 'en'); const baseUrl = window.location.origin; // --- Set Placeholders --- document.getElementById('metadataUserId').placeholder = `(Default: empty)`; document.getElementById('metadataUserEmail').placeholder = `(Default: empty)`; document.getElementById('metadataLanguage').placeholder = `(Widget default: en)`; document.getElementById('metadataBaseUrl').placeholder = `(Widget default: page URL)`; document.getElementById('metadataDetectedLocation').placeholder = `(Default: auto-detected if enabled)`; document.getElementById('metadataDetectedTimezone').placeholder = `(Default: auto-detected from browser)`; // --- Clear or Prefill Inputs --- document.getElementById('metadataUserId').value = ''; document.getElementById('metadataUserEmail').value = ''; document.getElementById('metadataLanguage').value = detectedLang; // Prefill detected document.getElementById('metadataBaseUrl').value = baseUrl; // Prefill detected document.getElementById('metadataDetectedLocation').value = ''; // Clear override field // Prefill timezone try { const detectedTz = Intl.DateTimeFormat().resolvedOptions().timeZone; document.getElementById('metadataDetectedTimezone').value = detectedTz; } catch (e) { console.warn("Could not detect browser timezone.", e); document.getElementById('metadataDetectedTimezone').value = ''; // Clear if detection fails document.getElementById('metadataDetectedTimezone').placeholder = `(Could not detect)`; } } ``` -------------------------------- ### Quick Action: Select Lists Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Renders a dropdown list for users to select an option. Selecting an option sends the corresponding action as a message, or opens a URL for external options. The select list resets to its title placeholder after selection. ```text // Bot message text sent from n8n: "Which plan are you interested in? [{list:Choose a plan|Basic:I want the Basic plan for $9/mo|Pro:I want the Pro plan for $29/mo|Enterprise:I need an Enterprise quote}]" // Also accepts Portuguese alias: [{lista:...}] // On change, calls sendMessage("I want the Basic plan for $9/mo") // Select resets to title placeholder after selection. ``` -------------------------------- ### Render Quick Action Buttons Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/test-objects.html Iterates through an array of quick action configurations to create and append button elements to a container. Each button is configured with text, action, and type attributes. ```javascript quickActions.buttons.forEach(buttonConfig => { const btn = document.createElement('button'); btn.className = 'quick-action-button'; btn.textContent = buttonConfig.text; btn.dataset.action = buttonConfig.action; btn.dataset.type = buttonConfig.type || 'normal'; // Icon rendering logic would be here if applicable // btn.appendChild(icon); buttonContainer.appendChild(btn); }); ``` -------------------------------- ### Quick Action: Select Lists Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Renders a dropdown select list within a bot message. Selecting an option sends a corresponding action as a message. ```APIDOC ## Quick Action: Select Lists ### Description Displays a dropdown select list in a bot message. Selecting an option sends the associated action as a message to the bot. ### Usage Format: `[{list:Dropdown Title|Option 1 Text:Action 1|Option 2 Text:Action 2|...}]` ### Example ``` "Which plan are you interested in? [{list:Choose a plan|Basic:I want the Basic plan for $9/mo|Pro:I want the Pro plan for $29/mo|Enterprise:I need an Enterprise quote}]" ``` ### Behavior - Selecting an option (e.g., "Basic") calls `sendMessage("I want the Basic plan for $9/mo")`. - The select list resets to the title placeholder after an option is selected. - The syntax `[{lista:...}]` is an accepted Portuguese alias. ``` -------------------------------- ### Quick Action Select List Format Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Format quick action select lists. The first part is the list title, followed by options and their corresponding messages, separated by pipes. ```markdown [{list:Choose a plan|Basic:I want the Basic plan|Pro:I want the Pro plan}] ``` -------------------------------- ### Render Links for Quick Actions Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/test-objects.html Creates and appends anchor (link) elements for quick actions. Each link is configured with text, an href attribute (set to '#'), and a data-action attribute. ```javascript quickActions.links.forEach(link => { const a = document.createElement('a'); a.className = 'quick-action-link'; a.textContent = link.text; a.href = '#'; a.dataset.action = link.action; a.dataset.type = 'link'; linksContainer.appendChild(a); }); ``` -------------------------------- ### List/Select Syntax for Chat Widget Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md Use this syntax to present a list of options for the user to select. The first argument is the title, followed by option-action pairs. ```text [{list:Title|Option1:action1|Option2:action2}] ``` -------------------------------- ### Quick Action Link Format Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Format quick action links using markdown. The text will be displayed, and the action will trigger the specified message. ```markdown [See pricing](action:Show me your pricing plans) ``` -------------------------------- ### Configure N8N Chat Widget Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Set up the global `window.ChatWidgetConfig` object before loading `chat-widget.js` to customize webhook, branding, styling, proactive prompts, and UI texts. All top-level keys are optional and merge with default settings. ```html ``` -------------------------------- ### Initialize Default Languages Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/demo.html Populates multi-language containers with predefined default language fields. Ensures that default languages like 'en' and 'pt' are marked as read-only. Call this function to set up initial language inputs. ```javascript function initializeDefaultLanguages() { multiLangContainers.forEach(containerInfo => { const container = document.getElementById(containerInfo.id); if(container) container.innerHTML = ''; // Clear previous entries first Object.entries(containerInfo.defaults).forEach(([langCode, textValue]) => { const isDefaultReadOnly = langCode === 'en' || langCode === 'pt'; addLanguageInput(containerInfo.id, containerInfo.fieldName, langCode, textValue, isDefaultReadOnly); }); }); } ``` -------------------------------- ### Configure Greeting Message Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Define the initial message displayed by the bot in multiple languages. ```javascript greetingMessage: { // Optional, the first message shown by the bot. en: "Hi! How can I help you today?", pt: "Olá! Como posso ajudar você hoje?", es: "¡Hola! ¿Cómo puedo ayudarte hoy?", ar: "مرحباً! كيف يمكنني مساعدتك اليوم?" } ``` -------------------------------- ### Event Listener and Initial Render Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/test-objects.html Attaches an input event listener to a textarea for rendering templates and performs an initial render. Includes a delayed render to ensure all components are initialized. ```javascript templateTextarea.addEventListener('input', renderTemplate); // Initial render if there's a default template if (templateTextarea.value) { renderTemplate(); } // Allow a moment for everything to initialize setTimeout(() => { console.log("Initial render after delay..."); renderTemplate(); },100); // NOTE: Removed duplicate addQuickActionEventListeners function definition, // duplicate event listeners, and duplicate initial render calls that were here. }); ``` -------------------------------- ### Quick Action: Buttons Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Renders tappable buttons below a bot message. Clicking a button either sends a predefined message or opens an external URL. ```APIDOC ## Quick Action: Buttons ### Description Displays one or more buttons below a bot message. Clicking a button can send a message to the bot or open an external URL. ### Usage Format: `[{button:Button Text|Action or URL}]` ### Examples **Internal Action:** ``` "How would you like to proceed? [{button:Yes, subscribe me|I want to subscribe to the newsletter}] [{button:No thanks|I do not want to subscribe}]" ``` **External URL:** ``` "Visit our docs: [{button:Open Documentation|https://docs.example.com}]" ``` ### Behavior - Clicking an internal button (e.g., "Yes, subscribe me") calls `sendMessage("I want to subscribe to the newsletter")`. - Clicking an external button (e.g., "Open Documentation") opens the URL in a new tab: `window.open("https://docs.example.com", "_blank")`. - Up to 4 buttons are displayed. - The syntax `[{botao:Text|Action}]` is an accepted Portuguese alias. ``` -------------------------------- ### Button Syntax for Chat Widget Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md Use this syntax to create clickable buttons within the chat widget. The second argument is the button text, and the third is the action triggered. ```text [{button|Button Text|action}] ``` -------------------------------- ### Configure Proactive Prompt Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Enable and configure proactive prompts to engage users. Set the delay and customize the message for different languages. ```javascript proactivePrompt: { enabled: false, // Optional, default: false. Set to true to enable. delay: 10000, // Optional, default: 10000 (10 seconds). Delay in milliseconds before showing the prompt. message: { // Optional, message to display in the prompt. en: "Chat with our AI now!", pt: "Converse com nossa IA agora!", es: "¡Chatea con nuestra IA ahora!", ar: "تحدث مع الذكاء الاصطناعي الخاص بنا الآن!" } } ``` -------------------------------- ### Multiple Buttons Syntax for Chat Widget Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/prompt.md Use this syntax to display multiple buttons side-by-side. Each button is defined with its text and associated action. ```text [Button1](action:ACTION1) [Button2](action:ACTION2) ``` -------------------------------- ### Configure Branding Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Customize the widget's branding with a logo, name, welcome text, and response time message. Optionally, configure a 'powered by' link. ```javascript branding: { logo: 'URL_TO_YOUR_LOGO', // Optional name: 'YOUR_BRAND_NAME', // Optional welcomeText: 'Welcome message', // Optional responseTimeText: 'Response time message', // Optional poweredBy: { // Optional text: 'Powered by', link: 'https://example.com' } } ``` -------------------------------- ### Quick Action: Inline Action Links Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Allows rendering hyperlink-style text within bot messages. Clicking these links sends a predefined message to the bot. ```APIDOC ## Quick Action: Inline Action Links ### Description Sends a predefined message to the bot when a user clicks on a specially formatted link within a bot message. ### Usage Format: `[Link Text](action:Message to send)` ### Example ``` "Need help choosing? [See pricing](action:Show me your pricing plans) or [talk to sales](action:I want to talk to the sales team)." ``` ### Behavior - Clicking "See pricing" will call `sendMessage("Show me your pricing plans")`. - Clicking "talk to sales" will call `sendMessage("I want to talk to the sales team")`. ``` -------------------------------- ### Configure Style Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/README.md Customize the widget's appearance, including primary and secondary colors, position, background color, and font color. ```javascript style: { primaryColor: '#080A56', // Optional, default: '#080A56' secondaryColor: '#0b0f7b', // Optional, default: '#0b0f7b' position: 'right', // Optional, 'left' or 'right' backgroundColor: '#ffffff', // Optional, default: '#ffffff' fontColor: '#333333' // Optional, default: '#333333' } ``` -------------------------------- ### Quick Action: Inline Action Links Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Allows creating clickable links within bot messages that send predefined text as a message to the bot. These are rendered as styled anchor tags. ```text // Bot message text sent from n8n: "Need help choosing? [See pricing](action:Show me your pricing plans) or [talk to sales](action:I want to talk to the sales team)." // Rendered as styled gradient-colored anchor tags. // Clicking "See pricing" calls sendMessage("Show me your pricing plans") // Clicking "talk to sales" calls sendMessage("I want to talk to the sales team") ``` -------------------------------- ### Update Color Previews Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/demo.html Listens for input events on color pickers and updates a corresponding color preview element. Includes initial preview update on load. ```javascript document.querySelectorAll('input[type="color"]').forEach(input => { input.addEventListener('input', function() { // Ensure the preview element exists next to the input const preview = this.nextElementSibling; if (preview && preview.classList.contains('color-preview')) { preview.style.backgroundColor = this.value; } else { console.warn("Color preview element not found next to input:", this.id); } }); // Initial preview update on load input.dispatchEvent(new Event('input', { bubbles: true })); }); ``` -------------------------------- ### Render SVG Icon for Quick Actions Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/test-objects.html Creates and appends an SVG icon with specific paths and attributes to a button element. This is used for visual representation within quick action buttons. ```javascript const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); icon.setAttribute('viewBox', '0 0 24 24'); icon.setAttribute('width', '20'); icon.setAttribute('height', '20'); icon.setAttribute('stroke', 'currentColor'); icon.setAttribute('fill', 'none'); icon.setAttribute('stroke-width', '2'); icon.setAttribute('stroke-linecap', 'round'); icon.setAttribute('stroke-linejoin', 'round'); const path1 = document.createElementNS('http://www.w3.org/2000/svg', 'path'); path1.setAttribute('d', 'M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'); icon.appendChild(path1); const path2 = document.createElementNS('http://www.w3.org/2000/svg', 'path'); path2.setAttribute('d', 'M15 3h6v6'); icon.appendChild(path2); const path3 = document.createElementNS('http://www.w3.org/2000/svg', 'path'); path3.setAttribute('d', 'M10 14L21 3'); icon.appendChild(path3); btn.appendChild(icon); ``` -------------------------------- ### Quick Action: Buttons Source: https://context7.com/10k-digital/n8n-advanced-chatclient/llms.txt Renders tappable buttons below bot messages for user interaction. Up to 4 buttons can be displayed. Internal actions are sent as messages, while external URLs open in a new tab. ```text // Bot message text sent from n8n (internal action): "How would you like to proceed? [{button:Yes, subscribe me|I want to subscribe to the newsletter}] [{button:No thanks|I do not want to subscribe}]" // Bot message text with an external link button: "Visit our docs: [{button:Open Documentation|https://docs.example.com}]" // Both syntaxes work: [{button:Text|Action}] and [{botao:Text|Action}] (Portuguese alias) // Clicking an internal button: calls sendMessage("I want to subscribe to the newsletter") // Clicking an external button: window.open("https://docs.example.com", "_blank") ``` -------------------------------- ### Create Language Select Element Source: https://github.com/10k-digital/n8n-advanced-chatclient/blob/main/demo.html Dynamically creates a `