fb-messenger-e2ee 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -245,6 +245,37 @@ interface SendMediaInput {
245
245
  /** Whether E2EE audio should be sent as push-to-talk/voice. Defaults to true for sendAudio. */
246
246
  ptt?: boolean;
247
247
  }
248
+ /** A single attachment item inside a multi-attachment message. */
249
+ interface SendAttachmentItem {
250
+ data: Buffer;
251
+ fileName: string;
252
+ /** Optional MIME type; inferred from fileName extension when omitted. */
253
+ mimeType?: string;
254
+ /** Optional width/height for image or video payloads. */
255
+ width?: number;
256
+ height?: number;
257
+ /** Optional duration in seconds for video/audio payloads. */
258
+ seconds?: number;
259
+ /** Whether audio should be sent as push-to-talk/voice. */
260
+ ptt?: boolean;
261
+ }
262
+ /**
263
+ * Send multiple attachments in a single Messenger message.
264
+ *
265
+ * - **Non-E2EE threads**: All attachments are bundled into one FCA message,
266
+ * delivered as a multi-attachment post.
267
+ * - **E2EE threads**: Each attachment is sent as a separate encrypted E2EE
268
+ * media message (the protocol does not support multi-attachment in one
269
+ * encrypted frame), so `results` will contain one entry per attachment.
270
+ */
271
+ interface SendMultipleMediaInput {
272
+ threadId: string;
273
+ /** Array of file attachments to send. At least one entry is required. */
274
+ attachments: SendAttachmentItem[];
275
+ /** Optional caption applied to the first attachment (or to the bundled non-E2EE message). */
276
+ caption?: string;
277
+ replyToMessageId?: string;
278
+ }
248
279
  interface TypingInput {
249
280
  threadId: string;
250
281
  isTyping: boolean;
@@ -345,6 +376,15 @@ declare class FBClient {
345
376
  sendVideo(input: SendMediaInput): Promise<Record<string, unknown>>;
346
377
  sendAudio(input: SendMediaInput): Promise<Record<string, unknown>>;
347
378
  sendFile(input: SendMediaInput): Promise<Record<string, unknown>>;
379
+ /**
380
+ * Send multiple files/attachments in one call.
381
+ *
382
+ * - **Non-E2EE threads**: All attachments land in a single Messenger message.
383
+ * - **E2EE threads**: Each attachment is sent as a separate encrypted message
384
+ * (E2EE does not support multi-attachment in one frame). Returns an array
385
+ * with one result per attachment.
386
+ */
387
+ sendFiles(input: SendMultipleMediaInput): Promise<Record<string, unknown> | Record<string, unknown>[]>;
348
388
  }
349
389
 
350
390
  interface EncryptMediaResult {
@@ -907,4 +947,4 @@ interface AuthConfig {
907
947
  platform: Platform;
908
948
  }
909
949
 
910
- export { type AppEnv, type Attachment, type AuthConfig, type ClientOptions, type E2EEDecryptMediaOptions, type E2EEDownloadOptions, type E2EEDownloadResult, type E2EEEditMessageInput, type E2EEEncryptMediaOptions, type E2EEEncryptMediaResult, type E2EEMessage, type E2EEMessageKind, type E2EESendTextOptions, type E2EESendTextResult, E2EEService, FBClient, type MediaUploadConfig, type MediaUploadResult, type Mention, type MessengerEvent, type MessengerEventMap, type MmsTypeStr, type Platform, type ReplyTo, type SendMediaInput, type SendMessageInput, type SendReactionInput, type SessionData, type TypingInput, type UnsendMessageInput };
950
+ export { type AppEnv, type Attachment, type AuthConfig, type ClientOptions, type E2EEDecryptMediaOptions, type E2EEDownloadOptions, type E2EEDownloadResult, type E2EEEditMessageInput, type E2EEEncryptMediaOptions, type E2EEEncryptMediaResult, type E2EEMessage, type E2EEMessageKind, type E2EESendTextOptions, type E2EESendTextResult, E2EEService, FBClient, type MediaUploadConfig, type MediaUploadResult, type Mention, type MessengerEvent, type MessengerEventMap, type MmsTypeStr, type Platform, type ReplyTo, type SendAttachmentItem, type SendMediaInput, type SendMessageInput, type SendMultipleMediaInput, type SendReactionInput, type SessionData, type TypingInput, type UnsendMessageInput };
package/dist/index.d.ts CHANGED
@@ -245,6 +245,37 @@ interface SendMediaInput {
245
245
  /** Whether E2EE audio should be sent as push-to-talk/voice. Defaults to true for sendAudio. */
246
246
  ptt?: boolean;
247
247
  }
248
+ /** A single attachment item inside a multi-attachment message. */
249
+ interface SendAttachmentItem {
250
+ data: Buffer;
251
+ fileName: string;
252
+ /** Optional MIME type; inferred from fileName extension when omitted. */
253
+ mimeType?: string;
254
+ /** Optional width/height for image or video payloads. */
255
+ width?: number;
256
+ height?: number;
257
+ /** Optional duration in seconds for video/audio payloads. */
258
+ seconds?: number;
259
+ /** Whether audio should be sent as push-to-talk/voice. */
260
+ ptt?: boolean;
261
+ }
262
+ /**
263
+ * Send multiple attachments in a single Messenger message.
264
+ *
265
+ * - **Non-E2EE threads**: All attachments are bundled into one FCA message,
266
+ * delivered as a multi-attachment post.
267
+ * - **E2EE threads**: Each attachment is sent as a separate encrypted E2EE
268
+ * media message (the protocol does not support multi-attachment in one
269
+ * encrypted frame), so `results` will contain one entry per attachment.
270
+ */
271
+ interface SendMultipleMediaInput {
272
+ threadId: string;
273
+ /** Array of file attachments to send. At least one entry is required. */
274
+ attachments: SendAttachmentItem[];
275
+ /** Optional caption applied to the first attachment (or to the bundled non-E2EE message). */
276
+ caption?: string;
277
+ replyToMessageId?: string;
278
+ }
248
279
  interface TypingInput {
249
280
  threadId: string;
250
281
  isTyping: boolean;
@@ -345,6 +376,15 @@ declare class FBClient {
345
376
  sendVideo(input: SendMediaInput): Promise<Record<string, unknown>>;
346
377
  sendAudio(input: SendMediaInput): Promise<Record<string, unknown>>;
347
378
  sendFile(input: SendMediaInput): Promise<Record<string, unknown>>;
379
+ /**
380
+ * Send multiple files/attachments in one call.
381
+ *
382
+ * - **Non-E2EE threads**: All attachments land in a single Messenger message.
383
+ * - **E2EE threads**: Each attachment is sent as a separate encrypted message
384
+ * (E2EE does not support multi-attachment in one frame). Returns an array
385
+ * with one result per attachment.
386
+ */
387
+ sendFiles(input: SendMultipleMediaInput): Promise<Record<string, unknown> | Record<string, unknown>[]>;
348
388
  }
349
389
 
350
390
  interface EncryptMediaResult {
@@ -907,4 +947,4 @@ interface AuthConfig {
907
947
  platform: Platform;
908
948
  }
909
949
 
910
- export { type AppEnv, type Attachment, type AuthConfig, type ClientOptions, type E2EEDecryptMediaOptions, type E2EEDownloadOptions, type E2EEDownloadResult, type E2EEEditMessageInput, type E2EEEncryptMediaOptions, type E2EEEncryptMediaResult, type E2EEMessage, type E2EEMessageKind, type E2EESendTextOptions, type E2EESendTextResult, E2EEService, FBClient, type MediaUploadConfig, type MediaUploadResult, type Mention, type MessengerEvent, type MessengerEventMap, type MmsTypeStr, type Platform, type ReplyTo, type SendMediaInput, type SendMessageInput, type SendReactionInput, type SessionData, type TypingInput, type UnsendMessageInput };
950
+ export { type AppEnv, type Attachment, type AuthConfig, type ClientOptions, type E2EEDecryptMediaOptions, type E2EEDownloadOptions, type E2EEDownloadResult, type E2EEEditMessageInput, type E2EEEncryptMediaOptions, type E2EEEncryptMediaResult, type E2EEMessage, type E2EEMessageKind, type E2EESendTextOptions, type E2EESendTextResult, E2EEService, FBClient, type MediaUploadConfig, type MediaUploadResult, type Mention, type MessengerEvent, type MessengerEventMap, type MmsTypeStr, type Platform, type ReplyTo, type SendAttachmentItem, type SendMediaInput, type SendMessageInput, type SendMultipleMediaInput, type SendReactionInput, type SessionData, type TypingInput, type UnsendMessageInput };
package/dist/index.js CHANGED
@@ -3465,6 +3465,30 @@ var FacebookGatewayService = class {
3465
3465
  );
3466
3466
  return response ?? {};
3467
3467
  }
3468
+ /**
3469
+ * Send multiple attachments in a single FCA message.
3470
+ * FCA-unofficial accepts an array in `attachment` field, which bundles all
3471
+ * files into one Messenger message on the wire.
3472
+ */
3473
+ async sendMultipleAttachmentsMessage(api, input) {
3474
+ if (input.attachments.length === 0) {
3475
+ throw new Error("sendMultipleAttachmentsMessage requires at least one attachment");
3476
+ }
3477
+ const streams = input.attachments.map(({ data, fileName }) => {
3478
+ const stream = Readable.from(data);
3479
+ Object.assign(stream, { path: fileName });
3480
+ return stream;
3481
+ });
3482
+ const payload = {
3483
+ body: input.caption ?? "",
3484
+ // FCA-unofficial accepts a single Readable or an array of Readables
3485
+ attachment: streams.length === 1 ? streams[0] : streams
3486
+ };
3487
+ const response = await Promise.resolve(
3488
+ api.sendMessage(payload, input.threadId, void 0, input.replyToMessageId)
3489
+ );
3490
+ return response ?? {};
3491
+ }
3468
3492
  async sendReaction(api, messageId, reaction) {
3469
3493
  if (!api.setMessageReaction) {
3470
3494
  throw new Error("setMessageReaction is not available in fca-unofficial");
@@ -3641,6 +3665,13 @@ var MediaService = class {
3641
3665
  replyToMessageId: input.replyToMessageId
3642
3666
  });
3643
3667
  }
3668
+ /**
3669
+ * Send multiple attachments bundled into a single FCA message.
3670
+ * Non-E2EE only — for E2EE threads use the controller which sends them sequentially.
3671
+ */
3672
+ async sendFiles(api, input) {
3673
+ return this.gateway.sendMultipleAttachmentsMessage(api, input);
3674
+ }
3644
3675
  async sendSticker(api, input) {
3645
3676
  return this.gateway.sendStickerMessage(api, {
3646
3677
  threadId: input.threadId,
@@ -8560,7 +8591,7 @@ var ClientController = class {
8560
8591
  async markAsRead(input) {
8561
8592
  await this.messagingService.markAsRead(this.requireApi(), input);
8562
8593
  }
8563
- // --- E2EE Media Upload Config ---
8594
+ // E2EE Media Upload Config
8564
8595
  async getE2EEMediaUploadConfig() {
8565
8596
  if (this.e2eeUploadConfig && !this.isMediaUploadConfigExpired(this.e2eeUploadConfig)) {
8566
8597
  return this.e2eeUploadConfig;
@@ -8707,6 +8738,62 @@ var ClientController = class {
8707
8738
  }
8708
8739
  return this.mediaService.sendFile(this.requireApi(), input);
8709
8740
  }
8741
+ /**
8742
+ * Send multiple files/attachments.
8743
+ *
8744
+ * - **Non-E2EE threads**: All files are bundled into a single FCA message.
8745
+ * - **E2EE threads**: Files are sent as separate sequential encrypted E2EE
8746
+ * media messages (the protocol does not support multi-attachment in one
8747
+ * encrypted frame). Returns an array with one result per attachment.
8748
+ */
8749
+ async sendFiles(input) {
8750
+ if (input.attachments.length === 0) {
8751
+ throw new Error("sendFiles requires at least one attachment");
8752
+ }
8753
+ if (this.e2eeConnected && this.isE2EEThreadId(input.threadId)) {
8754
+ const results = [];
8755
+ for (let i = 0; i < input.attachments.length; i++) {
8756
+ const att = input.attachments[i];
8757
+ const mediaInput = {
8758
+ threadId: input.threadId,
8759
+ data: att.data,
8760
+ fileName: att.fileName,
8761
+ mimeType: att.mimeType,
8762
+ // Caption on first attachment only
8763
+ caption: i === 0 ? input.caption : void 0,
8764
+ replyToMessageId: i === 0 ? input.replyToMessageId : void 0,
8765
+ width: att.width,
8766
+ height: att.height,
8767
+ seconds: att.seconds,
8768
+ ptt: att.ptt
8769
+ };
8770
+ const mediaType = inferMediaType(att.fileName, att.mimeType);
8771
+ let result;
8772
+ switch (mediaType) {
8773
+ case "image":
8774
+ result = await this.sendE2EEImage(mediaInput);
8775
+ break;
8776
+ case "video":
8777
+ result = await this.sendE2EEVideo(mediaInput);
8778
+ break;
8779
+ case "audio":
8780
+ result = await this.sendE2EEAudio(mediaInput);
8781
+ break;
8782
+ default:
8783
+ result = await this.sendE2EEFile(mediaInput);
8784
+ break;
8785
+ }
8786
+ results.push(result);
8787
+ }
8788
+ return results;
8789
+ }
8790
+ return this.mediaService.sendFiles(this.requireApi(), {
8791
+ threadId: input.threadId,
8792
+ attachments: input.attachments.map((a) => ({ data: a.data, fileName: a.fileName })),
8793
+ caption: input.caption,
8794
+ replyToMessageId: input.replyToMessageId
8795
+ });
8796
+ }
8710
8797
  async sendSticker(input) {
8711
8798
  return this.mediaService.sendSticker(this.requireApi(), input);
8712
8799
  }
@@ -8746,7 +8833,6 @@ var ClientController = class {
8746
8833
  async createPoll(input) {
8747
8834
  await this.threadService.createPoll(this.requireApi(), input);
8748
8835
  }
8749
- // editMessage is now handled by the E2EE-aware method above (routes E2EE → sendE2EEEdit, else → threadService.editMessage).
8750
8836
  async addGroupMember(input) {
8751
8837
  await this.threadService.addGroupMember(this.requireApi(), input);
8752
8838
  }
@@ -8764,6 +8850,17 @@ var ClientController = class {
8764
8850
  return this.api;
8765
8851
  }
8766
8852
  };
8853
+ function inferMediaType(fileName, mimeType) {
8854
+ const mime = (mimeType ?? "").toLowerCase();
8855
+ if (mime.startsWith("image/")) return "image";
8856
+ if (mime.startsWith("video/")) return "video";
8857
+ if (mime.startsWith("audio/")) return "audio";
8858
+ const ext = fileName.split(".").pop()?.toLowerCase() ?? "";
8859
+ if (["jpg", "jpeg", "png", "gif", "webp", "heic", "heif", "bmp"].includes(ext)) return "image";
8860
+ if (["mp4", "mov", "avi", "mkv", "webm", "3gp", "m4v"].includes(ext)) return "video";
8861
+ if (["mp3", "ogg", "aac", "flac", "wav", "m4a", "opus"].includes(ext)) return "audio";
8862
+ return "document";
8863
+ }
8767
8864
 
8768
8865
  // src/repositories/session.repository.ts
8769
8866
  init_esm_shims();
@@ -9025,6 +9122,17 @@ var FBClient = class {
9025
9122
  async sendFile(input) {
9026
9123
  return this.controller.sendFile(input);
9027
9124
  }
9125
+ /**
9126
+ * Send multiple files/attachments in one call.
9127
+ *
9128
+ * - **Non-E2EE threads**: All attachments land in a single Messenger message.
9129
+ * - **E2EE threads**: Each attachment is sent as a separate encrypted message
9130
+ * (E2EE does not support multi-attachment in one frame). Returns an array
9131
+ * with one result per attachment.
9132
+ */
9133
+ async sendFiles(input) {
9134
+ return this.controller.sendFiles(input);
9135
+ }
9028
9136
  };
9029
9137
  export {
9030
9138
  E2EEService,