Execute slash command as slack bot

14,069

Solution 1

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.

Solution 2

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.

Share:
14,069

Related videos on Youtube

ubuntudroid
Author by

ubuntudroid

Android engineer since 2009 (fragmentation was not an issue back then as there was just the emulator - good times :D). Productivity geek - I have probably tried out all relevant productivity systems and apps out there. My dark bane, but at the same time my biggest driver. Also avid gamer, history buff, tech lover and Indiegogo/Kickstarter addict. Always on the hunt for new technologies and optimizations - cannot get enough of new, fancy, geeky stuff! If I build things myself the most important thing is: the product of my work has to be of great usability, expandability and maintainability as well as ethically and morally unquestionable (no greyzones here!). In most situations my target groups are end users as well as other developers. I tend to spend an equal amount of time on code optimizations regarding flexibility and expandability of software projects as on the development of new features. Less than the achievement of these goals is usually not acceptable for me - and I'm motivating my collaborators to behave like this, too. Nevertheless I'm not a pedant and tend to behave pragmatically. And I'm a firm believer of teamwork and team spirit: together two people can achieve way more than each of them alone - but equally important are the times where you completely disconnect and just focus. The latter being one of the reasons why I firmly believe in the idea of working remotely. In the last two years I've also invested quite some time into iOS development, specifically with Kotlin Native. And lately one more thing is bothering me more and more: "meaning" in what I'm doing and how. For me that boils down to improving the world we live in - even if it is just a tiny bit. We make thousands of decisions every day and many of them just mindlessly choosing to ignore all the tiny opportunities there are to change the state of things - just because we do what everyone does and hide behind that. People may call me boring looking at my pretty conservative lifestyle, but there are possibilities for tiny little revolutions in everything we do - in every smile when we enter a room, every encouragement we choose to give, spending time with our family instead of our phone (and oh my, I'm struggling quite a bit here), and, yes, also every piece of user data we choose to NOT forward to third party services when writing user facing software. Many small decision which alone themselves don't change the world - but imagine we all chose to make every fifth decision mindfully... Certainly nothing I myself could ever hope to achieve, but better die trying than not trying at all. That's what provides meaning to my life, even if I fail at least a dozen times a day. Find me on LinkedIn: https://www.linkedin.com/in/svenbendel/.

Updated on October 28, 2021

Comments

  • ubuntudroid
    ubuntudroid over 2 years

    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?

  • dazlious
    dazlious almost 7 years
    I was stumbling across the exact same problem, so I did a bit of coding and a working example is here: github.com/dazlious/slack-cmd-trigger You can trigger with your api-token any channel with a command.
  • nithishr
    nithishr over 6 years
    @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
  • Erik Kalkoken
    Erik Kalkoken over 6 years
    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.
  • Avin
    Avin about 4 years
    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
    Avin about 4 years
    @ErikKalkoken, I am able to execute slack command as user using the legacy token, how do I execute it as slack app?
  • Erik Kalkoken
    Erik Kalkoken about 4 years
    @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.
  • nikicc
    nikicc over 3 years
    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.

Related