rapido-fca 0.0.10 → 1.0.0

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.

Potentially problematic release.


This version of rapido-fca might be problematic. Click here for more details.

Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/index.js +4 -4
  3. package/package.json +15 -16
  4. package/readme.md +237 -39
  5. package/src/Screenshot.js +83 -0
  6. package/src/addExternalModule.js +19 -23
  7. package/src/addUserToGroup.js +99 -97
  8. package/src/changeAdminStatus.js +86 -62
  9. package/src/changeArchivedStatus.js +49 -49
  10. package/src/changeAvatar.js +118 -108
  11. package/src/changeBio.js +63 -64
  12. package/src/changeBlockedStatus.js +40 -38
  13. package/src/changeGroupImage.js +129 -126
  14. package/src/changeNickname.js +49 -49
  15. package/src/changeThreadColor.js +53 -53
  16. package/src/changeThreadEmoji.js +45 -45
  17. package/src/createNewGroup.js +74 -72
  18. package/src/createPoll.js +59 -59
  19. package/src/deleteMessage.js +50 -50
  20. package/src/deleteThread.js +50 -50
  21. package/src/editMessage.js +51 -49
  22. package/src/forwardAttachment.js +54 -54
  23. package/src/getCurrentUserID.js +3 -3
  24. package/src/getEmojiUrl.js +17 -17
  25. package/src/getFriendsList.js +67 -67
  26. package/src/getMessage.js +806 -767
  27. package/src/getThreadHistory.js +656 -642
  28. package/src/getThreadInfo.js +1 -1
  29. package/src/getThreadList.js +199 -227
  30. package/src/getThreadPictures.js +51 -71
  31. package/src/getUserID.js +53 -58
  32. package/src/getUserInfo.js +52 -60
  33. package/src/handleFriendRequest.js +41 -65
  34. package/src/handleMessageRequest.js +42 -60
  35. package/src/httpGet.js +49 -57
  36. package/src/httpPost.js +48 -57
  37. package/src/listenMqtt.js +827 -827
  38. package/src/listenMqtt.txt +827 -0
  39. package/src/logout.js +61 -61
  40. package/src/markAsDelivered.js +42 -53
  41. package/src/markAsRead.js +59 -69
  42. package/src/markAsReadAll.js +32 -42
  43. package/src/markAsSeen.js +43 -54
  44. package/src/muteThread.js +40 -47
  45. package/src/postFormData.txt +46 -0
  46. package/src/refreshFb_dtsg.js +77 -69
  47. package/src/removeUserFromGroup.js +67 -67
  48. package/src/resolvePhotoUrl.js +34 -34
  49. package/src/searchForThread.js +43 -43
  50. package/src/sendMessage.js +80 -228
  51. package/src/sendTypingIndicator.js +86 -88
  52. package/src/setPostReaction.js +90 -87
  53. package/src/setTitle.js +76 -72
  54. package/src/threadColors.js +121 -121
  55. package/src/unfriend.js +43 -43
  56. package/src/unsendMessage.js +34 -38
  57. package/src/uploadAttachment.js +80 -81
  58. package/src/httpPostFormData.js +0 -63
  59. package/src/setEmojiReaction.js +0 -59
  60. package/src/videoAttachment.js +0 -76
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Avery, Benjamin, David, Maude
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/index.js CHANGED
@@ -135,8 +135,8 @@ function buildAPI(globalOptions, html, jar) {
135
135
  //logger.log(`${cra(`[ CONNECT ]`)} Logged in as ${userID}`, "DATABASE");
136
136
  try { clearInterval(checkVerified); } catch (_) { }
137
137
  const clientID = (Math.random() * 2147483648 | 0).toString(16);
138
- let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=frc&sid=${userID}`;
139
- let region = "FRC";
138
+ let mqttEndpoint = `wss://edge-chat.facebook.com/chat?region=prn&sid=${userID}`;
139
+ let region = "PRN";
140
140
 
141
141
  try {
142
142
  const endpointMatch = html.match(/"endpoint":"([^"]+)"/);
@@ -147,7 +147,7 @@ function buildAPI(globalOptions, html, jar) {
147
147
  if (endpointMatch) {
148
148
  mqttEndpoint = endpointMatch[1].replace(/\\\//g, '/');
149
149
  const url = new URL(mqttEndpoint);
150
- region = url.searchParams.get('region')?.toUpperCase() || "FRC";
150
+ region = url.searchParams.get('region')?.toUpperCase() || "PRN";
151
151
  }
152
152
  } catch (e) {
153
153
  console.log('Using default MQTT endpoint');
@@ -457,4 +457,4 @@ function login(loginData, options, callback) {
457
457
  }
458
458
 
459
459
 
460
- module.exports = login;
460
+ module.exports = login;
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "rapido-fca",
3
- "version": "0.0.10",
3
+ "version": "1.0.0",
4
4
  "description": "A Facebook chat api for messenger bots.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": ""
12
+ },
13
+ "author": "Mark",
14
+ "license": "MIT",
15
+ "homepage": "",
5
16
  "keywords": [
6
17
  "facebook",
7
18
  "chat",
@@ -10,21 +21,6 @@
10
21
  "messenger",
11
22
  "chatbot"
12
23
  ],
13
- "homepage": "",
14
- "repository": {
15
- "type": "git",
16
- "url": ""
17
- },
18
- "license": "MIT",
19
- "author": "rapidodev",
20
- "type": "commonjs",
21
- "main": "index.js",
22
- "directories": {
23
- "test": "test"
24
- },
25
- "scripts": {
26
- "start": "node index.js"
27
- },
28
24
  "dependencies": {
29
25
  "axios": "^1.6.5",
30
26
  "bluebird": "^3.7.2",
@@ -43,5 +39,8 @@
43
39
  },
44
40
  "engines": {
45
41
  "node": ">=10.x"
42
+ },
43
+ "directories": {
44
+ "test": "test"
46
45
  }
47
46
  }
package/readme.md CHANGED
@@ -1,56 +1,254 @@
1
- # Rapido-FCA: Unofficial Facebook Chat API
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
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
2
5
 
3
- A lightweight, fast, and unofficial API to interact with Facebook Chat programmatically.
6
+ Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
4
7
 
5
- ## Installation
8
+ This API is the only way to automate chat functionalities on a user account. We do this by emulating the browser. This means doing the exact same GET/POST requests and tricking Facebook into thinking we're accessing the website normally. Because we're doing it this way, this API won't work with an auth token but requires the credentials of a Facebook account.
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:
6
18
  ```bash
7
19
  npm install rapido-fca
8
20
  ```
21
+ It will download facebook-chat-api from NPM repositories
9
22
 
10
- ## Quick Start
23
+ ### Bleeding edge
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
+ ```
11
28
 
12
- ### Login Example
29
+ ## Testing your bots
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
13
33
  ```javascript
14
- const login = require('rapido-fca');
34
+ const login = require("rapido-fca");
35
+
36
+ // Create simple echo bot
37
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
38
+ if(err) return console.error(err);
15
39
 
16
- async function login() {
17
- try {
18
- const api = await login({
19
- email: 'your_facebook_email',
20
- password: 'your_password'
40
+ api.listenMqtt((err, message) => {
41
+ api.sendMessage(message.body, message.threadID);
21
42
  });
22
- console.log('Logged in successfully!');
23
- return api;
24
- } catch (error) {
25
- console.error('Login failed:', error);
26
- }
27
- }
28
-
29
- login();
43
+ });
30
44
  ```
31
45
 
32
- ### Send Message Example
33
- ```javascript
34
- const api = await login();
35
- api.sendMessage("Hello from Rapido-FCA!", "friend_user_id");
46
+ Result:
47
+
48
+ <img width="517" alt="screen shot 2016-11-04 at 14 36 00" src="https://cloud.githubusercontent.com/assets/4534692/20023545/f8c24130-a29d-11e6-9ef7-47568bdbc1f2.png">
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
+ });
36
119
  ```
37
120
 
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);
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);
43
135
  });
44
136
  ```
