naughty-fb-chatify 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/publish.yml +20 -0
- package/README.md +225 -0
- package/index.js +602 -0
- package/package.json +80 -0
- package/src/addExternalModule.js +19 -0
- package/src/addUserToGroup.js +113 -0
- package/src/changeAdminStatus.js +79 -0
- package/src/changeArchivedStatus.js +55 -0
- package/src/changeBio.js +77 -0
- package/src/changeBlockedStatus.js +47 -0
- package/src/changeGroupImage.js +129 -0
- package/src/changeNickname.js +59 -0
- package/src/changeThreadColor.js +71 -0
- package/src/changeThreadEmoji.js +55 -0
- package/src/createNewGroup.js +86 -0
- package/src/createPoll.js +71 -0
- package/src/deleteMessage.js +56 -0
- package/src/deleteThread.js +56 -0
- package/src/forwardAttachment.js +60 -0
- package/src/getCurrentUserID.js +7 -0
- package/src/getEmojiUrl.js +29 -0
- package/src/getFriendsList.js +84 -0
- package/src/getThreadHistory.js +645 -0
- package/src/getThreadHistoryDeprecated.js +93 -0
- package/src/getThreadInfo.js +201 -0
- package/src/getThreadInfoDeprecated.js +80 -0
- package/src/getThreadList.js +238 -0
- package/src/getThreadListDeprecated.js +75 -0
- package/src/getThreadPictures.js +79 -0
- package/src/getUserID.js +66 -0
- package/src/getUserInfo.js +72 -0
- package/src/handleFriendRequest.js +61 -0
- package/src/handleMessageRequest.js +65 -0
- package/src/httpGet.js +52 -0
- package/src/httpPost.js +52 -0
- package/src/listenMqtt.js +788 -0
- package/src/logout.js +75 -0
- package/src/markAsDelivered.js +58 -0
- package/src/markAsRead.js +80 -0
- package/src/markAsReadAll.js +50 -0
- package/src/markAsSeen.js +59 -0
- package/src/muteThread.js +52 -0
- package/src/removeUserFromGroup.js +79 -0
- package/src/resolvePhotoUrl.js +45 -0
- package/src/searchForThread.js +53 -0
- package/src/sendMessage.js +459 -0
- package/src/sendTypingIndicator.js +103 -0
- package/src/setMessageReaction.js +117 -0
- package/src/setPostReaction.js +76 -0
- package/src/setTitle.js +86 -0
- package/src/threadColors.js +57 -0
- package/src/unfriend.js +52 -0
- package/src/unsendMessage.js +49 -0
- package/test/data/shareAttach.js +146 -0
- package/test/data/something.mov +0 -0
- package/test/data/test.png +0 -0
- package/test/data/test.txt +1 -0
- package/test/test-page.js +140 -0
- package/test/test.js +385 -0
- package/utils.js +1357 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
name: "publish npm"
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
publish:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- name: checkout
|
10
|
+
uses: actions/checkout@v2
|
11
|
+
- name: node
|
12
|
+
uses: actions/setup-node@v2
|
13
|
+
with:
|
14
|
+
node-version: 14
|
15
|
+
registry-url: https://registry.npmjs.org
|
16
|
+
- name: publish
|
17
|
+
run: npm publish --access public
|
18
|
+
# working-directory: package.json
|
19
|
+
env:
|
20
|
+
NODE_AUTH_TOKEN: ${{secrets.NAUGHTY_FB_CHATIFY}}
|
package/README.md
ADDED
@@ -0,0 +1,225 @@
|
|
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
|
+
# 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.
|