mirror of
https://github.com/Heretek-AI/openclaw.git
synced 2026-08-27 14:07:18 -04:00
0a06867a34
Bash script for triad nodes without full Node.js workspace. Usage: matrix-triad-node.sh <tm1|tm2|tm3> <send|join|sync> [args] Uses raw curl + Python JSON — no node_modules needed. Also: ignore heretek-openclaw-src/ (npm-publish artifact directory).
69 lines
2.1 KiB
Bash
Executable File
69 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# Lightweight Matrix triad node client
|
|
# Usage: ./matrix-triad-node.sh <tmN> <command>
|
|
# Commands: send <room> <message>, join <room>, sync
|
|
set -euo pipefail
|
|
|
|
TM="${1:-}"
|
|
CMD="${2:-}"
|
|
SERVER="http://192.168.31.99:8008"
|
|
TOKEN_FILE="/home/openclaw/.openclaw/.secure/matrix/${TM}.token"
|
|
|
|
usage() {
|
|
echo "Usage: $0 <tm1|tm2|tm3> <send|join|sync> [args...]"
|
|
exit 1
|
|
}
|
|
|
|
[[ -z "$TM" || -z "$CMD" ]] && usage
|
|
[[ ! -f "$TOKEN_FILE" ]] && { echo "Token not found: $TOKEN_FILE"; exit 1; }
|
|
|
|
TOKEN=$(cat "$TOKEN_FILE")
|
|
AUTH="Authorization: Bearer $TOKEN"
|
|
CONTENT_TYPE="Content-Type: application/json"
|
|
|
|
send_msg() {
|
|
local room="$3"; local msg="$4"
|
|
local txn_id="mtx_${TM}_$(date +%s)"
|
|
local resp
|
|
resp=$(curl -s -X PUT -H "$AUTH" -H "$CONTENT_TYPE" \
|
|
-d "{\"msgtype\":\"m.text\",\"body\":\"$msg\"}" \
|
|
"${SERVER}/_matrix/client/v3/rooms/${room}/send/m.room.message/${txn_id}")
|
|
echo "$resp" | python3 -c "import sys,json; d=json.load(sys.stdin); print('Sent:', d.get('event_id','?'))" 2>/dev/null || echo "Sent (no event_id in response)"
|
|
}
|
|
|
|
join_room() {
|
|
local room="$3"
|
|
local resp
|
|
resp=$(curl -s -X POST -H "$AUTH" -H "$CONTENT_TYPE" \
|
|
-d '{}' \
|
|
"${SERVER}/_matrix/client/v3/join/${room}")
|
|
echo "$resp" | python3 -c "import sys,json; d=json.load(sys.stdin); print('Joined:', d.get('room_id','?'))" 2>/dev/null || echo "Joined (no room_id in response)"
|
|
}
|
|
|
|
sync_msgs() {
|
|
local since="${3:-}"
|
|
local url="${SERVER}/_matrix/client/v3/sync?timeout=5000"
|
|
[[ -n "$since" ]] && url="${url}&since=${since}"
|
|
curl -s -H "$AUTH" "$url" | python3 -c "
|
|
import sys,json
|
|
d=json.load(sys.stdin)
|
|
next_tok = d.get('next_batch','')
|
|
rooms = d.get('rooms',{}).get('join',{})
|
|
for rid,data in rooms.items():
|
|
for ev in data.get('timeline',{}).get('events',[]):
|
|
if ev.get('type')=='m.room.message':
|
|
body=ev.get('content',{}).get('body','')
|
|
sender=ev.get('sender','').split(':')[0].replace('@','')
|
|
if sender != '${TM}':
|
|
print(f'{sender}: {body}')
|
|
print('NEXT:', next_tok)
|
|
"
|
|
}
|
|
|
|
case "$CMD" in
|
|
send) send_msg "$@" ;;
|
|
join) join_room "$@" ;;
|
|
sync) sync_msgs "$@" ;;
|
|
*) usage ;;
|
|
esac
|