Reputation: 26441
I would like to create a command on slack that after being invoked returns result to the issuer and also writes another message to specific channel.
Is this possible?
In the docs I've found that I can set in_channel
property but I would like to specify response being sent to specific channel or even limit command invocation to specific channel.
Upvotes: 0
Views: 862
Reputation: 32698
Yes, you can achieve that with a standard slash commmand. The slash command triggers your app which can then return the results to the user and also send a message to another channel with chat.postMessage
(provided your all has the necessary permissions).
Limiting the slash command invocation to specific channels is possible, but only works for public channels, because Slack will tell your app the name if the public channel it was invoked in, but not the name of a private channel.
For public channels your app will get the channel ID from where the slash command was invoked with every request. Your app can use that information to decide whether the command is permitted or not and respond accordingly.
For private channels you only get privategroup
as channel name, but not the real name or group ID. You can of course use this info to exclude usage of the command in all private channels, but not for specific ones.
Here is an example of the request your app gets from Slack:
token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
enterprise_id=E0001
enterprise_name=Globular%20Construct%20Inc
channel_id=C2147483705
channel_name=test
user_id=U2147483697
user_name=Steve
command=/weather
text=94070
response_url=https://hooks.slack.com/commands/1234/5678
trigger_id=13345224609.738474920.8088930838d88f008e0
Upvotes: 2