@patricktobias86/node-red-telegram-account 1.1.10 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +2 -0
- package/docs/NODES.md +1 -0
- package/nodes/auth.js +18 -17
- package/nodes/get-entity.js +2 -2
- package/nodes/iter-dialogs.js +1 -1
- package/nodes/iter-messages.js +2 -2
- package/nodes/promote-admin.js +1 -1
- package/nodes/resolve-userid.js +2 -2
- package/nodes/send-file.js +1 -1
- package/nodes/send-message.js +1 -1
- package/package.json +1 -1
- package/test/pass-through.test.js +41 -0
package/CHANGELOG.md
CHANGED
|
@@ -19,3 +19,7 @@ All notable changes to this project will be documented in this file.
|
|
|
19
19
|
### Changed
|
|
20
20
|
- `delete-message` now forwards the original message along with the Telegram API response.
|
|
21
21
|
|
|
22
|
+
## [1.1.11] - 2025-08-04
|
|
23
|
+
### Fixed
|
|
24
|
+
- All nodes now preserve properties on the incoming message outside of the payload.
|
|
25
|
+
|
package/README.md
CHANGED
|
@@ -29,6 +29,8 @@ See [docs/NODES.md](docs/NODES.md) for a detailed description of every node. Bel
|
|
|
29
29
|
- **promote-admin** – promotes a user to admin with configurable rights.
|
|
30
30
|
- **resolve-userid** – converts a username to a numeric user ID.
|
|
31
31
|
|
|
32
|
+
All nodes preserve any properties on the incoming message outside of <code>msg.payload</code>.
|
|
33
|
+
|
|
32
34
|
All nodes include a <code>Debug</code> option that logs incoming and outgoing messages to the Node-RED log when enabled.
|
|
33
35
|
|
|
34
36
|
## Session management
|
package/docs/NODES.md
CHANGED
|
@@ -19,6 +19,7 @@ Below is a short description of each node. For a full list of configuration opti
|
|
|
19
19
|
| **promote-admin** | Grants admin rights to a user in a group or channel with configurable permissions. |
|
|
20
20
|
| **resolve-userid** | Converts a Telegram username to its numeric user ID. |
|
|
21
21
|
|
|
22
|
+
All nodes forward any properties on the incoming `msg` outside of `msg.payload` unchanged.
|
|
22
23
|
|
|
23
24
|
All nodes provide a **Debug** checkbox. When enabled the node will log its input and output messages to aid troubleshooting.
|
|
24
25
|
|
package/nodes/auth.js
CHANGED
|
@@ -58,27 +58,28 @@ module.exports = function (RED) {
|
|
|
58
58
|
]
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
const out = {
|
|
62
|
+
...msg,
|
|
63
|
+
topic: "auth_success",
|
|
64
|
+
payload: {
|
|
65
|
+
stringSession,
|
|
66
|
+
message: "Authorization successful!"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
node.send(out);
|
|
70
|
+
if (debug) {
|
|
71
|
+
node.log('auth output: ' + JSON.stringify(out));
|
|
72
|
+
}
|
|
72
73
|
|
|
73
74
|
node.status({ fill: "green", shape: "dot", text: "Authenticated" });
|
|
74
75
|
|
|
75
76
|
} catch (err) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
node.error("Authentication failed: " + err.message);
|
|
78
|
+
const out = { ...msg, topic: "auth_error", payload: { error: err.message } };
|
|
79
|
+
node.send(out);
|
|
80
|
+
if (debug) {
|
|
81
|
+
node.log('auth output: ' + JSON.stringify(out));
|
|
82
|
+
}
|
|
82
83
|
node.status({ fill: "red", shape: "ring", text: "Failed" });
|
|
83
84
|
}
|
|
84
85
|
});
|
package/nodes/get-entity.js
CHANGED
|
@@ -25,14 +25,14 @@ module.exports = function (RED) {
|
|
|
25
25
|
entity = await client.getEntity(input);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const out = { payload: { input: entity } };
|
|
28
|
+
const out = { ...msg, payload: { input: entity } };
|
|
29
29
|
node.send(out);
|
|
30
30
|
if (debug) {
|
|
31
31
|
node.log('get-entity output: ' + JSON.stringify(out));
|
|
32
32
|
}
|
|
33
33
|
} catch (err) {
|
|
34
34
|
node.error('Error getting entity: ' + err.message);
|
|
35
|
-
const out = { payload: { input: null } };
|
|
35
|
+
const out = { ...msg, payload: { input: null } };
|
|
36
36
|
node.send(out);
|
|
37
37
|
if (debug) {
|
|
38
38
|
node.log('get-entity output: ' + JSON.stringify(out));
|
package/nodes/iter-dialogs.js
CHANGED
|
@@ -45,7 +45,7 @@ module.exports = function (RED) {
|
|
|
45
45
|
dialogs[dialog.id] = dialog;
|
|
46
46
|
console.log(`${dialog.id}: ${dialog.title}`);
|
|
47
47
|
}
|
|
48
|
-
const out = { payload: { dialogs } };
|
|
48
|
+
const out = { ...msg, payload: { dialogs } };
|
|
49
49
|
node.send(out);
|
|
50
50
|
if (debug) {
|
|
51
51
|
node.log('iter-dialogs output: ' + JSON.stringify(out));
|
package/nodes/iter-messages.js
CHANGED
|
@@ -84,8 +84,8 @@ module.exports = function (RED) {
|
|
|
84
84
|
console.log(message.id, message.text);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
const out = { payload: { messages } };
|
|
87
|
+
|
|
88
|
+
const out = { ...msg, payload: { messages } };
|
|
89
89
|
node.send(out);
|
|
90
90
|
if (debug) {
|
|
91
91
|
node.log('iter-messages output: ' + JSON.stringify(out));
|
package/nodes/promote-admin.js
CHANGED
|
@@ -44,7 +44,7 @@ module.exports = function (RED) {
|
|
|
44
44
|
rank: rank,
|
|
45
45
|
}));
|
|
46
46
|
|
|
47
|
-
const out = { payload: { response: result } };
|
|
47
|
+
const out = { ...msg, payload: { response: result } };
|
|
48
48
|
node.send(out);
|
|
49
49
|
if (debug) {
|
|
50
50
|
node.log('promote-admin output: ' + JSON.stringify(out));
|
package/nodes/resolve-userid.js
CHANGED
|
@@ -30,14 +30,14 @@ module.exports = function(RED) {
|
|
|
30
30
|
} else if (entity?.userId) {
|
|
31
31
|
userId = entity.userId;
|
|
32
32
|
}
|
|
33
|
-
const out = { payload: { userId } };
|
|
33
|
+
const out = { ...msg, payload: { userId } };
|
|
34
34
|
node.send(out);
|
|
35
35
|
if (debug) {
|
|
36
36
|
node.log('resolve-userid output: ' + JSON.stringify(out));
|
|
37
37
|
}
|
|
38
38
|
} catch (err) {
|
|
39
39
|
node.error('Error resolving username: ' + err.message);
|
|
40
|
-
const out = { payload: { userId: null } };
|
|
40
|
+
const out = { ...msg, payload: { userId: null } };
|
|
41
41
|
node.send(out);
|
|
42
42
|
if (debug) {
|
|
43
43
|
node.log('resolve-userid output: ' + JSON.stringify(out));
|
package/nodes/send-file.js
CHANGED
|
@@ -64,7 +64,7 @@ module.exports = function (RED) {
|
|
|
64
64
|
|
|
65
65
|
// Send files
|
|
66
66
|
const response = await client.sendFile(chatId, params);
|
|
67
|
-
const out = { payload: response };
|
|
67
|
+
const out = { ...msg, payload: response };
|
|
68
68
|
node.send(out);
|
|
69
69
|
if (debug) {
|
|
70
70
|
node.log('send-files output: ' + JSON.stringify(out));
|
package/nodes/send-message.js
CHANGED
|
@@ -73,7 +73,7 @@ module.exports = function (RED) {
|
|
|
73
73
|
await client.sendMessage(entity, params);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const out = { payload: { response } };
|
|
76
|
+
const out = { ...msg, payload: { response } };
|
|
77
77
|
node.send(out);
|
|
78
78
|
if (debug) {
|
|
79
79
|
node.log('send-message output: ' + JSON.stringify(out));
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const proxyquire = require('proxyquire').noPreserveCache();
|
|
3
|
+
|
|
4
|
+
function setup() {
|
|
5
|
+
let NodeCtor;
|
|
6
|
+
let sent;
|
|
7
|
+
const configNode = { client: {} };
|
|
8
|
+
const RED = {
|
|
9
|
+
nodes: {
|
|
10
|
+
createNode(node) {
|
|
11
|
+
node._events = {};
|
|
12
|
+
node.on = (e, fn) => { node._events[e] = fn; };
|
|
13
|
+
node.send = (msg) => { sent = msg; };
|
|
14
|
+
node.log = () => {};
|
|
15
|
+
node.error = () => {};
|
|
16
|
+
},
|
|
17
|
+
registerType(name, ctor) { NodeCtor = ctor; },
|
|
18
|
+
getNode() { return configNode; }
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
proxyquire('../nodes/send-message.js', {
|
|
23
|
+
telegram: { TelegramClient: function() {} },
|
|
24
|
+
'telegram/Utils': { parseID: () => ({}) }
|
|
25
|
+
})(RED);
|
|
26
|
+
|
|
27
|
+
return { NodeCtor, getSent: () => sent };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('message property relay', function() {
|
|
31
|
+
it('keeps non-payload properties on send-message output', async function() {
|
|
32
|
+
const { NodeCtor, getSent } = setup();
|
|
33
|
+
const node = new NodeCtor({ config: 'c', file: "" });
|
|
34
|
+
const client = { sendMessage: async () => 'ok' };
|
|
35
|
+
const msg = { foo: 'bar', payload: { client, chatId: 'me', message: 'hi' } };
|
|
36
|
+
await node._events['input'](msg);
|
|
37
|
+
const out = getSent();
|
|
38
|
+
assert.strictEqual(out.foo, 'bar');
|
|
39
|
+
assert.deepStrictEqual(out.payload.response, 'ok');
|
|
40
|
+
});
|
|
41
|
+
});
|