@growsalesai/n8n-nodes-ycloud 0.2.3 → 2.6.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.
- package/dist/nodes/YCloud/YCloud.node.js +1 -0
- package/dist/nodes/YCloud/YCloud.node.js.map +1 -1
- package/dist/nodes/YCloud/YCloudAutoResponder.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudAutoResponder.node.js +236 -0
- package/dist/nodes/YCloud/YCloudAutoResponder.node.js.map +1 -0
- package/dist/nodes/YCloud/YCloudContactOnboarding.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudContactOnboarding.node.js +195 -0
- package/dist/nodes/YCloud/YCloudContactOnboarding.node.js.map +1 -0
- package/dist/nodes/YCloud/YCloudContactUpsert.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudContactUpsert.node.js +120 -0
- package/dist/nodes/YCloud/YCloudContactUpsert.node.js.map +1 -0
- package/dist/nodes/YCloud/YCloudInboundRouter.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudInboundRouter.node.js +100 -0
- package/dist/nodes/YCloud/YCloudInboundRouter.node.js.map +1 -0
- package/dist/nodes/YCloud/YCloudMessageStatusRouter.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudMessageStatusRouter.node.js +51 -0
- package/dist/nodes/YCloud/YCloudMessageStatusRouter.node.js.map +1 -0
- package/dist/nodes/YCloud/YCloudOptHandler.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudOptHandler.node.js +136 -0
- package/dist/nodes/YCloud/YCloudOptHandler.node.js.map +1 -0
- package/dist/nodes/YCloud/YCloudTagCampaign.node.d.ts +5 -0
- package/dist/nodes/YCloud/YCloudTagCampaign.node.js +178 -0
- package/dist/nodes/YCloud/YCloudTagCampaign.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudAutoResponder.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudAutoResponder.node.js +241 -0
- package/dist/nodes/YCloud/sequences/YCloudAutoResponder.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudContactOnboarding.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudContactOnboarding.node.js +200 -0
- package/dist/nodes/YCloud/sequences/YCloudContactOnboarding.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudContactUpsert.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudContactUpsert.node.js +125 -0
- package/dist/nodes/YCloud/sequences/YCloudContactUpsert.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudInboundRouter.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudInboundRouter.node.js +105 -0
- package/dist/nodes/YCloud/sequences/YCloudInboundRouter.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudMessageStatusRouter.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudMessageStatusRouter.node.js +56 -0
- package/dist/nodes/YCloud/sequences/YCloudMessageStatusRouter.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudOptHandler.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudOptHandler.node.js +141 -0
- package/dist/nodes/YCloud/sequences/YCloudOptHandler.node.js.map +1 -0
- package/dist/nodes/YCloud/sequences/YCloudTagCampaign.node.d.ts +5 -0
- package/dist/nodes/YCloud/sequences/YCloudTagCampaign.node.js +183 -0
- package/dist/nodes/YCloud/sequences/YCloudTagCampaign.node.js.map +1 -0
- package/package.json +9 -2
|
@@ -49,6 +49,7 @@ class YCloud {
|
|
|
49
49
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
50
50
|
description: 'Use YCloud to send WhatsApp messages, SMS, emails, manage templates, contacts, and more',
|
|
51
51
|
defaults: { name: 'YCloud' },
|
|
52
|
+
usableAsTool: true,
|
|
52
53
|
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
53
54
|
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
54
55
|
credentials: [{ name: 'yCloudApi', required: true }],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"YCloud.node.js","sourceRoot":"","sources":["../../../nodes/YCloud/YCloud.node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAuE;AACvE,iDAA4C;AAC5C,uCAAoC;AACpC,mDAAqC;AAErC,MAAa,MAAM;IAAnB;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,uBAAuB;YACpC,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,8DAA8D;YACxE,WAAW,EAAE,yFAAyF;YACtG,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC5B,MAAM,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YAClC,OAAO,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YACnC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACpD,UAAU,EAAV,yBAAU;SACX,CAAC;QAEF,YAAO,GAAG,iBAAO,CAAC;IAuDpB,CAAC;IArDC,KAAK,CAAC,OAAO;QACX,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAClC,MAAM,UAAU,GAAyB,EAAE,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,CAAW,CAAC;QAChE,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAW,CAAC;QAElE,MAAM,WAAW,GAA0H;YACzI,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,WAAW,EAAE,OAAO,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,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;gBAEpE,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;oBAChC,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;wBAChC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;oBAC3D,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBACnE,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;oBAC1B,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;oBACxF,SAAS;gBACX,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;CACF;AAxED,wBAwEC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class YCloudAutoResponder implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.YCloudAutoResponder = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
6
|
+
class YCloudAutoResponder {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.description = {
|
|
9
|
+
displayName: 'YCloud Auto Responder',
|
|
10
|
+
name: 'yCloudAutoResponder',
|
|
11
|
+
icon: 'file:logo-ycloud.png',
|
|
12
|
+
group: ['output'],
|
|
13
|
+
version: 1,
|
|
14
|
+
subtitle: 'Matched / No Match',
|
|
15
|
+
description: 'Retrieves the sender\'s contact profile, checks their tags and custom attributes against a set of rules, and sends the first matching WhatsApp template. Routes to "Matched" or "No Match".',
|
|
16
|
+
defaults: { name: 'YCloud Auto Responder' },
|
|
17
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
18
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main, n8n_workflow_1.NodeConnectionTypes.Main],
|
|
19
|
+
outputNames: ['Matched', 'No Match'],
|
|
20
|
+
credentials: [{ name: 'yCloudApi', required: true }],
|
|
21
|
+
properties: [
|
|
22
|
+
{
|
|
23
|
+
displayName: 'Message Object Field',
|
|
24
|
+
name: 'messageField',
|
|
25
|
+
type: 'string',
|
|
26
|
+
default: 'whatsappInboundMessage',
|
|
27
|
+
description: 'Field in the input item containing the WhatsApp message object (from YCloud Trigger). The "from" field inside is used to look up the contact.',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
displayName: 'From Phone Number',
|
|
31
|
+
name: 'fromPhone',
|
|
32
|
+
type: 'string',
|
|
33
|
+
required: true,
|
|
34
|
+
default: '',
|
|
35
|
+
placeholder: '+16315551111',
|
|
36
|
+
description: 'Your WhatsApp Business phone number used to send the response',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
displayName: 'Response Rules',
|
|
40
|
+
name: 'rules',
|
|
41
|
+
type: 'fixedCollection',
|
|
42
|
+
typeOptions: { multipleValues: true, sortable: true },
|
|
43
|
+
default: { items: [] },
|
|
44
|
+
placeholder: 'Add Rule',
|
|
45
|
+
description: 'Rules are evaluated in order. The first matching rule determines the template sent.',
|
|
46
|
+
options: [
|
|
47
|
+
{
|
|
48
|
+
name: 'items',
|
|
49
|
+
displayName: 'Rule',
|
|
50
|
+
values: [
|
|
51
|
+
{
|
|
52
|
+
displayName: 'Condition Type',
|
|
53
|
+
name: 'conditionType',
|
|
54
|
+
type: 'options',
|
|
55
|
+
default: 'hasTag',
|
|
56
|
+
options: [
|
|
57
|
+
{ name: 'Contact Has Tag', value: 'hasTag' },
|
|
58
|
+
{ name: 'Contact Attribute Equals', value: 'attributeEquals' },
|
|
59
|
+
{ name: 'Match All (default/fallback)', value: 'always' },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
displayName: 'Tag',
|
|
64
|
+
name: 'tag',
|
|
65
|
+
type: 'string',
|
|
66
|
+
default: '',
|
|
67
|
+
displayOptions: { show: { conditionType: ['hasTag'] } },
|
|
68
|
+
description: 'Contact must have this tag to match',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
displayName: 'Attribute Key',
|
|
72
|
+
name: 'attributeKey',
|
|
73
|
+
type: 'string',
|
|
74
|
+
default: '',
|
|
75
|
+
displayOptions: { show: { conditionType: ['attributeEquals'] } },
|
|
76
|
+
description: 'Custom attribute key to check (e.g. "plan")',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Attribute Value',
|
|
80
|
+
name: 'attributeValue',
|
|
81
|
+
type: 'string',
|
|
82
|
+
default: '',
|
|
83
|
+
displayOptions: { show: { conditionType: ['attributeEquals'] } },
|
|
84
|
+
description: 'Expected value of the attribute (case-insensitive)',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
displayName: 'Template Name',
|
|
88
|
+
name: 'templateName',
|
|
89
|
+
type: 'string',
|
|
90
|
+
required: true,
|
|
91
|
+
default: '',
|
|
92
|
+
placeholder: 'premium_response',
|
|
93
|
+
description: 'Name of the WhatsApp template to send when this rule matches',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
displayName: 'Template Language',
|
|
97
|
+
name: 'templateLanguage',
|
|
98
|
+
type: 'string',
|
|
99
|
+
default: 'pt_BR',
|
|
100
|
+
description: 'Language code, e.g. pt_BR, en_US',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
displayName: 'Template Body Variables (JSON)',
|
|
104
|
+
name: 'templateVarsJSON',
|
|
105
|
+
type: 'string',
|
|
106
|
+
default: '[]',
|
|
107
|
+
description: 'JSON array of body variable values: ["Name", "Value"]',
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
displayName: 'Options',
|
|
115
|
+
name: 'options',
|
|
116
|
+
type: 'collection',
|
|
117
|
+
placeholder: 'Add Option',
|
|
118
|
+
default: {},
|
|
119
|
+
options: [
|
|
120
|
+
{
|
|
121
|
+
displayName: 'Filter Unsubscribed',
|
|
122
|
+
name: 'filterUnsubscribed',
|
|
123
|
+
type: 'boolean',
|
|
124
|
+
default: true,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
displayName: 'Reply to Inbound Message',
|
|
128
|
+
name: 'replyToMessage',
|
|
129
|
+
type: 'boolean',
|
|
130
|
+
default: false,
|
|
131
|
+
description: 'Whether to send the response as a reply to the inbound message (sets context.message_id)',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
async execute() {
|
|
139
|
+
const items = this.getInputData();
|
|
140
|
+
const matchedItems = [];
|
|
141
|
+
const noMatchItems = [];
|
|
142
|
+
for (let i = 0; i < items.length; i++) {
|
|
143
|
+
try {
|
|
144
|
+
const messageField = this.getNodeParameter('messageField', i);
|
|
145
|
+
const fromPhone = this.getNodeParameter('fromPhone', i);
|
|
146
|
+
const rulesData = this.getNodeParameter('rules', i);
|
|
147
|
+
const rules = rulesData.items || [];
|
|
148
|
+
const options = this.getNodeParameter('options', i);
|
|
149
|
+
const data = items[i].json;
|
|
150
|
+
const message = data[messageField] || {};
|
|
151
|
+
const senderPhone = message.from;
|
|
152
|
+
if (!senderPhone) {
|
|
153
|
+
noMatchItems.push({ json: { ...data, _reason: 'no_sender_phone' }, pairedItem: { item: i } });
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const contactResp = await GenericFunctions_1.ycloudApiRequest.call(this, 'GET', '/contact/contacts', {}, { phoneNumber: senderPhone });
|
|
157
|
+
const contact = (contactResp.items || []).find((c) => c.phoneNumber === senderPhone) || {};
|
|
158
|
+
const contactTags = contact.tags || [];
|
|
159
|
+
const contactAttrs = contact.customAttributes || [];
|
|
160
|
+
const attrMap = {};
|
|
161
|
+
for (const attr of contactAttrs) {
|
|
162
|
+
if (attr.key)
|
|
163
|
+
attrMap[attr.key] = (attr.value || '').toLowerCase();
|
|
164
|
+
}
|
|
165
|
+
let matchedRule = null;
|
|
166
|
+
for (const rule of rules) {
|
|
167
|
+
const type = rule.conditionType;
|
|
168
|
+
if (type === 'always') {
|
|
169
|
+
matchedRule = rule;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if (type === 'hasTag' && contactTags.includes(rule.tag)) {
|
|
173
|
+
matchedRule = rule;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
if (type === 'attributeEquals') {
|
|
177
|
+
const key = rule.attributeKey;
|
|
178
|
+
const expectedVal = (rule.attributeValue || '').toLowerCase();
|
|
179
|
+
if (attrMap[key] === expectedVal) {
|
|
180
|
+
matchedRule = rule;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!matchedRule) {
|
|
186
|
+
noMatchItems.push({ json: { ...data, contact, _reason: 'no_rule_matched' }, pairedItem: { item: i } });
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const templateVars = JSON.parse(matchedRule.templateVarsJSON || '[]');
|
|
190
|
+
const components = [];
|
|
191
|
+
if (templateVars.length > 0) {
|
|
192
|
+
components.push({
|
|
193
|
+
type: 'body',
|
|
194
|
+
parameters: templateVars.map((v) => ({ type: 'text', text: v })),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
const messageBody = {
|
|
198
|
+
from: fromPhone,
|
|
199
|
+
to: senderPhone,
|
|
200
|
+
type: 'template',
|
|
201
|
+
filterUnsubscribed: options.filterUnsubscribed !== false,
|
|
202
|
+
template: {
|
|
203
|
+
name: matchedRule.templateName,
|
|
204
|
+
language: { code: matchedRule.templateLanguage || 'pt_BR' },
|
|
205
|
+
...(components.length > 0 ? { components } : {}),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
if (options.replyToMessage && message.id) {
|
|
209
|
+
messageBody.context = { message_id: message.id };
|
|
210
|
+
}
|
|
211
|
+
const sendResult = await GenericFunctions_1.ycloudApiRequest.call(this, 'POST', '/whatsapp/messages', messageBody);
|
|
212
|
+
matchedItems.push({
|
|
213
|
+
json: {
|
|
214
|
+
message: sendResult,
|
|
215
|
+
contact,
|
|
216
|
+
_rule: matchedRule.conditionType,
|
|
217
|
+
_template: matchedRule.templateName,
|
|
218
|
+
_phone: senderPhone,
|
|
219
|
+
},
|
|
220
|
+
pairedItem: { item: i },
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
if (this.continueOnFail()) {
|
|
225
|
+
noMatchItems.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return [matchedItems, noMatchItems];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.YCloudAutoResponder = YCloudAutoResponder;
|
|
236
|
+
//# sourceMappingURL=YCloudAutoResponder.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"YCloudAutoResponder.node.js","sourceRoot":"","sources":["../../../nodes/YCloud/YCloudAutoResponder.node.ts"],"names":[],"mappings":";;;AACA,+CAAmD;AACnD,yDAAsD;AAEtD,MAAa,mBAAmB;IAAhC;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,uBAAuB;YACpC,IAAI,EAAE,qBAAqB;YAC3B,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,oBAAoB;YAC9B,WAAW,EAAE,6LAA6L;YAC1M,QAAQ,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE;YAC3C,MAAM,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YAClC,OAAO,EAAE,CAAC,kCAAmB,CAAC,IAAI,EAAE,kCAAmB,CAAC,IAAI,CAAC;YAC7D,WAAW,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC;YACpC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACpD,UAAU,EAAE;gBACV;oBACE,WAAW,EAAE,sBAAsB;oBACnC,IAAI,EAAE,cAAc;oBACpB,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,wBAAwB;oBACjC,WAAW,EAAE,+IAA+I;iBAC7J;gBACD;oBACE,WAAW,EAAE,mBAAmB;oBAChC,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE,EAAE;oBACX,WAAW,EAAE,cAAc;oBAC3B,WAAW,EAAE,+DAA+D;iBAC7E;gBACD;oBACE,WAAW,EAAE,gBAAgB;oBAC7B,IAAI,E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AAC;gBAEhG,YAAY,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE;wBACJ,OAAO,EAAE,UAAU;wBACnB,OAAO;wBACP,KAAK,EAAE,WAAW,CAAC,aAAa;wBAChC,SAAS,EAAE,WAAW,CAAC,YAAY;wBACnC,MAAM,EAAE,WAAW;qBACpB;oBACD,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;iBACxB,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;oBAC1B,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC5F,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACtC,CAAC;CACF;AAhPD,kDAgPC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class YCloudContactOnboarding implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.YCloudContactOnboarding = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
6
|
+
class YCloudContactOnboarding {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.description = {
|
|
9
|
+
displayName: 'YCloud Contact Onboarding',
|
|
10
|
+
name: 'yCloudContactOnboarding',
|
|
11
|
+
icon: 'file:logo-ycloud.png',
|
|
12
|
+
group: ['output'],
|
|
13
|
+
version: 1,
|
|
14
|
+
subtitle: 'Send welcome template + tag contact',
|
|
15
|
+
description: 'Sends a welcome WhatsApp template to a new contact and optionally adds an onboarding tag. Designed to follow a "YCloud Trigger" listening for contact.created events.',
|
|
16
|
+
defaults: { name: 'YCloud Contact Onboarding' },
|
|
17
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
18
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
19
|
+
outputNames: ['Success'],
|
|
20
|
+
credentials: [{ name: 'yCloudApi', required: true }],
|
|
21
|
+
properties: [
|
|
22
|
+
{
|
|
23
|
+
displayName: 'Contact Phone Field',
|
|
24
|
+
name: 'contactPhoneField',
|
|
25
|
+
type: 'string',
|
|
26
|
+
default: 'contact.phoneNumber',
|
|
27
|
+
description: 'Dot-path to the phone number in the input item, e.g. "contact.phoneNumber" for contact.created events or just "phoneNumber"',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
displayName: 'Contact ID Field',
|
|
31
|
+
name: 'contactIdField',
|
|
32
|
+
type: 'string',
|
|
33
|
+
default: 'contact.id',
|
|
34
|
+
description: 'Dot-path to the contact ID in the input item. Used to add the welcome tag.',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
displayName: 'From Phone Number',
|
|
38
|
+
name: 'fromPhone',
|
|
39
|
+
type: 'string',
|
|
40
|
+
required: true,
|
|
41
|
+
default: '',
|
|
42
|
+
placeholder: '+16315551111',
|
|
43
|
+
description: 'Your WhatsApp Business phone number registered in YCloud',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
displayName: 'Template Name',
|
|
47
|
+
name: 'templateName',
|
|
48
|
+
type: 'string',
|
|
49
|
+
required: true,
|
|
50
|
+
default: '',
|
|
51
|
+
placeholder: 'welcome_message',
|
|
52
|
+
description: 'Name of the approved WhatsApp template to send',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
displayName: 'Template Language',
|
|
56
|
+
name: 'templateLanguage',
|
|
57
|
+
type: 'string',
|
|
58
|
+
required: true,
|
|
59
|
+
default: 'pt_BR',
|
|
60
|
+
placeholder: 'pt_BR',
|
|
61
|
+
description: 'Language code of the template, e.g. pt_BR, en_US',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
displayName: 'Template Body Variables (JSON)',
|
|
65
|
+
name: 'templateVarsJSON',
|
|
66
|
+
type: 'string',
|
|
67
|
+
typeOptions: { rows: 3 },
|
|
68
|
+
default: '[]',
|
|
69
|
+
description: 'JSON array of string values for template body variables in order: ["John", "Premium"]. Supports expressions.',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
displayName: 'Welcome Tag',
|
|
73
|
+
name: 'welcomeTag',
|
|
74
|
+
type: 'string',
|
|
75
|
+
default: 'onboarded',
|
|
76
|
+
description: 'Tag added to the contact after the welcome message is sent. Leave empty to skip tagging.',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Options',
|
|
80
|
+
name: 'options',
|
|
81
|
+
type: 'collection',
|
|
82
|
+
placeholder: 'Add Option',
|
|
83
|
+
default: {},
|
|
84
|
+
options: [
|
|
85
|
+
{
|
|
86
|
+
displayName: 'Filter Unsubscribed',
|
|
87
|
+
name: 'filterUnsubscribed',
|
|
88
|
+
type: 'boolean',
|
|
89
|
+
default: true,
|
|
90
|
+
description: 'Skip sending if the contact has opted out of WhatsApp messages',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
displayName: 'Header Media URL or ID',
|
|
94
|
+
name: 'headerMedia',
|
|
95
|
+
type: 'string',
|
|
96
|
+
default: '',
|
|
97
|
+
description: 'URL or media ID for image/video/document header (if your template uses one)',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async execute() {
|
|
105
|
+
const items = this.getInputData();
|
|
106
|
+
const successItems = [];
|
|
107
|
+
for (let i = 0; i < items.length; i++) {
|
|
108
|
+
try {
|
|
109
|
+
const phoneField = this.getNodeParameter('contactPhoneField', i);
|
|
110
|
+
const idField = this.getNodeParameter('contactIdField', i);
|
|
111
|
+
const fromPhone = this.getNodeParameter('fromPhone', i);
|
|
112
|
+
const templateName = this.getNodeParameter('templateName', i);
|
|
113
|
+
const templateLanguage = this.getNodeParameter('templateLanguage', i);
|
|
114
|
+
const templateVarsRaw = this.getNodeParameter('templateVarsJSON', i);
|
|
115
|
+
const welcomeTag = this.getNodeParameter('welcomeTag', i);
|
|
116
|
+
const options = this.getNodeParameter('options', i);
|
|
117
|
+
const getField = (obj, path) => {
|
|
118
|
+
return path.split('.').reduce((acc, key) => {
|
|
119
|
+
if (acc && typeof acc === 'object')
|
|
120
|
+
return acc[key];
|
|
121
|
+
return undefined;
|
|
122
|
+
}, obj);
|
|
123
|
+
};
|
|
124
|
+
const toPhone = getField(items[i].json, phoneField);
|
|
125
|
+
const contactId = getField(items[i].json, idField);
|
|
126
|
+
if (!toPhone) {
|
|
127
|
+
throw new Error(`Phone field "${phoneField}" not found in input item`);
|
|
128
|
+
}
|
|
129
|
+
const templateVars = JSON.parse(templateVarsRaw || '[]');
|
|
130
|
+
const components = [];
|
|
131
|
+
if (options.headerMedia) {
|
|
132
|
+
const headerMedia = options.headerMedia;
|
|
133
|
+
const isUrl = headerMedia.startsWith('http');
|
|
134
|
+
components.push({
|
|
135
|
+
type: 'header',
|
|
136
|
+
parameters: [{ type: 'image', image: isUrl ? { link: headerMedia } : { id: headerMedia } }],
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (templateVars.length > 0) {
|
|
140
|
+
components.push({
|
|
141
|
+
type: 'body',
|
|
142
|
+
parameters: templateVars.map((v) => ({ type: 'text', text: v })),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const messageBody = {
|
|
146
|
+
from: fromPhone,
|
|
147
|
+
to: toPhone,
|
|
148
|
+
type: 'template',
|
|
149
|
+
template: {
|
|
150
|
+
name: templateName,
|
|
151
|
+
language: { code: templateLanguage },
|
|
152
|
+
...(components.length > 0 ? { components } : {}),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
if (options.filterUnsubscribed !== undefined) {
|
|
156
|
+
messageBody.filterUnsubscribed = options.filterUnsubscribed;
|
|
157
|
+
}
|
|
158
|
+
const messageResult = await GenericFunctions_1.ycloudApiRequest.call(this, 'POST', '/whatsapp/messages', messageBody);
|
|
159
|
+
let tagResult = {};
|
|
160
|
+
if (welcomeTag && contactId) {
|
|
161
|
+
const contact = await GenericFunctions_1.ycloudApiRequest.call(this, 'GET', `/contact/contacts/${contactId}`);
|
|
162
|
+
const existingTags = contact.tags || [];
|
|
163
|
+
if (!existingTags.includes(welcomeTag)) {
|
|
164
|
+
tagResult = await GenericFunctions_1.ycloudApiRequest.call(this, 'PATCH', `/contact/contacts/${contactId}`, {
|
|
165
|
+
tags: [...existingTags, welcomeTag],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
tagResult = contact;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
successItems.push({
|
|
173
|
+
json: {
|
|
174
|
+
message: messageResult,
|
|
175
|
+
contact: tagResult,
|
|
176
|
+
_phone: toPhone,
|
|
177
|
+
_welcomeTag: welcomeTag || null,
|
|
178
|
+
},
|
|
179
|
+
pairedItem: { item: i },
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (this.continueOnFail()) {
|
|
184
|
+
successItems.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return [successItems];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.YCloudContactOnboarding = YCloudContactOnboarding;
|
|
195
|
+
//# sourceMappingURL=YCloudContactOnboarding.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"YCloudContactOnboarding.node.js","sourceRoot":"","sources":["../../../nodes/YCloud/YCloudContactOnboarding.node.ts"],"names":[],"mappings":";;;AACA,+CAAmD;AACnD,yDAAsD;AAEtD,MAAa,uBAAuB;IAApC;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,2BAA2B;YACxC,IAAI,EAAE,yBAAyB;YAC/B,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,qCAAqC;YAC/C,WAAW,EAAE,uKAAuK;YACpL,QAAQ,EAAE,EAAE,IAAI,EAAE,2BAA2B,EAAE;YAC/C,MAAM,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YAClC,OAAO,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YACnC,WAAW,EAAE,CAAC,SAAS,CAAC;YACxB,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACpD,UAAU,EAAE;gBACV;oBACE,WAAW,EAAE,qBAAqB;oBAClC,IAAI,EAAE,mBAAmB;oBACzB,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,qBAAqB;oBAC9B,WAAW,EAAE,6HAA6H;iBAC3I;gBACD;oBACE,WAAW,EAAE,kBAAkB;oBAC/B,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,YAAY;oBACrB,WAAW,EAAE,4EAA4E;iBAC1F;gBACD;oBACE,WAAW,EAAE,mBAAmB;oBAChC,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,IAAI;oBACd,OAAO,EAAE,EAAE;oBACX,WAAW,EAAE,cAAc;oBAC3B,WAAW,EAAE,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WAAW,EAAE,UAAU,IAAI,IAAI;qBAChC;oBACD,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;iBACxB,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;oBAC1B,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC5F,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;CACF;AAlMD,0DAkMC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class YCloudContactUpsert implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.YCloudContactUpsert = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
6
|
+
class YCloudContactUpsert {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.description = {
|
|
9
|
+
displayName: 'YCloud Contact Upsert',
|
|
10
|
+
name: 'yCloudContactUpsert',
|
|
11
|
+
icon: 'file:logo-ycloud.png',
|
|
12
|
+
group: ['output'],
|
|
13
|
+
version: 1,
|
|
14
|
+
subtitle: 'Found / Created',
|
|
15
|
+
description: 'Looks up a contact by phone number. Routes to "Found" if it exists (optionally updating it), or creates it and routes to "Created".',
|
|
16
|
+
defaults: { name: 'YCloud Contact Upsert' },
|
|
17
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
18
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main, n8n_workflow_1.NodeConnectionTypes.Main],
|
|
19
|
+
outputNames: ['Found', 'Created'],
|
|
20
|
+
credentials: [{ name: 'yCloudApi', required: true }],
|
|
21
|
+
properties: [
|
|
22
|
+
{
|
|
23
|
+
displayName: 'Phone Number',
|
|
24
|
+
name: 'phoneNumber',
|
|
25
|
+
type: 'string',
|
|
26
|
+
required: true,
|
|
27
|
+
default: '',
|
|
28
|
+
placeholder: '+16315551111',
|
|
29
|
+
description: 'Phone number in E.164 format. Supports expressions e.g. {{ $json.phone }}.',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
displayName: 'On Contact Found',
|
|
33
|
+
name: 'ifExists',
|
|
34
|
+
type: 'options',
|
|
35
|
+
default: 'doNothing',
|
|
36
|
+
options: [
|
|
37
|
+
{ name: 'Do Nothing — Return Existing Data', value: 'doNothing' },
|
|
38
|
+
{ name: 'Update Contact Fields', value: 'update' },
|
|
39
|
+
],
|
|
40
|
+
description: 'What to do when the contact already exists in YCloud',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
displayName: 'Contact Fields',
|
|
44
|
+
name: 'contactFields',
|
|
45
|
+
type: 'collection',
|
|
46
|
+
placeholder: 'Add Field',
|
|
47
|
+
default: {},
|
|
48
|
+
description: 'Fields to set on create. When "Update Contact Fields" is selected, also applied on update.',
|
|
49
|
+
options: [
|
|
50
|
+
{ displayName: 'Country Code', name: 'countryCode', type: 'string', default: '', description: 'ISO 3166-1 alpha-2 country code, e.g. US' },
|
|
51
|
+
{
|
|
52
|
+
displayName: 'Custom Attributes (JSON)',
|
|
53
|
+
name: 'customAttributes',
|
|
54
|
+
type: 'string',
|
|
55
|
+
typeOptions: { rows: 3 },
|
|
56
|
+
default: '',
|
|
57
|
+
description: 'JSON array of custom attributes: [{"key":"plan","value":"premium"}]',
|
|
58
|
+
},
|
|
59
|
+
{ displayName: 'Nickname', name: 'nickname', type: 'string', default: '' },
|
|
60
|
+
{ displayName: 'Owner Email', name: 'ownerEmail', type: 'string', default: '', placeholder: 'owner@example.com' },
|
|
61
|
+
{
|
|
62
|
+
displayName: 'Tags',
|
|
63
|
+
name: 'tags',
|
|
64
|
+
type: 'string',
|
|
65
|
+
default: '',
|
|
66
|
+
description: 'Comma-separated list of tags, e.g. lead,premium',
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async execute() {
|
|
74
|
+
const items = this.getInputData();
|
|
75
|
+
const foundItems = [];
|
|
76
|
+
const createdItems = [];
|
|
77
|
+
for (let i = 0; i < items.length; i++) {
|
|
78
|
+
try {
|
|
79
|
+
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
80
|
+
const ifExists = this.getNodeParameter('ifExists', i);
|
|
81
|
+
const fields = this.getNodeParameter('contactFields', i);
|
|
82
|
+
const body = {};
|
|
83
|
+
if (fields.nickname)
|
|
84
|
+
body.nickname = fields.nickname;
|
|
85
|
+
if (fields.countryCode)
|
|
86
|
+
body.countryCode = fields.countryCode;
|
|
87
|
+
if (fields.ownerEmail)
|
|
88
|
+
body.ownerEmail = fields.ownerEmail;
|
|
89
|
+
if (fields.tags)
|
|
90
|
+
body.tags = fields.tags.split(',').map((t) => t.trim()).filter(Boolean);
|
|
91
|
+
if (fields.customAttributes)
|
|
92
|
+
body.customAttributes = JSON.parse(fields.customAttributes);
|
|
93
|
+
const resp = await GenericFunctions_1.ycloudApiRequest.call(this, 'GET', '/contact/contacts', {}, { phoneNumber });
|
|
94
|
+
const existing = (resp.items || []).find((c) => c.phoneNumber === phoneNumber);
|
|
95
|
+
if (existing) {
|
|
96
|
+
let result = existing;
|
|
97
|
+
if (ifExists === 'update' && Object.keys(body).length > 0) {
|
|
98
|
+
result = await GenericFunctions_1.ycloudApiRequest.call(this, 'PATCH', `/contact/contacts/${existing.id}`, body);
|
|
99
|
+
}
|
|
100
|
+
foundItems.push({ json: result, pairedItem: { item: i } });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const created = await GenericFunctions_1.ycloudApiRequest.call(this, 'POST', '/contact/contacts', { phoneNumber, ...body });
|
|
104
|
+
createdItems.push({ json: created, pairedItem: { item: i } });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (this.continueOnFail()) {
|
|
109
|
+
foundItems.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return [foundItems, createdItems];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.YCloudContactUpsert = YCloudContactUpsert;
|
|
120
|
+
//# sourceMappingURL=YCloudContactUpsert.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"YCloudContactUpsert.node.js","sourceRoot":"","sources":["../../../nodes/YCloud/YCloudContactUpsert.node.ts"],"names":[],"mappings":";;;AACA,+CAAmD;AACnD,yDAAsD;AAEtD,MAAa,mBAAmB;IAAhC;QACE,gBAAW,GAAyB;YAClC,WAAW,EAAE,uBAAuB;YACpC,IAAI,EAAE,qBAAqB;YAC3B,IAAI,EAAE,sBAAsB;YAC5B,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,iBAAiB;YAC3B,WAAW,EAAE,qIAAqI;YAClJ,QAAQ,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE;YAC3C,MAAM,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YAClC,OAAO,EAAE,CAAC,kCAAmB,CAAC,IAAI,EAAE,kCAAmB,CAAC,IAAI,CAAC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Y,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;oBAC1B,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAG,KAAe,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC1F,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACpC,CAAC;CACF;AA9GD,kDA8GC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
|
|
2
|
+
export declare class YCloudInboundRouter implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
|
5
|
+
}
|