diff --git a/packages/@n8n/chat/src/plugins/chat.ts b/packages/@n8n/chat/src/plugins/chat.ts index 80b343ac4554e..a460a5274e9ea 100644 --- a/packages/@n8n/chat/src/plugins/chat.ts +++ b/packages/@n8n/chat/src/plugins/chat.ts @@ -45,9 +45,19 @@ export const ChatPlugin: Plugin = { options, ); + let textMessage = sendMessageResponse.output ?? sendMessageResponse.text ?? ''; + + if (textMessage === '' && Object.keys(sendMessageResponse).length > 0) { + try { + textMessage = JSON.stringify(sendMessageResponse, null, 2); + } catch (e) { + // Failed to stringify the object so fallback to empty string + } + } + const receivedMessage: ChatMessage = { id: uuidv4(), - text: sendMessageResponse.output, + text: textMessage, sender: 'bot', createdAt: new Date().toISOString(), }; diff --git a/packages/@n8n/chat/src/types/webhook.ts b/packages/@n8n/chat/src/types/webhook.ts index 16cd44678faf2..5926a8248bb91 100644 --- a/packages/@n8n/chat/src/types/webhook.ts +++ b/packages/@n8n/chat/src/types/webhook.ts @@ -13,5 +13,6 @@ export interface LoadPreviousSessionResponse { } export interface SendMessageResponse { - output: string; + output?: string; + text?: string; }