Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions telegrambot/nodes/bot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ module.exports = function (RED) {
let startTime = new Date().getTime();

let result = super.getUpdates(form);
result.then((updates) => {
let endTime = new Date().getTime();
this.emit('getUpdates_end', this.cycle, endTime - startTime, updates);
});
result
.then((updates) => {
let endTime = new Date().getTime();
this.emit('getUpdates_end', this.cycle, endTime - startTime, updates);
})
.catch(() => {
// Errors from getUpdates are handled by the caller; suppress unhandled rejection here.
});

return result;
}
Expand Down Expand Up @@ -383,21 +387,33 @@ module.exports = function (RED) {
certificate: options.webHook.cert,
};
}
newTelegramBot.setWebHook(botUrl, setWebHookOptions).then(function (success) {
if (self.verbose) {
newTelegramBot.getWebHookInfo().then(function (result) {
self.log('Webhook enabled: ' + JSON.stringify(result));
});
}
newTelegramBot
.setWebHook(botUrl, setWebHookOptions)
.then(function (success) {
if (self.verbose) {
newTelegramBot
.getWebHookInfo()
.then(function (result) {
self.log('Webhook enabled: ' + JSON.stringify(result));
})
.catch(function (err) {
self.warn('Failed to get webhook info: ' + err);
});
}

if (success) {
self.status = 'connected'; // TODO: check if this must be SetStatus
} else {
self.abortBot('Failed to set webhook ' + botUrl, function () {
if (success) {
self.status = 'connected'; // TODO: check if this must be SetStatus
} else {
self.abortBot('Failed to set webhook ' + botUrl, function () {
self.error('Bot stopped: Webhook not set.');
});
}
})
.catch(function (err) {
self.abortBot('Failed to set webhook ' + botUrl + ': ' + err, function () {
self.error('Bot stopped: Webhook not set.');
});
}
});
});

return newTelegramBot;
};
Expand Down
32 changes: 21 additions & 11 deletions telegrambot/nodes/in-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,29 @@ module.exports = function (RED) {
// downloadable "blob" message?
if (messageDetails.blob) {
let fileId = msg.payload.content;
telegramBot.getFileLink(fileId).then(function (weblink) {
msg.payload.weblink = weblink;
telegramBot
.getFileLink(fileId)
.then(function (weblink) {
msg.payload.weblink = weblink;

// download and provide with path
if (config.saveDataDir) {
telegramBot.downloadFile(fileId, config.saveDataDir).then(function (path) {
msg.payload.path = path;
// download and provide with path
if (config.saveDataDir) {
telegramBot
.downloadFile(fileId, config.saveDataDir)
.then(function (path) {
msg.payload.path = path;
node.send([msg, null]);
})
.catch(function (err) {
node.error('Failed to download file: ' + err, msg);
});
} else {
node.send([msg, null]);
});
} else {
node.send([msg, null]);
}
});
}
})
.catch(function (err) {
node.error('Failed to get file link: ' + err, msg);
});
// vanilla message
} else if (node.filterCommands && node.config.isCommandRegistered(messageDetails.content)) {
// Do nothing
Expand Down
Loading