fca-luxury 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/DOCS.md +1686 -0
  2. package/README.md +222 -0
  3. package/index.js +544 -0
  4. package/package.json +73 -0
  5. package/src/Screenshot.js +83 -0
  6. package/src/addExternalModule.js +15 -0
  7. package/src/addUserToGroup.js +77 -0
  8. package/src/changeAdminStatus.js +47 -0
  9. package/src/changeArchivedStatus.js +41 -0
  10. package/src/changeAvt.js +85 -0
  11. package/src/changeBio.js +65 -0
  12. package/src/changeBlockedStatus.js +36 -0
  13. package/src/changeGroupImage.js +106 -0
  14. package/src/changeNickname.js +45 -0
  15. package/src/changeThreadColor.js +61 -0
  16. package/src/changeThreadEmoji.js +41 -0
  17. package/src/createNewGroup.js +70 -0
  18. package/src/createPoll.js +59 -0
  19. package/src/deleteMessage.js +44 -0
  20. package/src/deleteThread.js +42 -0
  21. package/src/editMessage.js +55 -0
  22. package/src/forwardAttachment.js +47 -0
  23. package/src/getCurrentUserID.js +7 -0
  24. package/src/getEmojiUrl.js +27 -0
  25. package/src/getFriendsList.js +73 -0
  26. package/src/getThreadHistory.js +537 -0
  27. package/src/getThreadHistoryDeprecated.js +71 -0
  28. package/src/getThreadInfo.js +171 -0
  29. package/src/getThreadInfoDeprecated.js +56 -0
  30. package/src/getThreadList.js +213 -0
  31. package/src/getThreadListDeprecated.js +46 -0
  32. package/src/getThreadPictures.js +59 -0
  33. package/src/getUserID.js +61 -0
  34. package/src/getUserInfo.js +66 -0
  35. package/src/handleFriendRequest.js +46 -0
  36. package/src/handleMessageRequest.js +47 -0
  37. package/src/httpGet.js +49 -0
  38. package/src/httpPost.js +48 -0
  39. package/src/listenMqtt.js +701 -0
  40. package/src/logout.js +68 -0
  41. package/src/markAsDelivered.js +47 -0
  42. package/src/markAsRead.js +70 -0
  43. package/src/markAsReadAll.js +40 -0
  44. package/src/markAsSeen.js +48 -0
  45. package/src/muteThread.js +45 -0
  46. package/src/removeUserFromGroup.js +45 -0
  47. package/src/resolvePhotoUrl.js +36 -0
  48. package/src/searchForThread.js +42 -0
  49. package/src/sendMessage.js +461 -0
  50. package/src/sendTypingIndicator.js +70 -0
  51. package/src/setMessageReaction.js +109 -0
  52. package/src/setPostReaction.js +102 -0
  53. package/src/setTitle.js +70 -0
  54. package/src/shareContact.js +46 -0
  55. package/src/shareLink.js +55 -0
  56. package/src/threadColors.js +41 -0
  57. package/src/unfriend.js +42 -0
  58. package/src/unsendMessage.js +39 -0
  59. package/test/data/shareAttach.js +146 -0
  60. package/test/data/something.mov +0 -0
  61. package/test/data/test.png +0 -0
  62. package/test/data/test.txt +7 -0
  63. package/test/example-config.json +18 -0
  64. package/test/test-page.js +140 -0
  65. package/test/test.js +385 -0
  66. package/utils.js +1196 -0
