n8n-nodes-imessage 0.1.2
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/LICENSE +21 -0
- package/README.md +116 -0
- package/dist/credentials/PhotonIMessageApi.credentials.d.ts +9 -0
- package/dist/credentials/PhotonIMessageApi.credentials.js +47 -0
- package/dist/credentials/PhotonIMessageApi.credentials.js.map +1 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessage.node.d.ts +5 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessage.node.js +1168 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessage.node.js.map +1 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessageTrigger.node.d.ts +5 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessageTrigger.node.js +118 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessageTrigger.node.js.map +1 -0
- package/dist/nodes/PhotonIMessage/photon-imessage.svg +10 -0
- package/dist/package.json +65 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,1168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhotonIMessage = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
function generateTempGuid() {
|
|
6
|
+
const hex = '0123456789abcdef';
|
|
7
|
+
let result = 'temp_';
|
|
8
|
+
for (let i = 0; i < 32; i++) {
|
|
9
|
+
result += hex[Math.floor(Math.random() * 16)];
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
class PhotonIMessage {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.description = {
|
|
16
|
+
displayName: 'Photon iMessage',
|
|
17
|
+
name: 'photonIMessage',
|
|
18
|
+
icon: 'file:photon-imessage.svg',
|
|
19
|
+
group: ['output'],
|
|
20
|
+
version: 1,
|
|
21
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
22
|
+
description: 'Send, search, and manage iMessage conversations via the Photon server',
|
|
23
|
+
defaults: {
|
|
24
|
+
name: 'Photon iMessage',
|
|
25
|
+
},
|
|
26
|
+
inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
27
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
28
|
+
credentials: [
|
|
29
|
+
{
|
|
30
|
+
name: 'photonIMessageApi',
|
|
31
|
+
required: true,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
properties: [
|
|
35
|
+
{
|
|
36
|
+
displayName: 'Resource',
|
|
37
|
+
name: 'resource',
|
|
38
|
+
type: 'options',
|
|
39
|
+
noDataExpression: true,
|
|
40
|
+
options: [
|
|
41
|
+
{ name: 'Message', value: 'message' },
|
|
42
|
+
{ name: 'Chat', value: 'chat' },
|
|
43
|
+
{ name: 'Contact', value: 'contact' },
|
|
44
|
+
{ name: 'Poll', value: 'poll' },
|
|
45
|
+
{ name: 'Scheduled Message', value: 'scheduledMessage' },
|
|
46
|
+
{ name: 'Handle', value: 'handle' },
|
|
47
|
+
],
|
|
48
|
+
default: 'message',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
displayName: 'Operation',
|
|
52
|
+
name: 'operation',
|
|
53
|
+
type: 'options',
|
|
54
|
+
noDataExpression: true,
|
|
55
|
+
displayOptions: { show: { resource: ['message'] } },
|
|
56
|
+
options: [
|
|
57
|
+
{ name: 'Send Message', value: 'sendMessage', action: 'Send a message', description: 'Send a text message to a chat' },
|
|
58
|
+
{ name: 'Send Attachment', value: 'sendAttachment', action: 'Send an attachment', description: 'Send a file attachment to a chat' },
|
|
59
|
+
{ name: 'Unsend Message', value: 'unsendMessage', action: 'Unsend a message', description: 'Retract a sent message' },
|
|
60
|
+
{ name: 'Edit Message', value: 'editMessage', action: 'Edit a message', description: 'Edit the text of a sent message' },
|
|
61
|
+
{ name: 'React to Message', value: 'reactToMessage', action: 'React to a message', description: 'Send a tapback reaction to a message' },
|
|
62
|
+
{ name: 'Download Attachment', value: 'downloadAttachment', action: 'Download an attachment', description: 'Download a received file or media attachment' },
|
|
63
|
+
{ name: 'Search Messages', value: 'searchMessages', action: 'Search messages', description: 'Search messages by text content' },
|
|
64
|
+
{ name: 'Get Messages', value: 'getMessages', action: 'Get messages', description: 'Retrieve messages from a chat' },
|
|
65
|
+
],
|
|
66
|
+
default: 'sendMessage',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
displayName: 'Chat GUID',
|
|
70
|
+
name: 'chatGuid',
|
|
71
|
+
type: 'string',
|
|
72
|
+
required: true,
|
|
73
|
+
default: '',
|
|
74
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
75
|
+
description: 'The chat identifier (e.g. iMessage;-;+1234567890 or iMessage;+;chat123)',
|
|
76
|
+
displayOptions: { show: { resource: ['message'], operation: ['sendMessage'] } },
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Message Text',
|
|
80
|
+
name: 'message',
|
|
81
|
+
type: 'string',
|
|
82
|
+
typeOptions: { rows: 4 },
|
|
83
|
+
required: true,
|
|
84
|
+
default: '',
|
|
85
|
+
description: 'The text content of the message to send',
|
|
86
|
+
displayOptions: { show: { resource: ['message'], operation: ['sendMessage'] } },
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
displayName: 'Additional Fields',
|
|
90
|
+
name: 'additionalFields',
|
|
91
|
+
type: 'collection',
|
|
92
|
+
placeholder: 'Add Field',
|
|
93
|
+
default: {},
|
|
94
|
+
displayOptions: { show: { resource: ['message'], operation: ['sendMessage'] } },
|
|
95
|
+
options: [
|
|
96
|
+
{
|
|
97
|
+
displayName: 'Method',
|
|
98
|
+
name: 'method',
|
|
99
|
+
type: 'options',
|
|
100
|
+
options: [
|
|
101
|
+
{ name: 'AppleScript', value: 'apple-script' },
|
|
102
|
+
{ name: 'Private API', value: 'private-api' },
|
|
103
|
+
],
|
|
104
|
+
default: 'apple-script',
|
|
105
|
+
description: 'The method used to send the message',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
displayName: 'Subject',
|
|
109
|
+
name: 'subject',
|
|
110
|
+
type: 'string',
|
|
111
|
+
default: '',
|
|
112
|
+
description: 'Optional subject line for the message',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Effect ID',
|
|
116
|
+
name: 'effectId',
|
|
117
|
+
type: 'options',
|
|
118
|
+
options: [
|
|
119
|
+
{ name: 'None', value: '' },
|
|
120
|
+
{ name: 'Confetti', value: 'com.apple.messages.effect.CKConfettiEffect' },
|
|
121
|
+
{ name: 'Fireworks', value: 'com.apple.messages.effect.CKFireworksEffect' },
|
|
122
|
+
{ name: 'Balloons', value: 'com.apple.messages.effect.CKBalloonEffect' },
|
|
123
|
+
{ name: 'Hearts', value: 'com.apple.messages.effect.CKHeartEffect' },
|
|
124
|
+
{ name: 'Lasers', value: 'com.apple.messages.effect.CKHappyBirthdayEffect' },
|
|
125
|
+
{ name: 'Shooting Star', value: 'com.apple.messages.effect.CKShootingStarEffect' },
|
|
126
|
+
{ name: 'Sparkles', value: 'com.apple.messages.effect.CKSparklesEffect' },
|
|
127
|
+
{ name: 'Echo', value: 'com.apple.messages.effect.CKEchoEffect' },
|
|
128
|
+
{ name: 'Spotlight', value: 'com.apple.messages.effect.CKSpotlightEffect' },
|
|
129
|
+
{ name: 'Gentle', value: 'com.apple.MobileSMS.expressivesend.gentle' },
|
|
130
|
+
{ name: 'Loud', value: 'com.apple.MobileSMS.expressivesend.loud' },
|
|
131
|
+
{ name: 'Slam', value: 'com.apple.MobileSMS.expressivesend.impact' },
|
|
132
|
+
{ name: 'Invisible Ink', value: 'com.apple.MobileSMS.expressivesend.invisibleink' },
|
|
133
|
+
],
|
|
134
|
+
default: '',
|
|
135
|
+
description: 'iMessage screen effect to send with the message',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
displayName: 'Reply To Message GUID',
|
|
139
|
+
name: 'selectedMessageGuid',
|
|
140
|
+
type: 'string',
|
|
141
|
+
default: '',
|
|
142
|
+
description: 'GUID of a message to reply to inline',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
displayName: 'Chat GUID',
|
|
148
|
+
name: 'chatGuid',
|
|
149
|
+
type: 'string',
|
|
150
|
+
required: true,
|
|
151
|
+
default: '',
|
|
152
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
153
|
+
description: 'The chat identifier',
|
|
154
|
+
displayOptions: { show: { resource: ['message'], operation: ['sendAttachment'] } },
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
displayName: 'File Path',
|
|
158
|
+
name: 'filePath',
|
|
159
|
+
type: 'string',
|
|
160
|
+
required: true,
|
|
161
|
+
default: '',
|
|
162
|
+
placeholder: '/Users/you/Desktop/photo.jpg',
|
|
163
|
+
description: 'Absolute file path on the Photon server Mac',
|
|
164
|
+
displayOptions: { show: { resource: ['message'], operation: ['sendAttachment'] } },
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
displayName: 'Additional Fields',
|
|
168
|
+
name: 'attachmentAdditionalFields',
|
|
169
|
+
type: 'collection',
|
|
170
|
+
placeholder: 'Add Field',
|
|
171
|
+
default: {},
|
|
172
|
+
displayOptions: { show: { resource: ['message'], operation: ['sendAttachment'] } },
|
|
173
|
+
options: [
|
|
174
|
+
{
|
|
175
|
+
displayName: 'File Name',
|
|
176
|
+
name: 'fileName',
|
|
177
|
+
type: 'string',
|
|
178
|
+
default: '',
|
|
179
|
+
description: 'Override the file name sent with the attachment',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
displayName: 'Is Audio Message',
|
|
183
|
+
name: 'isAudioMessage',
|
|
184
|
+
type: 'boolean',
|
|
185
|
+
default: false,
|
|
186
|
+
description: 'Whether to send as a voice message',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
displayName: 'Message GUID',
|
|
192
|
+
name: 'messageGuid',
|
|
193
|
+
type: 'string',
|
|
194
|
+
required: true,
|
|
195
|
+
default: '',
|
|
196
|
+
description: 'GUID of the message to unsend',
|
|
197
|
+
displayOptions: { show: { resource: ['message'], operation: ['unsendMessage'] } },
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
displayName: 'Part Index',
|
|
201
|
+
name: 'unsendPartIndex',
|
|
202
|
+
type: 'number',
|
|
203
|
+
default: 0,
|
|
204
|
+
description: 'Index of the message part to unsend (0 for the first part)',
|
|
205
|
+
displayOptions: { show: { resource: ['message'], operation: ['unsendMessage'] } },
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
displayName: 'Message GUID',
|
|
209
|
+
name: 'messageGuid',
|
|
210
|
+
type: 'string',
|
|
211
|
+
required: true,
|
|
212
|
+
default: '',
|
|
213
|
+
description: 'GUID of the message to edit',
|
|
214
|
+
displayOptions: { show: { resource: ['message'], operation: ['editMessage'] } },
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
displayName: 'New Text',
|
|
218
|
+
name: 'editedMessage',
|
|
219
|
+
type: 'string',
|
|
220
|
+
typeOptions: { rows: 4 },
|
|
221
|
+
required: true,
|
|
222
|
+
default: '',
|
|
223
|
+
description: 'The replacement text for the message',
|
|
224
|
+
displayOptions: { show: { resource: ['message'], operation: ['editMessage'] } },
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
displayName: 'Part Index',
|
|
228
|
+
name: 'editPartIndex',
|
|
229
|
+
type: 'number',
|
|
230
|
+
default: 0,
|
|
231
|
+
description: 'Index of the message part to edit (0 for the first part)',
|
|
232
|
+
displayOptions: { show: { resource: ['message'], operation: ['editMessage'] } },
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
displayName: 'Attachment GUID',
|
|
236
|
+
name: 'attachmentGuid',
|
|
237
|
+
type: 'string',
|
|
238
|
+
required: true,
|
|
239
|
+
default: '',
|
|
240
|
+
description: 'GUID of the attachment to download',
|
|
241
|
+
displayOptions: { show: { resource: ['message'], operation: ['downloadAttachment'] } },
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
displayName: 'Additional Fields',
|
|
245
|
+
name: 'downloadAdditionalFields',
|
|
246
|
+
type: 'collection',
|
|
247
|
+
placeholder: 'Add Field',
|
|
248
|
+
default: {},
|
|
249
|
+
displayOptions: { show: { resource: ['message'], operation: ['downloadAttachment'] } },
|
|
250
|
+
options: [
|
|
251
|
+
{
|
|
252
|
+
displayName: 'Width',
|
|
253
|
+
name: 'width',
|
|
254
|
+
type: 'number',
|
|
255
|
+
default: 0,
|
|
256
|
+
description: 'Desired image width in pixels (0 for original)',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
displayName: 'Height',
|
|
260
|
+
name: 'height',
|
|
261
|
+
type: 'number',
|
|
262
|
+
default: 0,
|
|
263
|
+
description: 'Desired image height in pixels (0 for original)',
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
displayName: 'Quality',
|
|
267
|
+
name: 'quality',
|
|
268
|
+
type: 'number',
|
|
269
|
+
typeOptions: { minValue: 1, maxValue: 100 },
|
|
270
|
+
default: 80,
|
|
271
|
+
description: 'Image quality (1-100)',
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
displayName: 'Chat GUID',
|
|
277
|
+
name: 'chatGuid',
|
|
278
|
+
type: 'string',
|
|
279
|
+
required: true,
|
|
280
|
+
default: '',
|
|
281
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
282
|
+
description: 'The chat identifier',
|
|
283
|
+
displayOptions: { show: { resource: ['message'], operation: ['reactToMessage'] } },
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
displayName: 'Message GUID',
|
|
287
|
+
name: 'messageGuid',
|
|
288
|
+
type: 'string',
|
|
289
|
+
required: true,
|
|
290
|
+
default: '',
|
|
291
|
+
description: 'GUID of the message to react to',
|
|
292
|
+
displayOptions: { show: { resource: ['message'], operation: ['reactToMessage'] } },
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
displayName: 'Reaction',
|
|
296
|
+
name: 'reaction',
|
|
297
|
+
type: 'options',
|
|
298
|
+
required: true,
|
|
299
|
+
options: [
|
|
300
|
+
{ name: 'Love', value: 'love' },
|
|
301
|
+
{ name: 'Like', value: 'like' },
|
|
302
|
+
{ name: 'Dislike', value: 'dislike' },
|
|
303
|
+
{ name: 'Laugh', value: 'laugh' },
|
|
304
|
+
{ name: 'Emphasize', value: 'emphasize' },
|
|
305
|
+
{ name: 'Question', value: 'question' },
|
|
306
|
+
],
|
|
307
|
+
default: 'love',
|
|
308
|
+
description: 'The tapback reaction to send',
|
|
309
|
+
displayOptions: { show: { resource: ['message'], operation: ['reactToMessage'] } },
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
displayName: 'Part Index',
|
|
313
|
+
name: 'partIndex',
|
|
314
|
+
type: 'number',
|
|
315
|
+
default: 0,
|
|
316
|
+
description: 'Index of the message part to react to (0 for the first part)',
|
|
317
|
+
displayOptions: { show: { resource: ['message'], operation: ['reactToMessage'] } },
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
displayName: 'Query',
|
|
321
|
+
name: 'query',
|
|
322
|
+
type: 'string',
|
|
323
|
+
required: true,
|
|
324
|
+
default: '',
|
|
325
|
+
description: 'Text to search for in messages',
|
|
326
|
+
displayOptions: { show: { resource: ['message'], operation: ['searchMessages'] } },
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
displayName: 'Additional Fields',
|
|
330
|
+
name: 'searchAdditionalFields',
|
|
331
|
+
type: 'collection',
|
|
332
|
+
placeholder: 'Add Field',
|
|
333
|
+
default: {},
|
|
334
|
+
displayOptions: { show: { resource: ['message'], operation: ['searchMessages'] } },
|
|
335
|
+
options: [
|
|
336
|
+
{
|
|
337
|
+
displayName: 'Chat GUID',
|
|
338
|
+
name: 'chatGuid',
|
|
339
|
+
type: 'string',
|
|
340
|
+
default: '',
|
|
341
|
+
description: 'Limit search to a specific chat',
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
displayName: 'Limit',
|
|
345
|
+
name: 'limit',
|
|
346
|
+
type: 'number',
|
|
347
|
+
typeOptions: { minValue: 1 },
|
|
348
|
+
default: 20,
|
|
349
|
+
description: 'Max number of results to return',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
displayName: 'Sort',
|
|
353
|
+
name: 'sort',
|
|
354
|
+
type: 'options',
|
|
355
|
+
options: [
|
|
356
|
+
{ name: 'Newest First', value: 'DESC' },
|
|
357
|
+
{ name: 'Oldest First', value: 'ASC' },
|
|
358
|
+
],
|
|
359
|
+
default: 'DESC',
|
|
360
|
+
description: 'Sort order of results',
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
displayName: 'Chat GUID',
|
|
366
|
+
name: 'chatGuid',
|
|
367
|
+
type: 'string',
|
|
368
|
+
required: true,
|
|
369
|
+
default: '',
|
|
370
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
371
|
+
description: 'The chat identifier to retrieve messages from',
|
|
372
|
+
displayOptions: { show: { resource: ['message'], operation: ['getMessages'] } },
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
displayName: 'Additional Fields',
|
|
376
|
+
name: 'getMessagesAdditionalFields',
|
|
377
|
+
type: 'collection',
|
|
378
|
+
placeholder: 'Add Field',
|
|
379
|
+
default: {},
|
|
380
|
+
displayOptions: { show: { resource: ['message'], operation: ['getMessages'] } },
|
|
381
|
+
options: [
|
|
382
|
+
{
|
|
383
|
+
displayName: 'Limit',
|
|
384
|
+
name: 'limit',
|
|
385
|
+
type: 'number',
|
|
386
|
+
typeOptions: { minValue: 1 },
|
|
387
|
+
default: 20,
|
|
388
|
+
description: 'Max number of messages to return',
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
displayName: 'After',
|
|
392
|
+
name: 'after',
|
|
393
|
+
type: 'dateTime',
|
|
394
|
+
default: '',
|
|
395
|
+
description: 'Only return messages after this date',
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
displayName: 'Before',
|
|
399
|
+
name: 'before',
|
|
400
|
+
type: 'dateTime',
|
|
401
|
+
default: '',
|
|
402
|
+
description: 'Only return messages before this date',
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
displayName: 'Sort',
|
|
406
|
+
name: 'sort',
|
|
407
|
+
type: 'options',
|
|
408
|
+
options: [
|
|
409
|
+
{ name: 'Newest First', value: 'DESC' },
|
|
410
|
+
{ name: 'Oldest First', value: 'ASC' },
|
|
411
|
+
],
|
|
412
|
+
default: 'DESC',
|
|
413
|
+
description: 'Sort order of results',
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
displayName: 'Operation',
|
|
419
|
+
name: 'operation',
|
|
420
|
+
type: 'options',
|
|
421
|
+
noDataExpression: true,
|
|
422
|
+
displayOptions: { show: { resource: ['chat'] } },
|
|
423
|
+
options: [
|
|
424
|
+
{ name: 'List Chats', value: 'listChats', action: 'List chats', description: 'Retrieve a list of conversations' },
|
|
425
|
+
{ name: 'Create Chat', value: 'createChat', action: 'Create a chat', description: 'Start a new conversation' },
|
|
426
|
+
{ name: 'Mark Chat Read', value: 'markChatRead', action: 'Mark a chat as read', description: 'Mark all messages in a chat as read' },
|
|
427
|
+
{ name: 'Start Typing', value: 'startTyping', action: 'Start typing indicator', description: 'Show the typing indicator in a chat' },
|
|
428
|
+
{ name: 'Stop Typing', value: 'stopTyping', action: 'Stop typing indicator', description: 'Hide the typing indicator in a chat' },
|
|
429
|
+
],
|
|
430
|
+
default: 'listChats',
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
displayName: 'Additional Fields',
|
|
434
|
+
name: 'listChatsAdditionalFields',
|
|
435
|
+
type: 'collection',
|
|
436
|
+
placeholder: 'Add Field',
|
|
437
|
+
default: {},
|
|
438
|
+
displayOptions: { show: { resource: ['chat'], operation: ['listChats'] } },
|
|
439
|
+
options: [
|
|
440
|
+
{
|
|
441
|
+
displayName: 'Limit',
|
|
442
|
+
name: 'limit',
|
|
443
|
+
type: 'number',
|
|
444
|
+
typeOptions: { minValue: 1 },
|
|
445
|
+
default: 20,
|
|
446
|
+
description: 'Max number of chats to return',
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
displayName: 'Include Last Message',
|
|
450
|
+
name: 'withLastMessage',
|
|
451
|
+
type: 'boolean',
|
|
452
|
+
default: true,
|
|
453
|
+
description: 'Whether to include the last message in each chat',
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
displayName: 'Phone Numbers',
|
|
459
|
+
name: 'phoneNumbers',
|
|
460
|
+
type: 'string',
|
|
461
|
+
required: true,
|
|
462
|
+
default: '',
|
|
463
|
+
placeholder: '+1234567890,+0987654321',
|
|
464
|
+
description: 'Comma-separated phone numbers or email addresses for the chat participants',
|
|
465
|
+
displayOptions: { show: { resource: ['chat'], operation: ['createChat'] } },
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
displayName: 'Additional Fields',
|
|
469
|
+
name: 'createChatAdditionalFields',
|
|
470
|
+
type: 'collection',
|
|
471
|
+
placeholder: 'Add Field',
|
|
472
|
+
default: {},
|
|
473
|
+
displayOptions: { show: { resource: ['chat'], operation: ['createChat'] } },
|
|
474
|
+
options: [
|
|
475
|
+
{
|
|
476
|
+
displayName: 'Initial Message',
|
|
477
|
+
name: 'message',
|
|
478
|
+
type: 'string',
|
|
479
|
+
default: '',
|
|
480
|
+
description: 'An optional first message to send when creating the chat',
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
displayName: 'Service',
|
|
484
|
+
name: 'service',
|
|
485
|
+
type: 'options',
|
|
486
|
+
options: [
|
|
487
|
+
{ name: 'iMessage', value: 'iMessage' },
|
|
488
|
+
{ name: 'SMS', value: 'SMS' },
|
|
489
|
+
],
|
|
490
|
+
default: 'iMessage',
|
|
491
|
+
description: 'The messaging service to use',
|
|
492
|
+
},
|
|
493
|
+
],
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
displayName: 'Chat GUID',
|
|
497
|
+
name: 'chatGuid',
|
|
498
|
+
type: 'string',
|
|
499
|
+
required: true,
|
|
500
|
+
default: '',
|
|
501
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
502
|
+
description: 'The chat identifier to mark as read',
|
|
503
|
+
displayOptions: { show: { resource: ['chat'], operation: ['markChatRead'] } },
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
displayName: 'Chat GUID',
|
|
507
|
+
name: 'chatGuid',
|
|
508
|
+
type: 'string',
|
|
509
|
+
required: true,
|
|
510
|
+
default: '',
|
|
511
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
512
|
+
description: 'The chat identifier to show typing in',
|
|
513
|
+
displayOptions: { show: { resource: ['chat'], operation: ['startTyping', 'stopTyping'] } },
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
displayName: 'Operation',
|
|
517
|
+
name: 'operation',
|
|
518
|
+
type: 'options',
|
|
519
|
+
noDataExpression: true,
|
|
520
|
+
displayOptions: { show: { resource: ['scheduledMessage'] } },
|
|
521
|
+
options: [
|
|
522
|
+
{ name: 'Create Scheduled Message', value: 'createScheduledMessage', action: 'Create a scheduled message', description: 'Schedule a message to be sent later' },
|
|
523
|
+
{ name: 'List Scheduled Messages', value: 'listScheduledMessages', action: 'List scheduled messages', description: 'Get all scheduled messages' },
|
|
524
|
+
{ name: 'Delete Scheduled Message', value: 'deleteScheduledMessage', action: 'Delete a scheduled message', description: 'Remove a scheduled message' },
|
|
525
|
+
],
|
|
526
|
+
default: 'createScheduledMessage',
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
displayName: 'Chat GUID',
|
|
530
|
+
name: 'chatGuid',
|
|
531
|
+
type: 'string',
|
|
532
|
+
required: true,
|
|
533
|
+
default: '',
|
|
534
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
535
|
+
description: 'The chat identifier',
|
|
536
|
+
displayOptions: { show: { resource: ['scheduledMessage'], operation: ['createScheduledMessage'] } },
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
displayName: 'Message',
|
|
540
|
+
name: 'message',
|
|
541
|
+
type: 'string',
|
|
542
|
+
typeOptions: { rows: 4 },
|
|
543
|
+
required: true,
|
|
544
|
+
default: '',
|
|
545
|
+
description: 'The text content of the scheduled message',
|
|
546
|
+
displayOptions: { show: { resource: ['scheduledMessage'], operation: ['createScheduledMessage'] } },
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
displayName: 'Send At',
|
|
550
|
+
name: 'sendAt',
|
|
551
|
+
type: 'dateTime',
|
|
552
|
+
required: true,
|
|
553
|
+
default: '',
|
|
554
|
+
description: 'When to send the message',
|
|
555
|
+
displayOptions: { show: { resource: ['scheduledMessage'], operation: ['createScheduledMessage'] } },
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
displayName: 'Schedule Type',
|
|
559
|
+
name: 'scheduleType',
|
|
560
|
+
type: 'options',
|
|
561
|
+
options: [
|
|
562
|
+
{ name: 'Once', value: 'once' },
|
|
563
|
+
{ name: 'Hourly', value: 'hourly' },
|
|
564
|
+
{ name: 'Daily', value: 'daily' },
|
|
565
|
+
{ name: 'Weekly', value: 'weekly' },
|
|
566
|
+
{ name: 'Monthly', value: 'monthly' },
|
|
567
|
+
{ name: 'Yearly', value: 'yearly' },
|
|
568
|
+
],
|
|
569
|
+
default: 'once',
|
|
570
|
+
description: 'How often to send the message',
|
|
571
|
+
displayOptions: { show: { resource: ['scheduledMessage'], operation: ['createScheduledMessage'] } },
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
displayName: 'Scheduled Message ID',
|
|
575
|
+
name: 'scheduledMessageId',
|
|
576
|
+
type: 'string',
|
|
577
|
+
required: true,
|
|
578
|
+
default: '',
|
|
579
|
+
description: 'The ID of the scheduled message to delete',
|
|
580
|
+
displayOptions: { show: { resource: ['scheduledMessage'], operation: ['deleteScheduledMessage'] } },
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
displayName: 'Operation',
|
|
584
|
+
name: 'operation',
|
|
585
|
+
type: 'options',
|
|
586
|
+
noDataExpression: true,
|
|
587
|
+
displayOptions: { show: { resource: ['poll'] } },
|
|
588
|
+
options: [
|
|
589
|
+
{ name: 'Create Poll', value: 'createPoll', action: 'Create a poll', description: 'Create an interactive poll in a chat' },
|
|
590
|
+
{ name: 'Vote', value: 'vote', action: 'Vote on a poll', description: 'Vote on a poll option' },
|
|
591
|
+
{ name: 'Unvote', value: 'unvote', action: 'Remove vote from a poll', description: 'Remove your vote from a poll option' },
|
|
592
|
+
{ name: 'Add Option', value: 'addOption', action: 'Add a poll option', description: 'Add a new option to an existing poll' },
|
|
593
|
+
],
|
|
594
|
+
default: 'createPoll',
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
displayName: 'Chat GUID',
|
|
598
|
+
name: 'chatGuid',
|
|
599
|
+
type: 'string',
|
|
600
|
+
required: true,
|
|
601
|
+
default: '',
|
|
602
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
603
|
+
description: 'The chat identifier to create the poll in',
|
|
604
|
+
displayOptions: { show: { resource: ['poll'], operation: ['createPoll'] } },
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
displayName: 'Options',
|
|
608
|
+
name: 'pollOptions',
|
|
609
|
+
type: 'string',
|
|
610
|
+
required: true,
|
|
611
|
+
default: '',
|
|
612
|
+
placeholder: 'Option A, Option B, Option C',
|
|
613
|
+
description: 'Comma-separated list of poll options',
|
|
614
|
+
displayOptions: { show: { resource: ['poll'], operation: ['createPoll'] } },
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
displayName: 'Title',
|
|
618
|
+
name: 'pollTitle',
|
|
619
|
+
type: 'string',
|
|
620
|
+
default: '',
|
|
621
|
+
description: 'Optional title for the poll',
|
|
622
|
+
displayOptions: { show: { resource: ['poll'], operation: ['createPoll'] } },
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
displayName: 'Chat GUID',
|
|
626
|
+
name: 'chatGuid',
|
|
627
|
+
type: 'string',
|
|
628
|
+
required: true,
|
|
629
|
+
default: '',
|
|
630
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
631
|
+
description: 'The chat identifier containing the poll',
|
|
632
|
+
displayOptions: { show: { resource: ['poll'], operation: ['vote', 'unvote'] } },
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
displayName: 'Poll Message GUID',
|
|
636
|
+
name: 'pollMessageGuid',
|
|
637
|
+
type: 'string',
|
|
638
|
+
required: true,
|
|
639
|
+
default: '',
|
|
640
|
+
description: 'GUID of the poll message',
|
|
641
|
+
displayOptions: { show: { resource: ['poll'], operation: ['vote', 'unvote'] } },
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
displayName: 'Option Identifier',
|
|
645
|
+
name: 'optionIdentifier',
|
|
646
|
+
type: 'string',
|
|
647
|
+
required: true,
|
|
648
|
+
default: '',
|
|
649
|
+
description: 'UUID of the poll option to vote on or unvote from',
|
|
650
|
+
displayOptions: { show: { resource: ['poll'], operation: ['vote', 'unvote'] } },
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
displayName: 'Chat GUID',
|
|
654
|
+
name: 'chatGuid',
|
|
655
|
+
type: 'string',
|
|
656
|
+
required: true,
|
|
657
|
+
default: '',
|
|
658
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
659
|
+
description: 'The chat identifier containing the poll',
|
|
660
|
+
displayOptions: { show: { resource: ['poll'], operation: ['addOption'] } },
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
displayName: 'Poll Message GUID',
|
|
664
|
+
name: 'pollMessageGuid',
|
|
665
|
+
type: 'string',
|
|
666
|
+
required: true,
|
|
667
|
+
default: '',
|
|
668
|
+
description: 'GUID of the poll message to add the option to',
|
|
669
|
+
displayOptions: { show: { resource: ['poll'], operation: ['addOption'] } },
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
displayName: 'Option Text',
|
|
673
|
+
name: 'optionText',
|
|
674
|
+
type: 'string',
|
|
675
|
+
required: true,
|
|
676
|
+
default: '',
|
|
677
|
+
description: 'Text for the new poll option',
|
|
678
|
+
displayOptions: { show: { resource: ['poll'], operation: ['addOption'] } },
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
displayName: 'Operation',
|
|
682
|
+
name: 'operation',
|
|
683
|
+
type: 'options',
|
|
684
|
+
noDataExpression: true,
|
|
685
|
+
displayOptions: { show: { resource: ['contact'] } },
|
|
686
|
+
options: [
|
|
687
|
+
{ name: 'Share Contact Card', value: 'shareContactCard', action: 'Share your contact card', description: 'Share your Name and Photo contact card in a chat' },
|
|
688
|
+
],
|
|
689
|
+
default: 'shareContactCard',
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
displayName: 'Chat GUID',
|
|
693
|
+
name: 'chatGuid',
|
|
694
|
+
type: 'string',
|
|
695
|
+
required: true,
|
|
696
|
+
default: '',
|
|
697
|
+
placeholder: 'iMessage;-;+1234567890',
|
|
698
|
+
description: 'The chat to share your contact card in',
|
|
699
|
+
displayOptions: { show: { resource: ['contact'], operation: ['shareContactCard'] } },
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
displayName: 'Operation',
|
|
703
|
+
name: 'operation',
|
|
704
|
+
type: 'options',
|
|
705
|
+
noDataExpression: true,
|
|
706
|
+
displayOptions: { show: { resource: ['handle'] } },
|
|
707
|
+
options: [
|
|
708
|
+
{ name: 'Check iMessage Availability', value: 'checkAvailability', action: 'Check i message availability', description: 'Check if a phone number or email supports iMessage' },
|
|
709
|
+
],
|
|
710
|
+
default: 'checkAvailability',
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
displayName: 'Phone or Email',
|
|
714
|
+
name: 'address',
|
|
715
|
+
type: 'string',
|
|
716
|
+
required: true,
|
|
717
|
+
default: '',
|
|
718
|
+
placeholder: '+1234567890',
|
|
719
|
+
description: 'The phone number or email address to check',
|
|
720
|
+
displayOptions: { show: { resource: ['handle'], operation: ['checkAvailability'] } },
|
|
721
|
+
},
|
|
722
|
+
],
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
async execute() {
|
|
726
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
|
|
727
|
+
const items = this.getInputData();
|
|
728
|
+
const returnData = [];
|
|
729
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
730
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
731
|
+
const credentials = await this.getCredentials('photonIMessageApi');
|
|
732
|
+
const baseUrl = credentials.serverUrl.replace(/\/+$/, '');
|
|
733
|
+
for (let i = 0; i < items.length; i++) {
|
|
734
|
+
try {
|
|
735
|
+
let responseData;
|
|
736
|
+
if (resource === 'message') {
|
|
737
|
+
if (operation === 'sendMessage') {
|
|
738
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
739
|
+
const message = this.getNodeParameter('message', i);
|
|
740
|
+
const additionalFields = this.getNodeParameter('additionalFields', i);
|
|
741
|
+
const body = {
|
|
742
|
+
chatGuid,
|
|
743
|
+
message,
|
|
744
|
+
tempGuid: generateTempGuid(),
|
|
745
|
+
method: additionalFields.method || 'apple-script',
|
|
746
|
+
};
|
|
747
|
+
if (additionalFields.subject)
|
|
748
|
+
body.subject = additionalFields.subject;
|
|
749
|
+
if (additionalFields.effectId)
|
|
750
|
+
body.effectId = additionalFields.effectId;
|
|
751
|
+
if (additionalFields.selectedMessageGuid)
|
|
752
|
+
body.selectedMessageGuid = additionalFields.selectedMessageGuid;
|
|
753
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
754
|
+
method: 'POST',
|
|
755
|
+
url: `${baseUrl}/api/v1/message/text`,
|
|
756
|
+
body,
|
|
757
|
+
json: true,
|
|
758
|
+
});
|
|
759
|
+
responseData = (_a = response.data) !== null && _a !== void 0 ? _a : response;
|
|
760
|
+
}
|
|
761
|
+
else if (operation === 'sendAttachment') {
|
|
762
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
763
|
+
const filePath = this.getNodeParameter('filePath', i);
|
|
764
|
+
const additionalFields = this.getNodeParameter('attachmentAdditionalFields', i);
|
|
765
|
+
const body = {
|
|
766
|
+
chatGuid,
|
|
767
|
+
filePath,
|
|
768
|
+
};
|
|
769
|
+
if (additionalFields.fileName)
|
|
770
|
+
body.name = additionalFields.fileName;
|
|
771
|
+
if (additionalFields.isAudioMessage)
|
|
772
|
+
body.isAudioMessage = additionalFields.isAudioMessage;
|
|
773
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
774
|
+
method: 'POST',
|
|
775
|
+
url: `${baseUrl}/api/v1/message/attachment`,
|
|
776
|
+
body,
|
|
777
|
+
json: true,
|
|
778
|
+
});
|
|
779
|
+
responseData = (_b = response.data) !== null && _b !== void 0 ? _b : response;
|
|
780
|
+
}
|
|
781
|
+
else if (operation === 'unsendMessage') {
|
|
782
|
+
const messageGuid = this.getNodeParameter('messageGuid', i);
|
|
783
|
+
const partIndex = this.getNodeParameter('unsendPartIndex', i, 0);
|
|
784
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
785
|
+
method: 'POST',
|
|
786
|
+
url: `${baseUrl}/api/v1/message/${encodeURIComponent(messageGuid)}/unsend`,
|
|
787
|
+
body: { partIndex },
|
|
788
|
+
json: true,
|
|
789
|
+
});
|
|
790
|
+
responseData = (_c = response.data) !== null && _c !== void 0 ? _c : response;
|
|
791
|
+
}
|
|
792
|
+
else if (operation === 'editMessage') {
|
|
793
|
+
const messageGuid = this.getNodeParameter('messageGuid', i);
|
|
794
|
+
const editedMessage = this.getNodeParameter('editedMessage', i);
|
|
795
|
+
const partIndex = this.getNodeParameter('editPartIndex', i, 0);
|
|
796
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
797
|
+
method: 'POST',
|
|
798
|
+
url: `${baseUrl}/api/v1/message/${encodeURIComponent(messageGuid)}/edit`,
|
|
799
|
+
body: {
|
|
800
|
+
editedMessage,
|
|
801
|
+
backwardsCompatibilityMessage: editedMessage,
|
|
802
|
+
partIndex,
|
|
803
|
+
},
|
|
804
|
+
json: true,
|
|
805
|
+
});
|
|
806
|
+
responseData = (_d = response.data) !== null && _d !== void 0 ? _d : response;
|
|
807
|
+
}
|
|
808
|
+
else if (operation === 'downloadAttachment') {
|
|
809
|
+
const attachmentGuid = this.getNodeParameter('attachmentGuid', i);
|
|
810
|
+
const additionalFields = this.getNodeParameter('downloadAdditionalFields', i);
|
|
811
|
+
const qs = {};
|
|
812
|
+
if (additionalFields.width)
|
|
813
|
+
qs.width = additionalFields.width;
|
|
814
|
+
if (additionalFields.height)
|
|
815
|
+
qs.height = additionalFields.height;
|
|
816
|
+
if (additionalFields.quality)
|
|
817
|
+
qs.quality = additionalFields.quality;
|
|
818
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
819
|
+
method: 'GET',
|
|
820
|
+
url: `${baseUrl}/api/v1/attachment/${encodeURIComponent(attachmentGuid)}/download`,
|
|
821
|
+
qs,
|
|
822
|
+
json: true,
|
|
823
|
+
encoding: 'arraybuffer',
|
|
824
|
+
});
|
|
825
|
+
responseData = (_e = response.data) !== null && _e !== void 0 ? _e : response;
|
|
826
|
+
}
|
|
827
|
+
else if (operation === 'reactToMessage') {
|
|
828
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
829
|
+
const messageGuid = this.getNodeParameter('messageGuid', i);
|
|
830
|
+
const reaction = this.getNodeParameter('reaction', i);
|
|
831
|
+
const partIndex = this.getNodeParameter('partIndex', i, 0);
|
|
832
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
833
|
+
method: 'POST',
|
|
834
|
+
url: `${baseUrl}/api/v1/message/react`,
|
|
835
|
+
body: {
|
|
836
|
+
chatGuid,
|
|
837
|
+
selectedMessageGuid: messageGuid,
|
|
838
|
+
reaction,
|
|
839
|
+
partIndex,
|
|
840
|
+
},
|
|
841
|
+
json: true,
|
|
842
|
+
});
|
|
843
|
+
responseData = (_f = response.data) !== null && _f !== void 0 ? _f : response;
|
|
844
|
+
}
|
|
845
|
+
else if (operation === 'searchMessages') {
|
|
846
|
+
const query = this.getNodeParameter('query', i);
|
|
847
|
+
const additionalFields = this.getNodeParameter('searchAdditionalFields', i);
|
|
848
|
+
const body = {
|
|
849
|
+
where: [
|
|
850
|
+
{
|
|
851
|
+
statement: 'message.text LIKE :text',
|
|
852
|
+
args: { text: `%${query}%` },
|
|
853
|
+
},
|
|
854
|
+
],
|
|
855
|
+
limit: (_g = additionalFields.limit) !== null && _g !== void 0 ? _g : 20,
|
|
856
|
+
sort: (_h = additionalFields.sort) !== null && _h !== void 0 ? _h : 'DESC',
|
|
857
|
+
};
|
|
858
|
+
if (additionalFields.chatGuid)
|
|
859
|
+
body.chatGuid = additionalFields.chatGuid;
|
|
860
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
861
|
+
method: 'POST',
|
|
862
|
+
url: `${baseUrl}/api/v1/message/query`,
|
|
863
|
+
body,
|
|
864
|
+
json: true,
|
|
865
|
+
});
|
|
866
|
+
const messages = (_j = response.data) !== null && _j !== void 0 ? _j : response;
|
|
867
|
+
if (Array.isArray(messages)) {
|
|
868
|
+
for (const msg of messages) {
|
|
869
|
+
returnData.push({
|
|
870
|
+
json: {
|
|
871
|
+
guid: msg.guid,
|
|
872
|
+
text: msg.text,
|
|
873
|
+
sender: (_l = (_k = msg.handle) === null || _k === void 0 ? void 0 : _k.address) !== null && _l !== void 0 ? _l : null,
|
|
874
|
+
dateCreated: msg.dateCreated,
|
|
875
|
+
isFromMe: msg.isFromMe,
|
|
876
|
+
},
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
responseData = messages;
|
|
882
|
+
}
|
|
883
|
+
else if (operation === 'getMessages') {
|
|
884
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
885
|
+
const additionalFields = this.getNodeParameter('getMessagesAdditionalFields', i);
|
|
886
|
+
const body = {
|
|
887
|
+
chatGuid,
|
|
888
|
+
limit: (_m = additionalFields.limit) !== null && _m !== void 0 ? _m : 20,
|
|
889
|
+
sort: (_o = additionalFields.sort) !== null && _o !== void 0 ? _o : 'DESC',
|
|
890
|
+
};
|
|
891
|
+
if (additionalFields.after) {
|
|
892
|
+
const afterTime = new Date(additionalFields.after).getTime();
|
|
893
|
+
if (!Number.isNaN(afterTime))
|
|
894
|
+
body.after = afterTime;
|
|
895
|
+
}
|
|
896
|
+
if (additionalFields.before) {
|
|
897
|
+
const beforeTime = new Date(additionalFields.before).getTime();
|
|
898
|
+
if (!Number.isNaN(beforeTime))
|
|
899
|
+
body.before = beforeTime;
|
|
900
|
+
}
|
|
901
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
902
|
+
method: 'POST',
|
|
903
|
+
url: `${baseUrl}/api/v1/message/query`,
|
|
904
|
+
body,
|
|
905
|
+
json: true,
|
|
906
|
+
});
|
|
907
|
+
const messages = (_p = response.data) !== null && _p !== void 0 ? _p : response;
|
|
908
|
+
if (Array.isArray(messages)) {
|
|
909
|
+
for (const msg of messages) {
|
|
910
|
+
returnData.push({
|
|
911
|
+
json: {
|
|
912
|
+
guid: msg.guid,
|
|
913
|
+
text: msg.text,
|
|
914
|
+
sender: (_r = (_q = msg.handle) === null || _q === void 0 ? void 0 : _q.address) !== null && _r !== void 0 ? _r : null,
|
|
915
|
+
dateCreated: msg.dateCreated,
|
|
916
|
+
isFromMe: msg.isFromMe,
|
|
917
|
+
},
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
responseData = messages;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
else if (resource === 'chat') {
|
|
926
|
+
if (operation === 'listChats') {
|
|
927
|
+
const additionalFields = this.getNodeParameter('listChatsAdditionalFields', i);
|
|
928
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
929
|
+
method: 'POST',
|
|
930
|
+
url: `${baseUrl}/api/v1/chat/query`,
|
|
931
|
+
body: {
|
|
932
|
+
limit: (_s = additionalFields.limit) !== null && _s !== void 0 ? _s : 20,
|
|
933
|
+
withLastMessage: additionalFields.withLastMessage !== false,
|
|
934
|
+
},
|
|
935
|
+
json: true,
|
|
936
|
+
});
|
|
937
|
+
const chats = (_t = response.data) !== null && _t !== void 0 ? _t : response;
|
|
938
|
+
if (Array.isArray(chats)) {
|
|
939
|
+
for (const chat of chats) {
|
|
940
|
+
const lastMessage = chat.lastMessage;
|
|
941
|
+
returnData.push({
|
|
942
|
+
json: {
|
|
943
|
+
guid: chat.guid,
|
|
944
|
+
displayName: chat.displayName,
|
|
945
|
+
lastMessageText: (_u = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.text) !== null && _u !== void 0 ? _u : null,
|
|
946
|
+
lastMessageDate: (_v = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.dateCreated) !== null && _v !== void 0 ? _v : null,
|
|
947
|
+
},
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
responseData = chats;
|
|
953
|
+
}
|
|
954
|
+
else if (operation === 'createChat') {
|
|
955
|
+
const phoneNumbers = this.getNodeParameter('phoneNumbers', i);
|
|
956
|
+
const additionalFields = this.getNodeParameter('createChatAdditionalFields', i);
|
|
957
|
+
const body = {
|
|
958
|
+
addresses: phoneNumbers.split(',').map((s) => s.trim()),
|
|
959
|
+
service: additionalFields.service || 'iMessage',
|
|
960
|
+
method: 'private-api',
|
|
961
|
+
};
|
|
962
|
+
if (additionalFields.message)
|
|
963
|
+
body.message = additionalFields.message;
|
|
964
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
965
|
+
method: 'POST',
|
|
966
|
+
url: `${baseUrl}/api/v1/chat/new`,
|
|
967
|
+
body,
|
|
968
|
+
json: true,
|
|
969
|
+
});
|
|
970
|
+
responseData = (_w = response.data) !== null && _w !== void 0 ? _w : response;
|
|
971
|
+
}
|
|
972
|
+
else if (operation === 'markChatRead') {
|
|
973
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
974
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
975
|
+
method: 'POST',
|
|
976
|
+
url: `${baseUrl}/api/v1/chat/${encodeURIComponent(chatGuid)}/read`,
|
|
977
|
+
json: true,
|
|
978
|
+
});
|
|
979
|
+
responseData = (_x = response.data) !== null && _x !== void 0 ? _x : response;
|
|
980
|
+
}
|
|
981
|
+
else if (operation === 'startTyping') {
|
|
982
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
983
|
+
await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
984
|
+
method: 'POST',
|
|
985
|
+
url: `${baseUrl}/api/v1/chat/${encodeURIComponent(chatGuid)}/typing`,
|
|
986
|
+
json: true,
|
|
987
|
+
});
|
|
988
|
+
responseData = { typing: true, chatGuid };
|
|
989
|
+
}
|
|
990
|
+
else if (operation === 'stopTyping') {
|
|
991
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
992
|
+
await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
993
|
+
method: 'DELETE',
|
|
994
|
+
url: `${baseUrl}/api/v1/chat/${encodeURIComponent(chatGuid)}/typing`,
|
|
995
|
+
json: true,
|
|
996
|
+
});
|
|
997
|
+
responseData = { typing: false, chatGuid };
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
else if (resource === 'scheduledMessage') {
|
|
1001
|
+
if (operation === 'createScheduledMessage') {
|
|
1002
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
1003
|
+
const message = this.getNodeParameter('message', i);
|
|
1004
|
+
const sendAt = this.getNodeParameter('sendAt', i);
|
|
1005
|
+
const scheduleType = this.getNodeParameter('scheduleType', i);
|
|
1006
|
+
const schedule = { type: scheduleType };
|
|
1007
|
+
if (scheduleType !== 'once') {
|
|
1008
|
+
schedule.type = 'recurring';
|
|
1009
|
+
schedule.intervalType = scheduleType;
|
|
1010
|
+
schedule.interval = 1;
|
|
1011
|
+
}
|
|
1012
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1013
|
+
method: 'POST',
|
|
1014
|
+
url: `${baseUrl}/api/v1/message/schedule`,
|
|
1015
|
+
body: {
|
|
1016
|
+
type: 'send-message',
|
|
1017
|
+
payload: {
|
|
1018
|
+
chatGuid,
|
|
1019
|
+
message,
|
|
1020
|
+
method: 'apple-script',
|
|
1021
|
+
},
|
|
1022
|
+
scheduledFor: new Date(sendAt).getTime(),
|
|
1023
|
+
schedule,
|
|
1024
|
+
},
|
|
1025
|
+
json: true,
|
|
1026
|
+
});
|
|
1027
|
+
responseData = (_y = response.data) !== null && _y !== void 0 ? _y : response;
|
|
1028
|
+
}
|
|
1029
|
+
else if (operation === 'listScheduledMessages') {
|
|
1030
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1031
|
+
method: 'GET',
|
|
1032
|
+
url: `${baseUrl}/api/v1/message/schedule`,
|
|
1033
|
+
json: true,
|
|
1034
|
+
});
|
|
1035
|
+
const schedules = (_z = response.data) !== null && _z !== void 0 ? _z : response;
|
|
1036
|
+
if (Array.isArray(schedules)) {
|
|
1037
|
+
for (const sched of schedules) {
|
|
1038
|
+
const payload = sched.payload;
|
|
1039
|
+
const scheduleInfo = sched.schedule;
|
|
1040
|
+
returnData.push({
|
|
1041
|
+
json: {
|
|
1042
|
+
id: sched.id,
|
|
1043
|
+
message: (_0 = payload === null || payload === void 0 ? void 0 : payload.message) !== null && _0 !== void 0 ? _0 : null,
|
|
1044
|
+
chatGuid: (_1 = payload === null || payload === void 0 ? void 0 : payload.chatGuid) !== null && _1 !== void 0 ? _1 : null,
|
|
1045
|
+
scheduledFor: sched.scheduledFor,
|
|
1046
|
+
scheduleType: (_2 = scheduleInfo === null || scheduleInfo === void 0 ? void 0 : scheduleInfo.type) !== null && _2 !== void 0 ? _2 : null,
|
|
1047
|
+
},
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
continue;
|
|
1051
|
+
}
|
|
1052
|
+
responseData = schedules;
|
|
1053
|
+
}
|
|
1054
|
+
else if (operation === 'deleteScheduledMessage') {
|
|
1055
|
+
const scheduledMessageId = this.getNodeParameter('scheduledMessageId', i);
|
|
1056
|
+
await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1057
|
+
method: 'DELETE',
|
|
1058
|
+
url: `${baseUrl}/api/v1/message/schedule/${encodeURIComponent(scheduledMessageId)}`,
|
|
1059
|
+
json: true,
|
|
1060
|
+
});
|
|
1061
|
+
responseData = { deleted: true };
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
else if (resource === 'poll') {
|
|
1065
|
+
if (operation === 'createPoll') {
|
|
1066
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
1067
|
+
const pollOptions = this.getNodeParameter('pollOptions', i);
|
|
1068
|
+
const pollTitle = this.getNodeParameter('pollTitle', i, '');
|
|
1069
|
+
const body = {
|
|
1070
|
+
chatGuid,
|
|
1071
|
+
options: pollOptions.split(',').map((s) => s.trim()).filter(Boolean),
|
|
1072
|
+
};
|
|
1073
|
+
if (pollTitle)
|
|
1074
|
+
body.title = pollTitle;
|
|
1075
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1076
|
+
method: 'POST',
|
|
1077
|
+
url: `${baseUrl}/api/v1/message/poll/create`,
|
|
1078
|
+
body,
|
|
1079
|
+
json: true,
|
|
1080
|
+
});
|
|
1081
|
+
responseData = (_3 = response.data) !== null && _3 !== void 0 ? _3 : response;
|
|
1082
|
+
}
|
|
1083
|
+
else if (operation === 'vote') {
|
|
1084
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
1085
|
+
const pollMessageGuid = this.getNodeParameter('pollMessageGuid', i);
|
|
1086
|
+
const optionIdentifier = this.getNodeParameter('optionIdentifier', i);
|
|
1087
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1088
|
+
method: 'POST',
|
|
1089
|
+
url: `${baseUrl}/api/v1/message/poll/vote`,
|
|
1090
|
+
body: { chatGuid, pollMessageGuid, optionIdentifier },
|
|
1091
|
+
json: true,
|
|
1092
|
+
});
|
|
1093
|
+
responseData = (_4 = response.data) !== null && _4 !== void 0 ? _4 : response;
|
|
1094
|
+
}
|
|
1095
|
+
else if (operation === 'unvote') {
|
|
1096
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
1097
|
+
const pollMessageGuid = this.getNodeParameter('pollMessageGuid', i);
|
|
1098
|
+
const optionIdentifier = this.getNodeParameter('optionIdentifier', i);
|
|
1099
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1100
|
+
method: 'POST',
|
|
1101
|
+
url: `${baseUrl}/api/v1/message/poll/unvote`,
|
|
1102
|
+
body: { chatGuid, pollMessageGuid, optionIdentifier },
|
|
1103
|
+
json: true,
|
|
1104
|
+
});
|
|
1105
|
+
responseData = (_5 = response.data) !== null && _5 !== void 0 ? _5 : response;
|
|
1106
|
+
}
|
|
1107
|
+
else if (operation === 'addOption') {
|
|
1108
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
1109
|
+
const pollMessageGuid = this.getNodeParameter('pollMessageGuid', i);
|
|
1110
|
+
const optionText = this.getNodeParameter('optionText', i);
|
|
1111
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1112
|
+
method: 'POST',
|
|
1113
|
+
url: `${baseUrl}/api/v1/message/poll/add-option`,
|
|
1114
|
+
body: { chatGuid, pollMessageGuid, optionText },
|
|
1115
|
+
json: true,
|
|
1116
|
+
});
|
|
1117
|
+
responseData = (_6 = response.data) !== null && _6 !== void 0 ? _6 : response;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
else if (resource === 'contact') {
|
|
1121
|
+
if (operation === 'shareContactCard') {
|
|
1122
|
+
const chatGuid = this.getNodeParameter('chatGuid', i);
|
|
1123
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1124
|
+
method: 'POST',
|
|
1125
|
+
url: `${baseUrl}/api/v1/contact/share`,
|
|
1126
|
+
body: { chatGuid },
|
|
1127
|
+
json: true,
|
|
1128
|
+
});
|
|
1129
|
+
responseData = (_7 = response.data) !== null && _7 !== void 0 ? _7 : response;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
else if (resource === 'handle') {
|
|
1133
|
+
if (operation === 'checkAvailability') {
|
|
1134
|
+
const address = this.getNodeParameter('address', i);
|
|
1135
|
+
const response = await this.helpers.httpRequestWithAuthentication.call(this, 'photonIMessageApi', {
|
|
1136
|
+
method: 'GET',
|
|
1137
|
+
url: `${baseUrl}/api/v1/handle/availability/imessage`,
|
|
1138
|
+
qs: { address },
|
|
1139
|
+
json: true,
|
|
1140
|
+
});
|
|
1141
|
+
const availData = response;
|
|
1142
|
+
responseData = {
|
|
1143
|
+
address,
|
|
1144
|
+
available: !!availData.data,
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (responseData !== undefined) {
|
|
1149
|
+
returnData.push({
|
|
1150
|
+
json: responseData,
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
catch (error) {
|
|
1155
|
+
if (this.continueOnFail()) {
|
|
1156
|
+
returnData.push({
|
|
1157
|
+
json: { error: error.message },
|
|
1158
|
+
});
|
|
1159
|
+
continue;
|
|
1160
|
+
}
|
|
1161
|
+
throw error;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
return [returnData];
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
exports.PhotonIMessage = PhotonIMessage;
|
|
1168
|
+
//# sourceMappingURL=PhotonIMessage.node.js.map
|