Kri*_*ont 2 slack-api slack slack-commands
我的 Slack 机器人无法向带有空格或类似“频道名称”的频道发送消息,但对于单字频道效果很好。
$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;
Run Code Online (Sandbox Code Playgroud)
这是错误:
{"ok":false,"error":"not_in_channel","warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}
Run Code Online (Sandbox Code Playgroud)
找到了答案,事实证明我需要通过在频道中输入消息来邀请机器人:
/invite @bot-name
Run Code Online (Sandbox Code Playgroud)
在这里找到答案:https ://stackoverflow.com/a/61369364/5159914
| 归档时间: |
|
| 查看次数: |
2473 次 |
| 最近记录: |