'use strict';

var _telegraf = require('telegraf');

var _telegraf2 = _interopRequireDefault(_telegraf);

var _config = require('config');

var _config2 = _interopRequireDefault(_config);

var _feed = require('./feed');

var _feed2 = _interopRequireDefault(_feed);

var _commands = require('./commands');

var _commands2 = _interopRequireDefault(_commands);

var _messageHelper = require('./helpers/messageHelper');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// TODO move this to a DB

/* commands */
var chatids = process.env.CHAT_IDS || JSON.parse(_config2.default.get('CHAT_IDS'));
/* helpers */


var app = new _telegraf2.default(_config2.default.get('token'));

/* add commands from command array */
_commands2.default.forEach(function (command) {
  return app.command(command.key, function (ctx) {
    return command.func(ctx);
  });
});

/** telegram app **/
var token = process.env.token || _config2.default.get('token');
var URL = process.env.URL || _config2.default.get('URL');
var PORT = process.env.PORT || _config2.default.get('PORT');
var isDevelopment = process.env.NODE_ENV === 'development';

// start telegram listeners
if (isDevelopment) {
  // remove webhook in case any is attached from previous sessions
  app.telegram.setWebhook();

  app.startPolling();
} else {
  app.telegram.setWebhook(URL + '/bot' + token);
  app.startWebhook('/bot' + token, null, PORT);
}

// start reading rss articles
_feed2.default.read(function (articles) {
  if (!articles) return;
  chatids.forEach(function (id) {
    return (0, _messageHelper.sendIntervalMessages)(app.telegram, id, articles);
  });
});
@@ -637,270 +637,11 @@
 ));%0A
+%0A
 /*
- helpers */%0A%0A%0Avar app = new _telegraf2.default(_config2.default.get('token'));%0A%0A/* add commands from command array */%0A_commands2.default.forEach(function (command) %7B%0A  return app.command(command.key, function (ctx) %7B%0A    return command.func(ctx);%0A  %7D);%0A%7D);%0A%0A/*
 * te
@@ -652,16 +652,31 @@
 am app *
+*/%0A%0A/* helpers 
 */%0Avar t
@@ -914,16 +914,236 @@
 ment';%0A%0A
+var app = new _telegraf2.default(token);%0A%0A/* add commands from command array */%0A_commands2.default.forEach(function (command) %7B%0A  return app.command(command.key, function (ctx) %7B%0A    return command.func(ctx);%0A  %7D);%0A%7D);%0A%0A
 // start

Add latest version of dist folder