bb-fca 2.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/LICENSE-MIT +21 -0
- package/README.md +0 -0
- package/dist/core/client.js +50 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/models/buildAPI.js +103 -0
- package/dist/core/models/buildAPI.js.map +1 -0
- package/dist/core/models/loginHelper.js +209 -0
- package/dist/core/models/loginHelper.js.map +1 -0
- package/dist/core/models/setOptions.js +47 -0
- package/dist/core/models/setOptions.js.map +1 -0
- package/dist/deltas/apis/create.js +30 -0
- package/dist/deltas/apis/create.js.map +1 -0
- package/dist/deltas/apis/extra/addExternalModule.js +23 -0
- package/dist/deltas/apis/extra/addExternalModule.js.map +1 -0
- package/dist/deltas/apis/extra/getAccess.js +110 -0
- package/dist/deltas/apis/extra/getAccess.js.map +1 -0
- package/dist/deltas/apis/http/httpGet.js +57 -0
- package/dist/deltas/apis/http/httpGet.js.map +1 -0
- package/dist/deltas/apis/http/httpPost.js +57 -0
- package/dist/deltas/apis/http/httpPost.js.map +1 -0
- package/dist/deltas/apis/http/httpPostFormData.js +61 -0
- package/dist/deltas/apis/http/httpPostFormData.js.map +1 -0
- package/dist/deltas/apis/login/GetBotInfo.js +83 -0
- package/dist/deltas/apis/login/GetBotInfo.js.map +1 -0
- package/dist/deltas/apis/login/getBotInitialData.js +46 -0
- package/dist/deltas/apis/login/getBotInitialData.js.map +1 -0
- package/dist/deltas/apis/login/logout.js +54 -0
- package/dist/deltas/apis/login/logout.js.map +1 -0
- package/dist/deltas/apis/messaging/editMessage.js +64 -0
- package/dist/deltas/apis/messaging/editMessage.js.map +1 -0
- package/dist/deltas/apis/messaging/emoji.js +120 -0
- package/dist/deltas/apis/messaging/emoji.js.map +1 -0
- package/dist/deltas/apis/messaging/gcmember.js +164 -0
- package/dist/deltas/apis/messaging/gcmember.js.map +1 -0
- package/dist/deltas/apis/messaging/gcname.js +119 -0
- package/dist/deltas/apis/messaging/gcname.js.map +1 -0
- package/dist/deltas/apis/messaging/gcrule.js +144 -0
- package/dist/deltas/apis/messaging/gcrule.js.map +1 -0
- package/dist/deltas/apis/messaging/markAsDelivered.js +44 -0
- package/dist/deltas/apis/messaging/markAsDelivered.js.map +1 -0
- package/dist/deltas/apis/messaging/markAsRead.js +84 -0
- package/dist/deltas/apis/messaging/markAsRead.js.map +1 -0
- package/dist/deltas/apis/messaging/markAsReadAll.js +34 -0
- package/dist/deltas/apis/messaging/markAsReadAll.js.map +1 -0
- package/dist/deltas/apis/messaging/markAsSeen.js +64 -0
- package/dist/deltas/apis/messaging/markAsSeen.js.map +1 -0
- package/dist/deltas/apis/messaging/nickname.js +129 -0
- package/dist/deltas/apis/messaging/nickname.js.map +1 -0
- package/dist/deltas/apis/messaging/notes.js +156 -0
- package/dist/deltas/apis/messaging/notes.js.map +1 -0
- package/dist/deltas/apis/messaging/resolvePhotoUrl.js +55 -0
- package/dist/deltas/apis/messaging/resolvePhotoUrl.js.map +1 -0
- package/dist/deltas/apis/messaging/sendMessage.js +239 -0
- package/dist/deltas/apis/messaging/sendMessage.js.map +1 -0
- package/dist/deltas/apis/messaging/sendTypingIndicator.js +41 -0
- package/dist/deltas/apis/messaging/sendTypingIndicator.js.map +1 -0
- package/dist/deltas/apis/messaging/setMessageReaction.js +30 -0
- package/dist/deltas/apis/messaging/setMessageReaction.js.map +1 -0
- package/dist/deltas/apis/messaging/shareContact.js +59 -0
- package/dist/deltas/apis/messaging/shareContact.js.map +1 -0
- package/dist/deltas/apis/messaging/stickers.js +246 -0
- package/dist/deltas/apis/messaging/stickers.js.map +1 -0
- package/dist/deltas/apis/messaging/theme.js +227 -0
- package/dist/deltas/apis/messaging/theme.js.map +1 -0
- package/dist/deltas/apis/messaging/unsendMessage.js +19 -0
- package/dist/deltas/apis/messaging/unsendMessage.js.map +1 -0
- package/dist/deltas/apis/mqtt/deltas/value.js +193 -0
- package/dist/deltas/apis/mqtt/deltas/value.js.map +1 -0
- package/dist/deltas/apis/mqtt/listenMqtt.js +306 -0
- package/dist/deltas/apis/mqtt/listenMqtt.js.map +1 -0
- package/dist/deltas/apis/mqtt/listenSpeed.js +166 -0
- package/dist/deltas/apis/mqtt/listenSpeed.js.map +1 -0
- package/dist/deltas/apis/mqtt/pinMessage.js +166 -0
- package/dist/deltas/apis/mqtt/pinMessage.js.map +1 -0
- package/dist/deltas/apis/mqtt/realtime.js +160 -0
- package/dist/deltas/apis/mqtt/realtime.js.map +1 -0
- package/dist/deltas/apis/mqtt/sendMessageMqtt.js +184 -0
- package/dist/deltas/apis/mqtt/sendMessageMqtt.js.map +1 -0
- package/dist/deltas/apis/mqtt/setMessageReactionMqtt.js +57 -0
- package/dist/deltas/apis/mqtt/setMessageReactionMqtt.js.map +1 -0
- package/dist/deltas/apis/posting/comment.js +195 -0
- package/dist/deltas/apis/posting/comment.js.map +1 -0
- package/dist/deltas/apis/posting/follow.js +82 -0
- package/dist/deltas/apis/posting/follow.js.map +1 -0
- package/dist/deltas/apis/posting/friend.js +253 -0
- package/dist/deltas/apis/posting/friend.js.map +1 -0
- package/dist/deltas/apis/posting/post.js +551 -0
- package/dist/deltas/apis/posting/post.js.map +1 -0
- package/dist/deltas/apis/posting/share.js +59 -0
- package/dist/deltas/apis/posting/share.js.map +1 -0
- package/dist/deltas/apis/posting/story.js +176 -0
- package/dist/deltas/apis/posting/story.js.map +1 -0
- package/dist/deltas/apis/threads/getThreadHistory.js +233 -0
- package/dist/deltas/apis/threads/getThreadHistory.js.map +1 -0
- package/dist/deltas/apis/threads/getThreadInfo.js +197 -0
- package/dist/deltas/apis/threads/getThreadInfo.js.map +1 -0
- package/dist/deltas/apis/threads/getThreadList.js +201 -0
- package/dist/deltas/apis/threads/getThreadList.js.map +1 -0
- package/dist/deltas/apis/users/getUserInfo.js +254 -0
- package/dist/deltas/apis/users/getUserInfo.js.map +1 -0
- package/dist/index.d.ts +696 -0
- package/dist/types/core/client.d.ts +2 -0
- package/dist/types/core/models/buildAPI.d.ts +13 -0
- package/dist/types/core/models/loginHelper.d.ts +15 -0
- package/dist/types/core/models/setOptions.d.ts +2 -0
- package/dist/types/deltas/apis/create.d.ts +23 -0
- package/dist/types/deltas/apis/extra/addExternalModule.d.ts +1 -0
- package/dist/types/deltas/apis/extra/getAccess.d.ts +1 -0
- package/dist/types/deltas/apis/http/httpGet.d.ts +1 -0
- package/dist/types/deltas/apis/http/httpPost.d.ts +1 -0
- package/dist/types/deltas/apis/http/httpPostFormData.d.ts +1 -0
- package/dist/types/deltas/apis/login/GetBotInfo.d.ts +32 -0
- package/dist/types/deltas/apis/login/getBotInitialData.d.ts +1 -0
- package/dist/types/deltas/apis/login/logout.d.ts +7 -0
- package/dist/types/deltas/apis/messaging/editMessage.d.ts +7 -0
- package/dist/types/deltas/apis/messaging/emoji.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/gcmember.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/gcname.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/gcrule.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/markAsDelivered.d.ts +7 -0
- package/dist/types/deltas/apis/messaging/markAsRead.d.ts +6 -0
- package/dist/types/deltas/apis/messaging/markAsReadAll.d.ts +7 -0
- package/dist/types/deltas/apis/messaging/markAsSeen.d.ts +6 -0
- package/dist/types/deltas/apis/messaging/nickname.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/notes.d.ts +14 -0
- package/dist/types/deltas/apis/messaging/resolvePhotoUrl.d.ts +9 -0
- package/dist/types/deltas/apis/messaging/sendMessage.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/sendTypingIndicator.d.ts +6 -0
- package/dist/types/deltas/apis/messaging/setMessageReaction.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/shareContact.d.ts +8 -0
- package/dist/types/deltas/apis/messaging/stickers.d.ts +48 -0
- package/dist/types/deltas/apis/messaging/theme.d.ts +1 -0
- package/dist/types/deltas/apis/messaging/unsendMessage.d.ts +1 -0
- package/dist/types/deltas/apis/mqtt/deltas/value.d.ts +2 -0
- package/dist/types/deltas/apis/mqtt/listenMqtt.d.ts +20 -0
- package/dist/types/deltas/apis/mqtt/listenSpeed.d.ts +21 -0
- package/dist/types/deltas/apis/mqtt/pinMessage.d.ts +1 -0
- package/dist/types/deltas/apis/mqtt/realtime.d.ts +1 -0
- package/dist/types/deltas/apis/mqtt/sendMessageMqtt.d.ts +1 -0
- package/dist/types/deltas/apis/mqtt/setMessageReactionMqtt.d.ts +1 -0
- package/dist/types/deltas/apis/posting/comment.d.ts +9 -0
- package/dist/types/deltas/apis/posting/follow.d.ts +14 -0
- package/dist/types/deltas/apis/posting/friend.d.ts +61 -0
- package/dist/types/deltas/apis/posting/post.d.ts +20 -0
- package/dist/types/deltas/apis/posting/share.d.ts +1 -0
- package/dist/types/deltas/apis/posting/story.d.ts +39 -0
- package/dist/types/deltas/apis/threads/getThreadHistory.d.ts +7 -0
- package/dist/types/deltas/apis/threads/getThreadInfo.d.ts +7 -0
- package/dist/types/deltas/apis/threads/getThreadList.d.ts +7 -0
- package/dist/types/deltas/apis/users/getUserInfo.d.ts +1 -0
- package/dist/types/utils/axios.d.ts +7 -0
- package/dist/types/utils/clients.d.ts +4 -0
- package/dist/types/utils/constants.d.ts +24 -0
- package/dist/types/utils/formatters/data/formatAttachment.d.ts +2 -0
- package/dist/types/utils/formatters/data/formatDelta.d.ts +4 -0
- package/dist/types/utils/formatters/index.d.ts +17 -0
- package/dist/types/utils/formatters/value/formatCookie.d.ts +8 -0
- package/dist/types/utils/formatters/value/formatDate.d.ts +6 -0
- package/dist/types/utils/formatters/value/formatID.d.ts +7 -0
- package/dist/types/utils/headers.d.ts +2 -0
- package/dist/types/utils/index.d.ts +75 -0
- package/dist/types/utils/user-agents.d.ts +9 -0
- package/dist/utils/axios.js +148 -0
- package/dist/utils/axios.js.map +1 -0
- package/dist/utils/clients.js +120 -0
- package/dist/utils/clients.js.map +1 -0
- package/dist/utils/constants.js +249 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/formatters/data/formatAttachment.js +61 -0
- package/dist/utils/formatters/data/formatAttachment.js.map +1 -0
- package/dist/utils/formatters/data/formatDelta.js +67 -0
- package/dist/utils/formatters/data/formatDelta.js.map +1 -0
- package/dist/utils/formatters/index.js +132 -0
- package/dist/utils/formatters/index.js.map +1 -0
- package/dist/utils/formatters/value/formatCookie.js +13 -0
- package/dist/utils/formatters/value/formatCookie.js.map +1 -0
- package/dist/utils/formatters/value/formatDate.js +33 -0
- package/dist/utils/formatters/value/formatDate.js.map +1 -0
- package/dist/utils/formatters/value/formatID.js +17 -0
- package/dist/utils/formatters/value/formatID.js.map +1 -0
- package/dist/utils/headers.js +61 -0
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/index.js +105 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/user-agents.js +41 -0
- package/dist/utils/user-agents.js.map +1 -0
- package/examples/post.example.js +149 -0
- package/module/index.js +5 -0
- package/package.json +56 -0
- package/src/core/client.ts +66 -0
- package/src/core/models/buildAPI.ts +131 -0
- package/src/core/models/loginHelper.ts +226 -0
- package/src/core/models/setOptions.ts +48 -0
- package/src/deltas/apis/create.ts +28 -0
- package/src/deltas/apis/extra/addExternalModule.ts +23 -0
- package/src/deltas/apis/extra/getAccess.ts +141 -0
- package/src/deltas/apis/http/httpGet.ts +61 -0
- package/src/deltas/apis/http/httpPost.ts +61 -0
- package/src/deltas/apis/http/httpPostFormData.ts +67 -0
- package/src/deltas/apis/login/GetBotInfo.ts +88 -0
- package/src/deltas/apis/login/getBotInitialData.ts +42 -0
- package/src/deltas/apis/login/logout.ts +62 -0
- package/src/deltas/apis/messaging/editMessage.ts +69 -0
- package/src/deltas/apis/messaging/emoji.ts +135 -0
- package/src/deltas/apis/messaging/gcmember.ts +175 -0
- package/src/deltas/apis/messaging/gcname.ts +136 -0
- package/src/deltas/apis/messaging/gcrule.ts +152 -0
- package/src/deltas/apis/messaging/markAsDelivered.ts +47 -0
- package/src/deltas/apis/messaging/markAsRead.ts +94 -0
- package/src/deltas/apis/messaging/markAsReadAll.ts +38 -0
- package/src/deltas/apis/messaging/markAsSeen.ts +69 -0
- package/src/deltas/apis/messaging/nickname.ts +153 -0
- package/src/deltas/apis/messaging/notes.ts +165 -0
- package/src/deltas/apis/messaging/resolvePhotoUrl.ts +56 -0
- package/src/deltas/apis/messaging/sendMessage.ts +286 -0
- package/src/deltas/apis/messaging/sendTypingIndicator.ts +48 -0
- package/src/deltas/apis/messaging/setMessageReaction.ts +25 -0
- package/src/deltas/apis/messaging/shareContact.ts +63 -0
- package/src/deltas/apis/messaging/stickers.ts +255 -0
- package/src/deltas/apis/messaging/theme.ts +280 -0
- package/src/deltas/apis/messaging/unsendMessage.ts +15 -0
- package/src/deltas/apis/mqtt/deltas/value.ts +224 -0
- package/src/deltas/apis/mqtt/listenMqtt.ts +332 -0
- package/src/deltas/apis/mqtt/listenSpeed.ts +179 -0
- package/src/deltas/apis/mqtt/pinMessage.ts +135 -0
- package/src/deltas/apis/mqtt/realtime.ts +169 -0
- package/src/deltas/apis/mqtt/sendMessageMqtt.ts +206 -0
- package/src/deltas/apis/mqtt/setMessageReactionMqtt.ts +61 -0
- package/src/deltas/apis/posting/comment.ts +205 -0
- package/src/deltas/apis/posting/follow.ts +79 -0
- package/src/deltas/apis/posting/friend.ts +241 -0
- package/src/deltas/apis/posting/post.ts +599 -0
- package/src/deltas/apis/posting/share.ts +60 -0
- package/src/deltas/apis/posting/story.ts +207 -0
- package/src/deltas/apis/threads/getThreadHistory.ts +237 -0
- package/src/deltas/apis/threads/getThreadInfo.ts +210 -0
- package/src/deltas/apis/threads/getThreadList.ts +224 -0
- package/src/deltas/apis/users/getUserInfo.ts +244 -0
- package/src/types/index.d.ts +696 -0
- package/src/utils/axios.ts +178 -0
- package/src/utils/clients.ts +125 -0
- package/src/utils/constants.ts +281 -0
- package/src/utils/formatters/data/formatAttachment.ts +58 -0
- package/src/utils/formatters/data/formatDelta.ts +45 -0
- package/src/utils/formatters/index.ts +82 -0
- package/src/utils/formatters/value/formatCookie.ts +13 -0
- package/src/utils/formatters/value/formatDate.ts +34 -0
- package/src/utils/formatters/value/formatID.ts +14 -0
- package/src/utils/formatters.old.ts +1049 -0
- package/src/utils/headers.ts +65 -0
- package/src/utils/index.ts +65 -0
- package/src/utils/user-agents.ts +49 -0
- package/tsconfig.json +37 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import utils = require('../../../utils');
|
|
2
|
+
import { URL } from 'url';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @namespace api.story
|
|
6
|
+
* @description A collection of functions for interacting with Facebook Stories.
|
|
7
|
+
* @license Ex-it
|
|
8
|
+
* @author Jonell Magallanes, ChoruOfficial
|
|
9
|
+
*/
|
|
10
|
+
export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
11
|
+
/**
|
|
12
|
+
* (Internal) Extracts the Story ID from a Facebook story URL.
|
|
13
|
+
* @param {string} url The Facebook story URL.
|
|
14
|
+
* @returns {string|null} The extracted Story ID or null if not found.
|
|
15
|
+
*/
|
|
16
|
+
function getStoryIDFromURL(url) {
|
|
17
|
+
try {
|
|
18
|
+
const urlObject = new URL(url);
|
|
19
|
+
const pathParts = urlObject.pathname.split('/');
|
|
20
|
+
const storiesIndex = pathParts.indexOf('stories');
|
|
21
|
+
if (storiesIndex !== -1 && pathParts.length > storiesIndex + 2) {
|
|
22
|
+
return pathParts[storiesIndex + 2];
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* (Internal) The core function to send a reply or reaction to a story.
|
|
32
|
+
* @param {string} storyIdOrUrl The ID or URL of the story.
|
|
33
|
+
* @param {string} message The text message or emoji reaction.
|
|
34
|
+
* @param {boolean} isReaction True if the reply is a lightweight reaction.
|
|
35
|
+
* @returns {Promise<object>} The server's response.
|
|
36
|
+
*/
|
|
37
|
+
async function sendStoryReply(storyIdOrUrl, message, isReaction) {
|
|
38
|
+
try {
|
|
39
|
+
const allowedReactions = ['❤️', '👍', '🤗', '😆', '😡', '😢', '😮'];
|
|
40
|
+
|
|
41
|
+
if (!storyIdOrUrl) throw new Error('Story ID or URL is required.');
|
|
42
|
+
if (!message) throw new Error('A message or reaction is required.');
|
|
43
|
+
|
|
44
|
+
let storyID = getStoryIDFromURL(storyIdOrUrl);
|
|
45
|
+
if (!storyID) storyID = storyIdOrUrl;
|
|
46
|
+
|
|
47
|
+
const variables: any = {
|
|
48
|
+
input: {
|
|
49
|
+
attribution_id_v2:
|
|
50
|
+
'StoriesCometSuspenseRoot.react,comet.stories.viewer,via_cold_start',
|
|
51
|
+
message: message,
|
|
52
|
+
story_id: storyID,
|
|
53
|
+
story_reply_type: isReaction ? 'LIGHT_WEIGHT' : 'TEXT',
|
|
54
|
+
actor_id: ctx.userID,
|
|
55
|
+
client_mutation_id: Math.floor(Math.random() * 10 + 1).toString(),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (isReaction) {
|
|
60
|
+
if (!allowedReactions.includes(message)) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Invalid reaction. Please use one of: ${allowedReactions.join(
|
|
63
|
+
' ',
|
|
64
|
+
)}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
variables.input.lightweight_reaction_actions = {
|
|
68
|
+
offsets: [0],
|
|
69
|
+
reaction: message,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const form = {
|
|
74
|
+
av: ctx.userID,
|
|
75
|
+
__user: ctx.userID,
|
|
76
|
+
__a: '1',
|
|
77
|
+
fb_dtsg: ctx.fb_dtsg,
|
|
78
|
+
jazoest: ctx.jazoest,
|
|
79
|
+
fb_api_caller_class: 'RelayModern',
|
|
80
|
+
fb_api_req_friendly_name: 'useStoriesSendReplyMutation',
|
|
81
|
+
variables: JSON.stringify(variables),
|
|
82
|
+
doc_id: '9697491553691692',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const res = await defaultFuncs.post(
|
|
86
|
+
'https://www.facebook.com/api/graphql/',
|
|
87
|
+
ctx.jar,
|
|
88
|
+
form,
|
|
89
|
+
{},
|
|
90
|
+
);
|
|
91
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
92
|
+
|
|
93
|
+
const storyReplyData = res.data?.data?.direct_message_reply;
|
|
94
|
+
if (!storyReplyData)
|
|
95
|
+
throw new Error(
|
|
96
|
+
"Could not find 'direct_message_reply' in the response data.",
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return { success: true, result: storyReplyData };
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error('Error in story reply API:', err);
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new text-based story.
|
|
108
|
+
* @param {string} message The text content of the story.
|
|
109
|
+
* @param {string} [fontName="classic"] The name of the font to use. Options: `headline`, `classic`, `casual`, `fancy`.
|
|
110
|
+
* @param {string} [backgroundName="blue"] The name of the background to use. Options: `orange`, `blue`, `green`, `modern`.
|
|
111
|
+
* @returns {Promise<{success: boolean, storyID: string}>} A promise that resolves with the new story's ID.
|
|
112
|
+
*/
|
|
113
|
+
async function create(
|
|
114
|
+
message,
|
|
115
|
+
fontName = 'classic',
|
|
116
|
+
backgroundName = 'blue',
|
|
117
|
+
) {
|
|
118
|
+
const fontMap = {
|
|
119
|
+
headline: '1919119914775364',
|
|
120
|
+
classic: '516266749248495',
|
|
121
|
+
casual: '516266749248495',
|
|
122
|
+
fancy: '1790435664339626',
|
|
123
|
+
};
|
|
124
|
+
const bgMap = {
|
|
125
|
+
orange: '2163607613910521',
|
|
126
|
+
blue: '401372137331149',
|
|
127
|
+
green: '367314917184744',
|
|
128
|
+
modern: '554617635055752',
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const fontId = fontMap[fontName.toLowerCase()] || fontMap.classic;
|
|
132
|
+
const bgId = bgMap[backgroundName.toLowerCase()] || bgMap.blue;
|
|
133
|
+
|
|
134
|
+
const variables = {
|
|
135
|
+
input: {
|
|
136
|
+
audiences: [{ stories: { self: { target_id: ctx.userID } } }],
|
|
137
|
+
audiences_is_complete: true,
|
|
138
|
+
logging: { composer_session_id: 'createStoriesText-' + Date.now() },
|
|
139
|
+
navigation_data: {
|
|
140
|
+
attribution_id_v2: 'StoriesCreateRoot.react,comet.stories.create',
|
|
141
|
+
},
|
|
142
|
+
source: 'WWW',
|
|
143
|
+
message: { ranges: [], text: message },
|
|
144
|
+
text_format_metadata: { inspirations_custom_font_id: fontId },
|
|
145
|
+
text_format_preset_id: bgId,
|
|
146
|
+
tracking: [null],
|
|
147
|
+
actor_id: ctx.userID,
|
|
148
|
+
client_mutation_id: '2',
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const form = {
|
|
153
|
+
__a: '1',
|
|
154
|
+
fb_api_caller_class: 'RelayModern',
|
|
155
|
+
fb_api_req_friendly_name: 'StoriesCreateMutation',
|
|
156
|
+
variables: JSON.stringify(variables),
|
|
157
|
+
doc_id: '24226878183562473',
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
const res = await defaultFuncs.post(
|
|
162
|
+
'https://www.facebook.com/api/graphql/',
|
|
163
|
+
ctx.jar,
|
|
164
|
+
form,
|
|
165
|
+
{},
|
|
166
|
+
);
|
|
167
|
+
if (res.data.errors) throw new Error(JSON.stringify(res.data.errors));
|
|
168
|
+
|
|
169
|
+
const storyNode =
|
|
170
|
+
res.data?.data?.story_create?.viewer?.actor?.story_bucket?.nodes[0]
|
|
171
|
+
?.first_story_to_show;
|
|
172
|
+
if (!storyNode || !storyNode.id)
|
|
173
|
+
throw new Error('Could not find the storyCardID in the response.');
|
|
174
|
+
|
|
175
|
+
return { success: true, storyID: storyNode.id };
|
|
176
|
+
} catch (error) {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
/**
|
|
183
|
+
* Creates a new text-based story.
|
|
184
|
+
* @param {string} message The text content of the story.
|
|
185
|
+
* @param {string} [fontName="classic"] The font to use (`headline`, `classic`, `fancy`).
|
|
186
|
+
* @param {string} [backgroundName="blue"] The background to use (`orange`, `blue`, `green`, `modern`).
|
|
187
|
+
* @returns {Promise<{success: boolean, storyID: string}>}
|
|
188
|
+
*/
|
|
189
|
+
create,
|
|
190
|
+
/**
|
|
191
|
+
* Reacts to a story with a specific emoji.
|
|
192
|
+
* @param {string} storyIdOrUrl The ID or full URL of the story to react to.
|
|
193
|
+
* @param {string} reaction The emoji to react with. Must be one of: ❤️, 👍, 🤗, 😆, 😡, 😢, 😮.
|
|
194
|
+
* @returns {Promise<{success: boolean, result: object}>}
|
|
195
|
+
*/
|
|
196
|
+
react: (storyIdOrUrl, reaction) =>
|
|
197
|
+
sendStoryReply(storyIdOrUrl, reaction, true),
|
|
198
|
+
/**
|
|
199
|
+
* Sends a text message reply to a story.
|
|
200
|
+
* @param {string} storyIdOrUrl The ID or full URL of the story to reply to.
|
|
201
|
+
* @param {string} message The text message to send.
|
|
202
|
+
* @returns {Promise<{success: boolean, result: object}>}
|
|
203
|
+
*/
|
|
204
|
+
msg: (storyIdOrUrl, message) =>
|
|
205
|
+
sendStoryReply(storyIdOrUrl, message, false),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import utils = require("../../../utils");
|
|
2
|
+
|
|
3
|
+
// @ChoruOfficial
|
|
4
|
+
/**
|
|
5
|
+
* Formats a single attachment object from a GraphQL response.
|
|
6
|
+
* @param {Object} attachment The raw attachment object.
|
|
7
|
+
* @returns {Object} A formatted attachment object.
|
|
8
|
+
*/
|
|
9
|
+
function formatAttachmentsGraphQLResponse(attachment) {
|
|
10
|
+
switch (attachment.__typename) {
|
|
11
|
+
case "MessageImage":
|
|
12
|
+
return {
|
|
13
|
+
type: "photo",
|
|
14
|
+
ID: attachment.legacy_attachment_id,
|
|
15
|
+
filename: attachment.filename,
|
|
16
|
+
thumbnailUrl: attachment.thumbnail.uri,
|
|
17
|
+
previewUrl: attachment.preview.uri,
|
|
18
|
+
previewWidth: attachment.preview.width,
|
|
19
|
+
previewHeight: attachment.preview.height,
|
|
20
|
+
largePreviewUrl: attachment.large_preview.uri,
|
|
21
|
+
largePreviewHeight: attachment.large_preview.height,
|
|
22
|
+
largePreviewWidth: attachment.large_preview.width,
|
|
23
|
+
url: attachment.large_preview.uri,
|
|
24
|
+
width: attachment.original_dimensions.x,
|
|
25
|
+
height: attachment.original_dimensions.y,
|
|
26
|
+
name: attachment.filename
|
|
27
|
+
};
|
|
28
|
+
case "MessageAnimatedImage":
|
|
29
|
+
return {
|
|
30
|
+
type: "animated_image",
|
|
31
|
+
ID: attachment.legacy_attachment_id,
|
|
32
|
+
filename: attachment.filename,
|
|
33
|
+
previewUrl: attachment.preview_image.uri,
|
|
34
|
+
previewWidth: attachment.preview_image.width,
|
|
35
|
+
previewHeight: attachment.preview_image.height,
|
|
36
|
+
url: attachment.animated_image.uri,
|
|
37
|
+
width: attachment.animated_image.width,
|
|
38
|
+
height: attachment.animated_image.height,
|
|
39
|
+
name: attachment.filename,
|
|
40
|
+
facebookUrl: attachment.animated_image.uri,
|
|
41
|
+
};
|
|
42
|
+
case "MessageVideo":
|
|
43
|
+
return {
|
|
44
|
+
type: "video",
|
|
45
|
+
ID: attachment.legacy_attachment_id,
|
|
46
|
+
filename: attachment.filename,
|
|
47
|
+
duration: attachment.playable_duration_in_ms,
|
|
48
|
+
thumbnailUrl: attachment.large_image.uri,
|
|
49
|
+
previewUrl: attachment.large_image.uri,
|
|
50
|
+
previewWidth: attachment.large_image.width,
|
|
51
|
+
previewHeight: attachment.large_image.height,
|
|
52
|
+
url: attachment.playable_url,
|
|
53
|
+
width: attachment.original_dimensions.x,
|
|
54
|
+
height: attachment.original_dimensions.y,
|
|
55
|
+
videoType: attachment.video_type.toLowerCase(),
|
|
56
|
+
};
|
|
57
|
+
case "MessageFile":
|
|
58
|
+
return {
|
|
59
|
+
type: "file",
|
|
60
|
+
ID: attachment.message_file_fbid,
|
|
61
|
+
filename: attachment.filename,
|
|
62
|
+
url: attachment.url,
|
|
63
|
+
isMalicious: attachment.is_malicious,
|
|
64
|
+
contentType: attachment.content_type,
|
|
65
|
+
name: attachment.filename,
|
|
66
|
+
};
|
|
67
|
+
case "MessageAudio":
|
|
68
|
+
return {
|
|
69
|
+
type: "audio",
|
|
70
|
+
ID: attachment.url_shimhash,
|
|
71
|
+
filename: attachment.filename,
|
|
72
|
+
duration: attachment.playable_duration_in_ms,
|
|
73
|
+
audioType: attachment.audio_type,
|
|
74
|
+
url: attachment.playable_url,
|
|
75
|
+
isVoiceMail: attachment.is_voicemail,
|
|
76
|
+
};
|
|
77
|
+
default:
|
|
78
|
+
return {
|
|
79
|
+
type: "unknown",
|
|
80
|
+
error: "Don't know about attachment type " + attachment.__typename,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Formats a share (extensible) attachment from a GraphQL response.
|
|
87
|
+
* @param {Object} attachment The raw extensible attachment object.
|
|
88
|
+
* @returns {Object} A formatted share attachment object.
|
|
89
|
+
*/
|
|
90
|
+
function formatExtensibleAttachment(attachment) {
|
|
91
|
+
if (attachment.story_attachment) {
|
|
92
|
+
return {
|
|
93
|
+
type: "share",
|
|
94
|
+
ID: attachment.legacy_attachment_id,
|
|
95
|
+
url: attachment.story_attachment.url,
|
|
96
|
+
title: attachment.story_attachment.title_with_entities.text,
|
|
97
|
+
description: attachment.story_attachment.description && attachment.story_attachment.description.text,
|
|
98
|
+
source: attachment.story_attachment.source == null ? null : attachment.story_attachment.source.text,
|
|
99
|
+
image: attachment.story_attachment.media?.image?.uri,
|
|
100
|
+
width: attachment.story_attachment.media?.image?.width,
|
|
101
|
+
height: attachment.story_attachment.media?.image?.height,
|
|
102
|
+
playable: attachment.story_attachment.media?.is_playable,
|
|
103
|
+
duration: attachment.story_attachment.media?.playable_duration_in_ms,
|
|
104
|
+
playableUrl: attachment.story_attachment.media?.playable_url,
|
|
105
|
+
subattachments: attachment.story_attachment.subattachments,
|
|
106
|
+
properties: attachment.story_attachment.properties.reduce((obj, cur) => {
|
|
107
|
+
obj[cur.key] = cur.value.text;
|
|
108
|
+
return obj;
|
|
109
|
+
}, {}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return { type: "unknown", error: "Don't know what to do with extensible_attachment." };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Formats the response from a GraphQL message history query.
|
|
117
|
+
* @param {Object} data The raw GraphQL response data.
|
|
118
|
+
* @returns {Array<Object>} An array of formatted message objects.
|
|
119
|
+
*/
|
|
120
|
+
function formatMessagesGraphQLResponse(data) {
|
|
121
|
+
const messageThread = data.o0.data.message_thread;
|
|
122
|
+
if (!messageThread) return [];
|
|
123
|
+
|
|
124
|
+
const threadID = messageThread.thread_key.thread_fbid ? messageThread.thread_key.thread_fbid : messageThread.thread_key.other_user_id;
|
|
125
|
+
|
|
126
|
+
return messageThread.messages.nodes.map(d => {
|
|
127
|
+
switch (d.__typename) {
|
|
128
|
+
case "UserMessage":
|
|
129
|
+
const mentions = {};
|
|
130
|
+
if (d.message?.ranges) {
|
|
131
|
+
d.message.ranges.forEach(e => {
|
|
132
|
+
mentions[e.entity.id] = d.message.text.substring(e.offset, e.offset + e.length);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
type: "message",
|
|
137
|
+
attachments: d.sticker ? [{
|
|
138
|
+
type: "sticker",
|
|
139
|
+
ID: d.sticker.id,
|
|
140
|
+
url: d.sticker.url,
|
|
141
|
+
packID: d.sticker.pack?.id,
|
|
142
|
+
frameCount: d.sticker.frame_count,
|
|
143
|
+
frameRate: d.sticker.frame_rate,
|
|
144
|
+
framesPerRow: d.sticker.frames_per_row,
|
|
145
|
+
framesPerCol: d.sticker.frames_per_col,
|
|
146
|
+
stickerID: d.sticker.id,
|
|
147
|
+
}] : (d.blob_attachments || []).map(formatAttachmentsGraphQLResponse).concat(d.extensible_attachment ? [formatExtensibleAttachment(d.extensible_attachment)] : []),
|
|
148
|
+
body: d.message?.text || "",
|
|
149
|
+
isGroup: messageThread.thread_type === "GROUP",
|
|
150
|
+
messageID: d.message_id,
|
|
151
|
+
senderID: d.message_sender.id,
|
|
152
|
+
threadID: threadID,
|
|
153
|
+
timestamp: d.timestamp_precise,
|
|
154
|
+
mentions: mentions,
|
|
155
|
+
isUnread: d.unread,
|
|
156
|
+
messageReactions: d.message_reactions?.map(r => ({ reaction: r.reaction, userID: r.user.id })) || [],
|
|
157
|
+
};
|
|
158
|
+
case "ThreadNameMessage":
|
|
159
|
+
case "ThreadImageMessage":
|
|
160
|
+
case "ParticipantLeftMessage":
|
|
161
|
+
case "ParticipantsAddedMessage":
|
|
162
|
+
case "GenericAdminTextMessage": {
|
|
163
|
+
// This is the fix. We are now formatting the event directly
|
|
164
|
+
// instead of calling the incompatible `formatDeltaEvent`.
|
|
165
|
+
return {
|
|
166
|
+
type: "event",
|
|
167
|
+
messageID: d.message_id,
|
|
168
|
+
threadID: threadID,
|
|
169
|
+
isGroup: messageThread.thread_type === "GROUP",
|
|
170
|
+
senderID: d.message_sender.id,
|
|
171
|
+
author: d.message_sender.id,
|
|
172
|
+
timestamp: d.timestamp_precise,
|
|
173
|
+
snippet: d.snippet,
|
|
174
|
+
logMessageType: utils.getAdminTextMessageType(d.extensible_message_admin_text_type || d.__typename),
|
|
175
|
+
logMessageData: d.extensible_message_admin_text || d,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
default:
|
|
179
|
+
return { type: "unknown", error: "Unknown message type " + d.__typename, raw: d };
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param {Object} defaultFuncs
|
|
186
|
+
* @param {Object} api
|
|
187
|
+
* @param {Object} ctx
|
|
188
|
+
* @returns {function(threadID: string, amount: number, timestamp: number | null): Promise<Array<Object>>}
|
|
189
|
+
*/
|
|
190
|
+
export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves the message history for a specific thread.
|
|
193
|
+
* @param {string} threadID The ID of the thread to fetch history from.
|
|
194
|
+
* @param {number} amount The number of messages to retrieve.
|
|
195
|
+
* @param {number | null} timestamp The timestamp to start fetching messages before.
|
|
196
|
+
* @returns {Promise<Array<Object>>} A promise that resolves with an array of formatted message objects.
|
|
197
|
+
*/
|
|
198
|
+
return async function getThreadHistory(threadID, amount, timestamp) {
|
|
199
|
+
if (!threadID || !amount) {
|
|
200
|
+
throw new Error("getThreadHistory: threadID and amount are required.");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const form = {
|
|
204
|
+
av: ctx.globalOptions.pageID,
|
|
205
|
+
queries: JSON.stringify({
|
|
206
|
+
o0: {
|
|
207
|
+
doc_id: "1498317363570230",
|
|
208
|
+
query_params: {
|
|
209
|
+
id: threadID,
|
|
210
|
+
message_limit: amount,
|
|
211
|
+
load_messages: 1,
|
|
212
|
+
load_read_receipts: false,
|
|
213
|
+
before: timestamp || null,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
}),
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
const resData = await defaultFuncs.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form);
|
|
221
|
+
const parsedData = await utils.parseAndCheckLogin(ctx, defaultFuncs)(resData);
|
|
222
|
+
|
|
223
|
+
if (parsedData.error || (Array.isArray(parsedData) && parsedData[parsedData.length - 1].error_results !== 0)) {
|
|
224
|
+
throw parsedData;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!Array.isArray(parsedData) || !parsedData[0] || !parsedData[0].o0 || !parsedData[0].o0.data) {
|
|
228
|
+
throw { error: "getThreadHistory: Malformed response from GraphQL.", res: parsedData };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return formatMessagesGraphQLResponse(parsedData[0]);
|
|
232
|
+
} catch (err) {
|
|
233
|
+
utils.error("getThreadHistory", err);
|
|
234
|
+
throw err;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @ChoruOfficial
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
import utils = require("../../../utils");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Formats an event reminder object from a GraphQL response.
|
|
8
|
+
* @param {Object} reminder The raw event reminder object.
|
|
9
|
+
* @returns {Object} A formatted event reminder object.
|
|
10
|
+
*/
|
|
11
|
+
function formatEventReminders(reminder) {
|
|
12
|
+
return {
|
|
13
|
+
reminderID: reminder.id,
|
|
14
|
+
eventCreatorID: reminder.lightweight_event_creator.id,
|
|
15
|
+
time: reminder.time,
|
|
16
|
+
eventType: reminder.lightweight_event_type.toLowerCase(),
|
|
17
|
+
locationName: reminder.location_name,
|
|
18
|
+
locationCoordinates: reminder.location_coordinates,
|
|
19
|
+
locationPage: reminder.location_page,
|
|
20
|
+
eventStatus: reminder.lightweight_event_status.toLowerCase(),
|
|
21
|
+
note: reminder.note,
|
|
22
|
+
repeatMode: reminder.repeat_mode.toLowerCase(),
|
|
23
|
+
eventTitle: reminder.event_title,
|
|
24
|
+
triggerMessage: reminder.trigger_message,
|
|
25
|
+
secondsToNotifyBefore: reminder.seconds_to_notify_before,
|
|
26
|
+
allowsRsvp: reminder.allows_rsvp,
|
|
27
|
+
relatedEvent: reminder.related_event,
|
|
28
|
+
members: reminder.event_reminder_members.edges.map(function (member) {
|
|
29
|
+
return {
|
|
30
|
+
memberID: member.node.id,
|
|
31
|
+
state: member.guest_list_state.toLowerCase(),
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Formats a thread object from a GraphQL response.
|
|
39
|
+
* @param {Object} data The raw GraphQL data for a thread.
|
|
40
|
+
* @returns {Object | null} A formatted thread object or null if data is invalid.
|
|
41
|
+
*/
|
|
42
|
+
function formatThreadGraphQLResponse(data) {
|
|
43
|
+
if (data.errors) return null;
|
|
44
|
+
const messageThread = data.message_thread;
|
|
45
|
+
if (!messageThread) return null;
|
|
46
|
+
|
|
47
|
+
const threadID = messageThread.thread_key.thread_fbid
|
|
48
|
+
? messageThread.thread_key.thread_fbid
|
|
49
|
+
: messageThread.thread_key.other_user_id;
|
|
50
|
+
|
|
51
|
+
const lastM = messageThread.last_message;
|
|
52
|
+
const snippetID =
|
|
53
|
+
lastM?.nodes?.[0]?.message_sender?.messaging_actor?.id || null;
|
|
54
|
+
const snippetText = lastM?.nodes?.[0]?.snippet || null;
|
|
55
|
+
const lastR = messageThread.last_read_receipt;
|
|
56
|
+
const lastReadTimestamp = lastR?.nodes?.[0]?.timestamp_precise || null;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
threadID: threadID,
|
|
60
|
+
threadName: messageThread.name,
|
|
61
|
+
participantIDs: messageThread.all_participants.edges.map(
|
|
62
|
+
(d) => d.node.messaging_actor.id,
|
|
63
|
+
),
|
|
64
|
+
userInfo: messageThread.all_participants.edges.map((d) => ({
|
|
65
|
+
id: d.node.messaging_actor.id,
|
|
66
|
+
name: d.node.messaging_actor.name,
|
|
67
|
+
firstName: d.node.messaging_actor.short_name,
|
|
68
|
+
vanity: d.node.messaging_actor.username,
|
|
69
|
+
url: d.node.messaging_actor.url,
|
|
70
|
+
thumbSrc: d.node.messaging_actor.big_image_src.uri,
|
|
71
|
+
profileUrl: d.node.messaging_actor.big_image_src.uri,
|
|
72
|
+
gender: d.node.messaging_actor.gender,
|
|
73
|
+
type: d.node.messaging_actor.__typename,
|
|
74
|
+
isFriend: d.node.messaging_actor.is_viewer_friend,
|
|
75
|
+
isBirthday: !!d.node.messaging_actor.is_birthday,
|
|
76
|
+
})),
|
|
77
|
+
unreadCount: messageThread.unread_count,
|
|
78
|
+
messageCount: messageThread.messages_count,
|
|
79
|
+
timestamp: messageThread.updated_time_precise,
|
|
80
|
+
muteUntil: messageThread.mute_until,
|
|
81
|
+
isGroup: messageThread.thread_type == "GROUP",
|
|
82
|
+
isSubscribed: messageThread.is_viewer_subscribed,
|
|
83
|
+
isArchived: messageThread.has_viewer_archived,
|
|
84
|
+
folder: messageThread.folder,
|
|
85
|
+
cannotReplyReason: messageThread.cannot_reply_reason,
|
|
86
|
+
eventReminders: messageThread.event_reminders
|
|
87
|
+
? messageThread.event_reminders.nodes.map(formatEventReminders)
|
|
88
|
+
: null,
|
|
89
|
+
emoji: messageThread.customization_info
|
|
90
|
+
? messageThread.customization_info.emoji
|
|
91
|
+
: null,
|
|
92
|
+
color:
|
|
93
|
+
messageThread.customization_info &&
|
|
94
|
+
messageThread.customization_info.outgoing_bubble_color
|
|
95
|
+
? messageThread.customization_info.outgoing_bubble_color.slice(2)
|
|
96
|
+
: null,
|
|
97
|
+
threadTheme: messageThread.thread_theme,
|
|
98
|
+
nicknames:
|
|
99
|
+
messageThread.customization_info &&
|
|
100
|
+
messageThread.customization_info.participant_customizations
|
|
101
|
+
? messageThread.customization_info.participant_customizations.reduce(
|
|
102
|
+
function (res, val) {
|
|
103
|
+
if (val.nickname) res[val.participant_id] = val.nickname;
|
|
104
|
+
return res;
|
|
105
|
+
},
|
|
106
|
+
{},
|
|
107
|
+
)
|
|
108
|
+
: {},
|
|
109
|
+
adminIDs: messageThread.thread_admins,
|
|
110
|
+
approvalMode: Boolean(messageThread.approval_mode),
|
|
111
|
+
approvalQueue: messageThread.group_approval_queue.nodes.map((a) => ({
|
|
112
|
+
inviterID: a.inviter.id,
|
|
113
|
+
requesterID: a.requester.id,
|
|
114
|
+
timestamp: a.request_timestamp,
|
|
115
|
+
request_source: a.request_source,
|
|
116
|
+
})),
|
|
117
|
+
reactionsMuteMode: messageThread.reactions_mute_mode.toLowerCase(),
|
|
118
|
+
mentionsMuteMode: messageThread.mentions_mute_mode.toLowerCase(),
|
|
119
|
+
isPinProtected: messageThread.is_pin_protected,
|
|
120
|
+
relatedPageThread: messageThread.related_page_thread,
|
|
121
|
+
name: messageThread.name,
|
|
122
|
+
snippet: snippetText,
|
|
123
|
+
snippetSender: snippetID,
|
|
124
|
+
snippetAttachments: [],
|
|
125
|
+
serverTimestamp: messageThread.updated_time_precise,
|
|
126
|
+
imageSrc: messageThread.image ? messageThread.image.uri : null,
|
|
127
|
+
isCanonicalUser: messageThread.is_canonical_neo_user,
|
|
128
|
+
isCanonical: messageThread.thread_type != "GROUP",
|
|
129
|
+
recipientsLoadable: true,
|
|
130
|
+
hasEmailParticipant: false,
|
|
131
|
+
readOnly: false,
|
|
132
|
+
canReply: messageThread.cannot_reply_reason == null,
|
|
133
|
+
lastMessageTimestamp: messageThread.last_message
|
|
134
|
+
? messageThread.last_message.timestamp_precise
|
|
135
|
+
: null,
|
|
136
|
+
lastMessageType: "message",
|
|
137
|
+
lastReadTimestamp: lastReadTimestamp,
|
|
138
|
+
threadType: messageThread.thread_type == "GROUP" ? 2 : 1,
|
|
139
|
+
inviteLink: {
|
|
140
|
+
enable: messageThread.joinable_mode
|
|
141
|
+
? messageThread.joinable_mode.mode == 1
|
|
142
|
+
: false,
|
|
143
|
+
link: messageThread.joinable_mode
|
|
144
|
+
? messageThread.joinable_mode.link
|
|
145
|
+
: null,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @param {Object} defaultFuncs
|
|
152
|
+
* @param {Object} api
|
|
153
|
+
* @param {Object} ctx
|
|
154
|
+
* @returns {function(threadID: string | string[]): Promise<Object>}
|
|
155
|
+
*/
|
|
156
|
+
export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
157
|
+
/**
|
|
158
|
+
* Retrieves information about one or more threads.
|
|
159
|
+
* @param {string|string[]} threadID A single thread ID or an array of thread IDs.
|
|
160
|
+
* @returns {Promise<Object>} A promise that resolves with an object of thread info, or a single thread object if one ID was passed.
|
|
161
|
+
*/
|
|
162
|
+
return async function getThreadInfo(threadID) {
|
|
163
|
+
const threadIDs = Array.isArray(threadID) ? threadID : [threadID];
|
|
164
|
+
|
|
165
|
+
let form = {};
|
|
166
|
+
threadIDs.forEach((t, i) => {
|
|
167
|
+
form["o" + i] = {
|
|
168
|
+
doc_id: "3449967031715030",
|
|
169
|
+
query_params: {
|
|
170
|
+
id: t,
|
|
171
|
+
message_limit: 0,
|
|
172
|
+
load_messages: false,
|
|
173
|
+
load_read_receipts: false,
|
|
174
|
+
before: null,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
form = {
|
|
180
|
+
queries: JSON.stringify(form),
|
|
181
|
+
batch_name: "MessengerGraphQLThreadFetcher",
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const resData = await defaultFuncs
|
|
186
|
+
.post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
|
|
187
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
188
|
+
|
|
189
|
+
if (resData.error) {
|
|
190
|
+
throw resData;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const threadInfos = {};
|
|
194
|
+
for (let i = resData.length - 2; i >= 0; i--) {
|
|
195
|
+
const res = resData[i];
|
|
196
|
+
if (res.error_results) continue;
|
|
197
|
+
|
|
198
|
+
const threadInfo = formatThreadGraphQLResponse(res[Object.keys(res)[0]].data);
|
|
199
|
+
if (threadInfo) {
|
|
200
|
+
threadInfos[threadInfo.threadID || threadID[threadID.length - 1 - i]] = threadInfo;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return Array.isArray(threadID) ? threadInfos : Object.values(threadInfos)[0] || null;
|
|
205
|
+
} catch (err) {
|
|
206
|
+
utils.error("getThreadInfo", err);
|
|
207
|
+
throw err;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
};
|