rapido-fca 0.0.1 → 0.0.3
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/package.json +1 -1
- package/readme.md +39 -237
- package/src/addExternalModule.js +23 -19
- package/src/addUserToGroup.js +97 -99
- package/src/changeAdminStatus.js +62 -86
- package/src/changeArchivedStatus.js +49 -49
- package/src/changeAvatar.js +108 -118
- package/src/changeBio.js +64 -63
- package/src/changeBlockedStatus.js +38 -40
- package/src/changeGroupImage.js +126 -129
- package/src/changeNickname.js +49 -49
- package/src/changeThreadColor.js +53 -53
- package/src/changeThreadEmoji.js +45 -45
- package/src/createNewGroup.js +72 -74
- package/src/createPoll.js +59 -59
- package/src/deleteMessage.js +50 -50
- package/src/deleteThread.js +50 -50
- package/src/editMessage.js +49 -51
- package/src/forwardAttachment.js +54 -54
- package/src/getCurrentUserID.js +3 -3
- package/src/getEmojiUrl.js +17 -17
- package/src/getFriendsList.js +67 -67
- package/src/getMessage.js +767 -806
- package/src/getThreadHistory.js +642 -656
- package/src/getThreadInfo.js +1 -1
- package/src/getThreadList.js +227 -199
- package/src/getThreadPictures.js +71 -51
- package/src/getUserID.js +58 -53
- package/src/getUserInfo.js +60 -52
- package/src/handleFriendRequest.js +65 -41
- package/src/handleMessageRequest.js +60 -42
- package/src/httpGet.js +57 -49
- package/src/httpPost.js +57 -48
- package/src/httpPostFormData.js +63 -0
- package/src/listenMqtt.js +895 -827
- package/src/logout.js +61 -61
- package/src/markAsDelivered.js +53 -42
- package/src/markAsRead.js +69 -59
- package/src/markAsReadAll.js +42 -32
- package/src/markAsSeen.js +54 -43
- package/src/muteThread.js +47 -40
- package/src/refreshFb_dtsg.js +69 -77
- package/src/removeUserFromGroup.js +67 -67
- package/src/resolvePhotoUrl.js +34 -34
- package/src/searchForThread.js +43 -43
- package/src/sendMessage.js +228 -80
- package/src/sendTypingIndicator.js +88 -86
- package/src/setMessageReaction.js +109 -110
- package/src/setPostReaction.js +87 -90
- package/src/setTitle.js +72 -76
- package/src/threadColors.js +121 -121
- package/src/unfriend.js +43 -43
- package/src/unsendMessage.js +38 -34
- package/src/uploadAttachment.js +81 -79
- package/src/changeAvatarV2.js +0 -86
- package/src/changeAvt.js +0 -85
- package/src/changeBlockedStatusMqtt.js +0 -80
- package/src/changeCover.js +0 -72
- package/src/changeName.js +0 -79
- package/src/changeUsername.js +0 -59
- package/src/createCommentPost.js +0 -230
- package/src/createPost.js +0 -276
- package/src/editMessageOld.js +0 -67
- package/src/follow.js +0 -74
- package/src/getAccess.js +0 -112
- package/src/getAvatarUser.js +0 -78
- package/src/getRegion.js +0 -7
- package/src/getThreadHistoryDeprecated.js +0 -71
- package/src/getThreadInfoDeprecated.js +0 -56
- package/src/getThreadListDeprecated.js +0 -46
- package/src/getUID.js +0 -119
- package/src/searchStickers.js +0 -53
- package/src/sendMessageMqtt.js +0 -322
- package/src/sendTypingIndicatorV2.js +0 -28
- package/src/setMessageReactionMqtt.js +0 -62
- package/src/setStoryReaction.js +0 -64
- package/src/shareContact.js +0 -110
- package/src/shareLink.js +0 -59
- package/src/stopListenMqtt.js +0 -23
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,254 +1,56 @@
|
|
|
1
|
-
# Unofficial Facebook Chat API
|
|
2
|
-
<a href="https://www.npmjs.com/package/facebook-chat-api"><img alt="npm version" src="https://img.shields.io/npm/v/facebook-chat-api.svg?style=flat-square"></a>
|
|
3
|
-
<a href="https://www.npmjs.com/package/facebook-chat-api"><img src="https://img.shields.io/npm/dm/facebook-chat-api.svg?style=flat-square" alt="npm downloads"></a>
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
1
|
+
# Rapido-FCA: Unofficial Facebook Chat API
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
A lightweight, fast, and unofficial API to interact with Facebook Chat programmatically.
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_Disclaimer_: We are not responsible if your account gets banned for spammy activities such as sending lots of messages to people you don't know, sending messages very quickly, sending spammy looking URLs, logging in and out very quickly... Be responsible Facebook citizens.
|
|
11
|
-
|
|
12
|
-
See [below](#projects-using-this-api) for projects using this API.
|
|
13
|
-
|
|
14
|
-
See the [full changelog](/CHANGELOG.md) for release details.
|
|
15
|
-
|
|
16
|
-
## Install
|
|
17
|
-
If you just want to use facebook-chat-api, you should use this command:
|
|
5
|
+
## Installation
|
|
18
6
|
```bash
|
|
19
7
|
npm install rapido-fca
|
|
20
8
|
```
|
|
21
|
-
It will download facebook-chat-api from NPM repositories
|
|
22
9
|
|
|
23
|
-
|
|
24
|
-
If you want to use bleeding edge (directly from github) to test new features or submit bug report, this is the command for you:
|
|
25
|
-
```bash
|
|
26
|
-
npm install markzino09/rapido-fca
|
|
27
|
-
```
|
|
10
|
+
## Quick Start
|
|
28
11
|
|
|
29
|
-
|
|
30
|
-
If you want to test your bots without creating another account on Facebook, you can use [Facebook Whitehat Accounts](https://www.facebook.com/whitehat/accounts/).
|
|
31
|
-
|
|
32
|
-
## Example Usage
|
|
12
|
+
### Login Example
|
|
33
13
|
```javascript
|
|
34
|
-
const login = require(
|
|
35
|
-
|
|
36
|
-
// Create simple echo bot
|
|
37
|
-
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
|
38
|
-
if(err) return console.error(err);
|
|
14
|
+
const login = require('rapido-fca');
|
|
39
15
|
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
async function login() {
|
|
17
|
+
try {
|
|
18
|
+
const api = await login({
|
|
19
|
+
email: 'your_facebook_email',
|
|
20
|
+
password: 'your_password'
|
|
42
21
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## Documentation
|
|
52
|
-
|
|
53
|
-
* [`login`](DOCS.md#login)
|
|
54
|
-
* [`api.addUserToGroup`](DOCS.md#addUserToGroup)
|
|
55
|
-
* [`api.changeAdminStatus`](DOCS.md#changeAdminStatus)
|
|
56
|
-
* [`api.changeArchivedStatus`](DOCS.md#changeArchivedStatus)
|
|
57
|
-
* [`api.changeBlockedStatus`](DOCS.md#changeBlockedStatus)
|
|
58
|
-
* [`api.changeGroupImage`](DOCS.md#changeGroupImage)
|
|
59
|
-
* [`api.changeNickname`](DOCS.md#changeNickname)
|
|
60
|
-
* [`api.changeThreadColor`](DOCS.md#changeThreadColor)
|
|
61
|
-
* [`api.changeThreadEmoji`](DOCS.md#changeThreadEmoji)
|
|
62
|
-
* [`api.createPoll`](DOCS.md#createPoll)
|
|
63
|
-
* [`api.deleteMessage`](DOCS.md#deleteMessage)
|
|
64
|
-
* [`api.deleteThread`](DOCS.md#deleteThread)
|
|
65
|
-
* [`api.forwardAttachment`](DOCS.md#forwardAttachment)
|
|
66
|
-
* [`api.getAppState`](DOCS.md#getAppState)
|
|
67
|
-
* [`api.getCurrentUserID`](DOCS.md#getCurrentUserID)
|
|
68
|
-
* [`api.getFriendsList`](DOCS.md#getFriendsList)
|
|
69
|
-
* [`api.getThreadHistory`](DOCS.md#getThreadHistory)
|
|
70
|
-
* [`api.getThreadInfo`](DOCS.md#getThreadInfo)
|
|
71
|
-
* [`api.getThreadList`](DOCS.md#getThreadList)
|
|
72
|
-
* [`api.getThreadPictures`](DOCS.md#getThreadPictures)
|
|
73
|
-
* [`api.getUserID`](DOCS.md#getUserID)
|
|
74
|
-
* [`api.getUserInfo`](DOCS.md#getUserInfo)
|
|
75
|
-
* [`api.handleMessageRequest`](DOCS.md#handleMessageRequest)
|
|
76
|
-
* [`api.listen`](DOCS.md#listen)
|
|
77
|
-
* [`api.listenMqtt`](DOCS.md#listenMqtt)
|
|
78
|
-
* [`api.logout`](DOCS.md#logout)
|
|
79
|
-
* [`api.markAsRead`](DOCS.md#markAsRead)
|
|
80
|
-
* [`api.markAsReadAll`](DOCS.md#markAsReadAll)
|
|
81
|
-
* [`api.muteThread`](DOCS.md#muteThread)
|
|
82
|
-
* [`api.removeUserFromGroup`](DOCS.md#removeUserFromGroup)
|
|
83
|
-
* [`api.resolvePhotoUrl`](DOCS.md#resolvePhotoUrl)
|
|
84
|
-
* [`api.searchForThread`](DOCS.md#searchForThread)
|
|
85
|
-
* [`api.sendMessage`](DOCS.md#sendMessage)
|
|
86
|
-
* [`api.sendTypingIndicator`](DOCS.md#sendTypingIndicator)
|
|
87
|
-
* [`api.setMessageReaction`](DOCS.md#setMessageReaction)
|
|
88
|
-
* [`api.setOptions`](DOCS.md#setOptions)
|
|
89
|
-
* [`api.setTitle`](DOCS.md#setTitle)
|
|
90
|
-
* [`api.unsendMessage`](DOCS.md#unsendMessage)
|
|
91
|
-
|
|
92
|
-
## Main Functionality
|
|
93
|
-
|
|
94
|
-
### Sending a message
|
|
95
|
-
#### api.sendMessage(message, threadID[, callback][, messageID])
|
|
96
|
-
|
|
97
|
-
Various types of message can be sent:
|
|
98
|
-
* *Regular:* set field `body` to the desired message as a string.
|
|
99
|
-
* *Sticker:* set a field `sticker` to the desired sticker ID.
|
|
100
|
-
* *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
|
|
101
|
-
* *URL:* set a field `url` to the desired URL.
|
|
102
|
-
* *Emoji:* set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
|
|
103
|
-
|
|
104
|
-
Note that a message can only be a regular message (which can be empty) and optionally one of the following: a sticker, an attachment or a url.
|
|
105
|
-
|
|
106
|
-
__Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
|
|
107
|
-
|
|
108
|
-
__Example (Basic Message)__
|
|
109
|
-
```js
|
|
110
|
-
const login = require("rapido-fca");
|
|
111
|
-
|
|
112
|
-
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
|
113
|
-
if(err) return console.error(err);
|
|
114
|
-
|
|
115
|
-
var yourID = "000000000000000";
|
|
116
|
-
var msg = "Hey!";
|
|
117
|
-
api.sendMessage(msg, yourID);
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
__Example (File upload)__
|
|
122
|
-
```js
|
|
123
|
-
const login = require("rapido-fca");
|
|
124
|
-
|
|
125
|
-
login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
|
126
|
-
if(err) return console.error(err);
|
|
127
|
-
|
|
128
|
-
// Note this example uploads an image called image.jpg
|
|
129
|
-
var yourID = "000000000000000";
|
|
130
|
-
var msg = {
|
|
131
|
-
body: "Hey!",
|
|
132
|
-
attachment: fs.createReadStream(__dirname + '/image.jpg')
|
|
133
|
-
}
|
|
134
|
-
api.sendMessage(msg, yourID);
|
|
135
|
-
});
|
|
22
|
+
console.log('Logged in successfully!');
|
|
23
|
+
return api;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error('Login failed:', error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
login();
|
|
136
30
|
```
|
|
137
31
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
__Example__
|
|
144
|
-
|
|
145
|
-
```js
|
|
146
|
-
const fs = require("fs");
|
|
147
|
-
const login = require("rapido-fca");
|
|
148
|
-
|
|
149
|
-
var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
|
|
150
|
-
|
|
151
|
-
login(credentials, (err, api) => {
|
|
152
|
-
if(err) return console.error(err);
|
|
153
|
-
|
|
154
|
-
fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
|
|
155
|
-
});
|
|
32
|
+
### Send Message Example
|
|
33
|
+
```javascript
|
|
34
|
+
const api = await login();
|
|
35
|
+
api.sendMessage("Hello from Rapido-FCA!", "friend_user_id");
|
|
156
36
|
```
|
|
157
37
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
Listen watches for messages sent in a chat. By default this won't receive events (joining/leaving a chat, title change etc…) but it can be activated with `api.setOptions({listenEvents: true})`. This will by default ignore messages sent by the current account, you can enable listening to your own messages with `api.setOptions({selfListen: true})`.
|
|
164
|
-
|
|
165
|
-
__Example__
|
|
166
|
-
|
|
167
|
-
```js
|
|
168
|
-
const fs = require("fs");
|
|
169
|
-
const login = require("rapido-fca");
|
|
170
|
-
|
|
171
|
-
// Simple echo bot. It will repeat everything that you say.
|
|
172
|
-
// Will stop when you say '/stop'
|
|
173
|
-
login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
|
|
174
|
-
if(err) return console.error(err);
|
|
175
|
-
|
|
176
|
-
api.setOptions({listenEvents: true});
|
|
177
|
-
|
|
178
|
-
var stopListening = api.listen((err, event) => {
|
|
179
|
-
if(err) return console.error(err);
|
|
180
|
-
|
|
181
|
-
api.markAsRead(event.threadID, (err) => {
|
|
182
|
-
if(err) console.error(err);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
switch(event.type) {
|
|
186
|
-
case "message":
|
|
187
|
-
if(event.body === '/stop') {
|
|
188
|
-
api.sendMessage("Goodbye…", event.threadID);
|
|
189
|
-
return stopListening();
|
|
190
|
-
}
|
|
191
|
-
api.sendMessage("TEST BOT: " + event.body, event.threadID);
|
|
192
|
-
break;
|
|
193
|
-
case "event":
|
|
194
|
-
console.log(event);
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
38
|
+
### Listen for Messages
|
|
39
|
+
```javascript
|
|
40
|
+
api.listen((err, message) => {
|
|
41
|
+
if (err) return console.error(err);
|
|
42
|
+
console.log('Received message:', message.body);
|
|
198
43
|
});
|
|
199
44
|
```
|
|
200
45
|
|
|
201
|
-
##
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
4. How can I avoid logging in every time? Can I log into a previous session?
|
|
213
|
-
> We support caching everything relevant for you to bypass login. `api.getAppState()` returns an object that you can save and pass into login as `{appState: mySavedAppState}` instead of the credentials object. If this fails, your session has expired.
|
|
214
|
-
|
|
215
|
-
5. Do you support sending messages as a page?
|
|
216
|
-
> Yes, set the pageID option on login (this doesn't work if you set it using api.setOptions, it affects the login process).
|
|
217
|
-
> ```js
|
|
218
|
-
> login(credentials, {pageID: "000000000000000"}, (err, api) => { … }
|
|
219
|
-
> ```
|
|
220
|
-
|
|
221
|
-
6. I'm getting some crazy weird syntax error like `SyntaxError: Unexpected token [`!!!
|
|
222
|
-
> Please try to update your version of node.js before submitting an issue of this nature. We like to use new language features.
|
|
223
|
-
|
|
224
|
-
7. I don't want all of these logging messages!
|
|
225
|
-
> You can use `api.setOptions` to silence the logging. You get the `api` object from `login` (see example above). Do
|
|
226
|
-
> ```js
|
|
227
|
-
> api.setOptions({
|
|
228
|
-
> logLevel: "silent"
|
|
229
|
-
> });
|
|
230
|
-
> ```
|
|
231
|
-
|
|
232
|
-
## Projects using this API
|
|
233
|
-
|
|
234
|
-
- [Messer](https://github.com/mjkaufer/Messer) - Command-line messaging for Facebook Messenger
|
|
235
|
-
- [messen](https://github.com/tomquirk/messen) - Rapidly build Facebook Messenger apps in Node.js
|
|
236
|
-
- [Concierge](https://github.com/concierge/Concierge) - Concierge is a highly modular, easily extensible general purpose chat bot with a built in package manager
|
|
237
|
-
- [Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot) - Facebook chat bot
|
|
238
|
-
- [Marc Thuckerbot](https://github.com/bsansouci/lisp-bot) - Programmable lisp bot
|
|
239
|
-
- [MarkovsInequality](https://github.com/logicx24/MarkovsInequality) - Extensible chat bot adding useful functions to Facebook Messenger
|
|
240
|
-
- [AllanBot](https://github.com/AllanWang/AllanBot-Public) - Extensive module that combines the facebook api with firebase to create numerous functions; no coding experience is required to implement this.
|
|
241
|
-
- [Larry Pudding Dog Bot](https://github.com/Larry850806/facebook-chat-bot) - A facebook bot you can easily customize the response
|
|
242
|
-
- [fbash](https://github.com/avikj/fbash) - Run commands on your computer's terminal over Facebook Messenger
|
|
243
|
-
- [Klink](https://github.com/KeNt178/klink) - This Chrome extension will 1-click share the link of your active tab over Facebook Messenger
|
|
244
|
-
- [Botyo](https://github.com/ivkos/botyo) - Modular bot designed for group chat rooms on Facebook
|
|
245
|
-
- [matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook) - A facebook bridge for [matrix](https://matrix.org)
|
|
246
|
-
- [facebot](https://github.com/Weetbix/facebot) - A facebook bridge for Slack.
|
|
247
|
-
- [Botium](https://github.com/codeforequity-at/botium-core) - The Selenium for Chatbots
|
|
248
|
-
- [Messenger-CLI](https://github.com/AstroCB/Messenger-CLI) - A command-line interface for sending and receiving messages through Facebook Messenger.
|
|
249
|
-
- [AssumeZero-Bot](https://github.com/AstroCB/AssumeZero-Bot) – A highly customizable Facebook Messenger bot for group chats.
|
|
250
|
-
- [Miscord](https://github.com/Bjornskjald/miscord) - An easy-to-use Facebook bridge for Discord.
|
|
251
|
-
- [chat-bridge](https://github.com/rexx0520/chat-bridge) - A Messenger, Telegram and IRC chat bridge.
|
|
252
|
-
- [messenger-auto-reply](https://gitlab.com/theSander/messenger-auto-reply) - An auto-reply service for Messenger.
|
|
253
|
-
- [BotCore](https://github.com/AstroCB/BotCore) – A collection of tools for writing and managing Facebook Messenger bots.
|
|
254
|
-
- [mnotify](https://github.com/AstroCB/mnotify) – A command-line utility for sending alerts and notifications through Facebook Messenger.
|
|
46
|
+
## API Methods
|
|
47
|
+
| Method | Description |
|
|
48
|
+
|----------------------|--------------------------------------|
|
|
49
|
+
| `login()` | Authenticate with Facebook |
|
|
50
|
+
| `sendMessage()` | Send text message |
|
|
51
|
+
| `listen()` | Receive incoming messages |
|
|
52
|
+
| `getUserInfo()` | Fetch user profile data |
|
|
53
|
+
| `handleRequest()` | Accept/reject friend requests |
|
|
54
|
+
|
|
55
|
+
## Disclaimer
|
|
56
|
+
This is an **unofficial** API. Use at your own risk. Not affiliated with Facebook.
|
package/src/addExternalModule.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const utils = require("../utils");
|
|
4
|
+
const log = require("npmlog");
|
|
4
5
|
|
|
5
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} else {
|
|
20
|
-
throw new Error(
|
|
21
|
-
`moduleObj must be an object, not ${utils.getType(moduleObj)}!`,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
7
|
+
return function addExternalModule(moduleObj) {
|
|
8
|
+
if (utils.getType(moduleObj) == "Object") {
|
|
9
|
+
for (const apiName in moduleObj) {
|
|
10
|
+
if (utils.getType(moduleObj[apiName]) == "Function") {
|
|
11
|
+
api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx, utils, log);
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error(`Item "${apiName}" in moduleObj must be a function, not ${utils.getType(moduleObj[apiName])}!`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error(`moduleObj must be an object, not ${utils.getType(moduleObj)}!`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
25
20
|
};
|
|
21
|
+
|
|
22
|
+
// example usage:
|
|
23
|
+
// api.addExternalModule({
|
|
24
|
+
// getCtx: (defaultFuncs, api, ctx, utils, log) => {
|
|
25
|
+
// return function getCtx() {
|
|
26
|
+
// return ctx;
|
|
27
|
+
// };
|
|
28
|
+
// }
|
|
29
|
+
// });
|
package/src/addUserToGroup.js
CHANGED
|
@@ -1,115 +1,113 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const utils = require("../utils");
|
|
4
|
-
|
|
4
|
+
const log = require("npmlog");
|
|
5
5
|
|
|
6
6
|
module.exports = function (defaultFuncs, api, ctx) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
return function addUserToGroup(userID, threadID, callback) {
|
|
8
|
+
let resolveFunc = function () { };
|
|
9
|
+
let rejectFunc = function () { };
|
|
10
|
+
const returnPromise = new Promise(function (resolve, reject) {
|
|
11
|
+
resolveFunc = resolve;
|
|
12
|
+
rejectFunc = reject;
|
|
13
|
+
});
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
}
|
|
15
|
+
if (
|
|
16
|
+
!callback &&
|
|
17
|
+
(utils.getType(threadID) === "Function" ||
|
|
18
|
+
utils.getType(threadID) === "AsyncFunction")
|
|
19
|
+
) {
|
|
20
|
+
throw new utils.CustomError({ error: "please pass a threadID as a second argument." });
|
|
21
|
+
}
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (!callback) {
|
|
24
|
+
callback = function (err) {
|
|
25
|
+
if (err) {
|
|
26
|
+
return rejectFunc(err);
|
|
27
|
+
}
|
|
28
|
+
resolveFunc();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
if (
|
|
33
|
+
utils.getType(threadID) !== "Number" &&
|
|
34
|
+
utils.getType(threadID) !== "String"
|
|
35
|
+
) {
|
|
36
|
+
throw new utils.CustomError({
|
|
37
|
+
error:
|
|
38
|
+
"ThreadID should be of type Number or String and not " +
|
|
39
|
+
utils.getType(threadID) +
|
|
40
|
+
"."
|
|
41
|
+
});
|
|
42
|
+
}
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (utils.getType(userID) !== "Array") {
|
|
45
|
+
userID = [userID];
|
|
46
|
+
}
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
const messageAndOTID = utils.generateOfflineThreadingID();
|
|
49
|
+
const form = {
|
|
50
|
+
client: "mercury",
|
|
51
|
+
action_type: "ma-type:log-message",
|
|
52
|
+
author: "fbid:" + (ctx.i_userID || ctx.userID),
|
|
53
|
+
thread_id: "",
|
|
54
|
+
timestamp: Date.now(),
|
|
55
|
+
timestamp_absolute: "Today",
|
|
56
|
+
timestamp_relative: utils.generateTimestampRelative(),
|
|
57
|
+
timestamp_time_passed: "0",
|
|
58
|
+
is_unread: false,
|
|
59
|
+
is_cleared: false,
|
|
60
|
+
is_forward: false,
|
|
61
|
+
is_filtered_content: false,
|
|
62
|
+
is_filtered_content_bh: false,
|
|
63
|
+
is_filtered_content_account: false,
|
|
64
|
+
is_spoof_warning: false,
|
|
65
|
+
source: "source:chat:web",
|
|
66
|
+
"source_tags[0]": "source:chat",
|
|
67
|
+
log_message_type: "log:subscribe",
|
|
68
|
+
status: "0",
|
|
69
|
+
offline_threading_id: messageAndOTID,
|
|
70
|
+
message_id: messageAndOTID,
|
|
71
|
+
threading_id: utils.generateThreadingID(ctx.clientID),
|
|
72
|
+
manual_retry_cnt: "0",
|
|
73
|
+
thread_fbid: threadID
|
|
74
|
+
};
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
for (let i = 0; i < userID.length; i++) {
|
|
77
|
+
if (
|
|
78
|
+
utils.getType(userID[i]) !== "Number" &&
|
|
79
|
+
utils.getType(userID[i]) !== "String"
|
|
80
|
+
) {
|
|
81
|
+
throw new utils.CustomError({
|
|
82
|
+
error:
|
|
83
|
+
"Elements of userID should be of type Number or String and not " +
|
|
84
|
+
utils.getType(userID[i]) +
|
|
85
|
+
"."
|
|
86
|
+
});
|
|
87
|
+
}
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
form["log_message_data[added_participants][" + i + "]"] =
|
|
90
|
+
"fbid:" + userID[i];
|
|
91
|
+
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
defaultFuncs
|
|
94
|
+
.post("https://www.facebook.com/messaging/send/", ctx.jar, form)
|
|
95
|
+
.then(utils.parseAndCheckLogin(ctx, defaultFuncs))
|
|
96
|
+
.then(function (resData) {
|
|
97
|
+
if (!resData) {
|
|
98
|
+
throw new utils.CustomError({ error: "Add to group failed." });
|
|
99
|
+
}
|
|
100
|
+
if (resData.error) {
|
|
101
|
+
throw new utils.CustomError(resData);
|
|
102
|
+
}
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
return callback();
|
|
105
|
+
})
|
|
106
|
+
.catch(function (err) {
|
|
107
|
+
log.error("addUserToGroup", err);
|
|
108
|
+
return callback(err);
|
|
109
|
+
});
|
|
112
110
|
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
return returnPromise;
|
|
112
|
+
};
|
|
115
113
|
};
|