@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.
- package/.gitattributes +2 -0
- package/.github/workflows/npm-publish.yml +33 -0
- package/README.md +1 -0
- package/icons/tg.png +0 -0
- package/nodes/auth.html +138 -0
- package/nodes/auth.js +60 -0
- package/nodes/command.html +135 -0
- package/nodes/command.js +53 -0
- package/nodes/config.html +131 -0
- package/nodes/config.js +58 -0
- package/nodes/delete-message.html +96 -0
- package/nodes/delete-message.js +27 -0
- package/nodes/get-entity.html +87 -0
- package/nodes/get-entity.js +36 -0
- package/nodes/iter-dialogs.html +212 -0
- package/nodes/iter-dialogs.js +54 -0
- package/nodes/iter-messages.html +365 -0
- package/nodes/iter-messages.js +94 -0
- package/nodes/promote-admin.html +24 -0
- package/nodes/promote-admin.js +55 -0
- package/nodes/receiver.html +128 -0
- package/nodes/receiver.js +32 -0
- package/nodes/send-file.html +463 -0
- package/nodes/send-file.js +72 -0
- package/nodes/send-message.html +300 -0
- package/nodes/send-message.js +83 -0
- package/package.json +50 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { NewMessage } = require("telegram/events");
|
|
2
|
+
|
|
3
|
+
module.exports = function (RED) {
|
|
4
|
+
function Receiver(config) {
|
|
5
|
+
RED.nodes.createNode(this, config);
|
|
6
|
+
this.config = RED.nodes.getNode(config.config);
|
|
7
|
+
var node = this;
|
|
8
|
+
const client = this.config.client;
|
|
9
|
+
const ignore = config.ignore.split(/\n/);
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
client.addEventHandler((update) => {
|
|
14
|
+
if(update.message.fromId != null && !ignore.includes(update.message.fromId.userId.toString())){
|
|
15
|
+
|
|
16
|
+
node.send({
|
|
17
|
+
payload:{
|
|
18
|
+
update
|
|
19
|
+
}
|
|
20
|
+
} )
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}, new NewMessage());
|
|
24
|
+
|
|
25
|
+
} catch (err) {
|
|
26
|
+
node.error('Ошибка авторизации: ' + err.message);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
RED.nodes.registerType('receiver', Receiver);
|
|
32
|
+
};
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('send-files', {
|
|
3
|
+
category: 'telegram',
|
|
4
|
+
color: '#32a3e0',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
config: { type: 'config', required: true },
|
|
8
|
+
chatId: { value: '', required: true },
|
|
9
|
+
files: { value: '', required: true },
|
|
10
|
+
caption: { value: '' },
|
|
11
|
+
forceDocument: { value: false },
|
|
12
|
+
fileSize: { value: 0 },
|
|
13
|
+
clearDraft: { value: false },
|
|
14
|
+
progressCallback: { value: '' },
|
|
15
|
+
replyTo: { value: '' },
|
|
16
|
+
attributes: { value: '' },
|
|
17
|
+
thumb: { value: '' },
|
|
18
|
+
voiceNote: { value: false },
|
|
19
|
+
videoNote: { value: false },
|
|
20
|
+
supportsStreaming: { value: false },
|
|
21
|
+
parseMode: { value: '' },
|
|
22
|
+
formattingEntities: { value: '' },
|
|
23
|
+
silent: { value: false },
|
|
24
|
+
scheduleDate: { value: 0 },
|
|
25
|
+
buttons: { value: '' },
|
|
26
|
+
workers: { value: 0 },
|
|
27
|
+
noforwards: { value: false },
|
|
28
|
+
commentTo: { value: '' },
|
|
29
|
+
topMsgId: { value: '' },
|
|
30
|
+
},
|
|
31
|
+
inputs: 1,
|
|
32
|
+
outputs: 1,
|
|
33
|
+
icon: 'file.png',
|
|
34
|
+
paletteLabel: 'Send Files',
|
|
35
|
+
label: function () {
|
|
36
|
+
return this.name || 'Send Files';
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<script type="text/html" data-template-name="send-files">
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-input-name">
|
|
44
|
+
<i class="fa fa-tag"></i> Name
|
|
45
|
+
</label>
|
|
46
|
+
<input
|
|
47
|
+
type="text"
|
|
48
|
+
id="node-input-name"
|
|
49
|
+
placeholder="Name"
|
|
50
|
+
style="width: 60%"
|
|
51
|
+
ng-model="name"
|
|
52
|
+
/>
|
|
53
|
+
</div>
|
|
54
|
+
<div class="form-row">
|
|
55
|
+
<label for="node-input-config">
|
|
56
|
+
<i class="fa fa-tag"></i> Config
|
|
57
|
+
</label>
|
|
58
|
+
<input
|
|
59
|
+
type="text"
|
|
60
|
+
id="node-input-config"
|
|
61
|
+
placeholder="Config"
|
|
62
|
+
style="width: 60%"
|
|
63
|
+
ng-model="config"
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="form-row">
|
|
67
|
+
<label for="node-input-chatId">
|
|
68
|
+
<i class="fa fa-tag"></i> Chat ID
|
|
69
|
+
</label>
|
|
70
|
+
<input
|
|
71
|
+
type="text"
|
|
72
|
+
id="node-input-chatId"
|
|
73
|
+
placeholder="Chat ID"
|
|
74
|
+
style="width: 60%"
|
|
75
|
+
ng-model="chatId"
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
<div class="form-row">
|
|
79
|
+
<label for="node-input-files">
|
|
80
|
+
<i class="fa fa-tag"></i> Files (comma-separated)
|
|
81
|
+
</label>
|
|
82
|
+
<input
|
|
83
|
+
type="text"
|
|
84
|
+
id="node-input-files"
|
|
85
|
+
placeholder="url"
|
|
86
|
+
style="width: 60%"
|
|
87
|
+
ng-model="files"
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="form-row">
|
|
91
|
+
<label for="node-input-caption">
|
|
92
|
+
<i class="fa fa-tag"></i> Caption
|
|
93
|
+
</label>
|
|
94
|
+
<input
|
|
95
|
+
type="text"
|
|
96
|
+
id="node-input-caption"
|
|
97
|
+
placeholder="Caption"
|
|
98
|
+
style="width: 60%"
|
|
99
|
+
ng-model="caption"
|
|
100
|
+
/>
|
|
101
|
+
</div>
|
|
102
|
+
<div class="form-row">
|
|
103
|
+
<label for="node-input-forceDocument">
|
|
104
|
+
<i class="fa fa-tag"></i> Force Document
|
|
105
|
+
</label>
|
|
106
|
+
<input
|
|
107
|
+
type="checkbox"
|
|
108
|
+
id="node-input-forceDocument"
|
|
109
|
+
ng-model="forceDocument"
|
|
110
|
+
/>
|
|
111
|
+
</div>
|
|
112
|
+
<div class="form-row">
|
|
113
|
+
<label for="node-input-fileSize">
|
|
114
|
+
<i class="fa fa-tag"></i> File Size
|
|
115
|
+
</label>
|
|
116
|
+
<input
|
|
117
|
+
type="number"
|
|
118
|
+
id="node-input-fileSize"
|
|
119
|
+
placeholder="File Size"
|
|
120
|
+
style="width: 60%"
|
|
121
|
+
ng-model="fileSize"
|
|
122
|
+
/>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="form-row">
|
|
125
|
+
<label for="node-input-clearDraft">
|
|
126
|
+
<i class="fa fa-tag"></i> Clear Draft
|
|
127
|
+
</label>
|
|
128
|
+
<input
|
|
129
|
+
type="checkbox"
|
|
130
|
+
id="node-input-clearDraft"
|
|
131
|
+
ng-model="clearDraft"
|
|
132
|
+
/>
|
|
133
|
+
</div>
|
|
134
|
+
<div class="form-row">
|
|
135
|
+
<label for="node-input-progressCallback">
|
|
136
|
+
<i class="fa fa-tag"></i> Progress Callback
|
|
137
|
+
</label>
|
|
138
|
+
<input
|
|
139
|
+
type="text"
|
|
140
|
+
id="node-input-progressCallback"
|
|
141
|
+
placeholder="Progress Callback"
|
|
142
|
+
style="width: 60%"
|
|
143
|
+
ng-model="progressCallback"
|
|
144
|
+
/>
|
|
145
|
+
</div>
|
|
146
|
+
<div class="form-row">
|
|
147
|
+
<label for="node-input-replyTo">
|
|
148
|
+
<i class="fa fa-tag"></i> Reply To
|
|
149
|
+
</label>
|
|
150
|
+
<input
|
|
151
|
+
type="text"
|
|
152
|
+
id="node-input-replyTo"
|
|
153
|
+
placeholder="Reply To"
|
|
154
|
+
style="width: 60%"
|
|
155
|
+
ng-model="replyTo"
|
|
156
|
+
/>
|
|
157
|
+
</div>
|
|
158
|
+
<div class="form-row">
|
|
159
|
+
<label for="node-input-attributes">
|
|
160
|
+
<i class="fa fa-tag"></i> Attributes
|
|
161
|
+
</label>
|
|
162
|
+
<input
|
|
163
|
+
type="text"
|
|
164
|
+
id="node-input-attributes"
|
|
165
|
+
placeholder="Attributes"
|
|
166
|
+
style="width: 60%"
|
|
167
|
+
ng-model="attributes"
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
<div class="form-row">
|
|
171
|
+
<label for="node-input-thumb">
|
|
172
|
+
<i class="fa fa-tag"></i> Thumbnail
|
|
173
|
+
</label>
|
|
174
|
+
<input
|
|
175
|
+
type="text"
|
|
176
|
+
id="node-input-thumb"
|
|
177
|
+
placeholder="Thumbnail"
|
|
178
|
+
style="width: 60%"
|
|
179
|
+
ng-model="thumb"
|
|
180
|
+
/>
|
|
181
|
+
</div>
|
|
182
|
+
<div class="form-row">
|
|
183
|
+
<label for="node-input-voiceNote">
|
|
184
|
+
<i class="fa fa-tag"></i> Voice Note
|
|
185
|
+
</label>
|
|
186
|
+
<input
|
|
187
|
+
type="checkbox"
|
|
188
|
+
id="node-input-voiceNote"
|
|
189
|
+
ng-model="voiceNote"
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
<div class="form-row">
|
|
193
|
+
<label for="node-input-videoNote">
|
|
194
|
+
<i class="fa fa-tag"></i> Video Note
|
|
195
|
+
</label>
|
|
196
|
+
<input
|
|
197
|
+
type="checkbox"
|
|
198
|
+
id="node-input-videoNote"
|
|
199
|
+
ng-model="videoNote"
|
|
200
|
+
/>
|
|
201
|
+
</div>
|
|
202
|
+
<div class="form-row">
|
|
203
|
+
<label for="node-input-supportsStreaming">
|
|
204
|
+
<i class="fa fa-tag"></i> Supports Streaming
|
|
205
|
+
</label>
|
|
206
|
+
<input
|
|
207
|
+
type="checkbox"
|
|
208
|
+
id="node-input-supportsStreaming"
|
|
209
|
+
ng-model="supportsStreaming"
|
|
210
|
+
/>
|
|
211
|
+
</div>
|
|
212
|
+
<div class="form-row">
|
|
213
|
+
<label for="node-input-parseMode">
|
|
214
|
+
<i class="fa fa-tag"></i> Parse Mode
|
|
215
|
+
</label>
|
|
216
|
+
<input
|
|
217
|
+
type="text"
|
|
218
|
+
id="node-input-parseMode"
|
|
219
|
+
placeholder="Parse Mode"
|
|
220
|
+
style="width: 60%"
|
|
221
|
+
ng-model="parseMode"
|
|
222
|
+
/>
|
|
223
|
+
</div>
|
|
224
|
+
<div class="form-row">
|
|
225
|
+
<label for="node-input-formattingEntities">
|
|
226
|
+
<i class="fa fa-tag"></i> Formatting Entities
|
|
227
|
+
</label>
|
|
228
|
+
<input
|
|
229
|
+
type="text"
|
|
230
|
+
id="node-input-formattingEntities"
|
|
231
|
+
placeholder="Formatting Entities"
|
|
232
|
+
style="width: 60%"
|
|
233
|
+
ng-model="formattingEntities"
|
|
234
|
+
/>
|
|
235
|
+
</div>
|
|
236
|
+
<div class="form-row">
|
|
237
|
+
<label for="node-input-silent">
|
|
238
|
+
<i class="fa fa-tag"></i> Silent
|
|
239
|
+
</label>
|
|
240
|
+
<input
|
|
241
|
+
type="checkbox"
|
|
242
|
+
id="node-input-silent"
|
|
243
|
+
ng-model="silent"
|
|
244
|
+
/>
|
|
245
|
+
</div>
|
|
246
|
+
<div class="form-row">
|
|
247
|
+
<label for="node-input-scheduleDate">
|
|
248
|
+
<i class="fa fa-tag"></i> Schedule Date
|
|
249
|
+
</label>
|
|
250
|
+
<input
|
|
251
|
+
type="number"
|
|
252
|
+
id="node-input-scheduleDate"
|
|
253
|
+
placeholder="Schedule Date"
|
|
254
|
+
style="width: 60%"
|
|
255
|
+
ng-model="scheduleDate"
|
|
256
|
+
/>
|
|
257
|
+
</div>
|
|
258
|
+
<div class="form-row">
|
|
259
|
+
<label for="node-input-buttons">
|
|
260
|
+
<i class="fa fa-tag"></i> Buttons
|
|
261
|
+
</label>
|
|
262
|
+
<input
|
|
263
|
+
type="text"
|
|
264
|
+
id="node-input-buttons"
|
|
265
|
+
placeholder="Buttons"
|
|
266
|
+
style="width: 60%"
|
|
267
|
+
ng-model="buttons"
|
|
268
|
+
/>
|
|
269
|
+
</div>
|
|
270
|
+
<div class="form-row">
|
|
271
|
+
<label for="node-input-workers">
|
|
272
|
+
<i class="fa fa-tag"></i> Workers
|
|
273
|
+
</label>
|
|
274
|
+
<input
|
|
275
|
+
type="number"
|
|
276
|
+
id="node-input-workers"
|
|
277
|
+
placeholder="Workers"
|
|
278
|
+
style="width: 60%"
|
|
279
|
+
ng-model="workers"
|
|
280
|
+
/>
|
|
281
|
+
</div>
|
|
282
|
+
<div class="form-row">
|
|
283
|
+
<label for="node-input-noforwards">
|
|
284
|
+
<i class="fa fa-tag"></i> No Forwards
|
|
285
|
+
</label>
|
|
286
|
+
<input
|
|
287
|
+
type="checkbox"
|
|
288
|
+
id="node-input-noforwards"
|
|
289
|
+
ng-model="noforwards"
|
|
290
|
+
/>
|
|
291
|
+
</div>
|
|
292
|
+
<div class="form-row">
|
|
293
|
+
<label for="node-input-commentTo">
|
|
294
|
+
<i class="fa fa-tag"></i> Comment To
|
|
295
|
+
</label>
|
|
296
|
+
<input
|
|
297
|
+
type="text"
|
|
298
|
+
id="node-input-commentTo"
|
|
299
|
+
placeholder="Comment To"
|
|
300
|
+
style="width: 60%"
|
|
301
|
+
ng-model="commentTo"
|
|
302
|
+
/>
|
|
303
|
+
</div>
|
|
304
|
+
<div class="form-row">
|
|
305
|
+
<label for="node-input-topMsgId">
|
|
306
|
+
<i class="fa fa-tag"></i> Top Message ID
|
|
307
|
+
</label>
|
|
308
|
+
<input
|
|
309
|
+
type="text"
|
|
310
|
+
id="node-input-topMsgId"
|
|
311
|
+
placeholder="Top Message ID"
|
|
312
|
+
style="width: 60%"
|
|
313
|
+
ng-model="topMsgId"
|
|
314
|
+
/>
|
|
315
|
+
</div>
|
|
316
|
+
</script>
|
|
317
|
+
|
|
318
|
+
<script type="text/html" data-help-name="send-files">
|
|
319
|
+
<p>The <b>send-files</b> node allows you to send files to a Telegram chat or user using the Telegram API. It supports a wide range of parameters, including file attributes, captions, buttons, and scheduling options.</p>
|
|
320
|
+
|
|
321
|
+
<h3>Inputs</h3>
|
|
322
|
+
<dl class="message-properties">
|
|
323
|
+
<dt>payload.chatId
|
|
324
|
+
<span class="property-type">string</span>
|
|
325
|
+
</dt>
|
|
326
|
+
<dd>The ID or username of the chat or user to send files to.</dd>
|
|
327
|
+
|
|
328
|
+
<dt>payload.files
|
|
329
|
+
<span class="property-type">array</span>
|
|
330
|
+
</dt>
|
|
331
|
+
<dd>A list of file paths or URLs to be sent. Multiple files can be specified.</dd>
|
|
332
|
+
|
|
333
|
+
<dt>payload.caption
|
|
334
|
+
<span class="property-type">string</span>
|
|
335
|
+
</dt>
|
|
336
|
+
<dd>The caption text to include with the file. Supports Markdown or HTML formatting.</dd>
|
|
337
|
+
|
|
338
|
+
<dt>payload.forceDocument
|
|
339
|
+
<span class="property-type">boolean</span>
|
|
340
|
+
</dt>
|
|
341
|
+
<dd>If <code>true</code>, forces the file to be sent as a document instead of its native media type.</dd>
|
|
342
|
+
|
|
343
|
+
<dt>payload.fileSize
|
|
344
|
+
<span class="property-type">number</span>
|
|
345
|
+
</dt>
|
|
346
|
+
<dd>Specifies the file size, if known. Useful for optimization.</dd>
|
|
347
|
+
|
|
348
|
+
<dt>payload.clearDraft
|
|
349
|
+
<span class="property-type">boolean</span>
|
|
350
|
+
</dt>
|
|
351
|
+
<dd>If <code>true</code>, clears the draft in the chat before sending the file.</dd>
|
|
352
|
+
|
|
353
|
+
<dt>payload.progressCallback
|
|
354
|
+
<span class="property-type">function</span>
|
|
355
|
+
</dt>
|
|
356
|
+
<dd>A function to monitor the progress of file uploads.</dd>
|
|
357
|
+
|
|
358
|
+
<dt>payload.replyTo
|
|
359
|
+
<span class="property-type">number</span>
|
|
360
|
+
</dt>
|
|
361
|
+
<dd>The ID of the message to reply to with the file.</dd>
|
|
362
|
+
|
|
363
|
+
<dt>payload.attributes
|
|
364
|
+
<span class="property-type">object</span>
|
|
365
|
+
</dt>
|
|
366
|
+
<dd>Additional attributes for the file, such as file type or metadata.</dd>
|
|
367
|
+
|
|
368
|
+
<dt>payload.thumb
|
|
369
|
+
<span class="property-type">string</span>
|
|
370
|
+
</dt>
|
|
371
|
+
<dd>A path or URL to a thumbnail image for the file.</dd>
|
|
372
|
+
|
|
373
|
+
<dt>payload.voiceNote
|
|
374
|
+
<span class="property-type">boolean</span>
|
|
375
|
+
</dt>
|
|
376
|
+
<dd>If <code>true</code>, marks the file as a voice note.</dd>
|
|
377
|
+
|
|
378
|
+
<dt>payload.videoNote
|
|
379
|
+
<span class="property-type">boolean</span>
|
|
380
|
+
</dt>
|
|
381
|
+
<dd>If <code>true</code>, marks the file as a video note.</dd>
|
|
382
|
+
|
|
383
|
+
<dt>payload.supportsStreaming
|
|
384
|
+
<span class="property-type">boolean</span>
|
|
385
|
+
</dt>
|
|
386
|
+
<dd>If <code>true</code>, enables streaming support for video files.</dd>
|
|
387
|
+
|
|
388
|
+
<dt>payload.parseMode
|
|
389
|
+
<span class="property-type">string</span>
|
|
390
|
+
</dt>
|
|
391
|
+
<dd>Specifies the parse mode for captions (<code>Markdown</code> or <code>HTML</code>).</dd>
|
|
392
|
+
|
|
393
|
+
<dt>payload.silent
|
|
394
|
+
<span class="property-type">boolean</span>
|
|
395
|
+
</dt>
|
|
396
|
+
<dd>If <code>true</code>, sends the message silently without a notification.</dd>
|
|
397
|
+
|
|
398
|
+
<dt>payload.scheduleDate
|
|
399
|
+
<span class="property-type">string | number</span>
|
|
400
|
+
</dt>
|
|
401
|
+
<dd>Schedules the message to be sent at a specific time. Accepts a UNIX timestamp or date string.</dd>
|
|
402
|
+
|
|
403
|
+
<dt>payload.buttons
|
|
404
|
+
<span class="property-type">array</span>
|
|
405
|
+
</dt>
|
|
406
|
+
<dd>An array of buttons to include with the file message.</dd>
|
|
407
|
+
|
|
408
|
+
<dt>payload.workers
|
|
409
|
+
<span class="property-type">number</span>
|
|
410
|
+
</dt>
|
|
411
|
+
<dd>The number of workers for parallel uploads.</dd>
|
|
412
|
+
|
|
413
|
+
<dt>payload.noforwards
|
|
414
|
+
<span class="property-type">boolean</span>
|
|
415
|
+
</dt>
|
|
416
|
+
<dd>If <code>true</code>, prevents the message from being forwarded.</dd>
|
|
417
|
+
|
|
418
|
+
<dt>payload.commentTo
|
|
419
|
+
<span class="property-type">number</span>
|
|
420
|
+
</dt>
|
|
421
|
+
<dd>The ID of the message to comment on in a channel.</dd>
|
|
422
|
+
|
|
423
|
+
<dt>payload.topMsgId
|
|
424
|
+
<span class="property-type">number</span>
|
|
425
|
+
</dt>
|
|
426
|
+
<dd>The ID of the pinned message to associate with the file.</dd>
|
|
427
|
+
</dl>
|
|
428
|
+
|
|
429
|
+
<h3>Outputs</h3>
|
|
430
|
+
<dl class="message-properties">
|
|
431
|
+
<dt>payload
|
|
432
|
+
<span class="property-type">object</span>
|
|
433
|
+
</dt>
|
|
434
|
+
<dd>Contains the response from the Telegram API, including details of the sent message or file.</dd>
|
|
435
|
+
</dl>
|
|
436
|
+
|
|
437
|
+
<h3>Details</h3>
|
|
438
|
+
<p>The <b>send-files</b> node allows advanced file-sending capabilities with full customization. It supports various Telegram features such as captions with rich text formatting, scheduled messages, silent delivery, and progress tracking.</p>
|
|
439
|
+
|
|
440
|
+
<h3>Example</h3>
|
|
441
|
+
<pre>
|
|
442
|
+
{
|
|
443
|
+
"payload": {
|
|
444
|
+
"chatId": "@examplechannel",
|
|
445
|
+
"files": ["path/to/file1.jpg", "path/to/file2.mp4"],
|
|
446
|
+
"caption": "Check out these files!",
|
|
447
|
+
"silent": true,
|
|
448
|
+
"parseMode": "Markdown",
|
|
449
|
+
"buttons": [
|
|
450
|
+
{ "text": "Visit Website", "url": "https://example.com" }
|
|
451
|
+
]
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
</pre>
|
|
455
|
+
<p>This example sends two files with a caption, using Markdown for formatting, and includes a button linking to a website. The message is sent silently.</p>
|
|
456
|
+
|
|
457
|
+
<h3>Error Handling</h3>
|
|
458
|
+
<p>If an error occurs (e.g., invalid file path or chat ID), the node logs an error message and does not send the file.</p>
|
|
459
|
+
|
|
460
|
+
<h3>Configuration</h3>
|
|
461
|
+
<p>The node can use a globally configured Telegram client or a client instance provided in the message payload. Ensure the client has permissions to send messages in the specified chat.</p>
|
|
462
|
+
</script>
|
|
463
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module.exports = function (RED) {
|
|
2
|
+
function SendFile(config) {
|
|
3
|
+
RED.nodes.createNode(this, config);
|
|
4
|
+
this.config = RED.nodes.getNode(config.config);
|
|
5
|
+
var node = this;
|
|
6
|
+
|
|
7
|
+
this.on('input', async function (msg) {
|
|
8
|
+
const chatId = msg.payload.chatId || config.chatId;
|
|
9
|
+
const files = msg.payload.files || config.files.split(',').map(file => file.trim());
|
|
10
|
+
const caption = msg.payload.caption || config.caption;
|
|
11
|
+
const forceDocument = msg.payload.forceDocument || config.forceDocument;
|
|
12
|
+
const fileSize = msg.payload.fileSize || config.fileSize;
|
|
13
|
+
const clearDraft = msg.payload.clearDraft || config.clearDraft;
|
|
14
|
+
const progressCallback = msg.payload.progressCallback || config.progressCallback;
|
|
15
|
+
const replyTo = msg.payload.replyTo || config.replyTo;
|
|
16
|
+
const attributes = msg.payload.attributes || config.attributes;
|
|
17
|
+
const thumb = msg.payload.thumb || config.thumb;
|
|
18
|
+
const voiceNote = msg.payload.voiceNote || config.voiceNote;
|
|
19
|
+
const videoNote = msg.payload.videoNote || config.videoNote;
|
|
20
|
+
const supportsStreaming = msg.payload.supportsStreaming || config.supportsStreaming;
|
|
21
|
+
const parseMode = msg.payload.parseMode || config.parseMode;
|
|
22
|
+
const formattingEntities = msg.payload.formattingEntities || config.formattingEntities;
|
|
23
|
+
const silent = msg.payload.silent || config.silent;
|
|
24
|
+
const scheduleDate = msg.payload.scheduleDate || config.scheduleDate;
|
|
25
|
+
const buttons = msg.payload.buttons || config.buttons;
|
|
26
|
+
const workers = msg.payload.workers || config.workers;
|
|
27
|
+
const noforwards = msg.payload.noforwards || config.noforwards;
|
|
28
|
+
const commentTo = msg.payload.commentTo || config.commentTo;
|
|
29
|
+
const topMsgId = msg.payload.topMsgId || config.topMsgId;
|
|
30
|
+
|
|
31
|
+
/** @type {TelegramClient} */
|
|
32
|
+
const client = msg.payload?.client ? msg.payload.client : this.config.client;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const params = {
|
|
36
|
+
file: files,
|
|
37
|
+
caption: caption,
|
|
38
|
+
forceDocument: forceDocument,
|
|
39
|
+
fileSize: fileSize,
|
|
40
|
+
clearDraft: clearDraft,
|
|
41
|
+
progressCallback: progressCallback,
|
|
42
|
+
replyTo: replyTo,
|
|
43
|
+
attributes: attributes,
|
|
44
|
+
thumb: thumb,
|
|
45
|
+
voiceNote: voiceNote,
|
|
46
|
+
videoNote: videoNote,
|
|
47
|
+
supportsStreaming: supportsStreaming,
|
|
48
|
+
parseMode: parseMode,
|
|
49
|
+
formattingEntities: formattingEntities,
|
|
50
|
+
silent: silent,
|
|
51
|
+
scheduleDate: scheduleDate,
|
|
52
|
+
buttons: buttons,
|
|
53
|
+
workers: workers,
|
|
54
|
+
noforwards: noforwards,
|
|
55
|
+
commentTo: commentTo,
|
|
56
|
+
topMsgId: topMsgId,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Отправка файлов
|
|
61
|
+
const response = await client.sendFile(chatId, params);
|
|
62
|
+
node.send({
|
|
63
|
+
payload: response,
|
|
64
|
+
});
|
|
65
|
+
} catch (err) {
|
|
66
|
+
node.error('Error sending files: ' + err.message);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
RED.nodes.registerType('send-files', SendFile);
|
|
72
|
+
};
|