fca-riyad 37.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 (242) hide show
  1. package/CHANGELOG.md +325 -0
  2. package/DOCS.md +2712 -0
  3. package/README.md +410 -0
  4. package/func/checkUpdate.js +7 -0
  5. package/func/logAdapter.js +33 -0
  6. package/func/logger.js +48 -0
  7. package/index.d.ts +751 -0
  8. package/index.js +22 -0
  9. package/module/config.js +40 -0
  10. package/module/login.js +133 -0
  11. package/module/loginHelper.js +1359 -0
  12. package/module/options.js +44 -0
  13. package/package.json +95 -0
  14. package/src/api/action/addExternalModule.js +25 -0
  15. package/src/api/action/changeAvatar.js +137 -0
  16. package/src/api/action/changeBio.js +75 -0
  17. package/src/api/action/enableAutoSaveAppState.js +73 -0
  18. package/src/api/action/getCurrentUserID.js +7 -0
  19. package/src/api/action/handleFriendRequest.js +57 -0
  20. package/src/api/action/logout.js +76 -0
  21. package/src/api/action/refreshFb_dtsg.js +48 -0
  22. package/src/api/action/setPostReaction.js +106 -0
  23. package/src/api/action/unfriend.js +54 -0
  24. package/src/api/http/httpGet.js +46 -0
  25. package/src/api/http/httpPost.js +52 -0
  26. package/src/api/http/postFormData.js +47 -0
  27. package/src/api/messaging/addUserToGroup.js +68 -0
  28. package/src/api/messaging/changeAdminStatus.js +126 -0
  29. package/src/api/messaging/changeArchivedStatus.js +55 -0
  30. package/src/api/messaging/changeBlockedStatus.js +48 -0
  31. package/src/api/messaging/changeGroupImage.js +91 -0
  32. package/src/api/messaging/changeNickname.js +70 -0
  33. package/src/api/messaging/changeThreadColor.js +79 -0
  34. package/src/api/messaging/changeThreadEmoji.js +111 -0
  35. package/src/api/messaging/createNewGroup.js +88 -0
  36. package/src/api/messaging/createPoll.js +46 -0
  37. package/src/api/messaging/createThemeAI.js +98 -0
  38. package/src/api/messaging/deleteMessage.js +136 -0
  39. package/src/api/messaging/deleteThread.js +56 -0
  40. package/src/api/messaging/editMessage.js +90 -0
  41. package/src/api/messaging/forwardAttachment.js +57 -0
  42. package/src/api/messaging/forwardMessage.js +134 -0
  43. package/src/api/messaging/getEmojiUrl.js +29 -0
  44. package/src/api/messaging/getFriendsList.js +82 -0
  45. package/src/api/messaging/getMessage.js +829 -0
  46. package/src/api/messaging/getThemePictures.js +62 -0
  47. package/src/api/messaging/handleMessageRequest.js +65 -0
  48. package/src/api/messaging/markAsDelivered.js +57 -0
  49. package/src/api/messaging/markAsRead.js +88 -0
  50. package/src/api/messaging/markAsReadAll.js +49 -0
  51. package/src/api/messaging/markAsSeen.js +61 -0
  52. package/src/api/messaging/muteThread.js +50 -0
  53. package/src/api/messaging/pinMessage.js +115 -0
  54. package/src/api/messaging/removeUserFromGroup.js +62 -0
  55. package/src/api/messaging/resolvePhotoUrl.js +43 -0
  56. package/src/api/messaging/scheduler.js +264 -0
  57. package/src/api/messaging/searchForThread.js +53 -0
  58. package/src/api/messaging/sendBroadcast.js +93 -0
  59. package/src/api/messaging/sendMessage.js +269 -0
  60. package/src/api/messaging/sendTypingIndicator.js +74 -0
  61. package/src/api/messaging/sessionGuard.js +130 -0
  62. package/src/api/messaging/setMessageReaction.js +95 -0
  63. package/src/api/messaging/setTitle.js +124 -0
  64. package/src/api/messaging/shareContact.js +49 -0
  65. package/src/api/messaging/threadColors.js +128 -0
  66. package/src/api/messaging/unsendMessage.js +81 -0
  67. package/src/api/messaging/uploadAttachment.js +492 -0
  68. package/src/api/socket/OldMessage.js +186 -0
  69. package/src/api/socket/core/connectMqtt.js +269 -0
  70. package/src/api/socket/core/emitAuth.js +103 -0
  71. package/src/api/socket/core/getSeqID.js +321 -0
  72. package/src/api/socket/core/getTaskResponseData.js +25 -0
  73. package/src/api/socket/core/parseDelta.js +387 -0
  74. package/src/api/socket/detail/buildStream.js +215 -0
  75. package/src/api/socket/detail/constants.js +28 -0
  76. package/src/api/socket/e2ee/crypto.js +173 -0
  77. package/src/api/socket/e2ee/e2ee/crypto.js +173 -0
  78. package/src/api/socket/e2ee/e2ee/index.js +421 -0
  79. package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +281 -0
  80. package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +14 -0
  81. package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +232 -0
  82. package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +82 -0
  83. package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +77 -0
  84. package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +66 -0
  85. package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +176 -0
  86. package/src/api/socket/e2ee/e2ee/proto/proto-writer.ts +76 -0
  87. package/src/api/socket/e2ee/e2ee/protocol.js +196 -0
  88. package/src/api/socket/e2ee/e2ee/ratchet.js +219 -0
  89. package/src/api/socket/e2ee/e2ee/store.js +182 -0
  90. package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +9162 -0
  91. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  92. package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  93. package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  94. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +82 -0
  95. package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +77 -0
  96. package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +66 -0
  97. package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  98. package/src/api/socket/e2ee/e2ee/vendor/proto/proto-writer.ts +76 -0
  99. package/src/api/socket/e2ee/index.js +437 -0
  100. package/src/api/socket/e2ee/proto/ArmadilloApplication.proto +281 -0
  101. package/src/api/socket/e2ee/proto/ArmadilloICDC.proto +14 -0
  102. package/src/api/socket/e2ee/proto/ConsumerApplication.proto +232 -0
  103. package/src/api/socket/e2ee/proto/MessageApplication.proto +82 -0
  104. package/src/api/socket/e2ee/proto/MessageTransport.proto +77 -0
  105. package/src/api/socket/e2ee/proto/WACommon.proto +66 -0
  106. package/src/api/socket/e2ee/proto/WAMediaTransport.proto +176 -0
  107. package/src/api/socket/e2ee/proto/proto-writer.ts +76 -0
  108. package/src/api/socket/e2ee/protocol.js +196 -0
  109. package/src/api/socket/e2ee/ratchet.js +219 -0
  110. package/src/api/socket/e2ee/store.js +182 -0
  111. package/src/api/socket/e2ee/vendor/fb-e2ee.cjs +9162 -0
  112. package/src/api/socket/e2ee/vendor/proto/ArmadilloApplication.proto +281 -0
  113. package/src/api/socket/e2ee/vendor/proto/ArmadilloICDC.proto +14 -0
  114. package/src/api/socket/e2ee/vendor/proto/ConsumerApplication.proto +232 -0
  115. package/src/api/socket/e2ee/vendor/proto/MessageApplication.proto +82 -0
  116. package/src/api/socket/e2ee/vendor/proto/MessageTransport.proto +77 -0
  117. package/src/api/socket/e2ee/vendor/proto/WACommon.proto +66 -0
  118. package/src/api/socket/e2ee/vendor/proto/WAMediaTransport.proto +176 -0
  119. package/src/api/socket/e2ee/vendor/proto/proto-writer.ts +76 -0
  120. package/src/api/socket/listenE2EE.js +75 -0
  121. package/src/api/socket/listenMqtt.js +388 -0
  122. package/src/api/socket/middleware/index.js +216 -0
  123. package/src/api/socket/sendMessage.js +309 -0
  124. package/src/api/socket/sendMessageMqtt.js +69 -0
  125. package/src/api/threads/getThreadHistory.js +664 -0
  126. package/src/api/threads/getThreadInfo.js +296 -0
  127. package/src/api/threads/getThreadList.js +293 -0
  128. package/src/api/threads/getThreadPictures.js +78 -0
  129. package/src/api/users/getUserID.js +65 -0
  130. package/src/api/users/getUserInfo.js +402 -0
  131. package/src/api/users/getUserInfoV2.js +134 -0
  132. package/src/app/MessengerBot.js +209 -0
  133. package/src/app/MessengerContext.js +32 -0
  134. package/src/app/createFcaClient.js +136 -0
  135. package/src/app/threadInfoRealtimeSync.js +284 -0
  136. package/src/core/sendReqMqtt.js +96 -0
  137. package/src/database/helpers.js +53 -0
  138. package/src/database/models/index.js +88 -0
  139. package/src/database/models/thread.js +50 -0
  140. package/src/database/models/user.js +46 -0
  141. package/src/database/threadData.js +94 -0
  142. package/src/database/userData.js +98 -0
  143. package/src/remote/remoteClient.js +123 -0
  144. package/src/utils/broadcast.js +51 -0
  145. package/src/utils/client.js +10 -0
  146. package/src/utils/constants.js +23 -0
  147. package/src/utils/cookies.js +68 -0
  148. package/src/utils/format/attachment.js +357 -0
  149. package/src/utils/format/cookie.js +9 -0
  150. package/src/utils/format/date.js +50 -0
  151. package/src/utils/format/decode.js +44 -0
  152. package/src/utils/format/delta.js +194 -0
  153. package/src/utils/format/ids.js +64 -0
  154. package/src/utils/format/index.js +64 -0
  155. package/src/utils/format/message.js +88 -0
  156. package/src/utils/format/presence.js +132 -0
  157. package/src/utils/format/readTyp.js +44 -0
  158. package/src/utils/format/thread.js +42 -0
  159. package/src/utils/format/utils.js +141 -0
  160. package/src/utils/headers.js +115 -0
  161. package/src/utils/loginParser/autoLogin.js +125 -0
  162. package/src/utils/loginParser/helpers.js +43 -0
  163. package/src/utils/loginParser/index.js +10 -0
  164. package/src/utils/loginParser/parseAndCheckLogin.js +220 -0
  165. package/src/utils/loginParser/textUtils.js +28 -0
  166. package/src/utils/nexca-logger.js +144 -0
  167. package/src/utils/nexca-utils.js +686 -0
  168. package/src/utils/request/client.js +26 -0
  169. package/src/utils/request/config.js +23 -0
  170. package/src/utils/request/defaults.js +46 -0
  171. package/src/utils/request/helpers.js +46 -0
  172. package/src/utils/request/index.js +17 -0
  173. package/src/utils/request/methods.js +163 -0
  174. package/src/utils/request/proxy.js +21 -0
  175. package/src/utils/request/retry.js +77 -0
  176. package/src/utils/request/sanitize.js +49 -0
  177. package/src/utils/versionCheck.js +47 -0
  178. package/src/vendor/fca-unofficial/.github/workflows/nodejs.yml +26 -0
  179. package/src/vendor/fca-unofficial/.github/workflows/npmpublish.yml +30 -0
  180. package/src/vendor/fca-unofficial/.travis.yml +6 -0
  181. package/src/vendor/fca-unofficial/DOCS.md +1731 -0
  182. package/src/vendor/fca-unofficial/LICENSE-MIT +21 -0
  183. package/src/vendor/fca-unofficial/README.md +225 -0
  184. package/src/vendor/fca-unofficial/index.js +619 -0
  185. package/src/vendor/fca-unofficial/package.json +76 -0
  186. package/src/vendor/fca-unofficial/src/addExternalModule.js +19 -0
  187. package/src/vendor/fca-unofficial/src/addUserToGroup.js +113 -0
  188. package/src/vendor/fca-unofficial/src/changeAdminStatus.js +79 -0
  189. package/src/vendor/fca-unofficial/src/changeArchivedStatus.js +55 -0
  190. package/src/vendor/fca-unofficial/src/changeBio.js +77 -0
  191. package/src/vendor/fca-unofficial/src/changeBlockedStatus.js +47 -0
  192. package/src/vendor/fca-unofficial/src/changeGroupImage.js +129 -0
  193. package/src/vendor/fca-unofficial/src/changeNickname.js +59 -0
  194. package/src/vendor/fca-unofficial/src/changeThreadColor.js +71 -0
  195. package/src/vendor/fca-unofficial/src/changeThreadEmoji.js +55 -0
  196. package/src/vendor/fca-unofficial/src/createNewGroup.js +86 -0
  197. package/src/vendor/fca-unofficial/src/createPoll.js +71 -0
  198. package/src/vendor/fca-unofficial/src/deleteMessage.js +56 -0
  199. package/src/vendor/fca-unofficial/src/deleteThread.js +56 -0
  200. package/src/vendor/fca-unofficial/src/forwardAttachment.js +60 -0
  201. package/src/vendor/fca-unofficial/src/getCurrentUserID.js +7 -0
  202. package/src/vendor/fca-unofficial/src/getEmojiUrl.js +29 -0
  203. package/src/vendor/fca-unofficial/src/getFriendsList.js +84 -0
  204. package/src/vendor/fca-unofficial/src/getThreadHistory.js +645 -0
  205. package/src/vendor/fca-unofficial/src/getThreadHistoryDeprecated.js +93 -0
  206. package/src/vendor/fca-unofficial/src/getThreadInfo.js +201 -0
  207. package/src/vendor/fca-unofficial/src/getThreadInfoDeprecated.js +80 -0
  208. package/src/vendor/fca-unofficial/src/getThreadList.js +238 -0
  209. package/src/vendor/fca-unofficial/src/getThreadListDeprecated.js +75 -0
  210. package/src/vendor/fca-unofficial/src/getThreadPictures.js +79 -0
  211. package/src/vendor/fca-unofficial/src/getUserID.js +66 -0
  212. package/src/vendor/fca-unofficial/src/getUserInfo.js +72 -0
  213. package/src/vendor/fca-unofficial/src/handleFriendRequest.js +61 -0
  214. package/src/vendor/fca-unofficial/src/handleMessageRequest.js +65 -0
  215. package/src/vendor/fca-unofficial/src/httpGet.js +52 -0
  216. package/src/vendor/fca-unofficial/src/httpPost.js +52 -0
  217. package/src/vendor/fca-unofficial/src/listenMqtt.js +788 -0
  218. package/src/vendor/fca-unofficial/src/logout.js +75 -0
  219. package/src/vendor/fca-unofficial/src/markAsDelivered.js +58 -0
  220. package/src/vendor/fca-unofficial/src/markAsRead.js +80 -0
  221. package/src/vendor/fca-unofficial/src/markAsReadAll.js +50 -0
  222. package/src/vendor/fca-unofficial/src/markAsSeen.js +59 -0
  223. package/src/vendor/fca-unofficial/src/muteThread.js +52 -0
  224. package/src/vendor/fca-unofficial/src/removeUserFromGroup.js +79 -0
  225. package/src/vendor/fca-unofficial/src/resolvePhotoUrl.js +45 -0
  226. package/src/vendor/fca-unofficial/src/searchForThread.js +53 -0
  227. package/src/vendor/fca-unofficial/src/sendMessage.js +459 -0
  228. package/src/vendor/fca-unofficial/src/sendTypingIndicator.js +103 -0
  229. package/src/vendor/fca-unofficial/src/setMessageReaction.js +117 -0
  230. package/src/vendor/fca-unofficial/src/setPostReaction.js +76 -0
  231. package/src/vendor/fca-unofficial/src/setTitle.js +86 -0
  232. package/src/vendor/fca-unofficial/src/threadColors.js +57 -0
  233. package/src/vendor/fca-unofficial/src/unfriend.js +52 -0
  234. package/src/vendor/fca-unofficial/src/unsendMessage.js +49 -0
  235. package/src/vendor/fca-unofficial/test/data/shareAttach.js +146 -0
  236. package/src/vendor/fca-unofficial/test/data/something.mov +0 -0
  237. package/src/vendor/fca-unofficial/test/data/test.png +0 -0
  238. package/src/vendor/fca-unofficial/test/data/test.txt +7 -0
  239. package/src/vendor/fca-unofficial/test/example-config.json +18 -0
  240. package/src/vendor/fca-unofficial/test/test-page.js +140 -0
  241. package/src/vendor/fca-unofficial/test/test.js +385 -0
  242. package/src/vendor/fca-unofficial/utils.js +1358 -0
