bb-fca 2.0.9 → 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/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 +33 -11
- package/dist/deltas/apis/posting/group.js.map +1 -1
- 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/package.json +1 -1
- 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 +36 -11
- package/request.txt +0 -60
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Made by Choru Official
|
|
3
|
+
* Sets the name of a group chat thread via MQTT.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} defaultFuncs
|
|
6
|
+
* @param {Object} api
|
|
7
|
+
* @param {Object} ctx
|
|
8
|
+
*/
|
|
9
|
+
export default function gcname(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module gcrule
|
|
3
|
+
* @param {Object} defaultFuncs
|
|
4
|
+
* @param {Object} api
|
|
5
|
+
* @param {Object} ctx
|
|
6
|
+
*/
|
|
7
|
+
export default function gcrule(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
* @param {Object} defaultFuncs
|
|
3
3
|
* @param {Object} api
|
|
4
4
|
* @param {Object} ctx
|
|
5
|
-
* @returns {function(threadID: string, messageID: string): Promise<void>}
|
|
6
5
|
*/
|
|
7
|
-
export default function (defaultFuncs: any, api: any, ctx: any):
|
|
6
|
+
export default function markAsDelivered(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
* @param {Object} defaultFuncs
|
|
3
3
|
* @param {Object} api
|
|
4
4
|
* @param {Object} ctx
|
|
5
|
-
* @returns {function(): Promise<void>}
|
|
6
5
|
*/
|
|
7
|
-
export default function (defaultFuncs: any, api: any, ctx: any):
|
|
6
|
+
export default function markAsReadAll(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module nickname
|
|
3
|
+
* @param {Object} defaultFuncs
|
|
4
|
+
* @param {Object} api
|
|
5
|
+
* @param {Object} ctx
|
|
6
|
+
*/
|
|
7
|
+
export default function nickname(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @description
|
|
4
|
-
* @param {Object} defaultFuncs
|
|
5
|
-
* @param {Object} api
|
|
6
|
-
* @param {Object} ctx
|
|
7
|
-
* @returns {Object} An object containing methods to create, delete, recreate, and check notes.
|
|
2
|
+
* @module notes
|
|
3
|
+
* @description Interacts with Facebook Messenger Notes (temporary status-like notes).
|
|
4
|
+
* @param {Object} defaultFuncs
|
|
5
|
+
* @param {Object} api
|
|
6
|
+
* @param {Object} ctx
|
|
8
7
|
*/
|
|
9
|
-
export default function (defaultFuncs: any, api: any, ctx: any): {
|
|
10
|
-
create: (text:
|
|
11
|
-
delete: (noteID:
|
|
12
|
-
recreate: (oldNoteID:
|
|
13
|
-
|
|
8
|
+
export default function notes(defaultFuncs: any, api: any, ctx: any): {
|
|
9
|
+
create: (text: string, privacy?: string) => Promise<any>;
|
|
10
|
+
delete: (noteID: string) => Promise<any>;
|
|
11
|
+
recreate: (oldNoteID: string, newText: string) => Promise<{
|
|
12
|
+
deleted: any;
|
|
13
|
+
created: any;
|
|
14
|
+
}>;
|
|
15
|
+
check: () => Promise<any>;
|
|
14
16
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module resolvePhotoUrl
|
|
3
|
-
* @
|
|
4
|
-
* @param {Object}
|
|
5
|
-
* @param {Object}
|
|
6
|
-
* @param {Object} ctx - Context object containing cookies (jar) and other session info.
|
|
7
|
-
* @returns {Function} resolvePhotoUrl - A function that takes a photo ID and optional callback, and returns a Promise resolving to the photo URL.
|
|
3
|
+
* @param {Object} defaultFuncs
|
|
4
|
+
* @param {Object} api
|
|
5
|
+
* @param {Object} ctx
|
|
8
6
|
*/
|
|
9
|
-
export default function (defaultFuncs: any, api: any, ctx: any):
|
|
7
|
+
export default function resolvePhotoUrl(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function (defaultFuncs: any, api: any, ctx: any):
|
|
1
|
+
export default function sendMessage(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param {Object} api
|
|
4
4
|
* @param {Object} ctx
|
|
5
5
|
*/
|
|
6
|
-
export default function (defaultFuncs: any, api: any, ctx: any):
|
|
6
|
+
export default function sendTypingIndicator(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} defaultFuncs
|
|
3
|
+
* @param {Object} api
|
|
4
|
+
* @param {Object} ctx
|
|
5
|
+
*/
|
|
6
|
+
export default function setMessageReaction(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -3,6 +3,5 @@
|
|
|
3
3
|
* @param {Object} defaultFuncs - The default functions provided by the API.
|
|
4
4
|
* @param {Object} api - The full API object.
|
|
5
5
|
* @param {Object} ctx - The context object.
|
|
6
|
-
* @returns {function(text: string, senderID: string, threadID: string, callback: Function): void} - A function to share a contact.
|
|
7
6
|
*/
|
|
8
|
-
export default function (defaultFuncs: any, api: any, ctx: any):
|
|
7
|
+
export default function shareContact(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Provides access to Facebook's GraphQL-based sticker endpoints.
|
|
4
4
|
* Made by @ChoruOfficial
|
|
5
5
|
*/
|
|
6
|
-
export default function (defaultFuncs: any, api: any, ctx: any): {
|
|
6
|
+
export default function stickers(defaultFuncs: any, api: any, ctx: any): {
|
|
7
7
|
/**
|
|
8
8
|
* Search for stickers by keyword
|
|
9
9
|
* @param {string} query - Search term
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module theme
|
|
3
|
+
* @description Manages or sets the custom theme for a Facebook thread. Made by Choru Official.
|
|
4
|
+
* @param {Object} defaultFuncs
|
|
5
|
+
* @param {Object} api
|
|
6
|
+
* @param {Object} ctx
|
|
7
|
+
*/
|
|
8
|
+
export default function theme(defaultFuncs: any, api: any, ctx: any): Function;
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} defaultFuncs
|
|
3
|
+
* @param {Object} api
|
|
4
|
+
* @param {Object} ctx
|
|
5
|
+
*/
|
|
6
|
+
export default function unsendMessage(defaultFuncs: any, api: any, ctx: any): Function;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bb-fca",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "BB-FCA is a powerful and user-friendly Facebook Chat API wrapper for Node.js, designed to simplify the process of creating chatbots and automating interactions on Facebook Messenger. With BB-FCA, developers can easily send messages, manage conversations, and interact with the Facebook Messenger platform using a simple and intuitive API.",
|
|
5
5
|
"main": "dist/core/client.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -2,27 +2,25 @@
|
|
|
2
2
|
* @author RFS-ADRENO
|
|
3
3
|
* @rewrittenBy Isai Ivanov
|
|
4
4
|
*/
|
|
5
|
-
//fixed march 30
|
|
6
5
|
import utils = require('../../../utils');
|
|
7
6
|
|
|
8
|
-
function canBeCalled(func) {
|
|
9
|
-
try {
|
|
10
|
-
Reflect.apply(func, null, []);
|
|
11
|
-
return true;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
7
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {Object} callback - Callback for the function.
|
|
8
|
+
* @param {Object} defaultFuncs
|
|
9
|
+
* @param {Object} api
|
|
10
|
+
* @param {Object} ctx
|
|
22
11
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
export default function editMessage(
|
|
13
|
+
defaultFuncs: any,
|
|
14
|
+
api: any,
|
|
15
|
+
ctx: any,
|
|
16
|
+
): Function {
|
|
17
|
+
/**
|
|
18
|
+
* Edits a message previously sent by the bot via MQTT.
|
|
19
|
+
* @param {string} text - The new text for the message.
|
|
20
|
+
* @param {string} messageID - The ID of the message to edit.
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
return function editMessage(text: string, messageID: string): void {
|
|
26
24
|
if (!ctx.mqttClient) {
|
|
27
25
|
throw new Error('Not connected to MQTT');
|
|
28
26
|
}
|
|
@@ -30,10 +28,7 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
30
28
|
ctx.wsReqNumber += 1;
|
|
31
29
|
ctx.wsTaskNumber += 1;
|
|
32
30
|
|
|
33
|
-
const queryPayload = {
|
|
34
|
-
message_id: messageID,
|
|
35
|
-
text,
|
|
36
|
-
};
|
|
31
|
+
const queryPayload = { message_id: messageID, text };
|
|
37
32
|
|
|
38
33
|
const query = {
|
|
39
34
|
failure_count: null,
|
|
@@ -54,13 +49,8 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
54
49
|
request_id: ctx.wsReqNumber,
|
|
55
50
|
type: 3,
|
|
56
51
|
};
|
|
57
|
-
|
|
58
52
|
context.payload = JSON.stringify(context.payload);
|
|
59
53
|
|
|
60
|
-
// if (canBeCalled(callback)) {
|
|
61
|
-
// ctx.reqCallbacks[ctx.wsReqNumber] = callback;
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
54
|
ctx.mqttClient.publish('/ls_req', JSON.stringify(context), {
|
|
65
55
|
qos: 1,
|
|
66
56
|
retain: false,
|
|
@@ -1,88 +1,40 @@
|
|
|
1
1
|
import utils = require('../../../utils');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @module emoji
|
|
5
|
+
* @param {Object} defaultFuncs
|
|
6
|
+
* @param {Object} api
|
|
7
|
+
* @param {Object} ctx
|
|
8
|
+
*/
|
|
9
|
+
export default function emoji(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
4
14
|
/**
|
|
5
|
-
* Made by Choru Official
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @param {string} threadID The ID of the thread where the emoji will be set.
|
|
11
|
-
* @param {Function} [callback] Optional callback function to be invoked upon completion.
|
|
12
|
-
* @param {string} [initiatorID] The ID of the user who initiated the emoji change (e.g., from event.senderID).
|
|
13
|
-
* @returns {Promise<object>} A promise that resolves with a structured event object on success or rejects on error.
|
|
15
|
+
* Made by Choru Official — sets the custom emoji for a thread via MQTT.
|
|
16
|
+
* @param {string} emoji - The emoji character to set (e.g., "👍", "❤️").
|
|
17
|
+
* @param {string} threadID - The ID of the thread.
|
|
18
|
+
* @param {string} [initiatorID] - The ID of the initiating user.
|
|
19
|
+
* @returns {Promise<object>}
|
|
14
20
|
*/
|
|
15
|
-
return function emoji(
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
return async function emoji(
|
|
22
|
+
emojiChar: string,
|
|
23
|
+
threadID: string,
|
|
24
|
+
initiatorID?: string,
|
|
25
|
+
): Promise<any> {
|
|
26
|
+
const _initiatorID = initiatorID || ctx.userID;
|
|
18
27
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
_resolvePromise = resolve;
|
|
23
|
-
_rejectPromise = reject;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
utils.getType(callback) === 'Function' ||
|
|
28
|
-
utils.getType(callback) === 'AsyncFunction'
|
|
29
|
-
) {
|
|
30
|
-
_callback = callback;
|
|
31
|
-
_initiatorID = initiatorID;
|
|
32
|
-
} else if (
|
|
33
|
-
utils.getType(threadID) === 'Function' ||
|
|
34
|
-
utils.getType(threadID) === 'AsyncFunction'
|
|
35
|
-
) {
|
|
36
|
-
_callback = threadID;
|
|
37
|
-
threadID = null;
|
|
38
|
-
_initiatorID = callback;
|
|
39
|
-
} else if (utils.getType(callback) === 'string') {
|
|
40
|
-
_initiatorID = callback;
|
|
41
|
-
_callback = undefined;
|
|
42
|
-
} else {
|
|
43
|
-
_callback = undefined;
|
|
44
|
-
_initiatorID = undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!_callback) {
|
|
48
|
-
_callback = function(__err, __data) {
|
|
49
|
-
if (__err) _rejectPromise(__err);
|
|
50
|
-
else _resolvePromise(__data);
|
|
51
|
-
};
|
|
52
|
-
} else {
|
|
53
|
-
const originalCallback = _callback;
|
|
54
|
-
_callback = function(__err, __data) {
|
|
55
|
-
if (__err) {
|
|
56
|
-
originalCallback(__err);
|
|
57
|
-
_rejectPromise(__err);
|
|
58
|
-
} else {
|
|
59
|
-
originalCallback(null, __data);
|
|
60
|
-
_resolvePromise(__data);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_initiatorID = _initiatorID || ctx.userID;
|
|
66
|
-
|
|
67
|
-
threadID = threadID || ctx.threadID;
|
|
68
|
-
|
|
69
|
-
if (!threadID) {
|
|
70
|
-
return _callback(new Error('threadID is required to set an emoji.'));
|
|
71
|
-
}
|
|
72
|
-
if (!emoji) {
|
|
73
|
-
return _callback(new Error('An emoji character is required.'));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!ctx.mqttClient) {
|
|
77
|
-
return _callback(new Error('Not connected to MQTT'));
|
|
78
|
-
}
|
|
28
|
+
if (!threadID) throw new Error('threadID is required to set an emoji.');
|
|
29
|
+
if (!emojiChar) throw new Error('An emoji character is required.');
|
|
30
|
+
if (!ctx.mqttClient) throw new Error('Not connected to MQTT');
|
|
79
31
|
|
|
80
32
|
ctx.wsReqNumber += 1;
|
|
81
33
|
ctx.wsTaskNumber += 1;
|
|
82
34
|
|
|
83
35
|
const queryPayload = {
|
|
84
36
|
thread_key: threadID.toString(),
|
|
85
|
-
custom_emoji:
|
|
37
|
+
custom_emoji: emojiChar,
|
|
86
38
|
avatar_sticker_instruction_key_id: null,
|
|
87
39
|
sync_group: 1,
|
|
88
40
|
};
|
|
@@ -98,7 +50,7 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
98
50
|
const context: any = {
|
|
99
51
|
app_id: ctx.appID,
|
|
100
52
|
payload: {
|
|
101
|
-
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
|
53
|
+
epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
|
|
102
54
|
tasks: [query],
|
|
103
55
|
version_id: '24631415369801570',
|
|
104
56
|
},
|
|
@@ -107,29 +59,25 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
107
59
|
};
|
|
108
60
|
context.payload = JSON.stringify(context.payload);
|
|
109
61
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
new Error(`MQTT publish failed for emoji: ${err.message || err}`)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const emojiChangeEvent = {
|
|
122
|
-
type: 'thread_emoji_update',
|
|
123
|
-
threadID: threadID,
|
|
124
|
-
newEmoji: emoji,
|
|
125
|
-
senderID: _initiatorID,
|
|
126
|
-
BotID: ctx.userID,
|
|
127
|
-
timestamp: Date.now(),
|
|
128
|
-
};
|
|
129
|
-
_callback(null, emojiChangeEvent);
|
|
130
|
-
},
|
|
62
|
+
await new Promise<void>((resolve, reject) =>
|
|
63
|
+
ctx.mqttClient.publish(
|
|
64
|
+
'/ls_req',
|
|
65
|
+
JSON.stringify(context),
|
|
66
|
+
{ qos: 1, retain: false },
|
|
67
|
+
(err) =>
|
|
68
|
+
err
|
|
69
|
+
? reject(new Error(`MQTT publish failed for emoji: ${err.message || err}`))
|
|
70
|
+
: resolve(),
|
|
71
|
+
),
|
|
131
72
|
);
|
|
132
73
|
|
|
133
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
type: 'thread_emoji_update',
|
|
76
|
+
threadID,
|
|
77
|
+
newEmoji: emojiChar,
|
|
78
|
+
senderID: _initiatorID,
|
|
79
|
+
BotID: ctx.userID,
|
|
80
|
+
timestamp: Date.now(),
|
|
81
|
+
};
|
|
134
82
|
};
|
|
135
83
|
}
|
|
@@ -1,106 +1,71 @@
|
|
|
1
1
|
import utils = require('../../../utils');
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @module gcmember
|
|
5
|
+
* @param {Object} defaultFuncs
|
|
6
|
+
* @param {Object} api
|
|
7
|
+
* @param {Object} ctx
|
|
8
|
+
*/
|
|
9
|
+
export default function gcmember(
|
|
10
|
+
defaultFuncs: any,
|
|
11
|
+
api: any,
|
|
12
|
+
ctx: any,
|
|
13
|
+
): Function {
|
|
4
14
|
/**
|
|
5
|
-
* Made by ChoruOfficial
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @param {string|string[]} userIDs The user ID or array of user IDs.
|
|
11
|
-
* @param {string} threadID The ID of the group chat.
|
|
12
|
-
* @param {Function} [callback] Optional callback function.
|
|
13
|
-
* @returns {Promise<object>} A promise that resolves with information about the action.
|
|
15
|
+
* Made by ChoruOfficial — Adds or removes members from a group chat via MQTT.
|
|
16
|
+
* @param {"add" | "remove"} action - The action to perform.
|
|
17
|
+
* @param {string | string[]} userIDs - The user ID or array of user IDs.
|
|
18
|
+
* @param {string} threadID - The ID of the group chat.
|
|
19
|
+
* @returns {Promise<object>}
|
|
14
20
|
*/
|
|
15
|
-
return async function gcmember(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let resolvePromise, rejectPromise;
|
|
25
|
-
const returnPromise = new Promise<any>((resolve, reject) => {
|
|
26
|
-
resolvePromise = resolve;
|
|
27
|
-
rejectPromise = reject;
|
|
28
|
-
});
|
|
21
|
+
return async function gcmember(
|
|
22
|
+
action: 'add' | 'remove',
|
|
23
|
+
userIDs: string | string[],
|
|
24
|
+
threadID: string,
|
|
25
|
+
): Promise<any> {
|
|
26
|
+
const validActions = ['add', 'remove'];
|
|
27
|
+
const normalizedAction = (action || '').toLowerCase() as 'add' | 'remove';
|
|
29
28
|
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
if (!validActions.includes(normalizedAction)) {
|
|
30
|
+
return { type: 'error_gc', error: `Invalid action. Must be one of: ${validActions.join(', ')}` };
|
|
31
|
+
}
|
|
32
|
+
if (!userIDs || (Array.isArray(userIDs) && userIDs.length === 0)) {
|
|
33
|
+
return { type: 'error_gc', error: 'userIDs is required.' };
|
|
34
|
+
}
|
|
35
|
+
if (!threadID) {
|
|
36
|
+
return { type: 'error_gc', error: 'threadID is required.' };
|
|
37
|
+
}
|
|
38
|
+
if (!ctx.mqttClient) {
|
|
39
|
+
return { type: 'error_gc', error: 'Not connected to MQTT' };
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
try {
|
|
39
|
-
const validActions = ['add', 'remove'];
|
|
40
|
-
action = action ? action.toLowerCase() : '';
|
|
41
|
-
|
|
42
|
-
// --- ERROR CHECKS NOW RETURN AN OBJECT INSTEAD OF THROWING ---
|
|
43
|
-
if (!validActions.includes(action)) {
|
|
44
|
-
return _callback(null, {
|
|
45
|
-
type: 'error_gc',
|
|
46
|
-
error: `Invalid action. Must be one of: ${validActions.join(', ')}`,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (!userIDs || userIDs.length === 0) {
|
|
50
|
-
return _callback(null, {
|
|
51
|
-
type: 'error_gc',
|
|
52
|
-
error: 'userIDs is required.',
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (!threadID) {
|
|
56
|
-
return _callback(null, {
|
|
57
|
-
type: 'error_gc',
|
|
58
|
-
error: 'threadID is required.',
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (!ctx.mqttClient) {
|
|
62
|
-
return _callback(null, {
|
|
63
|
-
type: 'error_gc',
|
|
64
|
-
error: 'Not connected to MQTT',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
43
|
const threadInfo = await api.getThreadInfo(threadID);
|
|
69
44
|
if (!threadInfo) {
|
|
70
|
-
return
|
|
71
|
-
type: 'error_gc',
|
|
72
|
-
error: 'Could not retrieve thread information.',
|
|
73
|
-
});
|
|
45
|
+
return { type: 'error_gc', error: 'Could not retrieve thread information.' };
|
|
74
46
|
}
|
|
75
47
|
if (threadInfo.isGroup === false) {
|
|
76
|
-
return
|
|
77
|
-
type: 'error_gc',
|
|
78
|
-
error: 'This feature is only for group chats, not private messages.',
|
|
79
|
-
});
|
|
48
|
+
return { type: 'error_gc', error: 'This feature is only for group chats, not private messages.' };
|
|
80
49
|
}
|
|
81
50
|
|
|
82
|
-
const currentMembers = threadInfo.participantIDs;
|
|
51
|
+
const currentMembers: string[] = threadInfo.participantIDs;
|
|
83
52
|
const usersToModify = Array.isArray(userIDs) ? userIDs : [userIDs];
|
|
84
|
-
let queryPayload, query;
|
|
85
|
-
let finalUsers = usersToModify;
|
|
86
53
|
|
|
87
54
|
ctx.wsReqNumber = (ctx.wsReqNumber || 0) + 1;
|
|
88
55
|
ctx.wsTaskNumber = (ctx.wsTaskNumber || 0) + 1;
|
|
89
56
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
57
|
+
let query: any;
|
|
58
|
+
let finalUsers: string[];
|
|
59
|
+
|
|
60
|
+
if (normalizedAction === 'add') {
|
|
61
|
+
const usersToAdd = usersToModify.filter((id) => !currentMembers.includes(id));
|
|
94
62
|
if (usersToAdd.length === 0) {
|
|
95
|
-
return
|
|
96
|
-
type: 'error_gc',
|
|
97
|
-
error: 'All specified users are already in the group.',
|
|
98
|
-
});
|
|
63
|
+
return { type: 'error_gc', error: 'All specified users are already in the group.' };
|
|
99
64
|
}
|
|
100
65
|
finalUsers = usersToAdd;
|
|
101
|
-
queryPayload = {
|
|
102
|
-
thread_key: parseInt(threadID),
|
|
103
|
-
contact_ids: finalUsers.map((id) => parseInt(id)),
|
|
66
|
+
const queryPayload = {
|
|
67
|
+
thread_key: Number.parseInt(threadID),
|
|
68
|
+
contact_ids: finalUsers.map((id) => Number.parseInt(id)),
|
|
104
69
|
sync_group: 1,
|
|
105
70
|
};
|
|
106
71
|
query = {
|
|
@@ -110,16 +75,12 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
110
75
|
task_id: ctx.wsTaskNumber,
|
|
111
76
|
};
|
|
112
77
|
} else {
|
|
113
|
-
// action is 'remove'
|
|
114
78
|
const userToRemove = usersToModify[0];
|
|
115
79
|
if (!currentMembers.includes(userToRemove)) {
|
|
116
|
-
return
|
|
117
|
-
type: 'error_gc',
|
|
118
|
-
error: `User with ID ${userToRemove} is not in this group chat.`,
|
|
119
|
-
});
|
|
80
|
+
return { type: 'error_gc', error: `User with ID ${userToRemove} is not in this group chat.` };
|
|
120
81
|
}
|
|
121
82
|
finalUsers = [userToRemove];
|
|
122
|
-
queryPayload = {
|
|
83
|
+
const queryPayload = {
|
|
123
84
|
thread_id: threadID,
|
|
124
85
|
contact_id: userToRemove,
|
|
125
86
|
sync_group: 1,
|
|
@@ -135,7 +96,7 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
135
96
|
const context: any = {
|
|
136
97
|
app_id: ctx.appID,
|
|
137
98
|
payload: {
|
|
138
|
-
epoch_id: parseInt(utils.generateOfflineThreadingID()),
|
|
99
|
+
epoch_id: Number.parseInt(utils.generateOfflineThreadingID()),
|
|
139
100
|
tasks: [query],
|
|
140
101
|
version_id: '24631415369801570',
|
|
141
102
|
},
|
|
@@ -144,32 +105,26 @@ export default function(defaultFuncs: any, api: any, ctx: any) {
|
|
|
144
105
|
};
|
|
145
106
|
context.payload = JSON.stringify(context.payload);
|
|
146
107
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const gcmemberInfo = {
|
|
155
|
-
type: 'gc_member_update',
|
|
156
|
-
threadID: threadID,
|
|
157
|
-
userIDs: finalUsers,
|
|
158
|
-
action: action,
|
|
159
|
-
senderID: ctx.userID,
|
|
160
|
-
BotID: ctx.userID,
|
|
161
|
-
timestamp: Date.now(),
|
|
162
|
-
};
|
|
163
|
-
return _callback(null, gcmemberInfo);
|
|
164
|
-
},
|
|
108
|
+
await new Promise<void>((resolve, reject) =>
|
|
109
|
+
ctx.mqttClient.publish(
|
|
110
|
+
'/ls_req',
|
|
111
|
+
JSON.stringify(context),
|
|
112
|
+
{ qos: 1, retain: false },
|
|
113
|
+
(err) => (err ? reject(err) : resolve()),
|
|
114
|
+
),
|
|
165
115
|
);
|
|
166
|
-
} catch (err) {
|
|
167
|
-
return _callback(null, {
|
|
168
|
-
type: 'error_gc',
|
|
169
|
-
error: err.message || 'An unknown error occurred.',
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
116
|
|
|
173
|
-
|
|
117
|
+
return {
|
|
118
|
+
type: 'gc_member_update',
|
|
119
|
+
threadID,
|
|
120
|
+
userIDs: finalUsers,
|
|
121
|
+
action: normalizedAction,
|
|
122
|
+
senderID: ctx.userID,
|
|
123
|
+
BotID: ctx.userID,
|
|
124
|
+
timestamp: Date.now(),
|
|
125
|
+
};
|
|
126
|
+
} catch (err: any) {
|
|
127
|
+
return { type: 'error_gc', error: err.message || 'An unknown error occurred.' };
|
|
128
|
+
}
|
|
174
129
|
};
|
|
175
130
|
}
|