Bulk Adding Slack Reactions (Emojis) to Mattermost
Lastmod: 2025-01-21
Published: 2022-09-29

Since Slack’s log retention period has been reduced to 90 days, making it harder to view past logs, I decided to implement Mattermost. Here’s a note on how I copied custom emojis (reactions) from Slack to Mattermost.

Extracting Reactions from Slack

Initially, I planned to extract the reactions using Slack’s API, but using the Chrome extension Slack Custom Emoji Manager made it very easy to download them.

Install the Chrome extension and access https://.slack.com/emoji, then click “Download all emojis.”

Importing to Mattermost

We will use curl and the API to register the emojis in bulk. Note that while Slack allows Japanese names for reactions, Mattermost cannot register multibyte names, so you need to modify any reactions with Japanese names before proceeding.

Creating a Bot to Obtain the Access Token

  1. Select “Integrations.”
  2. Select “Bot Accounts.”
  3. Click “Add Bot Account.”
  4. Create the account. Set the role to “System Administrator.”
  5. Remember the issued token.

Obtaining the Bot’s User ID

To register emojis, you need the bot’s user ID. Use the API to get the bot’s user ID.

$ TOKEN="Your TOKEN"
$ CREATE_ID=$(curl -s -X GET -H "Authorization: Bearer ${TOKEN}" https://<Mattermost URL>/api/v4/users/me | jq -r .id)
$ echo $CREATE_ID

This should store the bot’s user ID in the CREATE_ID variable.

Registering Emojis in Bulk Using the API Token and Bot ID

Place the downloaded emojis in a directory and execute the following script:

$ TOKEN="Your TOKEN"
$ CREATE_ID="Your Bot's User ID"
$ for file in $(ls)
do
    name=$(echo $file | cut -d . -f 1)

    curl -X POST -H "Authorization: Bearer ${TOKEN}" \
             -H "Content-Type: multipart/form-data" \
             -F "emoji={\"name\":\"${name}\",\"creator_id\":\"${CREATE_ID}\"}" -F "image=@./${file}" \
             https://<Mattermost URL>/api/v4/emoji
done

This will register the files as emojis using their filenames.