diff --git a/CHANGELOG.md b/CHANGELOG.md index 01d320d..c9144ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +# [14.2.0] - 2022-09-19 +### MAde node more robust when initialization is aborted due to duplicate token usage - [#272](https://github.com/windkh/node-red-contrib-telegrambot/issues/272) + # [14.1.0] - 2022-09-01 ### Added web app data support - [#264](https://github.com/windkh/node-red-contrib-telegrambot/issues/264) diff --git a/package-lock.json b/package-lock.json index 24cde12..c6215a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "node-red-contrib-telegrambot", - "version": "12.0.0", + "version": "14.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "12.0.0", + "version": "14.1.0", "license": "MIT", "dependencies": { "bluebird": "^3.7.2", diff --git a/package.json b/package.json index 4a31127..685afaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-telegrambot", - "version": "14.1.0", + "version": "14.2.0", "description": "Telegram bot nodes for Node-RED", "dependencies": { "bluebird": "^3.7.2", diff --git a/telegrambot/99-telegrambot.js b/telegrambot/99-telegrambot.js index 6c12402..e8f1830 100644 --- a/telegrambot/99-telegrambot.js +++ b/telegrambot/99-telegrambot.js @@ -1331,18 +1331,19 @@ module.exports = function (RED) { language = undefined; } - this.config.registerCommand(node.id, command, description, language, scope, registerCommand); + node.telegramBot = this.config.getTelegramBot(); + if (node.telegramBot) { + this.config.registerCommand(node.id, command, description, language, scope, registerCommand); - node.status({ fill: 'red', shape: 'ring', text: 'not connected' }); + node.status({ fill: 'red', shape: 'ring', text: 'not connected' }); - node.onStatusChanged = function (status) { - node.status(status); - }; - node.config.addListener('status', node.onStatusChanged); + node.onStatusChanged = function (status) { + node.status(status); + }; + node.config.addListener('status', node.onStatusChanged); + + node.botname = this.config.botname; - node.telegramBot = this.config.getTelegramBot(); - node.botname = this.config.botname; - if (node.telegramBot) { if (node.telegramBot._polling !== null || node.telegramBot._webHook !== null) { node.status({ fill: 'green', @@ -2492,18 +2493,27 @@ module.exports = function (RED) { node.status({ fill: 'green', shape: 'ring', text: 'connected' }); if (msg.payload) { - if (!Array.isArray(msg.payload.chatId)) { - this.processMessage(msg.payload.chatId, msg, nodeSend, nodeDone); - } else { - let chatIds = msg.payload.chatId; - let length = chatIds.length; - for (let i = 0; i < length; i++) { - let chatId = chatIds[i]; - - let clonedMsg = RED.util.cloneMessage(msg); - clonedMsg.payload.chatId = chatId; - this.processMessage(chatId, clonedMsg, nodeSend, nodeDone); + if (node.telegramBot) { + if (!Array.isArray(msg.payload.chatId)) { + this.processMessage(msg.payload.chatId, msg, nodeSend, nodeDone); + } else { + let chatIds = msg.payload.chatId; + let length = chatIds.length; + for (let i = 0; i < length; i++) { + let chatId = chatIds[i]; + + let clonedMsg = RED.util.cloneMessage(msg); + clonedMsg.payload.chatId = chatId; + this.processMessage(chatId, clonedMsg, nodeSend, nodeDone); + } } + } else { + node.warn('bot not initialized.'); + node.status({ + fill: 'red', + shape: 'ring', + text: 'bot not initialized', + }); } } else { node.warn('msg.payload is empty'); @@ -2576,27 +2586,36 @@ module.exports = function (RED) { node.status({ fill: 'green', shape: 'ring', text: 'connected' }); if (msg.payload) { - if (msg.payload.chatId) { - if (msg.payload.sentMessageId) { - let chatId = msg.payload.chatId; - let messageId = msg.payload.sentMessageId; - - node.telegramBot.onReplyToMessage(chatId, messageId, function (botMsg) { - let messageDetails = getMessageDetails(botMsg); - if (messageDetails) { - msg.payload = messageDetails; - msg.originalMessage = botMsg; - nodeSend(msg); - if (nodeDone) { - nodeDone(); + if (node.telegramBot) { + if (msg.payload.chatId) { + if (msg.payload.sentMessageId) { + let chatId = msg.payload.chatId; + let messageId = msg.payload.sentMessageId; + + node.telegramBot.onReplyToMessage(chatId, messageId, function (botMsg) { + let messageDetails = getMessageDetails(botMsg); + if (messageDetails) { + msg.payload = messageDetails; + msg.originalMessage = botMsg; + nodeSend(msg); + if (nodeDone) { + nodeDone(); + } } - } - }); + }); + } else { + node.warn('msg.payload.sentMessageId is empty'); + } } else { - node.warn('msg.payload.sentMessageId is empty'); + node.warn('msg.payload.chatId is empty'); } } else { - node.warn('msg.payload.chatId is empty'); + node.warn('bot not initialized.'); + node.status({ + fill: 'red', + shape: 'ring', + text: 'bot not initialized', + }); } } else { node.warn('msg.payload is empty');