我正在制作我的第一个 Hubot 脚本,该脚本将为 Asana 添加一个快速任务。
我不打算做任何太疯狂的事情,或者至少我不这么认为。
目前我有
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 还有更多功能可以使其正常工作,但是观察我的日志尾部,没有任何输出,没有任何内容记录到控制台,什么也没有发生。
如果我在参数下执行 console.log,它将输出 JSON 并且它是正确的,但似乎该帖子从未发生过。
任何方向都很棒!
谢谢。
编辑
经过更多调整后,遵循 Dan 是朝着正确方向迈出的一步,删除 .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
关于api - Hubot 脚本与 Asana 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10489897/