From 33289bb5037f0845821e55bef3716a0015754dbd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:57:24 +0000 Subject: [PATCH 1/2] Initial plan From c7a430ebc93a74f4cc3bbdf6105c29baff41d020 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 15:01:48 +0000 Subject: [PATCH 2/2] Fix: auto-install npm deps to resolve 'Cannot find module whatsapp-web.js' error Co-authored-by: eeea2222 <209839587+eeea2222@users.noreply.github.com> --- .gitignore | 33 +++++++++++++++++++++++++++++++++ app.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7895b3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Node.js dependencies +node_modules/ +package-lock.json +npm-debug.log* + +# WhatsApp session data +.wwebjs_auth/ +.wwebjs_cache/ + +# Python +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +*.egg-info/ +dist/ +build/ + +# App data +chat_history.db +chat_history_archive.db +uploads/ +Sandbox/ +identity.txt + +# Environment +.env +.env.* + +# OS +.DS_Store +Thumbs.db diff --git a/app.py b/app.py index ef2c9c7..3b8fa51 100644 --- a/app.py +++ b/app.py @@ -3626,12 +3626,41 @@ def get_thumb_route(img_hash: str): # YARDIMCI FONKSİYONLAR # ═══════════════════════════════════════════════════════════════ +def ensure_npm_deps() -> None: + """node_modules eksikse npm install çalıştır.""" + node_modules = APP_DIR / "node_modules" + pkg_json = APP_DIR / "package.json" + if not pkg_json.exists(): + return + if not node_modules.exists(): + log.info("node_modules bulunamadı, 'npm install' çalıştırılıyor…") + try: + result = subprocess.run( + ['npm', 'install'], + cwd=str(APP_DIR), + capture_output=True, + text=True, + timeout=300, + ) + if result.returncode == 0: + log.info("npm install başarılı.") + else: + output = (result.stdout.strip() + "\n" + result.stderr.strip()).strip() + log.error(f"npm install başarısız (kod {result.returncode}): {output}") + except FileNotFoundError: + log.error("npm bulunamadı. Node.js kurulu olduğundan emin olun.") + except subprocess.TimeoutExpired: + log.error("npm install zaman aşımına uğradı.") + + def ensure_bot_file() -> Path: - """whatsapp_bot.js dosyasının var olduğunu doğrula.""" + """whatsapp_bot.js dosyasının var olduğunu ve npm bağımlılıklarının kurulu olduğunu doğrula.""" bot_path = APP_DIR / "whatsapp_bot.js" if not bot_path.exists(): log.error(f"whatsapp_bot.js bulunamadı: {bot_path}") log.error("Bot başlatılamıyor. Dosyayı proje dizinine kopyalayın.") + else: + ensure_npm_deps() return bot_path