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.
Files changed (105) hide show
  1. package/dist/core/models/buildAPI.js +3 -3
  2. package/dist/core/models/buildAPI.js.map +1 -1
  3. package/dist/core/models/loginHelper.js +29 -28
  4. package/dist/core/models/loginHelper.js.map +1 -1
  5. package/dist/deltas/apis/create.js +9 -0
  6. package/dist/deltas/apis/create.js.map +1 -1
  7. package/dist/deltas/apis/messaging/editMessage.js +13 -24
  8. package/dist/deltas/apis/messaging/editMessage.js.map +1 -1
  9. package/dist/deltas/apis/messaging/emoji.js +34 -88
  10. package/dist/deltas/apis/messaging/emoji.js.map +1 -1
  11. package/dist/deltas/apis/messaging/gcmember.js +48 -101
  12. package/dist/deltas/apis/messaging/gcmember.js.map +1 -1
  13. package/dist/deltas/apis/messaging/gcname.js +28 -79
  14. package/dist/deltas/apis/messaging/gcname.js.map +1 -1
  15. package/dist/deltas/apis/messaging/gcrule.js +47 -105
  16. package/dist/deltas/apis/messaging/gcrule.js.map +1 -1
  17. package/dist/deltas/apis/messaging/markAsDelivered.js +10 -12
  18. package/dist/deltas/apis/messaging/markAsDelivered.js.map +1 -1
  19. package/dist/deltas/apis/messaging/markAsRead.js +25 -60
  20. package/dist/deltas/apis/messaging/markAsRead.js.map +1 -1
  21. package/dist/deltas/apis/messaging/markAsReadAll.js +9 -11
  22. package/dist/deltas/apis/messaging/markAsReadAll.js.map +1 -1
  23. package/dist/deltas/apis/messaging/markAsSeen.js +10 -37
  24. package/dist/deltas/apis/messaging/markAsSeen.js.map +1 -1
  25. package/dist/deltas/apis/messaging/nickname.js +38 -98
  26. package/dist/deltas/apis/messaging/nickname.js.map +1 -1
  27. package/dist/deltas/apis/messaging/notes.js +52 -90
  28. package/dist/deltas/apis/messaging/notes.js.map +1 -1
  29. package/dist/deltas/apis/messaging/resolvePhotoUrl.js +17 -42
  30. package/dist/deltas/apis/messaging/resolvePhotoUrl.js.map +1 -1
  31. package/dist/deltas/apis/messaging/sendMessage.js +14 -15
  32. package/dist/deltas/apis/messaging/sendMessage.js.map +1 -1
  33. package/dist/deltas/apis/messaging/sendTypingIndicator.js +7 -13
  34. package/dist/deltas/apis/messaging/sendTypingIndicator.js.map +1 -1
  35. package/dist/deltas/apis/messaging/setMessageReaction.js +24 -14
  36. package/dist/deltas/apis/messaging/setMessageReaction.js.map +1 -1
  37. package/dist/deltas/apis/messaging/shareContact.js +14 -12
  38. package/dist/deltas/apis/messaging/shareContact.js.map +1 -1
  39. package/dist/deltas/apis/messaging/stickers.js +4 -5
  40. package/dist/deltas/apis/messaging/stickers.js.map +1 -1
  41. package/dist/deltas/apis/messaging/theme.js +142 -213
  42. package/dist/deltas/apis/messaging/theme.js.map +1 -1
  43. package/dist/deltas/apis/messaging/unsendMessage.js +14 -7
  44. package/dist/deltas/apis/messaging/unsendMessage.js.map +1 -1
  45. package/dist/deltas/apis/posting/group.js +22 -129
  46. package/dist/deltas/apis/posting/group.js.map +1 -1
  47. package/dist/deltas/apis/posting/post.js +805 -12
  48. package/dist/deltas/apis/posting/post.js.map +1 -1
  49. package/dist/index.d.ts +35 -58
  50. package/dist/types/deltas/apis/create.d.ts +9 -0
  51. package/dist/types/deltas/apis/messaging/editMessage.d.ts +4 -5
  52. package/dist/types/deltas/apis/messaging/emoji.d.ts +7 -1
  53. package/dist/types/deltas/apis/messaging/gcmember.d.ts +7 -1
  54. package/dist/types/deltas/apis/messaging/gcname.d.ts +9 -1
  55. package/dist/types/deltas/apis/messaging/gcrule.d.ts +7 -1
  56. package/dist/types/deltas/apis/messaging/markAsDelivered.d.ts +1 -2
  57. package/dist/types/deltas/apis/messaging/markAsRead.d.ts +1 -1
  58. package/dist/types/deltas/apis/messaging/markAsReadAll.d.ts +1 -2
  59. package/dist/types/deltas/apis/messaging/markAsSeen.d.ts +1 -1
  60. package/dist/types/deltas/apis/messaging/nickname.d.ts +7 -1
  61. package/dist/types/deltas/apis/messaging/notes.d.ts +13 -11
  62. package/dist/types/deltas/apis/messaging/resolvePhotoUrl.d.ts +4 -6
  63. package/dist/types/deltas/apis/messaging/sendMessage.d.ts +1 -1
  64. package/dist/types/deltas/apis/messaging/sendTypingIndicator.d.ts +1 -1
  65. package/dist/types/deltas/apis/messaging/setMessageReaction.d.ts +6 -1
  66. package/dist/types/deltas/apis/messaging/shareContact.d.ts +1 -2
  67. package/dist/types/deltas/apis/messaging/stickers.d.ts +1 -1
  68. package/dist/types/deltas/apis/messaging/theme.d.ts +8 -1
  69. package/dist/types/deltas/apis/messaging/unsendMessage.d.ts +6 -1
  70. package/dist/types/deltas/apis/posting/group.d.ts +1 -23
  71. package/dist/types/deltas/apis/posting/post.d.ts +23 -0
  72. package/dist/types/utils/constants.d.ts +26 -16
  73. package/dist/utils/constants.js +42 -29
  74. package/dist/utils/constants.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/core/models/buildAPI.ts +3 -3
  77. package/src/core/models/loginHelper.ts +32 -30
  78. package/src/deltas/apis/create.ts +10 -0
  79. package/src/deltas/apis/messaging/editMessage.ts +16 -26
  80. package/src/deltas/apis/messaging/emoji.ts +45 -97
  81. package/src/deltas/apis/messaging/gcmember.ts +68 -113
  82. package/src/deltas/apis/messaging/gcname.ts +42 -91
  83. package/src/deltas/apis/messaging/gcrule.ts +61 -111
  84. package/src/deltas/apis/messaging/markAsDelivered.ts +19 -14
  85. package/src/deltas/apis/messaging/markAsRead.ts +45 -72
  86. package/src/deltas/apis/messaging/markAsReadAll.ts +17 -17
  87. package/src/deltas/apis/messaging/markAsSeen.ts +17 -41
  88. package/src/deltas/apis/messaging/nickname.ts +50 -116
  89. package/src/deltas/apis/messaging/notes.ts +59 -95
  90. package/src/deltas/apis/messaging/resolvePhotoUrl.ts +27 -50
  91. package/src/deltas/apis/messaging/sendMessage.ts +28 -26
  92. package/src/deltas/apis/messaging/sendTypingIndicator.ts +13 -12
  93. package/src/deltas/apis/messaging/setMessageReaction.ts +45 -20
  94. package/src/deltas/apis/messaging/shareContact.ts +25 -15
  95. package/src/deltas/apis/messaging/stickers.ts +4 -4
  96. package/src/deltas/apis/messaging/theme.ts +172 -259
  97. package/src/deltas/apis/messaging/unsendMessage.ts +23 -7
  98. package/src/deltas/apis/posting/group.ts +56 -172
  99. package/src/deltas/apis/posting/post.ts +932 -33
  100. package/src/types/index.d.ts +35 -58
  101. package/src/utils/constants.ts +84 -57
  102. package/a.html +0 -537
  103. package/a.json +0 -5915
  104. package/src/utils/formatters.old.ts +0 -1049
  105. package/task.txt +0 -24
