我正在尝试从浏览器向 slack 发布一条简单的消息。我能够使用我在这里找到的方法上传完整文件: https://stackoverflow.com/a/45600450/2278676
但是当我将其转换为 chat.postMessage
API 时,如下所示,没有任何帖子。我知道这一定是我错过的一些简单的事情,因为我可以上传文件,只是不能发布文本!
var mData = new FormData();
mData.append('token', 'my_token');
mData.append('channels', 'my_channel');
mData.append('text', 'test message');
mData.append('as_user', 'true');
var xhr = new XMLHttpRequest();
xhr.open('POST','https://slack.com/api/chat.postMessage', true);
// Set up a handler for when the request finishes.
xhr.onload = function () {
if (xhr.status === 200) {
// File(s) uploaded.
console.log("posted");
} else {
alert('An error occurred!');
}
};
xhr.send(mData);
我在网络选项卡中收到“已发布”控制台日志和状态代码:200,但聊天未出现在 channel 中。我尝试过使用和不使用“as_user”行。有什么想法吗?
最佳答案
我使用“channels”作为键而不是“channel”。这就是问题所在
关于javascript - 通过 JS 和 API 向 slack 发布消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45643255/