← back to Launchd Reminders

twitter-token-reminder.sh

56 lines

#!/usr/bin/env bash
# One-shot reminder set on 2026-05-01: 1-week followup on the missing
# TWITTER_BEARER_TOKEN that's keeping norma-twitter functionally crippled.
# Sends email via George (local Mac, :9850), then self-removes.
set -uo pipefail

LABEL="com.steve.twitter-token-reminder"
PLIST="$HOME/Library/LaunchAgents/${LABEL}.plist"
LOG="$HOME/Projects/launchd-reminders/logs/twitter-token.log"

mkdir -p "$(dirname "$LOG")"
exec >> "$LOG" 2>&1
echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] firing twitter-token reminder"

read -r -d '' BODY <<'EOF'
One week ago (2026-05-01), `norma-twitter` was logging
`No TWITTER_BEARER_TOKEN configured — read operations will fail` on every poll
cycle (358 KB error log). The log-spam was patched (warning now emits once per
boot), but the underlying functional gap remains: the agent can't read tweets.

**Action items**
1. Get a Twitter API v2 bearer token from https://developer.twitter.com — use
   the Norma natalia@studentdebtcrisis.org dev account if Norma's the
   intended owner.
2. Paste the token into chat with Claude as `TWITTER_BEARER_TOKEN=AAA...`. The
   /secrets skill auto-routes it to Norma's `loadCredentials('twitter')` path.
3. `pm2 restart norma-twitter` once the token is in place.
4. Verify: tail ~/.pm2/logs/norma-twitter-out.log — the boot warning should be
   absent (token loaded successfully).

**Or**: if Norma doesn't actually need Twitter reads, kill the agent:
`pm2 delete norma-twitter && pm2 save`
EOF

PAYLOAD=$(jq -n --arg to 'steve@designerwallcoverings.com' \
                --arg subject 'norma-twitter: still missing TWITTER_BEARER_TOKEN (1 week)' \
                --arg body "$BODY" \
                '{to:$to, subject:$subject, body:$body}')
# Run curl on its own line so $? reflects curl's exit code, not the assignment.
# --fail makes HTTP 4xx/5xx a non-zero exit so a rejected send doesn't self-clean.
RESP=$(curl -sS --fail -X POST 'http://localhost:9850/api/send' \
  -u 'admin:DWSecure2024!' \
  -H 'Content-Type: application/json' \
  -d "$PAYLOAD" 2>&1)
RC=$?
echo "George response (rc=$RC): $RESP"

if [ "$RC" -eq 0 ]; then
  launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true
  rm -f "$PLIST"
  rm -f "$0"
  echo "self-cleaned: removed plist + script"
else
  echo "send failed; leaving plist in place — investigate then rm manually"
fi