Created
September 27, 2018 16:37
-
-
Save serkanh/7493538801411503c2c79e3a6cf1523c to your computer and use it in GitHub Desktop.
Slack query script
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/sh | |
#set -ox | |
#either pass slack token as a param or env var SLACK_TOKEN=${1:SLACK_TOKEN} | |
SLACK_TOKEN=${SLACK_TOKEN} | |
# Get the list of channels | |
# https://api.slack.com/methods/channels.list/test | |
function getChannels(){ | |
curl -s "https://slack.com/api/channels.list?token=${SLACK_TOKEN}&pretty=1" | jq '.channels[]|{name:.name,id:.id}' | |
} | |
# Get the list of all users | |
# https://api.slack.com/methods/users.list/test | |
function getUsers(){ | |
curl "https://slack.com/api/users.list?token=${SLACK_TOKEN}&pretty=1" | |
} | |
# Get the list of all users | |
# https://api.slack.com/methods/users.list/test | |
function getUsersName(){ | |
curl -s "https://slack.com/api/users.list?token=${SLACK_TOKEN}&pretty=1" | jq '.members[]|select(.is_bot==false)|{name:.name,real_name:.real_name}' | |
} | |
function getActiveBots(){ | |
getUsers | jq '.members[]|select(.is_bot==true)' | |
} | |
while [ "$1" != "" ];do | |
case $1 in | |
# set the token if not set as env var. | |
-t | --token ) | |
shift | |
SLACK_TOKEN=$1 | |
export SLACK_TOKEN | |
;; | |
-h | --help) | |
usage | |
exit | |
;; | |
-b | --getbots) | |
getActiveBots | |
exit | |
;; | |
-u | --getusersNames) | |
getUsersName | |
exit | |
;; | |
-a | --getUsers) | |
getUsers | |
exit | |
;; | |
-c | --getchans) | |
getChannels | |
exit | |
;; | |
*) usage | |
exit 1 | |
esac | |
shift | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment