#!/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 - <