简体   繁体   中英

Hubot And Django Development Server

I am trying to make a get request using coffeeScript, but it is not even making a request to my URL:

module.exports = (robot) ->
  robot.respond /foo (.*) bar (.*) foobar (.*) /i, (msg) ->
    foo = msg.match[1]
    bar = msg.match[2]
    foobar = msg.match[3]
    robot.http("http://localhost:8000/a/")
      .query({
        'foo': foo
        'bar': bar
        'foobar': foobar
      })
      .get() (err, res, body) ->
        json = JSON.parse(body)
        msg.send(json)

When i make the same request with my browser it works:

http://localhost:8000/a/?foo=1&bar=2&foobar=3

I am trying to run hubot as

hubot 1 bar 2 foobar 3

Your CoffeeScript syntax is a bit off. Your structure in your get call is like this:

f() x

when you want it to be like this:

f x

This part:

.get() (err, res, body) ->
    json = JSON.parse(body)
    msg.send(json)

will call get with no arguments and then call whatever get returns as a function with (err, res, body) -> ... as an argument. Presumably you want to pass the callback to get as an argument:

.get (err, res, body) ->
    json = JSON.parse(body)
    msg.send(json)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM