@patricktobias86/node-red-telegram-account 1.1.2 → 1.1.4

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/README.md CHANGED
@@ -1,11 +1,16 @@
1
1
  # Node-RED nodes to communicate with GramJS
2
2
 
3
3
  <p align="center">
4
- <img alt="Github issues" src="https://img.shields.io/github/issues/patricktobias86/node-red-telegram-account?color=56BEB8" />
5
- <img alt="Github forks" src="https://img.shields.io/github/forks/patricktobias86/node-red-telegram-account?color=56BEB8" />
6
- <img alt="Github stars" src="https://img.shields.io/github/stars/patricktobias86/node-red-telegram-account?color=56BEB8" />
4
+ <img alt="GitHub issues" src="https://img.shields.io/github/issues/patricktobias86/node-red-telegram-account?color=56BEB8" />
5
+ <img alt="GitHub forks" src="https://img.shields.io/github/forks/patricktobias86/node-red-telegram-account?color=56BEB8" />
6
+ <img alt="GitHub stars" src="https://img.shields.io/github/stars/patricktobias86/node-red-telegram-account?color=56BEB8" />
7
7
  </p>
8
8
 
9
9
  ```bash
10
10
  npm i @patricktobias86/node-red-telegram-account
11
- ```
11
+ ```
12
+
13
+ ## Nodes
14
+
15
+ - resolve-userid – resolve a Telegram username to its numeric user ID
16
+
@@ -0,0 +1,104 @@
1
+ [
2
+ {
3
+ "id": "8a1d5a99e1018272",
4
+ "type": "tab",
5
+ "label": "Example User Auth",
6
+ "disabled": false,
7
+ "info": "",
8
+ "env": []
9
+ },
10
+ {
11
+ "id": "inject_credentials",
12
+ "type": "inject",
13
+ "z": "8a1d5a99e1018272",
14
+ "name": "Start Auth",
15
+ "props": [],
16
+ "repeat": "",
17
+ "crontab": "",
18
+ "once": false,
19
+ "onceDelay": 0.1,
20
+ "topic": "",
21
+ "x": 160,
22
+ "y": 100,
23
+ "wires": [
24
+ [
25
+ "ee6466b89cc7a43b"
26
+ ]
27
+ ]
28
+ },
29
+ {
30
+ "id": "debug_output",
31
+ "type": "debug",
32
+ "z": "8a1d5a99e1018272",
33
+ "name": "Session Output",
34
+ "active": true,
35
+ "tosidebar": true,
36
+ "console": false,
37
+ "tostatus": false,
38
+ "complete": "true",
39
+ "targetType": "full",
40
+ "statusVal": "",
41
+ "statusType": "auto",
42
+ "x": 560,
43
+ "y": 100,
44
+ "wires": []
45
+ },
46
+ {
47
+ "id": "inject_code",
48
+ "type": "inject",
49
+ "z": "8a1d5a99e1018272",
50
+ "name": "Send Code",
51
+ "props": [
52
+ {
53
+ "p": "payload"
54
+ }
55
+ ],
56
+ "repeat": "",
57
+ "crontab": "",
58
+ "once": false,
59
+ "onceDelay": "",
60
+ "topic": "",
61
+ "payload": "{\"code\":\"00000\"}",
62
+ "payloadType": "json",
63
+ "x": 170,
64
+ "y": 180,
65
+ "wires": [
66
+ [
67
+ "function_send_code"
68
+ ]
69
+ ]
70
+ },
71
+ {
72
+ "id": "function_send_code",
73
+ "type": "function",
74
+ "z": "8a1d5a99e1018272",
75
+ "name": "Submit Code",
76
+ "func": "const code = msg.payload.code;\nconst wait = flow.get(\"waitForCode\");\nif (typeof wait === \"function\") {\n wait(code);\n flow.set(\"waitForCode\", null);\n node.status({fill:\"blue\",shape:\"ring\",text:\"Code sent!\"});\n} else {\n node.warn(\"No code listener available. Did you trigger auth first?\");\n}\nreturn null;",
77
+ "outputs": 0,
78
+ "timeout": "",
79
+ "noerr": 0,
80
+ "initialize": "",
81
+ "finalize": "",
82
+ "libs": [],
83
+ "x": 370,
84
+ "y": 180,
85
+ "wires": []
86
+ },
87
+ {
88
+ "id": "ee6466b89cc7a43b",
89
+ "type": "auth",
90
+ "z": "8a1d5a99e1018272",
91
+ "name": "",
92
+ "api_id": "",
93
+ "api_hash": "",
94
+ "phoneNumber": "",
95
+ "password": "",
96
+ "x": 350,
97
+ "y": 100,
98
+ "wires": [
99
+ [
100
+ "debug_output"
101
+ ]
102
+ ]
103
+ }
104
+ ]
package/nodes/auth.html CHANGED
@@ -3,6 +3,7 @@
3
3
  category: 'telegram-account',
4
4
  color: '#a6bbcf',
5
5
  defaults: {
6
+ name: { value: "" },
6
7
  api_id: { value: "" },
7
8
  api_hash: { value: "" },
8
9
  phoneNumber: { value: "" },
@@ -11,9 +12,14 @@
11
12
  inputs: 1,
12
13
  outputs: 1,
13
14
  icon: 'tg.png',
15
+ align: 'right',
14
16
  paletteLabel: 'user auth',
17
+ label: function() {
18
+ return this.name||'user auth';
19
+ },
15
20
  oneditprepare: function () {
16
21
  // Initialize values
22
+ $("#node-input-name").val(this.name || "");
17
23
  $("#node-input-api_id").val(this.api_id || "");
18
24
  $("#node-input-api_hash").val(this.api_hash || "");
19
25
  $("#node-input-phoneNumber").val(this.phoneNumber || "");
@@ -21,6 +27,7 @@
21
27
  },
22
28
  oneditsave: function () {
23
29
  // Save values
30
+ this.name = $("#node-input-name").val();
24
31
  this.api_id = $("#node-input-api_id").val();
25
32
  this.api_hash = $("#node-input-api_hash").val();
26
33
  this.phoneNumber = $("#node-input-phoneNumber").val();
@@ -30,6 +37,12 @@
30
37
  </script>
31
38
 
32
39
  <script type="text/html" data-template-name="auth">
40
+ <div class="form-row">
41
+ <label for="node-input-name">
42
+ <i class="fa fa-tag"></i> Name
43
+ </label>
44
+ <input type="text" id="node-input-name" placeholder="Name">
45
+ </div>
33
46
  <div class="form-row">
34
47
  <label for="node-input-api_id">
35
48
  <i class="fa fa-key"></i> API ID
@@ -90,6 +103,7 @@ const wait = flow.get("waitForCode");
90
103
  if (typeof wait === "function") {
91
104
  wait(code);
92
105
  flow.set("waitForCode", null);
106
+ node.status({fill:"blue",shape:"ring",text:"Code sent!"});
93
107
  }
94
108
  </pre>
95
109
 
package/nodes/auth.js CHANGED
@@ -44,14 +44,20 @@ module.exports = function (RED) {
44
44
  });
45
45
 
46
46
  const stringSession = client.session.save();
47
+
48
+ console.log("Sending result to output:", {
49
+ stringSession,
50
+ messages: [
51
+ { type: "auth_success", text: "Authorization successful!" },
52
+ { type: "session_token", text: "Copy this stringSession to use in other nodes." }
53
+ ]
54
+ });
55
+
47
56
  node.send({
48
- topic: "auth_complete",
57
+ topic: "auth_success",
49
58
  payload: {
50
59
  stringSession,
51
- messages: [
52
- { type: "auth_success", text: "Authorization successful!" },
53
- { type: "session_token", text: "Copy this stringSession to use in other nodes." }
54
- ]
60
+ message: "Authorization successful!"
55
61
  }
56
62
  });
57
63
 
@@ -11,10 +11,10 @@
11
11
  },
12
12
  inputs: 1,
13
13
  outputs: 1,
14
- label: function () {
15
- return this.name || 'command';
16
- },
17
-
14
+ paletteLabel: 'command',
15
+ label: function() {
16
+ return this.name||'command';
17
+ }
18
18
  });
19
19
  </script>
20
20
 
package/nodes/config.html CHANGED
@@ -27,7 +27,7 @@
27
27
  testServers: {value: undefined}
28
28
  },
29
29
  label: function() {
30
- return this.name || "telegram client config";
30
+ return this.name || "telegram user config";
31
31
  },
32
32
  oneditprepare: function() {
33
33
 
@@ -1,17 +1,19 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType('delete-message', {
3
- category: 'telegram-account',
4
- color: '#FF5733',
5
- icon: 'tg.png',
6
- defaults: {
7
- name: { value: '' },
8
- config: { type: 'config', required: false },
9
- },
10
- inputs: 1,
11
- outputs: 1,
12
- label: function () {
13
- return this.name || 'delete message';
14
- },
3
+ category: 'telegram-account',
4
+ color: '#FF5733',
5
+ icon: 'tg.png',
6
+ align: 'right',
7
+ defaults: {
8
+ name: { value: '' },
9
+ config: { type: 'config', required: false },
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ paletteLabel: 'delete message',
14
+ label: function() {
15
+ return this.name||'delete message';
16
+ }
15
17
  });
16
18
  </script>
17
19
 
@@ -3,14 +3,16 @@
3
3
  category: 'telegram-account',
4
4
  color: '#229ED9',
5
5
  icon: 'tg.png',
6
+ align: 'right',
6
7
  defaults: {
7
8
  name: { value: '' },
8
9
  config: { type: 'config', required: false },
9
10
  },
10
11
  inputs: 1,
11
12
  outputs: 1,
12
- label: function () {
13
- return this.name || 'get entity';
13
+ paletteLabel: 'get entity',
14
+ label: function() {
15
+ return this.name||'get entity';
14
16
  }
15
17
  });
16
18
  </script>
@@ -3,6 +3,7 @@
3
3
  category: 'telegram-account',
4
4
  color: '#32a3e0',
5
5
  icon: 'tg.png',
6
+ align: 'right',
6
7
  defaults: {
7
8
  name: { value: '' },
8
9
  config: { type: 'config', required: true },
@@ -17,9 +18,9 @@
17
18
  inputs: 1,
18
19
  outputs: 1,
19
20
  paletteLabel: 'iterate dialogs',
20
- label: function () {
21
- return this.name || 'iterate dialogs';
22
- },
21
+ label: function() {
22
+ return this.name||'iterate dialogs';
23
+ }
23
24
  });
24
25
  </script>
25
26
 
@@ -3,6 +3,7 @@
3
3
  category: 'telegram',
4
4
  color: '#32a3e0',
5
5
  icon: 'tg.png',
6
+ align: 'right',
6
7
  defaults: {
7
8
  name: { value: '' },
8
9
  config: { type: 'config', required: true },
@@ -24,9 +25,9 @@
24
25
  },
25
26
  inputs: 1,
26
27
  outputs: 1,
27
- paletteLabel: 'iterate messages',
28
- label: function () {
29
- return this.name || 'iterate messages';
28
+ paletteLabel: 'iter messages',
29
+ label: function() {
30
+ return this.name||'iter messages';
30
31
  },
31
32
  oneditprepare: function(){
32
33
  const node = this;
@@ -3,6 +3,7 @@
3
3
  category: 'telegram-account',
4
4
  color: '#229ED9',
5
5
  icon: 'tg.png',
6
+ align: 'right',
6
7
  defaults: {
7
8
  name: { value: '' },
8
9
  config: { type: 'config', required: false },
@@ -23,8 +24,9 @@
23
24
  },
24
25
  inputs: 1,
25
26
  outputs: 1,
26
- label: function () {
27
- return this.name || 'promote admin';
27
+ paletteLabel: 'promote admin',
28
+ label: function() {
29
+ return this.name||'promote admin';
28
30
  },
29
31
  oneditprepare: function () {
30
32
  // No extra logic needed
@@ -1,19 +1,19 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType('receiver', {
3
- category: 'telegram-account',
4
- color: '#229ED9',
5
- icon: 'tg.png',
6
- defaults: {
7
- name: { value: '' },
8
- config: { type: 'config', required: false },
9
- ignore: { value:""}
10
- },
11
- inputs: 1,
12
- outputs: 1,
13
- label: function () {
14
- return this.name || 'receiver';
15
- },
16
-
3
+ category: 'telegram-account',
4
+ color: '#229ED9',
5
+ icon: 'tg.png',
6
+ defaults: {
7
+ name: { value: '' },
8
+ config: { type: 'config', required: false },
9
+ ignore: { value:""}
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ paletteLabel: 'receiver',
14
+ label: function() {
15
+ return this.name||'receiver';
16
+ }
17
17
  });
18
18
  </script>
19
19
 
@@ -0,0 +1,56 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('resolve-userid', {
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
+ username: { value: '' }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ paletteLabel: 'resolve userid',
15
+ label: function() {
16
+ return this.name||'resolve userid';
17
+ }
18
+ });
19
+ </script>
20
+
21
+ <script type="text/html" data-template-name="resolve-userid">
22
+ <div class="form-row">
23
+ <label for="node-input-name">
24
+ <i class="fa fa-tag"></i> Name
25
+ </label>
26
+ <input type="text" id="node-input-name" placeholder="Name" style="width: 60%" />
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-input-config">
30
+ <i class="fa fa-gear"></i> Config
31
+ </label>
32
+ <input type="text" id="node-input-config" placeholder="Config" style="width: 60%" />
33
+ </div>
34
+ <div class="form-row">
35
+ <label for="node-input-username">
36
+ <i class="fa fa-user"></i> Username
37
+ </label>
38
+ <input type="text" id="node-input-username" placeholder="@username" style="width: 60%" />
39
+ </div>
40
+ </script>
41
+
42
+ <script type="text/html" data-help-name="resolve-userid">
43
+ <p>The <b>resolve-userid</b> node converts a Telegram username into a numeric user ID.</p>
44
+ <h3>Inputs</h3>
45
+ <dl class="message-properties">
46
+ <dt>payload.username <span class="property-type">string</span></dt>
47
+ <dd>The Telegram username to resolve, e.g., <code>@someuser</code>.</dd>
48
+ <dt>payload.client <span class="property-type">object</span></dt>
49
+ <dd>Optional Telegram client instance. If omitted, the client from the configuration node is used.</dd>
50
+ </dl>
51
+ <h3>Outputs</h3>
52
+ <dl class="message-properties">
53
+ <dt>payload.userId <span class="property-type">number | bigint</span></dt>
54
+ <dd>The resolved Telegram user ID, or <code>null</code> if resolution fails.</dd>
55
+ </dl>
56
+ </script>
@@ -0,0 +1,36 @@
1
+ module.exports = function(RED) {
2
+ function ResolveUserId(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 username = msg.payload?.username || config.username;
9
+ const client = msg.payload?.client ? msg.payload.client : node.config?.client;
10
+
11
+ if (!username) {
12
+ node.error('No username provided');
13
+ return;
14
+ }
15
+ if (!client) {
16
+ node.error('Telegram client not configured');
17
+ return;
18
+ }
19
+
20
+ try {
21
+ const entity = await client.getEntity(username);
22
+ let userId;
23
+ if (entity?.id) {
24
+ userId = entity.id;
25
+ } else if (entity?.userId) {
26
+ userId = entity.userId;
27
+ }
28
+ node.send({ payload: { userId } });
29
+ } catch (err) {
30
+ node.error('Error resolving username: ' + err.message);
31
+ node.send({ payload: { userId: null } });
32
+ }
33
+ });
34
+ }
35
+ RED.nodes.registerType('resolve-userid', ResolveUserId);
36
+ };
@@ -31,10 +31,11 @@
31
31
  inputs: 1,
32
32
  outputs: 1,
33
33
  icon: 'tg.png',
34
- paletteLabel: 'send files',
35
- label: function () {
36
- return this.name || 'send files';
37
- },
34
+ align: 'right',
35
+ paletteLabel: 'send file',
36
+ label: function() {
37
+ return this.name||'send file';
38
+ }
38
39
  });
39
40
  </script>
40
41
 
@@ -3,6 +3,7 @@
3
3
  category: 'telegram-account',
4
4
  color: '#229ED9',
5
5
  icon: 'tg.png',
6
+ align: 'right',
6
7
  defaults: {
7
8
  name: { value: '' },
8
9
  chatId: { value: '' },
@@ -27,8 +28,9 @@
27
28
  },
28
29
  inputs: 1,
29
30
  outputs: 1,
30
- label: function () {
31
- return this.name || 'send message';
31
+ paletteLabel: 'send message',
32
+ label: function() {
33
+ return this.name||'send message';
32
34
  },
33
35
  oneditprepare: function () {
34
36
  const node = this;
@@ -100,7 +102,7 @@
100
102
  </div>
101
103
 
102
104
  <div class="form-row">
103
- <label for="node-input-chat_id">
105
+ <label for="node-input-chatId">
104
106
  <i class="fa fa-user"></i> Chat ID
105
107
  </label>
106
108
  <input type="text" id="node-input-chatId" placeholder="Peer ID">
@@ -48,7 +48,7 @@ module.exports = function (RED) {
48
48
  supportStreaming: supportStreaming,
49
49
  noforwards: noforwards,
50
50
  commentTo: commentTo !== "" ? commentTo : undefined,
51
- topMsgId: topMsgId !== topMsgId ? commentTo : undefined,
51
+ topMsgId: topMsgId !== "" ? topMsgId : undefined,
52
52
  };
53
53
 
54
54
  if (schedule) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patricktobias86/node-red-telegram-account",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Node-RED nodes to communicate with GramJS.",
5
5
  "main": "nodes/config.js",
6
6
  "keywords": [
@@ -35,7 +35,8 @@
35
35
  "telegram-account-delete-message": "nodes/delete-message.js",
36
36
  "telegram-account-iter-dialog": "nodes/iter-dialogs.js",
37
37
  "telegram-account-iter-messages": "nodes/iter-messages.js",
38
- "telegram-account-promote-admin": "nodes/promote-admin.js"
38
+ "telegram-account-promote-admin": "nodes/promote-admin.js",
39
+ "telegram-account-resolve-userid": "nodes/resolve-userid.js"
39
40
  }
40
41
  },
41
42
  "publishConfig": {