From 0a06867a347eef06c52d95a6848c087a4f3f62f5 Mon Sep 17 00:00:00 2001 From: TM-1 Matrix Sync Date: Tue, 24 Mar 2026 16:04:48 -0400 Subject: [PATCH] feat: add lightweight matrix-triad-node.sh for minimal node deployments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bash script for triad nodes without full Node.js workspace. Usage: matrix-triad-node.sh [args] Uses raw curl + Python JSON — no node_modules needed. Also: ignore heretek-openclaw-src/ (npm-publish artifact directory). --- .gitignore | 1 + scripts/matrix-triad-node.sh | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100755 scripts/matrix-triad-node.sh diff --git a/.gitignore b/.gitignore index ac3d8548df..eec9f56c94 100755 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ matrix-dendrite/config/matrix_key.pem matrix-dendrite/config/tls.crt matrix-dendrite/config/tls.key matrix-data/ +heretek-openclaw-src/ diff --git a/scripts/matrix-triad-node.sh b/scripts/matrix-triad-node.sh new file mode 100755 index 0000000000..12e65106aa --- /dev/null +++ b/scripts/matrix-triad-node.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Lightweight Matrix triad node client +# Usage: ./matrix-triad-node.sh +# Commands: send , join , 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 [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