Skip to content

Instantly share code, notes, and snippets.

@thealanberman
Created September 7, 2018 07:05
Show Gist options
  • Save thealanberman/8000791b87c13ce36798bee1ea555587 to your computer and use it in GitHub Desktop.
Save thealanberman/8000791b87c13ce36798bee1ea555587 to your computer and use it in GitHub Desktop.
Bulk Emoji Uploader for Mattermost 5.x (v4 api)
#!/usr/bin/env bash
if [[ -d "${1}" ]]; then
dir="${1}"
else
echo "USAGE: $(basename "${0}") /path/to/emoji/folder"
exit
fi
read -r -p "Server Hostname: " MMSERVER
read -r -p "Username: " YOUR_USERNAME
read -r -s -p "Password: " VALID_PASSWORD
curl -c cookies.txt -d "{\"login_id\":\"${YOUR_USERNAME}\",\"password\":\"${VALID_PASSWORD}\"}" "https://${MMSERVER}/api/v4/users/login" || exit
MMAUTHTOKEN=$(grep MMAUTHTOKEN cookies.txt | cut -f7)
MMUSERID=$(grep MMUSERID cookies.txt | cut -f7)
pushd "${dir}"
for filename in *.png *.jpg *.gif; do
NAME=$(basename "${filename}" | cut -d '.' -f1)
IMAGE="@${dir}/${filename}"
FILENAME="${filename}"
EMOJI="{\"name\":\"${NAME}\",\"creator_id\":\"${MMUSERID}\"}"
curl -i -X POST -H "Authorization: Bearer ${MMAUTHTOKEN}" \
-H "Content-Type: multipart/form-data" \
-F "image=${IMAGE}" -F "filename=${FILENAME}" \
-F "emoji=${EMOJI}" -k "https://${MMSERVER}/api/v4/emoji"
done
popd
rm cookies.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment