import os import sys import paramiko pw = os.environ["DEPLOY_PASSWORD"] c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("20.191.152.26", username="wakka", password=pw, timeout=30) script = r""" echo '=== env ===' sudo docker exec guest-chat printenv MAXKB_BASE_URL MAXKB_ACCESS_TOKEN MAXKB_BRIDGE_ENABLED CHATWOOT_AGENT_BOT_TOKEN echo '=== agent bot webhook ===' sudo docker exec guest-chat-postgres-1 psql -U postgres -d chatwoot_production -t -A -c "SELECT name, outgoing_url FROM agent_bots WHERE id=1;" echo '=== maxkb auth+open+chat test ===' sudo docker exec guest-chat python3 - <<'PY' import os, json, urllib.request, sys sys.path.insert(0, '/opt/guest-cs') base = os.environ.get('MAXKB_BASE_URL', '') tok = os.environ.get('MAXKB_ACCESS_TOKEN', '') print('MAXKB', base) try: req = urllib.request.Request(base + '/chat/api/auth/anonymous', data=json.dumps({'access_token': tok}).encode(), headers={'Content-Type': 'application/json'}, method='POST') with urllib.request.urlopen(req, timeout=25) as r: body = json.loads(r.read().decode()) print('auth', body.get('code'), str(body.get('data', ''))[:40] + '...') jwt = body['data'] req2 = urllib.request.Request(base + '/chat/api/open', headers={'Authorization': 'Bearer ' + jwt}) with urllib.request.urlopen(req2, timeout=25) as r: open_body = json.loads(r.read().decode()) chat_id = open_body['data'] print('open chat_id', chat_id) req3 = urllib.request.Request(base + '/chat/api/chat_message/' + chat_id, data=json.dumps({'message': '你好', 'stream': False, 're_chat': False, 'form_data': {'username': 'test'}}).encode(), headers={'Authorization': 'Bearer ' + jwt, 'Content-Type': 'application/json'}, method='POST') with urllib.request.urlopen(req3, timeout=120) as r: ans = json.loads(r.read().decode()) content = (ans.get('data') or {}).get('content', '')[:120] print('chat reply', ans.get('code'), content) except Exception as e: print('FAIL', e) PY echo '=== recent bridge logs ===' sudo docker logs guest-chat 2>&1 | grep -iE 'MaxKB|bridge|webhook/bot1' | tail -8 """ _, o, e = c.exec_command(script, timeout=180) sys.stdout.buffer.write(o.read()) sys.stdout.buffer.write(e.read()) c.close()