const winston = require('winston');
const expressWinston = require('express-winston');
const Botkit = require('botkit');

const Services = require('./Services.js');
const Config = require('../config/Config.js');

const karma = Botkit.facebookbot({
  logger: new winston.Logger({
    transports: [
      new (winston.transports.Console)({level: 'debug'}),
    ],
  }),
  debug: true,
  log: true,
  access_token: Config.facebookPageAccessToken,
  verify_token: Config.facebookVerifyToken,
  app_secret: Config.facebookAppSecret,
  receive_via_postback: true,
  validate_requests: true,
  stats_optout: true,
});

karma.setupWebserver(Config.PORT, (err, webserver) => {
  if (Config.environment === 'production') {
    webserver.use(Services.sentry.requestHandler());
  }

  webserver.use(expressWinston.logger({
    transports: [
      new winston.transports.File({
        filename: Config.karmaAccessLogFile,
        logstash: true,
        zippedArchive: true,
      })],
  }));

  karma.createWebhookEndpoints(webserver, karma.spawn({}), () => {
  });

  webserver.get('/', (req, res) => {
    const html = '<h3>borq helps you make bots</h3>';
    res.send(html);
  });

  webserver.post('/trigger', (req, res) => {
    const response = res;
    response.statusCode = 200;
    response.send();
  });

  if (Config.environment === 'production') {
    webserver.use(Services.sentry.errorHandler());
  }
});


module.exports = {
  karma,
};

const winston = require('winston');
const expressWinston = require('express-winston');
const Botkit = require('botkit');

const Services = require('./Services.js');
const Config = require('../config/Config.js');

const karma = Botkit.facebookbot({
  logger: new winston.Logger({
    transports: [
      new (winston.transports.Console)({level: 'debug'}),
    ],
  }),
  debug: true,
  log: true,
  access_token: Config.facebookPageAccessToken,
  verify_token: Config.facebookVerifyToken,
  app_secret: Config.facebookAppSecret,
  receive_via_postback: true,
  validate_requests: true,
  stats_optout: true,
});

module.exports = {
  karma,
};

Remove setupWebServer call from borq
Remove setupWebServer call from borq

Setting up the webserver and spawning a bot is better handled by a
specific bot that way it can have additional endpoints.

Signed-off-by: Njagi Mwaniki <b6a4ba60ad861b9c9afb6daea7294be4be68f44c@urbanslug.com>
