No messages yet
Start the conversation to trigger your n8n workflow
{chat.text}
{new Date(chat.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
import { useState } from 'react'; import { Send, Loader2, MessageSquare } from 'lucide-react'; export default function ChatInterface() { const [message, setMessage] = useState(''); const [chatHistory, setChatHistory] = useState([]); const [isLoading, setIsLoading] = useState(false); const sendMessage = async (e) => { e.preventDefault(); if (!message.trim()) return; setIsLoading(true); const newMessage = { text: message, sender: 'user', timestamp: new Date().toISOString() }; setChatHistory(prev => [...prev, newMessage]); try { // Replace YOUR_N8N_WEBHOOK_URL with your actual n8n webhook URL const response = await fetch('YOUR_N8N_WEBHOOK_URL', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ message: message, timestamp: new Date().toISOString(), }), }); if (response.ok) { // Add system response if your n8n workflow sends one back const data = await response.json(); if (data.response) { setChatHistory(prev => [...prev, { text: data.response, sender: 'system', timestamp: new Date().toISOString() }]); } } } catch (error) { console.error('Error sending message:', error); setChatHistory(prev => [...prev, { text: 'Error sending message. Please try again.', sender: 'system', timestamp: new Date().toISOString() }]); } setIsLoading(false); setMessage(''); }; return (
Connected to your workflow
No messages yet
Start the conversation to trigger your n8n workflow
{chat.text}
{new Date(chat.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}