Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(WebSocket Node): New node #3393

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e58f910
:zap: Add thread and threadLabel resource
RicardoE105 Dec 28, 2021
df6718f
:zap: Improvements
RicardoE105 Jan 3, 2022
067330c
:zap: Improvements
RicardoE105 Jan 3, 2022
a45815a
Add fix when there no references defined
RicardoE105 Jan 4, 2022
3748ec4
upstream merge
michael-radency Mar 20, 2022
b950cec
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Mar 24, 2022
f406b9a
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Mar 29, 2022
4aee96a
Merge branch 'master' of https://github.com/n8n-io/n8n into feature/g…
michael-radency May 19, 2022
374f9e8
:zap: added delete, trash, untrash operations to threads resourse, li…
michael-radency May 19, 2022
03b87c9
:zap: fix for accesing subject and references
michael-radency May 19, 2022
83f7a6f
Merge branch 'master' of https://github.com/n8n-io/n8n into feature/g…
michael-radency May 23, 2022
bf0da3a
:zap: get all labels
michael-radency May 23, 2022
2ca1eaa
:hammer: trigger node
michael-radency May 28, 2022
4168b03
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jun 12, 2022
d73bd88
Merge branch 'master' of https://github.com/michael-radency/n8n
michael-radency Jun 12, 2022
aedc0c6
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jun 16, 2022
c41f9cb
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 11, 2022
35b69ad
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 14, 2022
138c688
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 18, 2022
bd24a68
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 19, 2022
139eaab
Merge branch 'master' of https://github.com/n8n-io/n8n into feature/g…
michael-radency Jul 19, 2022
e2ee7ce
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 19, 2022
b6acf15
:zap: linter fixes
michael-radency Jul 19, 2022
7816681
:zap: ui fixes
michael-radency Jul 19, 2022
6279023
:hammer: setup for versioning
michael-radency Jul 20, 2022
aad0592
:hammer: UI fixes
michael-radency Jul 20, 2022
fe9c815
:zap: mark as read/unread operations
michael-radency Jul 20, 2022
1baaee5
:zap: input change for Send To and email validation
michael-radency Jul 20, 2022
c45e83c
:zap: sender option
michael-radency Jul 21, 2022
a95276c
Merge branch 'master' of https://github.com/n8n-io/n8n into n8n-4124-…
michael-radency Jul 21, 2022
9ba67a4
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 21, 2022
349975d
Merge branch 'master' of https://github.com/michael-radency/n8n
michael-radency Jul 21, 2022
73d78c1
:zap: linter fixes
michael-radency Jul 21, 2022
b56f89e
Merge branch 'n8n-4124-overhaul-gmail-node' of https://github.com/n8n…
michael-radency Jul 21, 2022
82bdfb6
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Jul 25, 2022
e508c7d
Merge branch 'master' of https://github.com/michael-radency/n8n
michael-radency Jul 25, 2022
2ab080c
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency Aug 12, 2022
8340250
Merge branch 'master' of https://github.com/michael-radency/n8n
michael-radency Aug 12, 2022
49d1366
Merge branch 'master' of https://github.com/n8n-io/n8n into pr/michae…
michael-radency Nov 3, 2022
dfdaee9
:zap: webSocket node
michael-radency Nov 3, 2022
4033689
:zap: check for bufferedAmount
michael-radency Nov 3, 2022
4d42753
Merge branch 'master' of https://github.com/n8n-io/n8n
michael-radency May 6, 2023
b8bba88
Merge branch 'master' of https://github.com/michael-radency/n8n into …
michael-radency May 6, 2023
a91f80e
sync with master
michael-radency May 6, 2023
b136543
linter fixes
michael-radency May 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
INodeProperties,
} from 'n8n-workflow';

export const messageLabelOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [
'messageLabel',
],
},
},
options: [
{
name: 'Add',
value: 'add',
action: 'Add a label to a message',
},
{
name: 'Remove',
value: 'remove',
action: 'Remove a label from a message',
},
],
default: 'add',
},
];

export const messageLabelFields: INodeProperties[] = [
{
displayName: 'Message ID',
name: 'messageId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'messageLabel',
],
operation: [
'add',
'remove',
],
},
},
placeholder: '172ce2c4a72cc243',
},
{
displayName: 'Label Names or IDs',
name: 'labelIds',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getLabels',
},
default: [],
required: true,
displayOptions: {
show: {
resource: [
'messageLabel',
],
operation: [
'add',
'remove',
],
},
},
description: 'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
INodeProperties,
} from 'n8n-workflow';

