Skip to content

Commit

Permalink
Modified chatId handling in event nodes.
Browse files Browse the repository at this point in the history
inline_query does not require a chatId and will not be blocked by the sender node any longer.
The sender node created an error when the chatId was not present blocking all other types that do not make use of the chatid.
  • Loading branch information
windkh committed May 2, 2021
1 parent 7519e72 commit e349958
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

# [9.3.0] - 2021-05-02
### fixed chat id exceptions in event nodes.
- fixed - [#175](https://github.com/windkh/node-red-contrib-telegrambot/issues/175)

# [9.2.1] - 2021-04-07
### exception in event node.
- fixed - [#168](https://github.com/windkh/node-red-contrib-telegrambot/issues/168)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-telegrambot",
"version": "9.2.1",
"version": "9.3.0",
"description": "Telegram bot nodes for Node-RED",
"dependencies": {
"bluebird": "^3.5.1",
Expand Down
53 changes: 32 additions & 21 deletions telegrambot/99-telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,15 +1155,30 @@ module.exports = function (RED) {
userid = botMsg.from.id;
}
} else if (botMsg.from) {
//private, group, supergroup
chatid = botMsg.message.chat.id;
//sender, group, supergroup

switch (botMsg.chat_type) {
case 'sender':
if (botMsg.message !== undefined) {
chatid = botMsg.message.chat.id;
}
break;
case 'group':
case 'supergroup':
case 'channel':
if (botMsg.message !== undefined) {
chatid = botMsg.message.chat.id;
}
break;
default:
;
break;
}

username = botMsg.from.username;
userid = botMsg.from.id;
} else {
// polls can be anonymous, then we do not have a chatId.
if (this.event != 'poll') {
node.error('username or chatid undefined');
}
// chatid can be null in case of polls, inline_queries,...
}

if (node.config.isAuthorized(node, chatid, userid, username)) {
Expand Down Expand Up @@ -2054,22 +2069,18 @@ module.exports = function (RED) {
node.status({ fill: 'green', shape: 'ring', text: 'connected' });

if (msg.payload) {
if (msg.payload.chatId) {
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 (!Array.isArray(msg.payload.chatId)) {
this.processMessage(msg.payload.chatId, msg, nodeSend, nodeDone);
} else {
node.warn('msg.payload.chatId is empty');
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('msg.payload is empty');
Expand Down

0 comments on commit e349958

Please sign in to comment.