Skip to content

Commit

Permalink
fix(editor): Fix an issue with an empty chat response if not in `outp…
Browse files Browse the repository at this point in the history
…ut` property (#8913)

Signed-off-by: Oleg Ivaniv <[email protected]>
  • Loading branch information
OlegIvaniv authored Mar 18, 2024
1 parent 0c179e4 commit 024be62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/@n8n/chat/src/plugins/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ export const ChatPlugin: Plugin<ChatOptions> = {
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(),
};
Expand Down
3 changes: 2 additions & 1 deletion packages/@n8n/chat/src/types/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export interface LoadPreviousSessionResponse {
}

export interface SendMessageResponse {
output: string;
output?: string;
text?: string;
}

0 comments on commit 024be62

Please sign in to comment.