@patricktobias86/node-red-telegram-account 1.1.3 → 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,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
+ };
@@ -102,7 +102,7 @@
102
102
  </div>
103
103
 
104
104
  <div class="form-row">
105
- <label for="node-input-chat_id">
105
+ <label for="node-input-chatId">
106
106
  <i class="fa fa-user"></i> Chat ID
107
107
  </label>
108
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.3",
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": {