This method posts a message to a channel.
Official documentation | https://api.slack.com/methods/chat.postMessage |
Payload class |
ChannelsArchivePayload |
PayloadResponse class |
ChannelsArchivePayloadResponse |
$apiClient = new ApiClient('your-slack-token-here');
$payload = new ChatPostMessagePayload();
$payload->setChannel('#general');
$payload->setMessage('Hello world!');
$response = $apiClient->send($payload);
if ($response->isOk()) {
// message has been posted
} else {
// something went wrong, but what?
// simple error (Slack's error message)
echo $response->getError();
// explained error (Slack's explanation of the error, according to the documentation)
echo $response->getErrorExplanation();
}