UNPKG

n8n-nodes-coze

Version:

n8n node for Coze(扣子), supporting AI chat, workflow automation, file processing, and text-to-speech.

136 lines 5.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeChat = executeChat; async function executeChat(i) { const operation = this.getNodeParameter('operation', i); const authentication = this.getNodeParameter('authentication', i); const credentials = await this.getCredentials(authentication); if (operation === 'create') { const botId = this.getNodeParameter('botId', i); const userId = this.getNodeParameter('userId', i); const content = this.getNodeParameter('content', i); const body = { bot_id: botId, user_id: userId, }; const additionalMessagesParam = this.getNodeParameter('additionalMessages', i); if (additionalMessagesParam) { const additionalMessages = JSON.parse(additionalMessagesParam); additionalMessages.push({ role: 'user', content: content, content_type: 'text', }); body.additional_messages = additionalMessages; } else { body.additional_messages = [ { role: 'user', content: content, content_type: 'text', }, ]; } const conversationId = this.getNodeParameter('conversationId', i); if (conversationId) body.conversation_id = conversationId; const customVariablesParam = this.getNodeParameter('customVariables', i); if (customVariablesParam) body.custom_variables = JSON.parse(customVariablesParam); body.auto_save_history = this.getNodeParameter('autoSaveHistory', i); const metaDataParam = this.getNodeParameter('metaData', i); if (metaDataParam) body.meta_data = JSON.parse(metaDataParam); const extraParamsParam = this.getNodeParameter('extraParams', i); if (extraParamsParam) body.extra_params = JSON.parse(extraParamsParam); const shortcutCommandParam = this.getNodeParameter('shortcutCommand', i); if (shortcutCommandParam) body.shortcut_command = JSON.parse(shortcutCommandParam); const parametersParam = this.getNodeParameter('parameters', i); if (parametersParam) body.parameters = JSON.parse(parametersParam); body.enable_card = this.getNodeParameter('enableCard', i); const options = { baseURL: credentials.baseUrl, method: 'POST', url: `/v3/chat`, body, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } else if (operation === 'retrieve') { const conversationId = this.getNodeParameter('conversationId', i); const chatId = this.getNodeParameter('chatId', i); const qs = { conversation_id: conversationId, chat_id: chatId, }; const options = { baseURL: credentials.baseUrl, method: 'GET', url: `/v3/chat/retrieve`, qs, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } else if (operation === 'listMessages') { const conversationId = this.getNodeParameter('conversationId', i); const chatId = this.getNodeParameter('chatId', i); const qs = { conversation_id: conversationId, chat_id: chatId, }; const options = { baseURL: credentials.baseUrl, method: 'GET', url: `/v3/chat/message/list`, qs, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } else if (operation === 'submitToolOutputs') { const conversationId = this.getNodeParameter('conversationId', i); const chatId = this.getNodeParameter('chatId', i); const toolOutputs = this.getNodeParameter('toolOutputs', i); const stream = this.getNodeParameter('stream', i); const qs = { conversation_id: conversationId, chat_id: chatId, }; const body = { tool_outputs: JSON.parse(toolOutputs), stream, }; const options = { baseURL: credentials.baseUrl, method: 'POST', url: `/v3/chat/submit_tool_outputs`, qs, body, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } else if (operation === 'cancel') { const conversationId = this.getNodeParameter('conversationId', i); const chatId = this.getNodeParameter('chatId', i); const qs = { conversation_id: conversationId, chat_id: chatId, }; const options = { baseURL: credentials.baseUrl, method: 'POST', url: `/v3/chat/cancel`, qs, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } } //# sourceMappingURL=chat.js.map