@patricktobias86/node-red-telegram-account 1.1.18 → 1.1.20

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 CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [1.1.18] - 2026-01-05
5
+ ## [1.1.20] - 2026-01-05
6
+ ### Added
7
+ - Receiver node now emits debug events on a second output when Debug is enabled, so you can see internal logs in the Node-RED debug sidebar.
6
8
  ### Fixed
9
+ - Receiver node now also supports GramJS `Integer { value: ... }` wrappers when deriving `payload.chatId` / `payload.senderId`.
7
10
  - Receiver node now populates `payload.chatId` / `payload.senderId` when Telegram IDs arrive as numeric strings (common in debug/output), so downstream filters work reliably.
8
-
9
- ## [1.1.17] - 2026-01-05
10
- ### Fixed
11
11
  - Receiver node now listens to Raw MTProto updates and derives sender/chat identity safely so valid messages (channel posts, anonymous admins, service messages, missing fromId) are no longer dropped.
12
12
 
13
13
  ## [1.1.16] - 2025-09-22
package/docs/NODES.md CHANGED
@@ -8,7 +8,7 @@ Below is a short description of each node. For a full list of configuration opti
8
8
  |------|-------------|
9
9
  | **config** | Configuration node storing API credentials and connection options. Other nodes reference this to share a Telegram client and reuse the session. Connections are tracked in a Map with a reference count so multiple nodes can wait for the same connection. |
10
10
  | **auth** | Starts an interactive login flow. Produces a `stringSession` (available in both <code>msg.payload.stringSession</code> and <code>msg.stringSession</code>) that can be reused with the `config` node. |
11
- | **receiver** | Emits an output message for every incoming Telegram message using Raw MTProto updates (so channel posts, anonymous admins and service messages are not missed). Can ignore specific user IDs, skip selected message types (e.g. videos or documents), and optionally drop media above a configurable size. Output includes derived `peer`, `sender`, `senderType`, `senderId`, `chatId`, `isSilent`, and `messageTypes`. `chatId` is normalized to the MTProto dialog id (userId for private chats, chatId for legacy groups, channelId for supergroups/channels — not the Bot API `-100...` form). Event handlers are automatically removed when the node is closed. |
11
+ | **receiver** | Emits an output message for every incoming Telegram message using Raw MTProto updates (so channel posts, anonymous admins and service messages are not missed). Can ignore specific user IDs, skip selected message types (e.g. videos or documents), and optionally drop media above a configurable size. Output includes derived `peer`, `sender`, `senderType`, `senderId`, `chatId`, `isSilent`, and `messageTypes`. `chatId` is normalized to the MTProto dialog id (userId for private chats, chatId for legacy groups, channelId for supergroups/channels — not the Bot API `-100...` form). When Debug is enabled, a second output emits debug messages that can be wired to a Node-RED debug node. Event handlers are automatically removed when the node is closed. |
12
12
  | **command** | Listens for new messages and triggers when a message matches a configured command or regular expression. The event listener is cleaned up on node close to avoid duplicates. |
13
13
  | **send-message** | Sends text messages or media files to a chat. Supports parse mode, buttons, scheduling, and more. |
14
14
  | **send-files** | Uploads one or more files to a chat with optional caption, thumbnails and other parameters. |
@@ -12,7 +12,7 @@
12
12
  maxFileSizeMb: { value: "" }
13
13
  },
14
14
  inputs: 1,
15
- outputs: 1,
15
+ outputs: 2,
16
16
  paletteLabel: 'receiver',
