我的 Node 后端有以下带有快速中间件的路由。我的应用程序使用 Slack 反斜杠 api 发布指向用户 channel 的链接。当用户单击时,它会在 Heroku 上托管的 Angular 应用程序上打开一个表单。
我想要做的是在提交表单时更新 Slack 用户。
所以问题是,当下面的路由被触发时,如何向 slack url 发送 post 请求(显然 res 指向/update)。我进行了大量研究并尝试重写 header 并使用低级 http 方法,但我感觉有更好的解决方案。非常感谢您的帮助。
app.post("/update", function(req,res,next) {
res url -> http://slackapi/12345/
res.json({"text":"hello":}
})
最佳答案
res 不应发送到 slack,这是对与您联系的人的回复。您需要向 slack 发送不同的请求,并通过 res 返回您想要的任何内容。
您可以使用request模块生成一个 http 请求到 slack。
var request = require('request');
app.post("/update", function(req,res,next) {
request('http://slackapi/12345/', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
res.json({"text":"some answer to the requester"});
} else {
res.json({"text":"notify requester sending to slack falied"});
}
});
});
关于angularjs - 在 Express 中将数据响应到 Slack url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34665502/