mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 22:54:05 -08:00
88dea330b9
* ⚡ Update `lintfix` script * ⚡ Run baseline `lintfix` * 🔥 Remove unneeded exceptions (#3538) * 🔥 Remove exceptions for `node-param-default-wrong-for-simplify` * 🔥 Remove exceptions for `node-param-placeholder-miscased-id` * ⚡ Update version * 👕 Apply `node-param-placeholder-missing` (#3542) * 👕 Apply `filesystem-wrong-cred-filename` (#3543) * 👕 Apply `node-param-description-missing-from-dynamic-options` (#3545) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-class-description-empty-string` (#3546) * 👕 Apply `node-class-description-icon-not-svg` (#3548) * 👕 Apply `filesystem-wrong-node-filename` (#3549) Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Expand lintings to credentials (#3550) * 👕 Apply `node-param-multi-options-type-unsorted-items` (#3552) * ⚡ fix * ⚡ Minor fixes Co-authored-by: Michael Kret <michael.k@radency.com> * 👕 Apply `node-param-description-wrong-for-dynamic-multi-options` (#3541) * ⚡ Add new lint rule, node-param-description-wrong-for-dynamic-multi-options * ⚡ Fix with updated linting rules * ⚡ Minor fixes Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply `node-param-description-boolean-without-whether` (#3553) * ⚡ fix * Update packages/nodes-base/nodes/Clockify/ProjectDescription.ts Co-authored-by: Iván Ovejero <ivov.src@gmail.com> * 👕 Apply node-param-display-name-wrong-for-dynamic-multi-options (#3537) * 👕 Add exceptions * 👕 Add exception * ✏️ Alphabetize rules * ⚡ Restore `lintfix` command Co-authored-by: agobrech <45268029+agobrech@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: brianinoa <54530642+brianinoa@users.noreply.github.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com>
317 lines
6.9 KiB
TypeScript
317 lines
6.9 KiB
TypeScript
|
|
import {
|
|
IExecuteFunctions,
|
|
} from 'n8n-core';
|
|
|
|
import {
|
|
IDataObject,
|
|
INodeExecutionData,
|
|
INodeType,
|
|
INodeTypeDescription,
|
|
} from 'n8n-workflow';
|
|
|
|
import {
|
|
IData,
|
|
} from './Interface';
|
|
|
|
import {
|
|
googleApiRequest,
|
|
} from './GenericFunctions';
|
|
|
|
export class GoogleCloudNaturalLanguage implements INodeType {
|
|
description: INodeTypeDescription = {
|
|
displayName: 'Google Cloud Natural Language',
|
|
name: 'googleCloudNaturalLanguage',
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
|
icon: 'file:googlecloudnaturallanguage.png',
|
|
group: ['input', 'output'],
|
|
version: 1,
|
|
description: 'Consume Google Cloud Natural Language API',
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
defaults: {
|
|
name: 'Google Cloud Natural Language',
|
|
},
|
|
inputs: ['main'],
|
|
outputs: ['main'],
|
|
credentials: [
|
|
{
|
|
name: 'googleCloudNaturalLanguageOAuth2Api',
|
|
required: true,
|
|
},
|
|
],
|
|
properties: [
|
|
{
|
|
displayName: 'Resource',
|
|
name: 'resource',
|
|
type: 'options',
|
|
noDataExpression: true,
|
|
options: [
|
|
{
|
|
name: 'Document',
|
|
value: 'document',
|
|
},
|
|
],
|
|
default: 'document',
|
|
},
|
|
{
|
|
displayName: 'Operation',
|
|
name: 'operation',
|
|
type: 'options',
|
|
noDataExpression: true,
|
|
displayOptions: {
|
|
show: {
|
|
resource: [
|
|
'document',
|
|
],
|
|
},
|
|
},
|
|
options: [
|
|
{
|
|
name: 'Analyze Sentiment',
|
|
value: 'analyzeSentiment',
|
|
},
|
|
],
|
|
default: 'analyzeSentiment',
|
|
},
|
|
// ----------------------------------
|
|
// All
|
|
// ----------------------------------
|
|
{
|
|
displayName: 'Source',
|
|
name: 'source',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'Content',
|
|
value: 'content',
|
|
},
|
|
{
|
|
name: 'Google Cloud Storage URI',
|
|
value: 'gcsContentUri',
|
|
},
|
|
],
|
|
default: 'content',
|
|
description: 'The source of the document: a string containing the content or a Google Cloud Storage URI',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
operation: [
|
|
'analyzeSentiment',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
displayName: 'Content',
|
|
name: 'content',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The content of the input in string format. Cloud audit logging exempt since it is based on user data.',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
operation: [
|
|
'analyzeSentiment',
|
|
],
|
|
source: [
|
|
'content',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
displayName: 'Google Cloud Storage URI',
|
|
name: 'gcsContentUri',
|
|
type: 'string',
|
|
default: '',
|
|
description: 'The Google Cloud Storage URI where the file content is located. This URI must be of the form: <code>gs://bucket_name/object_name</code>. For more details, see <a href="https://cloud.google.com/storage/docs/reference-uris.">reference</a>.',
|
|
required: true,
|
|
displayOptions: {
|
|
show: {
|
|
operation: [
|
|
'analyzeSentiment',
|
|
],
|
|
source: [
|
|
'gcsContentUri',
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
displayName: 'Options',
|
|
name: 'options',
|
|
type: 'collection',
|
|
displayOptions: {
|
|
show: {
|
|
operation: [
|
|
'analyzeSentiment',
|
|
],
|
|
},
|
|
},
|
|
default: {},
|
|
placeholder: 'Add Option',
|
|
options: [
|
|
{
|
|
displayName: 'Document Type',
|
|
name: 'documentType',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'HTML',
|
|
value: 'HTML',
|
|
},
|
|
{
|
|
name: 'Plain Text',
|
|
value: 'PLAIN_TEXT',
|
|
},
|
|
],
|
|
default: 'PLAIN_TEXT',
|
|
description: 'The type of input document',
|
|
required: true,
|
|
},
|
|
{
|
|
displayName: 'Encoding Type',
|
|
name: 'encodingType',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'None',
|
|
value: 'NONE',
|
|
},
|
|
{
|
|
name: 'UTF-8',
|
|
value: 'UTF8',
|
|
},
|
|
{
|
|
name: 'UTF-16',
|
|
value: 'UTF16',
|
|
},
|
|
{
|
|
name: 'UTF-32',
|
|
value: 'UTF32',
|
|
},
|
|
],
|
|
default: 'UTF16',
|
|
description: 'The encoding type used by the API to calculate sentence offsets',
|
|
},
|
|
{
|
|
displayName: 'Language',
|
|
name: 'language',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
name: 'Arabic',
|
|
value: 'ar',
|
|
},
|
|
{
|
|
name: 'Chinese (Simplified)',
|
|
value: 'zh',
|
|
},
|
|
{
|
|
name: 'Chinese (Traditional)',
|
|
value: 'zh-Hant',
|
|
},
|
|
{
|
|
name: 'Dutch',
|
|
value: 'nl',
|
|
},
|
|
{
|
|
name: 'English',
|
|
value: 'en',
|
|
},
|
|
{
|
|
name: 'French',
|
|
value: 'fr',
|
|
},
|
|
{
|
|
name: 'German',
|
|
value: 'de',
|
|
},
|
|
{
|
|
name: 'Indonesian',
|
|
value: 'id',
|
|
},
|
|
{
|
|
name: 'Italian',
|
|
value: 'it',
|
|
},
|
|
{
|
|
name: 'Japanese',
|
|
value: 'ja',
|
|
},
|
|
{
|
|
name: 'Korean',
|
|
value: 'ko',
|
|
},
|
|
{
|
|
name: 'Portuguese (Brazilian & Continental)',
|
|
value: 'pt',
|
|
},
|
|
{
|
|
name: 'Spanish',
|
|
value: 'es',
|
|
},
|
|
{
|
|
name: 'Thai',
|
|
value: 'th',
|
|
},
|
|
{
|
|
name: 'Turkish',
|
|
value: 'tr',
|
|
},
|
|
{
|
|
name: 'Vietnamese',
|
|
value: 'vi',
|
|
},
|
|
],
|
|
default: 'en',
|
|
placeholder: '',
|
|
description: 'The language of the document (if not specified, the language is automatically detected). Both ISO and BCP-47 language codes are accepted.',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
const items = this.getInputData();
|
|
const length = items.length;
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
const responseData = [];
|
|
for (let i = 0; i < length; i++) {
|
|
if (resource === 'document') {
|
|
if (operation === 'analyzeSentiment') {
|
|
const source = this.getNodeParameter('source', i) as string;
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
|
const encodingType = (options.encodingType as string | undefined) || 'UTF16';
|
|
const documentType = (options.documentType as string | undefined) || 'PLAIN_TEXT';
|
|
|
|
const body: IData = {
|
|
document: {
|
|
type: documentType,
|
|
},
|
|
encodingType,
|
|
};
|
|
|
|
if (source === 'content') {
|
|
const content = this.getNodeParameter('content', i) as string;
|
|
body.document.content = content;
|
|
} else {
|
|
const gcsContentUri = this.getNodeParameter('gcsContentUri', i) as string;
|
|
body.document.gcsContentUri = gcsContentUri;
|
|
}
|
|
|
|
if (options.language) {
|
|
body.document.language = options.language as string;
|
|
}
|
|
|
|
const response = await googleApiRequest.call(this, 'POST', `/v1/documents:analyzeSentiment`, body);
|
|
responseData.push(response);
|
|
}
|
|
}
|
|
}
|
|
return [this.helpers.returnJsonArray(responseData)];
|
|
}
|
|
}
|