Helper function (Bash)

This is an example of a Bash function that you can save and use in your scripts to trigger notifications when needed.

Example
#!/usr/bin/env bash

# Notify17 helper function (Bash)
#
# Usage: n17 "TITLE" ["CONTENT"]
# 
# This script can both be sourced (when using Bash), or directly executed
#
# Requires N17_API_KEY environment variable to be set
function n17() {
  # Subshell to not propagate options around
  (
  set -Eeumo pipefail
  
  # Required
  TITLE="${1:-}"
  # If not provided, will be an empty string
  CONTENT="${2:-}"
  
  # Expects N17_API_KEY to be an environment variable
  if [[ -z "${N17_API_KEY:-}" ]]; then 
    echo "Missing N17_API_KEY env variable!" 
    return 1
  fi
  
  if [[ -z "$TITLE" ]]; then
    echo $'Title is required.\n\nUsage: n17 "TITLE" ["CONTENT"]'
    return 1
  fi

  # Makes the request to Notify17 backend, and keeps track both of status code
  # and response content.
  
  # Stores the request response in a temporary file
  RESPONSE_FILE=$(mktemp)
  STATUS=$(curl -sS -o ${RESPONSE_FILE} -w "%{http_code}" \
    -X POST "https://hook.notify17.net/api/raw/${N17_API_KEY}" \
    -H "Accept: text/plain" \
    -F title="$TITLE" \
    -F content="$CONTENT") || {
        # General curl error
        ERROR_CODE="$?"
        STATUS="999"
        echo "Curl error: $ERROR_CODE" > ${RESPONSE_FILE}
    }
      
  if [[ "$STATUS" -gt 255 ]]; then
    echo "Failed to trigger Notify17 alert (code $STATUS): $(cat ${RESPONSE_FILE})"
  fi
  
  # Clean tmp response file
  rm ${RESPONSE_FILE}
  )
}

# Check if this script has been sourced or not (Bash only)
# https://stackoverflow.com/a/28776166/3671330
(return 2>/dev/null) || {
  # Script has been directly executed, so pass the args to n17 function
  n17 $@
}