api - Hubot 脚本与 Asana 集成

标签 api node.js coffeescript asana hubot

我正在制作我的第一个 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/

相关文章:

c++ - 设置滚动条有问题

Android 沉浸式模式和向后兼容性

xml - NodeJS xpath 库是否支持 XPath 查询表达式?

node.js - 如何将主机和容器目录与Dockerode同步?

javascript - rails 5.1 : How to override confirmation dialog with bootstrap using rails-ujs

在 Node 0.5.10-pre 下抑制了 CoffeeScript 编译器错误

c# - Rest API 返回基于角色或不同实体的属性

rest - 尝试获取 acumatica 中特定商品的销售价格时,无法执行优化错误

javascript - 如何在 npm install 中克服这个错误?

javascript - 我可以在 Coffeescript 中继承类定义代码吗?