bb-fca 2.0.9 → 2.0.11
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/deltas/apis/messaging/editMessage.js +13 -24
- package/dist/deltas/apis/messaging/editMessage.js.map +1 -1
- package/dist/deltas/apis/messaging/emoji.js +34 -88
- package/dist/deltas/apis/messaging/emoji.js.map +1 -1
- package/dist/deltas/apis/messaging/gcmember.js +48 -101
- package/dist/deltas/apis/messaging/gcmember.js.map +1 -1
- package/dist/deltas/apis/messaging/gcname.js +28 -79
- package/dist/deltas/apis/messaging/gcname.js.map +1 -1
- package/dist/deltas/apis/messaging/gcrule.js +47 -105
- package/dist/deltas/apis/messaging/gcrule.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsDelivered.js +10 -12
- package/dist/deltas/apis/messaging/markAsDelivered.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsRead.js +25 -60
- package/dist/deltas/apis/messaging/markAsRead.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsReadAll.js +9 -11
- package/dist/deltas/apis/messaging/markAsReadAll.js.map +1 -1
- package/dist/deltas/apis/messaging/markAsSeen.js +10 -37
- package/dist/deltas/apis/messaging/markAsSeen.js.map +1 -1
- package/dist/deltas/apis/messaging/nickname.js +38 -98
- package/dist/deltas/apis/messaging/nickname.js.map +1 -1
- package/dist/deltas/apis/messaging/notes.js +52 -90
- package/dist/deltas/apis/messaging/notes.js.map +1 -1
- package/dist/deltas/apis/messaging/resolvePhotoUrl.js +17 -42
- package/dist/deltas/apis/messaging/resolvePhotoUrl.js.map +1 -1
- package/dist/deltas/apis/messaging/sendMessage.js +14 -15
- package/dist/deltas/apis/messaging/sendMessage.js.map +1 -1
- package/dist/deltas/apis/messaging/sendTypingIndicator.js +7 -13
- package/dist/deltas/apis/messaging/sendTypingIndicator.js.map +1 -1
- package/dist/deltas/apis/messaging/setMessageReaction.js +24 -14
- package/dist/deltas/apis/messaging/setMessageReaction.js.map +1 -1
- package/dist/deltas/apis/messaging/shareContact.js +14 -12
- package/dist/deltas/apis/messaging/shareContact.js.map +1 -1
- package/dist/deltas/apis/messaging/stickers.js +4 -5
- package/dist/deltas/apis/messaging/stickers.js.map +1 -1
- package/dist/deltas/apis/messaging/theme.js +142 -213
- package/dist/deltas/apis/messaging/theme.js.map +1 -1
- package/dist/deltas/apis/messaging/unsendMessage.js +14 -7
- package/dist/deltas/apis/messaging/unsendMessage.js.map +1 -1
- package/dist/deltas/apis/posting/group.js +440 -11
- package/dist/deltas/apis/posting/group.js.map +1 -1
- package/dist/index.d.ts +18 -0
- package/dist/types/deltas/apis/messaging/editMessage.d.ts +4 -5
- package/dist/types/deltas/apis/messaging/emoji.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/gcmember.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/gcname.d.ts +9 -1
- package/dist/types/deltas/apis/messaging/gcrule.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/markAsDelivered.d.ts +1 -2
- package/dist/types/deltas/apis/messaging/markAsRead.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/markAsReadAll.d.ts +1 -2
- package/dist/types/deltas/apis/messaging/markAsSeen.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/nickname.d.ts +7 -1
- package/dist/types/deltas/apis/messaging/notes.d.ts +13 -11
- package/dist/types/deltas/apis/messaging/resolvePhotoUrl.d.ts +4 -6
- package/dist/types/deltas/apis/messaging/sendMessage.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/sendTypingIndicator.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/setMessageReaction.d.ts +6 -1
- package/dist/types/deltas/apis/messaging/shareContact.d.ts +1 -2
- package/dist/types/deltas/apis/messaging/stickers.d.ts +1 -1
- package/dist/types/deltas/apis/messaging/theme.d.ts +8 -1
- package/dist/types/deltas/apis/messaging/unsendMessage.d.ts +6 -1
- package/dist/types/deltas/apis/posting/group.d.ts +88 -0
- package/package.json +1 -1
- package/src/deltas/apis/messaging/editMessage.ts +16 -26
- package/src/deltas/apis/messaging/emoji.ts +45 -97
- package/src/deltas/apis/messaging/gcmember.ts +68 -113
- package/src/deltas/apis/messaging/gcname.ts +42 -91
- package/src/deltas/apis/messaging/gcrule.ts +61 -111
- package/src/deltas/apis/messaging/markAsDelivered.ts +19 -14
- package/src/deltas/apis/messaging/markAsRead.ts +45 -72
- package/src/deltas/apis/messaging/markAsReadAll.ts +17 -17
- package/src/deltas/apis/messaging/markAsSeen.ts +17 -41
- package/src/deltas/apis/messaging/nickname.ts +50 -116
- package/src/deltas/apis/messaging/notes.ts +59 -95
- package/src/deltas/apis/messaging/resolvePhotoUrl.ts +27 -50
- package/src/deltas/apis/messaging/sendMessage.ts +28 -26
- package/src/deltas/apis/messaging/sendTypingIndicator.ts +13 -12
- package/src/deltas/apis/messaging/setMessageReaction.ts +45 -20
- package/src/deltas/apis/messaging/shareContact.ts +25 -15
- package/src/deltas/apis/messaging/stickers.ts +4 -4
- package/src/deltas/apis/messaging/theme.ts +172 -259
- package/src/deltas/apis/messaging/unsendMessage.ts +23 -7
- package/src/deltas/apis/posting/group.ts +516 -11
- package/src/types/index.d.ts +18 -0
- package/request.txt +0 -60
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
1
2
|
import utils = require('../../../utils');
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -280,18 +281,31 @@ export default function (defaultFuncs: any, api: any, ctx: any) {
|
|
|
280
281
|
if (!groupID) throw new Error('groupID is required.');
|
|
281
282
|
|
|
282
283
|
const variables = {
|
|
284
|
+
feedType: 'DISCUSSION',
|
|
285
|
+
groupID: groupID,
|
|
283
286
|
input: {
|
|
284
|
-
|
|
285
|
-
group_share_tracking_params: null,
|
|
286
|
-
join_action_source: 'GROUP_HEADER',
|
|
287
|
+
action_source: 'GROUP_MALL',
|
|
287
288
|
attribution_id_v2:
|
|
288
|
-
'
|
|
289
|
+
'CometGroupDiscussionRoot.react,comet.group,via_cold_start,' +
|
|
289
290
|
Date.now() +
|
|
290
|
-
'
|
|
291
|
+
',4531,2361831622,,',
|
|
292
|
+
group_id: groupID,
|
|
293
|
+
group_share_tracking_params: {
|
|
294
|
+
app_id: '2220391788200892',
|
|
295
|
+
exp_id: 'null',
|
|
296
|
+
is_from_share: false,
|
|
297
|
+
},
|
|
291
298
|
actor_id: ctx.userID,
|
|
292
299
|
client_mutation_id: Math.floor(Math.random() * 10 + 1).toString(),
|
|
293
300
|
},
|
|
301
|
+
inviteShortLinkKey: null,
|
|
302
|
+
isChainingRecommendationUnit: false,
|
|
294
303
|
scale: 1,
|
|
304
|
+
source: 'GROUP_MALL',
|
|
305
|
+
renderLocation: 'group_mall',
|
|
306
|
+
__relay_internal__pv__groups_comet_use_glvrelayprovider: false,
|
|
307
|
+
__relay_internal__pv__GroupsCometGYSJUnifiedUnitCardImageHeightrelayprovider: 150,
|
|
308
|
+
__relay_internal__pv__GroupsCometGroupChatLazyLoadLastMessageSnippetrelayprovider: false,
|
|
295
309
|
};
|
|
296
310
|
|
|
297
311
|
const form = {
|
|
@@ -302,20 +316,32 @@ export default function (defaultFuncs: any, api: any, ctx: any) {
|
|
|
302
316
|
jazoest: ctx.jazoest,
|
|
303
317
|
lsd: ctx.lsd,
|
|
304
318
|
fb_api_caller_class: 'RelayModern',
|
|
305
|
-
fb_api_req_friendly_name: '
|
|
319
|
+
fb_api_req_friendly_name: 'GroupCometJoinForumMutation',
|
|
306
320
|
variables: JSON.stringify(variables),
|
|
307
|
-
|
|
321
|
+
server_timestamps: 'true',
|
|
322
|
+
doc_id: '34675727242073813',
|
|
308
323
|
};
|
|
309
324
|
|
|
310
|
-
const
|
|
325
|
+
const customHeader = {
|
|
326
|
+
'x-fb-friendly-name': 'GroupCometJoinForumMutation',
|
|
327
|
+
'x-fb-lsd': ctx.lsd || '',
|
|
328
|
+
'x-asbd-id': '359341',
|
|
329
|
+
origin: 'https://www.facebook.com',
|
|
330
|
+
referer: `https://www.facebook.com/groups/${groupID}`,
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const res = await utils.post(
|
|
311
334
|
'https://www.facebook.com/api/graphql/',
|
|
312
335
|
ctx.jar,
|
|
313
336
|
form,
|
|
314
|
-
|
|
337
|
+
ctx.globalOptions,
|
|
338
|
+
ctx,
|
|
339
|
+
customHeader,
|
|
315
340
|
);
|
|
316
341
|
|
|
317
|
-
|
|
318
|
-
|
|
342
|
+
const data = parseResponseBody(res.body);
|
|
343
|
+
if (data?.errors) throw new Error(JSON.stringify(data.errors));
|
|
344
|
+
return data?.data ?? data;
|
|
319
345
|
},
|
|
320
346
|
|
|
321
347
|
/**
|
|
@@ -607,6 +633,485 @@ export default function (defaultFuncs: any, api: any, ctx: any) {
|
|
|
607
633
|
hasNextPage: Boolean(pageInfo.has_next_page),
|
|
608
634
|
};
|
|
609
635
|
},
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Resolves a Facebook share URL to the actual group ID.
|
|
639
|
+
*
|
|
640
|
+
* Accepts various formats:
|
|
641
|
+
* - Full URL: `https://www.facebook.com/share/g/14bKqsywAfu/`
|
|
642
|
+
* - Path only: `/share/g/14bKqsywAfu/`
|
|
643
|
+
* - Short key: `14bKqsywAfu`
|
|
644
|
+
*
|
|
645
|
+
* @param {string} shareUrl The share URL, path, or short key to resolve.
|
|
646
|
+
* @returns {Promise<{ groupID: string; name: string | null; url: string | null }>}
|
|
647
|
+
* The resolved group ID, name (if available), and canonical URL.
|
|
648
|
+
* @throws {Error} If the shareUrl is missing or the group ID cannot be extracted.
|
|
649
|
+
*
|
|
650
|
+
* @example
|
|
651
|
+
* const result = await api.group.resolveShareUrl('https://www.facebook.com/share/g/14bKqsywAfu/');
|
|
652
|
+
* console.log(result.groupID); // "1482314963016056"
|
|
653
|
+
*/
|
|
654
|
+
resolveShareUrl: async function (
|
|
655
|
+
shareUrl: string,
|
|
656
|
+
): Promise<{ groupID: string; name: string | null; url: string | null }> {
|
|
657
|
+
if (!shareUrl || typeof shareUrl !== 'string') {
|
|
658
|
+
throw new Error(
|
|
659
|
+
'resolveShareUrl: shareUrl must be a non-empty string.',
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// Normalize input to a full URL
|
|
664
|
+
let fullUrl: string;
|
|
665
|
+
if (shareUrl.startsWith('http://') || shareUrl.startsWith('https://')) {
|
|
666
|
+
fullUrl = shareUrl;
|
|
667
|
+
} else if (shareUrl.startsWith('/')) {
|
|
668
|
+
fullUrl = 'https://www.facebook.com' + shareUrl;
|
|
669
|
+
} else {
|
|
670
|
+
// Assume it's just the short key
|
|
671
|
+
fullUrl = `https://www.facebook.com/share/g/${shareUrl}/`;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// Fetch the share page - Facebook will embed the group data in the HTML
|
|
675
|
+
const allJsonData = await utils.json(
|
|
676
|
+
fullUrl,
|
|
677
|
+
ctx.jar,
|
|
678
|
+
null,
|
|
679
|
+
ctx.globalOptions,
|
|
680
|
+
ctx,
|
|
681
|
+
);
|
|
682
|
+
|
|
683
|
+
if (!allJsonData || allJsonData.length === 0) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
'resolveShareUrl: Could not fetch data from the share URL.',
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// Strategy 1: Look for group object with __typename "Group" in the JSON data
|
|
690
|
+
let groupID: string | null = null;
|
|
691
|
+
let groupName: string | null = null;
|
|
692
|
+
let groupUrl: string | null = null;
|
|
693
|
+
|
|
694
|
+
const groupObj = deepFind(
|
|
695
|
+
allJsonData,
|
|
696
|
+
(val, _key) =>
|
|
697
|
+
val &&
|
|
698
|
+
typeof val === 'object' &&
|
|
699
|
+
val.__typename === 'Group' &&
|
|
700
|
+
typeof val.id === 'string',
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
if (groupObj) {
|
|
704
|
+
groupID = groupObj.id;
|
|
705
|
+
groupName = groupObj.name || null;
|
|
706
|
+
groupUrl = groupObj.url || null;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
// Strategy 2: Look for groupID in various data patterns
|
|
710
|
+
if (!groupID) {
|
|
711
|
+
const groupIdVal = deepFind(
|
|
712
|
+
allJsonData,
|
|
713
|
+
(val, key) =>
|
|
714
|
+
(key === 'groupID' || key === 'group_id') &&
|
|
715
|
+
typeof val === 'string' &&
|
|
716
|
+
/^\d+$/.test(val),
|
|
717
|
+
);
|
|
718
|
+
if (groupIdVal) {
|
|
719
|
+
groupID = groupIdVal;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// Strategy 3: Look for meta property og:url or al:android:url containing group ID
|
|
724
|
+
if (!groupID) {
|
|
725
|
+
// Try to find the raw HTML response from the GET request
|
|
726
|
+
const res = await utils.get(
|
|
727
|
+
fullUrl,
|
|
728
|
+
ctx.jar,
|
|
729
|
+
null,
|
|
730
|
+
ctx.globalOptions,
|
|
731
|
+
ctx,
|
|
732
|
+
);
|
|
733
|
+
const html = typeof res.body === 'string' ? res.body : String(res.body);
|
|
734
|
+
|
|
735
|
+
// Try og:url meta tag: <meta property="og:url" content="https://www.facebook.com/groups/XXXXXXX/" />
|
|
736
|
+
const ogUrlMatch = html.match(
|
|
737
|
+
/property="og:url"\s+content="[^"]*\/groups\/(\d+)/,
|
|
738
|
+
);
|
|
739
|
+
if (ogUrlMatch) {
|
|
740
|
+
groupID = ogUrlMatch[1];
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// Try al:android:url: fb://group/XXXXXXX
|
|
744
|
+
if (!groupID) {
|
|
745
|
+
const androidUrlMatch = html.match(
|
|
746
|
+
/property="al:android:url"\s+content="fb:\/\/group\/(\d+)"/,
|
|
747
|
+
);
|
|
748
|
+
if (androidUrlMatch) {
|
|
749
|
+
groupID = androidUrlMatch[1];
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// Try entity_id pattern in the HTML
|
|
754
|
+
if (!groupID) {
|
|
755
|
+
const entityIdMatch = html.match(/"entity_id":"(\d+)"/);
|
|
756
|
+
if (entityIdMatch) {
|
|
757
|
+
groupID = entityIdMatch[1];
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// Try groupID in the URL of the final redirect
|
|
762
|
+
if (!groupID) {
|
|
763
|
+
const groupUrlMatch = html.match(
|
|
764
|
+
/facebook\.com\/groups\/(\d+)/,
|
|
765
|
+
);
|
|
766
|
+
if (groupUrlMatch) {
|
|
767
|
+
groupID = groupUrlMatch[1];
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// Extract group name from og:title if available
|
|
772
|
+
if (!groupName) {
|
|
773
|
+
const ogTitleMatch = html.match(
|
|
774
|
+
/property="og:title"\s+content="([^"]*)"/,
|
|
775
|
+
);
|
|
776
|
+
if (ogTitleMatch) {
|
|
777
|
+
groupName = ogTitleMatch[1];
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
if (!groupID) {
|
|
783
|
+
throw new Error(
|
|
784
|
+
'resolveShareUrl: Could not extract group ID from the share URL. ' +
|
|
785
|
+
'The link may be invalid, expired, or require authentication.',
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
if (!groupUrl) {
|
|
790
|
+
groupUrl = `https://www.facebook.com/groups/${groupID}/`;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return {
|
|
794
|
+
groupID,
|
|
795
|
+
name: groupName,
|
|
796
|
+
url: groupUrl,
|
|
797
|
+
};
|
|
798
|
+
},
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Uploads a photo to Facebook for use in group posts.
|
|
802
|
+
*
|
|
803
|
+
* The photo is uploaded to `upload.facebook.com` with the group discussion
|
|
804
|
+
* route context (`CometGroupDiscussionRoute`), making it ready to be
|
|
805
|
+
* attached to a group post via {@link createGroupPost}.
|
|
806
|
+
*
|
|
807
|
+
* @param {string | string[]} photoPaths - A single file path or an array of file paths to upload.
|
|
808
|
+
* @returns {Promise<{ photoID: string; uploadID: string; data: any }[]>}
|
|
809
|
+
* Array of upload results, one per photo, each containing:
|
|
810
|
+
* - `photoID` – The Facebook-assigned photo ID (use in `createGroupPost`).
|
|
811
|
+
* - `uploadID` – The client-generated upload ID.
|
|
812
|
+
* - `data` – The raw server response payload.
|
|
813
|
+
* @throws {Error} If any path is missing, not a string, or doesn't exist on disk.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* const [photo] = await api.group.uploadPhoto('/path/to/image.jpg');
|
|
817
|
+
* const post = await api.group.createGroupPost('123456789', {
|
|
818
|
+
* message: 'Check this out!',
|
|
819
|
+
* photos: [photo.photoID],
|
|
820
|
+
* });
|
|
821
|
+
*/
|
|
822
|
+
uploadPhoto: async function (
|
|
823
|
+
photoPaths: string | string[],
|
|
824
|
+
): Promise<{ photoID: string; uploadID: string; data: any }[]> {
|
|
825
|
+
const paths = Array.isArray(photoPaths) ? photoPaths : [photoPaths];
|
|
826
|
+
|
|
827
|
+
if (paths.length === 0) {
|
|
828
|
+
throw new Error('uploadPhoto: at least one photo path is required.');
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
const results: { photoID: string; uploadID: string; data: any }[] = [];
|
|
832
|
+
|
|
833
|
+
for (const photoPath of paths) {
|
|
834
|
+
if (!photoPath || typeof photoPath !== 'string') {
|
|
835
|
+
throw new Error('uploadPhoto: each photo path must be a non-empty string.');
|
|
836
|
+
}
|
|
837
|
+
if (!fs.existsSync(photoPath)) {
|
|
838
|
+
throw new Error(`uploadPhoto: file not found: ${photoPath}`);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
const photoStream = fs.createReadStream(photoPath);
|
|
842
|
+
|
|
843
|
+
const uploadId = `jsc_c_${Math.random().toString(36).substring(2, 11)}`;
|
|
844
|
+
|
|
845
|
+
// Build URL with query parameters matching the captured request
|
|
846
|
+
const url = new URL(
|
|
847
|
+
'https://upload.facebook.com/ajax/react_composer/attachments/photo/upload',
|
|
848
|
+
);
|
|
849
|
+
url.searchParams.append('av', ctx.userID);
|
|
850
|
+
url.searchParams.append('__aaid', '0');
|
|
851
|
+
url.searchParams.append('__user', ctx.userID);
|
|
852
|
+
url.searchParams.append('__a', '1');
|
|
853
|
+
url.searchParams.append('__req', '1');
|
|
854
|
+
url.searchParams.append('__hs', '20558.HCSV2:comet_pkg.2.1...0');
|
|
855
|
+
url.searchParams.append('dpr', '1');
|
|
856
|
+
url.searchParams.append('__ccg', 'EXCELLENT');
|
|
857
|
+
url.searchParams.append('__comet_req', '15');
|
|
858
|
+
url.searchParams.append('fb_dtsg', ctx.fb_dtsg);
|
|
859
|
+
url.searchParams.append('jazoest', ctx.jazoest);
|
|
860
|
+
url.searchParams.append('lsd', ctx.lsd || ctx.fb_dtsg);
|
|
861
|
+
url.searchParams.append('__spin_r', '1037381017');
|
|
862
|
+
url.searchParams.append('__spin_b', 'trunk');
|
|
863
|
+
url.searchParams.append('__spin_t', Math.floor(Date.now() / 1000).toString());
|
|
864
|
+
url.searchParams.append('__crn', 'comet.fbweb.CometGroupDiscussionRoute');
|
|
865
|
+
|
|
866
|
+
// Multipart form fields
|
|
867
|
+
const form = {
|
|
868
|
+
source: '8',
|
|
869
|
+
profile_id: ctx.userID,
|
|
870
|
+
waterfallxapp: 'comet',
|
|
871
|
+
farr: photoStream,
|
|
872
|
+
upload_id: uploadId,
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
const uploadResponse = await utils.postFormData(
|
|
876
|
+
url.toString(),
|
|
877
|
+
ctx.jar,
|
|
878
|
+
form,
|
|
879
|
+
ctx.globalOptions,
|
|
880
|
+
ctx,
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
const uploadResult = JSON.parse(
|
|
884
|
+
uploadResponse.body.toString().replace(/^for \(;;\);/, ''),
|
|
885
|
+
);
|
|
886
|
+
|
|
887
|
+
if (uploadResult.error || uploadResult.errors) {
|
|
888
|
+
throw new Error(
|
|
889
|
+
JSON.stringify(uploadResult.error || uploadResult.errors),
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
const photoId =
|
|
894
|
+
uploadResult.payload?.fbid ||
|
|
895
|
+
uploadResult.payload?.photoID ||
|
|
896
|
+
null;
|
|
897
|
+
|
|
898
|
+
results.push({
|
|
899
|
+
photoID: photoId,
|
|
900
|
+
uploadID: uploadId,
|
|
901
|
+
data: uploadResult,
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
return results;
|
|
906
|
+
},
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Creates a post in a Facebook group, optionally with photo attachments and a title.
|
|
910
|
+
*
|
|
911
|
+
* @param {string} groupID - The ID of the group to post in.
|
|
912
|
+
* @param {object} options - Post options.
|
|
913
|
+
* @param {string} [options.message=''] - The text content of the post.
|
|
914
|
+
* @param {string} [options.title] - Optional post title (for groups that support titled posts).
|
|
915
|
+
* @param {string[]} [options.photos=[]] - Array of photo IDs from {@link uploadPhoto}.
|
|
916
|
+
* @returns {Promise<{ success: boolean; postID: string | null; url: string | null; data: any }>}
|
|
917
|
+
* @throws {Error} If groupID is missing or the API request fails.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* // Text-only post
|
|
921
|
+
* await api.group.createGroupPost('123456789', { message: 'Hello group!' });
|
|
922
|
+
*
|
|
923
|
+
* // Post with photos
|
|
924
|
+
* const photos = await api.group.uploadPhoto(['/path/a.jpg', '/path/b.jpg']);
|
|
925
|
+
* await api.group.createGroupPost('123456789', {
|
|
926
|
+
* message: 'Check these out!',
|
|
927
|
+
* photos: photos.map(p => p.photoID),
|
|
928
|
+
* });
|
|
929
|
+
*
|
|
930
|
+
* // Post with title and photos
|
|
931
|
+
* await api.group.createGroupPost('123456789', {
|
|
932
|
+
* message: 'Post body here',
|
|
933
|
+
* title: 'My Post Title',
|
|
934
|
+
* photos: photos.map(p => p.photoID),
|
|
935
|
+
* });
|
|
936
|
+
*/
|
|
937
|
+
createGroupPost: async function (
|
|
938
|
+
groupID: string,
|
|
939
|
+
options: { message?: string; title?: string; photos?: string[] } = {},
|
|
940
|
+
): Promise<{
|
|
941
|
+
success: boolean;
|
|
942
|
+
postID: string | null;
|
|
943
|
+
url: string | null;
|
|
944
|
+
data: any;
|
|
945
|
+
}> {
|
|
946
|
+
if (!groupID) throw new Error('createGroupPost: groupID is required.');
|
|
947
|
+
|
|
948
|
+
const postMessage = options.message || '';
|
|
949
|
+
const postTitle = options.title || null;
|
|
950
|
+
const photos = options.photos || [];
|
|
951
|
+
|
|
952
|
+
const composerSessionId = createBsid();
|
|
953
|
+
|
|
954
|
+
const variables: any = {
|
|
955
|
+
input: {
|
|
956
|
+
composer_entry_point: 'inline_composer',
|
|
957
|
+
composer_source_surface: 'group',
|
|
958
|
+
composer_type: 'group',
|
|
959
|
+
logging: {
|
|
960
|
+
composer_session_id: composerSessionId,
|
|
961
|
+
},
|
|
962
|
+
source: 'WWW',
|
|
963
|
+
message: {
|
|
964
|
+
ranges: [],
|
|
965
|
+
text: postMessage,
|
|
966
|
+
},
|
|
967
|
+
with_tags_ids: null,
|
|
968
|
+
inline_activities: [],
|
|
969
|
+
text_format_preset_id: '0',
|
|
970
|
+
group_flair: {
|
|
971
|
+
flair_id: null,
|
|
972
|
+
},
|
|
973
|
+
composed_text: {
|
|
974
|
+
block_data: ['{}'],
|
|
975
|
+
block_depths: [0],
|
|
976
|
+
block_types: [0],
|
|
977
|
+
blocks: [postMessage],
|
|
978
|
+
entities: ['[]'],
|
|
979
|
+
entity_map: '{}',
|
|
980
|
+
inline_styles: ['[]'],
|
|
981
|
+
},
|
|
982
|
+
navigation_data: {
|
|
983
|
+
attribution_id_v2: `CometGroupDiscussionRoot.react,comet.group,tap_bookmark,${Date.now()},352021,${groupID},,`,
|
|
984
|
+
},
|
|
985
|
+
tracking: [null],
|
|
986
|
+
event_share_metadata: {
|
|
987
|
+
surface: 'newsfeed',
|
|
988
|
+
},
|
|
989
|
+
audience: {
|
|
990
|
+
to_id: groupID,
|
|
991
|
+
},
|
|
992
|
+
actor_id: ctx.userID,
|
|
993
|
+
client_mutation_id: Math.floor(Math.random() * 10 + 1).toString(),
|
|
994
|
+
},
|
|
995
|
+
feedLocation: 'GROUP',
|
|
996
|
+
feedbackSource: 0,
|
|
997
|
+
focusCommentID: null,
|
|
998
|
+
gridMediaWidth: null,
|
|
999
|
+
groupID: null,
|
|
1000
|
+
scale: 1,
|
|
1001
|
+
privacySelectorRenderLocation: 'COMET_STREAM',
|
|
1002
|
+
checkPhotosToReelsUpsellEligibility: false,
|
|
1003
|
+
referringStoryRenderLocation: null,
|
|
1004
|
+
renderLocation: 'group',
|
|
1005
|
+
useDefaultActor: false,
|
|
1006
|
+
inviteShortLinkKey: null,
|
|
1007
|
+
isFeed: false,
|
|
1008
|
+
isFundraiser: false,
|
|
1009
|
+
isFunFactPost: false,
|
|
1010
|
+
isGroup: true,
|
|
1011
|
+
isEvent: false,
|
|
1012
|
+
isTimeline: false,
|
|
1013
|
+
isSocialLearning: false,
|
|
1014
|
+
isPageNewsFeed: false,
|
|
1015
|
+
isProfileReviews: false,
|
|
1016
|
+
isWorkSharedDraft: false,
|
|
1017
|
+
canUserManageOffers: false,
|
|
1018
|
+
__relay_internal__pv__CometUFIShareActionMigrationrelayprovider: true,
|
|
1019
|
+
__relay_internal__pv__GHLShouldChangeSponsoredDataFieldNamerelayprovider: true,
|
|
1020
|
+
__relay_internal__pv__GHLShouldChangeAdIdFieldNamerelayprovider: true,
|
|
1021
|
+
__relay_internal__pv__CometUFI_dedicated_comment_routable_dialog_gkrelayprovider: true,
|
|
1022
|
+
__relay_internal__pv__CometUFICommentAutoTranslationTyperelayprovider: 'ORIGINAL',
|
|
1023
|
+
__relay_internal__pv__CometUFICommentAvatarStickerAnimatedImagerelayprovider: false,
|
|
1024
|
+
__relay_internal__pv__CometUFICommentActionLinksRewriteEnabledrelayprovider: false,
|
|
1025
|
+
__relay_internal__pv__IsWorkUserrelayprovider: false,
|
|
1026
|
+
__relay_internal__pv__CometUFIReactionsEnableShortNamerelayprovider: false,
|
|
1027
|
+
__relay_internal__pv__CometUFISingleLineUFIrelayprovider: false,
|
|
1028
|
+
__relay_internal__pv__CometFeedStory_enable_post_permalink_white_space_clickrelayprovider: false,
|
|
1029
|
+
__relay_internal__pv__TestPilotShouldIncludeDemoAdUseCaserelayprovider: false,
|
|
1030
|
+
__relay_internal__pv__FBReels_deprecate_short_form_video_context_gkrelayprovider: true,
|
|
1031
|
+
__relay_internal__pv__FBReels_enable_view_dubbed_audio_type_gkrelayprovider: true,
|
|
1032
|
+
__relay_internal__pv__CometImmersivePhotoCanUserDisable3DMotionrelayprovider: false,
|
|
1033
|
+
__relay_internal__pv__WorkCometIsEmployeeGKProviderrelayprovider: false,
|
|
1034
|
+
__relay_internal__pv__IsMergQAPollsrelayprovider: false,
|
|
1035
|
+
__relay_internal__pv__FBReelsMediaFooter_comet_enable_reels_ads_gkrelayprovider: true,
|
|
1036
|
+
__relay_internal__pv__FBReelsIFUTileContent_reelsIFUPlayOnHoverrelayprovider: true,
|
|
1037
|
+
__relay_internal__pv__GroupsCometGYSJFeedItemHeightrelayprovider: 150,
|
|
1038
|
+
__relay_internal__pv__ShouldEnableBakedInTextStoriesrelayprovider: false,
|
|
1039
|
+
__relay_internal__pv__StoriesShouldIncludeFbNotesrelayprovider: false,
|
|
1040
|
+
__relay_internal__pv__groups_comet_use_glvrelayprovider: false,
|
|
1041
|
+
__relay_internal__pv__GHLShouldChangeSponsoredAuctionDistanceFieldNamerelayprovider: false,
|
|
1042
|
+
__relay_internal__pv__GHLShouldUseSponsoredAuctionLabelFieldNameV1relayprovider: false,
|
|
1043
|
+
__relay_internal__pv__GHLShouldUseSponsoredAuctionLabelFieldNameV2relayprovider: false,
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
// Attach post title if provided
|
|
1047
|
+
if (postTitle) {
|
|
1048
|
+
variables.input.post_message_title = { text: postTitle };
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
// Attach photos if provided
|
|
1052
|
+
if (photos.length > 0) {
|
|
1053
|
+
variables.input.attachments = photos
|
|
1054
|
+
.filter(Boolean)
|
|
1055
|
+
.map((photoID) => ({
|
|
1056
|
+
photo: { id: String(photoID) },
|
|
1057
|
+
}));
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
const form = {
|
|
1061
|
+
av: ctx.userID,
|
|
1062
|
+
__aaid: '0',
|
|
1063
|
+
__user: ctx.userID,
|
|
1064
|
+
__a: '1',
|
|
1065
|
+
__req: '1z',
|
|
1066
|
+
__hs: '20558.HCSV2:comet_pkg.2.1...0',
|
|
1067
|
+
dpr: '1',
|
|
1068
|
+
__ccg: 'EXCELLENT',
|
|
1069
|
+
__comet_req: '15',
|
|
1070
|
+
locale: 'vi_VN',
|
|
1071
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
1072
|
+
jazoest: ctx.jazoest,
|
|
1073
|
+
lsd: ctx.lsd || ctx.fb_dtsg,
|
|
1074
|
+
__spin_r: '1037381017',
|
|
1075
|
+
__spin_b: 'trunk',
|
|
1076
|
+
__spin_t: Math.floor(Date.now() / 1000).toString(),
|
|
1077
|
+
__crn: 'comet.fbweb.CometGroupDiscussionRoute',
|
|
1078
|
+
fb_api_caller_class: 'RelayModern',
|
|
1079
|
+
fb_api_req_friendly_name: 'ComposerStoryCreateMutation',
|
|
1080
|
+
variables: JSON.stringify(variables),
|
|
1081
|
+
server_timestamps: 'true',
|
|
1082
|
+
doc_id: '34999618373018994',
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
const customHeader = {
|
|
1086
|
+
'x-fb-friendly-name': 'ComposerStoryCreateMutation',
|
|
1087
|
+
'x-fb-lsd': ctx.lsd || '',
|
|
1088
|
+
'x-asbd-id': '359341',
|
|
1089
|
+
origin: 'https://www.facebook.com',
|
|
1090
|
+
referer: `https://www.facebook.com/groups/${groupID}?locale=vi_VN`,
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
const res = await utils.post(
|
|
1094
|
+
'https://www.facebook.com/api/graphql/',
|
|
1095
|
+
ctx.jar,
|
|
1096
|
+
form,
|
|
1097
|
+
ctx.globalOptions,
|
|
1098
|
+
ctx,
|
|
1099
|
+
customHeader,
|
|
1100
|
+
);
|
|
1101
|
+
|
|
1102
|
+
const data = parseResponseBody(res.body);
|
|
1103
|
+
|
|
1104
|
+
if (data?.errors) {
|
|
1105
|
+
throw new Error(JSON.stringify(data.errors));
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
return {
|
|
1109
|
+
success: true,
|
|
1110
|
+
postID: data?.data?.story_create?.story?.id || null,
|
|
1111
|
+
url: data?.data?.story_create?.story?.url || null,
|
|
1112
|
+
data,
|
|
1113
|
+
};
|
|
1114
|
+
},
|
|
610
1115
|
};
|
|
611
1116
|
|
|
612
1117
|
return groupModule;
|
package/src/types/index.d.ts
CHANGED
|
@@ -422,6 +422,24 @@ export interface GroupModule {
|
|
|
422
422
|
keyword: string,
|
|
423
423
|
options?: SearchGroupOptions,
|
|
424
424
|
): Promise<SearchGroupResult>;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Resolves a Facebook share URL to the actual group ID.
|
|
428
|
+
*
|
|
429
|
+
* Accepts various formats:
|
|
430
|
+
* - Full URL: `https://www.facebook.com/share/g/14bKqsywAfu/`
|
|
431
|
+
* - Path only: `/share/g/14bKqsywAfu/`
|
|
432
|
+
* - Short key: `14bKqsywAfu`
|
|
433
|
+
*
|
|
434
|
+
* @param shareUrl The share URL, path, or short key to resolve.
|
|
435
|
+
*/
|
|
436
|
+
resolveShareUrl(
|
|
437
|
+
shareUrl: string,
|
|
438
|
+
): Promise<{
|
|
439
|
+
groupID: string;
|
|
440
|
+
name: string | null;
|
|
441
|
+
url: string | null;
|
|
442
|
+
}>;
|
|
425
443
|
}
|
|
426
444
|
|
|
427
445
|
export interface MessageObject {
|