#!/usr/bin/env bash
# Build: multi-channel cart recovery
# A three-step abandonment sequence in one command: email first, then SMS a day later only if they still have not booked. Multi-channel recovery is where the measurable revenue is.
#
# Category : Revenue
# Safety   : WRITES DATA, read before running
# Uses     : workflows create, email-templates list, sms-templates list
# Returns  : A live abandonment workflow with an email and an SMS leg.
#
# Requires the SendSquared CLI and jq:
#   curl -fsSL https://cli.sendsquared.com/install.sh | bash
#   sendsquared auth login
#
# Free to use and adapt. https://sendsquared.com/cli/scripts/#build-cart-abandon-recovery

# Build multi-channel cart abandonment recovery. Run once.
# Usage: ./build-cart-abandon-recovery.sh <emailTemplateId> <smsTemplateId>
set -euo pipefail
EMAIL=${1:?pass an email template id}
SMS=${2:?pass an sms template id}

STEPS=$(cat <<JSON
[
  { "type": "Wait",  "value": "1h",     "label": "Give them an hour to come back on their own" },
  { "type": "Email", "value": $EMAIL,   "label": "Recovery email" },
  { "type": "Wait",  "value": "1d",     "label": "Wait a day" },
  { "type": "Sms",   "value": $SMS,     "label": "SMS nudge if still unbooked" }
]
JSON
)

sendsquared workflows create \
  --name "Cart abandonment recovery" \
  --description "Email, then SMS a day later, for abandoned booking carts." \
  --trigger-type cart_abandon \
  --trigger-value cart_abandon.created \
  --steps "$STEPS"
