send_agent_message_fixed.sh
1 #!/bin/bash 2 3 # Send a message to an ECHO agent via Redis 4 # Usage: ./send_agent_message_fixed.sh <to_agent> <message_type> <subject> [json_content] 5 6 if [ $# -lt 3 ]; then 7 echo "Usage: $0 <to_agent> <message_type> <subject> [json_content]" 8 echo "" 9 echo "Examples:" 10 echo " $0 product_manager request test_message '{\"test\": \"hello\"}'" 11 exit 1 12 fi 13 14 TO_AGENT="$1" 15 MSG_TYPE="$2" 16 SUBJECT="$3" 17 CONTENT_JSON="${4:-{}}" 18 19 # Generate message ID 20 MSG_ID="msg_$(date +%s)_$(( RANDOM % 10000 ))" 21 TIMESTAMP="$(date -u +%Y-%m-%dT%H:%M:%SZ)" 22 23 # Create valid JSON using jq 24 MESSAGE=$(jq -n \ 25 --arg id "$MSG_ID" \ 26 --arg from "human" \ 27 --arg to "$TO_AGENT" \ 28 --arg type "$MSG_TYPE" \ 29 --arg subject "$SUBJECT" \ 30 --argjson content "$CONTENT_JSON" \ 31 --arg timestamp "$TIMESTAMP" \ 32 '{ 33 id: $id, 34 from: $from, 35 to: $to, 36 type: $type, 37 subject: $subject, 38 content: $content, 39 timestamp: $timestamp 40 }') 41 42 CHANNEL="messages:$TO_AGENT" 43 44 echo "Sending message to $TO_AGENT..." 45 echo "Channel: $CHANNEL" 46 echo "Message: $MESSAGE" 47 echo "" 48 49 # Publish to Redis on correct port 50 redis-cli -p 6383 PUBLISH "$CHANNEL" "$MESSAGE" 51 52 echo "" 53 echo "✓ Message sent!"