Buckets:

download
raw
2.3 kB
"""
Hermes WhatsApp Gateway Pairing Script.
Generates pairing code for WhatsApp Web (no QR needed).
Run: python pair.py +1234567890
"""
import json
import os
import sys
import time
import requests
HERMES_URL = os.environ.get("HERMES_URL", "http://localhost:9090")
PHONE_NUMBER = sys.argv[1] if len(sys.argv) > 1 else None
def request_pair(phone: str) -> dict:
resp = requests.post(
f"{HERMES_URL}/api/whatsapp/request-pair",
json={"phone": phone},
timeout=30,
)
resp.raise_for_status()
return resp.json()
def check_pair_status(request_id: str) -> dict:
resp = requests.get(
f"{HERMES_URL}/api/whatsapp/pair-status/{request_id}",
timeout=30,
)
resp.raise_for_status()
return resp.json()
def main():
if not PHONE_NUMBER:
print("Usage: python pair.py +1234567890")
print(" python pair.py +1234567890 --code 123456")
sys.exit(1)
phone = PHONE_NUMBER.strip().lstrip("+")
if not phone.isdigit():
print(f"Invalid phone: {PHONE_NUMBER}")
sys.exit(1)
print(f"Requesting pairing code for +{phone}...")
try:
result = request_pair(phone)
print(f"Pairing requested! ID: {result.get('request_id')}")
print(f"Code: {result.get('code', 'N/A')}")
print(f"Expires: {result.get('expires_in', 'N/A')}s")
if result.get("code"):
print("\nEnter this code in WhatsApp > Linked Devices > Link a Device")
print(f"Code: {result['code']}")
request_id = result.get("request_id")
if request_id:
print("\nWaiting for pairing confirmation...")
for _ in range(30):
status = check_pair_status(request_id)
if status.get("status") == "connected":
print("WhatsApp paired successfully!")
print(f"JID: {status.get('jid')}")
return
time.sleep(2)
print("Timeout waiting for pairing. Check Hermes logs.")
except requests.exceptions.ConnectionError:
print(f"Can't reach Hermes at {HERMES_URL}. Is the service running?")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()

Xet Storage Details

Size:
2.3 kB
·
Xet hash:
55d16484e2e9a312c01cedf8365acb499f073ef00d9d835cd030838875b726b2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.