6

I want to trigger a slash command in Slack every day at a certain time. Specifically, I want to clear my status every night at midnight.

From the documentation it seems like the only way to do this would be via an Incoming Webhook. However POSTing with the following JSON body just creates a message in Slack /status clear and does not actually run the command.

'{"text":"/status clear"}'

It also posts the message on behalf of the app associated with the webhook, not under my username.

Is there any way to invoke a slash command for my user from outside the official Slack app?

MattL
  • 1,132
  • 10
  • 23
  • How about use of Google Apps Script? Google Apps Script has a trigger. https://developers.google.com/apps-script/reference/script/trigger Using this, you can use Slack API on the time you want. If I misunderstand your question, I'm sorry. – Tanaike May 04 '17 at 00:30
  • Possible duplicate of [Execute slash command as slack bot](http://stackoverflow.com/questions/39829741/execute-slash-command-as-slack-bot) – Erik Kalkoken May 04 '17 at 05:27
  • @Tanaike that provides a way to trigger the post at a certain time, but it does not answer my question about how to invoke a slash command as myself. – MattL May 08 '17 at 20:59
  • @ErikKalkoken this is not a duplicate as in this case I want to invoke the slash command as myself, not as a Slack bot. – MattL May 08 '17 at 21:00
  • 1
    You can get the same effect for ``/status clear`` by ``{"status_text": "", "status_emoji": ""}`` at ``users.profile.set``. In this case, you can also select the user name. Own status can be cleared by sending this using Google trigger. – Tanaike May 08 '17 at 22:23
  • @Tanaike thank you for `users.profile.set` I was looking for that and it can be used with slack application token for whole team :) – kunicmarko20 Jun 29 '17 at 08:41
  • @Marko Kunic I'm glad it could be useful for you. Thank you, too. – Tanaike Jun 29 '17 at 08:56

1 Answers1

7

Here is how to execute slash command for your user with an external script.

  1. Use the undocumented API method chat.command execute any slash command, e.g. /status

  2. Use an access token linked to your user account for the API call. One way to get that is to create a so-called "legacy token" with your user.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • 1
    I was stumbling across the exact same problem, so I did a bit of coding and a working example is here: https://github.com/dazlious/slack-cmd-trigger You can trigger with your api-token any channel with a command. – dazlious Jun 02 '17 at 21:05
  • 6
    Is there any other way to be able to execute slack commands from a slack app, now that slack's legacy tokens are deprecated. – Avin Apr 21 '20 at 05:27
  • 1
    Unfortunately, there currently is no way to execute slash commands programmatically. @Avin – b.geisb Apr 08 '22 at 12:11