@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.cjs
CHANGED
|
@@ -134,6 +134,48 @@ var getLogger = (tag) => {
|
|
|
134
134
|
}
|
|
135
135
|
return logger;
|
|
136
136
|
};
|
|
137
|
+
|
|
138
|
+
// lib/auto-create-chat.ts
|
|
139
|
+
function isChatNotExistError(error) {
|
|
140
|
+
const axiosError = error;
|
|
141
|
+
const errorMsg = axiosError?.response?.data?.error?.message || axiosError?.response?.data?.message || "";
|
|
142
|
+
const lowerMsg = errorMsg.toLowerCase();
|
|
143
|
+
return lowerMsg.includes("chat does not exist") || lowerMsg.includes("chat not found");
|
|
144
|
+
}
|
|
145
|
+
function extractAddress(chatGuid) {
|
|
146
|
+
const parts = chatGuid.split(";-;");
|
|
147
|
+
if (parts.length !== 2 || !parts[1]) {
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
return parts[1];
|
|
151
|
+
}
|
|
152
|
+
function extractService(chatGuid) {
|
|
153
|
+
if (!chatGuid) return void 0;
|
|
154
|
+
const prefix = chatGuid.split(";")[0]?.toLowerCase();
|
|
155
|
+
if (prefix === "imessage") return "iMessage";
|
|
156
|
+
if (prefix === "sms") return "SMS";
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
async function createChatWithMessage(options) {
|
|
160
|
+
const { http, address, message, tempGuid, subject, effectId, service } = options;
|
|
161
|
+
try {
|
|
162
|
+
const response = await http.post("/api/v1/chat/new", {
|
|
163
|
+
addresses: [address],
|
|
164
|
+
message,
|
|
165
|
+
tempGuid,
|
|
166
|
+
subject,
|
|
167
|
+
effectId,
|
|
168
|
+
...service && { service }
|
|
169
|
+
});
|
|
170
|
+
return response.data.data?.guid;
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`Failed to create chat with address "${address}": ${error instanceof Error ? error.message : String(error)}`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// modules/attachment.ts
|
|
137
179
|
var AttachmentModule = class {
|
|
138
180
|
constructor(http, enqueueSend = (task) => task()) {
|
|
139
181
|
this.http = http;
|
|
@@ -176,52 +218,94 @@ var AttachmentModule = class {
|
|
|
176
218
|
});
|
|
177
219
|
return response.data.data.blurhash;
|
|
178
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Ensures the chat exists by creating it if it doesn't already exist.
|
|
223
|
+
*/
|
|
224
|
+
async ensureChatExists(chatGuid) {
|
|
225
|
+
const address = extractAddress(chatGuid);
|
|
226
|
+
if (!address) return;
|
|
227
|
+
const service = extractService(chatGuid);
|
|
228
|
+
await this.http.post("/api/v1/chat/new", {
|
|
229
|
+
addresses: [address],
|
|
230
|
+
...service && { service }
|
|
231
|
+
});
|
|
232
|
+
}
|
|
179
233
|
async sendAttachment(options) {
|
|
180
234
|
return this.enqueueSend(async () => {
|
|
181
235
|
const fileBuffer = await promises.readFile(options.filePath);
|
|
182
236
|
const fileName = options.fileName || path__namespace.default.basename(options.filePath);
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
form.append("
|
|
190
|
-
if (options.isAudioMessage) {
|
|
191
|
-
form.append("
|
|
237
|
+
const tempGuid = crypto.randomUUID();
|
|
238
|
+
const buildForm = () => {
|
|
239
|
+
const form = new FormData__default.default();
|
|
240
|
+
form.append("chatGuid", options.chatGuid);
|
|
241
|
+
form.append("attachment", fileBuffer, fileName);
|
|
242
|
+
form.append("name", fileName);
|
|
243
|
+
form.append("tempGuid", tempGuid);
|
|
244
|
+
if (options.isAudioMessage !== void 0) {
|
|
245
|
+
form.append("isAudioMessage", options.isAudioMessage.toString());
|
|
246
|
+
if (options.isAudioMessage) {
|
|
247
|
+
form.append("method", "private-api");
|
|
248
|
+
}
|
|
192
249
|
}
|
|
250
|
+
if (options.selectedMessageGuid) {
|
|
251
|
+
form.append("selectedMessageGuid", options.selectedMessageGuid);
|
|
252
|
+
}
|
|
253
|
+
return form;
|
|
254
|
+
};
|
|
255
|
+
try {
|
|
256
|
+
const form = buildForm();
|
|
257
|
+
const response = await this.http.post("/api/v1/message/attachment", form, {
|
|
258
|
+
headers: form.getHeaders()
|
|
259
|
+
});
|
|
260
|
+
return response.data.data;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (!isChatNotExistError(error)) throw error;
|
|
263
|
+
await this.ensureChatExists(options.chatGuid);
|
|
264
|
+
const form = buildForm();
|
|
265
|
+
const response = await this.http.post("/api/v1/message/attachment", form, {
|
|
266
|
+
headers: form.getHeaders()
|
|
267
|
+
});
|
|
268
|
+
return response.data.data;
|
|
193
269
|
}
|
|
194
|
-
if (options.selectedMessageGuid) {
|
|
195
|
-
form.append("selectedMessageGuid", options.selectedMessageGuid);
|
|
196
|
-
}
|
|
197
|
-
const response = await this.http.post("/api/v1/message/attachment", form, {
|
|
198
|
-
headers: form.getHeaders()
|
|
199
|
-
});
|
|
200
|
-
return response.data.data;
|
|
201
270
|
});
|
|
202
271
|
}
|
|
203
272
|
async sendSticker(options) {
|
|
204
273
|
return this.enqueueSend(async () => {
|
|
205
274
|
const fileName = options.fileName || path__namespace.default.basename(options.filePath);
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
form.append("
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
275
|
+
const fileBuffer = await promises.readFile(options.filePath);
|
|
276
|
+
const buildForm = () => {
|
|
277
|
+
const form = new FormData__default.default();
|
|
278
|
+
form.append("attachment", fileBuffer, fileName);
|
|
279
|
+
form.append("name", fileName);
|
|
280
|
+
form.append("chatGuid", options.chatGuid);
|
|
281
|
+
form.append("isSticker", "true");
|
|
282
|
+
form.append("method", "private-api");
|
|
283
|
+
if (options.selectedMessageGuid) {
|
|
284
|
+
form.append("selectedMessageGuid", options.selectedMessageGuid);
|
|
285
|
+
form.append("partIndex", "0");
|
|
286
|
+
form.append("stickerX", String(options.stickerX ?? 0.5));
|
|
287
|
+
form.append("stickerY", String(options.stickerY ?? 0.5));
|
|
288
|
+
form.append("stickerScale", String(options.stickerScale ?? 0.75));
|
|
289
|
+
form.append("stickerRotation", String(options.stickerRotation ?? 0));
|
|
290
|
+
form.append("stickerWidth", String(options.stickerWidth ?? 300));
|
|
291
|
+
}
|
|
292
|
+
return form;
|
|
293
|
+
};
|
|
294
|
+
try {
|
|
295
|
+
const form = buildForm();
|
|
296
|
+
const { data } = await this.http.post("/api/v1/message/attachment", form, {
|
|
297
|
+
headers: form.getHeaders()
|
|
298
|
+
});
|
|
299
|
+
return data.data;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if (!isChatNotExistError(error)) throw error;
|
|
302
|
+
await this.ensureChatExists(options.chatGuid);
|
|
303
|
+
const form = buildForm();
|
|
304
|
+
const { data } = await this.http.post("/api/v1/message/attachment", form, {
|
|
305
|
+
headers: form.getHeaders()
|
|
306
|
+
});
|
|
307
|
+
return data.data;
|
|
220
308
|
}
|
|
221
|
-
const { data } = await this.http.post("/api/v1/message/attachment", form, {
|
|
222
|
-
headers: form.getHeaders()
|
|
223
|
-
});
|
|
224
|
-
return data.data;
|
|
225
309
|
});
|
|
226
310
|
}
|
|
227
311
|
};
|
|
@@ -266,8 +350,8 @@ var ChatModule = class {
|
|
|
266
350
|
return response.data.data;
|
|
267
351
|
}
|
|
268
352
|
async removeParticipant(chatGuid, address) {
|
|
269
|
-
const response = await this.http.
|
|
270
|
-
|
|
353
|
+
const response = await this.http.post(`/api/v1/chat/${encodeURIComponent(chatGuid)}/participant/remove`, {
|
|
354
|
+
address
|
|
271
355
|
});
|
|
272
356
|
return response.data.data;
|
|
273
357
|
}
|
|
@@ -409,7 +493,16 @@ var ICloudModule = class {
|
|
|
409
493
|
return response.data.data;
|
|
410
494
|
}
|
|
411
495
|
async refreshFindMyFriends() {
|
|
412
|
-
await this.http.post("/api/v1/icloud/findmy/friends/refresh");
|
|
496
|
+
const response = await this.http.post("/api/v1/icloud/findmy/friends/refresh");
|
|
497
|
+
return response.data.data;
|
|
498
|
+
}
|
|
499
|
+
async getLocationForHandle(handle) {
|
|
500
|
+
const friends = await this.getFindMyFriends();
|
|
501
|
+
return friends.find((f) => f.handle === handle) ?? null;
|
|
502
|
+
}
|
|
503
|
+
async isHandleSharingLocation(handle) {
|
|
504
|
+
const location = await this.getLocationForHandle(handle);
|
|
505
|
+
return location !== null;
|
|
413
506
|
}
|
|
414
507
|
};
|
|
415
508
|
var MessageModule = class {
|
|
@@ -421,8 +514,25 @@ var MessageModule = class {
|
|
|
421
514
|
return this.enqueueSend(async () => {
|
|
422
515
|
const tempGuid = options.tempGuid || crypto.randomUUID();
|
|
423
516
|
const payload = { ...options, tempGuid };
|
|
424
|
-
|
|
425
|
-
|
|
517
|
+
try {
|
|
518
|
+
const response = await this.http.post("/api/v1/message/text", payload);
|
|
519
|
+
return response.data.data;
|
|
520
|
+
} catch (error) {
|
|
521
|
+
if (!isChatNotExistError(error)) throw error;
|
|
522
|
+
const address = extractAddress(options.chatGuid);
|
|
523
|
+
if (!address) throw error;
|
|
524
|
+
const service = extractService(options.chatGuid);
|
|
525
|
+
await createChatWithMessage({
|
|
526
|
+
http: this.http,
|
|
527
|
+
address,
|
|
528
|
+
message: options.message,
|
|
529
|
+
tempGuid,
|
|
530
|
+
subject: options.subject,
|
|
531
|
+
effectId: options.effectId,
|
|
532
|
+
service
|
|
533
|
+
});
|
|
534
|
+
return { guid: tempGuid, text: options.message, dateCreated: Date.now() };
|
|
535
|
+
}
|
|
426
536
|
});
|
|
427
537
|
}
|
|
428
538
|
async getMessage(guid, options) {
|