rss-o-bot-telegram
Version:
A Telegram notifier for RSS-o-Bot
48 lines (38 loc) • 2.27 kB
JavaScript
;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _require = require('rxjs');
var O = _require.Observable;
var _require2 = require('./lib');
var sendMessage = _require2.sendMessage;
var instantiate = _require2.instantiate;
var poll = _require2.poll;
var runCommand = _require2.runCommand;
var help = 'rss-o-bot-telegram poll\n Continuously checks telegram for incomming messages.\n When a message is sent to the defined Telegram Bot,\n the ID of the sender will be displayed. This ID then\n may be used as part of the configured\n "telegram-recipients" array. For further information\n on the configuration of Telegram notifications check\n the configuration reference below.\n';
var action = process.argv[2];
if (action === 'poll') {
instantiate().switchMap(poll()).map(function (update) {
return update.message.from.id;
}).subscribe(console.log, console.error);
} else if (action === 'run') {
instantiate().switchMap(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2);
var config = _ref2[0];
var tg = _ref2[1];
return poll(true)([config, tg]).concatMap(function (t) {
return runCommand(t.message.text.split(' ')).concatMap(function (v) {
return O.from(v.split('\n').reduce(function (m, s) {
var last = m.length - 1;
if (!m[last] || m[last].length + s.length > 2500) {
return m.concat(s);
} else {
m[last] += '\n' + s;
return m;
}
}, []));
}).concatMap(sendMessage(tg, t));
});
}).last().subscribe(console.log, console.error);
} else {
console.log(help);
}