@vocantai/n8n-nodes-translation-vocantai
Version:
Audio file transcription services. Your speech. Private.
99 lines • 3.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VocantAITrigger = void 0;
class VocantAITrigger {
constructor() {
this.description = {
displayName: 'Vocant AI Callback',
name: 'vocantAITrigger',
icon: 'file:vocant.svg',
group: ['trigger'],
version: 1,
description: 'Receives transcription results from Vocant AI',
defaults: {
name: 'Vocant AI Callback',
},
inputs: [],
outputs: ["main"],
webhooks: [
{
name: 'default',
httpMethod: 'POST',
responseMode: 'onReceived',
path: 'webhook',
},
],
credentials: [
{
name: 'vocantApi',
required: true,
},
],
properties: [],
};
}
async webhook() {
const req = this.getRequestObject();
const headers = this.getHeaderData();
const webhookData = req.body;
const credentials = await this.getCredentials('vocantApi');
const authToken = credentials.apiKey;
if (authToken && headers['x-api-key'] !== authToken) {
throw new Error('Unauthorized');
}
try {
if (!webhookData || !webhookData.jobId) {
throw new Error('Invalid webhook data: jobId');
}
const jobId = webhookData.jobId;
const downloadOptions = {
method: 'GET',
url: `https://app.vocant.ai/api/webhook/download/${jobId}`,
headers: {
'x-api-key': credentials.apiKey,
},
encoding: 'text',
};
const response = await this.helpers.httpRequest(downloadOptions);
const binaryResponse = {
data: Buffer.from(response).toString('base64'),
mimeType: 'text/plain',
fileName: `transcription_${jobId}.txt`,
};
return {
workflowData: [
[
{
json: {
success: true,
jobId,
timestamp: new Date().toISOString(),
},
binary: {
data: binaryResponse,
},
},
],
],
};
}
catch (error) {
return {
workflowData: [
[
{
json: {
status: 'error',
message: error.message,
originalData: webhookData,
timestamp: new Date().toISOString(),
},
},
],
],
};
}
}
}
exports.VocantAITrigger = VocantAITrigger;
//# sourceMappingURL=VocantAITrigger.node.js.map