@patricktobias86/node-red-telegram-account 1.0.8 → 1.0.9

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,4 @@
1
+ {
2
+ "simple.readme.settings.github": "patricktobias86",
3
+ "simple.readme.settings.name": "Patrick Tobias"
4
+ }
package/README.md CHANGED
@@ -1 +1,11 @@
1
- ### Node-RED nodes to communicate with GramJS.
1
+ # Node-RED nodes to communicate with GramJS
2
+
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" />
7
+ </p>
8
+
9
+ ```bash
10
+ npm i @patricktobias86/node-red-telegram-account
11
+ ```
@@ -10,7 +10,17 @@
10
10
  chatId: { value: '' },
11
11
  userId: { value: '' },
12
12
  rank: { value: 'Admin' },
13
- adminRights: { value: '' }, // JSON string of ChatAdminRights
13
+ changeInfo: { value: true },
14
+ postMessages: { value: true },
15
+ editMessages: { value: true },
16
+ deleteMessages: { value: true },
17
+ banUsers: { value: true },
18
+ inviteUsers: { value: true },
19
+ pinMessages: { value: true },
20
+ addAdmins: { value: false },
21
+ manageCall: { value: false },
22
+ anonymous: { value: false },
23
+ manageTopics: { value: true }
14
24
  },
15
25
  inputs: 1,
16
26
  outputs: 1,
@@ -18,7 +28,102 @@
18
28
  return this.name || 'Promote Admin';
19
29
  },
20
30
  oneditprepare: function () {
21
- // Nothing special here yet — could validate JSON if needed
31
+ // No extra logic needed
22
32
  }
23
33
  });
34
+ </script>
35
+ <script type="text/html" data-template-name="promote-admin">
36
+ <div class="form-row">
37
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
38
+ <input type="text" id="node-input-name" placeholder="Name">
39
+ </div>
40
+
41
+ <div class="form-row">
42
+ <label for="node-input-config"><i class="fa fa-gear"></i> Config</label>
43
+ <input type="hidden" id="node-input-config">
44
+ </div>
45
+
46
+ <div class="form-row">
47
+ <label for="node-input-chatId"><i class="fa fa-users"></i> Group Chat ID</label>
48
+ <input type="text" id="node-input-chatId" placeholder="@groupname or ID">
49
+ </div>
50
+
51
+ <div class="form-row">
52
+ <label for="node-input-userId"><i class="fa fa-user-plus"></i> User ID</label>
53
+ <input type="text" id="node-input-userId" placeholder="@username or ID">
54
+ </div>
55
+
56
+ <div class="form-row">
57
+ <label for="node-input-rank"><i class="fa fa-star"></i> Admin Rank</label>
58
+ <input type="text" id="node-input-rank" placeholder="e.g. Admin, Moderator">
59
+ </div>
60
+
61
+ <fieldset style="border: 1px solid #ccc; padding: 10px; margin-top: 1rem;">
62
+ <legend><i class="fa fa-unlock-alt"></i> Admin Rights</legend>
63
+
64
+ <div><input type="checkbox" id="node-input-changeInfo"> <label for="node-input-changeInfo">Can change group info</label></div>
65
+ <div><input type="checkbox" id="node-input-postMessages"> <label for="node-input-postMessages">Can post messages</label></div>
66
+ <div><input type="checkbox" id="node-input-editMessages"> <label for="node-input-editMessages">Can edit messages</label></div>
67
+ <div><input type="checkbox" id="node-input-deleteMessages"> <label for="node-input-deleteMessages">Can delete messages</label></div>
68
+ <div><input type="checkbox" id="node-input-banUsers"> <label for="node-input-banUsers">Can ban users</label></div>
69
+ <div><input type="checkbox" id="node-input-inviteUsers"> <label for="node-input-inviteUsers">Can invite users</label></div>
70
+ <div><input type="checkbox" id="node-input-pinMessages"> <label for="node-input-pinMessages">Can pin messages</label></div>
71
+ <div><input type="checkbox" id="node-input-addAdmins"> <label for="node-input-addAdmins">Can add new admins</label></div>
72
+ <div><input type="checkbox" id="node-input-manageCall"> <label for="node-input-manageCall">Can manage voice/video chats</label></div>
73
+ <div><input type="checkbox" id="node-input-anonymous"> <label for="node-input-anonymous">Is anonymous (hidden from group)</label></div>
74
+ <div><input type="checkbox" id="node-input-manageTopics"> <label for="node-input-manageTopics">Can manage topics</label></div>
75
+ </fieldset>
76
+ </script>
77
+ <script type="text/html" data-help-name="promote-admin">
78
+ <p><b>Promote Admin</b> lets you promote a user to admin in a Telegram group or channel using the Telegram MTProto API (via GramJS).</p>
79
+
80
+ <h3>Inputs</h3>
81
+ <dl class="message-properties">
82
+ <dt>payload.chatId <span class="property-type">string</span></dt>
83
+ <dd>The group/channel username (e.g., <code>@mygroup</code>) or internal Telegram ID.</dd>
84
+
85
+ <dt>payload.userId <span class="property-type">string</span></dt>
86
+ <dd>The user to promote — as a username (e.g., <code>@someuser</code>) or Telegram ID.</dd>
87
+
88
+ <dt>payload.rank <span class="property-type">string</span></dt>
89
+ <dd>The admin's visible title (e.g. "Moderator", "Editor").</dd>
90
+
91
+ <dt>payload.[rightName] <span class="property-type">boolean</span></dt>
92
+ <dd>Each right can be passed to override the checkbox values at runtime. For example, <code>payload.banUsers</code> = <code>true</code>.</dd>
93
+ </dl>
94
+
95
+ <h3>Admin Rights</h3>
96
+ <p>These rights are configured via checkboxes in the UI:</p>
97
+ <ul>
98
+ <li><code>changeInfo</code> – Can change group/channel info</li>
99
+ <li><code>postMessages</code> – Can post messages (channel only)</li>
100
+ <li><code>editMessages</code> – Can edit any message</li>
101
+ <li><code>deleteMessages</code> – Can delete messages</li>
102
+ <li><code>banUsers</code> – Can ban or remove users</li>
103
+ <li><code>inviteUsers</code> – Can invite users</li>
104
+ <li><code>pinMessages</code> – Can pin/unpin messages</li>
105
+ <li><code>addAdmins</code> – Can add new admins</li>
106
+ <li><code>manageCall</code> – Can manage voice/video chats</li>
107
+ <li><code>anonymous</code> – Acts anonymously (e.g., shows as "Group Admin")</li>
108
+ <li><code>manageTopics</code> – Can manage discussion topics (forum groups)</li>
109
+ </ul>
110
+
111
+ <h3>Outputs</h3>
112
+ <dl class="message-properties">
113
+ <dt>payload.response <span class="property-type">object</span></dt>
114
+ <dd>The Telegram API response from <code>channels.EditAdmin</code>.</dd>
115
+ </dl>
116
+
117
+ <h3>Example</h3>
118
+ <pre>
119
+ {
120
+ "payload": {
121
+ "chatId": "@mygroup",
122
+ "userId": "@targetuser",
123
+ "rank": "Moderator",
124
+ "banUsers": true,
125
+ "pinMessages": true
126
+ }
127
+ }
128
+ </pre>
24
129
  </script>
