levix-bot 4.9.2 → 5.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/README.md +57 -3
  2. package/SETUP.md +63 -7
  3. package/app.cjs +159 -46
  4. package/deploy/install.sh +10 -5
  5. package/package.json +9 -6
  6. package/public/dashboard/assets/40af6d88b63079a0-BZ8ojJNu.woff2 +0 -0
  7. package/public/dashboard/assets/481acf6760031cee-BypgxfGb.woff2 +0 -0
  8. package/public/dashboard/assets/6d3351fc535f8ef3-D2-eand5.woff2 +0 -0
  9. package/public/dashboard/assets/8ab0af53a3bda9d3-CyCXRvzh.woff2 +0 -0
  10. package/public/dashboard/assets/8f262393e9249e61-TQp-UTiE.woff2 +0 -0
  11. package/public/dashboard/assets/94d65887a83f1282-DmpS2jIq.woff2 +0 -0
  12. package/public/dashboard/assets/99e400330f36ae77-D3oMJlXt.woff2 +0 -0
  13. package/public/dashboard/assets/9d1f41b13e519d90-BVNSOH3d.woff2 +0 -0
  14. package/public/dashboard/assets/a005256cb957ecc7-CoYeBiSI.woff2 +0 -0
  15. package/public/dashboard/assets/b19c2080652a3c2b-DIC32ArD.woff2 +0 -0
  16. package/public/dashboard/assets/c4064400db3750ce-BehTv68k.woff2 +0 -0
  17. package/public/dashboard/assets/c69d345fa1068c2d-CmI34b-g.woff2 +0 -0
  18. package/public/dashboard/assets/cc27b30471250057-6fWv1k7M.woff2 +0 -0
  19. package/public/dashboard/assets/d8c30647abfeffe6-eXO_dkmS.woff2 +0 -0
  20. package/public/dashboard/assets/eb83d8d40af4411f-Buze_B52.woff2 +0 -0
  21. package/public/dashboard/assets/effc6711249e7349-qRpaaN48.woff2 +0 -0
  22. package/public/dashboard/assets/gateway-BDYet0pI.css +1 -0
  23. package/public/dashboard/assets/gateway-BYt6-s1O.js +1 -0
  24. package/public/dashboard/assets/index-B9wFpD_z.css +2 -0
  25. package/public/dashboard/assets/index-DWcQmu0_.js +124 -0
  26. package/public/dashboard/assets/index-Da-j89O-.js +458 -0
  27. package/public/dashboard/font-licenses/jetbrainsmono-OFL.txt +93 -0
  28. package/public/dashboard/font-licenses/plusjakartasans-OFL.txt +93 -0
  29. package/public/dashboard/font-licenses/tajawal-OFL.txt +93 -0
  30. package/public/dashboard/gateway.html +17 -0
  31. package/public/dashboard/index.html +3 -5
  32. package/public/ui-boot.js +33 -14
  33. package/scheduler.cjs +76 -23
  34. package/src/auth/auth-storage.cjs +54 -7
  35. package/src/auth/use-database-auth-state.js +70 -39
  36. package/src/automation/engine.js +412 -0
  37. package/src/automation/limits.cjs +6 -0
  38. package/src/automation/manage.js +290 -0
  39. package/src/automation/reactions.js +471 -0
  40. package/src/automation/rules.cjs +114 -0
  41. package/src/automation/status.cjs +76 -0
  42. package/src/backup/account.cjs +29 -0
  43. package/src/backup/activation.cjs +247 -0
  44. package/src/backup/content.cjs +36 -0
  45. package/src/backup/create.cjs +280 -0
  46. package/src/backup/extensions.cjs +101 -0
  47. package/src/backup/format.cjs +565 -0
  48. package/src/backup/jobs.cjs +111 -0
  49. package/src/backup/journal.cjs +41 -0
  50. package/src/backup/plan.cjs +223 -0
  51. package/src/backup/recovery.cjs +110 -0
  52. package/src/backup/restore.cjs +460 -0
  53. package/src/backup/uploads.cjs +146 -0
  54. package/src/bootstrap/core.js +46 -12
  55. package/src/bootstrap/panel.js +53 -2
  56. package/src/bootstrap/session-startup-policy.js +8 -1
  57. package/src/cli.js +163 -22
  58. package/src/commands/autodelete.cjs +41 -57
  59. package/src/commands/autoschedule.cjs +7 -33
  60. package/src/commands/blacklist.cjs +17 -35
  61. package/src/commands/block.cjs +4 -18
  62. package/src/commands/calc.cjs +22 -74
  63. package/src/commands/debt.cjs +28 -59
  64. package/src/commands/deleteschedule.cjs +7 -23
  65. package/src/commands/digit.cjs +5 -39
  66. package/src/commands/gemini.cjs +135 -218
  67. package/src/commands/group/add.cjs +28 -76
  68. package/src/commands/group/all.cjs +4 -15
  69. package/src/commands/group/antilink.cjs +28 -41
  70. package/src/commands/group/antispam.cjs +25 -35
  71. package/src/commands/group/approveall.cjs +7 -21
  72. package/src/commands/group/clearwarns.cjs +4 -18
  73. package/src/commands/group/deletenote.cjs +4 -18
  74. package/src/commands/group/demote.cjs +6 -23
  75. package/src/commands/group/flagged.cjs +10 -19
  76. package/src/commands/group/kick.cjs +26 -36
  77. package/src/commands/group/media.cjs +21 -36
  78. package/src/commands/group/members.cjs +16 -28
  79. package/src/commands/group/note.cjs +3 -14
  80. package/src/commands/group/policy.cjs +16 -37
  81. package/src/commands/group/promote.cjs +5 -22
  82. package/src/commands/group/removeall.cjs +6 -38
  83. package/src/commands/group/rules.cjs +4 -19
  84. package/src/commands/group/save.cjs +4 -18
  85. package/src/commands/group/setname.cjs +5 -19
  86. package/src/commands/group/setpp.cjs +8 -26
  87. package/src/commands/group/setrules.cjs +4 -15
  88. package/src/commands/group/setwarn.cjs +6 -23
  89. package/src/commands/group/tagadmins.cjs +5 -16
  90. package/src/commands/group/warn.cjs +5 -16
  91. package/src/commands/group/warns.cjs +12 -33
  92. package/src/commands/group/welcome.cjs +17 -34
  93. package/src/commands/group.cjs +91 -68
  94. package/src/commands/help.cjs +48 -89
  95. package/src/commands/lang.cjs +38 -97
  96. package/src/commands/listschedules.cjs +19 -30
  97. package/src/commands/loop.cjs +9 -55
  98. package/src/commands/md.cjs +2 -13
  99. package/src/commands/memory.cjs +53 -87
  100. package/src/commands/mod.cjs +40 -79
  101. package/src/commands/notes.cjs +4 -15
  102. package/src/commands/pack.cjs +26 -49
  103. package/src/commands/packs.cjs +8 -18
  104. package/src/commands/perm.cjs +48 -51
  105. package/src/commands/ping.cjs +2 -10
  106. package/src/commands/poll.cjs +5 -38
  107. package/src/commands/prayer.cjs +55 -36
  108. package/src/commands/qr.cjs +4 -18
  109. package/src/commands/rand.cjs +9 -58
  110. package/src/commands/restart.cjs +15 -33
  111. package/src/commands/schedule.cjs +5 -25
  112. package/src/commands/score.cjs +6 -27
  113. package/src/commands/send.cjs +4 -18
  114. package/src/commands/setprefix.cjs +11 -23
  115. package/src/commands/shortlink.cjs +13 -39
  116. package/src/commands/status.cjs +188 -76
  117. package/src/commands/sticker.cjs +5 -16
  118. package/src/commands/stickers.cjs +16 -20
  119. package/src/commands/stopbot.cjs +9 -25
  120. package/src/commands/stt.cjs +75 -107
  121. package/src/commands/todo.cjs +11 -31
  122. package/src/commands/toimage.cjs +11 -27
  123. package/src/commands/translate.cjs +53 -36
  124. package/src/commands/tts.cjs +46 -40
  125. package/src/commands/unblock.cjs +3 -17
  126. package/src/commands/update.cjs +23 -0
  127. package/src/commands/weather.cjs +40 -47
  128. package/src/config/ai-identity.cjs +14 -1
  129. package/src/config/baileys.config.js +1 -1
  130. package/src/config/data-dir.cjs +37 -0
  131. package/src/config/defaults.cjs +1 -0
  132. package/src/config/exit-codes.cjs +11 -0
  133. package/src/config/lock.cjs +55 -81
  134. package/src/config/official-links.cjs +61 -0
  135. package/src/config/paths.cjs +4 -33
  136. package/src/config/release.cjs +87 -0
  137. package/src/config/settings.cjs +182 -10
  138. package/src/core/connection.js +37 -8
  139. package/src/core/events.js +119 -33
  140. package/src/core/session.js +525 -82
  141. package/src/core/socket.js +81 -10
  142. package/src/db/copy.cjs +136 -0
  143. package/src/db/db.cjs +241 -36
  144. package/src/db/startup-guard.js +5 -0
  145. package/src/db/store.cjs +561 -54
  146. package/src/diagnostics/debugLog.cjs +16 -4
  147. package/src/diagnostics/device.cjs +4 -2
  148. package/src/diagnostics/signalSessionInspect.cjs +38 -0
  149. package/src/domain/command.js +24 -22
  150. package/src/extensions/autoReply.cjs +521 -0
  151. package/src/extensions/context.cjs +73 -0
  152. package/src/extensions/contract.cjs +69 -0
  153. package/src/extensions/entitlement/client.cjs +381 -0
  154. package/src/extensions/entitlement/index.cjs +629 -0
  155. package/src/extensions/entitlement/installation.cjs +117 -0
  156. package/src/extensions/entitlement/keys.cjs +72 -0
  157. package/src/extensions/entitlement/state.cjs +201 -0
  158. package/src/extensions/entitlement/target.cjs +7 -0
  159. package/src/extensions/entitlement/token.cjs +225 -0
  160. package/src/extensions/host.cjs +519 -0
  161. package/src/extensions/templateKeys.cjs +81 -0
  162. package/src/handlers/command.handler.js +191 -64
  163. package/src/handlers/group.handler.js +78 -18
  164. package/src/handlers/message.handler.js +56 -25
  165. package/src/i18n/catalog.generated.cjs +3537 -0
  166. package/src/index.js +51 -12
  167. package/src/legal/bundled/ar.json +102 -0
  168. package/src/legal/bundled/en.json +102 -0
  169. package/src/legal/bundled/es-419.json +102 -0
  170. package/src/legal/bundled/pt-BR.json +102 -0
  171. package/src/legal/cli.cjs +200 -0
  172. package/src/legal/consent.cjs +187 -0
  173. package/src/legal/document.cjs +156 -0
  174. package/src/legal/keys.cjs +100 -0
  175. package/src/legal/release.cjs +226 -0
  176. package/src/legal/remote.cjs +419 -0
  177. package/src/legal/terms.cjs +142 -0
  178. package/src/messaging/escape.cjs +31 -0
  179. package/src/messaging/health.cjs +65 -0
  180. package/src/messaging/identity.cjs +42 -0
  181. package/src/messaging/message.cjs +136 -0
  182. package/src/messaging/parser.cjs +88 -0
  183. package/src/messaging/router.cjs +217 -0
  184. package/src/middleware/permissions.middleware.js +34 -2
  185. package/src/panel/account-profile.cjs +489 -0
  186. package/src/panel/fallback-page.cjs +177 -0
  187. package/src/panel/password-reset.cjs +13 -14
  188. package/src/panel/recovery-email.cjs +3 -1
  189. package/src/routes/backup.api.esm.js +175 -0
  190. package/src/routes/dashboard.api.esm.js +183 -7
  191. package/src/routes/plus.api.esm.js +172 -0
  192. package/src/routes/reactions.api.esm.js +60 -0
  193. package/src/services/aiAgent.cjs +56 -43
  194. package/src/services/aiDocs.cjs +187 -0
  195. package/src/services/aiImage.cjs +183 -0
  196. package/src/services/aiMedia.cjs +146 -0
  197. package/src/services/aiProviders.cjs +76 -80
  198. package/src/services/aiRouter.cjs +2 -2
  199. package/src/services/aiToolAuth.cjs +76 -4
  200. package/src/services/aiTools.cjs +431 -105
  201. package/src/services/autoDelete.cjs +9 -1
  202. package/src/services/levix-docs.generated.json +2623 -0
  203. package/src/services/memoryPolicy.cjs +56 -0
  204. package/src/services/updateCheck.cjs +362 -0
  205. package/src/stickers/errors.cjs +53 -97
  206. package/src/stickers/library.cjs +13 -6
  207. package/src/stickers/owner.cjs +1 -1
  208. package/src/utils/commandContext.cjs +13 -0
  209. package/src/utils/commandDocs.cjs +42 -20
  210. package/src/utils/geminiHttpOptions.cjs +56 -0
  211. package/src/utils/geminiMedia.cjs +28 -3
  212. package/src/utils/groupMetadataCache.cjs +386 -21
  213. package/src/utils/httpsFetch.cjs +113 -0
  214. package/src/utils/i18n.cjs +117 -7
  215. package/src/utils/linkPreview.cjs +90 -0
  216. package/src/utils/markdownParser.cjs +3 -3
  217. package/src/utils/memory.cjs +375 -28
  218. package/src/utils/messageContent.cjs +7 -1
  219. package/src/utils/moderationAction.cjs +116 -73
  220. package/src/utils/moderationSummary.cjs +32 -56
  221. package/src/utils/permissionLevel.cjs +7 -28
  222. package/src/utils/permissions.cjs +23 -14
  223. package/src/utils/permissions.esm.js +99 -166
  224. package/src/utils/recentMessageCache.esm.js +241 -37
  225. package/src/utils/recurrence.cjs +78 -66
  226. package/src/utils/sendBotMessage.cjs +14 -29
  227. package/src/utils/sendBotMessage.esm.js +28 -13
  228. package/src/utils/statusMessage.cjs +94 -33
  229. package/src/utils/stickerBot.cjs +18 -16
  230. package/src/utils/storage.cjs +2 -0
  231. package/src/utils/storage.esm.js +2 -0
  232. package/src/utils/thumbnail.cjs +5 -21
  233. package/public/dashboard/assets/index-4xhK_Tpl.js +0 -561
  234. package/public/dashboard/assets/index-CK8osB4o.css +0 -2
  235. package/public/dashboard.css +0 -3127
  236. package/public/dashboard.js +0 -1981
  237. package/public/gateway-i18n.js +0 -321
  238. package/public/gateway.js +0 -70
  239. package/views/dashboard.ejs +0 -775
  240. package/views/login.ejs +0 -408
  241. package/views/qr.ejs +0 -155
  242. package/views/setup.ejs +0 -118
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  <a href="https://github.com/Abdodiab2005/levix/actions/workflows/ci.yml"><img src="https://github.com/Abdodiab2005/levix/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
7
7
  <a href="https://www.npmjs.com/package/levix-bot"><img src="https://img.shields.io/npm/v/levix-bot?color=2563eb" alt="npm version"></a>
