Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion nodes/WAHA/WAHA.node.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"node": "n8n-nodes-waha.WAHA",
"node": "n8n-nodes-waha.waha",
"nodeVersion": "1.0",
"codexVersion": "1.0",
"categories": ["Whatsapp"],
Expand Down
4 changes: 2 additions & 2 deletions nodes/WAHA/base/node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {INodeTypeBaseDescription, NodeConnectionType} from "n8n-workflow";

export const BASE_DESCRIPTION: INodeTypeBaseDescription = {
name: 'WAHA',
name: 'waha',
displayName: 'WAHA',
icon: 'file:waha.svg',
description: 'Connect with Whatsapp HTTP API',
Expand All @@ -14,7 +14,7 @@ export const NODE_DESCRIPTION = {
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
defaults: {
name: 'WAHA',
name: 'waha',
},
credentials: [
{
Expand Down
58 changes: 2 additions & 56 deletions nodes/WAHA/v202502/WAHATriggerV202502.test.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,7 @@
import { configuredOutputs } from './utils';
import { WAHATriggerV202502 } from './WAHATriggerV202502';

test('WAHATriggerV202502.outputs', () => {
const node = new WAHATriggerV202502();
expect(node.description.outputs).toEqual([
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main",
"main"
] );
expect(node.description.outputNames).toEqual([
"session.status",
"message",
"message.reaction",
"message.any",
"message.ack",
"message.waiting",
"message.revoked",
"state.change",
"group.join",
"group.leave",
"group.v2.join",
"group.v2.leave",
"group.v2.update",
"group.v2.participants",
"presence.update",
"poll.vote",
"poll.vote.failed",
"chat.archive",
"call.received",
"call.accepted",
"call.rejected",
"label.upsert",
"label.deleted",
"label.chat.added",
"label.chat.deleted",
"engine.event"
]);
expect(node.description.outputs).toEqual(`={{(${configuredOutputs})($parameter)}}`);
});
33 changes: 17 additions & 16 deletions nodes/WAHA/v202502/WAHATriggerV202502.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import {
INodeType,
INodeTypeDescription, NodeConnectionType,
INodeTypeDescription,
} from 'n8n-workflow';

import * as doc from './openapi.json';
import {
BASE_TRIGGER_DESCRIPTION,
CONFIGURE_WEBHOOK_NOTE,
makeEventNote, makeWebhookForEvents,
makeWebhookForEvents,
TRIGGER_DESCRIPTION,
} from '../base/trigger';
import { configuredOutputs, events } from './utils';

function getEvents() {
const schemas = doc.components.schemas;
const schema = schemas.WAHAWebhookSessionStatus;
const event = schema.properties.event;
return event.enum;
}

const events = getEvents();
const outputs = events.map((_) => NodeConnectionType.Main);
const outputNames = events;
const defaultEvent = 'message'


export class WAHATriggerV202502 implements INodeType {
description: INodeTypeDescription = {
...BASE_TRIGGER_DESCRIPTION,
...TRIGGER_DESCRIPTION,
version: 202502,
outputs: outputs,
outputNames: outputNames,
properties: [CONFIGURE_WEBHOOK_NOTE, makeEventNote(events)],
outputs: `={{(${configuredOutputs})($parameter)}}`,
properties: [CONFIGURE_WEBHOOK_NOTE, {
displayName: 'Events',
name: 'listenEvents',
type: 'multiOptions',
options: [
...events.map(event => ({name: event, value: event})),
],
required: true,
default: [
defaultEvent
],
}],
};
webhook = makeWebhookForEvents(events)
}
30 changes: 30 additions & 0 deletions nodes/WAHA/v202502/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import { INodeOutputConfiguration, INodeParameters, NodeConnectionType } from 'n8n-workflow';
import * as doc from './openapi.json';

function getEvents() {
const schemas = doc.components.schemas;
const schema = schemas.WAHAWebhookSessionStatus;
const event = schema.properties.event;
return event.enum;
}

export const events = getEvents();

export const configuredOutputs = (parameters: INodeParameters) => {
const listenEvents = parameters.listenEvents as string[];

if (listenEvents.length == 0) {
return []
}

let ruleOutputs: INodeOutputConfiguration[] = listenEvents.map((event, index): INodeOutputConfiguration => {
return {
type: NodeConnectionType.Main,
displayName: event || index.toString(),
};
});


return ruleOutputs
};