n8n-nodes-hamkar 3.3.2 → 3.3.4

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.
@@ -24,17 +24,25 @@ class HamkarBulkSms {
24
24
  ],
25
25
  properties: [
26
26
  {
27
- displayName: 'Phones (List)',
28
- name: 'phones',
27
+ displayName: 'Phone Number Field',
28
+ name: 'phoneFieldName',
29
29
  type: 'string',
30
+ default: 'phone_number',
31
+ description: 'Field name containing phone number in input data',
30
32
  required: true,
31
- default: '',
32
- description: 'List of phone numbers (comma separated or from previous node)',
33
- typeOptions: {
34
- multipleValues: true,
35
- multipleValueButtonText: 'Add Phone Number',
36
- },
37
33
  },
34
+ // {
35
+ // displayName: 'Phones (Manual List - Optional)',
36
+ // name: 'phones',
37
+ // type: 'string',
38
+ // required: false,
39
+ // default: '',
40
+ // description: 'Optional: Manual comma separated list (overrides input data)',
41
+ // typeOptions: {
42
+ // multipleValues: true,
43
+ // multipleValueButtonText: 'Add Phone Number',
44
+ // },
45
+ // },
38
46
  {
39
47
  displayName: 'Text (Common Message)',
40
48
  name: 'text',
@@ -48,42 +56,67 @@ class HamkarBulkSms {
48
56
  };
49
57
  }
50
58
  async execute() {
59
+ var _a;
51
60
  const items = this.getInputData();
52
61
  const returnData = [];
53
- for (let i = 0; i < items.length; i++) {
54
- let phonesParam = this.getNodeParameter('phones', i);
55
- let phonesList = [];
56
- if (typeof phonesParam === 'string') {
57
- if (phonesParam.includes(',')) {
58
- phonesList = phonesParam.split(',').map(p => p.trim());
62
+ const phoneFieldName = this.getNodeParameter('phoneFieldName', 0);
63
+ // const manualPhonesParam = this.getNodeParameter('phones', 0) as string | string[];
64
+ const commonText = this.getNodeParameter('text', 0);
65
+ let phonesList = [];
66
+ // if (manualPhonesParam && manualPhonesParam !== '') {
67
+ // if (typeof manualPhonesParam === 'string') {
68
+ // if (manualPhonesParam.includes(',')) {
69
+ // phonesList = manualPhonesParam.split(',').map(p => p.trim());
70
+ // } else {
71
+ // phonesList = [manualPhonesParam];
72
+ // }
73
+ // } else if (Array.isArray(manualPhonesParam)) {
74
+ // phonesList = manualPhonesParam;
75
+ // }
76
+ // }
77
+ // else
78
+ if (items && items.length > 0) {
79
+ for (const item of items) {
80
+ const jsonData = item.json;
81
+ let phoneNumber = '';
82
+ if (phoneFieldName.includes('.')) {
83
+ const fields = phoneFieldName.split('.');
84
+ let value = jsonData;
85
+ for (const field of fields) {
86
+ value = value === null || value === void 0 ? void 0 : value[field];
87
+ if (value === undefined)
88
+ break;
89
+ }
90
+ phoneNumber = (value === null || value === void 0 ? void 0 : value.toString()) || '';
59
91
  }
60
92
  else {
61
- phonesList = [phonesParam];
93
+ phoneNumber = ((_a = jsonData[phoneFieldName]) === null || _a === void 0 ? void 0 : _a.toString()) || '';
94
+ }
95
+ if (phoneNumber && phoneNumber !== '') {
96
+ phonesList.push(phoneNumber);
62
97
  }
63
98
  }
64
- else if (Array.isArray(phonesParam)) {
65
- phonesList = phonesParam;
66
- }
67
- const commonText = this.getNodeParameter('text', i);
68
- const bulkData = {
69
- text: commonText,
70
- phones: phonesList,
71
- total_count: phonesList.length
72
- };
73
- const response = await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
74
- method: 'POST',
75
- url: 'https://stg-api.hamkar.co/api/send-sms/bulk/',
76
- body: bulkData,
77
- json: true,
78
- });
79
- returnData.push({
80
- success: true,
81
- response: response,
82
- sent_to: phonesList,
83
- message: commonText,
84
- count: phonesList.length
85
- });
86
99
  }
100
+ // phonesList = [...new Set(phonesList)];
101
+ if (phonesList.length === 0) {
102
+ throw new Error('No phone numbers found in input data!');
103
+ }
104
+ const bulkData = {
105
+ text: commonText,
106
+ phones: phonesList,
107
+ total_count: phonesList.length
108
+ };
109
+ await this.helpers.httpRequestWithAuthentication.call(this, 'hamkarApi', {
110
+ method: 'POST',
111
+ url: 'https://stg-api.hamkar.co/api/send-bulk-sms/',
112
+ body: bulkData,
113
+ json: true,
114
+ });
115
+ returnData.push({
116
+ phones: phonesList,
117
+ message: commonText,
118
+ count: phonesList.length
119
+ });
87
120
  return [this.helpers.returnJsonArray(returnData)];
88
121
  }
89
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-hamkar",
3
- "version": "3.3.2",
3
+ "version": "3.3.4",
4
4
  "description": "n8n node for Hamkar.co API - Contact and Record management operations",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",