n8n-nodes-wwebjs-api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +204 -0
  2. package/README.md +381 -0
  3. package/dist/credentials/WWebJsApiCredentials.d.ts +9 -0
  4. package/dist/credentials/WWebJsApiCredentials.js +54 -0
  5. package/dist/credentials/WWebJsApiCredentials.js.map +1 -0
  6. package/dist/nodes/WWebJsApi/WWebJsApi.node.d.ts +5 -0
  7. package/dist/nodes/WWebJsApi/WWebJsApi.node.js +516 -0
  8. package/dist/nodes/WWebJsApi/WWebJsApi.node.js.map +1 -0
  9. package/dist/nodes/WWebJsApi/WWebJsApiTrigger.node.d.ts +5 -0
  10. package/dist/nodes/WWebJsApi/WWebJsApiTrigger.node.js +363 -0
  11. package/dist/nodes/WWebJsApi/WWebJsApiTrigger.node.js.map +1 -0
  12. package/dist/nodes/WWebJsApi/descriptions/ChannelDescription.d.ts +3 -0
  13. package/dist/nodes/WWebJsApi/descriptions/ChannelDescription.js +114 -0
  14. package/dist/nodes/WWebJsApi/descriptions/ChannelDescription.js.map +1 -0
  15. package/dist/nodes/WWebJsApi/descriptions/ChatDescription.d.ts +3 -0
  16. package/dist/nodes/WWebJsApi/descriptions/ChatDescription.js +73 -0
  17. package/dist/nodes/WWebJsApi/descriptions/ChatDescription.js.map +1 -0
  18. package/dist/nodes/WWebJsApi/descriptions/ClientDescription.d.ts +3 -0
  19. package/dist/nodes/WWebJsApi/descriptions/ClientDescription.js +220 -0
  20. package/dist/nodes/WWebJsApi/descriptions/ClientDescription.js.map +1 -0
  21. package/dist/nodes/WWebJsApi/descriptions/ContactDescription.d.ts +3 -0
  22. package/dist/nodes/WWebJsApi/descriptions/ContactDescription.js +45 -0
  23. package/dist/nodes/WWebJsApi/descriptions/ContactDescription.js.map +1 -0
  24. package/dist/nodes/WWebJsApi/descriptions/GroupChatDescription.d.ts +3 -0
  25. package/dist/nodes/WWebJsApi/descriptions/GroupChatDescription.js +84 -0
  26. package/dist/nodes/WWebJsApi/descriptions/GroupChatDescription.js.map +1 -0
  27. package/dist/nodes/WWebJsApi/descriptions/MessageDescription.d.ts +3 -0
  28. package/dist/nodes/WWebJsApi/descriptions/MessageDescription.js +135 -0
  29. package/dist/nodes/WWebJsApi/descriptions/MessageDescription.js.map +1 -0
  30. package/dist/nodes/WWebJsApi/descriptions/SessionDescription.d.ts +3 -0
  31. package/dist/nodes/WWebJsApi/descriptions/SessionDescription.js +44 -0
  32. package/dist/nodes/WWebJsApi/descriptions/SessionDescription.js.map +1 -0
  33. package/dist/nodes/WWebJsApi/descriptions/index.d.ts +7 -0
  34. package/dist/nodes/WWebJsApi/descriptions/index.js +25 -0
  35. package/dist/nodes/WWebJsApi/descriptions/index.js.map +1 -0
  36. package/dist/nodes/WWebJsApi/transport.d.ts +53 -0
  37. package/dist/nodes/WWebJsApi/transport.js +253 -0
  38. package/dist/nodes/WWebJsApi/transport.js.map +1 -0
  39. package/dist/nodes/WWebJsApi/types.d.ts +139 -0
  40. package/dist/nodes/WWebJsApi/types.js +6 -0
  41. package/dist/nodes/WWebJsApi/types.js.map +1 -0
  42. package/dist/nodes/WWebJsApi/wwebjs-api.svg +10 -0
  43. package/package.json +65 -0
