i'm creating a really small slash command for my channel right now. I send the command to a PHP script using HTTPS 200, manipulate it and send it back as JSON payload, basically like this:
<?php
header('Content-Type: application/json');
$text = $_POST['text'];
if ($text === "keyword") $answer = "Hello World";
else $answer = "Nothing in here";
$response = array(
'response_type' => 'in_channel',
'text' => $answer,
);
echo json_encode($response);
Now I don't want to post the intial slash commend in the channel as already mentioned in the title but only the answer of the server should be visible for everyone in the channel. I can't find a suitable article for this, so I ask myself: Is it even possible?
Anybody have an idea?
Edit: I dont want that slack also post my command as message. So that only the second message is post in the channel: see a screenshot
Update: I have now implemented the suggestion of Erik Kalkoken but I don't get a signal from the curl function. I also successfully checked if my webserver supports the curl functions. My code now looks like this (the code has been reduced to the necessary):
<?php
header('Content-Type: application/json');
$response = array(
'response_type' => 'in_channel',
'text' => "> \\M2\Kunden\_Tutorial"
);
echo json_encode(array('text' => 'One moment...'));
$ch = curl_init($_POST['response_url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
$exec = curl_exec($ch);
curl_close($ch);
Working Solution: After taking Erik Kalkoken's advice into account again, it still didn't work. Which doesn't mean that he said something wrong. On the contrary, I forgot something. I found out that my $response array needs to be encoded as json string. Below you can see a working version. Thanks to Erik Kalkoken!
<?php
$response = array(
'response_type' => 'in_channel',
'text' => '> \\M2\Kunden\_Tutorial'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_POST['response_url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close ($ch);