Learn how to integrate your chat widgets with n8n workflows or your custom backend, including response formats and setup instructions.
Widgets built with N8N Chat UI can be directly connected to n8n workflows or any custom backend that implements the required response format. This guide covers the response structure and setup instructions for both approaches.
Response Format
Your backend (whether n8n or custom) must return a JSON object with the following structure:
{ "output": "Your response text to render"}
Note for n8n users: If you encounter an "Unexpected end of JSON input" error, you need to JSON stringify your response before sending it. This is a common issue that occurs because the chat widget expects properly formatted text data in the response. When your dynamic output contains double quotes or special characters and you try to wrap it again with quotes manually, it can cause JSON parsing errors.
Using JSON.stringify() properly escapes any quotes and special characters in your content. Here's exactly how your response body should look in n8n's Respond to Webhook node:
{ "output": {{ JSON.stringify($json.output) }}}
Important: Do not wrap the {{ JSON.stringify(...) }} expressions with quotes, as the JSON.stringify() function already handles the proper quoting and escaping of the content. The expression should be used exactly as shown above in the Respond to Webhook node's Response Body field.
Required Fields
output - The text you want displayed in the chat window. Supports both plain text and rich formatting with Markdown & HTML. Learn more about formatting options.
Optional Fields
followUpPrompts - An array of predefined messages or questions that appear as clickable buttons below the chat response. When a user clicks one of these suggestions, it's automatically sent as their next message.
{ // other fields... "followUpPrompts": ["Track my order", "I need help", "Cancel order"]}