【问题标题】:Hubot And Django Development ServerHubot 和 Django 开发服务器
【发布时间】:2014-03-04 14:49:53
【问题描述】:

我正在尝试使用 coffeeScript 发出 get 请求,但它甚至没有向我的 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)

当我用我的浏览器发出相同的请求时,它可以工作:

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

我正在尝试将 hubot 运行为

hubot 1 bar 2 foobar 3

【问题讨论】:

    标签: django coffeescript hubot


    【解决方案1】:

    你的 CoffeeScript 语法有点不对劲。你在get 调用中的结构是这样的:

    f() x
    

    当你想要它是这样的时候:

    f x
    

    这部分:

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

    将调用不带参数的get,然后调用get 返回的任何函数,并以(err, res, body) -> ... 作为参数。大概您想将回调作为参数传递给get

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

    【讨论】:

    • 谢谢,但它仍然没有访问我的 localhost url
    • 你确定它甚至匹配你的正则表达式并进入你的处理程序吗?
    • 它可以在浏览器中运行,但不能从这里运行,我确信只有我的 hubot 脚本中缺少一些东西。
    • 你的回调被调用了吗?
    • 你的摄政与你想要匹配的匹配吗?
    猜你喜欢
    • 1970-01-01
    • 2013-04-24
    • 2011-07-02
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2011-02-14
    相关资源
    最近更新 更多