23

I'm writing a simple slack bot which should execute other slack commands upon being called. Everything is up and running, however the slack commands this bot issues don't seem to be executed.

For instance my bot posts /giphy kitten every hour and the message appears just like that in the channel (so the sending side seems to work), but the slash command itself isn't executed. If I post the same command into the same channel myself it works as expected. Are bots not allowed to execute slash commands?

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
ubuntudroid
  • 3,680
  • 6
  • 36
  • 60

2 Answers2

19

Bots can use the undocumented API method chat.command to invoke slash commands.

See here for an unofficial documentation page of this API method.

This question was also answered here.

Community
  • 1
  • 1
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • 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:06
  • @erik-kalkoken While trying chat.command, I am getting a missing scope error. What is the scope required for chat.command to work? I have tried both chat:write:bot & chat:write:user – nithishr Aug 06 '17 at 18:27
  • You need to provide scope `post` for the command to work. However, this scope does not seam to be available in the Slack app config window, so currently it only works with a legacy token I believe. – Erik Kalkoken Aug 08 '17 at 14:03
  • 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:41
  • @ErikKalkoken, I am able to execute slack command as user using the legacy token, how do I execute it as slack app? – Avin Apr 22 '20 at 04:43
  • 4
    @Avin You can't. It only works with tokens that have the `post` scopes, which only legacy tokens does and which is not available for Slack apps. – Erik Kalkoken Apr 22 '20 at 13:47
  • 3
    Is there still any way how to achieve this without the legacy tokens? It doesn't necessarily need to be a Slack app, I'd just like to periodically execute some commands in Slack. – nikicc Sep 08 '20 at 07:32
5

The command chat.command needs the permission scope post, which only legacy tokens have and which is not available for Slack apps.

I just asked the Slack customer support if sending slash commands programmatically is still possible and received the following reply:

I'm afraid not. Slash commands can only be triggered by human-sent messages from the client. Apologies.

b.geisb
  • 96
  • 2
  • 5