- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
67 lines
1.6 KiB
Bash
67 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
# oc_send.sh - proxy for `openclaw message send` that routes through outgoing_validator.js
|
|
# Usage: replace `openclaw message send [args]` with `/home/alex/clawd/tools/oc_send.sh [args]`
|
|
|
|
VALIDATOR="/home/alex/clawd/tools/outgoing_validator.js"
|
|
if [ ! -x "$VALIDATOR" ]; then
|
|
echo "Validator not found or not executable: $VALIDATOR" >&2
|
|
exit 2
|
|
fi
|
|
|
|
# Default REDIS_KEY for validator
|
|
REDIS_KEY=${REDIS_KEY:-agent:invalid_body:count}
|
|
|
|
# Default values
|
|
channel="discord"
|
|
message=""
|
|
target=""
|
|
# Parse args
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--channel)
|
|
channel="$2"; shift 2;;
|
|
--to|--target)
|
|
target="$2"; shift 2;;
|
|
--message)
|
|
message="$2"; shift 2;;
|
|
--json)
|
|
# pass-through: read next arg as JSON message
|
|
message="$2"; shift 2;;
|
|
--*)
|
|
# skip unknown flags and their values conservatively
|
|
shift
|
|
;;
|
|
*)
|
|
# positional: treat remaining as message text (join all)
|
|
if [ -z "$message" ]; then
|
|
message="$*"
|
|
break
|
|
else
|
|
shift
|
|
fi
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Trim
|
|
message=$(echo "$message" | sed -e 's/^\s*//' -e 's/\s*$//')
|
|
|
|
# Build JSON payload
|
|
payload=$(jq -n --arg ch "$channel" --arg msg "$message" --arg tgt "$target" '
|
|
($tgt==""?) | . as $ignore | {channel:$ch, message:$msg} + (if $tgt!="" then {target:$tgt} else {} end)')
|
|
|
|
# If jq not found, fallback to simple JSON (escape quotes)
|
|
if [ $? -ne 0 ] || [ -z "$payload" ]; then
|
|
esc=$(python3 - <<PY
|
|
import json,sys
|
|
obj={'channel':"%s", 'message':"%s"}
|
|
print(json.dumps(obj))
|
|
PY
|
|
"$channel" "$message")
|
|
payload="$esc"
|
|
fi
|
|
|
|
# Pipe to validator and send
|
|
echo "$payload" | "$VALIDATOR" --send
|
|
exit $?
|