node-telegram-api/build/functions/webhook.js
Ali Movahedi e5c25bd9c1 refactor: remove grunt and babel
remove grunt from dependencies, and use transformed code instead using babel/register.
change API a litte
2016-03-28 12:26:07 +04:30

43 lines
994 B
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = webhook;
var _http = require('http');
var _http2 = _interopRequireDefault(_http);
var _qs = require('qs');
var _qs2 = _interopRequireDefault(_qs);
var _fetch = require('./fetch');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var DEFAULTS = {
server: {},
port: 443
};
function webhook() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var bot = arguments[1];
options = Object.assign(DEFAULTS, options);
return bot.api.setWebhook(options.url).then(function () {
bot._webhookServer = _http2.default.createServer(options.server, function (req, res) {
return (0, _fetch.getBody)(req).then(function (data) {
bot.emit('update', _qs2.default.parse(data).result);
res.end('OK');
});
}).listen(options.port);
});
}
module.exports = exports['default'];