17
17
  label: function() {
18
18
  return this.name||'receiver';
@@ -95,6 +95,14 @@
95
95
 
96
96
  <h3>Outputs</h3>
97
97
  <dl class="message-properties">
98
+ <dt>output 1
99
+ <span class="property-type">message</span>
100
+ </dt>
101
+ <dd>The parsed incoming Telegram message.</dd>
102
+ <dt>output 2
103
+ <span class="property-type">message</span>
104
+ </dt>
105
+ <dd>Debug messages emitted when <b>Debug</b> is enabled (suitable for wiring to a Node-RED debug node).</dd>
98
106
  <dt>payload.update
99
107
  <span class="property-type">object</span>
100
108
  </dt>
package/nodes/receiver.js CHANGED
@@ -185,6 +185,13 @@ const toPeerInfo = (peer) => {
185
185
  };
186
186
 
187
187
  const toSafeNumber = (value) => {
188
+ if (value && typeof value === 'object') {
189
+ // GramJS can represent large integers using custom Integer wrappers.
190
+ // Those often serialize/log as `Integer { value: 123n }`.
191
+ if ('value' in value) {
192
+ return toSafeNumber(value.value);
193
+ }
194
+ }
188
195
  if (typeof value === 'number') {
189
196
  return Number.isFinite(value) ? value : null;
190
197
  }
@@ -424,11 +431,19 @@ module.exports = function (RED) {
424
431
  }
425
432
  };
426
433
 
434
+ const debugSend = (payload) => {
435
+ if (!node.debugEnabled) {
436
+ return;
437
+ }
438
+ node.send([null, { payload }]);
439
+ };
440
+
427
441
  const event = new Raw({});
428
442
  const handler = (rawUpdate) => {
429
443
  const debug = node.debugEnabled;
430
444
  if (debug) {
431
445
  node.log('receiver raw update: ' + util.inspect(rawUpdate, { depth: null }));
446
+ debugSend({ event: 'rawUpdate', rawUpdate });
432
447
  }
433
448
 
434
449
  const extracted = extractMessageEvents(rawUpdate);
@@ -436,12 +451,14 @@ module.exports = function (RED) {
436
451
  // Raw emits *all* MTProto updates; many are not message-bearing updates (typing, reads, etc.).
437
452
  // We do not output those by default, but we also do not silently hide that they occurred.
438
453
  debugLog(`receiver ignoring non-message MTProto update: ${getClassName(rawUpdate) || 'unknown'}`);
454
+ debugSend({ event: 'ignored', reason: 'non-message', rawUpdateClassName: getClassName(rawUpdate) || 'unknown' });
439
455
  return;
440
456
  }
441
457
 
442
458
  for (const { update, message } of extracted) {
443
459
  if (!message) {
444
460
  debugLog(`receiver ignoring message update without message payload: ${getClassName(update) || 'unknown'}`);
461
+ debugSend({ event: 'ignored', reason: 'missing-message', updateClassName: getClassName(update) || 'unknown' });
445
462
  continue;
446
463
  }
447
464
 
@@ -472,6 +489,7 @@ module.exports = function (RED) {
472
489
  const shouldIgnoreType = Array.from(messageTypes).some((type) => ignoredMessageTypes.has(type));
473
490
  if (shouldIgnoreType) {
474
491
  debugLog(`receiver ignoring message due to ignoreMessageTypes; types=${Array.from(messageTypes).join(', ')}`);
492
+ debugSend({ event: 'ignored', reason: 'ignoreMessageTypes', messageTypes: Array.from(messageTypes) });
475
493
  continue;
476
494
  }
477
495
  }
@@ -480,6 +498,7 @@ module.exports = function (RED) {
480
498
  const mediaSize = extractMediaSize(message.media);
481
499
  if (mediaSize != null && mediaSize > maxFileSizeBytes) {
482
500
  debugLog(`receiver ignoring message due to maxFileSizeMb; mediaSize=${mediaSize} limitBytes=${maxFileSizeBytes}`);
501
+ debugSend({ event: 'ignored', reason: 'maxFileSizeMb', mediaSize, limitBytes: maxFileSizeBytes });
483
502
  continue;
484
503
  }
485
504
  }
@@ -489,6 +508,7 @@ module.exports = function (RED) {
489
508
  // Now we only apply the ignore list when we can confidently identify a user sender.
490
509
  if (senderType === 'user' && senderId != null && ignore.includes(String(senderId))) {
491
510
  debugLog(`receiver ignoring message due to ignore list; userId=${senderId}`);
511
+ debugSend({ event: 'ignored', reason: 'ignore', userId: senderId });
492
512
  continue;
493
513
  }
494
514
 
@@ -506,7 +526,11 @@ module.exports = function (RED) {
506
526
  }
507
527
  };
508
528
 
509
- node.send(out);
529
+ if (debug) {
530
+ node.send([out, { payload: { event: 'output', out } }]);
531
+ } else {
532
+ node.send(out);
533
+ }
510
534
  if (debug) {
511
535
  node.log('receiver output: ' + util.inspect(out, { depth: null }));
512
536
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patricktobias86/node-red-telegram-account",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "description": "Node-RED nodes to communicate with GramJS.",
5
5
  "main": "nodes/config.js",
6
6
  "keywords": [
@@ -4,6 +4,7 @@ const proxyquire = require('proxyquire').noPreserveCache();
4
4
  function load() {
5
5
  const addCalls = [];
6
6
  const logs = [];
7
+ const sends = [];
7
8
  class TelegramClientStub {
8
9
  addEventHandler(fn, event) { addCalls.push({fn, event}); }
9
10
  removeEventHandler() {}
@@ -18,7 +19,7 @@ function load() {
18
19
  node._events = {};
19
20
  node.on = (e, fn) => { node._events[e] = fn; };
20
21
  node.log = (msg) => logs.push(msg);
21
- node.send = () => {};
22
+ node.send = (msg) => sends.push(msg);
22
23
  },
23
24
  registerType(name, ctor) { NodeCtor = ctor; },
24
25
  getNode() { return configNode; }
@@ -29,12 +30,12 @@ function load() {
29
30
  'telegram/events': { Raw: RawStub }
30
31
  })(RED);
31
32
 
32
- return { NodeCtor, addCalls, logs };
33
+ return { NodeCtor, addCalls, logs, sends };
33
34
  }
34
35
 
35
36
  describe('Receiver node debug with BigInt', function() {
36
37
  it('logs update and output without throwing', function() {
37
- const { NodeCtor, addCalls, logs } = load();
38
+ const { NodeCtor, addCalls, logs, sends } = load();
38
39
  const node = new NodeCtor({config:'c', ignore:'', debug:true});
39
40
  const handler = addCalls[0].fn;
40
41
  assert.doesNotThrow(() => handler({
@@ -43,5 +44,8 @@ describe('Receiver node debug with BigInt', function() {
43
44
  }));
44
45
  assert(logs.some(l => l.includes('receiver raw update')));
45
46
  assert(logs.some(l => l.includes('receiver output')));
47
+ assert(sends.some((msg) => Array.isArray(msg) && msg.length === 2));
48
+ assert(sends.some((msg) => Array.isArray(msg) && msg[1] && msg[1].payload && msg[1].payload.event === 'rawUpdate'));
49
+ assert(sends.some((msg) => Array.isArray(msg) && msg[1] && msg[1].payload && msg[1].payload.event === 'output'));
46
50
  });
47
51
  });
@@ -100,4 +100,46 @@ describe('Receiver node', function() {
100
100
 
101
101
  assert.strictEqual(sent.length, 1);
102
102
  });
103
+
104
+ it('populates chatId and senderId for string ids', function() {
105
+ const { NodeCtor, addCalls } = load();
106
+ const sent = [];
107
+ const node = new NodeCtor({config:'c', ignore:'', ignoreMessageTypes:'', maxFileSizeMb:''});
108
+ node.send = (msg) => sent.push(msg);
109
+ const handler = addCalls[0].fn;
110
+
111
+ handler({
112
+ className: 'UpdateNewChannelMessage',
113
+ message: {
114
+ fromId: { userId: '6304354944', className: 'PeerUser' },
115
+ peerId: { channelId: '2877134366', className: 'PeerChannel' },
116
+ message: 'hello'
117
+ }
118
+ });
119
+
120
+ assert.strictEqual(sent.length, 1);
121
+ assert.strictEqual(sent[0].payload.chatId, 2877134366);
122
+ assert.strictEqual(sent[0].payload.senderId, 6304354944);
123
+ });
124
+
125
+ it('populates chatId and senderId for Integer wrappers', function() {
126
+ const { NodeCtor, addCalls } = load();
127
+ const sent = [];
128
+ const node = new NodeCtor({config:'c', ignore:'', ignoreMessageTypes:'', maxFileSizeMb:''});
129
+ node.send = (msg) => sent.push(msg);
130
+ const handler = addCalls[0].fn;
131
+
132
+ handler({
133
+ className: 'UpdateNewChannelMessage',
134
+ message: {
135
+ fromId: { userId: { value: 6304354944n }, className: 'PeerUser' },
136
+ peerId: { channelId: { value: 2877134366n }, className: 'PeerChannel' },
137
+ message: 'hello'
138
+ }
139
+ });
140
+
141
+ assert.strictEqual(sent.length, 1);
142
+ assert.strictEqual(sent[0].payload.chatId, 2877134366);
143
+ assert.strictEqual(sent[0].payload.senderId, 6304354944);
144
+ });
103
145
  });