bb-fca 2.0.8 → 2.0.10
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/core/models/buildAPI.js +3 -3
- package/dist/core/models/buildAPI.js.map +1 -1
- package/dist/core/models/loginHelper.js +29 -28
- package/dist/core/models/loginHelper.js.map +1 -1
- package/dist/deltas/apis/create.js +9 -0
- package/dist/deltas/apis/create.js.map +1 -1
- 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 +22 -129
- package/dist/deltas/apis/posting/group.js.map +1 -1
- package/dist/deltas/apis/posting/post.js +805 -12
- package/dist/deltas/apis/posting/post.js.map +1 -1
- package/dist/index.d.ts +35 -58
- package/dist/types/deltas/apis/create.d.ts +9 -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 +1 -23
- package/dist/types/deltas/apis/posting/post.d.ts +23 -0
- package/dist/types/utils/constants.d.ts +26 -16
- package/dist/utils/constants.js +42 -29
- package/dist/utils/constants.js.map +1 -1
- package/package.json +1 -1
- package/src/core/models/buildAPI.ts +3 -3
- package/src/core/models/loginHelper.ts +32 -30
- package/src/deltas/apis/create.ts +10 -0
- 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 +56 -172
- package/src/deltas/apis/posting/post.ts +932 -33
- package/src/types/index.d.ts +35 -58
- package/src/utils/constants.ts +84 -57
- package/a.html +0 -537
- package/a.json +0 -5915
- package/src/utils/formatters.old.ts +0 -1049
- package/task.txt +0 -24
|
@@ -1,280 +1,193 @@
|
|
|
1
1
|
import utils = require('../../../utils');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @module theme
|
|
5
|
+
* @description Manages or sets the custom theme for a Facebook thread. Made by Choru Official.
|
|
6
|
+
* @param {Object} defaultFuncs
|
|
7
|
+
* @param {Object} api
|
|
8
|
+
* @param {Object} ctx
|
|
9
|
+
*/
|
|
10
|
+
export default function theme(
|
|
11
|
+
defaultFuncs: any,
|
|
12
|
+
api: any,
|
|
13
|
+
ctx: any,
|
|
14
|
+
): Function {
|
|
4
15
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* If only a theme name/keyword is provided, it attempts to find and set the matching theme.
|
|
9
|
-
* If "list" is provided as the themeName, it lists available themes.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} themeName The name or partial name of the theme (case-insensitive), or "list" to list themes.
|
|
12
|
-
* @param {string} threadID The ID of the thread.
|
|
13
|
-
* @param {Function} [callback] Optional callback function.
|
|
14
|
-
* @param {string} [initiatorID] The ID of the user who initiated the theme change (e.g., from event.senderID).
|
|
15
|
-
* @returns {Promise<void|Array<object>|object>} A promise that resolves on success (for setting theme, with a detailed event object), or with an array of themes (for listing), or rejects on error.
|
|
16
|
+
* Fetches all available messenger thread themes.
|
|
17
|
+
* @param {string} threadID - Used for referer header.
|
|
18
|
+
* @returns {Promise<Array<object>>}
|
|
16
19
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_resolveFunc = resolve;
|
|
25
|
-
_rejectFunc = reject;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
utils.getType(callback) === 'Function' ||
|
|
30
|
-
utils.getType(callback) === 'AsyncFunction'
|
|
31
|
-
) {
|
|
32
|
-
_callback = callback;
|
|
33
|
-
_initiatorID = initiatorID;
|
|
34
|
-
} else if (
|
|
35
|
-
utils.getType(threadID) === 'Function' ||
|
|
36
|
-
utils.getType(threadID) === 'AsyncFunction'
|
|
37
|
-
) {
|
|
38
|
-
_callback = threadID;
|
|
39
|
-
threadID = null;
|
|
40
|
-
_initiatorID = callback;
|
|
41
|
-
} else if (utils.getType(callback) === 'string') {
|
|
42
|
-
_initiatorID = callback;
|
|
43
|
-
_callback = undefined;
|
|
44
|
-
} else {
|
|
45
|
-
_callback = undefined;
|
|
46
|
-
_initiatorID = undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!_callback) {
|
|
50
|
-
_callback = function(_err, _data) {
|
|
51
|
-
if (_err) _rejectFunc(_err);
|
|
52
|
-
else _resolveFunc(_data);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
_initiatorID = _initiatorID || ctx.userID;
|
|
57
|
-
|
|
58
|
-
threadID = threadID || ctx.threadID;
|
|
59
|
-
|
|
60
|
-
if (!threadID) {
|
|
61
|
-
return _callback(new Error('threadID is required to manage themes.'));
|
|
62
|
-
}
|
|
63
|
-
if (!themeName) {
|
|
64
|
-
return _callback(new Error("themeName (or 'list') is required."));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (!ctx.mqttClient) {
|
|
68
|
-
return _callback(new Error('Not connected to MQTT'));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const fetchThemes = async () => {
|
|
72
|
-
const form = {
|
|
73
|
-
fb_api_caller_class: 'RelayModern',
|
|
74
|
-
fb_api_req_friendly_name: 'MWPThreadThemeQuery_AllThemesQuery',
|
|
75
|
-
variables: JSON.stringify({ version: 'default' }),
|
|
76
|
-
server_timestamps: true,
|
|
77
|
-
doc_id: '24474714052117636',
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
try {
|
|
81
|
-
const resData = await defaultFuncs
|
|
82
|
-
.post('https://www.facebook.com/api/graphql/', ctx.jar, form, null, {
|
|
83
|
-
'x-fb-friendly-name': 'MWPThreadThemeQuery_AllThemesQuery',
|
|
84
|
-
'x-fb-lsd': ctx.lsd,
|
|
85
|
-
referer: `https://www.facebook.com/messages/t/${threadID}`,
|
|
86
|
-
})
|
|
87
|
-
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
88
|
-
|
|
89
|
-
if (resData.errors) {
|
|
90
|
-
throw new Error(JSON.stringify(resData.errors));
|
|
91
|
-
}
|
|
92
|
-
if (!resData.data || !resData.data.messenger_thread_themes) {
|
|
93
|
-
throw new Error('Could not retrieve thread themes from response.');
|
|
94
|
-
}
|
|
95
|
-
return resData.data.messenger_thread_themes
|
|
96
|
-
.map((themeData) => {
|
|
97
|
-
if (!themeData || !themeData.id) return null;
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
id: themeData.id,
|
|
101
|
-
name: themeData.accessibility_label,
|
|
102
|
-
description: themeData.description,
|
|
103
|
-
appColorMode: themeData.app_color_mode,
|
|
104
|
-
composerBackgroundColor: themeData.composer_background_color,
|
|
105
|
-
backgroundGradientColors: themeData.background_gradient_colors,
|
|
106
|
-
titleBarButtonTintColor: themeData.title_bar_button_tint_color,
|
|
107
|
-
inboundMessageGradientColors:
|
|
108
|
-
themeData.inbound_message_gradient_colors,
|
|
109
|
-
titleBarTextColor: themeData.title_bar_text_color,
|
|
110
|
-
composerTintColor: themeData.composer_tint_color,
|
|
111
|
-
titleBarAttributionColor: themeData.title_bar_attribution_color,
|
|
112
|
-
composerInputBackgroundColor:
|
|
113
|
-
themeData.composer_input_background_color,
|
|
114
|
-
hotLikeColor: themeData.hot_like_color,
|
|
115
|
-
backgroundImage: themeData.background_asset?.image?.uri,
|
|
116
|
-
messageTextColor: themeData.message_text_color,
|
|
117
|
-
inboundMessageTextColor: themeData.inbound_message_text_color,
|
|
118
|
-
primaryButtonBackgroundColor:
|
|
119
|
-
themeData.primary_button_background_color,
|
|
120
|
-
titleBarBackgroundColor: themeData.title_bar_background_color,
|
|
121
|
-
tertiaryTextColor: themeData.tertiary_text_color,
|
|
122
|
-
reactionPillBackgroundColor:
|
|
123
|
-
themeData.reaction_pill_background_color,
|
|
124
|
-
secondaryTextColor: themeData.secondary_text_color,
|
|
125
|
-
fallbackColor: themeData.fallback_color,
|
|
126
|
-
gradientColors: themeData.gradient_colors,
|
|
127
|
-
normalThemeId: themeData.normal_theme_id,
|
|
128
|
-
iconAsset: themeData.icon_asset?.image?.uri,
|
|
129
|
-
};
|
|
130
|
-
})
|
|
131
|
-
.filter(Boolean);
|
|
132
|
-
} catch (fetchErr) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
`Failed to fetch theme list: ${fetchErr.message || fetchErr}`,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
20
|
+
async function fetchThemes(threadID: string): Promise<any[]> {
|
|
21
|
+
const form = {
|
|
22
|
+
fb_api_caller_class: 'RelayModern',
|
|
23
|
+
fb_api_req_friendly_name: 'MWPThreadThemeQuery_AllThemesQuery',
|
|
24
|
+
variables: JSON.stringify({ version: 'default' }),
|
|
25
|
+
server_timestamps: true,
|
|
26
|
+
doc_id: '24474714052117636',
|
|
137
27
|
};
|
|
138
28
|
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const request_id = ctx.wsReqNumber;
|
|
152
|
-
|
|
153
|
-
const queryPayload = {
|
|
154
|
-
thread_key: threadID.toString(),
|
|
155
|
-
theme_fbid: themeIDToSet.toString(),
|
|
156
|
-
sync_group: 1,
|
|
157
|
-
...payload,
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const query = {
|
|
161
|
-
failure_count: null,
|
|
162
|
-
label: label,
|
|
163
|
-
payload: JSON.stringify(queryPayload),
|
|
164
|
-
queue_name: queueName,
|
|
165
|
-
task_id: ctx.wsTaskNumber,
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const context: any = {
|
|
169
|
-
app_id: ctx.appID,
|
|
170
|
-
payload: {
|
|
171
|
-
epoch_id: currentEpochId,
|
|
172
|
-
tasks: [query],
|
|
173
|
-
version_id: '24631415369801570',
|
|
174
|
-
},
|
|
175
|
-
request_id: request_id,
|
|
176
|
-
type: 3,
|
|
177
|
-
};
|
|
178
|
-
context.payload = JSON.stringify(context.payload);
|
|
179
|
-
|
|
180
|
-
return new Promise<void>((res, rej) => {
|
|
181
|
-
ctx.mqttClient.publish(
|
|
182
|
-
'/ls_req',
|
|
183
|
-
JSON.stringify(context),
|
|
184
|
-
{ qos: 1, retain: false },
|
|
185
|
-
(err) => {
|
|
186
|
-
if (err) {
|
|
187
|
-
return rej(
|
|
188
|
-
new Error(
|
|
189
|
-
`MQTT publish failed for request ${request_id}: ${err.message}`,
|
|
190
|
-
),
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
res();
|
|
194
|
-
},
|
|
195
|
-
);
|
|
196
|
-
});
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
await Promise.all([
|
|
201
|
-
createAndPublish('1013', `ai_generated_theme`, {}),
|
|
202
|
-
createAndPublish('1037', `msgr_custom_thread_theme`, {}),
|
|
203
|
-
createAndPublish('1028', `thread_theme_writer`, {}),
|
|
204
|
-
createAndPublish('43', `thread_theme`, {
|
|
205
|
-
source: null,
|
|
206
|
-
payload: null,
|
|
207
|
-
}),
|
|
208
|
-
]);
|
|
29
|
+
const resData = await defaultFuncs
|
|
30
|
+
.post('https://www.facebook.com/api/graphql/', ctx.jar, form, null, {
|
|
31
|
+
'x-fb-friendly-name': 'MWPThreadThemeQuery_AllThemesQuery',
|
|
32
|
+
'x-fb-lsd': ctx.lsd,
|
|
33
|
+
referer: `https://www.facebook.com/messages/t/${threadID}`,
|
|
34
|
+
})
|
|
35
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
36
|
+
|
|
37
|
+
if (resData?.errors) throw new Error(JSON.stringify(resData.errors));
|
|
38
|
+
if (!resData?.data?.messenger_thread_themes) {
|
|
39
|
+
throw new Error('Could not retrieve thread themes from response.');
|
|
40
|
+
}
|
|
209
41
|
|
|
42
|
+
return resData.data.messenger_thread_themes
|
|
43
|
+
.map((themeData: any) => {
|
|
44
|
+
if (!themeData?.id) return null;
|
|
210
45
|
return {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
46
|
+
id: themeData.id,
|
|
47
|
+
name: themeData.accessibility_label,
|
|
48
|
+
description: themeData.description,
|
|
49
|
+
appColorMode: themeData.app_color_mode,
|
|
50
|
+
composerBackgroundColor: themeData.composer_background_color,
|
|
51
|
+
backgroundGradientColors: themeData.background_gradient_colors,
|
|
52
|
+
titleBarButtonTintColor: themeData.title_bar_button_tint_color,
|
|
53
|
+
inboundMessageGradientColors: themeData.inbound_message_gradient_colors,
|
|
54
|
+
titleBarTextColor: themeData.title_bar_text_color,
|
|
55
|
+
composerTintColor: themeData.composer_tint_color,
|
|
56
|
+
titleBarAttributionColor: themeData.title_bar_attribution_color,
|
|
57
|
+
composerInputBackgroundColor: themeData.composer_input_background_color,
|
|
58
|
+
hotLikeColor: themeData.hot_like_color,
|
|
59
|
+
backgroundImage: themeData.background_asset?.image?.uri,
|
|
60
|
+
messageTextColor: themeData.message_text_color,
|
|
61
|
+
inboundMessageTextColor: themeData.inbound_message_text_color,
|
|
62
|
+
primaryButtonBackgroundColor: themeData.primary_button_background_color,
|
|
63
|
+
titleBarBackgroundColor: themeData.title_bar_background_color,
|
|
64
|
+
tertiaryTextColor: themeData.tertiary_text_color,
|
|
65
|
+
reactionPillBackgroundColor: themeData.reaction_pill_background_color,
|
|
66
|
+
secondaryTextColor: themeData.secondary_text_color,
|
|
67
|
+
fallbackColor: themeData.fallback_color,
|
|
68
|
+
gradientColors: themeData.gradient_colors,
|
|
69
|
+
normalThemeId: themeData.normal_theme_id,
|
|
70
|
+
iconAsset: themeData.icon_asset?.image?.uri,
|
|
218
71
|
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
72
|
+
})
|
|
73
|
+
.filter(Boolean);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Publishes a single MQTT message to change the thread theme.
|
|
78
|
+
*/
|
|
79
|
+
function publishThemeMqtt(
|
|
80
|
+
label: string,
|
|
81
|
+
queueName: string,
|
|
82
|
+
extraPayload: Record<string, any>,
|
|
83
|
+
threadID: string,
|
|
84
|
+
themeIDToSet: string,
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
ctx.wsReqNumber += 1;
|
|
87
|
+
ctx.wsTaskNumber += 1;
|
|
88
|
+
|
|
89
|
+
const queryPayload = {
|
|
90
|
+
thread_key: threadID.toString(),
|
|
91
|
+
theme_fbid: themeIDToSet.toString(),
|
|
92
|
+
sync_group: 1,
|
|
93
|
+
...extraPayload,
|
|
225
94
|
};
|
|
226
95
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
96
|
+
const query = {
|
|
97
|
+
failure_count: null,
|
|
98
|
+
label,
|
|
99
|
+
payload: JSON.stringify(queryPayload),
|
|
100
|
+
queue_name: queueName,
|
|
101
|
+
task_id: ctx.wsTaskNumber,
|
|
102
|
+
};
|
|
234
103
|
|
|
235
|
-
|
|
104
|
+
const context: any = {
|
|
105
|
+
app_id: ctx.appID,
|
|
106
|
+
payload: {
|
|
107
|
+
epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
|
|
108
|
+
tasks: [query],
|
|
109
|
+
version_id: '24631415369801570',
|
|
110
|
+
},
|
|
111
|
+
request_id: ctx.wsReqNumber,
|
|
112
|
+
type: 3,
|
|
113
|
+
};
|
|
114
|
+
context.payload = JSON.stringify(context.payload);
|
|
115
|
+
|
|
116
|
+
return new Promise<void>((resolve, reject) =>
|
|
117
|
+
ctx.mqttClient.publish(
|
|
118
|
+
'/ls_req',
|
|
119
|
+
JSON.stringify(context),
|
|
120
|
+
{ qos: 1, retain: false },
|
|
121
|
+
(err) =>
|
|
122
|
+
err
|
|
123
|
+
? reject(new Error(`MQTT publish failed for label ${label}: ${err.message ?? err}`))
|
|
124
|
+
: resolve(),
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
236
128
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Sends all 4 MQTT messages required to apply a theme change and returns an event object.
|
|
131
|
+
*/
|
|
132
|
+
async function setThreadTheme(
|
|
133
|
+
themeIDToSet: string,
|
|
134
|
+
actualThemeName: string,
|
|
135
|
+
threadID: string,
|
|
136
|
+
initiatorID: string,
|
|
137
|
+
): Promise<any> {
|
|
138
|
+
await Promise.all([
|
|
139
|
+
publishThemeMqtt('1013', 'ai_generated_theme', {}, threadID, themeIDToSet),
|
|
140
|
+
publishThemeMqtt('1037', 'msgr_custom_thread_theme', {}, threadID, themeIDToSet),
|
|
141
|
+
publishThemeMqtt('1028', 'thread_theme_writer', {}, threadID, themeIDToSet),
|
|
142
|
+
publishThemeMqtt('43', 'thread_theme', { source: null, payload: null }, threadID, themeIDToSet),
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
type: 'thread_theme_update',
|
|
147
|
+
threadID,
|
|
148
|
+
themeID: themeIDToSet,
|
|
149
|
+
themeName: actualThemeName,
|
|
150
|
+
senderID: initiatorID,
|
|
151
|
+
BotID: ctx.userID,
|
|
152
|
+
timestamp: Date.now(),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
245
155
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Sets or lists thread themes.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} themeName - Theme name/keyword to set, or "list" to list all available themes.
|
|
160
|
+
* @param {string} threadID - The ID of the thread.
|
|
161
|
+
* @param {string} [initiatorID] - The ID of the user initiating the change.
|
|
162
|
+
* @returns {Promise<object|Array<object>>}
|
|
163
|
+
*/
|
|
164
|
+
return async function setTheme(
|
|
165
|
+
themeName: string,
|
|
166
|
+
threadID: string,
|
|
167
|
+
initiatorID?: string,
|
|
168
|
+
): Promise<any> {
|
|
169
|
+
if (!threadID) throw new Error('threadID is required to manage themes.');
|
|
170
|
+
if (!themeName) throw new Error("themeName (or 'list') is required.");
|
|
171
|
+
if (!ctx.mqttClient) throw new Error('Not connected to MQTT');
|
|
172
|
+
|
|
173
|
+
const _initiatorID = initiatorID ?? ctx.userID;
|
|
174
|
+
|
|
175
|
+
if (themeName.toLowerCase() === 'list') {
|
|
176
|
+
return fetchThemes(threadID);
|
|
177
|
+
}
|
|
251
178
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
`Theme "${themeName}" not found. Try '/theme list' for available themes.`,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
179
|
+
const themes = await fetchThemes(threadID);
|
|
180
|
+
const normalizedThemeName = themeName.toLowerCase();
|
|
257
181
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
);
|
|
182
|
+
let matchedTheme =
|
|
183
|
+
themes.find((t) => t.id === normalizedThemeName) ??
|
|
184
|
+
themes.find((t) => t.name.toLowerCase() === normalizedThemeName) ??
|
|
185
|
+
themes.find((t) => t.name.toLowerCase().includes(normalizedThemeName));
|
|
263
186
|
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
} catch (err) {
|
|
267
|
-
const finalError =
|
|
268
|
-
err instanceof Error
|
|
269
|
-
? err
|
|
270
|
-
: new Error(
|
|
271
|
-
err.message ||
|
|
272
|
-
err.error ||
|
|
273
|
-
'An unknown error occurred during theme operation.',
|
|
274
|
-
);
|
|
275
|
-
_callback(finalError);
|
|
187
|
+
if (!matchedTheme) {
|
|
188
|
+
throw new Error(`Theme "${themeName}" not found. Try 'list' for available themes.`);
|
|
276
189
|
}
|
|
277
190
|
|
|
278
|
-
return
|
|
191
|
+
return setThreadTheme(matchedTheme.id, matchedTheme.name, threadID, _initiatorID);
|
|
279
192
|
};
|
|
280
193
|
}
|
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import utils = require(
|
|
1
|
+
import utils = require('../../../utils');
|
|
2
2
|
// @NethWs3Dev
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @param {Object} defaultFuncs
|
|
6
|
+
* @param {Object} api
|
|
7
|
+
* @param {Object} ctx
|
|
8
|
+
*/
|
|
9
|
+
export default function unsendMessage(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
14
|
+
/**
|
|
15
|
+
* Unsends (deletes for everyone) a message sent by the bot.
|
|
16
|
+
* @param {string} messageID - The ID of the message to unsend.
|
|
17
|
+
* @returns {Promise<any>}
|
|
18
|
+
*/
|
|
19
|
+
return async function unsendMessage(messageID: string): Promise<any> {
|
|
20
|
+
const defData = await defaultFuncs.post(
|
|
21
|
+
'https://www.facebook.com/messaging/unsend_message/',
|
|
22
|
+
ctx.jar,
|
|
23
|
+
{ message_id: messageID },
|
|
24
|
+
);
|
|
9
25
|
const resData = await utils.parseAndCheckLogin(ctx, defaultFuncs)(defData);
|
|
10
26
|
if (resData.error) {
|
|
11
27
|
throw new Error(resData);
|
|
12
28
|
}
|
|
13
29
|
return resData;
|
|
14
30
|
};
|
|
15
|
-
}
|
|
31
|
+
}
|