@dongdev/fca-unofficial 0.0.6 → 0.0.8
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/README.md +77 -64
- package/index.js +403 -293
- package/lib/database/models/index.js +47 -0
- package/lib/database/models/thread.js +31 -0
- package/lib/database/threadData.js +93 -0
- package/lib/logger.js +96 -0
- package/package.json +8 -3
- package/src/getThreadInfo.js +293 -223
- package/src/getUserInfo.js +1 -7
- package/src/listenMqtt.js +716 -647
- package/src/refreshFb_dtsg.js +60 -75
- package/src/shareContact.js +49 -0
- package/utils.js +1236 -1350
- package/.travis.yml +0 -6
package/README.md
CHANGED
@@ -1,38 +1,74 @@
|
|
1
|
-
|
1
|
+
<div align="center">
|
2
2
|
|
3
|
-
|
4
|
-
<img alt="version" src="https://img.shields.io/github/package-json/v/miraiPr0ject/fca-unofficial?label=github&style=flat-square">
|
3
|
+

|
5
4
|
|
6
|
-
|
5
|
+
<h2 align="center"><b>Unoffcial Facebook Chat API</b></h2><br>This package is created by <b>DongDev</b>
|
7
6
|
|
8
|
-
|
7
|
+

|
9
8
|
|
10
9
|
_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
10
|
|
12
11
|
See [below](#projects-using-this-api) for projects using this API.
|
13
12
|
|
14
|
-
|
13
|
+
# 🤖 Features:
|
14
|
+
|
15
|
+
- [X] Once the error is detected it will automatically relogin the appstate.
|
16
|
+
- [X] If the appstate itself is logged out it will automatically logged out and you can resubmit it again, But aside of that, if it has an automated behavior, it will relogin then it will dismiss automatically and refreshes the login.
|
17
|
+
|
18
|
+

|
19
|
+
|
20
|
+
- [X] Added a feature where if the account is locked/suspended, it will stop the login process and shows the information and why it was locked/suspended.
|
21
|
+
|
22
|
+

|
23
|
+

|
24
|
+
|
25
|
+
- [X] Added api.stopListenMqtt()
|
26
|
+
- [X] Added api.getRegion()
|
27
|
+
- [X] Added api.setProfileGuard()
|
28
|
+
- [X] Added api.addFunctions()
|
29
|
+
- [X] Added api.getBotInitialData()
|
30
|
+
- [X] Added refreshFb_dtsg (*Facebook's dynamic token security generation*): This will automatically refresh every 12:00 AM in GMT+8 PH time.
|
31
|
+
- [X] Added a detection if it's locked or suspended (*will show the information about the lock/suspension*)
|
32
|
+
- [X] Added randomUserAgent on setOptions (*experimental*)
|
33
|
+
- [X] Added bypassRegion on setOptions (*choose between PRN, PNB, HKG, SYD, VLL, LLA, SIN..., experimental*)
|
34
|
+
- [X] Added a userAgent that has a possibility for less logout on accounts (*contributor to jonellcc*)
|
35
|
+
- [X] Tested on Mirai/Autobot (*try on Xavia or Goat*)
|
36
|
+
|
37
|
+
> You can use cookies editor available in kiwi browser, edge and chrome extension for PC.
|
38
|
+
> We the @dongdev/fca-unofficiala team/contributors are recommending you to use the Firefox app for less logout, or use this website if you have no access on these browsers specially iOS user.
|
39
|
+
|
40
|
+
If you encounter errors on fca, you can contact me [here](https://www.facebook.com/minhdong.dev)
|
41
|
+
|
42
|
+
`</div>`
|
43
|
+
|
44
|
+
Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
|
45
|
+
|
46
|
+
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.
|
15
47
|
|
16
48
|
## Install
|
17
|
-
|
49
|
+
|
50
|
+
If you just want to use ws3-fca, you should use this command:
|
51
|
+
|
18
52
|
```bash
|
19
|
-
npm install @
|
53
|
+
npm install @dongdev/fca-unofficial@latest
|
20
54
|
```
|
21
|
-
It will download `fca-unofficial` from NPM repositories
|
22
55
|
|
23
|
-
|
24
|
-
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/).
|
56
|
+
It will download @dongdev/fca-unofficial from NPM repositories
|
25
57
|
|
26
58
|
## Example Usage
|
59
|
+
|
27
60
|
```javascript
|
28
|
-
const login = require("fca-unofficial");
|
61
|
+
const login = require("@dongdev/fca-unofficial");
|
29
62
|
|
30
63
|
// Create simple echo bot
|
31
|
-
login({
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
64
|
+
login({
|
65
|
+
appState: []
|
66
|
+
}, {
|
67
|
+
//setOptions will be here
|
68
|
+
} (err, api) => {
|
69
|
+
if (err) return utils.error(err);
|
70
|
+
api.listenMqtt((err, event) => {
|
71
|
+
api.sendMessage(event.body, event.threadID);
|
36
72
|
});
|
37
73
|
});
|
38
74
|
```
|
@@ -41,17 +77,14 @@ Result:
|
|
41
77
|
|
42
78
|
<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">
|
43
79
|
|
44
|
-
|
45
|
-
## Documentation
|
46
|
-
|
47
|
-
You can see it [here](DOCS.md).
|
48
|
-
|
49
80
|
## Main Functionality
|
50
81
|
|
51
82
|
### Sending a message
|
83
|
+
|
52
84
|
#### api.sendMessage(message, threadID[, callback][, messageID])
|
53
85
|
|
54
86
|
Various types of message can be sent:
|
87
|
+
|
55
88
|
* *Regular:* set field `body` to the desired message as a string.
|
56
89
|
* *Sticker:* set a field `sticker` to the desired sticker ID.
|
57
90
|
* *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
|
@@ -63,10 +96,13 @@ Note that a message can only be a regular message (which can be empty) and optio
|
|
63
96
|
__Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
|
64
97
|
|
65
98
|
__Example (Basic Message)__
|
99
|
+
|
66
100
|
```js
|
67
|
-
const login = require("fca-unofficial");
|
101
|
+
const login = require("@dongdev/fca-unofficial");
|
68
102
|
|
69
|
-
login({
|
103
|
+
login({
|
104
|
+
appState: []
|
105
|
+
}, (err, api) => {
|
70
106
|
if(err) return console.error(err);
|
71
107
|
|
72
108
|
var yourID = "000000000000000";
|
@@ -76,10 +112,13 @@ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
|
76
112
|
```
|
77
113
|
|
78
114
|
__Example (File upload)__
|
115
|
+
|
79
116
|
```js
|
80
|
-
const login = require("fca-unofficial");
|
117
|
+
const login = require("@dongdev/fca-unofficial");
|
81
118
|
|
82
|
-
login({
|
119
|
+
login({
|
120
|
+
appState: []
|
121
|
+
}, (err, api) => {
|
83
122
|
if(err) return console.error(err);
|
84
123
|
|
85
124
|
// Note this example uploads an image called image.jpg
|
@@ -92,7 +131,8 @@ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
|
|
92
131
|
});
|
93
132
|
```
|
94
133
|
|
95
|
-
|
134
|
+
---
|
135
|
+
|
96
136
|
### Saving session.
|
97
137
|
|
98
138
|
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.
|
@@ -101,9 +141,11 @@ __Example__
|
|
101
141
|
|
102
142
|
```js
|
103
143
|
const fs = require("fs");
|
104
|
-
const login = require("fca-unofficial");
|
144
|
+
const login = require("@dongdev/fca-unofficial");
|
105
145
|
|
106
|
-
var credentials = {
|
146
|
+
var credentials = {
|
147
|
+
appState: []
|
148
|
+
};
|
107
149
|
|
108
150
|
login(credentials, (err, api) => {
|
109
151
|
if(err) return console.error(err);
|
@@ -114,10 +156,11 @@ login(credentials, (err, api) => {
|
|
114
156
|
|
115
157
|
Alternative: Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json (appstate.json)
|
116
158
|
|
117
|
-
|
159
|
+
---
|
118
160
|
|
119
161
|
### Listening to a chat
|
120
|
-
|
162
|
+
|
163
|
+
#### api.listenMqtt(callback)
|
121
164
|
|
122
165
|
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})`.
|
123
166
|
|
@@ -125,7 +168,7 @@ __Example__
|
|
125
168
|
|
126
169
|
```js
|
127
170
|
const fs = require("fs");
|
128
|
-
const login = require("fca-unofficial");
|
171
|
+
const login = require("@dongdev/fca-unofficial");
|
129
172
|
|
130
173
|
// Simple echo bot. It will repeat everything that you say.
|
131
174
|
// Will stop when you say '/stop'
|
@@ -135,7 +178,7 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap
|
|
135
178
|
api.setOptions({listenEvents: true});
|
136
179
|
|
137
180
|
var stopListening = api.listenMqtt((err, event) => {
|
138
|
-
if(err) return console.error(err);
|
181
|
+
if( err) return console.error(err);
|
139
182
|
|
140
183
|
api.markAsRead(event.threadID, (err) => {
|
141
184
|
if(err) console.error(err);
|
@@ -157,38 +200,8 @@ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, ap
|
|
157
200
|
});
|
158
201
|
```
|
159
202
|
|
160
|
-
|
161
|
-
|
162
|
-
1. How do I run tests?
|
163
|
-
> 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`.
|
164
|
-
|
165
|
-
2. Why doesn't `sendMessage` always work when I'm logged in as a page?
|
166
|
-
> Pages can't start conversations with users directly; this is to prevent pages from spamming users.
|
167
|
-
|
168
|
-
3. What do I do when `login` doesn't work?
|
169
|
-
> 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).
|
170
|
-
|
171
|
-
4. How can I avoid logging in every time? Can I log into a previous session?
|
172
|
-
> 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.
|
173
|
-
|
174
|
-
5. Do you support sending messages as a page?
|
175
|
-
> Yes, set the pageID option on login (this doesn't work if you set it using api.setOptions, it affects the login process).
|
176
|
-
> ```js
|
177
|
-
> login(credentials, {pageID: "000000000000000"}, (err, api) => { … }
|
178
|
-
> ```
|
179
|
-
|
180
|
-
6. I'm getting some crazy weird syntax error like `SyntaxError: Unexpected token [`!!!
|
181
|
-
> Please try to update your version of node.js before submitting an issue of this nature. We like to use new language features.
|
182
|
-
|
183
|
-
7. I don't want all of these logging messages!
|
184
|
-
> You can use `api.setOptions` to silence the logging. You get the `api` object from `login` (see example above). Do
|
185
|
-
> ```js
|
186
|
-
> api.setOptions({
|
187
|
-
> logLevel: "silent"
|
188
|
-
> });
|
189
|
-
> ```
|
203
|
+
`<a name="projects-using-this-api"></a>`
|
190
204
|
|
191
|
-
<a name="projects-using-this-api"></a>
|
192
205
|
## Projects using this API:
|
193
206
|
|
194
207
|
- [c3c](https://github.com/lequanglam/c3c) - A bot that can be customizable using plugins. Support Facebook & Discord.
|