#!/usr/bin/env bash
# Show a campaign's status and the first page of recipient results. Needs: curl, jq.
set -euo pipefail
BASE="${RELATIONSAI_API_BASE:-https://voice-api.relationsai.com/v1}"
: "${CAMPAIGN_ID:?Set CAMPAIGN_ID to a campaign id (cmp_...)}"
AUTH="Authorization: Bearer $RELATIONSAI_API_KEY"

campaign=$(curl -sS --fail-with-body "$BASE/campaigns/$CAMPAIGN_ID" -H "$AUTH") || { echo "$campaign" >&2; exit 1; }
jq -r '"\(.id) \(.status) run=\(.run_number) allowed: \([.capabilities | to_entries[] | select(.value) | .key] | join(", "))",
       "progress \(.progress | tojson)"' <<<"$campaign"

recipients=$(curl -sS --fail-with-body "$BASE/campaigns/$CAMPAIGN_ID/recipients?limit=100" -H "$AUTH") ||
  { echo "$recipients" >&2; exit 1; }
jq -r '.data[] | "  \(.phone_number) \(.status) attempts=\(.attempts) outcome=\(.outcome)"' <<<"$recipients"