package/README.md ADDED
@@ -0,0 +1,222 @@
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
+ <img alt="version" src="https://img.shields.io/github/package-json/v/miraiPr0ject/fca-unofficial?label=github&style=flat-square">
5
+
6
+ Facebook now has an official API for chat bots [here](https://developers.facebook.com/docs/messenger-platform).
7
+
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 fca-unofficial, you should use this command:
18
+ ```bash
19
+ npm install fca-luxury
20
+ ```
21
+ It will download ` fca-luxury` from NPM repositories
22
+
23
+ ## Testing your bots
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/).
25
+
26
+ ## Example Usage
27
+ ```javascript
28
+ const login = require("fca-luxury");
29
+
30
+ // Create simple echo bot
31
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
32
+ if(err) return console.error(err);
33
+
34
+ api.listen((err, message) => {
35
+ api.sendMessage(message.body, message.threadID);
36
+ });
37
+ });
38
+ ```
39
+
40
+ Result:
41
+
42
+ <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
+
44
+
45
+ ## Documentation
46
+
47
+ You can see it [here](DOCS.md).
48
+
49
+ ## Main Functionality
50
+
51
+ ### Sending a message
52
+ #### api.sendMessage(message, threadID[, callback][, messageID])
53
+
54
+ Various types of message can be sent:
55
+ * *Regular:* set field `body` to the desired message as a string.
56
+ * *Sticker:* set a field `sticker` to the desired sticker ID.
57
+ * *File or image:* Set field `attachment` to a readable stream or an array of readable streams.
58
+ * *URL:* set a field `url` to the desired URL.
59
+ * *Emoji:* set field `emoji` to the desired emoji as a string and set field `emojiSize` with size of the emoji (`small`, `medium`, `large`)
60
+
61
+ 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.
62
+
63
+ __Tip__: to find your own ID, you can look inside the cookies. The `userID` is under the name `c_user`.
64
+
65
+ __Example (Basic Message)__
66
+ ```js
67
+ const login = require("fca-luxury");
68
+
69
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
70
+ if(err) return console.error(err);
71
+
72
+ var yourID = "000000000000000";
73
+ var msg = "Hey!";
74
+ api.sendMessage(msg, yourID);
75
+ });
76
+ ```
77
+
78
+ __Example (File upload)__
79
+ ```js
80
+ const login = require("fca-luxury");
81
+
82
+ login({email: "FB_EMAIL", password: "FB_PASSWORD"}, (err, api) => {
83
+ if(err) return console.error(err);
84
+
85
+ // Note this example uploads an image called image.jpg
86
+ var yourID = "000000000000000";
87
+ var msg = {
88
+ body: "Hey!",
89
+ attachment: fs.createReadStream(__dirname + '/image.jpg')
90
+ }
91
+ api.sendMessage(msg, yourID);
92
+ });
93
+ ```
94
+
95
+ ------------------------------------
96
+ ### Saving session.
97
+
98
+ 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.
99
+
100
+ __Example__
101
+
102
+ ```js
103
+ const fs = require("fs");
104
+ const login = require("fca-luxury");
105
+
106
+ var credentials = {email: "FB_EMAIL", password: "FB_PASSWORD"};
107
+
108
+ login(credentials, (err, api) => {
109
+ if(err) return console.error(err);
110
+
111
+ fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
112
+ });
113
+ ```
114
+
115
+ Alternative: Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json (appstate.json)
116
+
117
+ ------------------------------------
118
+
119
+ ### Listening to a chat
120
+ #### api.listen(callback)
121
+
122
+ 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
+
124
+ __Example__
125
+
126
+ ```js
127
+ const fs = require("fs");
128
+ const login = require("fca-luxury");
129
+
130
+ // Simple echo bot. It will repeat everything that you say.
131
+ // Will stop when you say '/stop'
132
+ login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
133
+ if(err) return console.error(err);
134
+
135
+ api.setOptions({listenEvents: true});
136
+
137
+ var stopListening = api.listenMqtt((err, event) => {
138
+ if(err) return console.error(err);
139
+
140
+ api.markAsRead(event.threadID, (err) => {
141
+ if(err) console.error(err);
142
+ });
143
+
144
+ switch(event.type) {
145
+ case "message":
146
+ if(event.body === '/stop') {
147
+ api.sendMessage("Goodbye…", event.threadID);
148
+ return stopListening();
149
+ }
150
+ api.sendMessage("TEST BOT: " + event.body, event.threadID);
151
+ break;
152
+ case "event":
153
+ console.log(event);
154
+ break;
155
+ }
156
+ });
157
+ });
158
+ ```
159
+
160
+ ## FAQS
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
+ > ```
190
+
191
+ <a name="projects-using-this-api"></a>
192
+ ## Projects using this API:
193
+
194
+ - [c3c](https://github.com/lequanglam/c3c) - A bot that can be customizable using plugins. Support Facebook & Discord.
195
+ - [Miraiv2](https://github.com/miraiPr0ject/miraiv2) - A simple Facebook Messenger Bot made by CatalizCS and SpermLord.
196
+
197
+ ## Projects using this API (original repository, facebook-chat-api):
198
+
199
+ - [Messer](https://github.com/mjkaufer/Messer) - Command-line messaging for Facebook Messenger
200
+ - [messen](https://github.com/tomquirk/messen) - Rapidly build Facebook Messenger apps in Node.js
201
+ - [Concierge](https://github.com/concierge/Concierge) - Concierge is a highly modular, easily extensible general purpose chat bot with a built in package manager
202
+ - [Marc Zuckerbot](https://github.com/bsansouci/marc-zuckerbot) - Facebook chat bot
203
+ - [Marc Thuckerbot](https://github.com/bsansouci/lisp-bot) - Programmable lisp bot
204
+ - [MarkovsInequality](https://github.com/logicx24/MarkovsInequality) - Extensible chat bot adding useful functions to Facebook Messenger
205
+ - [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.
206
+ - [Larry Pudding Dog Bot](https://github.com/Larry850806/facebook-chat-bot) - A facebook bot you can easily customize the response
207
+ - [fbash](https://github.com/avikj/fbash) - Run commands on your computer's terminal over Facebook Messenger
208
+ - [Klink](https://github.com/KeNt178/klink) - This Chrome extension will 1-click share the link of your active tab over Facebook Messenger
209
+ - [Botyo](https://github.com/ivkos/botyo) - Modular bot designed for group chat rooms on Facebook
210
+ - [matrix-puppet-facebook](https://github.com/matrix-hacks/matrix-puppet-facebook) - A facebook bridge for [matrix](https://matrix.org)
211
+ - [facebot](https://github.com/Weetbix/facebot) - A facebook bridge for Slack.
212
+ - [Botium](https://github.com/codeforequity-at/botium-core) - The Selenium for Chatbots
213
+ - [Messenger-CLI](https://github.com/AstroCB/Messenger-CLI) - A command-line interface for sending and receiving messages through Facebook Messenger.
214
+ - [AssumeZero-Bot](https://github.com/AstroCB/AssumeZero-Bot) – A highly customizable Facebook Messenger bot for group chats.
215
+ - [Miscord](https://github.com/Bjornskjald/miscord) - An easy-to-use Facebook bridge for Discord.
216
+ - [chat-bridge](https://github.com/rexx0520/chat-bridge) - A Messenger, Telegram and IRC chat bridge.
217
+ - [messenger-auto-reply](https://gitlab.com/theSander/messenger-auto-reply) - An auto-reply service for Messenger.
218
+ - [BotCore](https://github.com/AstroCB/BotCore) – A collection of tools for writing and managing Facebook Messenger bots.
219
+ - [mnotify](https://github.com/AstroCB/mnotify) – A command-line utility for sending alerts and notifications through Facebook Messenger.
220
+ "# fca-luxury"
221
+ "# fca-luxury"
222
+ "# fca-luxury"