45
137
 
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.
138
+ ------------------------------------
139
+ ### Saving session.
140
+
141
+ To avoid logging in every time you should save AppState (cookies etc.) to a file, then you can use it without having password in your scripts.
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
+ });
156
+ ```
157
+
158
+ ------------------------------------
159
+
160
+ ### Listening to a chat
161
+ #### api.listen(callback)
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
+ });
198
+ });
199
+ ```
200
+
201
+ ## FAQS
202
+
203
+ 1. How do I run tests?
204
+ > For tests, create a `test-config.json` file that resembles `example-config.json` and put it in the `test` directory. From the root >directory, run `npm test`.
205
+
206
+ 2. Why doesn't `sendMessage` always work when I'm logged in as a page?
207
+ > Pages can't start conversations with users directly; this is to prevent pages from spamming users.
208
+
209
+ 3. What do I do when `login` doesn't work?
210
+ > First check that you can login to Facebook using the website. If login approvals are enabled, you might be logging in incorrectly. For how to handle login approvals, read our docs on [`login`](DOCS.md#login).
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.
@@ -0,0 +1,83 @@
1
+ /* eslint-disable linebreak-style */
2
+ "use strict";
3
+
4
+
5
+ module.exports = function (defaultFuncs, api, ctx) {
6
+ var Coookie = JSON.parse(JSON.stringify(ctx.jar.getCookies("https://www.facebook.com").concat(ctx.jar.getCookies("https://facebook.com")).concat(ctx.jar.getCookies("https://www.messenger.com"))));
7
+ for (let i of Coookie) {
8
+ i.name = i.key;
9
+ i.domain = 'www.facebook.com';
10
+ delete i.key;
11
+ }
12
+ return function(Link, callback) {
13
+ var logger = require('../logger');
14
+ if (process.platform != 'win32') return logger.Error('Not Supported Platform');
15
+ else try {
16
+ let i = require('puppeteer');
17
+ }
18
+ catch (e) {
19
+ var { execSync } = require('child_process');
20
+ execSync('npm i puppeteer', { stdio: 'inherit' });
21
+ }
22
+ const Screenshot = require('../Extra/ExtraScreenShot');
23
+ var resolveFunc = function () { };
24
+ var rejectFunc = function () { };
25
+ var returnPromise = new Promise(function (resolve, reject) {
26
+ resolveFunc = resolve;
27
+ rejectFunc = reject;
28
+ });
29
+
30
+ if (!callback) {
31
+ callback = function (err, data) {
32
+ if (err) return rejectFunc(err);
33
+ resolveFunc(data);
34
+ };
35
+ }
36
+ if (Link.includes('facebook.com') || Link.includes('Facebook.com') || Link.includes('fb')) {
37
+ let LinkSplit = Link.split('/');
38
+ if (LinkSplit.indexOf("https:") == 0) {
39
+ if (Link.includes('messages')) {
40
+ Screenshot.buffer(Link, {
41
+ cookies: Coookie
42
+ }).then(data => {
43
+ callback(null,data);
44
+ });
45
+ }
46
+ else if (!isNaN(LinkSplit[3]) && !Link.split('=')[1] && !isNaN(Link.split('=')[1])) {
47
+ api.sendMessage('Invaild link, format link: facebook.com/Lazic.Kanzu',global.Fca.Data.event.threadID,global.Fca.Data.event.messageID);
48
+ callback('Error Link', null);
49
+ }
50
+ else if (!isNaN(Link.split('=')[1]) && Link.split('=')[1]) {
51
+ let Format = `https://www.facebook.com/profile.php?id=${Link.split('=')[1]}`;
52
+ Screenshot.buffer(Format, {
53
+ cookies: Coookie
54
+ }).then(data => {
55
+ callback(null,data);
56
+ });
57
+ }
58
+ else {
59
+ let Format = `https://www.facebook.com/${LinkSplit[3]}`;
60
+ Screenshot.buffer(Format, {
61
+ cookies: Coookie
62
+ }).then(data => {
63
+ callback(null,data);
64
+ });
65
+ }
66
+ }
67
+ else {
68
+ let Form = `https://www.facebook.com/${LinkSplit[1]}`;
69
+ Screenshot.buffer(Form, {
70
+ cookies: Coookie
71
+ }).then(data => {
72
+ callback(null,data);
73
+ });
74
+ }
75
+ }
76
+ else {
77
+ Screenshot.buffer(Link).then(data => {
78
+ callback(null,data);
79
+ });
80
+ }
81
+ return returnPromise;
82
+ };
83
+ };
@@ -1,29 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  const utils = require("../utils");
4
- const log = require("npmlog");
5
4
 
6
5
  module.exports = function (defaultFuncs, api, ctx) {
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
- };
6
+ return function addExternalModule(moduleObj) {
7
+ if (utils.getType(moduleObj) == "Object") {
8
+ for (const apiName in moduleObj) {
9
+ if (utils.getType(moduleObj[apiName]) == "Function") {
10
+ api[apiName] = moduleObj[apiName](defaultFuncs, api, ctx);
11
+ } else {
12
+ throw new Error(
13
+ `Item "${apiName}" in moduleObj must be a function, not ${utils.getType(
14
+ moduleObj[apiName],
15
+ )}!`,
16
+ );
17
+ }
18
+ }
19
+ } else {
20
+ throw new Error(
21
+ `moduleObj must be an object, not ${utils.getType(moduleObj)}!`,
22
+ );
23
+ }
24
+ };
20
25
  };
21
-
22
- // example usage:
23
- // api.addExternalModule({
24
- // getCtx: (defaultFuncs, api, ctx, utils, log) => {
25
- // return function getCtx() {
26
- // return ctx;
27
- // };
28
- // }
29
- // });