Automated_Discord_Image_Pusher/push_discord.sh

34 lines
1.0 KiB
Bash

#!/bin/bash
#
# Purpose: Send image and message to a Discord webhook URL that will post the data to a Discord channel.
#
# Input arguments/parameters:
# 1. Image = $1
# 2. Message = $2
#
# Example:
# ./scripts/push_processors/push_discord.sh /srv/images/NOAA-18-20210212-091356-MCIR.jpg "test"
# import common lib and settings
#. "$HOME/.noaa-v2.conf"
#. "$NOAA_HOME/scripts/common.sh"
# input params
DISCORD_WEBHOOK=https://discord.com/api/webhooks/1328127093590196254/4qeyLRUweFwf8bBv_D9fOWq3xSQHzm2HEYZoKB_IyXRHxwd25byaICR3fd6Y2C2tttYQ
IMAGE=$1
MESSAGE=$2
# check that the file exists and is accessible
if [ -f "${IMAGE}" ]; then
# log "Sending message to Discord webhook" "INFO"
echo "Sending Message..."
push_log=$(curl -H "Content-Type: multipart/form-data" \
-F file=@$IMAGE \
-F "payload_json={\"content\":\"$MESSAGE\"}" \
$DISCORD_WEBHOOK 2>&1)
# log "${push_log}" "INFO"
else
# log "Could not find or access image/attachment - not sending message to Discord" "ERROR"
echo "Error..."
fi