我正在尝试通过浏览器发布一条简单的消息,以解决问题。我可以使用在这里找到的方法上传完整的文件:
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,但是聊天未出现在频道中。我尝试过使用和不使用“ as_user”行。有什么想法吗?

最佳答案

我使用“通道”而不是“通道”作为键。那就是问题

09-25 15:55