最初版本

This commit is contained in:
sa19840531
2026-08-15 14:51:51 +08:00
parent 4e01df4dce
commit ea47ea4449
176 changed files with 21009 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
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 '=== latest messages ==='
sudo docker exec guest-chat-postgres-1 psql -U postgres -d chatwoot_production -c "SELECT id, message_type, left(content,40) AS content, created_at FROM messages ORDER BY id DESC LIMIT 8;"
echo '=== bridge logs (last 25) ==='
sudo docker logs guest-chat 2>&1 | grep -iE 'MaxKB|bridge|401|failed|reply_len|exception|特平|webhook/bot1' | tail -25
echo '=== test maxkb ask ==='
sudo docker exec guest-chat python3 - <<'PY'
import os, json, urllib.request, sys, time
sys.path.insert(0,'/opt/guest-cs')
base=os.environ['MAXKB_BASE_URL']
tok=os.environ['MAXKB_ACCESS_TOKEN']
t0=time.time()
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=30) as r:
jwt=json.loads(r.read())['data']
req2=urllib.request.Request(base+'/chat/api/open', headers={'Authorization':'Bearer '+jwt})
with urllib.request.urlopen(req2, timeout=30) as r:
cid=json.loads(r.read())['data']
body={'message':'特平尾怎么赔?','stream':False,'re_chat':False,'form_data':{'username':'游客'}}
req3=urllib.request.Request(base+f'/chat/api/chat_message/{cid}', data=json.dumps(body).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())
print('elapsed', round(time.time()-t0,1), 's')
print('code', ans.get('code'))
data=ans.get('data') or {}
print('reply', (data.get('content') or '')[:200])
PY
echo '=== simulate webhook for user msg ==='
sudo docker exec guest-chat python3 - <<'PY'
import json, urllib.request, sys
sys.path.insert(0,'/opt/guest-cs')
import maxkb_chatwoot_bridge as m
# get latest incoming msg id from db would be ideal; use high id
p={'event':'conversation_updated','id':5,'account':{'id':1},'messages':[{'id':9999991,'content':'特平尾怎么赔?','message_type':0,'private':False,'conversation_id':5,'account_id':1,'sender':{'name':'游客'}}]}
print('extract', m._extract_incoming(p))
req=urllib.request.Request('http://127.0.0.1:7788/webhook/bot1/chatwoot', data=json.dumps(p).encode(), headers={'Content-Type':'application/json'}, method='POST')
with urllib.request.urlopen(req, timeout=180) as r:
print('webhook', r.status, r.read()[:300])
PY
sleep 3
sudo docker logs guest-chat 2>&1 | grep -iE 'bridge|MaxKB|401|reply_len|failed' | tail -8
"""
_, o, e = c.exec_command(script, timeout=240)
sys.stdout.buffer.write(o.read())
sys.stdout.buffer.write(e.read())
c.close()