简体   繁体   English

将Hubot作为Express App的一部分运行

[英]Run hubot as a part of express app

I have a pretty standard express app, built using the express-generator . 我有一个使用express-generator构建的非常标准的express应用。 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. 现在,我想使用hubot自动化应用程序中的hubot并且我已经成功地执行了测试并使用slack适配器运行hubot 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? 如何更改应用程序的结构(我有相当标准的routes.js导入,其中包含应用程序的所有路由),以允许两者一起运行?

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. 这是作为WebAppazure上运行的,并且我已经与GitHub了持续集成,因此我几乎只是推送代码并进行了部署,因此我没有在实际服务器上手动运行任何内容。 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. 如果它是常规的VPS,我将能够运行hubot并将其存储在应用程序的其他子域或路径上,但是由于azure正在处理这些事情,因此我需要以某种方式将hubot烘焙到实际的express应用程式。

As I know, Hubot has a build-in express web framework that can serve HTTP requests. 据我所知,Hubot有一个内置的快速Web框架,可以处理HTTP请求。 So theoretically you can integrate hubot with your express webapp thru the router dispatch different urls between express app and hubot. 因此,从理论上讲,您可以通过路由器在Express App和Hubot之间分配不同的URL,从而将Hubot与Express Web App集成在一起。

As references, there is a experimental package project hubot-express shows that hubot as a express app startup. 作为参考,有一个实验性的软件包项目hubot-express展示了hubot作为快速应用程序的启动。 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. 您可以尝试参考代码https://github.com/hubot-scripts/hubot-express/blob/master/src/hubot-express.coffee来实现集成。

The key code: robot.express = app = express(); 关键代码: 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. 文章“使用Hubot进行自动化和监视”显示了如何处理http请求的代码,请转到https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-serving-http -要求对其进行审查。

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

最后,我转移到botkit库,该库提供了一种更简单且集成的方式来同时拥有服务器和实际应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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