Stream respondToWebhook

Hi there,

I’m creating a respondToWebhook node with a streaming response option, but can’t figure out how to control the response header to put Content-Type: text/event-stream, My use case would be to get a steaming response from the previous node and return it to the webhook client and keep responding as long as the streaming is not closed.

Inspired by the HTTP request node, I wanted to return an array of responses with the header 'Content-Type': 'text/event-stream' but the response is considered as JSON body with no consideration of the headers put.

// For testing I'm just getting chunks of strings

let returnItems: INodeExecutionData[] = [];
		for (const chunk of chunks) {
			returnItems.push({
				json: {
					headers: {
						'Content-Type': 'text/event-stream',
					},
					body: {
						eventType: 'update',
						data: {
							message: chunk,
							timestamp: new Date().toISOString(),
						},
					},
				},
			});
		}

		return [returnItems];

also, the sendResponse function is not returning nothing at all:

		for (const chunk of chunks) {
			this.sendResponse({
				json: {
					headers: {
						'Content-Type': 'text/event-stream',
					},
					body: {
						eventType: 'update',
						data: {
							message: chunk,
							timestamp: new Date().toISOString(),
						},
					},
				},
			});

Am I missing something here?

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Very sorry, can not go into detail, but adding streaming support is more complicated, and deeper-level (core) changes in n8n are required.

Because of the amount of work and so time it would require from our side, to help you implement it (which is probably higher than doing it ourselves) we sadly not do help you. I started, however a while ago while I was traveling with the same idea. Sadly, I did not find enough time, but here is the wip code that is maybe helpful:

Good luck!

2 Likes

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