@patricktobias86/node-red-telegram-account 1.1.15 → 1.1.16

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,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.1.16] - 2025-09-22
6
+ ### Added
7
+ - Receiver node option to ignore configurable message types (such as videos or documents) to prevent oversized uploads.
8
+ ### Changed
9
+ - Receiver node collects detailed media type metadata to power the new filter while keeping debug logging informative.
10
+
5
11
  ## [1.1.15] - 2025-09-21
6
12
  ### Added
7
13
  - Receiver node option to drop updates when media exceeds a configurable size threshold, preventing large downloads.
package/README.md CHANGED
@@ -18,7 +18,7 @@ See [docs/NODES.md](docs/NODES.md) for a detailed description of every node. Bel
18
18
 
19
19
  - **config** – stores your API credentials and caches sessions for reuse.
20
20
  - **auth** – interactive login that outputs a `stringSession` (also set on `msg.stringSession`).
21
- - **receiver** – emits messages for every incoming update (with optional ignore list and media size limit). Event listeners are cleaned up on node close so redeploys won't duplicate messages.
21
+ - **receiver** – emits messages for every incoming update (with optional ignore list, message type filter, and media size limit). Event listeners are cleaned up on node close so redeploys won't duplicate messages.
22
22
  - **command** – triggers when an incoming message matches a command or regex. Event listeners are removed on redeploy to prevent duplicates.
23
23
  - **send-message** – sends text or media messages with rich options.
24
24
  - **send-files** – uploads one or more files with captions and buttons.
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. Can ignore specific user IDs and optionally skip media above a configurable size. Event handlers are automatically removed when the node is closed. |
11
+ | **receiver** | Emits an output message for every incoming Telegram message. Can ignore specific user IDs, skip selected message types (e.g. videos or documents), and optionally drop media above a configurable size. 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. |
@@ -7,6 +7,7 @@
7
7
  name: { value: '' },
8
8
  config: { type: 'config', required: false },
9
9
  ignore: { value:""},
10
+ ignoreMessageTypes: { value: "" },
10
11
  debug: { value: false },
11
12
  maxFileSizeMb: { value: "" }
12
13
  },
@@ -59,6 +60,17 @@
59
60
  style="width: 60%"
60
61
  ></textarea>
61
62
  </div>
63
+ <div class="form-row">
64
+ <label for="node-input-ignoreMessageTypes">
65
+ <i class="fa fa-ban"></i> Ignore message types
66
+ </label>
67
+ <textarea
68
+ id="node-input-ignoreMessageTypes"
69
+ placeholder="e.g. video, document, sticker"
70
+ style="width: 60%"
71
+ ></textarea>
72
+ <p class="form-tips">Separate types with commas or new lines.</p>
73
+ </div>
62
74
  <div class="form-row">
63
75
  <label for="node-input-maxFileSizeMb">
64
76
  <i class="fa fa-download"></i> Max media size (MB)
@@ -101,6 +113,11 @@
101
113
  </dt>
102
114
  <dd>A newline-separated list of user IDs to ignore. Messages from these users will not trigger the output.</dd>
103
115
 
116
+ <dt>Ignore message types
117
+ <span class="property-type">string</span>
118
+ </dt>
119
+ <dd>List of message or media types to skip (for example <code>video</code>, <code>document</code>, or <code>sticker</code>). Separate multiple entries with commas or new lines.</dd>
120
+
104
121
  <dt>Max media size (MB)
105
122
  <span class="property-type">number</span>
106
123
  </dt>
@@ -147,6 +164,7 @@
147
164
  <ul>
148
165
  <li>Ensure the Telegram bot has sufficient permissions to receive messages in the configured chat or channel.</li>
149
166
  <li>The <b>Ignore List</b> only filters messages based on the sender's user ID.</li>
167
+ <li>Use <b>Ignore message types</b> to drop updates that contain media you don't want to process, such as large videos or documents.</li>
150
168
  <li>For advanced filtering based on message content, consider chaining this node with additional processing nodes in Node-RED.</li>
151
169
  </ul>
152
170
  </script>
package/nodes/receiver.js CHANGED
@@ -1,6 +1,153 @@
1
1
  const { NewMessage } = require("telegram/events");
2
2
  const util = require("util");
3
3
 
