集成了Asana的Hubot脚本

我正在制作我的第一个Hubot脚本,它将为Asana添加一个快速任务。
我不是在看什么太疯狂,或者至less不认为我是。

目前我有

url = 'https://app.asana.com/api/1.0' WORKSPACE = "1111111111111" user = "xxxxxx.xxxxxxxxxxxxxxxx" pass = "" module.exports = (robot) -> robot.respond /task (.*)/i, (msg) -> params = {name: "#{msg.match[1]}", workspace: "#{WORKSPACE}"} stringParams = JSON.stringify params auth = 'Basic ' + new Buffer("#{user}:#{pass}").toString('base64') msg.http("#{url}/tasks") .headers("Authorization": auth, "Content-Length": stringParams.length, "Accept": "application/json") .query(params) .post() (err, res, body) -> console.log(err) console.log(res) console.log(body) msg.send body 

我真正希望它做的是输出它发布到工作区。 我知道有更多的Asana API使所有工作正常,但看我的日志的尾巴,什么都没有输出,没有任何logging到控制台,什么都没有发生。

如果我在params下做一个console.log,它会输出JSON,这是正确的,但似乎这个post从来没有发生过。

任何方向都会很棒!

谢谢。

编辑

经过一些调整之后,继丹是一个正确的方向,把.query()放到.post()中,输出最终是正确的。

 module.exports = (robot) -> robot.respond /task (.*)/i, (msg) -> params = {data:{name: "#{msg.match[1]}", workspace: "#{WORKSPACE}"}} stringParams = JSON.stringify params auth = 'Basic ' + new Buffer("#{user}:#{pass}").toString('base64') msg.http("#{url}/tasks") .headers("Authorization": auth, "Content-Length": stringParams.length, "Accept": "application/json") .post(stringParams) (err, res, body) -> console.log(err) console.log(res) console.log(body) msg.send body 

提交一个问题的答案,所以stackoverflow将不会显示为未答复。

在OP中从编辑复制。

将.query()放到.post()中,输出最终是正确的。

 module.exports = (robot) -> robot.respond /task (.*)/i, (msg) -> params = {data:{name: "#{msg.match[1]}", workspace: "#{WORKSPACE}"}} stringParams = JSON.stringify params auth = 'Basic ' + new Buffer("#{user}:#{pass}").toString('base64') msg.http("#{url}/tasks") .headers("Authorization": auth, "Content-Length": stringParams.length, "Accept": "application/json") .post(stringParams) (err, res, body) -> console.log(err) console.log(res) console.log(body) msg.send body 

我认为Hubot的http客户端需要query()的对象,而不是string。 尝试直接传递对象而不是调用JSON.stringify