@dongdev/fca-unofficial 0.0.6 → 0.0.8

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.
@@ -4,78 +4,63 @@ const utils = require("../utils");
4
4
  const log = require("npmlog");
5
5
 
6
6
  module.exports = function (defaultFuncs, api, ctx) {
7
- /**
8
- * Refreshes the fb_dtsg and jazoest values.
9
- * @param {Function} callback
10
- * @returns {Promise}
11
- * @description if you don't update the value of fb_dtsg and jazoest for a long time an error "Please try closing and re-opening your browser window" will appear
12
- * @description you should refresh it every 48h or less
13
- */
14
- return function refreshFb_dtsg(obj, callback) {
15
- let resolveFunc = function () { };
16
- let rejectFunc = function () { };
17
- const returnPromise = new Promise(function (resolve, reject) {
18
- resolveFunc = resolve;
19
- rejectFunc = reject;
20
- });
21
-
22
- if (utils.getType(obj) === "Function" || utils.getType(obj) === "AsyncFunction") {
23
- callback = obj;
24
- obj = {};
25
- }
26
-
27
- if (!obj) {
28
- obj = {};
29
- }
30
-
31
- if (utils.getType(obj) !== "Object") {
32
- throw new utils.CustomError("the first parameter must be an object or a callback function");
33
- }
34
-
35
- if (!callback) {
36
- callback = function (err, friendList) {
37
- if (err) {
38
- return rejectFunc(err);
39
- }
40
- resolveFunc(friendList);
41
- };
42
- }
43
-
44
- if (Object.keys(obj).length == 0) {
45
- utils
46
- .get('https://m.facebook.com/', ctx.jar, null, ctx.globalOptions, { noRef: true })
47
- .then(function (resData) {
48
- const html = resData.body;
49
- const fb_dtsg = utils.getFrom(html, 'name="fb_dtsg" value="', '"');
50
- const jazoest = utils.getFrom(html, 'name="jazoest" value="', '"');
51
- if (!fb_dtsg) {
52
- throw new utils.CustomError("Could not find fb_dtsg in HTML after requesting https://www.facebook.com/");
53
- }
54
- ctx.fb_dtsg = fb_dtsg;
55
- ctx.jazoest = jazoest;
56
- callback(null, {
57
- data: {
58
- fb_dtsg: fb_dtsg,
59
- jazoest: jazoest
60
- },
61
- message: "refreshed fb_dtsg and jazoest"
62
- });
63
- })
64
- .catch(function (err) {
65
- log.error("refreshFb_dtsg", err);
66
- return callback(err);
67
- });
68
- }
69
- else {
70
- Object.keys(obj).forEach(function (key) {
71
- ctx[key] = obj[key];
72
- });
73
- callback(null, {
74
- data: obj,
75
- message: "refreshed " + Object.keys(obj).join(", ")
76
- });
77
- }
78
-
79
- return returnPromise;
80
- };
81
- };
7
+ return function refreshFb_dtsg(obj, callback) {
8
+ let resolveFunc, rejectFunc;
9
+ const returnPromise = new Promise((resolve, reject) => {
10
+ resolveFunc = resolve;
11
+ rejectFunc = reject;
12
+ });
13
+ if (
14
+ utils.getType(obj) === "Function" ||
15
+ utils.getType(obj) === "AsyncFunction"
16
+ ) {
17
+ callback = obj;
18
+ obj = {};
19
+ }
20
+ if (!obj) obj = {};
21
+ if (utils.getType(obj) !== "Object") {
22
+ throw new utils.CustomError(
23
+ "The first parameter must be an object or a callback function"
24
+ );
25
+ }
26
+ if (!callback) {
27
+ callback = (err, data) => (err ? rejectFunc(err) : resolveFunc(data));
28
+ }
29
+ if (Object.keys(obj).length === 0) {
30
+ utils
31
+ .get("https://www.facebook.com/", ctx.jar, null, ctx.globalOptions, {
32
+ noRef: true,
33
+ })
34
+ .then((resData) => {
35
+ const fb_dtsg = utils.getFrom(
36
+ resData.body,
37
+ '["DTSGInitData",[],{"token":"',
38
+ '","'
39
+ );
40
+ const jazoest = utils.getFrom(resData.body, "jazoest=", '",');
41
+ if (!fb_dtsg) {
42
+ throw new utils.CustomError(
43
+ "Could not find fb_dtsg in HTML after requesting Facebook."
44
+ );
45
+ }
46
+ ctx.fb_dtsg = fb_dtsg;
47
+ ctx.jazoest = jazoest;
48
+ callback(null, {
49
+ data: { fb_dtsg, jazoest },
50
+ message: "Refreshed fb_dtsg and jazoest",
51
+ });
52
+ })
53
+ .catch((err) => {
54
+ log.error("refreshFb_dtsg", err);
55
+ callback(err);
56
+ });
57
+ } else {
58
+ Object.assign(ctx, obj);
59
+ callback(null, {
60
+ data: obj,
61
+ message: "Refreshed " + Object.keys(obj).join(", "),
62
+ });
63
+ }
64
+ return returnPromise;
65
+ };
66
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var utils = require("../utils");
4
+ var log = require("npmlog");
5
+
6
+ module.exports = function (defaultFuncs, api, ctx) {
7
+ return function shareContact(text, senderID, threadID, callback) {
8
+ if (!text) {
9
+ text = "";
10
+ }
11
+ var resolveFunc = function () { };
12
+ var rejectFunc = function () { };
13
+ var returnPromise = new Promise(function (resolve, reject) {
14
+ resolveFunc = resolve;
15
+ rejectFunc = reject;
16
+ });
17
+ if (!callback) {
18
+ callback = function (err, data) {
19
+ if (err) return rejectFunc(err);
20
+ resolveFunc(data);
21
+ data
22
+ };
23
+ }
24
+ let count_req = 0
25
+ var form = JSON.stringify({
26
+ "app_id": "2220391788200892",
27
+ "payload": JSON.stringify({
28
+ tasks: [{
29
+ label: '359',
30
+ payload: JSON.stringify({
31
+ "contact_id": senderID,
32
+ "sync_group": 1,
33
+ "text": text || "",
34
+ "thread_id": threadID
35
+ }),
36
+ queue_name: 'messenger_contact_sharing',
37
+ task_id: Math.random() * 1001 << 0,
38
+ failure_count: null,
39
+ }],
40
+ epoch_id: utils.generateOfflineThreadingID(),
41
+ version_id: '7214102258676893',
42
+ }),
43
+ "request_id": ++count_req,
44
+ "type": 3
45
+ });
46
+ mqttClient.publish('/ls_req', form);
47
+ return returnPromise;
48
+ };
49
+ };