46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
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"""
|
|
sudo docker exec guest-chat python3 -c "
|
|
import os, json, urllib.request, traceback
|
|
base=os.environ.get('MAXKB_BASE_URL','')
|
|
tok=os.environ.get('MAXKB_ACCESS_TOKEN','')
|
|
bot=os.environ.get('CHATWOOT_AGENT_BOT_TOKEN','')
|
|
print('MAXKB_BASE_URL', base)
|
|
print('BOT_TOKEN', bot[:8]+'...' if bot else 'EMPTY')
|
|
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=r.read().decode()
|
|
print('maxkb_auth_ok', r.status, body[:250])
|
|
except Exception as e:
|
|
print('maxkb_auth_err', repr(e))
|
|
traceback.print_exc()
|
|
|
|
payload={'event':'message_created','message_type':0,'content':'123','conversation':{'id':999,'account_id':1,'inbox_id':1},'account':{'id':1},'sender':{'id':1,'name':'test'}}
|
|
try:
|
|
req=urllib.request.Request('http://127.0.0.1:7788/webhook/bot1/chatwoot', data=json.dumps(payload).encode(), headers={'Content-Type':'application/json'}, method='POST')
|
|
with urllib.request.urlopen(req, timeout=20) as r:
|
|
print('webhook_ok', r.status, r.read()[:200])
|
|
except Exception as e:
|
|
if hasattr(e,'read'): print('webhook_err_body', e.read()[:500])
|
|
print('webhook_err', repr(e))
|
|
"
|
|
|
|
sudo docker exec guest-chat-postgres-1 psql -U postgres -d chatwoot_production -t -A -c "SELECT access_token FROM agent_bots WHERE id=1;"
|
|
|
|
sudo docker logs guest-chat 2>&1 | grep -iE 'MaxKB|bridge|webhook|Chatwoot.*回覆|agent_bot' | tail -20
|
|
"""
|
|
|
|
_, o, e = c.exec_command(script, timeout=120)
|
|
sys.stdout.buffer.write(o.read())
|
|
sys.stdout.buffer.write(e.read())
|
|
c.close()
|