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.
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) {...});
最后,我转移到botkit库,该库提供了一种更简单且集成的方式来同时拥有服务器和实际应用程序。
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.