@dongdev/fca-unofficial 0.0.9 → 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.
Files changed (2) hide show
  1. package/README.md +81 -43
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ This API is the only way to automate chat functionalities on a user account. We
20
20
 
21
21
  ## Install
22
22
 
23
- If you just want to use ws3-fca, you should use this command:
23
+ If you just want to use @dongdev/fca-unofficial, you should use this command:
24
24
 
25
25
  ```bash
26
26
  npm install @dongdev/fca-unofficial@latest
@@ -31,19 +31,19 @@ It will download @dongdev/fca-unofficial from NPM repositories
31
31
  ## Example Usage
32
32
 
33
33
  ```javascript
34
+
34
35
  const login = require("@dongdev/fca-unofficial");
35
36
 
36
- // Create simple echo bot
37
- login({
38
- appState: []
39
- }, {
40
- //setOptions will be here
41
- } (err, api) => {
42
- if (err) return utils.error(err);
37
+ login({ appState: [] }, (err, api) => {
38
+ if (err) return console.error(err);
39
+
43
40
  api.listenMqtt((err, event) => {
41
+ if (err) return console.error(err);
42
+
44
43
  api.sendMessage(event.body, event.threadID);
45
44
  });
46
45
  });
46
+
47
47
  ```
48
48
 
49
49
  Result:
@@ -73,35 +73,55 @@ __Example (Basic Message)__
73
73
  ```js
74
74
  const login = require("@dongdev/fca-unofficial");
75
75
 
76
- login({
77
- appState: []
78
- }, (err, api) => {
79
- if(err) return console.error(err);
76
+ login({ appState: [] }, (err, api) => {
77
+ if (err) {
78
+ console.error("Login Error:", err);
79
+ return;
80
+ }
80
81
 
81
- var yourID = "000000000000000";
82
- var msg = "Hey!";
83
- api.sendMessage(msg, yourID);
82
+ let yourID = "000000000000000"; // Replace with actual Facebook ID
83
+ let msg = "Hey!";
84
+
85
+ api.sendMessage(msg, yourID, (err) => {
86
+ if (err) console.error("Message Sending Error:", err);
87
+ else console.log("Message sent successfully!");
88
+ });
84
89
  });
90
+
85
91
  ```
86
92
 
87
93
  __Example (File upload)__
88
94
 
89
95
  ```js
90
96
  const login = require("@dongdev/fca-unofficial");
97
+ const fs = require("fs"); // ✅ Required the fs module
91
98
 
92
- login({
93
- appState: []
94
- }, (err, api) => {
95
- if(err) return console.error(err);
99
+ login({ appState: [] }, (err, api) => {
100
+ if (err) {
101
+ console.error("Login Error:", err);
102
+ return;
103
+ }
96
104
 
97
- // Note this example uploads an image called image.jpg
98
- var yourID = "000000000000000";
99
- var msg = {
100
- body: "Hey!",
101
- attachment: fs.createReadStream(__dirname + '/image.jpg')
105
+ let yourID = "000000000000000"; // Replace with actual Facebook ID
106
+ let imagePath = __dirname + "/image.jpg";
107
+
108
+ // Check if the file exists before sending
109
+ if (!fs.existsSync(imagePath)) {
110
+ console.error("Error: Image file not found!");
111
+ return;
102
112
  }
103
- api.sendMessage(msg, yourID);
113
+
114
+ let msg = {
115
+ body: "Hey!",
116
+ attachment: fs.createReadStream(imagePath)
117
+ };
118
+
119
+ api.sendMessage(msg, yourID, (err) => {
120
+ if (err) console.error("Message Sending Error:", err);
121
+ else console.log("Message sent successfully!");
122
+ });
104
123
  });
124
+
105
125
  ```
106
126
 
107
127
  ---
@@ -116,15 +136,23 @@ __Example__
116
136
  const fs = require("fs");
117
137
  const login = require("@dongdev/fca-unofficial");
118
138
 
119
- var credentials = {
120
- appState: []
121
- };
139
+ const credentials = { appState: [] };
122
140
 
123
141
  login(credentials, (err, api) => {
124
- if(err) return console.error(err);
142
+ if (err) {
143
+ console.error("Login Error:", err);
144
+ return;
145
+ }
125
146
 
126
- fs.writeFileSync('appstate.json', JSON.stringify(api.getAppState()));
147
+ try {
148
+ const appState = JSON.stringify(api.getAppState(), null, 2); // Pretty print for readability
149
+ fs.writeFileSync("appstate.json", appState);
150
+ console.log("✅ AppState saved successfully!");
151
+ } catch (error) {
152
+ console.error("Error saving AppState:", error);
153
+ }
127
154
  });
155
+
128
156
  ```
129
157
 
130
158
  Alternative: Use [c3c-fbstate](https://github.com/c3cbot/c3c-fbstate) to get fbstate.json (appstate.json)
@@ -143,34 +171,44 @@ __Example__
143
171
  const fs = require("fs");
144
172
  const login = require("@dongdev/fca-unofficial");
145
173
 
146
- // Simple echo bot. It will repeat everything that you say.
147
- // Will stop when you say '/stop'
148
- login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
149
- if(err) return console.error(err);
174
+ // Simple echo bot: Repeats everything you say. Stops when you say "/stop".
175
+ login({ appState: JSON.parse(fs.readFileSync("appstate.json", "utf8")) }, (err, api) => {
176
+ if (err) {
177
+ console.error("Login Error:", err);
178
+ return;
179
+ }
150
180
 
151
- api.setOptions({listenEvents: true});
181
+ api.setOptions({ listenEvents: true });
152
182
 
153
- var stopListening = api.listenMqtt((err, event) => {
154
- if( err) return console.error(err);
183
+ const stopListening = api.listenMqtt((err, event) => {
184
+ if (err) {
185
+ console.error("Listen Error:", err);
186
+ return;
187
+ }
155
188
 
189
+ // Mark message as read
156
190
  api.markAsRead(event.threadID, (err) => {
157
- if(err) console.error(err);
191
+ if (err) console.error("Mark as read error:", err);
158
192
  });
159
193
 
160
- switch(event.type) {
194
+ // Handle different event types
195
+ switch (event.type) {
161
196
  case "message":
162
- if(event.body === '/stop') {
197
+ if (event.body && event.body.trim().toLowerCase() === "/stop") {
163
198
  api.sendMessage("Goodbye…", event.threadID);
164
- return stopListening();
199
+ stopListening();
200
+ return;
165
201
  }
166
- api.sendMessage("TEST BOT: " + event.body, event.threadID);
202
+ api.sendMessage(`TEST BOT: ${event.body}`, event.threadID);
167
203
  break;
204
+
168
205
  case "event":
169
- console.log(event);
206
+ console.log("Event Received:", event);
170
207
  break;
171
208
  }
172
209
  });
173
210
  });
211
+
174
212
  ```
175
213
 
176
214
  `<a name="projects-using-this-api"></a>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongdev/fca-unofficial",
3
- "version": "0.0.9",
3
+ "version": "1.0.0",
4
4
  "description": "A Facebook chat API without XMPP, will not be deprecated after April 30th, 2015.",
5
5
  "main": "index.js",
6
6
  "repository": {