所以使用 curl 我可以成功地将发布请求发送到 slack
curl -X POST --data-urlencode 'payload={"channel": "#tech-experiment", "username": "at-bot", "text": "This is posted to #general and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https:/company.slack.com/services/hooks/incoming-webhook?token=dddddddd2342343
但是,当我使用 nodejs 将其转换为代码时
var request = require('request');
var http = require('http');
var server = http.createServer(function(req, response){
response.writeHead(200,{"Content-Type":"text/plain"});
response.end("end");
});
option = {
url: 'https://company.slack.com/services/hooks/incoming-webhook?token=13123213asdfda',
payload: '{"text": "This is a line of text in a channel.\nAnd this is another line of text."}'
}
request.post(
option,
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}else {
console.log('wtf')
console.log(response.statusCode)
console.log(response)
console.log(error)
}
}
);
它抛出状态 500。有人可以帮忙吗?
我审查了令牌也做了我的研究,但没有任何工作..
感谢您的帮助