@@ -9,47 +9,43 @@ module.exports = function (RED) {
9
9
  var node = this;
10
10
 
11
11
  this.on('input', async function (msg) {
12
- let chatId = msg.payload.chatId || config.chatId;
13
- let userId = msg.payload.userId || config.userId;
14
- let rank = msg.payload.rank || config.rank || "Admin";
15
- const customRights = msg.payload.adminRights || config.adminRights;
12
+ const client = msg.payload?.client || this.config.client;
16
13
 
17
- /** @type {TelegramClient} */
18
- const client = msg.payload?.client ? msg.payload.client : this.config.client;
19
- let group, user;
14
+ const chatId = msg.payload.chatId || config.chatId;
15
+ const userId = msg.payload.userId || config.userId;
16
+ const rank = msg.payload.rank || config.rank || "Admin";
20
17
 
21
18
  try {
22
- group = chatId[0] === "@" ? await client.getEntity(chatId) : parseID(chatId);
23
- user = userId[0] === "@" ? await client.getEntity(userId) : parseID(userId);
24
-
25
- const adminRights = customRights || new Api.ChatAdminRights({
26
- changeInfo: true,
27
- postMessages: true,
28
- editMessages: true,
29
- deleteMessages: true,
30
- banUsers: true,
31
- inviteUsers: true,
32
- pinMessages: true,
33
- addAdmins: true,
34
- manageCall: true,
35
- anonymous: false,
36
- manageTopics: true,
19
+ const group = chatId[0] === "@" ? await client.getEntity(chatId) : parseID(chatId);
20
+ const user = userId[0] === "@" ? await client.getEntity(userId) : parseID(userId);
21
+
22
+ const adminRights = new Api.ChatAdminRights({
23
+ changeInfo: msg.payload.changeInfo ?? config.changeInfo,
24
+ postMessages: msg.payload.postMessages ?? config.postMessages,
25
+ editMessages: msg.payload.editMessages ?? config.editMessages,
26
+ deleteMessages: msg.payload.deleteMessages ?? config.deleteMessages,
27
+ banUsers: msg.payload.banUsers ?? config.banUsers,
28
+ inviteUsers: msg.payload.inviteUsers ?? config.inviteUsers,
29
+ pinMessages: msg.payload.pinMessages ?? config.pinMessages,
30
+ addAdmins: msg.payload.addAdmins ?? config.addAdmins,
31
+ manageCall: msg.payload.manageCall ?? config.manageCall,
32
+ anonymous: msg.payload.anonymous ?? config.anonymous,
33
+ manageTopics: msg.payload.manageTopics ?? config.manageTopics,
37
34
  });
38
35
 
39
36
  const result = await client.invoke(new Api.channels.EditAdmin({
40
37
  channel: group,
41
38
  userId: user,
42
- adminRights,
43
- rank,
39
+ adminRights: adminRights,
40
+ rank: rank,
44
41
  }));
45
42
 
46
- node.send({ payload: result });
47
-
43
+ node.send({ payload: { response: result } });
48
44
  } catch (err) {
49
- node.error('Error promoting admin: ' + err.message);
45
+ node.error("Error promoting admin: " + err.message);
50
46
  }
51
47
  });
52
48
  }
53
49
 
54
- RED.nodes.registerType('promote-admin', PromoteAdmin);
50
+ RED.nodes.registerType("promote-admin", PromoteAdmin);
55
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patricktobias86/node-red-telegram-account",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Node-RED nodes to communicate with GramJS.",
5
5
  "main": "nodes/config.js",
6
6
  "keywords": [