package/README.md ADDED
@@ -0,0 +1,410 @@
1
+ <div align="center">
2
+
3
+ # 💬 fca-riyad
4
+
5
+ **Unofficial Facebook Messenger Bot API for Node.js**
6
+ NEXCA Engine · Signal Protocol E2EE · sessionGuard · 90+ API Methods · Zero TypeScript
7
+
8
+ [![npm](https://img.shields.io/npm/v/fca-riyad?color=blue)](https://www.npmjs.com/package/fca-riyad)
9
+ [![license](https://img.shields.io/badge/license-MIT-green)](./LICENSE-MIT)
10
+ [![node](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
11
+
12
+ [Features](#-features) • [Installation](#-installation) • [Quick Start](#-quick-start) • [E2EE](#-e2ee--encrypted-conversations) • [sessionGuard](#-sessionguard) • [sendBroadcast](#-sendbroadcast) • [API Reference](#-api-reference)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ ## ⚡ Why fca-riyad?
19
+
20
+ - ✅ **NEXCA Engine** — nexca MQTT, E2EE, sessionGuard core integrated
21
+ - ✅ **Signal Protocol E2EE** — Facebook real encrypted conversations support
22
+ - ✅ **sessionGuard** — appstate corruption and silent logout protection, auto-backup
23
+ - ✅ **sendBroadcast** — rate-limited multi-thread broadcast
24
+ - ✅ **Fixed MQTT subscribe race condition** — no more "Connection refused: No subscription existed"
25
+ - ✅ **`isActiveClient()` guard** — stale MQTT client events no longer processed
26
+ - ✅ **`connectTimeout` extended** — no premature logout on slow networks
27
+ - ✅ **autoReconnect** — auto-reconnect on connection drop
28
+ - ✅ **GoatBot compatible** — all API signatures unchanged (`threadID` optional etc.)
29
+ - ✅ **90+ API methods** — sendMessage, editMessage, setMessageReaction, getThreadInfo and more
30
+
31
+ ---
32
+
33
+ ## ✨ Features
34
+
35
+ - ✅ Full Messenger API — messages, reactions, attachments, stickers, polls, pins
36
+ - ✅ NEXCA MQTT — stable connection, autoReconnect, jitter, isActiveClient guard
37
+ - ✅ E2EE — Signal Protocol encrypted threads (connectE2EE, listenE2EE, e2ee.*)
38
+ - ✅ sessionGuard — appstate auto-save, corruption guard, .bak backup
39
+ - ✅ sendBroadcast — parallel/sequential multi-thread sending with rate limit
40
+ - ✅ MessengerBot — Discord.js/Telegraf style (.command, .hears, .launch)
41
+ - ✅ createFcaClient — namespaced facade (client.messages, client.threads etc.)
42
+ - ✅ GoatBot / Mirai compatible — drop-in replacement
43
+
44
+ ---
45
+
46
+ ## 📦 Installation
47
+
48
+ ```bash
49
+ npm install fca-riyad
50
+ ```
51
+
52
+ Node.js >= 18 required.
53
+
54
+ ---
55
+
56
+ ## 🚀 Quick Start
57
+
58
+ ### Classic (GoatBot compatible)
59
+
60
+ ```javascript
61
+ const login = require("fca-riyad");
62
+
63
+ login({ appState: require("./account.json") }, { listenEvents: true }, (err, api) => {
64
+ if (err) throw err;
65
+
66
+ api.sessionGuard("./account.json", {
67
+ interval: 3 * 60 * 1000,
68
+ debounce: 30 * 1000
69
+ });
70
+
71
+ api.listenMqtt((err, event) => {
72
+ if (err) throw err;
73
+ if (event.type === "message") api.sendMessage(event.body, event.threadID);
74
+ });
75
+ });
76
+ ```
77
+
78
+ ### With E2EE (regular + encrypted threads)
79
+
80
+ ```javascript
81
+ login({ appState: require("./account.json") }, { listenEvents: true }, async (err, api) => {
82
+ if (err) throw err;
83
+
84
+ api.sessionGuard("./account.json");
85
+ await api.connectE2EE();
86
+
87
+ api.listenE2EE((err, event) => {
88
+ if (err) throw err;
89
+ if (event.type === "message") {
90
+ if (event.isE2EE) {
91
+ api.e2ee.sendMessage(event.threadID, "Got your encrypted message!");
92
+ } else {
93
+ api.sendMessage("Got it!", event.threadID);
94
+ }
95
+ }
96
+ });
97
+ });
98
+ ```
99
+
100
+ ### GoatBot login.js
101
+
102
+ ```javascript
103
+ const login = require("fca-riyad");
104
+
105
+ login({ appState }, options, async (err, api) => {
106
+ if (err) return;
107
+
108
+ api.sessionGuard(path.join(process.cwd(), "account.txt"), {
109
+ interval: 3 * 60 * 1000,
110
+ debounce: 30 * 1000
111
+ });
112
+
113
+ try { await api.connectE2EE(); } catch (e) {}
114
+
115
+ api.listenMqtt(callback);
116
+ });
117
+ ```
118
+
119
+ ---
120
+
121
+ ## 🔐 E2EE — Encrypted Conversations
122
+
123
+ Uses Facebook's real Signal Protocol infrastructure — same as the official Messenger app.
124
+
125
+ ### Setup
126
+
127
+ ```javascript
128
+ await api.connectE2EE();
129
+ // Auto-creates .nexca/e2ee_device.json
130
+
131
+ console.log(api.e2ee.isConnected()); // true
132
+ ```
133
+
134
+ ### Listen (regular + E2EE combined)
135
+
136
+ ```javascript
137
+ api.listenE2EE((err, event) => {
138
+ if (event.type === "message") {
139
+ if (event.isE2EE) {
140
+ api.e2ee.sendMessage(event.threadID, "Encrypted reply!");
141
+ } else {
142
+ api.sendMessage("Normal reply!", event.threadID);
143
+ }
144
+ }
145
+ });
146
+ ```
147
+
148
+ ### E2EE Methods
149
+
150
+ ```javascript
151
+ await api.e2ee.sendMessage(threadID, "Hello!");
152
+ await api.e2ee.sendMessage(threadID, { body: "Photo!", attachment: fs.createReadStream("photo.jpg") });
153
+ await api.e2ee.sendReaction(threadID, messageID, "❤️");
154
+ await api.e2ee.sendTyping(threadID, true);
155
+ await api.e2ee.unsendMessage(messageID, threadID);
156
+ await api.e2ee.editMessage(threadID, messageID, "Updated!");
157
+ api.e2ee.isConnected();
158
+ await api.e2ee.disconnect();
159
+ ```
160
+
161
+ ---
162
+
163
+ ## 🛡️ sessionGuard
164
+
165
+ Protects your appstate from corruption and silent logouts.
166
+
167
+ ```javascript
168
+ api.sessionGuard("./account.json");
169
+
170
+ // Custom timing
171
+ api.sessionGuard("./account.json", {
172
+ interval: 3 * 60 * 1000,
173
+ debounce: 30 * 1000
174
+ });
175
+ ```
176
+
177
+ What it does:
178
+ - Auto-saves appstate every N minutes
179
+ - Saves after every successful sendMessage (debounced)
180
+ - Corruption guard — never overwrites a larger appstate with a smaller one
181
+ - Auto-backup — writes `.bak` before every overwrite
182
+
183
+ ```javascript
184
+ api.saveSession(); // force save now
185
+ api.restoreSessionBackup(); // restore from .bak
186
+ api.stopSessionGuard(); // stop the timer
187
+ ```
188
+
189
+ ---
190
+
191
+ ## 📡 sendBroadcast
192
+
193
+ Rate-limited multi-thread broadcast.
194
+
195
+ ```javascript
196
+ const result = await api.sendBroadcast(
197
+ "Hello everyone!",
198
+ ["THREAD_1", "THREAD_2", "THREAD_3"],
199
+ {
200
+ delay: 2000,
201
+ parallel: 2,
202
+ onEach: (err, info, id) => {
203
+ console.log(err ? "Failed: " + id : "Sent: " + id);
204
+ }
205
+ }
206
+ );
207
+ console.log(result.sent.length + "/" + result.total + " delivered");
208
+ ```
209
+
210
+ ---
211
+
212
+ ## 🤖 MessengerBot
213
+
214
+ Discord.js/Telegraf style high-level bot class.
215
+
216
+ ```javascript
217
+ const { createMessengerBot } = require("fca-riyad");
218
+
219
+ const bot = await createMessengerBot(
220
+ { appState: require("./account.json") },
221
+ { commandPrefix: "/", stopOnSignals: true }
222
+ );
223
+
224
+ bot.command("ping", async ctx => await ctx.replyAsync("pong 🏓"));
225
+ bot.hears(/hello/i, async ctx => await ctx.replyAsync("Hi! 👋"));
226
+ bot.on("messageCreate", event => console.log(event.body));
227
+
228
+ await bot.launch({ stopOnSignals: true });
229
+ ```
230
+
231
+ ---
232
+
233
+ ## 🎯 createFcaClient
234
+
235
+ Namespaced facade grouping all API methods by domain.
236
+
237
+ ```javascript
238
+ const { createFcaClient } = require("fca-riyad");
239
+ const client = createFcaClient(api);
240
+
241
+ await client.messages.send("Hello!", threadID);
242
+ await client.messages.react("❤️", messageID, threadID);
243
+ await client.threads.getInfo(threadID);
244
+ await client.users.getInfo(userID);
245
+ await client.account.refreshDtsg();
246
+ ```
247
+
248
+ ---
249
+
250
+ ## 📖 API Reference
251
+
252
+ ### Sending Messages
253
+
254
+ ```javascript
255
+ api.sendMessage("Hello!", threadID);
256
+ api.sendMessage({ body: "Photo!", attachment: fs.createReadStream("photo.jpg") }, threadID);
257
+ api.sendMessage({ body: "Hey @John", mentions: [{ id: "uid", tag: "@John", fromIndex: 4 }] }, threadID);
258
+ api.sendMessage({ sticker: "369239263222822" }, threadID);
259
+ api.sendMessage({ location: { latitude: 23.8, longitude: 90.4, current: true } }, threadID);
260
+ api.sendBroadcast("msg", ["tid1", "tid2"], { delay: 2000 });
261
+ api.sendGif("https://media.giphy.com/xyz.gif", threadID);
262
+ api.sendLocation(23.8, 90.4, threadID);
263
+ api.sendImage("./photo.jpg", threadID, "caption");
264
+ api.sendVideo("./video.mp4", threadID);
265
+ api.sendAudio("./voice.ogg", threadID);
266
+ api.sendFile("./doc.pdf", threadID);
267
+ api.shareLink("https://github.com", threadID, "Check this!");
268
+ api.shareContact("Meet my friend!", userID, threadID);
269
+ ```
270
+
271
+ ### Message Actions
272
+
273
+ ```javascript
274
+ api.editMessage("Updated text", messageID);
275
+ api.unsendMessage(messageID);
276
+ api.deleteMessage([messageID]);
277
+ api.setMessageReaction("😍", messageID, threadID); // threadID optional
278
+ api.setMessageReaction("", messageID); // remove reaction
279
+ api.getMessage(threadID, messageID);
280
+ api.forwardAttachment(attachmentID, [userID]);
281
+ api.uploadAttachment([fs.createReadStream("photo.jpg")]);
282
+ ```
283
+
284
+ ### Read Receipts & Typing
285
+
286
+ ```javascript
287
+ api.markAsRead(threadID);
288
+ api.markAsReadAll();
289
+ api.markAsDelivered(threadID, messageID);
290
+ api.markAsSeen();
291
+ api.sendTypingIndicator(threadID, true);
292
+ ```
293
+
294
+ ### Thread Management
295
+
296
+ ```javascript
297
+ api.getThreadInfo(threadID);
298
+ api.getThreadList(10, null, ["INBOX"]);
299
+ api.getThreadHistory(threadID, 20);
300
+ api.createGroup("Hey!", ["uid1", "uid2"]);
301
+ api.deleteThread(threadID);
302
+ api.muteThread(threadID, 3600);
303
+ api.changeArchivedStatus(threadID, true);
304
+ api.handleMessageRequest(threadID, true);
305
+ api.searchForThread("query");
306
+ ```
307
+
308
+ ### Thread Customization
309
+
310
+ ```javascript
311
+ api.setTitle("New Name", threadID);
312
+ api.changeThreadColor("#0084FF", threadID);
313
+ api.changeThreadEmoji("🔥", threadID);
314
+ api.changeNickname("The Boss", threadID, userID);
315
+ api.changeGroupImage(fs.createReadStream("group.jpg"), threadID);
316
+ api.changeAdminStatus(threadID, userID, true);
317
+ api.addUserToGroup(userID, threadID);
318
+ api.removeUserFromGroup(userID, threadID);
319
+ api.createPoll("Question?", threadID, { "Yes": false, "No": false });
320
+ api.pinMessage(messageID, threadID);
321
+ api.unpinMessage(messageID, threadID);
322
+ ```
323
+
324
+ ### User Info
325
+
326
+ ```javascript
327
+ api.getUserInfo(userID);
328
+ api.getUserID("John Doe", callback);
329
+ api.getUID("https://facebook.com/zuck");
330
+ api.getFriendsList();
331
+ api.getAvatarUser(userID);
332
+ api.getProfileInfo(userID);
333
+ api.getPublicData(userID);
334
+ api.sendFriendRequest(userID);
335
+ api.handleFriendRequest(userID, true);
336
+ api.changeBlockedStatus(userID, true);
337
+ api.followUser(userID);
338
+ api.unfollowUser(userID);
339
+ api.unfriend(userID);
340
+ ```
341
+
342
+ ### Social
343
+
344
+ ```javascript
345
+ api.reactToPost(postID, "love");
346
+ api.reactToComment(commentID, "haha");
347
+ api.postComment(postID, "Great post!");
348
+ api.sharePost(postID, "Check this!");
349
+ ```
350
+
351
+ ### Account & Config
352
+
353
+ ```javascript
354
+ api.getCurrentUserID();
355
+ api.getAppState();
356
+ api.setOptions({ listenTyping: true });
357
+ api.logout();
358
+ api.refreshFb_dtsg();
359
+ api.addExternalModule("myFunc", (defaultFuncs, api, ctx) => {
360
+ return function(text, threadID) {
361
+ return api.sendMessage("[BOT] " + text, threadID);
362
+ };
363
+ });
364
+ ```
365
+
366
+ ### HTTP Utilities
367
+
368
+ ```javascript
369
+ api.httpGet(url, params, callback);
370
+ api.httpPost(url, form, callback);
371
+ api.httpPostFormData(url, form, callback);
372
+ api.uploadImageToImgbb(imageUrl);
373
+ ```
374
+
375
+ ---
376
+
377
+ ## 📋 Login Options
378
+
379
+ | Option | Type | Default | Description |
380
+ |--------|------|---------|-------------|
381
+ | `selfListen` | boolean | false | Receive your own sent messages |
382
+ | `listenEvents` | boolean | true | Receive thread/group events |
383
+ | `listenTyping` | boolean | false | Receive typing indicator events |
384
+ | `updatePresence` | boolean | false | Receive online/offline presence events |
385
+ | `autoMarkDelivery` | boolean | false | Auto-mark incoming messages as delivered |
386
+ | `autoMarkRead` | boolean | false | Auto-mark threads as read |
387
+ | `autoReconnect` | boolean | true | Auto-reconnect MQTT on disconnect |
388
+ | `online` | boolean | false | Appear as online to others |
389
+ | `emitReady` | boolean | false | Emit ready event when MQTT connected |
390
+ | `proxy` | string | — | HTTP proxy URL |
391
+ | `userAgent` | string | Safari UA | Override HTTP User-Agent |
392
+
393
+ ---
394
+
395
+ ## 📄 License
396
+
397
+ MIT License
398
+
399
+ **fca-riyad** by [Riyad (Mohammad Akash)](https://github.com/Riyad)
400
+ NEXCA Engine by [Deku](https://github.com/dekuzxc) — MIT License
401
+
402
+ > Unauthorized copying or redistribution without credit is prohibited.
403
+
404
+ ---
405
+
406
+ <div align="center">
407
+
408
+ Made with ❤️ by Riyad
409
+
410
+ </div>
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ // Auto-update disabled in fca-riyad
3
+ function checkAndUpdateVersion(callback) {
4
+ if (typeof callback === "function") callback(null);
5
+ return Promise.resolve();
6
+ }
7
+ module.exports = { checkAndUpdateVersion };
@@ -0,0 +1,33 @@
1
+ const logger = require("./logger");
2
+
3
+ function formatArgs(args) {
4
+ const [prefix, msg] = args;
5
+
6
+ // Single argument: log as-is
7
+ if (msg === undefined) {
8
+ if (prefix instanceof Error) {
9
+ return prefix.stack || prefix.message || String(prefix);
10
+ }
11
+ return String(prefix);
12
+ }
13
+
14
+ // Two arguments: mimic npmlog("tag", message)
15
+ const tag = prefix == null ? "" : String(prefix);
16
+ if (msg instanceof Error) {
17
+ const base = msg.message || String(msg);
18
+ return tag ? `${tag}: ${base}` : base;
19
+ }
20
+ const text = msg == null ? "" : String(msg);
21
+ return tag ? `${tag}: ${text}` : text;
22
+ }
23
+
24
+ const log = {
25
+ info: (...args) => logger(formatArgs(args), "info"),
26
+ warn: (...args) => logger(formatArgs(args), "warn"),
27
+ error: (...args) => logger(formatArgs(args), "error"),
28
+ verbose: (...args) => logger(formatArgs(args), "info"),
29
+ silly: (...args) => logger(formatArgs(args), "info")
30
+ };
31
+
32
+ module.exports = log;
33
+
package/func/logger.js ADDED
@@ -0,0 +1,48 @@
1
+ const chalk = require("chalk");
2
+ const gradient = require("gradient-string");
3
+
4
+ const themes = [
5
+ "blue", "dream2", "dream", "fiery", "rainbow", "pastel", "cristal", "red", "aqua", "pink", "retro", "sunlight", "teen", "summer", "flower", "ghost", "hacker"
6
+ ];
7
+
8
+ function buildGradient(name) {
9
+ const t = String(name || "").toLowerCase();
10
+ if (t === "blue") return gradient([{ color: "#1affa3", pos: 0.2 }, { color: "cyan", pos: 0.4 }, { color: "pink", pos: 0.6 }, { color: "cyan", pos: 0.8 }, { color: "#1affa3", pos: 1 }]);
11
+ if (t === "dream2") return gradient("blue", "pink");
12
+ if (t === "dream") return gradient([{ color: "blue", pos: 0.2 }, { color: "pink", pos: 0.3 }, { color: "gold", pos: 0.6 }, { color: "pink", pos: 0.8 }, { color: "blue", pos: 1 }]);
13
+ if (t === "fiery") return gradient("#fc2803", "#fc6f03", "#fcba03");
14
+ if (t === "rainbow") return gradient.rainbow;
15
+ if (t === "pastel") return gradient.pastel;
16
+ if (t === "cristal") return gradient.cristal;
17
+ if (t === "red") return gradient("red", "orange");
18
+ if (t === "aqua") return gradient("#0030ff", "#4e6cf2");
19
+ if (t === "pink") return gradient("#d94fff", "purple");
20
+ if (t === "retro") return gradient.retro;
21
+ if (t === "sunlight") return gradient("orange", "#ffff00", "#ffe600");
22
+ if (t === "teen") return gradient.teen;
23
+ if (t === "summer") return gradient.summer;
24
+ if (t === "flower") return gradient("blue", "purple", "yellow", "#81ff6e");
25
+ if (t === "ghost") return gradient.mind;
26
+ if (t === "hacker") return gradient("#47a127", "#0eed19", "#27f231");
27
+ return gradient("#243aff", "#4687f0", "#5800d4");
28
+ }
29
+
30
+ const themeName = themes[Math.floor(Math.random() * themes.length)];
31
+ const co = buildGradient(themeName);
32
+
33
+ module.exports = (text, type) => {
34
+ const s = String(type || "info").toLowerCase();
35
+ if (s === "warn") {
36
+ process.stderr.write(co(`\r[ FCA-WARN ] > ${text}`) + "\n");
37
+ return;
38
+ }
39
+ if (s === "error") {
40
+ process.stderr.write(chalk.bold.hex("#ff0000")(`\r[ FCA-ERROR ]`) + ` > ${text}\n`);
41
+ return;
42
+ }
43
+ if (s === "info") {
44
+ process.stderr.write(chalk.bold(co(`\r[ FCA-UNO ] > ${text}`)) + "\n");
45
+ return;
46
+ }
47
+ process.stderr.write(chalk.bold(co(`\r[ ${s.toUpperCase()} ] > ${text}`)) + "\n");
48
+ };