bb-fca 2.0.9 → 2.0.11
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 +440 -11
- package/dist/deltas/apis/posting/group.js.map +1 -1
- package/dist/index.d.ts +18 -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 +88 -0
- 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 +516 -11
- package/src/types/index.d.ts +18 -0
- package/request.txt +0 -60
|
@@ -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;
|
|
@@ -65,4 +65,92 @@ export default function (defaultFuncs: any, api: any, ctx: any): {
|
|
|
65
65
|
cursor: string | null;
|
|
66
66
|
hasNextPage: boolean;
|
|
67
67
|
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Resolves a Facebook share URL to the actual group ID.
|
|
70
|
+
*
|
|
71
|
+
* Accepts various formats:
|
|
72
|
+
* - Full URL: `https://www.facebook.com/share/g/14bKqsywAfu/`
|
|
73
|
+
* - Path only: `/share/g/14bKqsywAfu/`
|
|
74
|
+
* - Short key: `14bKqsywAfu`
|
|
75
|
+
*
|
|
76
|
+
* @param {string} shareUrl The share URL, path, or short key to resolve.
|
|
77
|
+
* @returns {Promise<{ groupID: string; name: string | null; url: string | null }>}
|
|
78
|
+
* The resolved group ID, name (if available), and canonical URL.
|
|
79
|
+
* @throws {Error} If the shareUrl is missing or the group ID cannot be extracted.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const result = await api.group.resolveShareUrl('https://www.facebook.com/share/g/14bKqsywAfu/');
|
|
83
|
+
* console.log(result.groupID); // "1482314963016056"
|
|
84
|
+
*/
|
|
85
|
+
resolveShareUrl: (shareUrl: string) => Promise<{
|
|
86
|
+
groupID: string;
|
|
87
|
+
name: string | null;
|
|
88
|
+
url: string | null;
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Uploads a photo to Facebook for use in group posts.
|
|
92
|
+
*
|
|
93
|
+
* The photo is uploaded to `upload.facebook.com` with the group discussion
|
|
94
|
+
* route context (`CometGroupDiscussionRoute`), making it ready to be
|
|
95
|
+
* attached to a group post via {@link createGroupPost}.
|
|
96
|
+
*
|
|
97
|
+
* @param {string | string[]} photoPaths - A single file path or an array of file paths to upload.
|
|
98
|
+
* @returns {Promise<{ photoID: string; uploadID: string; data: any }[]>}
|
|
99
|
+
* Array of upload results, one per photo, each containing:
|
|
100
|
+
* - `photoID` – The Facebook-assigned photo ID (use in `createGroupPost`).
|
|
101
|
+
* - `uploadID` – The client-generated upload ID.
|
|
102
|
+
* - `data` – The raw server response payload.
|
|
103
|
+
* @throws {Error} If any path is missing, not a string, or doesn't exist on disk.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const [photo] = await api.group.uploadPhoto('/path/to/image.jpg');
|
|
107
|
+
* const post = await api.group.createGroupPost('123456789', {
|
|
108
|
+
* message: 'Check this out!',
|
|
109
|
+
* photos: [photo.photoID],
|
|
110
|
+
* });
|
|
111
|
+
*/
|
|
112
|
+
uploadPhoto: (photoPaths: string | string[]) => Promise<{
|
|
113
|
+
photoID: string;
|
|
114
|
+
uploadID: string;
|
|
115
|
+
data: any;
|
|
116
|
+
}[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a post in a Facebook group, optionally with photo attachments and a title.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} groupID - The ID of the group to post in.
|
|
121
|
+
* @param {object} options - Post options.
|
|
122
|
+
* @param {string} [options.message=''] - The text content of the post.
|
|
123
|
+
* @param {string} [options.title] - Optional post title (for groups that support titled posts).
|
|
124
|
+
* @param {string[]} [options.photos=[]] - Array of photo IDs from {@link uploadPhoto}.
|
|
125
|
+
* @returns {Promise<{ success: boolean; postID: string | null; url: string | null; data: any }>}
|
|
126
|
+
* @throws {Error} If groupID is missing or the API request fails.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* // Text-only post
|
|
130
|
+
* await api.group.createGroupPost('123456789', { message: 'Hello group!' });
|
|
131
|
+
*
|
|
132
|
+
* // Post with photos
|
|
133
|
+
* const photos = await api.group.uploadPhoto(['/path/a.jpg', '/path/b.jpg']);
|
|
134
|
+
* await api.group.createGroupPost('123456789', {
|
|
135
|
+
* message: 'Check these out!',
|
|
136
|
+
* photos: photos.map(p => p.photoID),
|
|
137
|
+
* });
|
|
138
|
+
*
|
|
139
|
+
* // Post with title and photos
|
|
140
|
+
* await api.group.createGroupPost('123456789', {
|
|
141
|
+
* message: 'Post body here',
|
|
142
|
+
* title: 'My Post Title',
|
|
143
|
+
* photos: photos.map(p => p.photoID),
|
|
144
|
+
* });
|
|
145
|
+
*/
|
|
146
|
+
createGroupPost: (groupID: string, options?: {
|
|
147
|
+
message?: string;
|
|
148
|
+
title?: string;
|
|
149
|
+
photos?: string[];
|
|
150
|
+
}) => Promise<{
|
|
151
|
+
success: boolean;
|
|
152
|
+
postID: string | null;
|
|
153
|
+
url: string | null;
|
|
154
|
+
data: any;
|
|
155
|
+
}>;
|
|
68
156
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bb-fca",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
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
|
}
|