最初版本
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""Apply auto-reply fix on wakka-test-server."""
|
||||
import os
|
||||
|
||||
import paramiko
|
||||
|
||||
pw = os.environ["DEPLOY_PASSWORD"]
|
||||
base = os.path.dirname(os.path.abspath(__file__))
|
||||
remote_stack = "/home/wakka/guest-cs-stack"
|
||||
compose = "docker-compose.chat.yaml -f docker-compose.chat.test7777.yaml"
|
||||
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect("20.191.152.26", username="wakka", password=pw, timeout=30)
|
||||
|
||||
uploads = [
|
||||
(os.path.join(base, "flask", "maxkb_chatwoot_bridge.py"), "/home/wakka/maxkb_chatwoot_bridge.py"),
|
||||
(os.path.join(base, "flask", "app.py"), "/home/wakka/app.py"),
|
||||
(os.path.join(base, "guest-cs.test.env"), f"{remote_stack}/guest-cs.test.env"),
|
||||
]
|
||||
|
||||
sftp = c.open_sftp()
|
||||
for local, remote in uploads:
|
||||
with open(local, "rb") as fh:
|
||||
data = fh.read().replace(b"\r\n", b"\n")
|
||||
with sftp.file(remote, "w") as rf:
|
||||
rf.write(data)
|
||||
print("uploaded", os.path.basename(local))
|
||||
sftp.close()
|
||||
|
||||
cmd = f"""
|
||||
set -e
|
||||
sudo docker cp /home/wakka/maxkb_chatwoot_bridge.py guest-chat:/opt/guest-cs/maxkb_chatwoot_bridge.py
|
||||
sudo docker cp /home/wakka/app.py guest-chat:/opt/guest-cs/app.py
|
||||
cd {remote_stack}
|
||||
sudo docker compose -f {compose} up -d --force-recreate guest-chat
|
||||
sleep 40
|
||||
sudo docker exec guest-chat printenv CHATWOOT_AGENT_BOT_TOKEN
|
||||
sudo docker exec guest-chat python3 -c "
|
||||
import json, urllib.request
|
||||
p={{'event':'conversation_updated','id':3,'account':{{'id':1}},'messages':[{{'id':888888,'content':'你好','message_type':0,'private':False,'conversation_id':3,'account_id':1,'sender':{{'name':'游客'}}}}]}}
|
||||
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=120) as r:
|
||||
print('webhook', r.status, r.read()[:250])
|
||||
"
|
||||
sudo docker logs guest-chat 2>&1 | grep -iE 'bridge|MaxKB|401|reply_len' | tail -6
|
||||
"""
|
||||
|
||||
print(">>> apply fix")
|
||||
_, o, e = c.exec_command(cmd, timeout=240)
|
||||
print(o.read().decode(errors="replace"))
|
||||
err = e.read().decode(errors="replace")
|
||||
if err.strip():
|
||||
print(err)
|
||||
c.close()
|
||||
Reference in New Issue
Block a user