booking_sms.sh 656 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. : ${SMS_API:=https://room-api.sea.zi3.fi}
  3. : ${SMS_TOKEN:=foobar}
  4. if [[ -z "$SMS_API" ]]; then
  5. echo "booking_sms: SMS_API not set" 1>&2
  6. exit 0
  7. fi
  8. # Read the full email from stdin and extract the first 6-digit Extranet code.
  9. code=$(grep -oP 'Extranet code: \K[0-9]{6}' | head -1)
  10. if [[ -z "$code" ]]; then
  11. echo "booking_sms: no Extranet code found in message" >&2
  12. exit 0 # exit 0 so Sieve doesn't treat it as a filter failure
  13. fi
  14. # Upload
  15. echo curl -fsS \
  16. -X POST \
  17. -H "Content-Type: application/json" \
  18. -H "X-SMS-Secret: ${SMS_TOKEN}" \
  19. -d "{\"code\": \"${code}\"}" \
  20. "${SMS_API%/}/sms/code"
  21. # Always clean for Sieve
  22. exit 0