运行hubot作为表达的一部分应用 - Run hubot as a part of express app

- 此内容更新于:2015-12-20
主题:

我有一个非常标准的应用程序,使用。现在,我想自动化在应用程序的一些事情,我已经设法成功地执行测试并运行hubot适配器。然而,我想要机器人是一个例行程序的一部分。我怎么能改变应用程序的结构(我有一个非常标准的进口的所有航线app)允许两个一起跑步吗?这是运行在一个和我建立一个持续集成,所以我几乎就把代码和部署,我不实际的服务器上运行任何手动。我能够跑hubot和服务器在不同的子域或路径的应用如果是普通的VPS,但自从azure是照顾这些事情,我需要hubot不知何故常用实际表达应用。

原文:

I have a pretty standard express app, built using the express-generator. Now, I would like to automate some of the things in the app with hubot and I have managed to successfully perform testing and run hubot with slack adapter. However, I would like to have the bot be a part of a regular app.

How can I change the structure of the app (I have a pretty standard import of routes.js which has all of the routes for the app) to allow for the two to run together?

This is running on azure as a WebApp and I have set up a continuous integration with GitHub, so I pretty much just push code and it gets deployed, I don't run anything manually on the actual server. I would be able to run the hubot and server it on a different subdomain or path on the app if it was a regular VPS, but since the azure is taking care of those things, I would need the hubot somehow baked-in the actual express app.

解决方案:
就我所知,Hubot内置表达web框架,它可以为HTTP请求。所以理论上你可以整合hubot表达webapp穿过路由器表达应用和hubot之间分派不同的url。作为参考,有一个实验计划项目显示hubot作为应用程序启动。你可以试着参考https://github.com/hubot-scripts/hubot-express/blob/master/src/hubot-express.coffee实现集成的代码。关键代码:和这篇文章“Hubot自动化和监测”显示的代码如何服务的http请求,请到https://leanpub.com/automation-and-monitoring-with-hubot/readleanpub-auto-serving-http-requests审查它。关键代码:
原文:

As I know, Hubot has a build-in express web framework that can serve HTTP requests. So theoretically you can integrate hubot with your express webapp thru the router dispatch different urls between express app and hubot.

As references, there is a experimental package project hubot-express shows that hubot as a express app startup. you can try to refer to the code https://github.com/hubot-scripts/hubot-express/blob/master/src/hubot-express.coffee to implement the integration.

The key code: robot.express = app = express();

And the article "Automation and Monitoring with Hubot" show the code that how to serving http requests, please move to https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-serving-http-requests to review it.

The key code: robot.router.post('/hubot/notify/:room', function(req, res) {...});