2

Is there a way to programmatically send a command to Slack via the API? I'm successfully posting a message using

var postingResponse = client.UploadValues("https://slack.com/api/chat.postMessage", 
                      "POST", new NameValueCollection() {
                            {"token","<token>"},
                            {"channel","<ID>"}, 
                            {"text", "/mycommand hello" },
                            {"username","<username>" },
                            {"link_names", "true" },
                            {"parse", "full" }
                       });

This works well but the /mycommand hello is just printed as text instead of executing as a command. I tried adding a pair {"command", "/mycommand hello" } but nothing happened either.

Thanks

iso123
  • 89
  • 1
  • 3
  • 9
  • 1
    Possible duplicate of [How can I trigger a slash command in Slack every day at a certain time](https://stackoverflow.com/questions/43762414/how-can-i-trigger-a-slash-command-in-slack-every-day-at-a-certain-time) and [Execute slash command as slack bot](https://stackoverflow.com/questions/39829741/execute-slash-command-as-slack-bot) – Erik Kalkoken Jul 27 '17 at 16:07

2 Answers2

1

The command chat.command needs the permission scope post. However, this scope is now depracted (see list of all scopes).

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
0

I did not try it out by myself, but according to this answer there is the undocumented API method chat.command for executing commands in public channels. There is also a Python program for sending commands to slack.

user1364368
  • 1,474
  • 1
  • 16
  • 22