8
8
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-10b981" alt="MIT License"></a>
9
- <img src="https://img.shields.io/badge/Node.js-24%2B-339933?logo=nodedotjs&logoColor=white" alt="Node.js 24+">
9
+ <img src="https://img.shields.io/badge/Node.js-24-339933?logo=nodedotjs&logoColor=white" alt="Node.js 24">
10
10
  </p>
11
11
 
12
12
  <p align="center">
@@ -100,7 +100,7 @@ proxies, headless mode, backups, and troubleshooting.
100
100
  | Area | What Levix provides |
101
101
  | --- | --- |
102
102
  | Commands | Utilities, notes, reminders, polls, media, speech, weather, prayer times, and more — configurable from the panel |
103
- | Translation | `!translate` between Arabic and English, or into a language you name — with an AI engine (your active AI provider, with its own editable prompt) or Google's translation engine, plus summary, tone, explain, and detect options |
103
+ | Translation | `!translate` between Arabic and English, or into a language you name, with your active AI provider or Google translation (the official API with a key, or Google's public endpoint without one), plus summary, tone, explain, and detect options |
104
104
  | Group moderation | Welcome messages, anti-link, anti-spam, media rules, and forbidden words in one linked pipeline with a shared warning counter per member — at the limit the group removes the member automatically or flags them for admin review, guided by a per-group policy (Relaxed / Standard / Strict presets, warning limit, per-feature actions, warning expiry); warnings, roles, rules, and notes too |
105
105
  | AI agent | Pick Google Gemini, OpenAI / any OpenAI-compatible server, or Anthropic from the panel; each provider has its own endpoint, API key, and model, with tools for web search, page reading, memory, and role management |
106
106
  | Scheduling | One-off, daily, and weekly messages with durable jobs, delivery status, and manual retry |
@@ -135,6 +135,31 @@ Existing WhatsApp `*bold*` and `_italic_` text keeps its formatting.
135
135
 
136
136
  AI is optional. The rest of Levix works without an AI key.
137
137
 
138
+ #### Ask about Levix or request media
139
+
140
+ Ask `!ai How do I back up Levix?` for help grounded in this release's bundled
141
+ README, setup, Android, privacy and four-language command reference. The AI can
142
+ search those documents offline and cite the source section and version. Prose
143
+ guides are English; Arabic, Brazilian Portuguese and Latin American Spanish
144
+ queries can fall back to them. Missing evidence is reported instead of treating
145
+ future plans as installed features. Only the retrieval is offline: an AI answer
146
+ still uses your configured chat provider.
147
+
148
+ - `!ai Create an image of a cat on the moon` uses the same dedicated Gemini
149
+ image key and model as `!generate`.
150
+ - Reply to text with `!ai Read this aloud` for Google TTS, the same synthesizer
151
+ as `!tts`. FFmpeg makes a voice note; MP3 is the fallback.
152
+ - Reply to a voice message with `!ai Transcribe this voice note` for the same
153
+ Gemini/OpenAI-compatible transcription policy as `!stt`. The transcript then
154
+ becomes context for the selected chat provider's answer.
155
+
156
+ These actions retain the backing command's live permission and enabled state,
157
+ and results follow the configured reply router. They do not change your chat
158
+ provider. Image and transcription providers may charge against your own key;
159
+ Google TTS has no API-key charge. There is no music or sound-effect generator.
160
+ Natural-language media tools have bounded input, output, time and request rates;
161
+ a missing key, unsupported response or refused delivery is a failure.
162
+
138
163
  ### Persistent schedules and memory
139
164
 
140
165
  One-off and recurring schedules survive restarts and record their latest
@@ -148,9 +173,37 @@ The panel can start, stop, reconnect, and unlink WhatsApp while showing the
148
173
  actual state: idle, waiting for a scan, connected, reconnecting, or stopped.
149
174
  Reconnect attempts continue inside the bot even when no browser is open.
150
175
 
176
+ The Free account card on **Connection** shows your connected WhatsApp profile
177
+ picture, display name, verified phone number and About text. Missing or private
178
+ details use a neutral placeholder. Open the screen or use its refresh button;
179
+ stats polling does not query your profile. Profile lookups and images use a
180
+ short memory cache, and disconnecting clears the visible account details.
181
+
151
182
  An optional HTTP, HTTPS, or SOCKS5 proxy can route WhatsApp traffic, including
152
183
  media, without changing how the panel or AI connects.
153
184
 
185
+ ## Checking for updates
186
+
187
+ `!update` checks official release information and replies with the current
188
+ version and a release link. It is owner-only by default, with the same command
189
+ permission controls as other commands. Stable installations see stable releases;
190
+ beta installations can see a newer beta in their release line or a stable
191
+ release. An offline check leaves the bot running normally. Checks share a short
192
+ local cache and never download or install executable code.
193
+
194
+ Open **Settings → About Levix** or **Help → About Levix** to check manually,
195
+ read release notes, and open the official documentation, support, developer and
196
+ Leviro links. Google Play installations check through Play and offer a flexible
197
+ update: you choose when to download and when to restart. Other installations
198
+ open the official GitHub release so you can use your normal installation method.
199
+ Rating and GitHub stars are optional. Play review prompts have a separate local
200
+ switch that is off by default; Google controls whether a review card appears.
201
+
202
+ The optional **Powered by Levix** watermark stays off by default. Its existing
203
+ Free switch is retained. When enabled, it excludes exact output, raw transcripts,
204
+ forwarded text, short links, files and security messages. Active Plus extensions
205
+ can hide it through the existing entitlement-controlled hook.
206
+
154
207
  ## CLI
155
208
 
156
209
  ```text
@@ -186,7 +239,8 @@ start.
186
239
 
187
240
  ## Architecture
188
241
 
189
- - **Node.js 24+** with ES modules and CommonJS where needed.
242
+ - **Node.js 24** with ES modules and CommonJS where needed. A newer Node starts with a warning that it
243
+ is not officially supported.
190
244
  - **Baileys v7** for the WhatsApp protocol engine, LID support, and phone pairing codes.
191
245
  - **`node:sqlite`** for a zero-dependency, single-file datastore.
192
246
  - **React + Vite Control Panel** (`frontend/`) with TypeScript, native RTL Arabic / English internationalization, Lucide icons, responsive drawer, modal dialogs, and real-time Socket.IO synchronization.
package/SETUP.md CHANGED
@@ -12,8 +12,9 @@ guide anywhere tells you to create a `.env` file, it is out of date.
12
12
  ## What you need
13
13
 
14
14
  - A computer or a small server that stays on. A Raspberry Pi is enough.
15
- - **Node.js 24 or newer** — [nodejs.org](https://nodejs.org), pick the LTS
16
- button. (Or skip Node entirely and use Docker, below.)
15
+ - **Node.js 24** — [nodejs.org](https://nodejs.org), pick the Node 24 LTS
16
+ build. A newer Node also starts, with a warning that only Node 24 is
17
+ supported. (Or skip Node entirely and use Docker, below.)
17
18
  - A phone with WhatsApp, to scan the QR once.
18
19
 
19
20
  Levix stores everything in one file using SQLite, which Node 24 includes.
@@ -72,6 +73,10 @@ it off anywhere.
72
73
 
73
74
  That's the whole setup. Keep the terminal open, or see *Keeping it running*.
74
75
 
76
+ If the panel files are missing, the basic English setup and login forms still work.
77
+ Run `npm run build:frontend` from a source checkout or reinstall Levix to restore
78
+ the full panel and QR screen.
79
+
75
80
  ---
76
81
 
77
82
  ## With Docker instead
@@ -224,9 +229,56 @@ levix where
224
229
  - running from a git clone: `./data` inside the clone
225
230
  - Docker: the `levix-data` volume
226
231
 
227
- **Backing up** means copying that directory. **Moving to another machine**
228
- means copying it across and starting Levix there — including the WhatsApp
229
- session, so you don't even rescan the QR.
232
+ A copy of this directory, taken while Levix is stopped, is a full copy: it holds
233
+ the WhatsApp pairing and the encryption key, so keep it private. On another
234
+ device WhatsApp may still ask you to pair again. For an encrypted backup without
235
+ the pairing, use **Settings → Backup** (below).
236
+
237
+ ## Back up and restore
238
+
239
+ Open **Settings → Backup**. Create a backup with a password of at least 12
240
+ characters and save the `.levixbak` file. Keep the password safe: Levix cannot
241
+ recover it. To restore, upload the file, enter its backup password, review the
242
+ preview, then confirm with your panel password.
243
+
244
+ The preview lists what the restore changes: settings and API keys that are
245
+ added, replaced or unchanged, the ones the backup does not hold (they stay as
246
+ they are), the AI persona, and the WhatsApp account data. When the restore would
247
+ replace or remove something this install already has, tick the confirmation
248
+ before **Confirm restore** is enabled. Restore writes only what the backup
249
+ holds: a setting, an API key or a persona missing from the backup keeps its
250
+ current value. It keeps this install's panel password, recovery email, session
251
+ key, device settings and encryption key. WhatsApp pairing is never in the backup;
252
+ pair the account again by hand. Conversations, AI memory, stickers, schedules,
253
+ roles and group data activate only when the same WhatsApp account connects.
254
+ If a different account connects, the Backup screen shows **waiting account
255
+ data**. You can later pair the matching account or choose **Discard** to remove
256
+ the waiting data.
257
+
258
+ ## Going back to 4.9.x
259
+
260
+ Starting 4.9.x on the same data after 5.0.0 has run is not supported.
261
+ 4.9.x does not refuse that database. It runs and ignores the newer data.
262
+ Writes from 4.9.x can leave that data inconsistent. A later 5.0.0 start
263
+ does not repair it.
264
+
265
+ Stop Levix. Keep a copy of the whole data directory first. Copy
266
+ `backups/pre-migration/levix-v10-<time>.db` (first 5.0.0 start, from
267
+ 4.9.2) over `levix.db`. Keep your own copy of that file, because later
268
+ upgrades remove older copies. Delete `levix.db-wal` and `levix.db-shm`.
269
+ Start 4.9.x.
270
+
271
+ The setup page asks for a new panel password. From another machine it
272
+ also asks for the setup code printed in the terminal. Enter your API
273
+ keys again. If you use a WhatsApp proxy with a password, enter the proxy
274
+ password again in **Settings** before you press **Start** on **Connection**.
275
+ Pair the same WhatsApp account on the **Connection** screen.
276
+ Anything written after the upgrade is not in that copy.
277
+
278
+ A **Settings → Backup** `.levixbak` file is a 5.0.0 backup. 4.9.x cannot
279
+ restore it. Google Play cannot downgrade an installed app. A GitHub APK
280
+ can go back only after you uninstall, which deletes the app data. Do not
281
+ start a 4.9.x Docker image on a volume 5.0.0 has used. Pin the image tag.
230
282
 
231
283
  ---
232
284
 
@@ -267,8 +319,12 @@ Then start it again and pick a new one. The WhatsApp link is untouched.
267
319
  phone was offline for a long time. Open the panel; if it asks for a QR, scan it
268
320
  again.
269
321
 
270
- **"Levix needs Node 24 or newer"** — your Node is older. Install the LTS build
271
- from [nodejs.org](https://nodejs.org) and try again.
322
+ **"levix-bot needs Node 24"** — your Node is older. Install the Node 24 LTS
323
+ build from [nodejs.org](https://nodejs.org) and try again.
324
+
325
+ **"Warning: Node 26… is newer than Node 24"** — Levix still runs. Only Node 24
326
+ is built and tested, so help with problems on a newer Node is best effort.
327
+ Install Node 24 LTS for a supported setup.
272
328
 
273
329
  **Start over completely** — stop the bot, delete the data directory
274
330
  (`levix where` prints it), start it again. That wipes everything: settings,
package/app.cjs CHANGED
@@ -21,6 +21,7 @@ const { assetPath } = require("./src/config/paths.cjs");
21
21
  const brand = require("./src/config/brand.cjs");
22
22
  const settings = require("./src/config/settings.cjs");
23
23
  const secrets = require("./src/config/secrets.cjs");
24
+ const { renderFallbackPage } = require("./src/panel/fallback-page.cjs");
24
25
  const { PanelSessionStore } = require("./src/panel/session-store.cjs");
25
26
  const { getQrCode } = require("./src/utils/storage.cjs");
26
27
  const { clientAddress, isDirectLocalRequest } = require("./src/utils/requestOrigin.cjs");
@@ -143,17 +144,20 @@ function noStore(req, res, next) {
143
144
  next();
144
145
  }
145
146
 
147
+ // Android keeps FLAG_SECURE on unless the document just rendered says capture
148
+ // is allowed. The value is the exact token "allow": the host trims it and
149
+ // rejects any other text, including a repeated header joined as "allow, allow".
150
+ function allowScreenCapture(res) {
151
+ res.set("X-Levix-Screen-Capture", "allow");
152
+ }
153
+
146
154
  function requireLoginPage(req, res, next) {
147
155
  if (isPanelSessionValid(req.session)) return next();
148
156
  return res.redirect("/");
149
157
  }
150
158
 
151
- // Bind the engine by value rather than letting express require("ejs") lazily
152
- // by name: a packaged build has no module resolver to answer that call.
153
- app.engine("ejs", require("ejs").__express);
154
- app.set("view engine", "ejs");
155
- app.set("views", assetPath("views"));
156
- // Name, tagline and credit for every template. Frozen — see brand.cjs.
159
+ // Name, tagline and credit for the gateway state, the dashboard shell and the
160
+ // fallback page. Frozen — see brand.cjs.
157
161
  // The one addition is the version from package.json, so the panel shows the
158
162
  // shipped version instead of a string frozen in the frontend bundle.
159
163
  const pkg = require("./package.json");
@@ -219,17 +223,71 @@ function isLocalRequest(req) {
219
223
  return isDirectLocalRequest(req, { proxyConfigured: PROXY_CONFIGURED });
220
224
  }
221
225
 
226
+ // The code-owned static page from src/panel/fallback-page.cjs, for a build
227
+ // that is missing. `view` is "login", "setup", "qr" or "panel".
228
+ function sendFallback(res, view, locals, status = 200) {
229
+ const html = renderFallbackPage({
230
+ page: view,
231
+ brandName: app.locals.brand.name,
232
+ error: locals.error || null,
233
+ needsCode: view === "setup" && locals.needsCode === true,
234
+ minLength: locals.minLength ?? secrets.MIN_PASSWORD_LENGTH,
235
+ });
236
+ return res.status(status).type("html").send(html);
237
+ }
238
+
239
+ // The React shell when the frontend build exists; otherwise the fallback page.
240
+ // The status code is the same either way.
241
+ function renderGateway(req, res, view, locals, status = 200) {
242
+ const shell = assetPath("public", "dashboard", "gateway.html");
243
+ if (!fs.existsSync(shell)) return sendFallback(res, view, locals, status);
244
+ const state = {
245
+ page: view,
246
+ error: locals.error ? { code: locals.errorCode || null, message: locals.error } : null,
247
+ minLength: locals.minLength ?? secrets.MIN_PASSWORD_LENGTH,
248
+ needsCode: view === "setup" && locals.needsCode === true,
249
+ recoveryEmail: view === "login" ? (locals.recoveryEmail ?? null) : null,
250
+ recoveryEmailVerified: view === "login" && locals.recoveryEmailVerified === true,
251
+ ...(view === "qr" ? { qr: locals.qr } : {}),
252
+ brand: app.locals.brand,
253
+ };
254
+ const json = JSON.stringify(state).replace(
255
+ /[<>&\u2028\u2029]/g,
256
+ (char) =>
257
+ ({
258
+ "<": "\\u003c",
259
+ ">": "\\u003e",
260
+ "&": "\\u0026",
261
+ "\u2028": "\\u2028",
262
+ "\u2029": "\\u2029",
263
+ })[char],
264
+ );
265
+ const html = fs
266
+ .readFileSync(shell, "utf8")
267
+ .replace(
268
+ "</head>",
269
+ () => `<script id="levix-gateway-state" type="application/json">${json}</script></head>`,
270
+ );
271
+ return res.status(status).type("html").send(html);
272
+ }
273
+
222
274
  // `error` is { code, message } or null: `message` is the English the page
223
- // renders by default, `code` is the stable key public/gateway-i18n.js turns
224
- // into the reader's language. A string is still accepted for callers that
275
+ // renders by default, `code` is the stable key the React gateway turns into
276
+ // the reader's language. A string is still accepted for callers that
225
277
  // have no code to offer.
226
278
  function renderSetup(req, res, error, status = 200) {
227
- res.status(status).render("setup", {
228
- error: error ? error.message || error : null,
229
- errorCode: error?.code ?? null,
230
- needsCode: !isLocalRequest(req),
231
- minLength: secrets.MIN_PASSWORD_LENGTH,
232
- });
279
+ renderGateway(
280
+ req,
281
+ res,
282
+ "setup",
283
+ {
284
+ error: error ? error.message || error : null,
285
+ errorCode: error?.code ?? null,
286
+ needsCode: !isLocalRequest(req),
287
+ minLength: secrets.MIN_PASSWORD_LENGTH,
288
+ },
289
+ status,
290
+ );
233
291
  }
234
292
 
235
293
  app.get("/setup", noStore, (req, res) => {
@@ -237,19 +295,24 @@ app.get("/setup", noStore, (req, res) => {
237
295
  renderSetup(req, res, null);
238
296
  });
239
297
 
298
+ function gatewayError(req, res, status, error, render, retryAfter) {
299
+ if (req.accepts(["html", "json"]) !== "json") return render();
300
+ res.set("Cache-Control", "no-store");
301
+ return res.status(status).json({ ok: false, error, ...(retryAfter ? { retryAfter } : {}) });
302
+ }
303
+
240
304
  app.post("/setup", (req, res, next) => {
241
- if (secrets.hasDashboardPassword()) return res.redirect("/");
305
+ const json = req.accepts(["html", "json"]) === "json";
306
+ if (json) res.set("Cache-Control", "no-store");
307
+ if (secrets.hasDashboardPassword())
308
+ return json ? res.status(409).json({ ok: false, redirect: "/" }) : res.redirect("/");
242
309
 
243
310
  const peer = clientAddress(req);
244
311
  const retryAfter = blockedFor(peer);
245
312
  if (retryAfter) {
246
313
  res.set("Retry-After", String(retryAfter));
247
- return renderSetup(
248
- req,
249
- res,
250
- { code: "tooManyAttempts", message: "Too many attempts. Try again later." },
251
- 429,
252
- );
314
+ const error = { code: "tooManyAttempts", message: "Too many attempts. Try again later." };
315
+ return gatewayError(req, res, 429, error, () => renderSetup(req, res, error, 429), retryAfter);
253
316
  }
254
317
 
255
318
  const { password, confirm, code } = req.body || {};
@@ -257,22 +320,20 @@ app.post("/setup", (req, res, next) => {
257
320
  if (!isLocalRequest(req) && !secrets.setupCodeMatches(code)) {
258
321
  recordFailure(peer);
259
322
  logger.warn({ ip: peer }, "[dashboard] Setup attempted with a wrong code");
260
- return renderSetup(req, res, { code: "wrongSetupCode", message: "Wrong setup code." }, 401);
323
+ const error = { code: "wrongSetupCode", message: "Wrong setup code." };
324
+ return gatewayError(req, res, 401, error, () => renderSetup(req, res, error, 401));
261
325
  }
262
326
 
263
327
  if (password !== confirm) {
264
- return renderSetup(
265
- req,
266
- res,
267
- { code: "passwordMismatch", message: "The two passwords don't match." },
268
- 400,
269
- );
328
+ const error = { code: "passwordMismatch", message: "The two passwords don't match." };
329
+ return gatewayError(req, res, 400, error, () => renderSetup(req, res, error, 400));
270
330
  }
271
331
 
272
332
  try {
273
333
  secrets.setDashboardPassword(password);
274
334
  } catch (error) {
275
- return renderSetup(req, res, { code: "invalidPassword", message: error.message }, 400);
335
+ const detail = { code: "invalidPassword", message: error.message };
336
+ return gatewayError(req, res, 400, detail, () => renderSetup(req, res, detail, 400));
276
337
  }
277
338
 
278
339
  clearAttempts(peer);
@@ -283,7 +344,8 @@ app.post("/setup", (req, res, next) => {
283
344
  stampPanelSession(req.session);
284
345
  req.session.save((saveErr) => {
285
346
  if (saveErr) return next(saveErr);
286
- res.redirect(303, "/");
347
+ if (json) return res.status(200).json({ ok: true, redirect: "/" });
348
+ return res.redirect(303, "/");
287
349
  });
288
350
  });
289
351
  });
@@ -314,6 +376,8 @@ function loginPageLocals(error, errorCode) {
314
376
  app.get("/", noStore, (req, res) => {
315
377
  if (!secrets.hasDashboardPassword()) return res.redirect("/setup");
316
378
  if (isPanelSessionValid(req.session)) {
379
+ // Both signed-in documents: built index.html, and the static panel
380
+ // fallback (sendFallback "panel") when that file is absent.
317
381
  const dashboardHtmlPath = path.join(assetPath("public"), "dashboard", "index.html");
318
382
  if (fs.existsSync(dashboardHtmlPath)) {
319
383
  let html = fs.readFileSync(dashboardHtmlPath, "utf8");
@@ -324,39 +388,55 @@ app.get("/", noStore, (req, res) => {
324
388
  `<script>window.__BRAND__ = ${JSON.stringify(app.locals.brand)};</script></head>`,
325
389
  )
326
390
  .replace("</body>", `${credits}</body>`);
391
+ allowScreenCapture(res);
327
392
  return res.type("html").send(html);
328
393
  }
329
- return res.render("dashboard");
394
+ allowScreenCapture(res);
395
+ return sendFallback(res, "panel", {});
330
396
  }
331
- return res.render("login", loginPageLocals(null, null));
397
+ return renderGateway(req, res, "login", loginPageLocals(null, null));
332
398
  });
333
399
 
334
400
  app.get("/login", noStore, (req, res) => {
335
401
  if (!secrets.hasDashboardPassword()) return res.redirect("/setup");
336
402
  if (isPanelSessionValid(req.session)) return res.redirect("/");
337
- return res.render("login", loginPageLocals(null, null));
403
+ return renderGateway(req, res, "login", loginPageLocals(null, null));
338
404
  });
339
405
 
340
406
  app.post("/login", (req, res, next) => {
341
- if (!secrets.hasDashboardPassword()) return res.redirect("/setup");
407
+ const json = req.accepts(["html", "json"]) === "json";
408
+ if (json) res.set("Cache-Control", "no-store");
409
+ if (!secrets.hasDashboardPassword())
410
+ return json ? res.status(409).json({ ok: false, redirect: "/setup" }) : res.redirect("/setup");
342
411
 
343
412
  const peer = clientAddress(req);
344
413
  const retryAfter = blockedFor(peer);
345
414
  if (retryAfter) {
346
415
  res.set("Retry-After", String(retryAfter));
347
- return res
348
- .status(429)
349
- .render("login", loginPageLocals("Too many attempts. Try again later.", "tooManyAttempts"));
416
+ const error = { code: "tooManyAttempts", message: "Too many attempts. Try again later." };
417
+ return gatewayError(
418
+ req,
419
+ res,
420
+ 429,
421
+ error,
422
+ () => renderGateway(req, res, "login", loginPageLocals(error.message, error.code), 429),
423
+ retryAfter,
424
+ );
350
425
  }
351
426
 
352
427
  if (!secrets.verifyDashboardPassword(req.body?.password)) {
353
428
  recordFailure(peer);
354
429
  logger.warn({ ip: peer }, "[dashboard] Failed login attempt");
355
- return res.status(401).render("login", {
356
- ...loginPageLocals(null, null),
357
- error: "Incorrect Password",
358
- errorCode: "incorrectPassword",
359
- });
430
+ const error = { code: "incorrectPassword", message: "Incorrect Password" };
431
+ return gatewayError(req, res, 401, error, () =>
432
+ renderGateway(
433
+ req,
434
+ res,
435
+ "login",
436
+ { ...loginPageLocals(null, null), error: error.message, errorCode: error.code },
437
+ 401,
438
+ ),
439
+ );
360
440
  }
361
441
 
362
442
  clearAttempts(peer);
@@ -367,7 +447,8 @@ app.post("/login", (req, res, next) => {
367
447
  stampPanelSession(req.session);
368
448
  req.session.save((saveErr) => {
369
449
  if (saveErr) return next(saveErr);
370
- res.redirect(303, "/");
450
+ if (json) return res.status(200).json({ ok: true, redirect: "/" });
451
+ return res.redirect(303, "/");
371
452
  });
372
453
  });
373
454
  });
@@ -463,7 +544,8 @@ app.post("/logout", (req, res, next) => {
463
544
 
464
545
  app.get("/qr", requireLoginPage, noStore, (req, res) => {
465
546
  const qr = getQrCode();
466
- res.render("qr", { qr: qr || "" });
547
+ allowScreenCapture(res);
548
+ renderGateway(req, res, "qr", { qr: qr || "" });
467
549
  });
468
550
 
469
551
  // Unlink / restart / everything else live on the dashboard API
@@ -478,9 +560,39 @@ function installFinalHandlers() {
478
560
 
479
561
  // eslint-disable-next-line no-unused-vars
480
562
  app.use((err, req, res, next) => {
481
- logger.error({ err, method: req.method, path: req.path }, "[http] Unhandled error");
563
+ const status = err?.statusCode || err?.status || 500;
564
+ const isSyntax =
565
+ err instanceof SyntaxError ||
566
+ err?.name === "SyntaxError" ||
567
+ err?.type === "entity.parse.failed" ||
568
+ (typeof err?.message === "string" && err.message.includes("is not valid JSON"));
569
+
570
+ if (isSyntax) {
571
+ logger.error(
572
+ { type: err?.name || "SyntaxError", status, method: req.method, path: req.path },
573
+ "[http] Unhandled error",
574
+ );
575
+ } else {
576
+ if (err && typeof err === "object") {
577
+ if ("body" in err) {
578
+ try {
579
+ delete err.body;
580
+ } catch {
581
+ err.body = undefined;
582
+ }
583
+ }
584
+ if ("rawBody" in err) {
585
+ try {
586
+ delete err.rawBody;
587
+ } catch {
588
+ err.rawBody = undefined;
589
+ }
590
+ }
591
+ }
592
+ logger.error({ err, method: req.method, path: req.path }, "[http] Unhandled error");
593
+ }
482
594
  if (res.headersSent) return;
483
- res.status(err.statusCode || 500).json({ error: "Internal server error" });
595
+ res.status(status).json({ error: "Internal server error" });
484
596
  });
485
597
  }
486
598
 
@@ -495,4 +607,5 @@ module.exports = {
495
607
  installFinalHandlers,
496
608
  disconnectInvalidPanelSockets,
497
609
  disconnectSessionSockets,
610
+ renderGateway,
498
611
  };
package/deploy/install.sh CHANGED
@@ -11,16 +11,16 @@
11
11
  # What it does, in order — read it before you pipe it into a shell, as you
12
12
  # should with any script that asks for sudo:
13
13
  #
14
- # 1. makes sure Node 24+ is available (bootstraps it on Debian/Ubuntu)
14
+ # 1. makes sure Node 24 is available (bootstraps it on Debian/Ubuntu)
15
15
  # 2. installs the `levix` command globally from the `levix-bot` npm package
16
16
  # 3. creates a `levix` system user and /var/lib/levix for its data
17
17
  # 4. installs the systemd unit, pointed at the levix it just installed
18
18
  # 5. enables it, starts it, and prints where to go next
19
19
  # 6. offers — but never assumes — to connect a domain
20
20
  #
21
- # On a machine that already has Node 24+, the installer does not touch the
22
- # system package manager. On a fresh Debian/Ubuntu machine it also installs
23
- # Node.js from NodeSource, which adds its signing key and APT source.
21
+ # A machine that already has Node 24 or newer keeps it (a newer major gets a
22
+ # warning, because only Node 24 is supported). A fresh Debian/Ubuntu machine
23
+ # gets Node 24 from NodeSource, which adds its signing key and APT source.
24
24
  #
25
25
  # Levix itself writes exactly three things outside npm's own prefix: the system
26
26
  # user, /var/lib/levix, and /etc/systemd/system/levix.service. It never touches
@@ -40,6 +40,7 @@ PORT=3001
40
40
 
41
41
  say() { printf '\n %s\n' "$*"; }
42
42
  die() { printf '\n error: %s\n\n' "$*" >&2; exit 1; }
43
+ warn() { printf '\n warning: %s\n' "$*" >&2; }
43
44
 
44
45
  sudo_if_needed() {
45
46
  if [ "$(id -u)" -eq 0 ]; then
@@ -155,7 +156,11 @@ command -v npm >/dev/null 2>&1 ||
155
156
  command -v systemctl >/dev/null 2>&1 ||
156
157
  die "This script installs a systemd service, and systemd isn't here. Run 'npm i -g ${PACKAGE}' and start 'levix' yourself."
157
158
 
158
- say "Node $(node -v) — good."
159
+ if [ "$NODE_MAJOR" -gt "$MIN_NODE_MAJOR" ]; then
160
+ warn "Node $(node -v) is newer than Node ${MIN_NODE_MAJOR}, the version Levix is built and tested on. Levix will run, but this Node version is not officially supported, and help with problems on it is best effort."
161
+ else
162
+ say "Node $(node -v) — good."
163
+ fi
159
164
 
160
165
  # --- 2. The package --------------------------------------------------------
161
166
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "levix-bot",
3
- "version": "4.9.2",
3
+ "version": "5.0.0",
4
4
  "description": "A self-hosted personal WhatsApp bot with an AI agent, group moderation and a web control panel.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -11,6 +11,10 @@
11
11
  "format": "biome format --write .",
12
12
  "check": "biome check .",
13
13
  "check:fix": "biome check --write .",
14
+ "i18n:build": "node scripts/i18n.mjs build",
15
+ "i18n:check": "node scripts/i18n.mjs check",
16
+ "docs:build": "node scripts/build-ai-docs.mjs build",
17
+ "docs:check": "node scripts/build-ai-docs.mjs check",
14
18
  "brand:assets": "node scripts/build-brand-assets.mjs",
15
19
  "build": "npm run build:frontend",
16
20
  "build:frontend": "node scripts/build-frontend.mjs",
@@ -19,7 +23,8 @@
19
23
  "validate:tarball": "node scripts/validate-tarball.mjs",
20
24
  "validate:sea": "node scripts/validate-sea.mjs",
21
25
  "validate:docker": "bash scripts/validate-docker.sh",
22
- "validate:recovery": "node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON scripts/validate-recovery-contract.mjs"
26
+ "validate:recovery": "node --disable-warning=MODULE_TYPELESS_PACKAGE_JSON scripts/validate-recovery-contract.mjs",
27
+ "scan:public": "node scripts/scan-public-artifacts.mjs"
23
28
  },
24
29
  "keywords": [
25
30
  "whatsapp",
@@ -37,11 +42,10 @@
37
42
  "license": "MIT",
38
43
  "type": "module",
39
44
  "dependencies": {
40
- "@google/genai": "^2.19.0",
45
+ "@google/genai": "^3.0.0",
41
46
  "@sefinek/google-tts-api": "^2.1.15",
42
47
  "@whiskeysockets/baileys": "7.0.0-rc14",
43
48
  "axios": "^1.9.0",
44
- "ejs": "^7.0.1",
45
49
  "express": "^5.1.0",
46
50
  "express-session": "^1.18.1",
47
51
  "ffmpeg-static": "^5.3.0",
@@ -73,7 +77,7 @@
73
77
  "url": "https://github.com/Abdodiab2005/levix/issues"
74
78
  },
75
79
  "engines": {
76
- "node": ">=24"
80
+ "node": ">=24 <25"
77
81
  },
78
82
  "devDependencies": {
79
83
  "@biomejs/biome": "^2.5.14",
@@ -87,7 +91,6 @@
87
91
  "files": [
88
92
  "bin/",
89
93
  "src/",
90
- "views/",
91
94
  "public/",
92
95
  "deploy/",
93
96
  "app.cjs",