How to configure slash command response to entire

2019-09-15 16:30发布

问题:

I'm currently using the "Isitup" slack slash command example authored by David McCreath (more here": https://github.com/mccreath/isitup-for-slack/blob/master/isitup.php).

Within this code, I am wondering how I would go about making the response go from appearing "only to me" to posting in to the entire channel, along with the query posted by the user. I've read the slack documentation which shows the "in_channel" parameter that needs to be added, however I am just not that strong with code so I'm really not sure where I should input this in to the code I've got.

I'm sure this is a simple fix - can someone provide assistance? I've searched everywhere and can't seem to find a comprehensive answer.

回答1:

As you correctly mentioned the trick is to reply to Slack by setting the property response_type to in_channel.

The current code (as per your github link) is replaying to Slack with a simple plain text in the following line:

echo $reply;

In order to set the response_type property it needs to reply with a JSON array instead that should look like this:

{
    "response_type": "in_channel",
    "text": "It's 80 degrees right now."
}

All you need to do is build a PHP array with those two properties, convert it to JSON with json_encode() and send it back to Slack instead of the plain text.