naughty-fb-chatify 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +4 -224
  2. package/index.js +37 -20
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,225 +1,5 @@
1
- This repo is a fork from main repo and will usually have new features bundled faster than main repo (and maybe bundle some bugs, too).
2
-
3
1
  # Unofficial Facebook Chat API
4
- <a href="https://www.npmjs.com/package/fca-unofficial"><img alt="npm version" src="https://img.shields.io/npm/v/fca-unofficial.svg?style=flat-square"></a>
5
- <img alt="version" src="https://img.shields.io/github/package-json/v/fca-unofficial/fca-unofficial?label=github&style=flat-square">
6
- <a href="https://www.npmjs.com/package/fca-unofficial"><img src="https://img.shields.io/npm/dm/fca-unofficial.svg?style=flat-square" alt="npm downloads"></a>
7
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
8
-
9
- Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
10
-
11
- 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.
12
-
13
- _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.
14
-
15
- See [below](#projects-using-this-api) for projects using this API.
16
-
17
- See the [full changelog](/CHANGELOG.md) for release details.
18
-
19
- ## Install
20
- If you just want to use fca-unofficial, you should use this command:
21
- ```bash
22
- npm install fca-unofficial
23
- ```
24
- It will download `fca-unofficial` from NPM repositories
25
-
26
- ### Bleeding edge
27
- If you want to use bleeding edge (directly from github) to test new features or submit bug report, this is the command for you:
28
- ```bash
29
- npm install fca-unofficial/fca-unofficial
30
- ```
31
-
32
- ## Testing your bots
33
- 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/).
34
-
35
- ## Example Usage
36
- ```javascript
37
- const login = require("fca-unofficial");
38
-
39
- // Create simple echo bot
40
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
41
- if(err) return console.error(err);
42
-
43
- api.listen((err, message) => {
44
- api.sendMessage(message.body, message.threadID);
45
- });
46
- });
47
- ```
48
-
49
- Result:
50
-
51
- <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">
52
-
53
-
54
- ## Documentation
55
-
56
- You can see it [here](DOCS.md).
57
-
58
- ## Main Functionality
59
-
60
- ### Sending a message
61
- #### api.sendMessage(message, threadID[, callback][, messageID])
62
-
63
- Various types of message can be sent:
64
- * *Regular:* set field `body` to the desired message as a string.
65
- * *Sticker:* set a field `sticker` to the desired sticker ID.
66
- * *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
67
- * *URL:* set a field `url` to the desired URL.
68
- * *Emoji:* set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
69
-
70
- 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.
71
-
72
- __Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
73
-
74
- __Example (Basic Message)__
75
- ```js
76
- const login = require("fca-unofficial");
77
-
78
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
79
- if(err) return console.error(err);
80
-
81
- var yourID = "000000000000000";
82
- var msg = "Hey!";
83
- api.sendMessage(msg, yourID);
84
- });
85
- ```
86
-
87
- __Example (File upload)__
88
- ```js
89
- const login = require("fca-unofficial");
90
-
91
- login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
92
- if(err) return console.error(err);
93
-
94
- // Note this example uploads an image called image.jpg
95
- var yourID = "000000000000000";
96
- var msg = {
97
- body: "Hey!",
98
- attachment: fs.createReadStream(__dirname + '/image.jpg')
99
- }
100
- api.sendMessage(msg, yourID);
101
- });
102
- ```
103
-
104
- ------------------------------------
105
- ### Saving session.
106
-
107
- 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.
108
-
109
- __Example__
110
-
111
- ```js
112
- const fs = require("fs");
113
- const login = require("fca-unofficial");
114
-
115
- var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
116
-
117
- login(credentials, (err, api) => {
118
- if(err) return console.error(err);
119
-
120
- fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
121
- });
122
- ```
123
-
124
- Alternative: Use [c3c-fbstate](https://github.com/lequanglam/c3c-fbstate) to get fbstate.json (appstate.json)
125
-
126
- ------------------------------------
127
-
128
- ### Listening to a chat
129
- #### api.listen(callback)
130
-
131
- 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})`.
132
-
133
- __Example__
134
-
135
- ```js
136
- const fs = require("fs");
137
- const login = require("fca-unofficial");
138
-
139
- // Simple echo bot. It will repeat everything that you say.
140
- // Will stop when you say '/stop'
141
- login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
142
- if(err) return console.error(err);
143
-
144
- api.setOptions({listenEvents: true});
145
-
146
- var stopListening = api.listenMqtt((err, event) => {
147
- if(err) return console.error(err);
148
-
149
- api.markAsRead(event.threadID, (err) => {
150
- if(err) console.error(err);
151
- });
152
-
153
- switch(event.type) {
154
- case "message":
155
- if(event.body === '/stop') {
156
- api.sendMessage("Goodbye…", event.threadID);
157
- return stopListening();
158
- }
159
- api.sendMessage("TEST BOT: " + event.body, event.threadID);
160
- break;
161
- case "event":
162
- console.log(event);
163
- break;
164
- }
165
- });
166
- });
167
- ```
168
-
169
- ## FAQS
170
-
171
- 1. How do I run tests?
172
- > 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`.
173
-
174
- 2. Why doesn't `sendMessage` always work when I'm logged in as a page?
175
- > Pages can't start conversations with users directly; this is to prevent pages from spamming users.
176
-
177
- 3. What do I do when `login` doesn't work?
178
- > 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).
179
-
180
- 4. How can I avoid logging in every time? Can I log into a previous session?
181
- > 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.
182
-
183
- 5. Do you support sending messages as a page?
184
- > Yes, set the pageID option on login (this doesn't work if you set it using api.setOptions, it affects the login process).
185
- > ```js
186
- > login(credentials, {pageID: "000000000000000"}, (err, api) => { … }
187
- > ```
188
-
189
- 6. I'm getting some crazy weird syntax error like `SyntaxError: Unexpected token [`!!!
190
- > Please try to update your version of node.js before submitting an issue of this nature. We like to use new language features.
191
-
192
- 7. I don't want all of these logging messages!
193
- > You can use `api.setOptions` to silence the logging. You get the `api` object from `login` (see example above). Do
194
- > ```js
195
- > api.setOptions({
196
- > logLevel: "silent"
197
- > });
198
- > ```
199
-
200
- <a name="projects-using-this-api"></a>
201
- ## Projects using this API:
202
-
203
- - [c3c](https://github.com/lequanglam/c3c) - A bot that can be customizable using plugins. Support Facebook & Discord.
204
-
205
- ## Projects using this API (original repository, facebook-chat-api):
206
-
207
- - [Messer](https://github.com/mjkaufer/Messer) - Command-line messaging for Facebook Messenger
208
- - [messen](https://github.com/tomquirk/messen) - Rapidly build Facebook Messenger apps in Node.js
209
- - [Concierge](https://github.com/concierge/Concierge) - Concierge is a highly modular, easily extensible general purpose chat bot with a built in package manager
210
- - [Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot) - Facebook chat bot
211
- - [Marc Thuckerbot](https://github.com/bsansouci/lisp-bot) - Programmable lisp bot
212
- - [MarkovsInequality](https://github.com/logicx24/MarkovsInequality) - Extensible chat bot adding useful functions to Facebook Messenger
213
- - [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.
214
- - [Larry Pudding Dog Bot](https://github.com/Larry850806/facebook-chat-bot) - A facebook bot you can easily customize the response
215
- - [fbash](https://github.com/avikj/fbash) - Run commands on your computer's terminal over Facebook Messenger
216
- - [Klink](https://github.com/KeNt178/klink) - This Chrome extension will 1-click share the link of your active tab over Facebook Messenger
217
- - [Botyo](https://github.com/ivkos/botyo) - Modular bot designed for group chat rooms on Facebook
218
- - [matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook) - A facebook bridge for [matrix](https://matrix.org)
219
- - [facebot](https://github.com/Weetbix/facebot) - A facebook bridge for Slack.
220
- - [Botium](https://github.com/codeforequity-at/botium-core) - The Selenium for Chatbots
221
- - [Messenger-CLI](https://github.com/AstroCB/Messenger-CLI) - A command-line interface for sending and receiving messages through Facebook Messenger.
222
- - [AssumeZero-Bot](https://github.com/AstroCB/AssumeZero-Bot) – A highly customizable Facebook Messenger bot for group chats.
223
- - [Miscord](https://github.com/Bjornskjald/miscord) - An easy-to-use Facebook bridge for Discord.
224
- - [chat-bridge](https://github.com/rexx0520/chat-bridge) - A Messenger, Telegram and IRC chat bridge.
225
- - [messenger-auto-reply](https://gitlab.com/theSander/messenger-auto-reply) - An auto-reply service for Messenger.
2
+ ## Made By Maryam Rajput
3
+ ### Fca For Naughty-Bot-V1
4
+ #### Will Write The Next Garbage Later ):
5
+ ##### FB: facebook.com/naugh7y.dev
package/index.js CHANGED
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
-
2
+ console.log(`┌────────────────────────────────────────────────────────────────────────────────┐
3
+ │ │
4
+ │ │
5
+ │ │
6
+ │ ███╗ ██╗ █████╗ ██╗ ██╗ ██████╗ ██╗ ██╗████████╗██╗ ██╗ │
7
+ │ ████╗ ██║██╔══██╗██║ ██║██╔════╝ ██║ ██║╚══██╔══╝╚██╗ ██╔╝ │
8
+ │ ██╔██╗ ██║███████║██║ ██║██║ ███╗███████║ ██║ ╚████╔╝ │
9
+ │ ██║╚██╗██║██╔══██║██║ ██║██║ ██║██╔══██║ ██║ ╚██╔╝ │
10
+ │ ██║ ╚████║██║ ██║╚██████╔╝╚██████╔╝██║ ██║ ██║ ██║ │
11
+ │ ╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ │
12
+ │ │
13
+ │ │
14
+ │ naughty-fb-chatify │
15
+ │ Version: 1.0.3 │
16
+ └────────────────────────────────────────────────────────────────────────────────┘`);
17
+ const chalk = require("chalk");
3
18
  var utils = require("./utils");
4
19
  var cheerio = require("cheerio");
5
20
  var log = require("npmlog");
@@ -66,7 +81,7 @@ function setOptions(globalOptions, options) {
66
81
  globalOptions.emitReady = Boolean(options.emitReady);
67
82
  break;
68
83
  default:
69
- log.warn("setOptions", "Unrecognized option given to setOptions: " + key);
84
+ console.log(`${chalk.bold.yellowBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Unrecognized option given to setOptions:`)} ${chalk.bold.redBright(`${key}`)}`);
70
85
  break;
71
86
  }
72
87
  });
@@ -78,15 +93,16 @@ function buildAPI(globalOptions, html, jar) {
78
93
  });
79
94
 
80
95
  if (maybeCookie.length === 0) {
81
- throw { error: "Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify." };
96
+ console.log(`${chalk.bold.redBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Error retrieving userID. This can be caused by a lot of things, including getting blocked by Facebook for logging in from an unknown location. Try logging in with a browser to verify.`)}`);
97
+ return null;
82
98
  }
83
99
 
84
100
  if (html.indexOf("/checkpoint/block/?next") > -1) {
85
- log.warn("login", "Checkpoint detected. Please log in with a browser to verify.");
101
+ console.log(`${chalk.bold.red(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Checkpoint detected. Please log in with a browser to verify.`)}`)
86
102
  }
87
103
 
88
104
  var userID = maybeCookie[0].cookieString().split("=")[1].toString();
89
- log.info("login", `Logged in as ${userID}`);
105
+ console.log(`${chalk.bold.cyan(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Sucesfully Logged In As`)} ${chalk.bold.redBright(`${userID}`)}`)
90
106
 
91
107
  try {
92
108
  clearInterval(checkVerified);
@@ -105,24 +121,24 @@ function buildAPI(globalOptions, html, jar) {
105
121
  irisSeqID = oldFBMQTTMatch[1];
106
122
  mqttEndpoint = oldFBMQTTMatch[2];
107
123
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
108
- log.info("login", `Got this account's message region: ${region}`);
124
+ console.log(`${chalk.bold.cyan(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Got this account's message region:`)} ${chalk.bold.redBright(`${region}`)}`);
109
125
  } else {
110
126
  let newFBMQTTMatch = html.match(/{"app_id":"219994525426954","endpoint":"(.+?)","iris_seq_id":"(.+?)"}/);
111
127
  if (newFBMQTTMatch) {
112
128
  irisSeqID = newFBMQTTMatch[2];
113
129
  mqttEndpoint = newFBMQTTMatch[1].replace(/\\\//g, "/");
114
130
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
115
- log.info("login", `Got this account's message region: ${region}`);
131
+ console.log(`${chalk.bold.cyan(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Got this account's message region:`)} ${chalk.bold.redBright(`${region}`)}`);
116
132
  } else {
117
133
  let legacyFBMQTTMatch = html.match(/(\["MqttWebConfig",\[\],{fbid:")(.+?)(",appID:219994525426954,endpoint:")(.+?)(",pollingEndpoint:")(.+?)(3790])/);
118
134
  if (legacyFBMQTTMatch) {
119
135
  mqttEndpoint = legacyFBMQTTMatch[4];
120
136
  region = new URL(mqttEndpoint).searchParams.get("region").toUpperCase();
121
- log.warn("login", `Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`);
122
- log.info("login", `Got this account's message region: ${region}`);
123
- log.info("login", `[Unused] Polling endpoint: ${legacyFBMQTTMatch[6]}`);
137
+ console.log(`${chalk.bold.yellowBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Cannot get sequence ID with new RegExp. Fallback to old RegExp (without seqID)...`)}`);
138
+ console.log(`${chalk.bold.cyan(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`Got this account's message region:`)} ${chalk.bold.redBright(`${region}`)}`);
139
+ console.log(`${chalk.bold.cyan(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.greenBright(`[Unused] Polling endpoint:`)} ${chalk.bold.redBright(`${legacyFBMQTTMatch[6]}`)}`);
124
140
  } else {
125
- log.warn("login", "Cannot get MQTT region & sequence ID.");
141
+ console.log(`${chalk.bold.yellowBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.cyanBright(`Cannot get MQTT region & sequence ID.`)}`);
126
142
  noMqttData = html;
127
143
  }
128
144
  }
@@ -266,19 +282,20 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
266
282
  });
267
283
  // ---------- Very Hacky Part Ends -----------------
268
284
 
269
- log.info("login", "Logging in...");
285
+ console.log(`${chalk.bold.magentaBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.cyanBright(`Logging In....`)}`);
270
286
  return utils
271
287
  .post("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110", jar, form, loginOptions)
272
288
  .then(utils.saveCookies(jar))
273
289
  .then(function (res) {
274
290
  var headers = res.headers;
275
291
  if (!headers.location) {
276
- throw { error: "Wrong username/password." };
292
+ console.log(`${chalk.bold.redBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.yellowBright(`Your UserName or Password Is Incorrect`)}`);
293
+ return null;
277
294
  }
278
295
 
279
296
  // This means the account has login approvals turned on.
280
297
  if (headers.location.indexOf('https://www.facebook.com/checkpoint/') > -1) {
281
- log.info("login", "You have login approvals turned on.");
298
+ console.log(`${chalk.bold.redBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.yellowBright(`You have login approvals turned on`)}`);
282
299
  var nextURL = 'https://www.facebook.com/checkpoint/?next=https%3A%2F%2Fwww.facebook.com%2Fhome.php';
283
300
 
284
301
  return utils
@@ -311,7 +328,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
311
328
  JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*()/, ""));
312
329
  } catch (ex) {
313
330
  clearInterval(checkVerified);
314
- log.info("login", "Verified from browser. Logging in...");
331
+ console.log(`${chalk.bold.magentaBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.cyanBright(`Verified from browser, Logging in...`)}`);
315
332
  return loginHelper(utils.getAppState(jar), email, password, loginOptions, callback);
316
333
  }
317
334
  })
@@ -401,7 +418,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
401
418
  JSON.parse(res.body.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, ""));
402
419
  } catch (ex) {
403
420
  clearInterval(checkVerified);
404
- log.info("login", "Verified from browser. Logging in...");
421
+ console.log(`${chalk.bold.magentaBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.cyanBright(`Verified from browser, Logging in...`)}`);
405
422
  if (callback === prCallback) {
406
423
  callback = function (err, api) {
407
424
  if (err) {
@@ -427,7 +444,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
427
444
  };
428
445
  } else {
429
446
  if (!loginOptions.forceLogin) {
430
- throw { error: "Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again." };
447
+ console.log(`${chalk.bold.redBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.yellowBright(`Couldn't login. Facebook might have blocked this account. Please login with a browser or enable the option 'forceLogin' and try again.`)}`);
431
448
  }
432
449
  if (html.indexOf("Suspicious Login Attempt") > -1) {
433
450
  form['submit[This was me]'] = "This was me";
@@ -450,7 +467,7 @@ function makeLogin(jar, email, password, loginOptions, callback, prCallback) {
450
467
  var headers = res.headers;
451
468
 
452
469
  if (!headers.location && res.body.indexOf('Review Recent Login') > -1) {
453
- throw { error: "Something went wrong with review recent login." };
470
+ console.log(`${chalk.bold.redBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.yellowBright(`Something went wrong with review recent login.`)}`);
454
471
  }
455
472
 
456
473
  var appState = utils.getAppState(jar);
@@ -548,7 +565,7 @@ function loginHelper(appState, email, password, globalOptions, callback, prCallb
548
565
  // At the end we call the callback or catch an exception
549
566
  mainPromise
550
567
  .then(function () {
551
- log.info("login", 'Done logging in.');
568
+ console.log(`${chalk.bold.magentaBright(`[ NAUGHTY-FB-CHATIFY ] >> `)} ${chalk.redBright(`Done Logging In....`)}`);
552
569
  return callback(null, api);
553
570
  })
554
571
  .catch(function (e) {
@@ -599,4 +616,4 @@ function login(loginData, options, callback) {
599
616
  loginHelper(loginData.appState, loginData.email, loginData.password, globalOptions, callback, prCallback);
600
617
  return returnPromise;
601
618
  }
602
- module.exports = login;
619
+ module.exports = login;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naughty-fb-chatify",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Fca For Naughty-Bot-V1",
5
5
  "scripts": {
6
6
  "test": "mocha",