└── toggle-slack-dnd ├── config.json ├── README.md └── toggle-slack-dnd.rb /toggle-slack-dnd/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pluginName": "Toggle Slack DnD", 3 | "pluginDescription": "Toggles Slack DnD and set status", 4 | "pluginReadMore": "", 5 | "protocolVersion": 1, 6 | "actions": 7 | [ 8 | { 9 | "actionName": "Toggle Slack DnD", 10 | "fileName": "toggle-slack-dnd.rb", 11 | }, 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /toggle-slack-dnd/README.md: -------------------------------------------------------------------------------- 1 | Toggle your Slack status and snooze notifications. Handy for running when you're going into or out of a call. Will let your teammates know you're unavailable. 2 | 3 | # Slack Token 4 | 5 | This script requires you to edit it and fill in the TOKEN variable with yoru Slack token. Get your token here: https://api.slack.com/custom-integrations/legacy-tokens 6 | 7 | # Flic button 8 | 9 | For running through a Flic.io button, read here how to install a plugin: http://macplugins.flic.io/ 10 | 11 | This whole directory can just be moved into that plugin directory. Make sure to install the `httparty` gem for the system ruby in case you're using RVM or rbenv. 12 | 13 | - david@crowdway.com 14 | 15 | -------------------------------------------------------------------------------- /toggle-slack-dnd/toggle-slack-dnd.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "httparty" 3 | 4 | # This is run using system ruby, not with rbenv etc 5 | # So to make sure it works, you need to: 6 | # 7 | # - disable rbenv temporarily by commenting out the `eval "$(rbenv init -)"` line in `rbenv.zsh` 8 | # - then in a new terminal run `sudo gem install httparty` 9 | # - chmod +x this script 10 | 11 | # Go here to get a token: 12 | # https://api.slack.com/custom-integrations/legacy-tokens 13 | 14 | BASE = "https://slack.com/api/" 15 | TOKEN = "" 16 | DURATION = 240 # snooze in minutes 17 | STATUS_TEXT = "In a meeting" 18 | STATUS_EMOJI = ":call_me_hand:" 19 | 20 | def get_slack(endpoint, query = {}) 21 | url = BASE + endpoint 22 | query[:token] = TOKEN 23 | 24 | HTTParty.get(url, query: query) 25 | end 26 | 27 | def post_slack(endpoint, body = {}) 28 | url = BASE + endpoint 29 | body[:token] = TOKEN 30 | 31 | HTTParty.post(url, body: body) 32 | end 33 | 34 | def snoozed? 35 | get_slack("dnd.info")["snooze_enabled"] 36 | end 37 | 38 | def set_snooze!(duration = DURATION) 39 | get_slack("dnd.setSnooze", num_minutes: duration) 40 | end 41 | 42 | def set_status!(status_text:, status_emoji:) 43 | profile = {status_text: status_text, status_emoji: status_emoji}.to_json 44 | 45 | post_slack("users.profile.set", profile: profile) 46 | end 47 | 48 | # Now do it! 49 | if snoozed? 50 | set_snooze!(0) 51 | set_status!(status_text: "", status_emoji: "") 52 | else 53 | set_snooze! 54 | set_status!(status_text: STATUS_TEXT, status_emoji: STATUS_EMOJI) 55 | end 56 | --------------------------------------------------------------------------------