logger

Self-hosted WhatsApp logger us...
Log | Files | Refs | README | LICENSE

commit 1cbbb9d583cfd937b3e704e368c50fbf4f7b2881
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Fri, 26 Sep 2025 17:18:36 +0530

Add files via upload
Diffstat:
AData/Procfile | 3+++
AData/message_log.json | 20++++++++++++++++++++
AMain.py | 152+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ARequirements.txt | 18++++++++++++++++++
Aai.py | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abaileys_auth_info/app-state-sync-key-AAAAADHR.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHS.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHT.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHU.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHV.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHW.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHX.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHY.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHZ.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHa.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHb.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHc.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHd.json | 2++
Abaileys_auth_info/app-state-sync-key-AAAAADHe.json | 2++
Abaileys_auth_info/creds.json | 2++
Abaileys_auth_info/pre-key-1.json | 2++
Abaileys_auth_info/pre-key-10.json | 2++
Abaileys_auth_info/pre-key-11.json | 2++
Abaileys_auth_info/pre-key-12.json | 2++
Abaileys_auth_info/pre-key-13.json | 2++
Abaileys_auth_info/pre-key-14.json | 2++
Abaileys_auth_info/pre-key-15.json | 2++
Abaileys_auth_info/pre-key-16.json | 2++
Abaileys_auth_info/pre-key-17.json | 2++
Abaileys_auth_info/pre-key-18.json | 2++
Abaileys_auth_info/pre-key-19.json | 2++
Abaileys_auth_info/pre-key-2.json | 2++
Abaileys_auth_info/pre-key-20.json | 2++
Abaileys_auth_info/pre-key-21.json | 2++
Abaileys_auth_info/pre-key-22.json | 2++
Abaileys_auth_info/pre-key-23.json | 2++
Abaileys_auth_info/pre-key-25.json | 2++
Abaileys_auth_info/pre-key-26.json | 2++
Abaileys_auth_info/pre-key-27.json | 2++
Abaileys_auth_info/pre-key-28.json | 2++
Abaileys_auth_info/pre-key-29.json | 2++
Abaileys_auth_info/pre-key-3.json | 2++
Abaileys_auth_info/pre-key-30.json | 2++
Abaileys_auth_info/pre-key-4.json | 2++
Abaileys_auth_info/pre-key-5.json | 2++
Abaileys_auth_info/pre-key-6.json | 2++
Abaileys_auth_info/pre-key-7.json | 2++
Abaileys_auth_info/pre-key-8.json | 2++
Abaileys_auth_info/pre-key-9.json | 2++
Abaileys_auth_info/session-917278779512.0.json | 2++
Abaileys_auth_info/session-917439454418.0.json | 2++
Aindex.js | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apackage.json | 20++++++++++++++++++++
53 files changed, 498 insertions(+), 0 deletions(-)

