There are many ways to find the channel id.
The simplest is, to use the Slack browser application and copy the channel id from the URL after you enter the channel.
The URL looks like https://app.slack.com/client/xxx/C0XXXXXXXX
.
The Channel id is the last segment, starting with a 'C'.
https://api.slack.com/tutorials/tracks/posting-messages-with-curl
Select the workspace and make sure there are the right scopes: chat:write, chat:write.public
At the end, there is an overlay on top of the page with the headline "Your're all set for now!".
Press the link "Posting messages using curl" and get back to the page from step 1.
You are back on the "Posting messages using curl".
The "Create app" is gone.
There is now a black box with your token.
$channelId = "Cxxxxxxxxxx";
$token = "xoxb-xxxxxxx-xxxxxx-xxxxxx";
$ch = curl_init();
$message = [
"channel" => $channelId,
"blocks" => [
[
"type" => "section",
"text" => [
"type" => "mrkdwn",
"text" => "This is a *test-message*"
]
]
]
];
curl_setopt_array($ch, [
CURLOPT_URL => "https://slack.com/api/chat.postMessage",
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json; charset=UTF-8',
"Authorization: Bearer {$token}"
],
CURLOPT_POSTFIELDS => json_encode($message)
]);
$content = curl_exec($ch);
$header = curl_getinfo($ch);
Another way to post messages in a channel is incoming webhooks.