@thaleslaray/n8n-nodes-elevenlabs
Version:
Nó n8n para integração com a API da ElevenLabs incluindo Speech-to-Text, Text-to-Speech e Conversational AI
45 lines (44 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatReturnData = exports.handleApiError = exports.createBaseOptions = void 0;
const n8n_workflow_1 = require("n8n-workflow");
async function createBaseOptions(endpoint, method = 'GET', body, formData) {
const credentials = await this.getCredentials('elevenLabsApi');
if (!credentials) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Credenciais da ElevenLabs não foram fornecidas');
}
const options = {
headers: {
'xi-api-key': credentials.apiKey,
'Accept': 'application/json',
},
method,
uri: `https://api.elevenlabs.io/v1/${endpoint}`,
json: true,
};
if (body) {
options.body = body;
}
if (formData) {
options.formData = formData;
}
return options;
}
exports.createBaseOptions = createBaseOptions;
function handleApiError(error, itemIndex) {
if (this.continueOnFail()) {
return {
json: { error: error.message || 'Erro desconhecido' },
pairedItem: { item: itemIndex },
};
}
throw error;
}
exports.handleApiError = handleApiError;
function formatReturnData(response, itemIndex) {
return {
json: response,
pairedItem: { item: itemIndex },
};
}
exports.formatReturnData = formatReturnData;