@patricktobias86/node-red-telegram-account 1.0.6

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.
@@ -0,0 +1,300 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('send-message', {
3
+ category: 'telegram-account',
4
+ color: '#229ED9',
5
+ icon: 'tg.png',
6
+ align: "right",
7
+ defaults: {
8
+ name: { value: '' },
9
+ chatId: { value: '' },
10
+ message: { value: '' },
11
+ config: { type: 'config', required: false },
12
+ parseMode: { value: 'md' }, // Default parse mode is Markdown
13
+ schedule: { value: '' }, // Default schedule is empty
14
+ replyTo: { value: '' }, // Reply to a message
15
+ attributes: { value: '' }, // Message attributes
16
+ formattingEntities: { value: '' }, // Message formatting entities
17
+ linkPreview: { value: false }, // Show link preview
18
+ file: { value: [] }, // File to be sent
19
+ thumb: { value: '' }, // Thumbnail for the file
20
+ forceDocument: { value: false }, // Send the file as a document
21
+ clearDraft: { value: false }, // Clear existing draft
22
+ buttons: { value: '' }, // Buttons to be shown after sending
23
+ silent: { value: false }, // Whether to notify in a broadcast channel
24
+ supportStreaming: { value: false }, // Whether the sent video supports streaming
25
+ noforwards: { value: false }, // Disable forwarding
26
+ commentTo: { value: '' }, // Comment to a message in a broadcast channel
27
+ topMsgId: { value: '' }, // Reply to a specific thread
28
+ },
29
+ inputs: 1,
30
+ outputs: 1,
31
+ label: function () {
32
+ return this.name || 'Send Message';
33
+ },
34
+ oneditprepare: function () {
35
+ const node = this;
36
+
37
+ $("#node-input-parseMode").change(function () {
38
+ if ($(this).val() === "html") {
39
+ $("#node-linkPreview-row").show();
40
+ } else {
41
+ $("#node-linkPreview-row").hide();
42
+ }
43
+ });
44
+
45
+
46
+ // const filesContainer = $("#node-input-files-container");
47
+ // if (Array.isArray(node.file)) {
48
+ // node.file.forEach(file => {
49
+ // const fileInput = `
50
+ // <div class="node-input-file-container">
51
+ // <input type="text" class="node-input-file" style="display: block; margin-top: 5px;" value="${file}">
52
+ // <button class="node-input-remove-file editor-button editor-button-small editor-button-delete" type="button">Remove</button>
53
+ // </div>
54
+ // `;
55
+ // filesContainer.append(fileInput);
56
+ // });
57
+ // }
58
+
59
+ // $("#node-input-add-file").click(function () {
60
+ // const filesContainer = $("#node-input-files-container");
61
+ // const fileInput = `
62
+ // <div class="node-input-file-container">
63
+ // <input type="text" class="node-input-file" style="display: block; margin-top: 5px;">
64
+ // <button class="node-input-remove-file editor-button editor-button-small editor-button-delete" type="button">Remove</button>
65
+ // </div>
66
+ // `;
67
+ // filesContainer.append(fileInput);
68
+ // });
69
+
70
+ // $("#node-input-files-container").on("click", ".node-input-remove-file", function () {
71
+ // $(this).closest(".node-input-file-container").remove();
72
+ // const removedIndex = $(this).closest(".node-input-file-container").index();
73
+ // const updatedFiles = node.file || [];
74
+ // updatedFiles.splice(removedIndex, 1);
75
+ // node.file = updatedFiles;
76
+ // });
77
+
78
+ // $("#node-input-files-container").on("change", ".node-input-file", function () {
79
+ // const fileInput = $(this);
80
+ // const updatedFiles = node.file || [];
81
+ // updatedFiles.push(fileInput.val());
82
+ // node.file = updatedFiles;
83
+ // });
84
+ },
85
+ });
86
+ </script>
87
+
88
+
89
+ <script type="text/html" data-template-name="send-message">
90
+ <div class="form-row">
91
+ <label for="node-input-name">
92
+ <i class="fa fa-tag"></i> Name
93
+ </label>
94
+ <input type="text" id="node-input-name" placeholder="Name">
95
+ </div>
96
+ <div class="form-row">
97
+ <label for="node-input-config">
98
+ <i class="fa fa-gear"></i> Config
99
+ </label>
100
+ <input type="hidden" id="node-input-config">
101
+ </div>
102
+
103
+ <div class="form-row">
104
+ <label for="node-input-chat_id">
105
+ <i class="fa fa-user"></i> Chat ID
106
+ </label>
107
+ <input type="text" id="node-input-chatId" placeholder="Peer ID">
108
+ </div>
109
+
110
+ <div class="form-row">
111
+ <label for="node-input-message">
112
+ <i class="fa fa-pencil"></i> Message
113
+ </label>
114
+ <textarea type="text" id="node-input-message" placeholder="Message"></textarea>
115
+ </div>
116
+
117
+ <div class="form-row">
118
+ <label for="node-input-parseMode">
119
+ <i class="fa fa-code"></i> Parse Mode
120
+ </label>
121
+ <select id="node-input-parseMode">
122
+ <option value="md" selected>Markdown</option>
123
+ <option value="html">HTML</option>
124
+ </select>
125
+ </div>
126
+
127
+ <div class="form-row">
128
+ <label for="node-input-schedule">
129
+ <i class="fa fa-clock"></i> Schedule
130
+ </label>
131
+ <input type="datetime-local" id="node-input-schedule" placeholder="Schedule">
132
+ </div>
133
+ <div class="form-row" id="node-linkPreview-row">
134
+ <label for="node-input-linkPreview">
135
+ <i class="fa fa-link"></i> Show Link Preview
136
+ </label>
137
+ <input type="checkbox" id="node-input-linkPreview">
138
+ </div>
139
+
140
+ <div class="form-row">
141
+ <label>
142
+ <i class="fa fa-file"></i> Files
143
+ </label>
144
+ <div id="node-input-files-container">
145
+
146
+ </div>
147
+ <button id="node-input-add-file" class="editor-button editor-button-large editor-button-add" style="margin-top: 1rem;" type="button">Add File</button>
148
+ </div>
149
+
150
+ <div class="form-row" id="node-thumb-row">
151
+ <label for="node-input-thumb">
152
+ <i class="fa fa-file-image"></i> Thumbnail (Optional)
153
+ </label>
154
+ <input type="text" id="node-input-thumb">
155
+ </div>
156
+
157
+ <div class="form-row">
158
+ <label for="node-input-forceDocument">
159
+ <i class="fa fa-file"></i> Force Send as Document
160
+ </label>
161
+ <input type="checkbox" id="node-input-forceDocument">
162
+ </div>
163
+
164
+ <div class="form-row">
165
+ <label for="node-input-clearDraft">
166
+ <i class="fa fa-trash"></i> Clear Existing Draft
167
+ </label>
168
+ <input type="checkbox" id="node-input-clearDraft">
169
+ </div>
170
+
171
+ <div class="form-row">
172
+ <label for="node-input-buttons">
173
+ <i class="fa fa-th"></i> Buttons
174
+ </label>
175
+ <textarea type="text" id="node-input-buttons" placeholder="Buttons"></textarea>
176
+ </div>
177
+
178
+ <div class="form-row">
179
+ <label for="node-input-silent">
180
+ <i class="fa fa-bell-slash"></i> Silent Notification
181
+ </label>
182
+ <input type="checkbox" id="node-input-silent">
183
+ </div>
184
+
185
+ <div class="form-row">
186
+ <label for="node-input-supportStreaming">
187
+ <i class="fa fa-video"></i> Support Streaming
188
+ </label>
189
+ <input type="checkbox" id="node-input-supportStreaming">
190
+ </div>
191
+
192
+ <div class="form-row">
193
+ <label for="node-input-noforwards">
194
+ <i class="fa fa-forward"></i> Disable Forwarding
195
+ </label>
196
+ <input type="checkbox" id="node-input-noforwards">
197
+ </div>
198
+
199
+ <div class="form-row">
200
+ <label for="node-input-commentTo">
201
+ <i class="fa fa-comments"></i> Comment To Message
202
+ </label>
203
+ <input type="text" id="node-input-commentTo" placeholder="Comment To">
204
+ </div>
205
+
206
+ <div class="form-row">
207
+ <label for="node-input-topMsgId">
208
+ <i class="fa fa-reply"></i> Reply To Thread
209
+ </label>
210
+ <input type="text" id="node-input-topMsgId" placeholder="Top Msg ID">
211
+ </div>
212
+ </script>
213
+
214
+ <script type="text/html" data-help-name="send-message">
215
+ <p>The <b>send-message</b> node allows sending messages via Telegram using the <code>telegram</code> library. It supports various message types, formatting options, and additional features like scheduling and silent messages.</p>
216
+
217
+ <h3>Inputs</h3>
218
+ <dl class="message-properties">
219
+ <dt>payload.chatId
220
+ <span class="property-type">string</span>
221
+ </dt>
222
+ <dd>The recipient's chat ID, username (prefixed with <code>@</code>), or "me" for personal chats.</dd>
223
+
224
+ <dt>payload.message
225
+ <span class="property-type">string</span>
226
+ </dt>
227
+ <dd>The message text to send.</dd>
228
+
229
+ <dt>payload.parseMode
230
+ <span class="property-type">string</span>
231
+ </dt>
232
+ <dd>Specifies the formatting mode, such as <code>markdown</code> or <code>html</code>.</dd>
233
+
234
+ <dt>payload.schedule
235
+ <span class="property-type">string</span>
236
+ </dt>
237
+ <dd>The timestamp (or ISO date string) to schedule the message for later sending.</dd>
238
+
239
+ <dt>payload.replyTo
240
+ <span class="property-type">number</span>
241
+ </dt>
242
+ <dd>The ID of the message to reply to, if applicable.</dd>
243
+
244
+ <dt>payload.attributes
245
+ <span class="property-type">object</span>
246
+ </dt>
247
+ <dd>Additional attributes for the message.</dd>
248
+
249
+ <dt>payload.linkPreview
250
+ <span class="property-type">boolean</span>
251
+ </dt>
252
+ <dd>Determines whether to show link previews in the message.</dd>
253
+
254
+ <dt>payload.file
255
+ <span class="property-type">string</span>
256
+ </dt>
257
+ <dd>The path to a file to send (e.g., images, videos, documents).</dd>
258
+
259
+ <dt>payload.thumb
260
+ <span class="property-type">string</span>
261
+ </dt>
262
+ <dd>The path to a thumbnail for the file, if applicable.</dd>
263
+
264
+ <dt>payload.buttons
265
+ <span class="property-type">array</span>
266
+ </dt>
267
+ <dd>An array of button configurations for inline or reply keyboards.</dd>
268
+
269
+ <dt>payload.silent
270
+ <span class="property-type">boolean</span>
271
+ </dt>
272
+ <dd>If true, sends the message silently (no notification sound).</dd>
273
+ </dl>
274
+
275
+ <h3>Outputs</h3>
276
+ <dl class="message-properties">
277
+ <dt>payload.response
278
+ <span class="property-type">object</span>
279
+ </dt>
280
+ <dd>The response from the Telegram API, containing details of the sent message.</dd>
281
+ </dl>
282
+
283
+ <h3>Details</h3>
284
+ <p>To use the <b>send-message</b> node, you must provide the recipient's chat ID and the message content. Additional parameters like <code>file</code>, <code>thumb</code>, and <code>buttons</code> enable sending multimedia messages or interactive content. The node automatically resolves usernames prefixed with <code>@</code> to their corresponding chat entities.</p>
285
+
286
+ <p>If scheduling is enabled, the <code>schedule</code> parameter should contain a valid timestamp or ISO date string. When sending files, ensure the <code>file</code> parameter specifies the correct path or URL.</p>
287
+
288
+ <h3>Example</h3>
289
+ <pre>
290
+ {
291
+ "payload": {
292
+ "chatId": "@example_user",
293
+ "message": "Hello, World!",
294
+ "parseMode": "markdown",
295
+ "silent": true
296
+ }
297
+ }
298
+ </pre>
299
+ <p>This input sends a silent message in Markdown format to the user <code>@example_user</code>.</p>
300
+ </script>
@@ -0,0 +1,83 @@
1
+ const { TelegramClient } = require("telegram");
2
+ const { parseID } = require("telegram/Utils");
3
+
4
+ module.exports = function (RED) {
5
+ function SendMessage(config) {
6
+ RED.nodes.createNode(this, config);
7
+ this.config = RED.nodes.getNode(config.config);
8
+ var node = this;
9
+
10
+ this.on('input', async function (msg) {
11
+ let chatId = msg.payload.chatId || config.chatId;
12
+ const message = msg.payload.message || config.message;
13
+ const parseMode = msg.payload.parseMode || config.parseMode;
14
+ const schedule = msg.payload.schedule || config.schedule;
15
+ const replyTo = msg.payload.replyTo || config.replyTo;
16
+ const attributes = msg.payload.attributes || config.attributes;
17
+ const formattingEntities = msg.payload.formattingEntities || config.formattingEntities;
18
+ const linkPreview = msg.payload.linkPreview || config.linkPreview;
19
+ const file = msg.payload.file || config.file;
20
+ const thumb = msg.payload.thumb || config.thumb;
21
+ const forceDocument = msg.payload.forceDocument || config.forceDocument;
22
+ const clearDraft = msg.payload.clearDraft || config.clearDraft;
23
+ const buttons = msg.payload.buttons || config.buttons;
24
+ const silent = msg.payload.silent || config.silent;
25
+ const supportStreaming = msg.payload.supportStreaming || config.supportStreaming;
26
+ const noforwards = msg.payload.noforwards || config.noforwards;
27
+ const commentTo = msg.payload.commentTo || config.commentTo;
28
+ const topMsgId = msg.payload.topMsgId || config.topMsgId;
29
+
30
+ /** @type {TelegramClient} */
31
+ const client = msg.payload?.client ? msg.payload.client : this.config.client;
32
+ let peerId = chatId === "me" ? chatId : parseID(chatId);
33
+
34
+ try {
35
+ const params = {
36
+ message: message,
37
+ parseMode: parseMode,
38
+ replyTo: replyTo !== ""? replyTo:undefined,
39
+ attributes: attributes,
40
+ formattingEntities: formattingEntities !== ""? formattingEntities:undefined,
41
+ linkPreview: linkPreview,
42
+ file: file !== "" && file.length > 1? file:undefined,
43
+ thumb: thumb,
44
+ forceDocument: forceDocument,
45
+ clearDraft: clearDraft,
46
+ buttons: buttons !== "" ? buttons : undefined,
47
+ silent: silent,
48
+ supportStreaming: supportStreaming,
49
+ noforwards: noforwards,
50
+ commentTo: commentTo !== "" ? commentTo : undefined,
51
+ topMsgId: topMsgId !== topMsgId ? commentTo : undefined,
52
+ };
53
+
54
+ if (schedule) {
55
+ params.schedule = new Date(schedule).getTime() / 1000;
56
+ }
57
+
58
+ let response;
59
+ if (chatId[0] === "@") {
60
+ peerId = await client.getEntity(chatId);
61
+ }
62
+
63
+
64
+ try {
65
+ response = await client.sendMessage(peerId, params);
66
+ } catch (error) {
67
+ const entity = await client.getInputEntity(peerId)
68
+ await client.sendMessage(entity, params);
69
+ }
70
+
71
+ node.send({
72
+ payload: { response },
73
+ });
74
+ } catch (err) {
75
+ node.error('Error send message: ' + err.message);
76
+ }
77
+
78
+ });
79
+
80
+ }
81
+
82
+ RED.nodes.registerType('send-message', SendMessage);
83
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@patricktobias86/node-red-telegram-account",
3
+ "version": "1.0.6",
4
+ "description": "",
5
+ "main": "nodes/config.js",
6
+ "scripts": {
7
+ "dev": "npm install /home/user/Desktop/node-red-telegram-account -g & node-red"
8
+ },
9
+ "keywords": [
10
+ "node-red",
11
+ "telegram"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/patricktobias86/node-red-telegram-account.git"
16
+ },
17
+ "author": {
18
+ "name": "Patrick Tobias",
19
+ "url": "https://github.com/patricktobias86"
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/patricktobias86/node-red-telegram-account/issues"
26
+ },
27
+ "homepage": "https://github.com/patricktobias86/node-red-telegram-account#readme",
28
+ "license": "MIT",
29
+ "node-red": {
30
+ "nodes": {
31
+ "telegram-account-auth": "nodes/auth.js",
32
+ "telegram-account-config": "nodes/config.js",
33
+ "telegram-account-receiver": "nodes/receiver.js",
34
+ "telegram-account-command": "nodes/command.js",
35
+ "telegram-account-send-message": "nodes/send-message.js",
36
+ "telegram-account-send-file": "nodes/send-file.js",
37
+ "telegram-account-entity": "nodes/get-entity.js",
38
+ "telegram-account-delete-message": "nodes/delete-message.js",
39
+ "telegram-account-iter-dialog": "nodes/iter-dialogs.js",
40
+ "telegram-account-iter-messages": "nodes/iter-messages.js",
41
+ "telegram-account-promote-admin": "nodes/promote-admin.js"
42
+ }
43
+ },
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "telegram": "^2.17.10"
49
+ }
50
+ }