How to configure slash command response to entire channel?

∥☆過路亽.° 提交于 2019-12-25 14:00:27

问题


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.



来源:https://stackoverflow.com/questions/43773761/how-to-configure-slash-command-response-to-entire-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!