mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
Emit message only on webhook
This commit is contained in:
parent
60d44a4307
commit
aa9636e1b2
@ -76,8 +76,10 @@ TelegramBot.prototype._configureWebHook = function (port, host, key, cert) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TelegramBot.prototype._requestListener = function (req, res) {
|
TelegramBot.prototype._requestListener = function (req, res) {
|
||||||
|
console.log(req)
|
||||||
var self = this;
|
var self = this;
|
||||||
if (req.url === '/bot' && req.method === 'POST') {
|
var url = '/bot';
|
||||||
|
if (req.url === url && req.method === 'POST') {
|
||||||
var fullBody = '';
|
var fullBody = '';
|
||||||
req.on('data', function (chunk) {
|
req.on('data', function (chunk) {
|
||||||
fullBody += chunk.toString();
|
fullBody += chunk.toString();
|
||||||
@ -85,11 +87,12 @@ TelegramBot.prototype._requestListener = function (req, res) {
|
|||||||
req.on('end', function () {
|
req.on('end', function () {
|
||||||
try {
|
try {
|
||||||
var data = JSON.parse(fullBody);
|
var data = JSON.parse(fullBody);
|
||||||
self.emit('message', data);
|
self.offset = data.update_id;
|
||||||
|
self.emit('message', data.message);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
res.end('OK\n');
|
res.end('OK :P\n');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.end('OK\n');
|
res.end('OK\n');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user