4
+ const splitList = (value) => {
5
+ if (typeof value !== 'string') {
6
+ return [];
7
+ }
8
+ return value
9
+ .split(/[\n,\r]/)
10
+ .map((entry) => entry.trim())
11
+ .filter(Boolean);
12
+ };
13
+
14
+ const toLowerCaseSet = (values) => {
15
+ const result = new Set();
16
+ for (const value of values) {
17
+ result.add(value.toLowerCase());
18
+ }
19
+ return result;
20
+ };
21
+
22
+ const addType = (target, value) => {
23
+ if (!value) {
24
+ return;
25
+ }
26
+ target.add(String(value).toLowerCase());
27
+ };
28
+
29
+ const collectDocumentTypes = (document, types) => {
30
+ if (!document) {
31
+ return;
32
+ }
33
+
34
+ addType(types, 'document');
35
+
36
+ if (Array.isArray(document.attributes)) {
37
+ for (const attribute of document.attributes) {
38
+ if (!attribute) {
39
+ continue;
40
+ }
41
+ const attributeName = attribute.className || attribute._;
42
+ addType(types, attributeName);
43
+ switch (attributeName) {
44
+ case 'DocumentAttributeVideo':
45
+ addType(types, 'video');
46
+ break;
47
+ case 'DocumentAttributeAudio':
48
+ addType(types, 'audio');
49
+ if (attribute.voice) {
50
+ addType(types, 'voice');
51
+ }
52
+ break;
53
+ case 'DocumentAttributeAnimated':
54
+ addType(types, 'animation');
55
+ break;
56
+ case 'DocumentAttributeSticker':
57
+ addType(types, 'sticker');
58
+ break;
59
+ default:
60
+ break;
61
+ }
62
+ }
63
+ }
64
+
65
+ if (typeof document.mimeType === 'string') {
66
+ const mimeType = document.mimeType.toLowerCase();
67
+ addType(types, mimeType);
68
+ const slashIndex = mimeType.indexOf('/');
69
+ if (slashIndex > 0) {
70
+ addType(types, mimeType.slice(0, slashIndex));
71
+ }
72
+ if (mimeType.startsWith('video/')) {
73
+ addType(types, 'video');
74
+ } else if (mimeType.startsWith('audio/')) {
75
+ addType(types, 'audio');
76
+ } else if (mimeType.startsWith('image/')) {
77
+ addType(types, 'image');
78
+ }
79
+ }
80
+ };
81
+
82
+ const collectMediaTypes = (media, types) => {
83
+ if (!media) {
84
+ return;
85
+ }
86
+ addType(types, 'media');
87
+ addType(types, media.className || media._);
88
+
89
+ if (media.document) {
90
+ collectDocumentTypes(media.document, types);
91
+ }
92
+ if (media.photo) {
93
+ addType(types, 'photo');
94
+ }
95
+ if (media.webpage) {
96
+ addType(types, 'webpage');
97
+ if (media.webpage.document) {
98
+ collectDocumentTypes(media.webpage.document, types);
99
+ }
100
+ if (media.webpage.photo) {
101
+ addType(types, 'photo');
102
+ }
103
+ }
104
+ if (media.poll) {
105
+ addType(types, 'poll');
106
+ }
107
+ if (media.contact) {
108
+ addType(types, 'contact');
109
+ }
110
+ if (media.geo || media.geoPoint) {
111
+ addType(types, 'location');
112
+ }
113
+ if (media.venue) {
114
+ addType(types, 'venue');
115
+ }
116
+ if (media.game) {
117
+ addType(types, 'game');
118
+ }
119
+ if (media.sticker) {
120
+ addType(types, 'sticker');
121
+ }
122
+ };
123
+
124
+ const collectMessageTypes = (message) => {
125
+ const types = new Set();
126
+ if (!message || typeof message !== 'object') {
127
+ return types;
128
+ }
129
+
130
+ collectMediaTypes(message.media, types);
131
+
132
+ if (typeof message.message === 'string' && message.message.length > 0 && !message.media) {
133
+ addType(types, 'text');
134
+ }
135
+
136
+ if (message.action) {
137
+ const actionName = message.action.className || message.action._;
138
+ addType(types, actionName);
139
+ if (actionName) {
140
+ addType(types, 'service');
141
+ }
142
+ }
143
+
144
+ if (message.ttlPeriod) {
145
+ addType(types, 'self-destructing');
146
+ }
147
+
148
+ return types;
149
+ };
150
+
4
151
  module.exports = function (RED) {
5
152
  function Receiver(config) {
6
153
  RED.nodes.createNode(this, config);
@@ -8,10 +155,8 @@ module.exports = function (RED) {
8
155
  this.debugEnabled = config.debug;
9
156
  var node = this;
10
157
  const client = this.config.client;
11
- const ignore = (config.ignore || "")
12
- .split(/\n/)
13
- .map((entry) => entry.trim())
14
- .filter(Boolean);
158
+ const ignore = splitList(config.ignore || "");
159
+ const ignoredMessageTypes = toLowerCaseSet(splitList(config.ignoreMessageTypes || ""));
15
160
  const maxFileSizeMb = Number(config.maxFileSizeMb);
16
161
  const maxFileSizeBytes = Number.isFinite(maxFileSizeMb) && maxFileSizeMb > 0
17
162
  ? maxFileSizeMb * 1024 * 1024
@@ -106,6 +251,17 @@ module.exports = function (RED) {
106
251
  return;
107
252
  }
108
253
 
254
+ if (ignoredMessageTypes.size > 0) {
255
+ const messageTypes = collectMessageTypes(message);
256
+ const shouldIgnoreType = Array.from(messageTypes).some((type) => ignoredMessageTypes.has(type));
257
+ if (shouldIgnoreType) {
258
+ if (debug) {
259
+ node.log(`receiver ignoring update with types: ${Array.from(messageTypes).join(', ')}`);
260
+ }
261
+ return;
262
+ }
263
+ }
264
+
109
265
  if (maxFileSizeBytes != null) {
110
266
  const mediaSize = extractMediaSize(message.media);
111
267
  if (mediaSize != null && mediaSize > maxFileSizeBytes) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patricktobias86/node-red-telegram-account",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "description": "Node-RED nodes to communicate with GramJS.",
5
5
  "main": "nodes/config.js",
6
6
  "keywords": [
@@ -44,7 +44,7 @@ describe('Receiver node', function() {
44
44
  it('skips media updates when size exceeds threshold', function() {
45
45
  const { NodeCtor, addCalls } = load();
46
46
  const sent = [];
47
- const node = new NodeCtor({config:'c', ignore:'', maxFileSizeMb:'5'});
47
+ const node = new NodeCtor({config:'c', ignore:'', ignoreMessageTypes:'', maxFileSizeMb:'5'});
48
48
  node.send = (msg) => sent.push(msg);
49
49
  const handler = addCalls[0].fn;
50
50
 
@@ -56,7 +56,7 @@ describe('Receiver node', function() {
56
56
  it('delivers media updates when size is below threshold', function() {
57
57
  const { NodeCtor, addCalls } = load();
58
58
  const sent = [];
59
- const node = new NodeCtor({config:'c', ignore:'', maxFileSizeMb:'5'});
59
+ const node = new NodeCtor({config:'c', ignore:'', ignoreMessageTypes:'', maxFileSizeMb:'5'});
60
60
  node.send = (msg) => sent.push(msg);
61
61
  const handler = addCalls[0].fn;
62
62
 
@@ -64,4 +64,28 @@ describe('Receiver node', function() {
64
64
 
65
65
  assert.strictEqual(sent.length, 1);
66
66
  });
67
+
68
+ it('skips updates when media type is ignored', function() {
69
+ const { NodeCtor, addCalls } = load();
70
+ const sent = [];
71
+ const node = new NodeCtor({config:'c', ignore:'', ignoreMessageTypes:'video\ndocument', maxFileSizeMb:''});
72
+ node.send = (msg) => sent.push(msg);
73
+ const handler = addCalls[0].fn;
74
+
75
+ handler({ message: { fromId: { userId: 123 }, media: { document: { mimeType: 'video/mp4', attributes: [{ className: 'DocumentAttributeVideo' }] } } } });
76
+
77
+ assert.strictEqual(sent.length, 0);
78
+ });
79
+
80
+ it('delivers updates when media type is not ignored', function() {
81
+ const { NodeCtor, addCalls } = load();
82
+ const sent = [];
83
+ const node = new NodeCtor({config:'c', ignore:'', ignoreMessageTypes:'voice', maxFileSizeMb:''});
84
+ node.send = (msg) => sent.push(msg);
85
+ const handler = addCalls[0].fn;
86
+
87
+ handler({ message: { fromId: { userId: 123 }, media: { document: { mimeType: 'video/mp4', attributes: [{ className: 'DocumentAttributeVideo' }] } } } });
88
+
89
+ assert.strictEqual(sent.length, 1);
90
+ });
67
91
  });