Created
October 22, 2024 17:11
-
-
Save NeilMasters/9e7007b1452355e004af343ca767a76d to your computer and use it in GitHub Desktop.
Play a sound file when a user posts a message into a specific slack channel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
########################################################################### | |
# | |
# Very very rough script! Does not work well! | |
# | |
# Will monitor a slack channel (has to be public unless you give it special | |
# permissions) for a specific user and if there is a message in the last 30 | |
# seconds will play a sound file of your choosing. Obviously not great | |
# for conversational channels. | |
# | |
# afplay is obviously for macs, switch to your own variant. | |
# | |
# ./monitor-for-person.sh {channel_id} {user_id} | |
# | |
########################################################################### | |
CHANNEL_ID=$1 | |
NOW=$(date +%s) | |
POLL_HISTORY="$(($NOW-45))" | |
USER_ID=$2 | |
SLACK_BEARER_TOKEN="" | |
while true | |
do | |
echo "Searching for any messages since ${POLL_HISTORY} in channel ${CHANNEL_ID} for user ${USER_ID} every 30 seconds" | |
HAS_MESSAGES=$(curl --silent "https://slack.com/api/conversations.history?channel=${CHANNEL_ID}&oldest=${POLL_HISTORY}" \ | |
-H "Authorization: Bearer ${SLACK_BEARER_TOKEN}" \ | |
| jq -r ".messages[] | select(.user | contains(\"${USER_ID}\"))") | |
if [ -z "${HAS_MESSAGES}" ]; then | |
echo "No messages found... yet..." | |
else | |
echo "Uh oh..." | |
# A janky sound clip I made, replace with your own or do a cb function | |
afplay ~/Downloads/Record\ \(online-voice-recorder.com\).mp3 | |
fi | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment