windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
264 stars 117 forks source link

Not authorized chats are not filter out from messages from the configuration node #356

Closed alglez closed 8 months ago

alglez commented 8 months ago

When sending a message to a group if the bot is in that group, the message is still sent, even though the chatId is not present and the chatIds in the "telegram bot node configuration" is not blank (meaning there are at least one chatId there different) the message is still sent to telegram chats with the bot in it.

msg.payload = {
    chatId: id,
    type: "message",
    content: `whatever message`
};

return msg;

windkh commented 8 months ago

@alglez I am not sure if I understood everything. Can you provide an example so that I can reproduce it?

alglez commented 8 months ago

Thanks for the quick answer.

Bot is in chats: '123' and '234' but in nodered i only authorized chat 234 in the optional list of authorized chats.

When I send a message to chat 123, the message is still sent, which i guessed the case should be that those chat that are not in the list should be filtered out, but I just realize without checking the code that current authorized chatIds filter only is used to "incoming" messages, which I guess is the correct use case, so probably not a bug. I only realize of this because I was sending messages explicitly without adding those chats to the list of authorized.

Edit: probably makes more sense the current setup, since is possible that you want to send a message without restrictions but still filter incoming messages,

`[
    {
        "id": "7b0b0d6c9459944e",
        "type": "inject",
        "z": "fea0c0a0a08492f6",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "id",
                "v": "123",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 360,
        "y": 220,
        "wires": [
            [
                "e3a9d17794ff4130"
            ]
        ]
    },
    {
        "id": "e3a9d17794ff4130",
        "type": "function",
        "z": "fea0c0a0a08492f6",
        "name": "message",
        "func": "\nmsg.payload = {\n    chatId: msg.id,\n    type: \"message\",\n    content: `whatever`\n};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 220,
        "wires": [
            [
                "98d98179eb2bda26"
            ]
        ]
    },
    {
        "id": "98d98179eb2bda26",
        "type": "telegram sender",
        "z": "fea0c0a0a08492f6",
        "name": "",
        "bot": "94d330e75b9a45b8",
        "haserroroutput": false,
        "outputs": 1,
        "x": 810,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "94d330e75b9a45b8",
        "type": "telegram bot",
        "botname": "",
        "usernames": "",
        "chatids": "234",
        "baseapiurl": "",
        "updatemode": "polling",
        "pollinterval": "300",
        "usesocks": false,
        "sockshost": "",
        "socksprotocol": "socks5",
        "socksport": "6667",
        "socksusername": "anonymous",
        "sockspassword": "",
        "bothost": "",
        "botpath": "",
        "localbotport": "8443",
        "publicbotport": "8443",
        "privatekey": "",
        "certificate": "",
        "useselfsignedcertificate": false,
        "sslterminated": false,
        "verboselogging": false,
        "credentials": {
            "token": ""
        }
    }
]`
windkh commented 8 months ago

@alglez sorry for delay... The user Ids or chat ids that you configure in the node only affect the receiver node. The usage of the bot is limited to those users. However the bot itself is free to send messages to all chats and users. Thus the sender node is not limited in any way.

windkh commented 8 months ago

I will close the issue: functions as designed