export const threadLabelOperations: INodeProperties[] = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
resource: [
'threadLabel',
],
},
},
options: [
{
name: 'Add',
value: 'add',
action: 'Add a thread label',
},
{
name: 'Remove',
value: 'remove',
action: 'Remove a thread label',
},
],
default: 'add',
},
];

export const threadLabelFields: INodeProperties[] = [
{
displayName: 'Thread ID',
name: 'threadId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
resource: [
'threadLabel',
],
operation: [
'add',
'remove',
],
},
},
},
{
displayName: 'Label ID Names or IDs',
name: 'labelIds',
type: 'multiOptions',
description: 'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: {
loadOptionsMethod: 'getLabels',
},
default: [],
required: true,
displayOptions: {
show: {
resource: [
'threadLabel',
],
operation: [
'add',
'remove',
],
},
},
},
];
14 changes: 14 additions & 0 deletions packages/nodes-base/nodes/WebSocket/WebSocket.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"node": "n8n-nodes-base.webSocket",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Development"],
"resources": {
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.websocket/"
}
]
},
"alias": ["Socket", "Channel", "wss"]
}
177 changes: 177 additions & 0 deletions packages/nodes-base/nodes/WebSocket/WebSocket.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import type { IExecuteFunctions } from 'n8n-core';
import type { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
import { WebSocket as WebSocketClient } from 'ws';
import type { ClientBinaryType } from './interface';

export class WebSocket implements INodeType {
description: INodeTypeDescription = {
displayName: 'WebSocket',
name: 'webSocket',
icon: 'file:websocket.svg',
group: ['input'],
version: 1,
description: 'Send messages to a WebSocket server',
defaults: {
name: 'WebSocket',
},
inputs: ['main'],
outputs: ['main'],
properties: [
{
displayName: 'Address',
name: 'address',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Use Input Data',
name: 'useInputData',
type: 'boolean',
default: true,
required: true,
description: 'Whether to use the input data or the message property',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
useInputData: [false],
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Binary Type',
name: 'binaryType',
type: 'options',
default: 'nodebuffer',
options: [
{
name: 'Node Buffer',
value: 'nodebuffer',
},
{
name: 'Array Buffer',
value: 'arraybuffer',
},
{
name: 'Fragments',
value: 'fragments',
},
],
},
{
displayName: 'Message Encoding',
name: 'encoding',
type: 'string',
default: 'utf8',
},
{
displayName: 'Parse JSON',
name: 'toJson',
type: 'boolean',
default: false,
},
],
},
],
};

async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();

const returnData: INodeExecutionData[] = [];

const address = this.getNodeParameter('address', 0) as string;
const options = this.getNodeParameter('options', 0);
const useInputData = this.getNodeParameter('useInputData', 0) as boolean;

const client = new WebSocketClient(address);

if (options.binaryType) {
client.binaryType = options.binaryType as ClientBinaryType;
}

// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;

async function manualTriggerFunction() {
return new Promise((resolve, reject) => {
client.on('open', () => {
if (useInputData) {
for (let i = 0; i < items.length; i++) {
const item = items[i].json;
client.send(JSON.stringify(item), (error) => {
if (error) {
if (self.continueOnFail()) {
returnData.push({ json: { error: error.message } });
} else {
throw error;
}
}
});
returnData.push({ json: items[i].json });
}
resolve(true);
} else {
const message = self.getNodeParameter('message', 0) as string;
client.send(message, (error) => {
if (error) {
if (self.continueOnFail()) {
returnData.push({ json: { error: error.message } });
} else {
throw error;
}
}
});
returnData.push({ json: { message } });
resolve(true);
}
});

// client.on('message', (data, isBinary) => {
// const message = isBinary ? data : data.toString(encoding as BufferEncoding);
// console.log('message', message);
// if (useInputData) {
// if (message === JSON.stringify(items[items.length - 1].json)) {
// resolve(true);
// }
// } else {
// if (message === self.getNodeParameter('message', 0)) {
// resolve(true);
// }
// }
// });

client.on('error', (error) => {
if (self.continueOnFail()) {
returnData.push({ json: { error: error.message } });
} else {
reject(error);
}
});
});
}

await manualTriggerFunction();

while (client.bufferedAmount > 0) {
await new Promise((resolve) => setTimeout(resolve, 100));
}

client.terminate();

return this.prepareOutputData(returnData);
}
}
14 changes: 14 additions & 0 deletions packages/nodes-base/nodes/WebSocket/WebSocketTrigger.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"node": "n8n-nodes-base.webSocketTrigger",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Development"],
"resources": {
"primaryDocumentation": [
{
"url": "https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.websockettrigger/"
}
]
},
"alias": ["Socket", "Channel", "wss"]
}
Loading