n8n-nodes-imessage 0.3.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -85
- package/dist/credentials/PhotonSpectrumApi.credentials.d.ts +14 -0
- package/dist/credentials/PhotonSpectrumApi.credentials.js +226 -0
- package/dist/credentials/PhotonSpectrumApi.credentials.js.map +1 -0
- package/dist/credentials/httpErrors.d.ts +1 -0
- package/dist/credentials/httpErrors.js +9 -0
- package/dist/credentials/httpErrors.js.map +1 -0
- package/dist/credentials/imessageLines.d.ts +23 -0
- package/dist/credentials/imessageLines.js +120 -0
- package/dist/credentials/imessageLines.js.map +1 -0
- package/dist/credentials/photonHttp.d.ts +22 -0
- package/dist/credentials/photonHttp.js +149 -0
- package/dist/credentials/photonHttp.js.map +1 -0
- package/dist/credentials/projectResolve.d.ts +13 -0
- package/dist/credentials/projectResolve.js +46 -0
- package/dist/credentials/projectResolve.js.map +1 -0
- package/dist/credentials/spectrumProvision.d.ts +8 -0
- package/dist/credentials/spectrumProvision.js +37 -0
- package/dist/credentials/spectrumProvision.js.map +1 -0
- package/dist/credentials/spectrumTypes.d.ts +7 -0
- package/dist/credentials/spectrumTypes.js +3 -0
- package/dist/credentials/spectrumTypes.js.map +1 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessage.node.d.ts +9 -1
- package/dist/nodes/PhotonIMessage/PhotonIMessage.node.js +172947 -1225
- package/dist/nodes/PhotonIMessage/PhotonIMessage.node.js.map +1 -1
- package/dist/nodes/PhotonIMessage/PhotonIMessageTrigger.node.d.ts +1 -1
- package/dist/nodes/PhotonIMessage/PhotonIMessageTrigger.node.js +597 -182
- package/dist/nodes/PhotonIMessage/PhotonIMessageTrigger.node.js.map +1 -1
- package/dist/nodes/PhotonIMessage/PhotonIMessageTyping.node.d.ts +13 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessageTyping.node.js +172338 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessageTyping.node.js.map +1 -0
- package/dist/nodes/PhotonIMessage/PhotonIMessageTyping.node.json +18 -0
- package/dist/nodes/PhotonIMessage/lib/credentials.d.ts +3 -0
- package/dist/nodes/PhotonIMessage/lib/credentials.js +21 -0
- package/dist/nodes/PhotonIMessage/lib/credentials.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/effects.d.ts +8 -0
- package/dist/nodes/PhotonIMessage/lib/effects.js +14 -0
- package/dist/nodes/PhotonIMessage/lib/effects.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/lines.d.ts +42 -0
- package/dist/nodes/PhotonIMessage/lib/lines.js +128 -0
- package/dist/nodes/PhotonIMessage/lib/lines.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/outboundErrors.d.ts +3 -0
- package/dist/nodes/PhotonIMessage/lib/outboundErrors.js +51 -0
- package/dist/nodes/PhotonIMessage/lib/outboundErrors.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/recipients.d.ts +4 -0
- package/dist/nodes/PhotonIMessage/lib/recipients.js +32 -0
- package/dist/nodes/PhotonIMessage/lib/recipients.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/spectrumClient.d.ts +35 -0
- package/dist/nodes/PhotonIMessage/lib/spectrumClient.js +70 -0
- package/dist/nodes/PhotonIMessage/lib/spectrumClient.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/spectrumHeaders.d.ts +1 -0
- package/dist/nodes/PhotonIMessage/lib/spectrumHeaders.js +12 -0
- package/dist/nodes/PhotonIMessage/lib/spectrumHeaders.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/types.d.ts +18 -0
- package/dist/nodes/PhotonIMessage/lib/types.js +24 -0
- package/dist/nodes/PhotonIMessage/lib/types.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/verifySignature.d.ts +14 -0
- package/dist/nodes/PhotonIMessage/lib/verifySignature.js +28 -0
- package/dist/nodes/PhotonIMessage/lib/verifySignature.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/webhookApi.d.ts +12 -0
- package/dist/nodes/PhotonIMessage/lib/webhookApi.js +78 -0
- package/dist/nodes/PhotonIMessage/lib/webhookApi.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/webhookSync.d.ts +26 -0
- package/dist/nodes/PhotonIMessage/lib/webhookSync.js +67 -0
- package/dist/nodes/PhotonIMessage/lib/webhookSync.js.map +1 -0
- package/dist/nodes/PhotonIMessage/lib/webhookUrl.d.ts +4 -0
- package/dist/nodes/PhotonIMessage/lib/webhookUrl.js +58 -0
- package/dist/nodes/PhotonIMessage/lib/webhookUrl.js.map +1 -0
- package/dist/package.json +11 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -5
- package/dist/credentials/PhotonIMessageApi.credentials.d.ts +0 -13
- package/dist/credentials/PhotonIMessageApi.credentials.js +0 -48
- package/dist/credentials/PhotonIMessageApi.credentials.js.map +0 -1
- package/npm-shrinkwrap.json +0 -19
package/README.md
CHANGED
|
@@ -3,115 +3,60 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/n8n-nodes-imessage)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="assets/hero.jpg" alt="n8n now has native iMessage support" width="1024">
|
|
8
|
+
</p>
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
Send and receive iMessages from n8n workflows — powered by [Photon Spectrum](https://docs.photon.codes/spectrum-ts/providers/imessage).
|
|
9
11
|
|
|
10
|
-
##
|
|
12
|
+
## Install
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
1. Visit [photon.codes](https://photon.codes) to create an account
|
|
15
|
-
2. Get your **Server URL** and **API Key** from the Photon dashboard
|
|
16
|
-
|
|
17
|
-
## Installation
|
|
18
|
-
|
|
19
|
-
Follow the [n8n community nodes installation guide](https://docs.n8n.io/integrations/community-nodes/installation/) to install `n8n-nodes-imessage` in your n8n instance.
|
|
20
|
-
|
|
21
|
-
```
|
|
14
|
+
```bash
|
|
22
15
|
npm install n8n-nodes-imessage
|
|
23
16
|
```
|
|
24
17
|
|
|
18
|
+
See the [n8n community nodes guide](https://docs.n8n.io/integrations/community-nodes/installation/) for self-hosted setup.
|
|
19
|
+
|
|
25
20
|
## Credentials
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
2. Enter your **Server URL** — from your [Photon dashboard](https://photon.codes) (no trailing slash)
|
|
29
|
-
3. Enter your **API Key** — from your [Photon dashboard](https://photon.codes), sent as an `X-API-Key` header on every request
|
|
30
|
-
4. Click **Test** to verify the connection
|
|
22
|
+
In n8n, create a **Photon iMessage API** credential with your **Project ID** and **API Key** from [app.photon.codes](https://app.photon.codes) → your project → **Settings**.
|
|
31
23
|
|
|
32
24
|
## Nodes
|
|
33
25
|
|
|
34
|
-
###
|
|
35
|
-
|
|
36
|
-
Perform operations on your iMessage account.
|
|
37
|
-
|
|
38
|
-
#### Message
|
|
39
|
-
|
|
40
|
-
| Operation | Description |
|
|
41
|
-
|-----------|-------------|
|
|
42
|
-
| **Send Message** | Send a text message to a chat. Supports reply-to, message effects (confetti, fireworks, etc.), and subject lines. |
|
|
43
|
-
| **Send Attachment** | Send a file from the server Mac to a chat. Supports voice messages. |
|
|
44
|
-
| **Unsend Message** | Retract a sent message. |
|
|
45
|
-
| **Edit Message** | Edit the text of a sent message. |
|
|
46
|
-
| **React to Message** | Send a tapback reaction (love, like, dislike, laugh, emphasize, question). |
|
|
47
|
-
| **Download Attachment** | Download a received file or media attachment. |
|
|
48
|
-
| **Search Messages** | Search messages by text content across all chats or a specific chat. |
|
|
49
|
-
| **Get Messages** | Retrieve messages from a chat with date range and sort options. |
|
|
26
|
+
### iMessage by Photon
|
|
50
27
|
|
|
51
|
-
|
|
28
|
+
Send iMessages from a workflow.
|
|
52
29
|
|
|
53
|
-
|
|
54
|
-
|-----------|-------------|
|
|
55
|
-
| **List Chats** | List all conversations with optional last message preview. |
|
|
56
|
-
| **Create Chat** | Start a new conversation with one or more participants. |
|
|
57
|
-
| **Mark Chat Read** | Mark all messages in a chat as read. |
|
|
58
|
-
| **Start Typing** | Show the typing indicator in a chat. |
|
|
59
|
-
| **Stop Typing** | Hide the typing indicator in a chat. |
|
|
30
|
+
**Default actions:** Send Message, Send Attachment, Reply, React.
|
|
60
31
|
|
|
61
|
-
|
|
32
|
+
Turn on **Show Expert Options** for rich links, voice notes, polls, effects, group albums, and more.
|
|
62
33
|
|
|
63
|
-
|
|
64
|
-
|-----------|-------------|
|
|
65
|
-
| **Share Contact Card** | Share your Name and Photo contact card in a chat. |
|
|
34
|
+
**Quick start:** Manual Trigger → Send Message → phone number (+15551234567) + text. Apple ID emails are not supported — use a phone number.
|
|
66
35
|
|
|
67
|
-
|
|
36
|
+
**Auto-reply:** On iMessage Event → Reply or React (sender and message ID come from the trigger).
|
|
68
37
|
|
|
69
|
-
|
|
70
|
-
|-----------|-------------|
|
|
71
|
-
| **Create Poll** | Create an interactive poll in a chat. |
|
|
72
|
-
| **Vote** | Vote on a poll option. |
|
|
73
|
-
| **Unvote** | Remove your vote from a poll option. |
|
|
74
|
-
| **Add Option** | Add a new option to an existing poll. |
|
|
38
|
+
### iMessage by Photon Trigger
|
|
75
39
|
|
|
76
|
-
|
|
40
|
+
Runs when an inbound text message arrives. Output includes `messageId`, `sender`, `text`, `linePhone`, `spaceId`, `spaceType`, and `timestamp`.
|
|
77
41
|
|
|
78
|
-
|
|
79
|
-
|-----------|-------------|
|
|
80
|
-
| **Create Scheduled Message** | Schedule a message to send later. Supports one-time and recurring schedules (hourly, daily, weekly, monthly, yearly). |
|
|
81
|
-
| **List Scheduled Messages** | View all pending scheduled messages. |
|
|
82
|
-
| **Delete Scheduled Message** | Remove a scheduled message. |
|
|
42
|
+
Activate the workflow to register the webhook. For local development:
|
|
83
43
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|-----------|-------------|
|
|
88
|
-
| **Check iMessage Availability** | Check if a phone number or email address supports iMessage. |
|
|
89
|
-
|
|
90
|
-
### Photon iMessage Trigger (Polling Trigger)
|
|
91
|
-
|
|
92
|
-
Triggers your workflow when new iMessages are received.
|
|
93
|
-
|
|
94
|
-
| Parameter | Description |
|
|
95
|
-
|-----------|-------------|
|
|
96
|
-
| **Chat GUID** | Only trigger for messages in a specific chat (leave blank for all). |
|
|
97
|
-
| **Include Sent Messages** | Also trigger for messages you sent (default: off). |
|
|
98
|
-
| **Max Messages Per Poll** | Maximum number of messages to fetch per poll interval (default: 100). |
|
|
99
|
-
|
|
100
|
-
The trigger polls for new messages and tracks the last message timestamp to avoid duplicates.
|
|
101
|
-
|
|
102
|
-
## Chat GUID Format
|
|
44
|
+
```bash
|
|
45
|
+
npm run dev:tunnel
|
|
46
|
+
```
|
|
103
47
|
|
|
104
|
-
|
|
48
|
+
## Local development
|
|
105
49
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
50
|
+
```bash
|
|
51
|
+
npm install
|
|
52
|
+
npm run dev:tunnel
|
|
53
|
+
```
|
|
109
54
|
|
|
110
|
-
##
|
|
55
|
+
## Docs
|
|
111
56
|
|
|
112
|
-
- [
|
|
113
|
-
- [
|
|
114
|
-
- [
|
|
57
|
+
- [Spectrum iMessage provider](https://docs.photon.codes/spectrum-ts/providers/imessage)
|
|
58
|
+
- [Webhook events](https://docs.photon.codes/webhooks/events)
|
|
59
|
+
- [iMessage deliverability](https://docs.photon.codes/best-practices/imessage-deliverability)
|
|
115
60
|
|
|
116
61
|
## License
|
|
117
62
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IAuthenticateGeneric, ICredentialDataDecryptedObject, ICredentialTestRequest, ICredentialType, IDataObject, IHttpRequestHelper, INodeProperties } from 'n8n-workflow';
|
|
2
|
+
export declare class PhotonSpectrumApi implements ICredentialType {
|
|
3
|
+
name: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
icon: {
|
|
6
|
+
readonly light: "file:../nodes/PhotonIMessage/Dark.svg";
|
|
7
|
+
readonly dark: "file:../nodes/PhotonIMessage/Dark.svg";
|
|
8
|
+
};
|
|
9
|
+
documentationUrl: string;
|
|
10
|
+
properties: INodeProperties[];
|
|
11
|
+
preAuthentication(this: IHttpRequestHelper, credentials: ICredentialDataDecryptedObject): Promise<IDataObject>;
|
|
12
|
+
authenticate: IAuthenticateGeneric;
|
|
13
|
+
test: ICredentialTestRequest;
|
|
14
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PhotonSpectrumApi = void 0;
|
|
4
|
+
const imessageLines_1 = require("./imessageLines");
|
|
5
|
+
const httpErrors_1 = require("./httpErrors");
|
|
6
|
+
const spectrumProvision_1 = require("./spectrumProvision");
|
|
7
|
+
const DEFAULT_RUNTIME = 'https://spectrum.photon.codes';
|
|
8
|
+
const DEFAULT_DASHBOARD = 'https://app.photon.codes';
|
|
9
|
+
const CREDENTIAL_TEST_URL = `${DEFAULT_DASHBOARD}/api/auth/ok`;
|
|
10
|
+
function timeoutAfter(ms, message) {
|
|
11
|
+
return new Promise((_, reject) => {
|
|
12
|
+
setTimeout(() => reject(new Error(message)), ms);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function trimHost(host, fallback) {
|
|
16
|
+
const raw = (typeof host === 'string' && host) || fallback;
|
|
17
|
+
return raw.replace(/\/+$/, '');
|
|
18
|
+
}
|
|
19
|
+
function isRedactedSecret(value) {
|
|
20
|
+
return typeof value === 'string' && value.startsWith('*****');
|
|
21
|
+
}
|
|
22
|
+
function looksLikeSpectrumSecret(value) {
|
|
23
|
+
return value.length >= 24 && /^[A-Za-z0-9_-]+$/.test(value);
|
|
24
|
+
}
|
|
25
|
+
function withConnectionState(data, state) {
|
|
26
|
+
return { ...data, connectionState: state };
|
|
27
|
+
}
|
|
28
|
+
class PhotonSpectrumApi {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.name = 'photonSpectrumApi';
|
|
31
|
+
this.displayName = 'Photon iMessage API';
|
|
32
|
+
this.icon = {
|
|
33
|
+
light: 'file:../nodes/PhotonIMessage/Dark.svg',
|
|
34
|
+
dark: 'file:../nodes/PhotonIMessage/Dark.svg',
|
|
35
|
+
};
|
|
36
|
+
this.documentationUrl = 'https://docs.photon.codes/spectrum-ts/providers/imessage';
|
|
37
|
+
this.properties = [
|
|
38
|
+
{ displayName: 'Connection State', name: 'connectionState', type: 'hidden', default: 'setup' },
|
|
39
|
+
{
|
|
40
|
+
displayName: 'Enter <b>Project ID</b> and <b>API Key</b> from <a href="https://app.photon.codes" target="_blank">app.photon.codes</a> → your project → <b>Settings</b>, then click <b>Save</b>.',
|
|
41
|
+
name: 'setupNotice',
|
|
42
|
+
type: 'notice',
|
|
43
|
+
default: '',
|
|
44
|
+
displayOptions: {
|
|
45
|
+
show: { connectionState: ['setup'] },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
displayName: 'Project ID',
|
|
50
|
+
name: 'projectId',
|
|
51
|
+
type: 'string',
|
|
52
|
+
default: '',
|
|
53
|
+
required: true,
|
|
54
|
+
placeholder: 'From app.photon.codes → Settings',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
displayName: 'API Key',
|
|
58
|
+
name: 'projectSecret',
|
|
59
|
+
type: 'string',
|
|
60
|
+
typeOptions: { password: true },
|
|
61
|
+
default: '',
|
|
62
|
+
required: true,
|
|
63
|
+
description: 'Project API key from app.photon.codes → Settings (shown as Project Secret on the dashboard).',
|
|
64
|
+
placeholder: 'From app.photon.codes → Settings',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
displayName: '<b>Connected.</b> Add <b>iMessage by Photon Trigger</b> to a workflow and toggle it <b>Active</b>. Manage lines and contacts on app.photon.codes.',
|
|
68
|
+
name: 'connectedNotice',
|
|
69
|
+
type: 'notice',
|
|
70
|
+
default: '',
|
|
71
|
+
displayOptions: {
|
|
72
|
+
show: {
|
|
73
|
+
connectionState: ['connected'],
|
|
74
|
+
projectId: [{ _cnd: { not: '' } }],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
displayName: 'Your iMessage Line',
|
|
80
|
+
name: 'primaryLineNumber',
|
|
81
|
+
type: 'string',
|
|
82
|
+
default: '',
|
|
83
|
+
typeOptions: { editable: false },
|
|
84
|
+
description: 'First line on this project (read-only). Add or assign lines on app.photon.codes.',
|
|
85
|
+
displayOptions: {
|
|
86
|
+
show: {
|
|
87
|
+
connectionState: ['connected'],
|
|
88
|
+
primaryLineNumber: [{ _cnd: { not: '' } }],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
displayName: 'Project lines',
|
|
94
|
+
name: 'imessageLines',
|
|
95
|
+
type: 'string',
|
|
96
|
+
default: '',
|
|
97
|
+
typeOptions: { editable: false, rows: 4 },
|
|
98
|
+
description: 'Lines loaded from Spectrum. Update users and assignments on app.photon.codes.',
|
|
99
|
+
displayOptions: {
|
|
100
|
+
show: {
|
|
101
|
+
connectionState: ['connected'],
|
|
102
|
+
imessageLines: [{ _cnd: { not: '' } }],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
displayName: 'Line status',
|
|
108
|
+
name: 'lineStatus',
|
|
109
|
+
type: 'string',
|
|
110
|
+
default: '',
|
|
111
|
+
typeOptions: { editable: false },
|
|
112
|
+
displayOptions: {
|
|
113
|
+
show: {
|
|
114
|
+
connectionState: ['connected'],
|
|
115
|
+
lineStatus: [{ _cnd: { not: '' } }],
|
|
116
|
+
primaryLineNumber: [''],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{ displayName: 'Line mode key', name: 'lineMode', type: 'hidden', default: '' },
|
|
121
|
+
{ displayName: 'Line mode label', name: 'lineModeLabel', type: 'hidden', default: '' },
|
|
122
|
+
{ displayName: 'Line numbers JSON', name: 'lineNumbersJson', type: 'hidden', default: '[]' },
|
|
123
|
+
{ displayName: 'Line count', name: 'lineCount', type: 'hidden', default: 0 },
|
|
124
|
+
{ displayName: 'Spectrum Runtime URL', name: 'apiHost', type: 'hidden', default: DEFAULT_RUNTIME },
|
|
125
|
+
{ displayName: 'Dashboard URL', name: 'dashboardHost', type: 'hidden', default: DEFAULT_DASHBOARD },
|
|
126
|
+
];
|
|
127
|
+
this.authenticate = {
|
|
128
|
+
type: 'generic',
|
|
129
|
+
properties: {
|
|
130
|
+
headers: {
|
|
131
|
+
Authorization: '={{ $credentials.projectSecret ? "Basic " + Buffer.from($credentials.projectId + ":" + $credentials.projectSecret).toString("base64") : "" }}',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
this.test = {
|
|
136
|
+
request: {
|
|
137
|
+
url: CREDENTIAL_TEST_URL,
|
|
138
|
+
method: 'GET',
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
async preAuthentication(credentials) {
|
|
143
|
+
try {
|
|
144
|
+
return await runPreAuthentication(this, credentials);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
148
|
+
const projectId = (credentials.projectId || '').trim();
|
|
149
|
+
const projectSecret = (credentials.projectSecret || '').trim();
|
|
150
|
+
return withConnectionState({
|
|
151
|
+
projectId,
|
|
152
|
+
projectSecret,
|
|
153
|
+
lineStatus: message,
|
|
154
|
+
}, 'setup');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.PhotonSpectrumApi = PhotonSpectrumApi;
|
|
159
|
+
async function runPreAuthentication(helper, credentials) {
|
|
160
|
+
const projectId = (credentials.projectId || '').trim();
|
|
161
|
+
const projectSecretRaw = (credentials.projectSecret || '').trim();
|
|
162
|
+
const connectionState = credentials.connectionState || '';
|
|
163
|
+
const projectSecret = isRedactedSecret(projectSecretRaw) ? '' : projectSecretRaw;
|
|
164
|
+
if (!projectId ||
|
|
165
|
+
(!projectSecret && !(isRedactedSecret(projectSecretRaw) && connectionState === 'connected'))) {
|
|
166
|
+
return withConnectionState({ projectId, projectSecret: projectSecretRaw }, 'setup');
|
|
167
|
+
}
|
|
168
|
+
if (!projectSecret && isRedactedSecret(projectSecretRaw)) {
|
|
169
|
+
return withConnectionState({
|
|
170
|
+
projectId,
|
|
171
|
+
projectSecret: projectSecretRaw,
|
|
172
|
+
lineMode: credentials.lineMode,
|
|
173
|
+
lineModeLabel: credentials.lineModeLabel,
|
|
174
|
+
imessageLines: credentials.imessageLines,
|
|
175
|
+
primaryLineNumber: credentials.primaryLineNumber,
|
|
176
|
+
lineStatus: credentials.lineStatus,
|
|
177
|
+
lineNumbersJson: credentials.lineNumbersJson,
|
|
178
|
+
lineCount: credentials.lineCount,
|
|
179
|
+
}, 'connected');
|
|
180
|
+
}
|
|
181
|
+
if (!looksLikeSpectrumSecret(projectSecret)) {
|
|
182
|
+
throw new Error('API Key looks invalid. Copy it again from app.photon.codes → Settings.');
|
|
183
|
+
}
|
|
184
|
+
const apiHost = trimHost(credentials.apiHost, DEFAULT_RUNTIME);
|
|
185
|
+
const base = {
|
|
186
|
+
projectId,
|
|
187
|
+
projectSecret,
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
await Promise.race([
|
|
191
|
+
(0, spectrumProvision_1.provisionSpectrumProject)(helper, {
|
|
192
|
+
apiHost,
|
|
193
|
+
projectId,
|
|
194
|
+
projectSecret,
|
|
195
|
+
}),
|
|
196
|
+
timeoutAfter(15000, 'provision timeout'),
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
if ((0, httpErrors_1.isAuthError)(err)) {
|
|
201
|
+
throw new Error('Invalid Project ID or API Key. Check values at app.photon.codes → Settings.');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const lines = await Promise.race([
|
|
206
|
+
(0, imessageLines_1.lineInfoFields)(helper, apiHost, projectId, projectSecret),
|
|
207
|
+
timeoutAfter(10000, 'line-enrich timeout'),
|
|
208
|
+
]);
|
|
209
|
+
base.lineMode = lines.lineMode;
|
|
210
|
+
base.lineModeLabel = lines.lineModeLabel;
|
|
211
|
+
base.imessageLines = lines.imessageLines;
|
|
212
|
+
base.primaryLineNumber = lines.primaryLineNumber;
|
|
213
|
+
base.lineNumbersJson = lines.lineNumbersJson;
|
|
214
|
+
base.lineCount = lines.lineCount;
|
|
215
|
+
base.lineStatus = (0, imessageLines_1.buildLineStatus)(lines);
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
if ((0, httpErrors_1.isAuthError)(err)) {
|
|
219
|
+
throw new Error('Invalid Project ID or API Key. Check values at app.photon.codes → Settings.');
|
|
220
|
+
}
|
|
221
|
+
base.lineStatus =
|
|
222
|
+
'Connected, but line details could not be loaded. Save again to refresh.';
|
|
223
|
+
}
|
|
224
|
+
return withConnectionState(base, 'connected');
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=PhotonSpectrumApi.credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PhotonSpectrumApi.credentials.js","sourceRoot":"","sources":["../../credentials/PhotonSpectrumApi.credentials.ts"],"names":[],"mappings":";;;AAUA,mDAAkE;AAClE,6CAA2C;AAC3C,2DAA+D;AAE/D,MAAM,eAAe,GAAG,+BAA+B,CAAC;AACxD,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AACrD,MAAM,mBAAmB,GAAG,GAAG,iBAAiB,cAAc,CAAC;AAE/D,SAAS,YAAY,CAAC,EAAU,EAAE,OAAe;IAChD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAEhC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO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J,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,IAAI,IAAA,wBAAW,EAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACd,6EAA6E,CAC7E,CAAC;QACH,CAAC;IACF,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YAChC,IAAA,8BAAc,EAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC;YACzD,YAAY,CAAC,KAAM,EAAE,qBAAqB,CAAC;SAC3C,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;QACzC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;QACzC,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC;QACjD,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAA,+BAAe,EAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,IAAI,IAAA,wBAAW,EAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACd,6EAA6E,CAC7E,CAAC;QACH,CAAC;QACD,IAAI,CAAC,UAAU;YACd,yEAAyE,CAAC;IAC5E,CAAC;IAED,OAAO,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isAuthError(err: unknown): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAuthError = isAuthError;
|
|
4
|
+
function isAuthError(err) {
|
|
5
|
+
var _a;
|
|
6
|
+
const status = (_a = err.httpCode) !== null && _a !== void 0 ? _a : err.statusCode;
|
|
7
|
+
return status === 401 || status === 403;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=httpErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpErrors.js","sourceRoot":"","sources":["../../credentials/httpErrors.ts"],"names":[],"mappings":";;AACA,kCAKC;AALD,SAAgB,WAAW,CAAC,GAAY;;IACvC,MAAM,MAAM,GACX,MAAC,GAAkD,CAAC,QAAQ,mCAC3D,GAA+B,CAAC,UAAU,CAAC;IAC7C,OAAO,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { IHttpRequestHelper } from 'n8n-workflow';
|
|
2
|
+
export interface IMessageLineInfo {
|
|
3
|
+
mode: 'shared' | 'dedicated' | '';
|
|
4
|
+
lineModeLabel: string;
|
|
5
|
+
imessageLines: string;
|
|
6
|
+
primaryLineNumber: string;
|
|
7
|
+
lineNumbers: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function fetchIMessageLineInfo(helper: IHttpRequestHelper, apiHost: string, projectId: string, projectSecret: string): Promise<IMessageLineInfo>;
|
|
10
|
+
export declare function buildLineStatus(lines: {
|
|
11
|
+
lineMode: string;
|
|
12
|
+
lineModeLabel: string;
|
|
13
|
+
imessageLines: string;
|
|
14
|
+
primaryLineNumber: string;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function lineInfoFields(helper: IHttpRequestHelper, apiHost: string, projectId: string, projectSecret: string): Promise<{
|
|
17
|
+
lineMode: string;
|
|
18
|
+
lineModeLabel: string;
|
|
19
|
+
imessageLines: string;
|
|
20
|
+
primaryLineNumber: string;
|
|
21
|
+
lineNumbersJson: string;
|
|
22
|
+
lineCount: number;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchIMessageLineInfo = fetchIMessageLineInfo;
|
|
4
|
+
exports.buildLineStatus = buildLineStatus;
|
|
5
|
+
exports.lineInfoFields = lineInfoFields;
|
|
6
|
+
const photonHttp_1 = require("./photonHttp");
|
|
7
|
+
const HTTP_TIMEOUT_MS = 20000;
|
|
8
|
+
async function spectrumGet(_helper, apiHost, projectId, projectSecret, path) {
|
|
9
|
+
const host = apiHost.replace(/\/+$/, '');
|
|
10
|
+
const auth = 'Basic ' + Buffer.from(`${projectId}:${projectSecret}`).toString('base64');
|
|
11
|
+
const raw = await (0, photonHttp_1.photonHttpsJson)(`${host}/projects/${encodeURIComponent(projectId)}${path}`, {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: auth,
|
|
15
|
+
Accept: 'application/json',
|
|
16
|
+
},
|
|
17
|
+
timeout: HTTP_TIMEOUT_MS,
|
|
18
|
+
});
|
|
19
|
+
if (raw && typeof raw === 'object' && 'data' in raw) {
|
|
20
|
+
return raw.data;
|
|
21
|
+
}
|
|
22
|
+
return raw;
|
|
23
|
+
}
|
|
24
|
+
function userLabel(user) {
|
|
25
|
+
const name = [user.firstName, user.lastName].filter(Boolean).join(' ').trim();
|
|
26
|
+
if (name)
|
|
27
|
+
return name;
|
|
28
|
+
if (user.email)
|
|
29
|
+
return user.email;
|
|
30
|
+
if (user.phoneNumber)
|
|
31
|
+
return user.phoneNumber;
|
|
32
|
+
return user.id;
|
|
33
|
+
}
|
|
34
|
+
function formatDedicatedLines(lines) {
|
|
35
|
+
const numbers = lines
|
|
36
|
+
.filter((l) => l.platform === 'imessage' && l.phoneNumber)
|
|
37
|
+
.map((l) => l.phoneNumber);
|
|
38
|
+
if (numbers.length === 0) {
|
|
39
|
+
return 'No dedicated iMessage lines on this project yet. Add one in the Photon dashboard.';
|
|
40
|
+
}
|
|
41
|
+
return numbers.map((n) => `Dedicated line: ${n}`).join('\n');
|
|
42
|
+
}
|
|
43
|
+
function formatSharedUsers(users) {
|
|
44
|
+
const withLine = users.filter((u) => u.assignedPhoneNumber);
|
|
45
|
+
if (withLine.length === 0) {
|
|
46
|
+
return 'No shared contacts with assigned lines yet. Create a shared user in the Photon dashboard — each gets a number end users can text.';
|
|
47
|
+
}
|
|
48
|
+
return withLine
|
|
49
|
+
.map((u) => {
|
|
50
|
+
const label = userLabel(u);
|
|
51
|
+
const contact = u.phoneNumber ? ` (contact ${u.phoneNumber})` : '';
|
|
52
|
+
return `${label}${contact} → text ${u.assignedPhoneNumber}`;
|
|
53
|
+
})
|
|
54
|
+
.join('\n');
|
|
55
|
+
}
|
|
56
|
+
async function fetchIMessageLineInfo(helper, apiHost, projectId, projectSecret) {
|
|
57
|
+
var _a, _b, _c, _d;
|
|
58
|
+
const info = await spectrumGet(helper, apiHost, projectId, projectSecret, '/imessage/');
|
|
59
|
+
if (info.type === 'dedicated') {
|
|
60
|
+
const linesData = await spectrumGet(helper, apiHost, projectId, projectSecret, '/lines/?platform=imessage');
|
|
61
|
+
const lines = (_a = linesData.lines) !== null && _a !== void 0 ? _a : [];
|
|
62
|
+
const imessageOnly = lines.filter((l) => l.platform === 'imessage' && l.phoneNumber);
|
|
63
|
+
const numbers = imessageOnly.map((l) => l.phoneNumber);
|
|
64
|
+
return {
|
|
65
|
+
mode: 'dedicated',
|
|
66
|
+
lineModeLabel: 'Dedicated line(s)',
|
|
67
|
+
imessageLines: formatDedicatedLines(lines),
|
|
68
|
+
primaryLineNumber: (_b = numbers[0]) !== null && _b !== void 0 ? _b : '',
|
|
69
|
+
lineNumbers: numbers,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const usersData = await spectrumGet(helper, apiHost, projectId, projectSecret, '/users/?type=shared');
|
|
73
|
+
const users = (_c = usersData.users) !== null && _c !== void 0 ? _c : [];
|
|
74
|
+
const withLine = users.filter((u) => u.assignedPhoneNumber);
|
|
75
|
+
const numbers = withLine.map((u) => u.assignedPhoneNumber);
|
|
76
|
+
return {
|
|
77
|
+
mode: 'shared',
|
|
78
|
+
lineModeLabel: 'Shared pool (per-contact lines)',
|
|
79
|
+
imessageLines: formatSharedUsers(users),
|
|
80
|
+
primaryLineNumber: (_d = numbers[0]) !== null && _d !== void 0 ? _d : '',
|
|
81
|
+
lineNumbers: numbers,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function buildLineStatus(lines) {
|
|
85
|
+
if (lines.primaryLineNumber) {
|
|
86
|
+
const extra = lines.imessageLines &&
|
|
87
|
+
!lines.imessageLines.startsWith('No ') &&
|
|
88
|
+
lines.imessageLines !== lines.primaryLineNumber
|
|
89
|
+
? `\n${lines.imessageLines}`
|
|
90
|
+
: '';
|
|
91
|
+
return `${lines.lineModeLabel}${extra}`;
|
|
92
|
+
}
|
|
93
|
+
if (lines.imessageLines)
|
|
94
|
+
return lines.imessageLines;
|
|
95
|
+
return 'No iMessage line on this project yet. Add lines or shared users on app.photon.codes, then Save again.';
|
|
96
|
+
}
|
|
97
|
+
async function lineInfoFields(helper, apiHost, projectId, projectSecret) {
|
|
98
|
+
try {
|
|
99
|
+
const info = await fetchIMessageLineInfo(helper, apiHost, projectId, projectSecret);
|
|
100
|
+
return {
|
|
101
|
+
lineMode: info.mode,
|
|
102
|
+
lineModeLabel: info.lineModeLabel,
|
|
103
|
+
imessageLines: info.imessageLines,
|
|
104
|
+
primaryLineNumber: info.primaryLineNumber,
|
|
105
|
+
lineNumbersJson: JSON.stringify(info.lineNumbers),
|
|
106
|
+
lineCount: info.lineNumbers.length,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return {
|
|
111
|
+
lineMode: '',
|
|
112
|
+
lineModeLabel: '',
|
|
113
|
+
primaryLineNumber: '',
|
|
114
|
+
lineNumbersJson: '[]',
|
|
115
|
+
lineCount: 0,
|
|
116
|
+
imessageLines: 'Could not load line numbers from Spectrum. Check the dashboard at app.photon.codes.',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=imessageLines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imessageLines.js","sourceRoot":"","sources":["../../credentials/imessageLines.ts"],"names":[],"mappings":";;AAmGA,sDAmDC;AAGD,0CAiBC;AAED,wCAkCC;AA5MD,6CAA+C;AAI/C,MAAM,eAAe,GAAG,KAAM,CAAC;AA4B/B,KAAK,UAAU,WAAW,CACzB,OAA2B,EAC3B,OAAe,EACf,SAAiB,EACjB,aAAqB,EACrB,IAAY;IAEZ,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzC,MAAM,IAAI,GACT,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,IAAI,aAAa,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAG,MAAM,IAAA,4BAAe,EAChC,GAAG,IAAI,aAAa,kBAAkB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,EAC1D;QACC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACR,aAAa,EAAE,IAAI;YACnB,MAAM,EAAE,kBAAkB;SAC1B;QACD,OAAO,EAAE,eAAe;KACxB,CACD,CAAC;IACF,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QACrD,OAAQ,GAA2B,CAAC,IAAI,CAAC;IAC1C,CAAC;IACD,OAAO,GAAQ,CAAC;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,IAAgB;IAClC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,E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I,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC;YACjD,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM;SAClC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO;YACN,QAAQ,EAAE,EAAE;YACZ,aAAa,EAAE,EAAE;YACjB,iBAAiB,EAAE,EAAE;YACrB,eAAe,EAAE,IAAI;YACrB,SAAS,EAAE,CAAC;YACZ,aAAa,EACZ,qFAAqF;SACtF,CAAC;IACH,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface PhotonRequestOptions {
|
|
2
|
+
method?: string;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
body?: unknown;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
returnFullResponse?: boolean;
|
|
7
|
+
ignoreHttpStatusErrors?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PhotonFetchResponse {
|
|
10
|
+
ok: boolean;
|
|
11
|
+
status: number;
|
|
12
|
+
statusText: string;
|
|
13
|
+
json(): Promise<unknown>;
|
|
14
|
+
text(): Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
export declare function photonHttpsJson<T>(urlString: string, options?: PhotonRequestOptions): Promise<T>;
|
|
17
|
+
export declare function photonFetch(urlString: string, init?: {
|
|
18
|
+
method?: string;
|
|
19
|
+
headers?: Record<string, string> | [string, string][] | Headers;
|
|
20
|
+
body?: string | URLSearchParams;
|
|
21
|
+
}): Promise<PhotonFetchResponse>;
|
|
22
|
+
export declare function installPhotonIpv4Fetch(): void;
|