diff --git a/Data/Procfile b/Data/Procfile @@ -0,0 +1,2 @@ +web: python Main.py +bot: node index.js+ \ No newline at end of file diff --git a/Data/message_log.json b/Data/message_log.json @@ -0,0 +1,19 @@ +[ + { + "timestamp": "2025-09-26 17:05:34", + "sender": "917439454418@s.whatsapp.net", + "content": "Hi" + }, + { + "id": "AC3E680C66B7EE67BECDB0DEE33982D1", + "timestamp": "2025-09-26 17:10:19", + "sender": "917439454418@s.whatsapp.net", + "content": "Hello" + }, + { + "id": "ACCDB6B50D89550C3C30F11493C69537", + "timestamp": "2025-09-26 17:10:46", + "sender": "917439454418@s.whatsapp.net", + "content": "How are you?" + } +]+ \ No newline at end of file diff --git a/Main.py b/Main.py @@ -0,0 +1,152 @@ +import os +import json +from datetime import datetime +from flask import Flask, request, jsonify, render_template_string + +# Initialize a Flask web application +app = Flask(__name__) + +# Define the log file path +log_dir = "Data" +log_file = os.path.join(log_dir, "message_log.json") + +# Ensure the Data directory exists +if not os.path.exists(log_dir): + os.makedirs(log_dir) + +# Ensure the log file exists and is a valid JSON array +if not os.path.exists(log_file) or os.path.getsize(log_file) == 0: + with open(log_file, "w", encoding='utf-8') as f: + f.write("[]") + +def log_message(sender_id, message_content, message_id): + """ + Logs a new message to a JSON file. + Each message is stored with a timestamp, sender ID, content, and a unique message ID. + """ + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + message_entry = { + "id": message_id, + "timestamp": timestamp, + "sender": sender_id, + "content": message_content + } + + # Read existing log or create a new one + try: + with open(log_file, "r", encoding='utf-8') as f: + log_data = json.load(f) + except (FileNotFoundError, json.JSONDecodeError): + log_data = [] + + # Append the new message entry and save + log_data.append(message_entry) + with open(log_file, "w", encoding='utf-8') as f: + json.dump(log_data, f, indent=4) + print(f"Logged message from {sender_id} with ID {message_id}") + +def log_edit_message(message_id, new_content): + """ + Updates an existing message entry in the log file. + """ + try: + with open(log_file, "r", encoding='utf-8') as f: + log_data = json.load(f) + except (FileNotFoundError, json.JSONDecodeError): + return + + updated_message = None + for entry in log_data: + if entry["id"] == message_id: + entry["content"] = f"(EDITED) {new_content}" + entry["timestamp"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + updated_message = entry + break + + if updated_message: + with open(log_file, "w", encoding='utf-8') as f: + json.dump(log_data, f, indent=4) + print(f"Updated message with ID {message_id}") + else: + print(f"Message with ID {message_id} not found, logging a new entry.") + log_message("Edited Message", new_content, message_id) + + +@app.route("/health", methods=["GET"]) +def health_check(): + """ + Provides a simple health check endpoint. + Returns a 200 OK status for services like UptimeRobot. + """ + return "OK", 200 + +@app.route("/logs", methods=["GET"]) +def show_logs(): + """ + Displays all logged messages in a human-readable format. + """ + try: + with open(log_file, "r", encoding='utf-8') as f: + log_data = json.load(f) + except FileNotFoundError: + return render_template_string("<h1>No messages have been logged yet.</h1>") + except json.JSONDecodeError: + return render_template_string("<h1>No messages have been logged yet.</h1>") + + if not log_data: + return render_template_string("<h1>No messages have been logged yet.</h1>") + + # Create an HTML-formatted string for display + log_html = "<h1>Recorded Messages</h1>" + for entry in log_data: + log_html += f""" + <div style="border: 1px solid #ccc; margin: 10px; padding: 10px; border-radius: 8px;"> + <strong>Timestamp:</strong> {entry['timestamp']}<br> + <strong>From:</strong> {entry['sender']}<br> + <p><strong>Message:</strong><br>{entry['content']}</p> + </div> + """ + return render_template_string(log_html) + +@app.route("/save_message", methods=["POST"]) +def save_message(): + """ + Endpoint to receive messages from the Node.js client and log them. + """ + try: + data = request.json + sender = data.get("sender") + query = data.get("query") + message_id = data.get("message_id") + + if not sender or not query or not message_id: + return jsonify({"error": "Missing sender, query, or message_id"}), 400 + + log_message(sender, query, message_id) + return jsonify({"status": "success", "message": "Message logged successfully"}), 200 + + except Exception as e: + return jsonify({"error": str(e)}), 500 + +@app.route("/edit_message", methods=["POST"]) +def edit_message_route(): + """ + Endpoint to receive edited messages and update the log. + """ + try: + data = request.json + message_id = data.get("message_id") + new_content = data.get("new_content") + + if not message_id or not new_content: + return jsonify({"error": "Missing message_id or new_content"}), 400 + + log_edit_message(message_id, new_content) + return jsonify({"status": "success", "message": "Message updated successfully"}), 200 + + except Exception as e: + return jsonify({"error": str(e)}), 500 + +# Run the Flask app on a local server +if __name__ == "__main__": + app.run(host='0.0.0.0', port=5000) diff --git a/Requirements.txt b/Requirements.txt @@ -0,0 +1,18 @@ +python-dotenv +groq +elevenlabs +appopener +pywhatkit +bs4 +pillow +rich +requests +keyboard +cohere +googlesearch-python +selenium +mtranslate +pygame +edge-tts +PyQt5 +webdriver-manager diff --git a/ai.py b/ai.py @@ -0,0 +1,60 @@ +import sys +import requests +import json +import shutil +import os + +# Fix encoding for emojis/unicode output +sys.stdout.reconfigure(encoding='utf-8') + +def log_message(query, sender, message_id): + """ + Logs a new message to the Python logging server. + """ + try: + payload = { + "sender": sender, + "query": query, + "message_id": message_id + } + + response = requests.post("http://localhost:5000/save_message", json=payload) + response.raise_for_status() + print("✅ Message successfully sent to logging server.") + except requests.exceptions.RequestException as e: + print(f"❌ Error sending message to logging server: {e}") + except Exception as e: + print(f"❌ An unexpected error occurred: {e}") + +def edit_message(message_id, new_content): + """ + Sends an updated message to the Python logging server. + """ + try: + payload = { + "message_id": message_id, + "new_content": new_content + } + response = requests.post("http://localhost:5000/edit_message", json=payload) + response.raise_for_status() + print("✅ Edited message successfully sent to logging server.") + except requests.exceptions.RequestException as e: + print(f"❌ Error sending edited message to logging server: {e}") + except Exception as e: + print(f"❌ An unexpected error occurred: {e}") + +if len(sys.argv) < 4: + print("Invalid arguments. Usage: ai.py <query> <sender> <message_id> [action]") + sys.exit() + +query = sys.argv[1] +sender = sys.argv[2] +message_id = sys.argv[3] +action = sys.argv[4] if len(sys.argv) > 4 else "log" + +if action == "edit": + edit_message(message_id, query) +elif action == "log": + log_message(query, sender, message_id) +else: + print("Invalid action. Supported actions are 'log' and 'edit'.") diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHR.json b/baileys_auth_info/app-state-sync-key-AAAAADHR.json @@ -0,0 +1 @@ +{"keyData":"aAhwSAEIHQB1SPXdGoVhGlN7QjpEM+F2N9pVwXzevj8=","fingerprint":{"rawId":1264993325,"currentIndex":1,"deviceIndexes":[0,1]},"timestamp":"1740488510673"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHS.json b/baileys_auth_info/app-state-sync-key-AAAAADHS.json @@ -0,0 +1 @@ +{"keyData":"r+Ak+sb1XLy3pNFKgNcK6j3VaRmECt2oic0tERTX+XU=","fingerprint":{"rawId":1264993325,"currentIndex":2,"deviceIndexes":[0,1,2]},"timestamp":"1743137318195"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHT.json b/baileys_auth_info/app-state-sync-key-AAAAADHT.json @@ -0,0 +1 @@ +{"keyData":"mT2ZYCSFYta6mT37xuHitGhrgStkEMsSKU35SGyEKDY=","fingerprint":{"rawId":1264993325,"currentIndex":2,"deviceIndexes":[0,1]},"timestamp":"1745295429601"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHU.json b/baileys_auth_info/app-state-sync-key-AAAAADHU.json @@ -0,0 +1 @@ +{"keyData":"FLcVl6ARUCof3CteI9BVGXgzsPIHDWpDZOPk3adz5GQ=","fingerprint":{"rawId":1264993325,"currentIndex":2,"deviceIndexes":[0,1]},"timestamp":"1747887640509"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHV.json b/baileys_auth_info/app-state-sync-key-AAAAADHV.json @@ -0,0 +1 @@ +{"keyData":"dHMW7WwqSXj9DFF9X2RW4D0/HtOMdSz2cRrucISApKw=","fingerprint":{"rawId":1264993325,"currentIndex":2,"deviceIndexes":[0,1]},"timestamp":"0"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHW.json b/baileys_auth_info/app-state-sync-key-AAAAADHW.json @@ -0,0 +1 @@ +{"keyData":"yg5uYI6i+89EMFWBN3OVzcrowOcvFYSP2KbdWhE+nV0=","fingerprint":{"rawId":1264993325,"currentIndex":3,"deviceIndexes":[0,1]},"timestamp":"0"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHX.json b/baileys_auth_info/app-state-sync-key-AAAAADHX.json @@ -0,0 +1 @@ +{"keyData":"zsKBCDXpYAmpFXLDSpuhuFW8iPtrm4U0kCq5pAWerhE=","fingerprint":{"rawId":1264993325,"currentIndex":4,"deviceIndexes":[0,1]},"timestamp":"1751595351340"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHY.json b/baileys_auth_info/app-state-sync-key-AAAAADHY.json @@ -0,0 +1 @@ +{"keyData":"/vdCYwDcVeTZOEvlNxIjIHQohqgOnneb8VjOcM2uKUo=","fingerprint":{"rawId":1264993325,"currentIndex":5,"deviceIndexes":[0,5]},"timestamp":"1752252736115"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHZ.json b/baileys_auth_info/app-state-sync-key-AAAAADHZ.json @@ -0,0 +1 @@ +{"keyData":"fh4lRClm4+4KFdgiTD0O76SFts/Duba9jAx9QKG04Fo=","fingerprint":{"rawId":1264993325,"currentIndex":5,"deviceIndexes":[0,5]},"timestamp":"1754915180519"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHa.json b/baileys_auth_info/app-state-sync-key-AAAAADHa.json @@ -0,0 +1 @@ +{"keyData":"kVUA3TBQwGxpdkRlRT9Nk08/g/HEuhV2S+rpXdCBUyg=","fingerprint":{"rawId":1264993325,"currentIndex":6,"deviceIndexes":[0,5,6]},"timestamp":"0"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHb.json b/baileys_auth_info/app-state-sync-key-AAAAADHb.json @@ -0,0 +1 @@ +{"keyData":"qeC7pcGdHWDP6gW1is+kwXGEYdcPVLCgZeGuevhibpc=","fingerprint":{"rawId":1264993325,"currentIndex":6,"deviceIndexes":[0,5]},"timestamp":"0"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHc.json b/baileys_auth_info/app-state-sync-key-AAAAADHc.json @@ -0,0 +1 @@ +{"keyData":"+NHQmh2K6ux+A/twE7JZ01ghCWiBAxja0AGJr3Djmc0=","fingerprint":{"rawId":1264993325,"currentIndex":7,"deviceIndexes":[0,5]},"timestamp":"0"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHd.json b/baileys_auth_info/app-state-sync-key-AAAAADHd.json @@ -0,0 +1 @@ +{"keyData":"2fsEm/N/mhYCOk5oRCkl0jqXggY5a+Vg9ADl9TXCm+Q=","fingerprint":{"rawId":1264993325,"currentIndex":8,"deviceIndexes":[0,5]},"timestamp":"0"}+ \ No newline at end of file diff --git a/baileys_auth_info/app-state-sync-key-AAAAADHe.json b/baileys_auth_info/app-state-sync-key-AAAAADHe.json @@ -0,0 +1 @@ +{"keyData":"HGvtkhH01xGJr4fJIUQCUSAX57PZHJBsEfWj7EZKNaM=","fingerprint":{"rawId":1264993325,"currentIndex":9,"deviceIndexes":[0,5]},"timestamp":"1758886334809"}+ \ No newline at end of file diff --git a/baileys_auth_info/creds.json b/baileys_auth_info/creds.json @@ -0,0 +1 @@ +{"noiseKey":{"private":{"type":"Buffer","data":"eAL9oQQuYCMaNzjWwwvjE2GYp/b8mnae7dGYzpuj7lI="},"public":{"type":"Buffer","data":"yEYjPjN29DhL4ez8LKI9TObymHtx9axfxzKboWdx1xg="}},"pairingEphemeralKeyPair":{"private":{"type":"Buffer","data":"aCztvN7ZQCjRB7ClboVCQIwfmM8oUYwsGWCcK5FVT20="},"public":{"type":"Buffer","data":"tnTpepk0nYR+U3+/xiizNes0cwXigR74ID0LLvKUVjg="}},"signedIdentityKey":{"private":{"type":"Buffer","data":"MJE1cs5roFr8RK4uMu1RG27Lm+60okysxX6We/ZdE3g="},"public":{"type":"Buffer","data":"Wr/JhuijSL82ZNGF/oWT622eiamLE3q5BQjuZ7fGeR4="}},"signedPreKey":{"keyPair":{"private":{"type":"Buffer","data":"sOsDghBdBcbRp4fCDIJeiw13S9r9rgn9/EGmkltUP3I="},"public":{"type":"Buffer","data":"B2HYFJlTDyQ3G32OL3/W7yS+0G2Tzxvn7z1J17cTAno="}},"signature":{"type":"Buffer","data":"wUq2C+MqU37nZdh4DGdbHW0iP89i6LGP3jH/Z1c88bhVjqi2gyw1D5Um8o8fv/Bl97A9e3Kdo/K0uJjkc7lEDg=="},"keyId":1},"registrationId":36,"advSecretKey":"p11dgcV3ajjRc7ddBHuHvj35gpbAYqh3SIwP0QaILHY=","processedHistoryMessages":[],"nextPreKeyId":31,"firstUnuploadedPreKeyId":31,"accountSyncCounter":0,"accountSettings":{"unarchiveChats":false},"registered":false,"account":{"details":"CK2ImdsEENj12cYGGAogACgA","accountSignatureKey":"UpgGYpzwDEIKqC8UDIMWHlQ24zbSw+DHAs2hQXUysC4=","accountSignature":"9jDdgrrOGDItIWPsU03siu/EE+iU/4d5koochLR19EBJpwWFmb7BmO5L22qbCm0If2SKbAAf3eULa4SuboPRDg==","deviceSignature":"Wsl6pgn/jlqFwfdUNNT6rv3eVDr9+nXxJ/z1+P4dtDTJic+5Q3TjLO67vDPiC4DrwhYqOiTjRHrTaXgIQmKJAA=="},"me":{"id":"917278779512:18@s.whatsapp.net","lid":"201554426618024:18@lid"},"signalIdentities":[{"identifier":{"name":"917278779512:18@s.whatsapp.net","deviceId":0},"identifierKey":{"type":"Buffer","data":"BVKYBmKc8AxCCqgvFAyDFh5UNuM20sPgxwLNoUF1MrAu"}}],"platform":"android","routingInfo":{"type":"Buffer","data":"CA0IBQ=="},"lastAccountSyncTimestamp":1758886903,"myAppStateKeyId":"AAAAADHZ","lastPropHash":"3fYwCK"}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-1.json b/baileys_auth_info/pre-key-1.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"mMvmkzMbHDhclW2XjZIFbKvpZCAo9xwdsppN/vACV0w="},"public":{"type":"Buffer","data":"vgJW6DufbI0VCUQpoYrdJB+Y309G3ZITco3V1B4fDjA="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-10.json b/baileys_auth_info/pre-key-10.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"INzte03QlpvovL1bxsdjdK7NRu9vQ83BcFYiJJARonY="},"public":{"type":"Buffer","data":"D8TdRjDRKObrXrCLIBtjL/K5OBHC0kMvTTyud/W+O1M="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-11.json b/baileys_auth_info/pre-key-11.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"YJK/HnEzKzffsUisbUy0/GBUL3Dq92K7JoiDIGvemHo="},"public":{"type":"Buffer","data":"29chohH47UXpAVNgA7/Ct5W5pNcHN2vAFNUIegkFPiU="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-12.json b/baileys_auth_info/pre-key-12.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"KDZ12X8cS3ay8yR4TQ2c9lLXIqdrZNvdtVPwB8YYrFk="},"public":{"type":"Buffer","data":"wYScHwnrY4q5WOXWaBWceXCkRYXGTWObUfSCQl4qASs="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-13.json b/baileys_auth_info/pre-key-13.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"AKWMZNyKqqV637lstVXvpIO1O310VqfLxoVjp6hnX0U="},"public":{"type":"Buffer","data":"8h5ou0Hb8e/np4Ve37yHRCXe/oF5DDyesU3EAK//Ihs="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-14.json b/baileys_auth_info/pre-key-14.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"YHysIy8wdAN1di19teoL0iDQ0DgZGHcYhr6IwpDPSEg="},"public":{"type":"Buffer","data":"GbLJDBaYnEPVexGwlDXonx2MUvtooV42qXVA2Q/exAc="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-15.json b/baileys_auth_info/pre-key-15.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"MOh4vDu/3udiIFhTUg6L+Ud8UE9/KeNCm9NInTUD5nI="},"public":{"type":"Buffer","data":"gSw3m8HgoRwz+A2iPiuHh6vGDzhINbx6/JoPxatAkXc="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-16.json b/baileys_auth_info/pre-key-16.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"yNYjNOou9g/dWyTLK/LTAeQIMHsj4H0oCEF+4zGImXM="},"public":{"type":"Buffer","data":"Y2rOt5dbiMM6x3t6iNbVgByk5VDUsgBpLJbSKy3F/B4="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-17.json b/baileys_auth_info/pre-key-17.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"WLJ6NV+uGsotY/bJrcBFitS1pt59XPl1rer3f7sV8kI="},"public":{"type":"Buffer","data":"wXZcxNAYabw/eWS8bi9Gy8cIwUsQBCrvzFL5Hmw7kQA="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-18.json b/baileys_auth_info/pre-key-18.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"mOjh0YLhv/eh/LYlcbANnTIw2UO8IgqVccu6pZNH5Ws="},"public":{"type":"Buffer","data":"rosFE+8+BbEFfSXxI2F2E9tJkshSs1/dHdjZ52VSBEQ="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-19.json b/baileys_auth_info/pre-key-19.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"GAk6eEa3u+v4DdaCtL32Hmedc++2d2FqnW1jOJSddVg="},"public":{"type":"Buffer","data":"1bBg4U1l+ETnWf/rDwGGSjtgiUi5SEAbjNA+AOEZ9zY="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-2.json b/baileys_auth_info/pre-key-2.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"OB9AUv10vLDv7dLr8DilFsBCfoN0Hv9AAVbhcjF/JFU="},"public":{"type":"Buffer","data":"tKiDgMIPCg9FLwy+1PRh8H/Isa35HkPf91oazGu5AV4="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-20.json b/baileys_auth_info/pre-key-20.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"iFIFuilgM+PMwllxn5u82Q3srcyeD3+jyLumB67t+0U="},"public":{"type":"Buffer","data":"9gMfBqb4QGpPI2KJHHWQ09ZjiUuHgu0aSQFZJ0wS1V0="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-21.json b/baileys_auth_info/pre-key-21.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"2BxC37yjLXp+LggA/mpGnvLeQhKflaVQiLuhrPA1akA="},"public":{"type":"Buffer","data":"r1JEBcSnNS/1FnBEvxZj8RZXLsEwNg733vfHakCi7C4="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-22.json b/baileys_auth_info/pre-key-22.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"YJv8LZ1yEK+RbKCOmVZEGo5MjolXlR2X8WhYVQHyy2s="},"public":{"type":"Buffer","data":"IcBgk3KOmmcYBT+d4LOv10jSij0XBrwhoMJvuIvOdnU="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-23.json b/baileys_auth_info/pre-key-23.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"aK6ggyplASmR1gWbGH+X8IC6QDNt4SZe8dFhaschAUo="},"public":{"type":"Buffer","data":"bBf5uVX0ehGTRjFAy0lD+rnztVPc5d5aYbq7HyAqxXc="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-25.json b/baileys_auth_info/pre-key-25.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"MLHW4jNq95xsY8pdo+EaJe3utCrgP4pYEhVcHYO1PU8="},"public":{"type":"Buffer","data":"TA7BvYvHbBqBgozV2nEtWypP1YYPCehnpG3f2NWYo18="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-26.json b/baileys_auth_info/pre-key-26.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"GLFtFjx4hSniKB/rjJhPfXHf39Akk5KeA6bi2f1pC0E="},"public":{"type":"Buffer","data":"oABdu5vJTaZ6lQQnIYd9gw9KwcExJBtEXa7NT14/NVc="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-27.json b/baileys_auth_info/pre-key-27.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"uCCo6zcL184Cr/ZByhbJjzv1KSLIFnft26k0Oh6BZ3I="},"public":{"type":"Buffer","data":"Ar4DPYE4Jj9+X/GmBsT0YBPFKYvUCmowe9MnbzfqsCo="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-28.json b/baileys_auth_info/pre-key-28.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"aMgo9nVxxpST3t8B+uWPZGFCcjh+QaLUMJGVQW/ouUk="},"public":{"type":"Buffer","data":"W0GMldgGczhSqYrnyZUhOKdIkjIHu1QqYVSvlARLTVM="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-29.json b/baileys_auth_info/pre-key-29.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"oKBfbXAtCccyKRHyAZVFJQlnFpgHl8FInoj+v5Y8qnk="},"public":{"type":"Buffer","data":"5ZpzTNvv4Skcg6FyFhANmz2J26DkJTzBIca6lmJ/w1U="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-3.json b/baileys_auth_info/pre-key-3.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"OH7fNv1NpIiii15b0ohsNZFwP40hsKv0hS7CjvZyAGo="},"public":{"type":"Buffer","data":"BI8G4warVbSHU18QqIkoXdLwYagbbhSTKLoV/t6rPBU="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-30.json b/baileys_auth_info/pre-key-30.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"iF4OQhftbGs5PxhsKKnXGpa4H914AMDSN40UqCEx1FA="},"public":{"type":"Buffer","data":"ib51xpQ8C4rNQWhvhGjvjdYhvsphSMbY3BF3Y156Bm0="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-4.json b/baileys_auth_info/pre-key-4.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"CGJvUaF/Cw0OAZGJ5xJCCW4KM2CUBh6UJ/gmRpEZ9nI="},"public":{"type":"Buffer","data":"Vb+FXuCJutQjRt96Pr0XzQNzvH3Gq7Y3e3fvojRqASM="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-5.json b/baileys_auth_info/pre-key-5.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"2MePUJQVHSk+Azye2peJGl6mevjOWH1UTkwnTKczw0g="},"public":{"type":"Buffer","data":"RDdQ16ZB5RbQN/R+Nhaaq7/IXLmlMjAB4C4f9cq8hns="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-6.json b/baileys_auth_info/pre-key-6.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"6F/QVNIyeP6EYn1lfEuphDrfYZmtPO4PTF2G0/zYeGk="},"public":{"type":"Buffer","data":"bUEP/UdxttU2sq9thDSHnBywmH+TIBe6bxjCX85yqEY="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-7.json b/baileys_auth_info/pre-key-7.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"2JLll0IykvmA2qkd9gQc3PBJnlqYePgtCxidCeztF1U="},"public":{"type":"Buffer","data":"x2hePPefcTp/fow7BSig9nr/oafFL0/8CKasacrUuyI="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-8.json b/baileys_auth_info/pre-key-8.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"uOFbqlIqTp3jajyLNQNcdVcNsiSrnv3/t30cNBNcvWo="},"public":{"type":"Buffer","data":"hYIJvYSyeBeyHdq8O4O/1D1r/OVWYkxSo12c54AZfXM="}}+ \ No newline at end of file diff --git a/baileys_auth_info/pre-key-9.json b/baileys_auth_info/pre-key-9.json @@ -0,0 +1 @@ +{"private":{"type":"Buffer","data":"OPDkGUu7upDxh+LkbonoVLd4qd/q5ymLlxwMwfhB1nY="},"public":{"type":"Buffer","data":"KNVLD3pYD50U04s5mfR5n7oL/7V44bBTAUYhjT6gFTc="}}+ \ No newline at end of file diff --git a/baileys_auth_info/session-917278779512.0.json b/baileys_auth_info/session-917278779512.0.json @@ -0,0 +1 @@ +{"_sessions":{"BfbMS4WGe/jwVAP5yzLP1v1Jzyipof96NapJC9xTYeFQ":{"registrationId":318434822,"currentRatchet":{"ephemeralKeyPair":{"pubKey":"Bdi/QMkbb4KBA9nEPTf3XhMqj70Sgl7cuD8sl00u2aN0","privKey":"ULOj2a4G3/3p7Bgol064CPNotieM8sZ8ilz2WefPU3E="},"lastRemoteEphemeralKey":"BYALISdhIi8ZhsKxbnpraUALDqT4XQfJfQ3URr4p4k9p","previousCounter":0,"rootKey":"2RXDr2/0u/APbklpHhC76H2I7631q09i9cflI58JQP8="},"indexInfo":{"baseKey":"BfbMS4WGe/jwVAP5yzLP1v1Jzyipof96NapJC9xTYeFQ","baseKeyType":2,"closed":-1,"used":1758886464330,"created":1758886464330,"remoteIdentityKey":"BVKYBmKc8AxCCqgvFAyDFh5UNuM20sPgxwLNoUF1MrAu"},"_chains":{"BYALISdhIi8ZhsKxbnpraUALDqT4XQfJfQ3URr4p4k9p":{"chainKey":{"counter":7,"key":"WHxReuc7sujbcsgiNEYiulCbxbOu4iNULhEl42WrBFA="},"chainType":2,"messageKeys":{}},"Bdi/QMkbb4KBA9nEPTf3XhMqj70Sgl7cuD8sl00u2aN0":{"chainKey":{"counter":-1,"key":"Q1p3+Fwu1w9O3LPM35ro/pQEPoqGgWwgtBpA3cX5XLw="},"chainType":1,"messageKeys":{}}}}},"version":"v1"}+ \ No newline at end of file diff --git a/baileys_auth_info/session-917439454418.0.json b/baileys_auth_info/session-917439454418.0.json @@ -0,0 +1 @@ +{"_sessions":{"BUEfJP6Xt7yurTmtzwhvpg2ho8bdQZRsfpUZHJf570so":{"registrationId":838113029,"currentRatchet":{"ephemeralKeyPair":{"pubKey":"BfDv35Cb1mcWQGcK8KA5lniF5iwgKeJFlnvGt1qwZOhi","privKey":"oBx3C8zEoeZzlcRtCucKid9JoYISPGgsTiGgVms65XA="},"lastRemoteEphemeralKey":"Bc2g10ooy2CZt8/QuFGknFdMhJUbjHTRcjYP33MTGvM7","previousCounter":0,"rootKey":"x/FgTHAwFNOLVfk6rvMAARQ43dnGj5SiHJBbuSzJkXo="},"indexInfo":{"baseKey":"BUEfJP6Xt7yurTmtzwhvpg2ho8bdQZRsfpUZHJf570so","baseKeyType":2,"closed":-1,"used":1758886531570,"created":1758886531570,"remoteIdentityKey":"BRpgEmc4EZZSsZ6OLbB0tc3jwrGNavrv2rAvUNO7XxID"},"_chains":{"Bc2g10ooy2CZt8/QuFGknFdMhJUbjHTRcjYP33MTGvM7":{"chainKey":{"counter":5,"key":"z6hiRRHHQdKOOWhUYnRw4TYKQrT0K/NOjxGuKlTApbI="},"chainType":2,"messageKeys":{}},"BfDv35Cb1mcWQGcK8KA5lniF5iwgKeJFlnvGt1qwZOhi":{"chainKey":{"counter":-1,"key":"ivWucSrTQAFKEEF/juXrPYiRa4I4Y3n7IUBS6VzGHaw="},"chainType":1,"messageKeys":{}}}}},"version":"v1"}+ \ No newline at end of file diff --git a/index.js b/index.js @@ -0,0 +1,133 @@ +import makeWASocket, { + makeCacheableSignalKeyStore, + useMultiFileAuthState, + DisconnectReason, + fetchLatestBaileysVersion +} from "@whiskeysockets/baileys"; +import { Boom } from "@hapi/boom"; +import pino from "pino"; +import { execFile } from "child_process"; +import qrcode from "qrcode-terminal"; +import fs from "fs"; + +// Initialize a silent logger for Baileys +const logger = pino().child({ level: "silent" }); + +// Define the path for the authentication credentials +const authPath = "./baileys_auth_info"; + +// Function to run the Python script +const runPythonScript = (text, sender, messageId, action = "log") => { + // Execute the Python script "ai.py" to handle the message. + execFile('python', ['ai.py', text, sender, messageId, action], (error, stdout, stderr) => { + if (error) { + console.error("❌ Python Error:", error.message); + return; + } + if (stderr) { + console.error("⚠️ Python stderr:", stderr); + return; + } + console.log("🐍 Python stdout:", stdout); + }); +}; + +// Main function to start the bot +const startSock = async () => { + // Check if the auth directory exists, otherwise create it + if (!fs.existsSync(authPath)) { + fs.mkdirSync(authPath); + } + + const { state, saveCreds } = await useMultiFileAuthState(authPath); + + // Fetch the latest compatible version of WhatsApp Web + const { version } = await fetchLatestBaileysVersion(); + console.log(`Using WhatsApp version: ${version.join('.')}`); + + const sock = makeWASocket({ + version, + logger, + auth: { + creds: state.creds, + keys: makeCacheableSignalKeyStore(state.keys, logger.child({ level: 'silent' })), + }, + browser: ["WhatsApp Bot", "Chrome", "1.0.0"], // This is a fake browser ID + patchMessageBeforeSending: (message) => { + const requiresPatch = !!( + message.buttonsMessage || + message.listMessage + ); + if (requiresPatch) { + message = { + viewOnceMessage: { + message: { + ...message, + }, + }, + }; + } + return message; + }, + }); + + // Save credentials when they are updated + sock.ev.on("creds.update", saveCreds); + + // Handle connection state changes + sock.ev.on("connection.update", (update) => { + const { connection, lastDisconnect, qr } = update; + if (qr) { + console.log("Scan the QR code to connect:"); + qrcode.generate(qr, { small: true }); + } + if (connection === "close") { + const reason = new Boom(lastDisconnect?.error)?.output?.statusCode; + if (reason === DisconnectReason.loggedOut) { + console.log("Logged out. Deleting auth directory and trying again."); + fs.rmSync(authPath, { recursive: true, force: true }); + startSock(); + } else { + console.log("Connection closed. Reconnecting..."); + startSock(); + } + } else if (connection === "open") { + console.log("✅ Baileys bot is ready and running!"); + } + }); + + // Listen for incoming messages + sock.ev.on("messages.upsert", async ({ messages, type }) => { + if (type === "notify") { + const msg = messages[0]; + if (!msg.message || msg.key.fromMe) return; + + const sender = msg.key.remoteJid; + const senderName = msg.pushName || sender; + const text = msg.message.conversation || msg.message.extendedTextMessage?.text; + const messageId = msg.key.id; + + if (text) { + console.log(`📥 From ${senderName} (${sender}): ${text}`); + runPythonScript(text, sender, messageId); + } + } + }); + + // Listen for edited messages + sock.ev.on("messages.update", async (messages) => { + const message = messages[0]; + if (message.update.edited) { + const updatedText = message.update.edited.message.extendedTextMessage?.text; + const originalMessageId = message.key.id; + + if (updatedText) { + console.log(`✏️ Edited message from ${message.key.remoteJid}: ${updatedText}`); + runPythonScript(updatedText, message.key.remoteJid, originalMessageId, "edit"); + } + } + }); +}; + +// Start the bot +startSock(); diff --git a/package.json b/package.json @@ -0,0 +1,20 @@ +{ + "name": "whatsapptracking", + "version": "1.0.0", + "description": "A simple WhatsApp message logger.", + "main": "index.js", + "type": "module", + "scripts": { + "start": "node index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@hapi/boom": "^10.0.1", + "@whiskeysockets/baileys": "^6.7.2", + "package.json": "^2.0.1", + "pino": "^8.1.0", + "qrcode-terminal": "^0.12.0" + } +}
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror