shadowx-fca 2.4.0 → 2.6.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/checkUpdate.js +1 -1
- package/index.js +663 -418
- package/package.json +2 -2
- package/src/GetBotInfo.js +66 -0
- package/src/OldMessage.js +96 -76
- package/src/comment.js +226 -0
- package/src/emoji.js +124 -0
- package/src/friend.js +243 -0
- package/src/gcmember.js +122 -0
- package/src/listenMqtt.js +4 -4
- package/src/nickname.js +140 -0
- package/src/sendMessage.js +398 -234
- package/src/sendMessage2.js +243 -0
- package/src/share.js +62 -0
- package/src/shareContact.js +73 -69
- package/src/shareContact.js.bak +110 -0
- package/src/stickers.js +117 -0
- package/src/story.js +181 -0
- package/src/theme.js +233 -0
- package/utils.js +24 -1311
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
// @NethWs3Dev
|
|
5
|
+
|
|
6
|
+
const allowedProperties = {
|
|
7
|
+
attachment: true,
|
|
8
|
+
url: true,
|
|
9
|
+
sticker: true,
|
|
10
|
+
emoji: true,
|
|
11
|
+
emojiSize: true,
|
|
12
|
+
body: true,
|
|
13
|
+
mentions: true,
|
|
14
|
+
location: true,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports = (defaultFuncs, api, ctx) => {
|
|
18
|
+
async function uploadAttachment(attachments) {
|
|
19
|
+
var uploads = [];
|
|
20
|
+
for (var i = 0; i < attachments.length; i++) {
|
|
21
|
+
if (!utils.isReadableStream(attachments[i])) {
|
|
22
|
+
throw new Error("Attachment should be a readable stream and not " + utils.getType(attachments[i]) + ".");
|
|
23
|
+
}
|
|
24
|
+
const oksir = await defaultFuncs.postFormData("https://upload.facebook.com/ajax/mercury/upload.php", ctx.jar,{
|
|
25
|
+
upload_1024: attachments[i],
|
|
26
|
+
voice_clip: "true"
|
|
27
|
+
}, {}).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
28
|
+
if (oksir.error) {
|
|
29
|
+
throw new Error(resData);
|
|
30
|
+
}
|
|
31
|
+
uploads.push(oksir.payload.metadata[0]);
|
|
32
|
+
}
|
|
33
|
+
return uploads;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function getUrl(url) {
|
|
37
|
+
const resData = await defaultFuncs.post("https://www.facebook.com/message_share_attachment/fromURI/", ctx.jar, {
|
|
38
|
+
image_height: 960,
|
|
39
|
+
image_width: 960,
|
|
40
|
+
uri: url
|
|
41
|
+
}).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
42
|
+
if (!resData || resData.error || !resData.payload){
|
|
43
|
+
throw new Error(resData);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function sendContent(form, threadID, isSingleUser, messageAndOTID, callback) {
|
|
48
|
+
// There are three cases here:
|
|
49
|
+
// 1. threadID is of type array, where we're starting a new group chat with users
|
|
50
|
+
// specified in the array.
|
|
51
|
+
// 2. User is sending a message to a specific user.
|
|
52
|
+
// 3. No additional form params and the message goes to an existing group chat.
|
|
53
|
+
if (utils.getType(threadID) === "Array") {
|
|
54
|
+
for (var i = 0; i < threadID.length; i++) {
|
|
55
|
+
form["specific_to_list[" + i + "]"] = "fbid:" + threadID[i];
|
|
56
|
+
}
|
|
57
|
+
form["specific_to_list[" + threadID.length + "]"] = "fbid:" + ctx.userID;
|
|
58
|
+
form["client_thread_id"] = "root:" + messageAndOTID;
|
|
59
|
+
utils.log("sendMessage", "Sending message to multiple users: " + threadID);
|
|
60
|
+
} else {
|
|
61
|
+
const threadIDStr = threadID.toString();
|
|
62
|
+
// Check if it's a DM: doesn't start with numeric group ID pattern or explicitly marked as single user
|
|
63
|
+
const isDM = !threadIDStr.match(/^\d{15,}$/) || isSingleUser === true;
|
|
64
|
+
|
|
65
|
+
// This means that threadID is the id of a user, and the chat
|
|
66
|
+
// is a single person chat
|
|
67
|
+
if (isDM) {
|
|
68
|
+
form["specific_to_list[0]"] = "fbid:" + threadID;
|
|
69
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.userID;
|
|
70
|
+
form["other_user_fbid"] = threadID;
|
|
71
|
+
} else {
|
|
72
|
+
form["thread_fbid"] = threadID;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (ctx.globalOptions.pageID) {
|
|
77
|
+
form["author"] = "fbid:" + ctx.globalOptions.pageID;
|
|
78
|
+
form["specific_to_list[1]"] = "fbid:" + ctx.globalOptions.pageID;
|
|
79
|
+
form["creator_info[creatorID]"] = ctx.userID;
|
|
80
|
+
form["creator_info[creatorType]"] = "direct_admin";
|
|
81
|
+
form["creator_info[labelType]"] = "sent_message";
|
|
82
|
+
form["creator_info[pageID]"] = ctx.globalOptions.pageID;
|
|
83
|
+
form["request_user_id"] = ctx.globalOptions.pageID;
|
|
84
|
+
form["creator_info[profileURI]"] =
|
|
85
|
+
"https://www.facebook.com/profile.php?id=" + ctx.userID;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const resData = await defaultFuncs.post("https://www.facebook.com/messaging/send/", ctx.jar, form).then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
89
|
+
if (!resData) {
|
|
90
|
+
throw new Error("Send message failed.");
|
|
91
|
+
}
|
|
92
|
+
if (resData.error) {
|
|
93
|
+
if (resData.error === 1545012) {
|
|
94
|
+
utils.warn("sendMessage", "Got error 1545012. This might mean that you're not part of the conversation " + threadID);
|
|
95
|
+
throw new Error(`Cannot send message to thread ${threadID}: Bot is not part of this conversation (Error 1545012)`);
|
|
96
|
+
}
|
|
97
|
+
throw new Error(resData);
|
|
98
|
+
}
|
|
99
|
+
const messageInfo = resData.payload.actions.reduce((p, v) => {
|
|
100
|
+
return { threadID: v.thread_fbid, messageID: v.message_id, timestamp: v.timestamp } || p;
|
|
101
|
+
}, null);
|
|
102
|
+
return messageInfo;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return async (msg, threadID, callback, replyToMessage, isSingleUser = null) => {
|
|
106
|
+
// Handle different parameter patterns for backward compatibility
|
|
107
|
+
if (typeof callback === "string" || (callback && typeof callback === "object")) {
|
|
108
|
+
// callback is actually replyToMessage, shift parameters
|
|
109
|
+
isSingleUser = replyToMessage;
|
|
110
|
+
replyToMessage = callback;
|
|
111
|
+
callback = function() {};
|
|
112
|
+
} else if (typeof callback !== "function") {
|
|
113
|
+
callback = function() {};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let msgType = utils.getType(msg);
|
|
117
|
+
let threadIDType = utils.getType(threadID);
|
|
118
|
+
let messageIDType = utils.getType(replyToMessage);
|
|
119
|
+
if (msgType !== "String" && msgType !== "Object") throw new Error("Message should be of type string or object and not " + msgType + ".");
|
|
120
|
+
if (threadIDType !== "Array" && threadIDType !== "Number" && threadIDType !== "String") throw new Error("ThreadID should be of type number, string, or array and not " + threadIDType + ".");
|
|
121
|
+
if (replyToMessage && messageIDType !== 'String' && messageIDType !== 'string') throw new Error("MessageID should be of type string and not " + messageIDType + ".");
|
|
122
|
+
if (msgType === "String") {
|
|
123
|
+
msg = { body: msg };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Auto-detect if this is a DM if not explicitly specified
|
|
127
|
+
if (isSingleUser === null && ctx.threadTypes && ctx.threadTypes[threadID]) {
|
|
128
|
+
isSingleUser = ctx.threadTypes[threadID] === 'dm';
|
|
129
|
+
} else if (isSingleUser === null) {
|
|
130
|
+
// Fallback: check if threadID looks like a user ID (15 digits) vs group ID (longer)
|
|
131
|
+
const threadIDStr = threadID.toString();
|
|
132
|
+
isSingleUser = threadIDStr.length === 15 || !threadIDStr.match(/^\d{16,}$/);
|
|
133
|
+
}
|
|
134
|
+
let disallowedProperties = Object.keys(msg).filter(prop => !allowedProperties[prop]);
|
|
135
|
+
if (disallowedProperties.length > 0) {
|
|
136
|
+
throw new Error("Dissallowed props: `" + disallowedProperties.join(", ") + "`");
|
|
137
|
+
}
|
|
138
|
+
let messageAndOTID = utils.generateOfflineThreadingID();
|
|
139
|
+
let form = {
|
|
140
|
+
client: "mercury",
|
|
141
|
+
action_type: "ma-type:user-generated-message",
|
|
142
|
+
author: "fbid:" + ctx.userID,
|
|
143
|
+
timestamp: Date.now(),
|
|
144
|
+
timestamp_absolute: "Today",
|
|
145
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
146
|
+
timestamp_time_passed: "0",
|
|
147
|
+
is_unread: false,
|
|
148
|
+
is_cleared: false,
|
|
149
|
+
is_forward: false,
|
|
150
|
+
is_filtered_content: false,
|
|
151
|
+
is_filtered_content_bh: false,
|
|
152
|
+
is_filtered_content_account: false,
|
|
153
|
+
is_filtered_content_quasar: false,
|
|
154
|
+
is_filtered_content_invalid_app: false,
|
|
155
|
+
is_spoof_warning: false,
|
|
156
|
+
source: "source:chat:web",
|
|
157
|
+
"source_tags[0]": "source:chat",
|
|
158
|
+
...(msg.body && {
|
|
159
|
+
body: msg.body
|
|
160
|
+
}),
|
|
161
|
+
html_body: false,
|
|
162
|
+
ui_push_phase: "V3",
|
|
163
|
+
status: "0",
|
|
164
|
+
offline_threading_id: messageAndOTID,
|
|
165
|
+
message_id: messageAndOTID,
|
|
166
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
|
167
|
+
"ephemeral_ttl_mode:": "0",
|
|
168
|
+
manual_retry_cnt: "0",
|
|
169
|
+
has_attachment: !!(msg.attachment || msg.url || msg.sticker),
|
|
170
|
+
signatureID: utils.getSignatureID(),
|
|
171
|
+
...(replyToMessage && {
|
|
172
|
+
replied_to_message_id: replyToMessage
|
|
173
|
+
})
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (msg.location) {
|
|
177
|
+
if (!msg.location.latitude || !msg.location.longitude) throw new Error("location property needs both latitude and longitude");
|
|
178
|
+
form["location_attachment[coordinates][latitude]"] = msg.location.latitude;
|
|
179
|
+
form["location_attachment[coordinates][longitude]"] = msg.location.longitude;
|
|
180
|
+
form["location_attachment[is_current_location]"] = !!msg.location.current;
|
|
181
|
+
}
|
|
182
|
+
if (msg.sticker) {
|
|
183
|
+
form["sticker_id"] = msg.sticker;
|
|
184
|
+
}
|
|
185
|
+
if (msg.attachment) {
|
|
186
|
+
form.image_ids = [];
|
|
187
|
+
form.gif_ids = [];
|
|
188
|
+
form.file_ids = [];
|
|
189
|
+
form.video_ids = [];
|
|
190
|
+
form.audio_ids = [];
|
|
191
|
+
if (utils.getType(msg.attachment) !== "Array") {
|
|
192
|
+
msg.attachment = [msg.attachment];
|
|
193
|
+
}
|
|
194
|
+
const files = await uploadAttachment(msg.attachment);
|
|
195
|
+
files.forEach(file => {
|
|
196
|
+
const type = Object.keys(file)[0];
|
|
197
|
+
form["" + type + "s"].push(file[type]);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (msg.url) {
|
|
201
|
+
form["shareable_attachment[share_type]"] = "100";
|
|
202
|
+
const params = await getUrl(msg.url);
|
|
203
|
+
form["shareable_attachment[share_params]"] = params;
|
|
204
|
+
}
|
|
205
|
+
if (msg.emoji) {
|
|
206
|
+
if (!msg.emojiSize) {
|
|
207
|
+
msg.emojiSize = "medium";
|
|
208
|
+
}
|
|
209
|
+
if (msg.emojiSize !== "small" && msg.emojiSize !== "medium" && msg.emojiSize !== "large") {
|
|
210
|
+
throw new Error("emojiSize property is invalid");
|
|
211
|
+
}
|
|
212
|
+
if (!form.body) {
|
|
213
|
+
throw new Error("body is not empty");
|
|
214
|
+
}
|
|
215
|
+
form.body = msg.emoji;
|
|
216
|
+
form["tags[0]"] = "hot_emoji_size:" + msg.emojiSize;
|
|
217
|
+
}
|
|
218
|
+
if (msg.mentions) {
|
|
219
|
+
for (let i = 0; i < msg.mentions.length; i++) {
|
|
220
|
+
const mention = msg.mentions[i];
|
|
221
|
+
const tag = mention.tag;
|
|
222
|
+
if (typeof tag !== "string") {
|
|
223
|
+
throw new Error("Mention tags must be strings.");
|
|
224
|
+
}
|
|
225
|
+
const offset = msg.body.indexOf(tag, mention.fromIndex || 0);
|
|
226
|
+
if (offset < 0) utils.warn("handleMention", 'Mention for "' + tag + '" not found in message string.');
|
|
227
|
+
if (!mention.id) utils.warn("handleMention", "Mention id should be non-null.");
|
|
228
|
+
const id = mention.id || 0;
|
|
229
|
+
const emptyChar = '\u200E';
|
|
230
|
+
form["body"] = emptyChar + msg.body;
|
|
231
|
+
form["profile_xmd[" + i + "][offset]"] = offset + 1;
|
|
232
|
+
form["profile_xmd[" + i + "][length]"] = tag.length;
|
|
233
|
+
form["profile_xmd[" + i + "][id]"] = id;
|
|
234
|
+
form["profile_xmd[" + i + "][type]"] = "p";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const result = await sendContent(form, threadID, isSingleUser, messageAndOTID);
|
|
238
|
+
if (callback && typeof callback === "function") {
|
|
239
|
+
callback(null, result);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
};
|
|
243
|
+
};
|
package/src/share.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
function formatPreviewResult(data) {
|
|
6
|
+
if (data.errors) {
|
|
7
|
+
throw data.errors[0];
|
|
8
|
+
}
|
|
9
|
+
const previewData = data.data?.xma_preview_data;
|
|
10
|
+
if (!previewData) {
|
|
11
|
+
throw { error: "Could not generate a preview for this post." };
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
postID: previewData.post_id,
|
|
15
|
+
header: previewData.header_title,
|
|
16
|
+
subtitle: previewData.subtitle_text,
|
|
17
|
+
title: previewData.title_text,
|
|
18
|
+
previewImage: previewData.preview_url,
|
|
19
|
+
favicon: previewData.favicon_url,
|
|
20
|
+
headerImage: previewData.header_image_url
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
25
|
+
return async function getPostPreview(postID, callback) {
|
|
26
|
+
let cb;
|
|
27
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
28
|
+
cb = (err, data) => err ? reject(err) : resolve(data);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (typeof callback === 'function') cb = callback;
|
|
32
|
+
if (!postID) {
|
|
33
|
+
return cb({ error: "A postID is required to generate a preview." });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const variables = {
|
|
37
|
+
shareable_id: postID.toString(),
|
|
38
|
+
scale: 3,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const form = {
|
|
42
|
+
fb_api_caller_class: 'RelayModern',
|
|
43
|
+
fb_api_req_friendly_name: 'CometXMAProxyShareablePreviewQuery',
|
|
44
|
+
variables: JSON.stringify(variables),
|
|
45
|
+
doc_id: '28939050904374351'
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const resData = await defaultFuncs
|
|
50
|
+
.post("https://www.facebook.com/api/graphql/", ctx.jar, form)
|
|
51
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs));
|
|
52
|
+
|
|
53
|
+
const result = formatPreviewResult(resData);
|
|
54
|
+
return cb(null, result);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
utils.error("getPostPreview", err);
|
|
57
|
+
return cb(err);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return returnPromise;
|
|
61
|
+
};
|
|
62
|
+
};
|
package/src/shareContact.js
CHANGED
|
@@ -4,39 +4,87 @@
|
|
|
4
4
|
// fixed by kenneth panio
|
|
5
5
|
|
|
6
6
|
var utils = require("../utils");
|
|
7
|
+
var log = require("npmlog");
|
|
7
8
|
|
|
8
9
|
module.exports = function(defaultFuncs, api, ctx) {
|
|
9
10
|
return function shareContact(text, senderID, threadID, callback) {
|
|
11
|
+
let _callback;
|
|
12
|
+
let _resolvePromise;
|
|
13
|
+
let _rejectPromise;
|
|
14
|
+
|
|
15
|
+
const returnPromise = new Promise((resolve, reject) => {
|
|
16
|
+
_resolvePromise = resolve;
|
|
17
|
+
_rejectPromise = reject;
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Setup callback with Promise support
|
|
21
|
+
if (typeof callback === 'function') {
|
|
22
|
+
_callback = (err, data) => {
|
|
23
|
+
if (err) {
|
|
24
|
+
callback(err);
|
|
25
|
+
_rejectPromise(err);
|
|
26
|
+
} else {
|
|
27
|
+
callback(null, data);
|
|
28
|
+
_resolvePromise(data);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
} else {
|
|
32
|
+
_callback = (err, data) => {
|
|
33
|
+
if (err) _rejectPromise(err);
|
|
34
|
+
else _resolvePromise(data);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Validation
|
|
10
39
|
if (!ctx.mqttClient) {
|
|
11
|
-
|
|
40
|
+
const error = new Error('Not connected to MQTT');
|
|
41
|
+
log.error('shareContact', error);
|
|
42
|
+
_callback(error);
|
|
43
|
+
return returnPromise;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!senderID) {
|
|
47
|
+
const error = new Error('senderID is required');
|
|
48
|
+
log.error('shareContact', error);
|
|
49
|
+
_callback(error);
|
|
50
|
+
return returnPromise;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!threadID) {
|
|
54
|
+
const error = new Error('threadID is required');
|
|
55
|
+
log.error('shareContact', error);
|
|
56
|
+
_callback(error);
|
|
57
|
+
return returnPromise;
|
|
12
58
|
}
|
|
13
59
|
|
|
14
|
-
|
|
15
|
-
ctx.
|
|
60
|
+
// Initialize counters (fixed for compatibility)
|
|
61
|
+
ctx.wsReqNumber = ctx.wsReqNumber || 0;
|
|
62
|
+
ctx.wsTaskNumber = ctx.wsTaskNumber || 0;
|
|
63
|
+
ctx.callback_Task = ctx.callback_Task || {};
|
|
16
64
|
|
|
17
65
|
ctx.wsReqNumber += 1;
|
|
18
66
|
ctx.wsTaskNumber += 1;
|
|
19
67
|
|
|
20
68
|
const queryPayload = {
|
|
21
|
-
contact_id: senderID,
|
|
69
|
+
contact_id: String(senderID),
|
|
22
70
|
sync_group: 1,
|
|
23
71
|
text: text || "",
|
|
24
|
-
thread_id: threadID
|
|
72
|
+
thread_id: String(threadID)
|
|
25
73
|
};
|
|
26
74
|
|
|
27
75
|
const query = {
|
|
28
76
|
failure_count: null,
|
|
29
77
|
label: '359',
|
|
30
78
|
payload: JSON.stringify(queryPayload),
|
|
31
|
-
queue_name:
|
|
32
|
-
task_id:
|
|
79
|
+
queue_name: String(threadID), // Use threadID for queue_name
|
|
80
|
+
task_id: ctx.wsTaskNumber, // Use consistent counter instead of random
|
|
33
81
|
};
|
|
34
82
|
|
|
35
83
|
const context = {
|
|
36
|
-
app_id: '2220391788200892',
|
|
84
|
+
app_id: ctx.appID || '2220391788200892',
|
|
37
85
|
payload: {
|
|
38
86
|
tasks: [query],
|
|
39
|
-
epoch_id: utils.generateOfflineThreadingID(),
|
|
87
|
+
epoch_id: parseInt(utils.generateOfflineThreadingID()) || Date.now(),
|
|
40
88
|
version_id: '7214102258676893',
|
|
41
89
|
},
|
|
42
90
|
request_id: ctx.wsReqNumber,
|
|
@@ -45,66 +93,22 @@ module.exports = function(defaultFuncs, api, ctx) {
|
|
|
45
93
|
|
|
46
94
|
context.payload = JSON.stringify(context.payload);
|
|
47
95
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/*"use strict";
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var utils = require("../utils");
|
|
60
|
-
|
|
61
|
-
// @NethWs3Dev
|
|
96
|
+
// Store callback for response
|
|
97
|
+
ctx.callback_Task[ctx.wsReqNumber] = {
|
|
98
|
+
callback: _callback,
|
|
99
|
+
type: "shareContact"
|
|
100
|
+
};
|
|
62
101
|
|
|
102
|
+
log.info('shareContact', `Sharing contact ${senderID} to thread ${threadID}`);
|
|
63
103
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
104
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false }, (err) => {
|
|
105
|
+
if (err) {
|
|
106
|
+
log.error('shareContact', `MQTT publish failed: ${err.message || err}`);
|
|
107
|
+
delete ctx.callback_Task[ctx.wsReqNumber];
|
|
108
|
+
_callback(new Error(`MQTT publish failed: ${err.message || err}`));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
68
111
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var resolveFunc = function () { };
|
|
73
|
-
var rejectFunc = function () { };
|
|
74
|
-
var returnPromise = new Promise(function (resolve, reject) {
|
|
75
|
-
resolveFunc = resolve;
|
|
76
|
-
rejectFunc = reject;
|
|
77
|
-
});
|
|
78
|
-
if (!callback) {
|
|
79
|
-
callback = function (err, data) {
|
|
80
|
-
if (err) return rejectFunc(err);
|
|
81
|
-
resolveFunc(data);
|
|
82
|
-
data };
|
|
83
|
-
}
|
|
84
|
-
let count_req = 0
|
|
85
|
-
var form = JSON.stringify({
|
|
86
|
-
"app_id": "2220391788200892",
|
|
87
|
-
"payload": JSON.stringify({
|
|
88
|
-
tasks: [{
|
|
89
|
-
label: '359',
|
|
90
|
-
payload: JSON.stringify({
|
|
91
|
-
"contact_id": senderID,
|
|
92
|
-
"sync_group": 1,
|
|
93
|
-
"text": text || "",
|
|
94
|
-
"thread_id": threadID
|
|
95
|
-
}),
|
|
96
|
-
queue_name: 'messenger_contact_sharing',
|
|
97
|
-
task_id: Math.random() * 1001 << 0,
|
|
98
|
-
failure_count: null,
|
|
99
|
-
}],
|
|
100
|
-
epoch_id: utils.generateOfflineThreadingID(),
|
|
101
|
-
version_id: '7214102258676893',
|
|
102
|
-
}),
|
|
103
|
-
"request_id": ++count_req,
|
|
104
|
-
"type": 3
|
|
105
|
-
});
|
|
106
|
-
mqttClient.publish('/ls_req',form)
|
|
107
|
-
|
|
108
|
-
return returnPromise;
|
|
109
|
-
};
|
|
110
|
-
};*/
|
|
112
|
+
return returnPromise;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* eslint-disable linebreak-style */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// fixed by kenneth panio
|
|
5
|
+
|
|
6
|
+
var utils = require("../utils");
|
|
7
|
+
|
|
8
|
+
module.exports = function(defaultFuncs, api, ctx) {
|
|
9
|
+
return function shareContact(text, senderID, threadID, callback) {
|
|
10
|
+
if (!ctx.mqttClient) {
|
|
11
|
+
throw new Error('Not connected to MQTT');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
ctx.wsReqNumber ??= 0;
|
|
15
|
+
ctx.wsTaskNumber ??= 0;
|
|
16
|
+
|
|
17
|
+
ctx.wsReqNumber += 1;
|
|
18
|
+
ctx.wsTaskNumber += 1;
|
|
19
|
+
|
|
20
|
+
const queryPayload = {
|
|
21
|
+
contact_id: senderID,
|
|
22
|
+
sync_group: 1,
|
|
23
|
+
text: text || "",
|
|
24
|
+
thread_id: threadID
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const query = {
|
|
28
|
+
failure_count: null,
|
|
29
|
+
label: '359',
|
|
30
|
+
payload: JSON.stringify(queryPayload),
|
|
31
|
+
queue_name: 'messenger_contact_sharing',//xma_open_contact_share
|
|
32
|
+
task_id: Math.random() * 1001 << 0,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const context = {
|
|
36
|
+
app_id: '2220391788200892',
|
|
37
|
+
payload: {
|
|
38
|
+
tasks: [query],
|
|
39
|
+
epoch_id: utils.generateOfflineThreadingID(),
|
|
40
|
+
version_id: '7214102258676893',
|
|
41
|
+
},
|
|
42
|
+
request_id: ctx.wsReqNumber,
|
|
43
|
+
type: 3,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
context.payload = JSON.stringify(context.payload);
|
|
47
|
+
|
|
48
|
+
if (typeof callback === 'function') {
|
|
49
|
+
ctx.callback_Task[ctx.wsReqNumber] = { callback, type: "shareContact" };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), { qos: 1, retain: false });
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/*"use strict";
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
var utils = require("../utils");
|
|
60
|
+
|
|
61
|
+
// @NethWs3Dev
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
module.exports = function (defaultFuncs, api, ctx) {
|
|
65
|
+
return async function shareContact(text, senderID, threadID, callback) {
|
|
66
|
+
await utils.parseAndCheckLogin(ctx, defaultFuncs);
|
|
67
|
+
const mqttClient = ctx.mqttClient;
|
|
68
|
+
|
|
69
|
+
if (!mqttClient) {
|
|
70
|
+
throw new Error("Not connected to MQTT");
|
|
71
|
+
}
|
|
72
|
+
var resolveFunc = function () { };
|
|
73
|
+
var rejectFunc = function () { };
|
|
74
|
+
var returnPromise = new Promise(function (resolve, reject) {
|
|
75
|
+
resolveFunc = resolve;
|
|
76
|
+
rejectFunc = reject;
|
|
77
|
+
});
|
|
78
|
+
if (!callback) {
|
|
79
|
+
callback = function (err, data) {
|
|
80
|
+
if (err) return rejectFunc(err);
|
|
81
|
+
resolveFunc(data);
|
|
82
|
+
data };
|
|
83
|
+
}
|
|
84
|
+
let count_req = 0
|
|
85
|
+
var form = JSON.stringify({
|
|
86
|
+
"app_id": "2220391788200892",
|
|
87
|
+
"payload": JSON.stringify({
|
|
88
|
+
tasks: [{
|
|
89
|
+
label: '359',
|
|
90
|
+
payload: JSON.stringify({
|
|
91
|
+
"contact_id": senderID,
|
|
92
|
+
"sync_group": 1,
|
|
93
|
+
"text": text || "",
|
|
94
|
+
"thread_id": threadID
|
|
95
|
+
}),
|
|
96
|
+
queue_name: 'messenger_contact_sharing',
|
|
97
|
+
task_id: Math.random() * 1001 << 0,
|
|
98
|
+
failure_count: null,
|
|
99
|
+
}],
|
|
100
|
+
epoch_id: utils.generateOfflineThreadingID(),
|
|
101
|
+
version_id: '7214102258676893',
|
|
102
|
+
}),
|
|
103
|
+
"request_id": ++count_req,
|
|
104
|
+
"type": 3
|
|
105
|
+
});
|
|
106
|
+
mqttClient.publish('/ls_req',form)
|
|
107
|
+
|
|
108
|
+
return returnPromise;
|
|
109
|
+
};
|
|
110
|
+
};*/
|