n8n-nodes-linq 0.1.12 → 0.1.14
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/Linq/Linq.node.js +35 -8
- package/package.json +1 -1
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Linq = void 0;
|
|
4
4
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
// Helper function to format phone numbers with proper country code
|
|
6
|
+
function formatPhoneNumber(phoneNumber) {
|
|
7
|
+
// Remove any whitespace and other formatting characters
|
|
8
|
+
let cleaned = phoneNumber.replace(/\s+/g, '').replace(/[\(\)\-\.]/g, '');
|
|
9
|
+
// If it already starts with +, return as is
|
|
10
|
+
if (cleaned.startsWith('+')) {
|
|
11
|
+
return cleaned;
|
|
12
|
+
}
|
|
13
|
+
// If it starts with 00, replace with +
|
|
14
|
+
if (cleaned.startsWith('00')) {
|
|
15
|
+
return '+' + cleaned.substring(2);
|
|
16
|
+
}
|
|
17
|
+
// If it's all digits and doesn't start with +, assume it needs a +
|
|
18
|
+
if (/^\d+$/.test(cleaned)) {
|
|
19
|
+
return '+' + cleaned;
|
|
20
|
+
}
|
|
21
|
+
// For other cases, just return the cleaned number
|
|
22
|
+
return cleaned;
|
|
23
|
+
}
|
|
5
24
|
class Linq {
|
|
6
25
|
constructor() {
|
|
7
26
|
this.description = {
|
|
@@ -450,7 +469,7 @@ class Linq {
|
|
|
450
469
|
if (perPage && perPage !== 25)
|
|
451
470
|
qs.per_page = perPage;
|
|
452
471
|
if (phoneNumber)
|
|
453
|
-
qs.phone_number = phoneNumber;
|
|
472
|
+
qs.phone_number = formatPhoneNumber(phoneNumber);
|
|
454
473
|
responseData = await this.helpers.request({
|
|
455
474
|
method: 'GET',
|
|
456
475
|
url: 'https://api.linqapp.com/api/partner/v2/chats',
|
|
@@ -478,8 +497,16 @@ class Linq {
|
|
|
478
497
|
const phoneNumbers = this.getNodeParameter('phoneNumbers', i, '');
|
|
479
498
|
const qs = {};
|
|
480
499
|
if (phoneNumbers) {
|
|
481
|
-
//
|
|
482
|
-
|
|
500
|
+
// Check if we have a single phone number or multiple
|
|
501
|
+
const phoneNumbersArray = phoneNumbers.split(',').map(p => formatPhoneNumber(p.trim()));
|
|
502
|
+
if (phoneNumbersArray.length === 1) {
|
|
503
|
+
// For single phone number, use 'phone' parameter
|
|
504
|
+
qs.phone = phoneNumbersArray[0];
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
// For multiple phone numbers, use 'phone_numbers[]' parameter
|
|
508
|
+
qs['phone_numbers[]'] = phoneNumbersArray;
|
|
509
|
+
}
|
|
483
510
|
}
|
|
484
511
|
responseData = await this.helpers.request({
|
|
485
512
|
method: 'GET',
|
|
@@ -499,14 +526,14 @@ class Linq {
|
|
|
499
526
|
const messageText = this.getNodeParameter('messageText', i);
|
|
500
527
|
const body = {
|
|
501
528
|
chat: {
|
|
502
|
-
phone_numbers: phoneNumbers.split(',').map(p => p.trim())
|
|
529
|
+
phone_numbers: phoneNumbers.split(',').map(p => formatPhoneNumber(p.trim()))
|
|
503
530
|
},
|
|
504
531
|
message: {
|
|
505
532
|
text: messageText
|
|
506
533
|
}
|
|
507
534
|
};
|
|
508
535
|
if (sendFrom) {
|
|
509
|
-
body.send_from = sendFrom;
|
|
536
|
+
body.send_from = formatPhoneNumber(sendFrom);
|
|
510
537
|
}
|
|
511
538
|
if (displayName) {
|
|
512
539
|
body.chat.display_name = displayName;
|
|
@@ -659,7 +686,7 @@ class Linq {
|
|
|
659
686
|
if (operation === 'checkIMessageAvailability') {
|
|
660
687
|
const phoneNumber = this.getNodeParameter('phoneNumber', i);
|
|
661
688
|
const body = {
|
|
662
|
-
phone_number: phoneNumber
|
|
689
|
+
phone_number: formatPhoneNumber(phoneNumber)
|
|
663
690
|
};
|
|
664
691
|
responseData = await this.helpers.request({
|
|
665
692
|
method: 'POST',
|
|
@@ -785,7 +812,7 @@ class Linq {
|
|
|
785
812
|
if (email)
|
|
786
813
|
body.contact.email = email;
|
|
787
814
|
if (phoneNumber)
|
|
788
|
-
body.contact.phone_number = phoneNumber;
|
|
815
|
+
body.contact.phone_number = formatPhoneNumber(phoneNumber);
|
|
789
816
|
if (company)
|
|
790
817
|
body.contact.company = company;
|
|
791
818
|
if (title)
|
|
@@ -835,7 +862,7 @@ class Linq {
|
|
|
835
862
|
if (email)
|
|
836
863
|
body.contact.email = email;
|
|
837
864
|
if (phoneNumber)
|
|
838
|
-
body.contact.phone_number = phoneNumber;
|
|
865
|
+
body.contact.phone_number = formatPhoneNumber(phoneNumber);
|
|
839
866
|
if (company)
|
|
840
867
|
body.contact.company = company;
|
|
841
868
|
if (title)
|