#!/usr/bin/env bash
# Place one outbound call. Needs: curl, jq.
set -euo pipefail
BASE="${RELATIONSAI_API_BASE:-https://voice-api.relationsai.com/v1}"
AGENT_ID="${AGENT_ID:-agent_1ZltiWzxrXmMprGD6q63}" # the test-mode Sample agent unless you set your own
TO="${TO:-+12025550100}"

call=$(curl -sS --fail-with-body -X POST "$BASE/calls" \
  -H "Authorization: Bearer $RELATIONSAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg agent "$AGENT_ID" --arg to "$TO" '{
        agent_id: $agent,
        to: $to,
        variables: { first_name: "Asha" },
        metadata: { crm_record_id: "L-1042" }
      }')") || { echo "$call" >&2; exit 1; }

jq -r '"\(.id) status=\(.status) livemode=\(.livemode)"' <<<"$call"
