2012-05-07 5 views
1

아사나에 빠른 작업을 추가하는 첫 번째 Hubot 스크립트를 만드는 중입니다.
나는 너무 미친 짓을하는 것을보고 있지 않으며, 적어도 나는 생각하지 않았다. 아사나와 통합 된 Hubot 스크립트

은 현재 내가

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 

이 내가 정말하고 싶은 것은이 작업 영역에 게시의 출력이다. 아사나 API가 제대로 작동하도록하려면 API가 더 필요하다는 것을 알고 있지만 로그의 꼬리를보고 아무 것도 출력하지 않고 콘솔에 로깅하는 것도 아무것도 일어나지 않습니다.

params에서 console.log를 실행하면 JSON이 출력되고 올바르지 만 포스트가 발생하지 않는 것처럼 보입니다.

모든 방향이 좋습니다!

감사합니다. 댄 다음

EDIT 더 약간의 조정 후

는 (.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 
+2

최상위 개체의'data' 매개 변수 내부에 있어야한다는 것을 잊지 마십시오. '{data : {parameters : values}}' – DanRedux

+0

@ DanRedux에게 감사의 말을 전했으나 아무 것도 변경하지 않았습니다. :/ – LostInQuery

+0

미세 조정을 위해 약간 마친 후, 결국 효과가있었습니다. 포인터 주셔서 감사합니다! – LostInQuery

답변

1

질문에 대한 답변을 제출하면 stackoverflow에서 응답을받지 않은 것으로 표시하지 않습니다.

OP의 EDIT에서 복사.

.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 
0

나는 Hubot의 http 클라이언트가 query()에 대한 객체가 아니라 문자열을 기대한다고 생각합니다. JSON.stringify을 호출하는 대신 객체를 직접 전달하십시오.

+0

개체를 호출 중입니다. – LostInQuery