Skip to content

Instantly share code, notes, and snippets.

@alejandro-isaza
Last active July 6, 2018 23:17
Show Gist options
  • Save alejandro-isaza/d3e3361e6737626e3675fd9b82045635 to your computer and use it in GitHub Desktop.
Save alejandro-isaza/d3e3361e6737626e3675fd9b82045635 to your computer and use it in GitHub Desktop.
Change your slack status from the command line with custom presets.
#!/usr/bin/env ruby
#
# Instructions:
# 1. Get personal Slack legacy tokens from https://api.slack.com/custom-integrations/legacy-tokens
# 2. Save this in ~/bin/ss and add $HOME/bin to your PATH so that you can invoke it easily.
# 3. Add custom status presets below.
# 4. Run `ss lunch` to test
require 'net/http'
require 'json'
require 'pp'
# Get legacy tokens at https://api.slack.com/custom-integrations/legacy-tokens
SLACK_TOKENS = [
'xoxp-secret-token-1',
'xoxp-secret-token-2'
].freeze
# Add status presets below
profile = {}
case ARGV[0]
when 'lunch'
profile = {
status_text: 'Having lunch',
status_emoji: ':shallow_pan_of_food:'
}
when 'meeting'
profile = {
status_text: 'In a meeting',
status_emoji: ':clipboard:'
}
when 'wfh'
profile = {
status_text: 'Working from home',
status_emoji: ':house:'
}
when 'coding'
profile = {
status_text: 'Coding',
status_emoji: ':nerd_face:'
}
when 'coffee'
profile = {
status_text: 'Out for a coffee',
status_emoji: ':coffee:'
}
when 'social'
profile = {
status_text: 'Socializing',
status_emoji: ':beer:'
}
when 'clear'
profile = {
status_text: '',
status_emoji: ''
}
else
puts 'Invalid status preset'
abort(1)
end
uri = URI.parse('https://slack.com/api/users.profile.set')
SLACK_TOKENS.each do |token|
res = Net::HTTP.post_form(uri, 'token' => token, 'profile' => profile.to_json)
if res.is_a?(Net::HTTPSuccess)
puts 'Success'
else
puts res.body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment