You can easily grab files from your devices  and post them to Slack using Slack API's Legacy Token and a simple curl command.    


Creating Your Slack Token

To start posting to Slack, you'll first need to generate an API Legacy Token. Head over to Slack's Legacy Token generator and create a new token.   


Take some time to read the safety considerations. Slack API Legacy Tokens provide powerful tools for modifying your Slack workspace and you be used carefully.


Uploading Files

Now that you have your token, here's the simplest method for uploading files from Addigy. These commands can easily be run right on the Devices page. Simply replace the text after file=, channels=, and token= with your desired file on the target device, the channel it should be sent to, and your Legacy Token.


curl -F file=@/tmp/dramacat.gif -F channels=#general -F token=xxxx-xxxxxxxxx-xxxx https://slack.com/api/files.upload


Here's what successfully running the above command within Addigy on the Devices page should look like.



And this is what the upload will look like in Slack.



Get Creative

This simple integration can really do a lot if you or your customers use Slack. Here in the Addigy Support team, we commonly use Slack as a simple method for collecting and uploading device logs.


This script is a sample how you could quickly pull logs from your device into your Slack workspace.


#!/bin/bash

# Enter your own Legacy Slack API code to upload. Revoke after running.
#   https://api.slack.com/custom-integrations/legacy-tokens
device=$(hostname | awk -F'.' '{print $1}')
file_name="${device}_log_upload.tar.gz"
file_path='/Library/Addigy/logs'
slack_token='xxxx-xxxxxxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx'

# Create System Information export
system_profiler -xml > ${file_path}/system_information.spx

cd "$file_path" || (echo "Could not cd to $file_path. Exiting..." && exit 1)
tar -czvf "$file_name" ./*
curl -F file=@./"$file_name" -F channels=#log_uploads -F token="$slack_token" https://slack.com/api/files.upload
rm "./$file_name"
rm "${file_path}/system_information.spx"


Scripts like this can easily be run from the Predefined Commands section on the Devices page. For more insight on running Predefined Commands, check out our article Creating and Running Scripts.