Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "path" to config, to run bot on non-root URLS and run multiple bots on same site #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const express = require('express');
const bodyParser = require('body-parser');
const stream = require('stream');

function Middleware(logger, messageValidatorService) {
function Middleware(logger, messageValidatorService, path) {
this._logger = logger;
this._stream = this._createStream();
this._buffer = null;

this._path=path;
this._app = express();
this._app.use(bodyParser.text({ type: "*/*" }));

Expand All @@ -26,12 +26,12 @@ Middleware.prototype.getStream = function() {

Middleware.prototype._configureEndpoints = function() {
const self = this;
this._app.get("/ping", (request, response) => {
this._app.get(self._path+"/ping", (request, response) => {
response.send("pong");
response.end();
});

this._app.post("/", (request, response) => {
this._app.post(self._path+"/", (request, response) => {
self._logger.debug("Request data:", request.body);
self._stream.push(request.body);

Expand Down
2 changes: 1 addition & 1 deletion lib/viber-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function ViberBot(loggerOrConfiguration, configuration) {

this._logger = logger;
this._client = new ViberClient(this._logger, this, API_URL, configuration.registerToEvents || SUBSCRIBED_EVENTS);
this._middleware = new Middleware(this._logger, new MessageValidator(this._logger, this.authToken));
this._middleware = new Middleware(this._logger, new MessageValidator(this._logger, this.authToken),configuration.path);
this._messageFactory = new MessageFactory(this._logger);
this._regexMatcherRouter = new RegexMatcherRouter(this._logger);
this._callbacks = { [EventConsts.CONVERSATION_STARTED]: []};
Expand Down