Is there a way to pass query parameters in the Chat trigger?

Describe the problem/error/question

Is there a way to pass parameters, i.e. metadata, to the Chat Trigger when the chat is not embedded on a external page, but with the hosted chat option?

I know I’m able to pass metadata using the metadata option as described in the topic below. But is there a way to pass metadata using the n8n hosted chat option?

Information on your n8n setup

  • n8n version: 1.54.0
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): k82
  • Operating system: ubuntu

Hello,
Where does the data come from?
Parameters in the URL?
Can you give a use case?

@LucBerge, thank you for your answer.

I have a “Hosted Chat” Chat Trigger which is publicly available, as shown in the screenshot below. When sending a message, and checking the execution of the workflow, I can see metadata is passed from the Chat to the execution, and those are basically user metadata.

Say this chat is accessed through https://url/abc/chat
I was thinking on passing query parameters, such as https://url/abc/chat?q=123, so I can reutilize the same webhook, but be able to pass parameters to it.

One use case would be for a Question and Answer Chain plugged to a Vector Store. I want to have many chats, each one connecting to a different Collection Name. Currently the only way is to create many Chat Webhooks, which doesn’t scale any well. I don’t believe that should be the case, since I only want to change a single parameter between chats.

I know what I’m trying to do is doable via external embedded chats, as explained in the referred topic, as you can pass metadata as a parameter, but I’m looking for a way to do it on the n8n hosted chat as well.

Hello @miguel-mconf, I just tried and indeed, query parameters are not passed to the metadata field. This is a feature you can ask for: Create a new topic and select Feature Requests.

That beeing said, there is a workaround:

  1. Create a 1st workflow with embedded chat trigger
  2. Create a simple http page with the embedded chat code
  3. Create a 2nd workflow with a webhook trigger (GET)
  4. Dynamicaly compute the http page source code based on the query parameters
  5. Return the following http page as text
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>Chatbot</title>
		<link rel="stylesheet" href="./style.css">
		<link rel="icon" href="./favicon.ico" type="image/x-icon">
		<style>
			body {
				margin: 0;
				padding: 0;
			}
			.container {
				display: flex;
				height: 600px
			}
		</style>
		<script type="module">
			import { createChat } from 'https://cdn.jsdelivr.net/npm/@n8n/chat/chat.bundle.es.js';

			createChat({
				webhookUrl: 'https://your.webhook/chat',
				target: '.container',
				mode: 'fullscreen',
				defaultLanguage: 'fr',
				metadata: {
					//Add the query parameters here
				},
				i18n: {
					fr: {
						title: 'My Bot',
						subtitle: "Simple agent.",
						inputPlaceholder: '',
					},
				},
			});
    	</script>
	</head>
	<body>
		<link href="https://cdn.jsdelivr.net/npm/@n8n/chat/style.css" rel="stylesheet" />
		<div class="container">
		</div>
  </body>
</html>
2 Likes

Hi @LucBerge , thank you very much for your answer. I’ll create the feature request as suggested, and your workaround is going to be very useful for the time being.

Edit: I’ve created the Feature Request.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.