@@ -1,94 +1,67 @@
1
1
  // @ChoruOfficial
2
- import utils = require("../../../utils");
2
+ import utils = require('../../../utils');
3
3
 
4
4
  /**
5
5
  * @param {Object} defaultFuncs
6
6
  * @param {Object} api
7
7
  * @param {Object} ctx
8
8
  */
9
- export default function(defaultFuncs: any, api: any, ctx: any) {
9
+ export default function markAsRead(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
10
14
  /**
11
- * Marks a thread as read.
15
+ * Marks a thread as read or unread.
12
16
  * @param {string} threadID - The ID of the thread to mark as read.
13
- * @param {boolean} [read=true] - Whether to mark as read (true) or unread (false). Defaults to true.
14
- * @param {Function} [callback] - The callback function.
15
- * @returns {Promise<null|Error>} A Promise that resolves with null on success, or rejects with an Error.
17
+ * @param {boolean} [read=true] - Whether to mark as read (true) or unread (false).
18
+ * @returns {Promise<null>}
16
19
  */
17
- return async function markAsRead(threadID, read, callback) {
18
- if (
19
- utils.getType(read) === "Function" ||
20
- utils.getType(read) === "AsyncFunction"
21
- ) {
22
- callback = read;
23
- read = true;
24
- }
25
- if (read == undefined) {
26
- read = true;
27
- }
28
-
29
- if (!callback) {
30
- callback = () => {};
31
- }
32
-
33
- const form = {};
20
+ return async function markAsRead(
21
+ threadID: string,
22
+ read: boolean = true,
23
+ ): Promise<null> {
24
+ const form: Record<string, any> = {};
34
25
 
35
- if (typeof ctx.globalOptions.pageID !== "undefined") {
36
- form["source"] = "PagesManagerMessagesInterface";
37
- form["request_user_id"] = ctx.globalOptions.pageID;
38
- form["ids[" + threadID + "]"] = read;
39
- form["watermarkTimestamp"] = new Date().getTime();
40
- form["shouldSendReadReceipt"] = true;
41
- form["commerce_last_message_type"] = "";
26
+ if (typeof ctx.globalOptions.pageID !== 'undefined') {
27
+ form['source'] = 'PagesManagerMessagesInterface';
28
+ form['request_user_id'] = ctx.globalOptions.pageID;
29
+ form['ids[' + threadID + ']'] = read;
30
+ form['watermarkTimestamp'] = new Date().getTime();
31
+ form['shouldSendReadReceipt'] = true;
32
+ form['commerce_last_message_type'] = '';
42
33
 
43
- let resData;
44
- try {
45
- resData = await defaultFuncs
46
- .post(
47
- "https://www.facebook.com/ajax/mercury/change_read_status.php",
48
- ctx.jar,
49
- form,
50
- )
51
- .then(utils.saveCookies(ctx.jar))
52
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
53
- } catch (e) {
54
- callback(e);
55
- return e;
56
- }
34
+ const resData = await defaultFuncs
35
+ .post(
36
+ 'https://www.facebook.com/ajax/mercury/change_read_status.php',
37
+ ctx.jar,
38
+ form,
39
+ )
40
+ .then(utils.saveCookies(ctx.jar))
41
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
57
42
 
58
43
  if (resData.error) {
59
44
  const err = resData.error;
60
- utils.error("markAsRead", err);
61
- callback(err);
62
- return err;
45
+ utils.error('markAsRead', err);
46
+ throw new Error(err);
63
47
  }
64
48
 
65
- callback();
66
49
  return null;
67
50
  } else {
68
- try {
69
- if (ctx.mqttClient) {
70
- const err = await new Promise((r) =>
71
- ctx.mqttClient.publish(
72
- "/mark_thread",
73
- JSON.stringify({
74
- threadID,
75
- mark: "read",
76
- state: read,
77
- }),
78
- { qos: 1, retain: false },
79
- r,
80
- ),
81
- );
82
- if (err) throw err;
83
- } else {
84
- throw {
85
- error: "You can only use this function after you start listening.",
86
- };
87
- }
88
- } catch (e) {
89
- callback(e);
90
- return e;
51
+ if (!ctx.mqttClient) {
52
+ throw {
53
+ error: 'You can only use this function after you start listening.',
54
+ };
91
55
  }
56
+ await new Promise<void>((resolve, reject) =>
57
+ ctx.mqttClient.publish(
58
+ '/mark_thread',
59
+ JSON.stringify({ threadID, mark: 'read', state: read }),
60
+ { qos: 1, retain: false },
61
+ (err) => (err ? reject(err) : resolve()),
62
+ ),
63
+ );
92
64
  }
65
+ return null;
93
66
  };
94
- };
67
+ }
@@ -5,31 +5,31 @@ import utils = require('../../../utils');
5
5
  * @param {Object} defaultFuncs
6
6
  * @param {Object} api
7
7
  * @param {Object} ctx
8
- * @returns {function(): Promise<void>}
9
8
  */
10
- export default function(defaultFuncs: any, api: any, ctx: any) {
9
+ export default function markAsReadAll(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
11
14
  /**
15
+ * Marks all messages in the inbox as read.
12
16
  * @returns {Promise<void>}
13
17
  */
14
- return async function markAsReadAll() {
15
- const form = {
16
- folder: 'inbox',
17
- };
18
+ return async function markAsReadAll(): Promise<void> {
19
+ const form = { folder: 'inbox' };
18
20
 
19
21
  try {
20
- const resData = await defaultFuncs.post(
21
- 'https://www.facebook.com/ajax/mercury/mark_folder_as_read.php',
22
- ctx.jar,
23
- form,
24
- );
22
+ const resData = await defaultFuncs
23
+ .post(
24
+ 'https://www.facebook.com/ajax/mercury/mark_folder_as_read.php',
25
+ ctx.jar,
26
+ form,
27
+ )
28
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
25
29
 
26
- const parsedData = utils.parseAndCheckLogin(resData, defaultFuncs) as any;
27
-
28
- if (parsedData.error) {
29
- throw parsedData;
30
+ if (resData.error) {
31
+ throw resData;
30
32
  }
31
-
32
- return;
33
33
  } catch (err) {
34
34
  utils.error('markAsReadAll', err);
35
35
  throw err;
@@ -1,50 +1,30 @@
1
1
  // @ChoruOfficial
2
- import utils = require("../../../utils");
2
+ import utils = require('../../../utils');
3
3
 
4
4
  /**
5
5
  * @param {Object} defaultFuncs
6
6
  * @param {Object} api
7
7
  * @param {Object} ctx
8
8
  */
9
- export default function(defaultFuncs: any, api: any, ctx: any) {
9
+ export default function markAsSeen(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
10
14
  /**
11
15
  * Marks all messages as "seen" up to a specific timestamp.
12
- * @param {number} [seen_timestamp=Date.now()] - The timestamp (in milliseconds) up to which messages should be marked as seen. If a function is provided, it's treated as the callback and the timestamp defaults to the current time.
13
- * @param {Function} [callback] - The callback function.
14
- * @returns {Promise<void>} A Promise that resolves on success or rejects with an error.
16
+ * @param {number} [seen_timestamp=Date.now()] - The timestamp (in ms) up to which messages should be marked as seen.
17
+ * @returns {Promise<void>}
15
18
  */
16
- return async function markAsRead(seen_timestamp, callback) {
17
- let resolveFunc: Function = function () {};
18
- let rejectFunc: Function = function () {};
19
- const returnPromise = new Promise<any>(function (resolve, reject) {
20
- resolveFunc = resolve;
21
- rejectFunc = reject;
22
- });
23
-
24
- if (utils.getType(seen_timestamp) == "Function" || utils.getType(seen_timestamp) == "AsyncFunction") {
25
- callback = seen_timestamp;
26
- seen_timestamp = Date.now();
27
- } else if (seen_timestamp === undefined) {
28
- seen_timestamp = Date.now();
29
- }
30
-
31
- if (!callback) {
32
- callback = function (err, friendList) {
33
- if (err) {
34
- return rejectFunc(err);
35
- }
36
- resolveFunc(friendList);
37
- };
38
- }
39
-
40
- const form = {
41
- seen_timestamp: seen_timestamp,
42
- };
19
+ return async function markAsSeen(
20
+ seen_timestamp: number = Date.now(),
21
+ ): Promise<void> {
22
+ const form = { seen_timestamp };
43
23
 
44
24
  try {
45
25
  const resData = await defaultFuncs
46
26
  .post(
47
- "https://www.facebook.com/ajax/mercury/mark_seen.php",
27
+ 'https://www.facebook.com/ajax/mercury/mark_seen.php',
48
28
  ctx.jar,
49
29
  form,
50
30
  )
@@ -54,16 +34,12 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
54
34
  if (resData.error) {
55
35
  throw resData;
56
36
  }
57
-
58
- return callback();
59
37
  } catch (err) {
60
- utils.error("markAsSeen", err);
61
- if (utils.getType(err) == "Object" && err.error === "Not logged in.") {
38
+ utils.error('markAsSeen', err);
39
+ if (utils.getType(err) === 'Object' && (err as any).error === 'Not logged in.') {
62
40
  ctx.loggedIn = false;
63
41
  }
64
- return callback(err);
42
+ throw err;
65
43
  }
66
-
67
- return returnPromise;
68
44
  };
69
- };
45
+ }
@@ -1,104 +1,44 @@
1
1
  import utils = require('../../../utils');
2
2
 
3
- export default function(defaultFuncs: any, api: any, ctx: any) {
3
+ /**
4
+ * @module nickname
5
+ * @param {Object} defaultFuncs
6
+ * @param {Object} api
7
+ * @param {Object} ctx
8
+ */
9
+ export default function nickname(
10
+ defaultFuncs: any,
11
+ api: any,
12
+ ctx: any,
13
+ ): Function {
4
14
  /**
5
- * Made by Choru Official
6
- * Mqtt
7
- * Sets a nickname for a participant in a Facebook thread via MQTT.
8
- *
9
- * @param {string} nickname The new nickname to set.
10
- * @param {string} threadID The ID of the thread.
11
- * @param {string} participantID The ID of the participant whose nickname will be changed. Defaults to the current user's ID if not provided or a function.
12
- * @param {Function} [callback] Optional callback function to be invoked upon completion.
13
- * @param {string} [initiatorID] The ID of the user who initiated the nickname change (e.g., from event.senderID).
14
- * @returns {Promise<object>} A promise that resolves with a structured event object on success or rejects on error.
15
+ * Made by Choru Official — Sets a nickname for a participant in a thread via MQTT.
16
+ * @param {string} nickname - The new nickname to set.
17
+ * @param {string} threadID - The ID of the thread.
18
+ * @param {string} [participantID] - The ID of the participant. Defaults to the bot's own ID.
19
+ * @param {string} [initiatorID] - The ID of the user initiating the change.
20
+ * @returns {Promise<object>}
15
21
  */
16
- return function setNickname(
17
- nickname,
18
- threadID,
19
- participantID,
20
- callback,
21
- initiatorID,
22
- ) {
23
- let _callback;
24
- let _initiatorID;
22
+ return async function setNickname(
23
+ nicknameStr: string,
24
+ threadID: string,
25
+ participantID?: string,
26
+ initiatorID?: string,
27
+ ): Promise<any> {
28
+ const _initiatorID = initiatorID || ctx.userID;
29
+ const _participantID = participantID || ctx.userID;
25
30
 
26
- let _resolvePromise;
27
- let _rejectPromise;
28
- const returnPromise = new Promise<any>((resolve, reject) => {
29
- _resolvePromise = resolve;
30
- _rejectPromise = reject;
31
- });
32
-
33
- if (
34
- utils.getType(callback) === 'Function' ||
35
- utils.getType(callback) === 'AsyncFunction'
36
- ) {
37
- _callback = callback;
38
- _initiatorID = initiatorID;
39
- } else if (
40
- utils.getType(threadID) === 'Function' ||
41
- utils.getType(threadID) === 'AsyncFunction'
42
- ) {
43
- _callback = threadID;
44
- threadID = null;
45
- _initiatorID = callback;
46
- } else if (
47
- utils.getType(participantID) === 'Function' ||
48
- utils.getType(participantID) === 'AsyncFunction'
49
- ) {
50
- _callback = participantID;
51
- participantID = ctx.userID;
52
- _initiatorID = callback;
53
- } else if (utils.getType(callback) === 'string') {
54
- _initiatorID = callback;
55
- _callback = undefined;
56
- } else {
57
- _callback = undefined;
58
- _initiatorID = undefined;
59
- }
60
-
61
- if (!_callback) {
62
- _callback = function(__err, __data) {
63
- if (__err) _rejectPromise(__err);
64
- else _resolvePromise(__data);
65
- };
66
- } else {
67
- const originalCallback = _callback;
68
- _callback = function(__err, __data) {
69
- if (__err) {
70
- originalCallback(__err);
71
- _rejectPromise(__err);
72
- } else {
73
- originalCallback(null, __data);
74
- _resolvePromise(__data);
75
- }
76
- };
77
- }
78
-
79
- _initiatorID = _initiatorID || ctx.userID;
80
-
81
- threadID = threadID || ctx.threadID;
82
- participantID = participantID || ctx.userID;
83
-
84
- if (!threadID) {
85
- return _callback(new Error('threadID is required to set a nickname.'));
86
- }
87
- if (typeof nickname !== 'string') {
88
- return _callback(new Error('nickname must be a string.'));
89
- }
90
-
91
- if (!ctx.mqttClient) {
92
- return _callback(new Error('Not connected to MQTT'));
93
- }
31
+ if (!threadID) throw new TypeError('threadID is required to set a nickname.');
32
+ if (typeof nicknameStr !== 'string') throw new TypeError('nickname must be a string.');
33
+ if (!ctx.mqttClient) throw new Error('Not connected to MQTT');
94
34
 
95
35
  ctx.wsReqNumber += 1;
96
36
  ctx.wsTaskNumber += 1;
97
37
 
98
38
  const queryPayload = {
99
39
  thread_key: threadID.toString(),
100
- contact_id: participantID.toString(),
101
- nickname: nickname,
40
+ contact_id: _participantID.toString(),
41
+ nickname: nicknameStr,
102
42
  sync_group: 1,
103
43
  };
104
44
 
@@ -113,7 +53,7 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
113
53
  const context: any = {
114
54
  app_id: ctx.appID,
115
55
  payload: {
116
- epoch_id: parseInt(utils.generateOfflineThreadingID()),
56
+ epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
117
57
  tasks: [query],
118
58
  version_id: '24631415369801570',
119
59
  },
@@ -122,32 +62,26 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
122
62
  };
123
63
  context.payload = JSON.stringify(context.payload);
124
64
 
125
- ctx.mqttClient.publish(
126
- '/ls_req',
127
- JSON.stringify(context),
128
- { qos: 1, retain: false },
129
- (err) => {
130
- if (err) {
131
- return _callback(
132
- new Error(
133
- `MQTT publish failed for setNickname: ${err.message || err}`,
134
- ),
135
- );
136
- }
137
-
138
- const nicknameChangeEvent = {
139
- type: 'thread_nickname_update',
140
- threadID: threadID,
141
- participantID: participantID,
142
- newNickname: nickname,
143
- senderID: _initiatorID,
144
- BotID: ctx.userID,
145
- timestamp: Date.now(),
146
- };
147
- _callback(null, nicknameChangeEvent);
148
- },
65
+ await new Promise<void>((resolve, reject) =>
66
+ ctx.mqttClient.publish(
67
+ '/ls_req',
68
+ JSON.stringify(context),
69
+ { qos: 1, retain: false },
70
+ (err) =>
71
+ err
72
+ ? reject(new Error(`MQTT publish failed for setNickname: ${err.message || err}`))
73
+ : resolve(),
74
+ ),
149
75
  );
150
76
 
151
- return returnPromise;
77
+ return {
78
+ type: 'thread_nickname_update',
79
+ threadID,
80
+ participantID: _participantID,
81
+ newNickname: nicknameStr,
82
+ senderID: _initiatorID,
83
+ BotID: ctx.userID,
84
+ timestamp: Date.now(),
85
+ };
152
86
  };
153
87
  }
@@ -1,29 +1,22 @@
1
1
  import utils = require('../../../utils');
2
2
 
3
3
  /**
4
- * @ChoruOfficial
5
- * @description A module for interacting with Facebook Messenger Notes. This is not for creating notes on a user's profile page, but rather the temporary status-like notes in Messenger.
6
- * @param {Object} defaultFuncs The default functions provided by the API wrapper.
7
- * @param {Object} api The full API object.
8
- * @param {Object} ctx The context object containing the user's session state (e.g., userID, jar).
9
- * @returns {Object} An object containing methods to create, delete, recreate, and check notes.
4
+ * @module notes
5
+ * @description Interacts with Facebook Messenger Notes (temporary status-like notes).
6
+ * @param {Object} defaultFuncs
7
+ * @param {Object} api
8
+ * @param {Object} ctx
10
9
  */
11
- export default function(defaultFuncs: any, api: any, ctx: any) {
12
- /**
13
- * @callback notesCallback
14
- * @param {Error|null} error An error object if the request fails, otherwise null.
15
- * @param {Object} [data] The data returned from the API.
16
- */
17
-
10
+ export default function notes(
11
+ defaultFuncs: any,
12
+ api: any,
13
+ ctx: any,
14
+ ) {
18
15
  /**
19
16
  * Checks for the currently active note for the logged-in user.
20
- * @param {notesCallback} callback A callback function that is executed after the request. It receives an error object (if any) and an object representing the current note.
17
+ * @returns {Promise<object|null>}
21
18
  */
22
- function checkNote(callback) {
23
- if (typeof callback !== 'function') {
24
- callback = () => {};
25
- }
26
-
19
+ async function checkNote(): Promise<any> {
27
20
  const form = {
28
21
  fb_api_caller_class: 'RelayModern',
29
22
  fb_api_req_friendly_name: 'MWInboxTrayNoteCreationDialogQuery',
@@ -31,30 +24,24 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
31
24
  doc_id: '30899655739648624',
32
25
  };
33
26
 
34
- defaultFuncs
27
+ const resData = await defaultFuncs
35
28
  .post('https://www.facebook.com/api/graphql/', ctx.jar, form)
36
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
37
- .then((resData) => {
38
- if (resData && resData.errors) throw resData.errors[0];
39
- const currentNote = resData?.data?.viewer?.actor?.msgr_user_rich_status;
40
- callback(null, currentNote);
41
- })
42
- .catch((err) => {
43
- utils.error('notes.checkNote', err);
44
- callback(err);
45
- });
29
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
30
+
31
+ if (resData?.errors) {
32
+ utils.error('notes.checkNote', resData.errors[0]);
33
+ throw resData.errors[0];
34
+ }
35
+ return resData?.data?.viewer?.actor?.msgr_user_rich_status ?? null;
46
36
  }
47
37
 
48
38
  /**
49
- * Creates a new note with the provided text. The note lasts for 24 hours (86400 seconds).
50
- * @param {string} text The content of the note.
51
- * @param {notesCallback} callback A callback function that is executed after the request. It receives an error object (if any) and an object confirming the note's creation status.
39
+ * Creates a new note with the provided text. The note lasts for 24 hours.
40
+ * @param {string} text - The content of the note.
41
+ * @param {string} [privacy="EVERYONE"] - Privacy setting.
42
+ * @returns {Promise<object>}
52
43
  */
53
- function createNote(text, privacy = 'EVERYONE', callback?) {
54
- if (typeof callback !== 'function') {
55
- callback = () => {};
56
- }
57
-
44
+ async function createNote(text: string, privacy = 'EVERYONE'): Promise<any> {
58
45
  const variables = {
59
46
  input: {
60
47
  client_mutation_id: Math.round(Math.random() * 10).toString(),
@@ -68,38 +55,31 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
68
55
  };
69
56
  const form = {
70
57
  fb_api_caller_class: 'RelayModern',
71
- fb_api_req_friendly_name:
72
- 'MWInboxTrayNoteCreationDialogCreationStepContentMutation',
58
+ fb_api_req_friendly_name: 'MWInboxTrayNoteCreationDialogCreationStepContentMutation',
73
59
  variables: JSON.stringify(variables),
74
60
  doc_id: '24060573783603122',
75
61
  };
76
62
 
77
- defaultFuncs
63
+ const resData = await defaultFuncs
78
64
  .post('https://www.facebook.com/api/graphql/', ctx.jar, form)
79
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
80
- .then((resData) => {
81
- if (resData && resData.errors) throw resData.errors[0];
82
- const status = resData?.data?.xfb_rich_status_create?.status;
83
- if (!status)
84
- throw new Error('Could not find note status in the server response.');
85
- callback(null, status);
86
- })
87
- .catch((err) => {
88
- utils.error('notes.createNote', err);
89
- callback(err);
90
- });
65
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
66
+
67
+ if (resData?.errors) {
68
+ utils.error('notes.createNote', resData.errors[0]);
69
+ throw resData.errors[0];
70
+ }
71
+
72
+ const status = resData?.data?.xfb_rich_status_create?.status;
73
+ if (!status) throw new Error('Could not find note status in the server response.');
74
+ return status;
91
75
  }
92
76
 
93
77
  /**
94
78
  * Deletes a specific note by its ID.
95
- * @param {string} noteID The ID of the note to be deleted.
96
- * @param {notesCallback} callback A callback function that is executed after the request. It receives an error object (if any) and an object confirming the deletion.
79
+ * @param {string} noteID - The ID of the note to delete.
80
+ * @returns {Promise<object>}
97
81
  */
98
- function deleteNote(noteID, callback) {
99
- if (typeof callback !== 'function') {
100
- callback = () => {};
101
- }
102
-
82
+ async function deleteNote(noteID: string): Promise<any> {
103
83
  const variables = {
104
84
  input: {
105
85
  client_mutation_id: Math.round(Math.random() * 10).toString(),
@@ -114,46 +94,30 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
114
94
  doc_id: '9532619970198958',
115
95
  };
116
96
 
117
- defaultFuncs
97
+ const resData = await defaultFuncs
118
98
  .post('https://www.facebook.com/api/graphql/', ctx.jar, form)
119
- .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
120
- .then((resData) => {
121
- if (resData && resData.errors) throw resData.errors[0];
122
- const deletedStatus = resData?.data?.xfb_rich_status_delete;
123
- if (!deletedStatus)
124
- throw new Error(
125
- 'Could not find deletion status in the server response.',
126
- );
127
- callback(null, deletedStatus);
128
- })
129
- .catch((err) => {
130
- utils.error('notes.deleteNote', err);
131
- callback(err);
132
- });
99
+ .then(utils.parseAndCheckLogin(ctx, defaultFuncs));
100
+
101
+ if (resData?.errors) {
102
+ utils.error('notes.deleteNote', resData.errors[0]);
103
+ throw resData.errors[0];
104
+ }
105
+
106
+ const deletedStatus = resData?.data?.xfb_rich_status_delete;
107
+ if (!deletedStatus) throw new Error('Could not find deletion status in the server response.');
108
+ return deletedStatus;
133
109
  }
134
110
 
135
111
  /**
136
- * A convenience function that first deletes an old note and then creates a new one.
137
- * @param {string} oldNoteID The ID of the note to delete.
138
- * @param {string} newText The text for the new note.
139
- * @param {notesCallback} callback A callback function that is executed after the request. It receives an error object (if any) and an object containing the deletion and creation statuses.
112
+ * Deletes an old note and creates a new one.
113
+ * @param {string} oldNoteID - The ID of the note to delete.
114
+ * @param {string} newText - The text for the new note.
115
+ * @returns {Promise<{ deleted: object, created: object }>}
140
116
  */
141
- function recreateNote(oldNoteID, newText, callback) {
142
- if (typeof callback !== 'function') {
143
- callback = () => {};
144
- }
145
-
146
- deleteNote(oldNoteID, (err, deleted) => {
147
- if (err) {
148
- return callback(err);
149
- }
150
- createNote(newText, undefined, (err, created) => {
151
- if (err) {
152
- return callback(err);
153
- }
154
- callback(null, { deleted, created });
155
- });
156
- });
117
+ async function recreateNote(oldNoteID: string, newText: string): Promise<{ deleted: any; created: any }> {
118
+ const deleted = await deleteNote(oldNoteID);
119
+ const created = await createNote(newText);
120
+ return { deleted, created };
157
121
  }
158
122
 
159
123
  return {