Slack 机器人无法将消息发送到带有 - 或 space(例如 "channel-name")的频道
Slack bot can't send a message to a channel with - or space like "channel-name"
我的 slack bot 无法将消息发送到带有 space 或 - 类似“频道名称”的频道,但适用于单字频道。
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://slack.com/api/chat.postMessage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{ \"channel\": \"channel-withspace\",\"text\": \"hello\"}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer <here>"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
这里是错误:
{"ok":false,"error":"not_in_channel","warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}
找到答案,原来我需要通过在频道中输入消息来邀请机器人:
/invite @channel-name
在这里找到答案:
您可以将以下范围添加到您的机器人到 post 消息到 public 频道,而无需邀请机器人加入频道。
范围: chat:write.public
Send messages to channels @your_slack_app isn't a member of
我的 slack bot 无法将消息发送到带有 space 或 - 类似“频道名称”的频道,但适用于单字频道。
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://slack.com/api/chat.postMessage",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{ \"channel\": \"channel-withspace\",\"text\": \"hello\"}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Bearer <here>"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
这里是错误:
{"ok":false,"error":"not_in_channel","warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}
找到答案,原来我需要通过在频道中输入消息来邀请机器人:
/invite @channel-name
在这里找到答案:
您可以将以下范围添加到您的机器人到 post 消息到 public 频道,而无需邀请机器人加入频道。
范围: chat:write.public
Send messages to channels @your_slack_app isn't a member of