@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
package/.gitattributes
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
20
|
+
|
|
21
|
+
publish-npm:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 20
|
|
29
|
+
registry-url: https://registry.npmjs.org/
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- run: npm publish
|
|
32
|
+
env:
|
|
33
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Node-red and telegram (gramjs) integration
|
package/icons/tg.png
ADDED
|
Binary file
|
package/nodes/auth.html
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('auth', {
|
|
3
|
+
category: 'telegram-account',
|
|
4
|
+
color: '#a6bbcf',
|
|
5
|
+
defaults: {
|
|
6
|
+
api_id: { value: "", required: true },
|
|
7
|
+
api_hash: { value: "", required: true },
|
|
8
|
+
phoneNumber: { value: "", required: true },
|
|
9
|
+
password: { value: "" },
|
|
10
|
+
},
|
|
11
|
+
inputs: 1,
|
|
12
|
+
outputs: 1,
|
|
13
|
+
icon: "font-awesome/fa-lock",
|
|
14
|
+
label: function () {
|
|
15
|
+
return this.name || "Telegram Auth";
|
|
16
|
+
},
|
|
17
|
+
oneditprepare: function () {
|
|
18
|
+
// Инициализация значений
|
|
19
|
+
$("#node-input-api_id").val(this.api_id || "");
|
|
20
|
+
$("#node-input-api_hash").val(this.api_hash || "");
|
|
21
|
+
$("#node-input-phoneNumber").val(this.phoneNumber || "");
|
|
22
|
+
$("#node-input-password").val(this.password || "");
|
|
23
|
+
},
|
|
24
|
+
oneditsave: function () {
|
|
25
|
+
// Сохранение значений
|
|
26
|
+
this.api_id = $("#node-input-api_id").val();
|
|
27
|
+
this.api_hash = $("#node-input-api_hash").val();
|
|
28
|
+
this.phoneNumber = $("#node-input-phoneNumber").val();
|
|
29
|
+
this.password = $("#node-input-password").val();
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script type="text/html" data-template-name="auth">
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-api_id">
|
|
37
|
+
<i class="fa fa-key"></i> API ID
|
|
38
|
+
</label>
|
|
39
|
+
<input type="text" id="node-input-api_id" placeholder="Enter your API ID">
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div class="form-row">
|
|
43
|
+
<label for="node-input-api_hash">
|
|
44
|
+
<i class="fa fa-lock"></i> API Hash
|
|
45
|
+
</label>
|
|
46
|
+
<input type="text" id="node-input-api_hash" placeholder="Enter your API Hash">
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-phoneNumber">
|
|
51
|
+
<i class="fa fa-phone"></i> Phone Number
|
|
52
|
+
</label>
|
|
53
|
+
<input type="text" id="node-input-phoneNumber" placeholder="Enter your phone number">
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<div class="form-row">
|
|
57
|
+
<label for="node-input-password">
|
|
58
|
+
<i class="fa fa-unlock-alt"></i> Password (optional)
|
|
59
|
+
</label>
|
|
60
|
+
<input type="password" id="node-input-password" placeholder="Enter your password (if any)">
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<p>
|
|
64
|
+
<strong>Note:</strong> This configuration is required for connecting to the Telegram API and starting a session.
|
|
65
|
+
</p>
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
<script type="text/html" data-help-name="auth">
|
|
70
|
+
<p>The <b>auth</b> node facilitates Telegram API authentication using the <code>telegram</code> library. It allows users to authenticate a session and retrieve a stringSession for future use.</p>
|
|
71
|
+
|
|
72
|
+
<h3>Inputs</h3>
|
|
73
|
+
<dl class="message-properties">
|
|
74
|
+
<dt>payload.api_id
|
|
75
|
+
<span class="property-type">number | string</span>
|
|
76
|
+
</dt>
|
|
77
|
+
<dd>The Telegram API ID. Required for authentication.</dd>
|
|
78
|
+
|
|
79
|
+
<dt>payload.api_hash
|
|
80
|
+
<span class="property-type">string</span>
|
|
81
|
+
</dt>
|
|
82
|
+
<dd>The Telegram API hash. Required for authentication.</dd>
|
|
83
|
+
|
|
84
|
+
<dt>payload.phoneNumber
|
|
85
|
+
<span class="property-type">string</span>
|
|
86
|
+
</dt>
|
|
87
|
+
<dd>The phone number associated with the Telegram account.</dd>
|
|
88
|
+
|
|
89
|
+
<dt>payload.password
|
|
90
|
+
<span class="property-type">string</span>
|
|
91
|
+
</dt>
|
|
92
|
+
<dd>The password for two-factor authentication (if enabled on the Telegram account).</dd>
|
|
93
|
+
</dl>
|
|
94
|
+
|
|
95
|
+
<h3>Outputs</h3>
|
|
96
|
+
<dl class="message-properties">
|
|
97
|
+
<dt>topic
|
|
98
|
+
<span class="property-type">string</span>
|
|
99
|
+
</dt>
|
|
100
|
+
<dd>
|
|
101
|
+
- <b>"auth_success"</b>: Authentication was successful.
|
|
102
|
+
- <b>"auth_error"</b>: An error occurred during authentication.
|
|
103
|
+
</dd>
|
|
104
|
+
|
|
105
|
+
<dt>payload
|
|
106
|
+
<span class="property-type">object</span>
|
|
107
|
+
</dt>
|
|
108
|
+
<dd>
|
|
109
|
+
For <b>"auth_success"</b>:
|
|
110
|
+
<ul>
|
|
111
|
+
<li><code>payload.stringSession</code>: The generated session string.</li>
|
|
112
|
+
<li><code>payload.message</code>: Success message.</li>
|
|
113
|
+
</ul>
|
|
114
|
+
For <b>"auth_error"</b>:
|
|
115
|
+
<ul>
|
|
116
|
+
<li><code>payload.error</code>: The error message describing the issue.</li>
|
|
117
|
+
</ul>
|
|
118
|
+
</dd>
|
|
119
|
+
</dl>
|
|
120
|
+
|
|
121
|
+
<h3>Details</h3>
|
|
122
|
+
<p>To use the <b>auth</b> node, pass the required API credentials and phone number as part of the input message payload. The node will initiate the Telegram authentication flow. If a two-factor password is required, include it in the <code>payload.password</code>.</p>
|
|
123
|
+
|
|
124
|
+
<p>The node temporarily stores the phone code resolver in the flow context under the key <code>phoneCode</code>. This allows subsequent nodes to resolve the phone code using a separate input mechanism, such as user interaction.</p>
|
|
125
|
+
|
|
126
|
+
<h3>Example</h3>
|
|
127
|
+
<pre>
|
|
128
|
+
{
|
|
129
|
+
"payload": {
|
|
130
|
+
"api_id": 123456,
|
|
131
|
+
"api_hash": "your_api_hash",
|
|
132
|
+
"phoneNumber": "+123456789",
|
|
133
|
+
"password": "your_password"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
</pre>
|
|
137
|
+
<p>This example input payload initiates the authentication process. Upon receiving the phone code, it should be resolved using a dedicated node or interface.</p>
|
|
138
|
+
</script>
|
package/nodes/auth.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { TelegramClient } = require("telegram");
|
|
2
|
+
const { StringSession } = require("telegram/sessions");
|
|
3
|
+
|
|
4
|
+
module.exports = function (RED) {
|
|
5
|
+
function TelegramClientConfig(config) {
|
|
6
|
+
RED.nodes.createNode(this, config);
|
|
7
|
+
const node = this;
|
|
8
|
+
|
|
9
|
+
this.on("input", async (msg) => {
|
|
10
|
+
const api_idString = msg.payload.api_id || config.api_id;
|
|
11
|
+
const api_hash = msg.payload.api_hash || config.api_hash;
|
|
12
|
+
const phoneNumber = msg.payload.phoneNumber || config.phoneNumber;
|
|
13
|
+
const password = msg.payload.password || config.password;
|
|
14
|
+
const api_id = parseInt(api_idString);
|
|
15
|
+
|
|
16
|
+
const session = new StringSession("");
|
|
17
|
+
const client = new TelegramClient(session, api_id, api_hash, {
|
|
18
|
+
connectionRetries: 5,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
let resolvePhoneCode;
|
|
23
|
+
const context = node.context().flow;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await client.start({
|
|
27
|
+
phoneNumber: () => phoneNumber,
|
|
28
|
+
password: () => password,
|
|
29
|
+
phoneCode: async () =>{
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
resolvePhoneCode = resolve;
|
|
32
|
+
context.set("phoneCode", resolvePhoneCode);
|
|
33
|
+
})
|
|
34
|
+
},
|
|
35
|
+
onError: (err) => node.error(`Ошибка: ${err.message}`),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const stringSession = client.session.save(); // Сохраняем сессию
|
|
39
|
+
node.send({
|
|
40
|
+
topic: "auth_success",
|
|
41
|
+
payload: {
|
|
42
|
+
stringSession,
|
|
43
|
+
message: "Авторизация прошла успешно!",
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
} catch (error) {
|
|
48
|
+
node.error(`Ошибка авторизации: ${error.message}`);
|
|
49
|
+
node.send({
|
|
50
|
+
topic: "auth_error",
|
|
51
|
+
payload: {
|
|
52
|
+
error: error.message,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
RED.nodes.registerType("auth", TelegramClientConfig);
|
|
60
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('command', {
|
|
3
|
+
category: 'telegram-account',
|
|
4
|
+
color: '#229ED9',
|
|
5
|
+
icon: 'tg.png',
|
|
6
|
+
align:"right",
|
|
7
|
+
defaults: {
|
|
8
|
+
name: { value: '' },
|
|
9
|
+
config: { type: 'config', required: false },
|
|
10
|
+
command: { value: "", required:true },
|
|
11
|
+
regex:{ value:false }
|
|
12
|
+
},
|
|
13
|
+
inputs: 1,
|
|
14
|
+
outputs: 1,
|
|
15
|
+
label: function () {
|
|
16
|
+
return this.name || 'Command';
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="command">
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-input-name">
|
|
25
|
+
<i class="fa fa-tag"></i> Name
|
|
26
|
+
</label>
|
|
27
|
+
<input
|
|
28
|
+
type="text"
|
|
29
|
+
id="node-input-name"
|
|
30
|
+
placeholder="Name"
|
|
31
|
+
style="width: 60%"
|
|
32
|
+
/>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="form-row">
|
|
35
|
+
<label for="node-input-config">
|
|
36
|
+
<i class="fa fa-tag"></i> Config
|
|
37
|
+
</label>
|
|
38
|
+
<input
|
|
39
|
+
type="text"
|
|
40
|
+
id="node-input-config"
|
|
41
|
+
placeholder="Config"
|
|
42
|
+
style="width: 60%"
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<div class="form-row">
|
|
47
|
+
<label for="node-input-command">
|
|
48
|
+
<i class="fa fa-tag"></i> Message
|
|
49
|
+
</label>
|
|
50
|
+
<input type="text" id="node-input-command" placeholder="Message">
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="regex">
|
|
55
|
+
<i class="fa fa-cog"></i><span>Regular expression</span>
|
|
56
|
+
</label>
|
|
57
|
+
<input type="checkbox" style="display: inline; width: 22px;vertical-align: top;" id="node-input-regex">
|
|
58
|
+
</div>
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<script type="text/html" data-help-name="command">
|
|
62
|
+
<p>The <b>command</b> node listens for specific commands or patterns in Telegram messages and triggers further processing when a match is found. It supports both exact matches and regex-based pattern matching.</p>
|
|
63
|
+
|
|
64
|
+
<h3>Inputs</h3>
|
|
65
|
+
<p>This node does not take any direct inputs. Instead, it listens for incoming messages from the Telegram bot or user.</p>
|
|
66
|
+
|
|
67
|
+
<h3>Outputs</h3>
|
|
68
|
+
<dl class="message-properties">
|
|
69
|
+
<dt>payload.update
|
|
70
|
+
<span class="property-type">object</span>
|
|
71
|
+
</dt>
|
|
72
|
+
<dd>The raw Telegram update object, containing the details of the matched message, including text, sender, chat ID, and other metadata.</dd>
|
|
73
|
+
</dl>
|
|
74
|
+
|
|
75
|
+
<h3>Configuration</h3>
|
|
76
|
+
<dl class="message-properties">
|
|
77
|
+
<dt>Command
|
|
78
|
+
<span class="property-type">string</span>
|
|
79
|
+
</dt>
|
|
80
|
+
<dd>The text or pattern to match against incoming messages. For example, <code>/start</code> or <code>/help</code>.</dd>
|
|
81
|
+
|
|
82
|
+
<dt>Regex
|
|
83
|
+
<span class="property-type">boolean</span>
|
|
84
|
+
</dt>
|
|
85
|
+
<dd>If checked, treats the <b>Command</b> field as a regular expression. This allows for advanced pattern matching (e.g., <code>^/command\\s*</code>).</dd>
|
|
86
|
+
|
|
87
|
+
<dt>Telegram Configuration
|
|
88
|
+
<span class="property-type">node</span>
|
|
89
|
+
</dt>
|
|
90
|
+
<dd>A configured Telegram client node to listen for messages. Ensure the client has the necessary permissions and is correctly authenticated.</dd>
|
|
91
|
+
</dl>
|
|
92
|
+
|
|
93
|
+
<h3>Details</h3>
|
|
94
|
+
<p>The <b>command</b> node integrates with the Telegram API to monitor incoming messages in real time. When a message matches the configured command or regex, the node outputs the Telegram update object for further processing. This is particularly useful for creating bots that respond to specific commands.</p>
|
|
95
|
+
|
|
96
|
+
<h3>Example</h3>
|
|
97
|
+
<pre>
|
|
98
|
+
{
|
|
99
|
+
"payload": {
|
|
100
|
+
"update": {
|
|
101
|
+
"message": {
|
|
102
|
+
"message": "/start",
|
|
103
|
+
"sender": {
|
|
104
|
+
"id": 123456789,
|
|
105
|
+
"username": "exampleuser"
|
|
106
|
+
},
|
|
107
|
+
"chat": {
|
|
108
|
+
"id": 987654321,
|
|
109
|
+
"type": "private"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
</pre>
|
|
116
|
+
<p>This example output is triggered when the bot receives the <code>/start</code> command. The <code>update</code> object contains metadata about the message, sender, and chat.</p>
|
|
117
|
+
|
|
118
|
+
<h3>Error Handling</h3>
|
|
119
|
+
<p>If the Telegram client fails to authenticate or there is an error in the configuration, the node logs an error message and stops functioning.</p>
|
|
120
|
+
|
|
121
|
+
<h3>Advanced Usage</h3>
|
|
122
|
+
<p>By enabling the <b>Regex</b> option, you can create dynamic commands or match patterns such as:</p>
|
|
123
|
+
<ul>
|
|
124
|
+
<li><code>^/command\\s*</code>: Matches the command followed by optional whitespace.</li>
|
|
125
|
+
<li><code>^/start|/help$</code>: Matches either <code>/start</code> or <code>/help</code>.</li>
|
|
126
|
+
</ul>
|
|
127
|
+
<p>This makes the <b>command</b> node versatile for building complex Telegram bot functionality.</p>
|
|
128
|
+
|
|
129
|
+
<h3>Notes</h3>
|
|
130
|
+
<ul>
|
|
131
|
+
<li>Ensure the Telegram bot has sufficient permissions to receive messages in the configured chat or channel.</li>
|
|
132
|
+
<li>Regular expressions should be carefully tested to avoid unintended matches or errors.</li>
|
|
133
|
+
</ul>
|
|
134
|
+
</script>
|
|
135
|
+
|
package/nodes/command.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const { NewMessage } = require("telegram/events");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module.exports = function (RED) {
|
|
5
|
+
function Command(config) {
|
|
6
|
+
RED.nodes.createNode(this, config);
|
|
7
|
+
this.config = RED.nodes.getNode(config.config);
|
|
8
|
+
var node = this;
|
|
9
|
+
/** @type {TelegramClient} */
|
|
10
|
+
const client = this.config.client;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
client.addEventHandler((update) => {
|
|
16
|
+
const message = update.message.message
|
|
17
|
+
if (message) {
|
|
18
|
+
if (config.regex) {
|
|
19
|
+
const regex = new RegExp(config.command);
|
|
20
|
+
|
|
21
|
+
if (regex.test(message)) {
|
|
22
|
+
|
|
23
|
+
var msg = {
|
|
24
|
+
payload: {
|
|
25
|
+
update
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
node.send(msg);
|
|
31
|
+
}
|
|
32
|
+
} else if (message === config.command) {
|
|
33
|
+
|
|
34
|
+
var msg = {
|
|
35
|
+
payload: {
|
|
36
|
+
update
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
node.send(msg);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, new NewMessage());
|
|
45
|
+
|
|
46
|
+
} catch (err) {
|
|
47
|
+
node.error('Ошибка авторизации: ' + err.message);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
RED.nodes.registerType('command', Command);
|
|
53
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('config',{
|
|
3
|
+
category: 'config',
|
|
4
|
+
defaults: {
|
|
5
|
+
name: { value: '' },
|
|
6
|
+
api_id: {value:"", required:true},
|
|
7
|
+
api_hash: {value:"", required:true},
|
|
8
|
+
session: {value:"", required:true},
|
|
9
|
+
useIPV6: {value: undefined},
|
|
10
|
+
timeout: {value: undefined},
|
|
11
|
+
requestRetries: {value: undefined},
|
|
12
|
+
connectionRetries: {value: undefined},
|
|
13
|
+
proxy: {value: undefined},
|
|
14
|
+
downloadRetries: {value: undefined},
|
|
15
|
+
retryDelay: {value: undefined},
|
|
16
|
+
autoReconnect: {value: undefined},
|
|
17
|
+
sequentialUpdates: {value: undefined},
|
|
18
|
+
floodSleepThreshold: {value: undefined},
|
|
19
|
+
deviceModel: {value: undefined},
|
|
20
|
+
systemVersion: {value: undefined},
|
|
21
|
+
appVersion: {value: undefined},
|
|
22
|
+
langCode: {value: undefined},
|
|
23
|
+
systemLangCode: {value: undefined},
|
|
24
|
+
useWSS: {value: undefined},
|
|
25
|
+
maxConcurrentDownloads: {value: undefined},
|
|
26
|
+
securityChecks: {value: undefined},
|
|
27
|
+
testServers: {value: undefined}
|
|
28
|
+
},
|
|
29
|
+
label: function() {
|
|
30
|
+
return this.name || "Telegram Client Config";
|
|
31
|
+
},
|
|
32
|
+
oneditprepare: function() {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<script type="text/html" data-template-name="config">
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-config-input-name"><i class="icon-tasks"></i>Name</label>
|
|
41
|
+
<input type="text" id="node-config-input-name" placeholder="Name" style="width:70%" ng-model="node.api_id">
|
|
42
|
+
</div>
|
|
43
|
+
<div class="form-row">
|
|
44
|
+
<label for="node-config-input-api_id"><i class="icon-tasks"></i> API ID</label>
|
|
45
|
+
<input type="text" id="node-config-input-api_id" placeholder="Enter API ID" style="width:70%" ng-model="node.api_id">
|
|
46
|
+
</div>
|
|
47
|
+
<div class="form-row">
|
|
48
|
+
<label for="node-config-input-api_hash"><i class="icon-tasks"></i> API Hash</label>
|
|
49
|
+
<input type="text" id="node-config-input-api_hash" placeholder="Enter API Hash" style="width:70%" ng-model="node.api_hash">
|
|
50
|
+
</div>
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-config-input-session"><i class="icon-tasks"></i> Session</label>
|
|
53
|
+
<input type="text" id="node-config-input-session" placeholder="Enter Session" style="width:70%" ng-model="node.session">
|
|
54
|
+
</div>
|
|
55
|
+
<div class="form-row">
|
|
56
|
+
<label for="node-config-input-useIPV6"><i class="icon-tasks"></i> Use IPV6</label>
|
|
57
|
+
<input type="checkbox" id="node-config-input-useIPV6" ng-model="node.useIPV6">
|
|
58
|
+
</div>
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<label for="node-config-input-timeout"><i class="icon-tasks"></i> Timeout</label>
|
|
61
|
+
<input type="number" id="node-config-input-timeout" placeholder="Enter Timeout" style="width:70%" ng-model="node.timeout">
|
|
62
|
+
</div>
|
|
63
|
+
<div class="form-row">
|
|
64
|
+
<label for="node-config-input-requestRetries"><i class="icon-tasks"></i> Request Retries</label>
|
|
65
|
+
<input type="number" id="node-config-input-requestRetries" placeholder="Enter Request Retries" style="width:70%" ng-model="node.requestRetries">
|
|
66
|
+
</div>
|
|
67
|
+
<div class="form-row">
|
|
68
|
+
<label for="node-config-input-connectionRetries"><i class="icon-tasks"></i> Connection Retries</label>
|
|
69
|
+
<input type="number" id="node-config-input-connectionRetries" placeholder="Enter Connection Retries" style="width:70%" ng-model="node.connectionRetries">
|
|
70
|
+
</div>
|
|
71
|
+
<div class="form-row">
|
|
72
|
+
<label for="node-config-input-proxy"><i class="icon-tasks"></i> Proxy</label>
|
|
73
|
+
<input type="text" id="node-config-input-proxy" placeholder="Enter Proxy" style="width:70%" ng-model="node.proxy">
|
|
74
|
+
</div>
|
|
75
|
+
<div class="form-row">
|
|
76
|
+
<label for="node-config-input-downloadRetries"><i class="icon-tasks"></i> Download Retries</label>
|
|
77
|
+
<input type="number" id="node-config-input-downloadRetries" placeholder="Enter Download Retries" style="width:70%" ng-model="node.downloadRetries">
|
|
78
|
+
</div>
|
|
79
|
+
<div class="form-row">
|
|
80
|
+
<label for="node-config-input-retryDelay"><i class="icon-tasks"></i> Retry Delay</label>
|
|
81
|
+
<input type="number" id="node-config-input-retryDelay" placeholder="Enter Retry Delay" style="width:70%" ng-model="node.retryDelay">
|
|
82
|
+
</div>
|
|
83
|
+
<div class="form-row">
|
|
84
|
+
<label for="node-config-input-autoReconnect"><i class="icon-tasks"></i> Auto Reconnect</label>
|
|
85
|
+
<input type="checkbox" id="node-config-input-autoReconnect" ng-model="node.autoReconnect">
|
|
86
|
+
</div>
|
|
87
|
+
<div class="form-row">
|
|
88
|
+
<label for="node-config-input-sequentialUpdates"><i class="icon-tasks"></i> Sequential Updates</label>
|
|
89
|
+
<input type="checkbox" id="node-config-input-sequentialUpdates" ng-model="node.sequentialUpdates">
|
|
90
|
+
</div>
|
|
91
|
+
<div class="form-row">
|
|
92
|
+
<label for="node-config-input-floodSleepThreshold"><i class="icon-tasks"></i> Flood Sleep Threshold</label>
|
|
93
|
+
<input type="number" id="node-config-input-floodSleepThreshold" placeholder="Enter Flood Sleep Threshold" style="width:70%" ng-model="node.floodSleepThreshold">
|
|
94
|
+
</div>
|
|
95
|
+
<div class="form-row">
|
|
96
|
+
<label for="node-config-input-deviceModel"><i class="icon-tasks"></i> Device Model</label>
|
|
97
|
+
<input type="text" id="node-config-input-deviceModel" placeholder="Enter Device Model" style="width:70%" ng-model="node.deviceModel">
|
|
98
|
+
</div>
|
|
99
|
+
<div class="form-row">
|
|
100
|
+
<label for="node-config-input-systemVersion"><i class="icon-tasks"></i> System Version</label>
|
|
101
|
+
<input type="text" id="node-config-input-systemVersion" placeholder="Enter System Version" style="width:70%" ng-model="node.systemVersion">
|
|
102
|
+
</div>
|
|
103
|
+
<div class="form-row">
|
|
104
|
+
<label for="node-config-input-appVersion"><i class="icon-tasks"></i> App Version</label>
|
|
105
|
+
<input type="text" id="node-config-input-appVersion" placeholder="Enter App Version" style="width:70%" ng-model="node.appVersion">
|
|
106
|
+
</div>
|
|
107
|
+
<div class="form-row">
|
|
108
|
+
<label for="node-config-input-langCode"><i class="icon-tasks"></i> Language Code</label>
|
|
109
|
+
<input type="text" id="node-config-input-langCode" placeholder="Enter Language Code" style="width:70%" ng-model="node.langCode">
|
|
110
|
+
</div>
|
|
111
|
+
<div class="form-row">
|
|
112
|
+
<label for="node-config-input-systemLangCode"><i class="icon-tasks"></i> System Language Code</label>
|
|
113
|
+
<input type="text" id="node-config-input-systemLangCode" placeholder="Enter System Language Code" style="width:70%" ng-model="node.systemLangCode">
|
|
114
|
+
</div>
|
|
115
|
+
<div class="form-row">
|
|
116
|
+
<label for="node-config-input-useWSS"><i class="icon-tasks"></i> Use WSS</label>
|
|
117
|
+
<input type="checkbox" id="node-config-input-useWSS" ng-model="node.useWSS">
|
|
118
|
+
</div>
|
|
119
|
+
<div class="form-row">
|
|
120
|
+
<label for="node-config-input-maxConcurrentDownloads"><i class="icon-tasks"></i> Max Concurrent Downloads</label>
|
|
121
|
+
<input type="number" id="node-config-input-maxConcurrentDownloads" placeholder="Enter Max Concurrent Downloads" style="width:70%" ng-model="node.maxConcurrentDownloads">
|
|
122
|
+
</div>
|
|
123
|
+
<div class="form-row">
|
|
124
|
+
<label for="node-config-input-securityChecks"><i class="icon-tasks"></i> Security Checks</label>
|
|
125
|
+
<input type="checkbox" id="node-config-input-securityChecks" ng-model="node.securityChecks">
|
|
126
|
+
</div>
|
|
127
|
+
<div class="form-row">
|
|
128
|
+
<label for="node-config-input-testServers"><i class="icon-tasks"></i> Test Servers</label>
|
|
129
|
+
<input type="checkbox" id="node-config-input-testServers" ng-model="node.testServers">
|
|
130
|
+
</div>
|
|
131
|
+
</script>
|
package/nodes/config.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { TelegramClient } = require("telegram");
|
|
2
|
+
const { StringSession } = require("telegram/sessions");
|
|
3
|
+
|
|
4
|
+
module.exports = function (RED) {
|
|
5
|
+
function TelegramClientConfig(config) {
|
|
6
|
+
RED.nodes.createNode(this, config);
|
|
7
|
+
this.apiId = config.api_id;
|
|
8
|
+
this.apiHash = config.api_hash;
|
|
9
|
+
this.session = new StringSession(config.session);
|
|
10
|
+
this.useIPV6 = config.useIPV6;
|
|
11
|
+
this.timeout = config.timeout;
|
|
12
|
+
this.requestRetries = config.requestRetries;
|
|
13
|
+
this.connectionRetries = config.connectionRetries;
|
|
14
|
+
this.proxy = config.proxy;
|
|
15
|
+
this.downloadRetries = config.downloadRetries;
|
|
16
|
+
this.retryDelay = config.retryDelay;
|
|
17
|
+
this.autoReconnect = config.autoReconnect;
|
|
18
|
+
this.sequentialUpdates = config.sequentialUpdates;
|
|
19
|
+
this.floodSleepThreshold = config.floodSleepThreshold;
|
|
20
|
+
this.deviceModel = config.deviceModel;
|
|
21
|
+
this.systemVersion = config.systemVersion;
|
|
22
|
+
this.appVersion = config.appVersion;
|
|
23
|
+
this.langCode = config.langCode;
|
|
24
|
+
this.systemLangCode = config.systemLangCode;
|
|
25
|
+
this.useWSS = config.useWSS;
|
|
26
|
+
this.maxConcurrentDownloads = config.maxConcurrentDownloads;
|
|
27
|
+
this.securityChecks = config.securityChecks;
|
|
28
|
+
this.testServers = config.testServers;
|
|
29
|
+
const node = this;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
this.client = new TelegramClient(this.session, parseInt(this.apiId), this.apiHash, {
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
this.client.connect().then(async () => {
|
|
39
|
+
let isAuthorized = await this.client.isUserAuthorized();
|
|
40
|
+
if (!isAuthorized) {
|
|
41
|
+
node.error(`Session is invalid`);
|
|
42
|
+
} else {
|
|
43
|
+
node.status({ fill: "green", shape: "dot", text: "Connected" });
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
} catch (err) {
|
|
47
|
+
node.error('Authorisation error: ' + err.message);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.on("close", () => {
|
|
51
|
+
if (this.client) {
|
|
52
|
+
this.client.disconnect();
|
|
53
|
+
node.status({ fill: "red", shape: "ring", text: "Disconnected" });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
RED.nodes.registerType('config', TelegramClientConfig);
|
|
58
|
+
};
|