@photon-ai/advanced-imessage-kit 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +149 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +149 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105,6 +105,48 @@ var getLogger = (tag) => {
|
|
|
105
105
|
}
|
|
106
106
|
return logger;
|
|
107
107
|
};
|
|
108
|
+
|
|
109
|
+
// lib/auto-create-chat.ts
|
|
110
|
+
function isChatNotExistError(error) {
|
|
111
|
+
const axiosError = error;
|
|
112
|
+
const errorMsg = axiosError?.response?.data?.error?.message || axiosError?.response?.data?.message || "";
|
|
113
|
+
const lowerMsg = errorMsg.toLowerCase();
|
|
114
|
+
return lowerMsg.includes("chat does not exist") || lowerMsg.includes("chat not found");
|
|
115
|
+
}
|
|
116
|
+
function extractAddress(chatGuid) {
|
|
117
|
+
const parts = chatGuid.split(";-;");
|
|
118
|
+
if (parts.length !== 2 || !parts[1]) {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
return parts[1];
|
|
122
|
+
}
|
|
123
|
+
function extractService(chatGuid) {
|
|
124
|
+
if (!chatGuid) return void 0;
|
|
125
|
+
const prefix = chatGuid.split(";")[0]?.toLowerCase();
|
|
126
|
+
if (prefix === "imessage") return "iMessage";
|
|
127
|
+
if (prefix === "sms") return "SMS";
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
async function createChatWithMessage(options) {
|
|
131
|
+
const { http, address, message, tempGuid, subject, effectId, service } = options;
|
|
132
|
+
try {
|
|
133
|
+
const response = await http.post("/api/v1/chat/new", {
|
|
134
|
+
addresses: [address],
|
|
135
|
+
message,
|
|
136
|
+
tempGuid,
|
|
137
|
+
subject,
|
|
138
|
+
effectId,
|
|
139
|
+
...service && { service }
|
|
140
|
+
});
|
|
141
|
+
return response.data.data?.guid;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
`Failed to create chat with address "${address}": ${error instanceof Error ? error.message : String(error)}`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// modules/attachment.ts
|
|
108
150
|
var AttachmentModule = class {
|
|
109
151
|
constructor(http, enqueueSend = (task) => task()) {
|
|
110
152
|
this.http = http;
|
|
@@ -147,52 +189,94 @@ var AttachmentModule = class {
|
|
|
147
189
|
});
|
|
148
190
|
return response.data.data.blurhash;
|
|
149
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Ensures the chat exists by creating it if it doesn't already exist.
|
|
194
|
+
*/
|
|
195
|
+
async ensureChatExists(chatGuid) {
|
|
196
|
+
const address = extractAddress(chatGuid);
|
|
197
|
+
if (!address) return;
|
|
198
|
+
const service = extractService(chatGuid);
|
|
199
|
+
await this.http.post("/api/v1/chat/new", {
|
|
200
|
+
addresses: [address],
|
|
201
|
+
...service && { service }
|
|
202
|
+
});
|
|
203
|
+
}
|
|
150
204
|
async sendAttachment(options) {
|
|
151
205
|
return this.enqueueSend(async () => {
|
|
152
206
|
const fileBuffer = await readFile(options.filePath);
|
|
153
207
|
const fileName = options.fileName || path__default.basename(options.filePath);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
form.append("
|
|
161
|
-
if (options.isAudioMessage) {
|
|
162
|
-
form.append("
|
|
208
|
+
const tempGuid = randomUUID();
|
|
209
|
+
const buildForm = () => {
|
|
210
|
+
const form = new FormData();
|
|
211
|
+
form.append("chatGuid", options.chatGuid);
|
|
212
|
+
form.append("attachment", fileBuffer, fileName);
|
|
213
|
+
form.append("name", fileName);
|
|
214
|
+
form.append("tempGuid", tempGuid);
|
|
215
|
+
if (options.isAudioMessage !== void 0) {
|
|
216
|
+
form.append("isAudioMessage", options.isAudioMessage.toString());
|
|
217
|
+
if (options.isAudioMessage) {
|
|
218
|
+
form.append("method", "private-api");
|
|
219
|
+
}
|
|
163
220
|
}
|
|
221
|
+
if (options.selectedMessageGuid) {
|
|
222
|
+
form.append("selectedMessageGuid", options.selectedMessageGuid);
|
|
223
|
+
}
|
|
224
|
+
return form;
|
|
225
|
+
};
|
|
226
|
+
try {
|
|
227
|
+
const form = buildForm();
|
|
228
|
+
const response = await this.http.post("/api/v1/message/attachment", form, {
|
|
229
|
+
headers: form.getHeaders()
|
|
230
|
+
});
|
|
231
|
+
return response.data.data;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (!isChatNotExistError(error)) throw error;
|
|
234
|
+
await this.ensureChatExists(options.chatGuid);
|
|
235
|
+
const form = buildForm();
|
|
236
|
+
const response = await this.http.post("/api/v1/message/attachment", form, {
|
|
237
|
+
headers: form.getHeaders()
|
|
238
|
+
});
|
|
239
|
+
return response.data.data;
|
|
164
240
|
}
|
|
165
|
-
if (options.selectedMessageGuid) {
|
|
166
|
-
form.append("selectedMessageGuid", options.selectedMessageGuid);
|
|
167
|
-
}
|
|
168
|
-
const response = await this.http.post("/api/v1/message/attachment", form, {
|
|
169
|
-
headers: form.getHeaders()
|
|
170
|
-
});
|
|
171
|
-
return response.data.data;
|
|
172
241
|
});
|
|
173
242
|
}
|
|
174
243
|
async sendSticker(options) {
|
|
175
244
|
return this.enqueueSend(async () => {
|
|
176
245
|
const fileName = options.fileName || path__default.basename(options.filePath);
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
form.append("
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
246
|
+
const fileBuffer = await readFile(options.filePath);
|
|
247
|
+
const buildForm = () => {
|
|
248
|
+
const form = new FormData();
|
|
249
|
+
form.append("attachment", fileBuffer, fileName);
|
|
250
|
+
form.append("name", fileName);
|
|
251
|
+
form.append("chatGuid", options.chatGuid);
|
|
252
|
+
form.append("isSticker", "true");
|
|
253
|
+
form.append("method", "private-api");
|
|
254
|
+
if (options.selectedMessageGuid) {
|
|
255
|
+
form.append("selectedMessageGuid", options.selectedMessageGuid);
|
|
256
|
+
form.append("partIndex", "0");
|
|
257
|
+
form.append("stickerX", String(options.stickerX ?? 0.5));
|
|
258
|
+
form.append("stickerY", String(options.stickerY ?? 0.5));
|
|
259
|
+
form.append("stickerScale", String(options.stickerScale ?? 0.75));
|
|
260
|
+
form.append("stickerRotation", String(options.stickerRotation ?? 0));
|
|
261
|
+
form.append("stickerWidth", String(options.stickerWidth ?? 300));
|
|
262
|
+
}
|
|
263
|
+
return form;
|
|
264
|
+
};
|
|
265
|
+
try {
|
|
266
|
+
const form = buildForm();
|
|
267
|
+
const { data } = await this.http.post("/api/v1/message/attachment", form, {
|
|
268
|
+
headers: form.getHeaders()
|
|
269
|
+
});
|
|
270
|
+
return data.data;
|
|
271
|
+
} catch (error) {
|
|
272
|
+
if (!isChatNotExistError(error)) throw error;
|
|
273
|
+
await this.ensureChatExists(options.chatGuid);
|
|
274
|
+
const form = buildForm();
|
|
275
|
+
const { data } = await this.http.post("/api/v1/message/attachment", form, {
|
|
276
|
+
headers: form.getHeaders()
|
|
277
|
+
});
|
|
278
|
+
return data.data;
|
|
191
279
|
}
|
|
192
|
-
const { data } = await this.http.post("/api/v1/message/attachment", form, {
|
|
193
|
-
headers: form.getHeaders()
|
|
194
|
-
});
|
|
195
|
-
return data.data;
|
|
196
280
|
});
|
|
197
281
|
}
|
|
198
282
|
};
|
|
@@ -237,8 +321,8 @@ var ChatModule = class {
|
|
|
237
321
|
return response.data.data;
|
|
238
322
|
}
|
|
239
323
|
async removeParticipant(chatGuid, address) {
|
|
240
|
-
const response = await this.http.
|
|
241
|
-
|
|
324
|
+
const response = await this.http.post(`/api/v1/chat/${encodeURIComponent(chatGuid)}/participant/remove`, {
|
|
325
|
+
address
|
|
242
326
|
});
|
|
243
327
|
return response.data.data;
|
|
244
328
|
}
|
|
@@ -380,7 +464,16 @@ var ICloudModule = class {
|
|
|
380
464
|
return response.data.data;
|
|
381
465
|
}
|
|
382
466
|
async refreshFindMyFriends() {
|
|
383
|
-
await this.http.post("/api/v1/icloud/findmy/friends/refresh");
|
|
467
|
+
const response = await this.http.post("/api/v1/icloud/findmy/friends/refresh");
|
|
468
|
+
return response.data.data;
|
|
469
|
+
}
|
|
470
|
+
async getLocationForHandle(handle) {
|
|
471
|
+
const friends = await this.getFindMyFriends();
|
|
472
|
+
return friends.find((f) => f.handle === handle) ?? null;
|
|
473
|
+
}
|
|
474
|
+
async isHandleSharingLocation(handle) {
|
|
475
|
+
const location = await this.getLocationForHandle(handle);
|
|
476
|
+
return location !== null;
|
|
384
477
|
}
|
|
385
478
|
};
|
|
386
479
|
var MessageModule = class {
|
|
@@ -392,8 +485,25 @@ var MessageModule = class {
|
|
|
392
485
|
return this.enqueueSend(async () => {
|
|
393
486
|
const tempGuid = options.tempGuid || randomUUID();
|
|
394
487
|
const payload = { ...options, tempGuid };
|
|
395
|
-
|
|
396
|
-
|
|
488
|
+
try {
|
|
489
|
+
const response = await this.http.post("/api/v1/message/text", payload);
|
|
490
|
+
return response.data.data;
|
|
491
|
+
} catch (error) {
|
|
492
|
+
if (!isChatNotExistError(error)) throw error;
|
|
493
|
+
const address = extractAddress(options.chatGuid);
|
|
494
|
+
if (!address) throw error;
|
|
495
|
+
const service = extractService(options.chatGuid);
|
|
496
|
+
await createChatWithMessage({
|
|
497
|
+
http: this.http,
|
|
498
|
+
address,
|
|
499
|
+
message: options.message,
|
|
500
|
+
tempGuid,
|
|
501
|
+
subject: options.subject,
|
|
502
|
+
effectId: options.effectId,
|
|
503
|
+
service
|
|
504
|
+
});
|
|
505
|
+
return { guid: tempGuid, text: options.message, dateCreated: Date.now() };
|
|
506
|
+
}
|
|
397
507
|
});
|
|
398
508
|
}
|
|
399
509
|
async getMessage(guid, options) {
|