7

My company has recently switched to Slack, and I'm really enjoying it so far. I'm learning about Slack Custom commands, and I would like to try writing a few.

One of the first ideas I had was to create a shortcut for going away -- either for lunch, or for a short break. When I go to lunch, I set my status as "Away" with the /away command, and snooze notifications with /dnd 1 hour. It would be nice if I could create a custom Slack command, called /lunch that does both of these things, and another one called /back that switches back to Online and not Snoozed.

All of the documentation for Custom Commands is oriented towards interfacing with an external API, but is there a way to write a custom command that triggers actions within Slack itself? Would this require using the Slack API?

Russell Stewart
  • 1,960
  • 4
  • 24
  • 31

1 Answers1

3

Yes, you would have to use the Slack API. But that's fine, because it's really fun to use :)

You can programmatically set your away preference with this method: https://api.slack.com/methods/users.setPresence

And you can set your do not disturb duration with this one: https://api.slack.com/methods/dnd.setSnooze

The guide for getting started with a custom integration is here.

Hope this helps :)

Wilhelm Klopp
  • 5,030
  • 2
  • 29
  • 37
  • Great! I was hoping this might work. So then I assume that this will automatically set those values for the currently authenticated user? Also, is it possible to have it echo a command/message back to the screen? I.e., something like `/me is taking a break`? – Russell Stewart Mar 07 '16 at 17:32
  • It is definitely possible to echo back a message. This is the easy part. In terms of dealing with it on a per user basis, this might be more difficult if you require explicit OAuth scopes. Check https://api.slack.com/docs/oauth-scopes for whether you do. – Wilhelm Klopp Mar 08 '16 at 01:46
  • If I understand this response correctly, then there is no easy way to set up a macro or batch of commands? For example, when creating a new channel, I currently (manually) run a series of /poll commands to create and pin a number of polls to the new channel. It's a bit of tedious copy/pasting, followed by some tedious UI selection and confirmation. If I could copy/paste the whole set of commands (or a macro/script/alias/batch) in a single action, it would make the process much cleaner and easier. So, do you know if this is possible or not? I'm still trying to figure it out. – Pseudothink Nov 11 '16 at 18:28
  • @Pseudothink this is not possible with Slack's API, as slash commands (such as /poll) need to be invoked by the user. But with Selenium, anything is possible ;) – Wilhelm Klopp Nov 11 '16 at 18:31