Slack slash commands - show user-entered text?

From Slack's /Command API Docs:

In Channel" vs "Ephemeral" responses

By default, the response messages sent to commands will only be visible to the user that issued the command (we call these "ephemeral" messages). However, if you would like the response to be visible to all members of the channel in which the user typed the command, you can add a response_type of in_channel to the JSON response, like this:

{ "response_type": "in_channel", "text": "It's 80 degrees right now.", "attachments": [ { "text":"Partly cloudy today and tomorrow" } ] }

I think you need to set response_type to "in_channel" to allow other users to see the response.


I was having this problem recently and even came across this question. The answer is spread across two places in the slash command documentation. Under the '"In Channel" vs "Ephemeral" responses' heading:

By default, the response messages sent to commands will only be visible to the user that issued the command (we call these "ephemeral" messages). However, if you would like the response to be visible to all members of the channel in which the user typed the command, you can add a response_type of in_channel to the JSON response, like this.

Then later, when talking about delayed responses (which a request from a node server will be):

The only user-facing difference between immediate responses and delayed responses is that "in channel" delayed responses will not include the initial command sent by the user. To echo the command back to the channel, you'll still need to provide a response to Slack's original visit to your invocation URL.

So at the end of your initial request to the server the bot is on, you'll want to send a response looking something like

response.send({"response_type": "in_channel"});

which will echo back /command. Shortly after, when the response from the image fetching request comes back, posting to the response_url will send the payload back to slack and it will be printed under the echoed out /command.


I believe it has to do with the difference between 'immediate response' and 'delayed response'.

When I send my messages through cURL, it doesn't show the slash command 'in channel'. I found that if I merely included header('content-type header: application/json'), and echo'd my response with a json payload including 'in_channel', the slash command showed up. No API required!

Example:

$reply = "Whatever you want";
    $data = array(
        "response_type"=>"in_channel",
        "text"=>$repy,
        );
    header('Content-Type: application/json');
    echo json_encode($data);

Hope this helps, this is my first post, so be gentle if I broke any unspoken rules of stackoverflow.