Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
31 changes: 30 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Comment on lines +3635 to +3644

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure_npm_deps() can be reached from the threaded Flask server (/api/bot/start) and potentially by multiple gunicorn workers; as written, concurrent calls can launch multiple npm install processes against the same directory, risking corrupted/partial installs. Consider adding a process-level/thread-level lock (and ideally an inter-process file lock) around the install path and re-checking node_modules after acquiring the lock.

Copilot uses AI. Check for mistakes.
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ı.")
Comment on lines +3645 to +3653

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure_npm_deps() logs npm install failures (non-zero exit, timeout, or missing npm) but still returns normally, so callers will proceed to start the bot and hit the same “Cannot find module …” crash. Consider making this function fail-fast (raise an exception or return a boolean that ensure_bot_file()/bot_start checks) so startup is aborted when dependencies cannot be installed.

Copilot uses AI. Check for mistakes.


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()
Comment on lines 3660 to +3663

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure_bot_file() logs that whatsapp_bot.js is missing but still returns bot_path, and /api/bot/start calls bot.start() unconditionally afterward. This leads to a confusing follow-on failure; consider raising FileNotFoundError (or another explicit exception) when the file is absent so callers can stop early and return a clear error.

Suggested change
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()
msg = f"whatsapp_bot.js bulunamadı: {bot_path}"
log.error(msg)
log.error("Bot başlatılamıyor. Dosyayı proje dizinine kopyalayın.")
raise FileNotFoundError(msg)
ensure_npm_deps()

Copilot uses AI. Check for mistakes.
return bot_path


Expand Down
Loading