@@ -0,0 +1,53 @@
1
+ import type { IExecuteFunctions, IDataObject, IHttpRequestMethods } from 'n8n-workflow';
2
+ import type { ContentType, ParsedContent, ValidationResult } from './types';
3
+ /**
4
+ * Validates a chat ID format (individual or group)
5
+ */
6
+ export declare function validateChatId(chatId: string): ValidationResult;
7
+ /**
8
+ * Validates a contact ID format
9
+ */
10
+ export declare function validateContactId(contactId: string): ValidationResult;
11
+ /**
12
+ * Validates a group chat ID format
13
+ */
14
+ export declare function validateGroupChatId(chatId: string): ValidationResult;
15
+ /**
16
+ * Validates a phone number format
17
+ */
18
+ export declare function validatePhoneNumber(number: string): ValidationResult;
19
+ /**
20
+ * Validates a channel ID format
21
+ */
22
+ export declare function validateChannelId(channelId: string): ValidationResult;
23
+ /**
24
+ * Validates a session ID format
25
+ */
26
+ export declare function validateSessionId(sessionId: string): ValidationResult;
27
+ /**
28
+ * Parses content based on content type.
29
+ * Returns the appropriate content value (string for text, parsed JSON for others).
30
+ */
31
+ export declare function parseContent(contentType: ContentType, textContent: string, jsonContent: string): ParsedContent;
32
+ /**
33
+ * Parses a comma-separated list of participant IDs into an array.
34
+ * Validates each ID and returns cleaned array.
35
+ */
36
+ export declare function parseParticipantIds(ids: string): string[];
37
+ /**
38
+ * Parses a comma-separated list of mentions into an array.
39
+ */
40
+ export declare function parseMentions(mentions: string): string[];
41
+ /**
42
+ * Resolves the session ID from node parameter or credentials default.
43
+ * Throws an error if no session ID is available.
44
+ */
45
+ export declare function resolveSessionId(executeFn: IExecuteFunctions, itemIndex: number): Promise<string>;
46
+ /**
47
+ * Makes an HTTP request to the WWebJS API.
48
+ */
49
+ export declare function wpiRequest(this: IExecuteFunctions, method: IHttpRequestMethods, endpoint: string, body?: IDataObject, query?: IDataObject): Promise<IDataObject>;
50
+ /**
51
+ * Builds the endpoint path replacing {sessionId} with the actual value.
52
+ */
53
+ export declare function buildEndpoint(path: string, sessionId: string): string;
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateChatId = validateChatId;
4
+ exports.validateContactId = validateContactId;
5
+ exports.validateGroupChatId = validateGroupChatId;
6
+ exports.validatePhoneNumber = validatePhoneNumber;
7
+ exports.validateChannelId = validateChannelId;
8
+ exports.validateSessionId = validateSessionId;
9
+ exports.parseContent = parseContent;
10
+ exports.parseParticipantIds = parseParticipantIds;
11
+ exports.parseMentions = parseMentions;
12
+ exports.resolveSessionId = resolveSessionId;
13
+ exports.wpiRequest = wpiRequest;
14
+ exports.buildEndpoint = buildEndpoint;
15
+ const n8n_workflow_1 = require("n8n-workflow");
16
+ // ═══════════════════════════════════════════════════════════════════
17
+ // Validation Utilities
18
+ // ═══════════════════════════════════════════════════════════════════
19
+ /**
20
+ * Regular expressions for validating WhatsApp IDs
21
+ */
22
+ const CHAT_ID_REGEX = /^[0-9]+@[cg]\.us$/;
23
+ const CONTACT_ID_REGEX = /^[0-9]+@c\.us$/;
24
+ const GROUP_ID_REGEX = /^[0-9]+-[0-9]+@g\.us$/;
25
+ const PHONE_NUMBER_REGEX = /^[0-9]{7,15}$/;
26
+ const CHANNEL_ID_REGEX = /^[0-9]+@newsletter$/;
27
+ /**
28
+ * Validates a chat ID format (individual or group)
29
+ */
30
+ function validateChatId(chatId) {
31
+ if (!chatId || chatId.trim() === '') {
32
+ return { valid: false, error: 'Chat ID is required' };
33
+ }
34
+ const trimmed = chatId.trim();
35
+ // Allow both individual and group formats
36
+ if (!CHAT_ID_REGEX.test(trimmed) && !GROUP_ID_REGEX.test(trimmed)) {
37
+ return {
38
+ valid: false,
39
+ error: `Invalid chat ID format: "${trimmed}". Expected format: number@c.us (individual) or number-timestamp@g.us (group)`,
40
+ };
41
+ }
42
+ return { valid: true };
43
+ }
44
+ /**
45
+ * Validates a contact ID format
46
+ */
47
+ function validateContactId(contactId) {
48
+ if (!contactId || contactId.trim() === '') {
49
+ return { valid: false, error: 'Contact ID is required' };
50
+ }
51
+ const trimmed = contactId.trim();
52
+ if (!CONTACT_ID_REGEX.test(trimmed)) {
53
+ return {
54
+ valid: false,
55
+ error: `Invalid contact ID format: "${trimmed}". Expected format: number@c.us`,
56
+ };
57
+ }
58
+ return { valid: true };
59
+ }
60
+ /**
61
+ * Validates a group chat ID format
62
+ */
63
+ function validateGroupChatId(chatId) {
64
+ if (!chatId || chatId.trim() === '') {
65
+ return { valid: false, error: 'Group Chat ID is required' };
66
+ }
67
+ const trimmed = chatId.trim();
68
+ // Groups can be either number@g.us or number-timestamp@g.us
69
+ if (!trimmed.endsWith('@g.us')) {
70
+ return {
71
+ valid: false,
72
+ error: `Invalid group chat ID format: "${trimmed}". Expected format: number@g.us or number-timestamp@g.us`,
73
+ };
74
+ }
75
+ return { valid: true };
76
+ }
77
+ /**
78
+ * Validates a phone number format
79
+ */
80
+ function validatePhoneNumber(number) {
81
+ if (!number || number.trim() === '') {
82
+ return { valid: false, error: 'Phone number is required' };
83
+ }
84
+ const trimmed = number.trim().replace(/[^0-9]/g, '');
85
+ if (!PHONE_NUMBER_REGEX.test(trimmed)) {
86
+ return {
87
+ valid: false,
88
+ error: `Invalid phone number format: "${number}". Expected 7-15 digits without + or spaces.`,
89
+ };
90
+ }
91
+ return { valid: true };
92
+ }
93
+ /**
94
+ * Validates a channel ID format
95
+ */
96
+ function validateChannelId(channelId) {
97
+ if (!channelId || channelId.trim() === '') {
98
+ return { valid: false, error: 'Channel ID is required' };
99
+ }
100
+ const trimmed = channelId.trim();
101
+ if (!CHANNEL_ID_REGEX.test(trimmed)) {
102
+ return {
103
+ valid: false,
104
+ error: `Invalid channel ID format: "${trimmed}". Expected format: number@newsletter`,
105
+ };
106
+ }
107
+ return { valid: true };
108
+ }
109
+ /**
110
+ * Validates a session ID format
111
+ */
112
+ function validateSessionId(sessionId) {
113
+ if (!sessionId || sessionId.trim() === '') {
114
+ return { valid: false, error: 'Session ID is required' };
115
+ }
116
+ // Session IDs should be alphanumeric with dashes/underscores
117
+ const trimmed = sessionId.trim();
118
+ if (!/^[a-zA-Z0-9_-]+$/.test(trimmed)) {
119
+ return {
120
+ valid: false,
121
+ error: `Invalid session ID format: "${trimmed}". Use only alphanumeric characters, dashes, and underscores.`,
122
+ };
123
+ }
124
+ return { valid: true };
125
+ }
126
+ // ═══════════════════════════════════════════════════════════════════
127
+ // Content Parsing Utilities
128
+ // ═══════════════════════════════════════════════════════════════════
129
+ /**
130
+ * Parses content based on content type.
131
+ * Returns the appropriate content value (string for text, parsed JSON for others).
132
+ */
133
+ function parseContent(contentType, textContent, jsonContent) {
134
+ if (contentType === 'string') {
135
+ return {
136
+ contentType,
137
+ content: textContent,
138
+ };
139
+ }
140
+ try {
141
+ const parsed = JSON.parse(jsonContent);
142
+ return {
143
+ contentType,
144
+ content: parsed,
145
+ };
146
+ }
147
+ catch (error) {
148
+ throw new Error(`Invalid JSON content for type "${contentType}": ${error.message}`);
149
+ }
150
+ }
151
+ /**
152
+ * Parses a comma-separated list of participant IDs into an array.
153
+ * Validates each ID and returns cleaned array.
154
+ */
155
+ function parseParticipantIds(ids) {
156
+ if (!ids || ids.trim() === '') {
157
+ return [];
158
+ }
159
+ const parsed = ids
160
+ .split(',')
161
+ .map((id) => id.trim())
162
+ .filter((id) => id !== '');
163
+ // Validate each participant ID
164
+ for (const id of parsed) {
165
+ if (!CONTACT_ID_REGEX.test(id)) {
166
+ throw new Error(`Invalid participant ID: "${id}". Expected format: number@c.us`);
167
+ }
168
+ }
169
+ return parsed;
170
+ }
171
+ /**
172
+ * Parses a comma-separated list of mentions into an array.
173
+ */
174
+ function parseMentions(mentions) {
175
+ if (!mentions || mentions.trim() === '') {
176
+ return [];
177
+ }
178
+ return mentions
179
+ .split(',')
180
+ .map((m) => m.trim())
181
+ .filter((m) => m !== '');
182
+ }
183
+ // ═══════════════════════════════════════════════════════════════════
184
+ // Session Resolution
185
+ // ═══════════════════════════════════════════════════════════════════
186
+ /**
187
+ * Resolves the session ID from node parameter or credentials default.
188
+ * Throws an error if no session ID is available.
189
+ */
190
+ async function resolveSessionId(executeFn, itemIndex) {
191
+ // Try to get from node parameter
192
+ let sessionId = '';
193
+ try {
194
+ sessionId = executeFn.getNodeParameter('sessionId', itemIndex, '');
195
+ }
196
+ catch {
197
+ // Parameter might not exist for some operations
198
+ }
199
+ // Fallback to credentials default
200
+ if (!sessionId) {
201
+ const credentials = await executeFn.getCredentials('wWebJsApi');
202
+ sessionId = credentials.defaultSessionId || '';
203
+ }
204
+ // Validate
205
+ if (!sessionId) {
206
+ throw new Error('Session ID is required. Set it in the node or as the default in your credentials.');
207
+ }
208
+ const validation = validateSessionId(sessionId);
209
+ if (!validation.valid) {
210
+ throw new Error(validation.error);
211
+ }
212
+ return sessionId;
213
+ }
214
+ // ═══════════════════════════════════════════════════════════════════
215
+ // HTTP Request Helper
216
+ // ═══════════════════════════════════════════════════════════════════
217
+ /**
218
+ * Makes an HTTP request to the WWebJS API.
219
+ */
220
+ async function wpiRequest(method, endpoint, body = {}, query = {}) {
221
+ const credentials = await this.getCredentials('wWebJsApi');
222
+ const baseUrl = credentials.baseUrl.replace(/\/$/, '');
223
+ const options = {
224
+ method,
225
+ uri: `${baseUrl}${endpoint}`,
226
+ headers: {
227
+ 'Content-Type': 'application/json',
228
+ },
229
+ json: true,
230
+ qs: query,
231
+ };
232
+ if (credentials.apiKey) {
233
+ options.headers['x-api-key'] = credentials.apiKey;
234
+ }
235
+ if (Object.keys(body).length > 0 && method !== 'GET') {
236
+ options.body = body;
237
+ }
238
+ try {
239
+ return (await this.helpers.request(options));
240
+ }
241
+ catch (error) {
242
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
243
+ message: `WWebJS API request failed: ${error.message}`,
244
+ });
245
+ }
246
+ }
247
+ /**
248
+ * Builds the endpoint path replacing {sessionId} with the actual value.
249
+ */
250
+ function buildEndpoint(path, sessionId) {
251
+ return path.replace('{sessionId}', sessionId);
252
+ }
253
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../nodes/WWebJsApi/transport.ts"],"names":[],"mappings":";;AA0BA,wCAgBC;AAKD,8CAeC;AAKD,kDAgBC;AAKD,kDAeC;AAKD,8CAeC;AAKD,8CAeC;AAUD,oCAuBC;AAMD,kDAoBC;AAKD,sCASC;AAUD,4CA+BC;AASD,gCAmCC;AAKD,sCAEC;AA7SD,+CAA4C;AAG5C,sEAAsE;AACtE,uBAAuB;AACvB,sEAAsE;AAEtE;;GAEG;AACH,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAC1C,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAC/C,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3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,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QACtD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,IAAI,CAAC;QACJ,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAgB,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,2BAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,KAAmB,EAAE;YAC3D,OAAO,EAAE,8BAA+B,KAAe,CAAC,OAAO,EAAE;SACjE,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,IAAY,EAAE,SAAiB;IAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Type definitions for WWebJS API Node
3
+ */
4
+ import type { IDataObject } from 'n8n-workflow';
5
+ export type ContentType = 'string' | 'MessageMedia' | 'MessageMediaFromURL' | 'Location' | 'Contact' | 'Poll';
6
+ export interface ParsedContent {
7
+ contentType: ContentType;
8
+ content: string | IDataObject;
9
+ }
10
+ export interface ValidationResult {
11
+ valid: boolean;
12
+ error?: string;
13
+ }
14
+ export interface WWebJsApiResponse extends IDataObject {
15
+ success?: boolean;
16
+ message?: string;
17
+ data?: IDataObject | IDataObject[];
18
+ }
19
+ export interface SessionInfo extends IDataObject {
20
+ id: string;
21
+ status: 'STARTING' | 'SCAN_QR_CODE' | 'WORKING' | 'FAILED';
22
+ }
23
+ export interface ChatInfo extends IDataObject {
24
+ id: {
25
+ server: string;
26
+ user: string;
27
+ _serialized: string;
28
+ };
29
+ name: string;
30
+ isGroup: boolean;
31
+ isReadOnly: boolean;
32
+ unreadCount: number;
33
+ timestamp: number;
34
+ archived: boolean;
35
+ pinned: boolean;
36
+ isMuted: boolean;
37
+ }
38
+ export interface MessageInfo extends IDataObject {
39
+ id: {
40
+ fromMe: boolean;
41
+ remote: string;
42
+ id: string;
43
+ _serialized: string;
44
+ };
45
+ body: string;
46
+ type: string;
47
+ timestamp: number;
48
+ from: string;
49
+ to: string;
50
+ author?: string;
51
+ isForwarded: boolean;
52
+ forwardingScore: number;
53
+ isStatus: boolean;
54
+ isStarred: boolean;
55
+ broadcast: boolean;
56
+ fromMe: boolean;
57
+ hasMedia: boolean;
58
+ hasQuotedMsg: boolean;
59
+ mentionedIds: string[];
60
+ }
61
+ export interface ContactInfo extends IDataObject {
62
+ id: {
63
+ server: string;
64
+ user: string;
65
+ _serialized: string;
66
+ };
67
+ number: string;
68
+ name: string;
69
+ shortName: string;
70
+ pushname: string;
71
+ isUser: boolean;
72
+ isGroup: boolean;
73
+ isWAContact: boolean;
74
+ isMyContact: boolean;
75
+ isBlocked: boolean;
76
+ }
77
+ export interface GroupChatInfo extends ChatInfo {
78
+ groupMetadata: {
79
+ id: {
80
+ server: string;
81
+ user: string;
82
+ _serialized: string;
83
+ };
84
+ owner: string;
85
+ subject: string;
86
+ subjectTime: number;
87
+ creation: number;
88
+ desc?: string;
89
+ descId?: string;
90
+ descTime?: number;
91
+ restrict: boolean;
92
+ announce: boolean;
93
+ participants: GroupParticipant[];
94
+ };
95
+ }
96
+ export interface GroupParticipant extends IDataObject {
97
+ id: {
98
+ server: string;
99
+ user: string;
100
+ _serialized: string;
101
+ };
102
+ isAdmin: boolean;
103
+ isSuperAdmin: boolean;
104
+ }
105
+ export type WebhookEventType = 'authenticated' | 'auth_failure' | 'message' | 'message_create' | 'message_ack' | 'message_revoke_everyone' | 'message_revoke_me' | 'qr' | 'ready' | 'disconnected' | 'change_state' | 'call' | 'group_join' | 'group_leave' | 'group_update' | 'chat_archived' | 'chat_removed' | 'loading_screen' | 'media_uploaded' | 'contact_changed';
106
+ export interface WebhookPayload extends IDataObject {
107
+ dataType: WebhookEventType;
108
+ sessionId: string;
109
+ data: IDataObject;
110
+ }
111
+ export interface MessageWebhookData extends IDataObject {
112
+ from: string;
113
+ to: string;
114
+ body: string;
115
+ fromMe: boolean;
116
+ chatId?: string;
117
+ hasMedia: boolean;
118
+ type: string;
119
+ }
120
+ export interface TriggerFilters extends IDataObject {
121
+ sessionId?: string;
122
+ chatIdContains?: string;
123
+ bodyContains?: string;
124
+ fromMe?: boolean;
125
+ excludeFromMe?: boolean;
126
+ groupsOnly?: boolean;
127
+ individualsOnly?: boolean;
128
+ }
129
+ export interface SendMessageOptions extends IDataObject {
130
+ quotedMessageId?: string;
131
+ mentions?: string[];
132
+ sendSeen?: boolean;
133
+ }
134
+ export interface SendMessageBody extends IDataObject {
135
+ chatId: string;
136
+ contentType: ContentType;
137
+ content: string | IDataObject;
138
+ options?: SendMessageOptions;
139
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Type definitions for WWebJS API Node
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../nodes/WWebJsApi/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
@@ -0,0 +1,10 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64">
2
+ <defs>
3
+ <linearGradient id="wg" x1="0%" y1="100%" x2="0%" y2="0%">
4
+ <stop offset="0%" style="stop-color:#20B038"/>
5
+ <stop offset="100%" style="stop-color:#60D66A"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <circle cx="32" cy="32" r="30" fill="url(#wg)"/>
9
+ <path d="M32 14c-9.94 0-18 7.5-18 16.76a16.27 16.27 0 0 0 2.5 8.64L14 48l9.06-2.38A18.44 18.44 0 0 0 32 47.52c9.94 0 18-7.5 18-16.76S41.94 14 32 14zm0 30.52a15.4 15.4 0 0 1-7.88-2.16l-.56-.34-5.84 1.54 1.56-5.7-.38-.6A13.52 13.52 0 0 1 17 30.76C17 23.3 23.72 17.2 32 17.2s15 6.1 15 13.56-6.72 13.76-15 13.76zm8.22-10.3c-.44-.22-2.66-1.32-3.08-1.46s-.72-.22-.98.22-.14.17-1.32 1.62c-.24.3-.48.34-.92.12a11.56 11.56 0 0 1-3.4-2.1 12.74 12.74 0 0 1-2.36-2.94c-.24-.44 0-.66.2-.88.18-.2.44-.5.66-.76s.26-.44.42-.72a.78.78 0 0 0-.04-.76c-.12-.22-1-2.38-1.36-3.26-.36-.86-.72-.74-.98-.76h-.84a1.62 1.62 0 0 0-1.18.56 4.96 4.96 0 0 0-1.54 3.68c0 2.18 1.58 4.28 1.8 4.58s3.1 4.74 7.52 6.64c1.06.46 1.88.72 2.52.94.98.32 2.04.28 2.8.16.86-.12 2.66-1.08 3.04-2.14s.38-1.96.26-2.14-.42-.32-.86-.54z" fill="#fff"/>
10
+ </svg>
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "n8n-nodes-wwebjs-api",
3
+ "version": "1.0.0",
4
+ "description": "n8n community node for WWebJS REST API — WhatsApp Web automation via whatsapp-web.js",
5
+ "keywords": [
6
+ "n8n-community-node-package",
7
+ "n8n",
8
+ "whatsapp",
9
+ "wwebjs",
10
+ "whatsapp-web",
11
+ "whatsapp-api",
12
+ "messaging"
13
+ ],
14
+ "license": "Apache-2.0",
15
+ "author": {
16
+ "name": "Victor García Pastor",
17
+ "url": "https://github.com/vgpastor"
18
+ },
19
+ "homepage": "https://github.com/vgpastor/n8n-nodes-wwebjs-api",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/vgpastor/n8n-nodes-wwebjs-api.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/vgpastor/n8n-nodes-wwebjs-api/issues"
26
+ },
27
+ "main": "index.js",
28
+ "scripts": {
29
+ "build": "tsc && gulp build:icons",
30
+ "dev": "tsc --watch",
31
+ "format": "prettier nodes credentials --write",
32
+ "lint": "eslint nodes credentials --ext .ts",
33
+ "test": "vitest run",
34
+ "test:watch": "vitest",
35
+ "prepublishOnly": "npm run build"
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "n8n": {
41
+ "n8nNodesApiVersion": 1,
42
+ "credentials": [
43
+ "dist/credentials/WWebJsApiCredentials.js"
44
+ ],
45
+ "nodes": [
46
+ "dist/nodes/WWebJsApi/WWebJsApi.node.js",
47
+ "dist/nodes/WWebJsApi/WWebJsApiTrigger.node.js"
48
+ ]
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.19.7",
52
+ "eslint": "^9.39.2",
53
+ "gulp": "^5.0.1",
54
+ "n8n-workflow": "^2.6.0",
55
+ "prettier": "^3.8.1",
56
+ "typescript": "~5.9.3",
57
+ "vitest": "^4.0.18"
58
+ },
59
+ "peerDependencies": {
60
+ "n8n-workflow": ">=2.0.0"
61
+ },
62
+ "engines": {
63
+ "node": ">=22.0.0"
64
+ }
65
+ }