robot.router 和 robot.http 有什么区别?
What's the difference between robot.router and robot.http?
我继承了一个 coffeescript hubot 应用程序。除了自述文件和教程外,我找不到论坛或任何其他问题的答案,所以我在这里问。
我用谷歌搜索了这个问题,但找不到答案。
robot.router 和 robot.http 有什么区别?两者似乎都采用 get、put、delete 等和 URL。我的应用程序同时使用了两者,但在我看来,我无法区分它们。
看起来路由器是 运行 express 而 http 是自己开发的。这会对客户端产生语义差异吗?
我也很难找到好的文档,但设法从 Hubot Scripting doc 中获得了一些见解。如果您在页面中搜索“robot.router”和“robot.http”,您会遇到以下定义:
robot.http
这是为了对其他网络服务进行 HTTP 调用(类似于 jQuery AJAX or Axios)
Hubot can make HTTP calls on your behalf to integrate & consume third party APIs. This can be through an instance of node-scoped-http-client available at robot.http. The simplest case looks like:
robot.http("https://midnight-train")
.get() (err, res, body) ->
# your code here
robot.router
这是一个 Express 服务器。它是一个 HTTP 侦听器,用于接受和响应 HTTP 请求
Hubot includes support for the express web framework to serve up HTTP requests. It listens on the port specified by the EXPRESS_PORT or PORT environment variables (preferred in that order) and defaults to 8080. An instance of an express application is available at robot.router. It can be protected with username and password by specifying EXPRESS_USER and EXPRESS_PASSWORD. It can automatically serve static files by setting EXPRESS_STATIC.
The most common use of this is for providing HTTP end points for services with webhooks to push to, and have those show up in chat.
module.exports = (robot) ->
# the expected value of :room is going to vary by adapter, it
# might be a numeric id, name, token, or some other value
robot.router.post '/hubot/chatsecrets/:room', (req, res) ->
room = req.params.room
data = if req.body.payload? then JSON.parse req.body.payload else req.body
secret = data.secret
robot.messageRoom room, "I have a secret: #{secret}"
res.send 'OK'
我继承了一个 coffeescript hubot 应用程序。除了自述文件和教程外,我找不到论坛或任何其他问题的答案,所以我在这里问。
我用谷歌搜索了这个问题,但找不到答案。
robot.router 和 robot.http 有什么区别?两者似乎都采用 get、put、delete 等和 URL。我的应用程序同时使用了两者,但在我看来,我无法区分它们。
看起来路由器是 运行 express 而 http 是自己开发的。这会对客户端产生语义差异吗?
我也很难找到好的文档,但设法从 Hubot Scripting doc 中获得了一些见解。如果您在页面中搜索“robot.router”和“robot.http”,您会遇到以下定义:
robot.http
这是为了对其他网络服务进行 HTTP 调用(类似于 jQuery AJAX or Axios)
Hubot can make HTTP calls on your behalf to integrate & consume third party APIs. This can be through an instance of node-scoped-http-client available at robot.http. The simplest case looks like:
robot.http("https://midnight-train") .get() (err, res, body) -> # your code here
robot.router
这是一个 Express 服务器。它是一个 HTTP 侦听器,用于接受和响应 HTTP 请求
Hubot includes support for the express web framework to serve up HTTP requests. It listens on the port specified by the EXPRESS_PORT or PORT environment variables (preferred in that order) and defaults to 8080. An instance of an express application is available at robot.router. It can be protected with username and password by specifying EXPRESS_USER and EXPRESS_PASSWORD. It can automatically serve static files by setting EXPRESS_STATIC.
The most common use of this is for providing HTTP end points for services with webhooks to push to, and have those show up in chat.
module.exports = (robot) -> # the expected value of :room is going to vary by adapter, it # might be a numeric id, name, token, or some other value robot.router.post '/hubot/chatsecrets/:room', (req, res) -> room = req.params.room data = if req.body.payload? then JSON.parse req.body.payload else req.body secret = data.secret robot.messageRoom room, "I have a secret: #{secret}" res.send 'OK'