@patricktobias86/node-red-telegram-account 1.0.8 → 1.1.1
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/.editorconfig +12 -0
- package/README.md +11 -1
- package/nodes/promote-admin.html +224 -3
- package/nodes/promote-admin.js +24 -29
- package/package.json +1 -1
package/.editorconfig
ADDED
package/README.md
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
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
|
+
```
|
package/nodes/promote-admin.html
CHANGED
|
@@ -9,8 +9,18 @@
|
|
|
9
9
|
config: { type: 'config', required: false },
|
|
10
10
|
chatId: { value: '' },
|
|
11
11
|
userId: { value: '' },
|
|
12
|
-
rank: { value: '
|
|
13
|
-
|
|
12
|
+
rank: { value: 'admin' },
|
|
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,218 @@
|
|
|
18
28
|
return this.name || 'Promote Admin';
|
|
19
29
|
},
|
|
20
30
|
oneditprepare: function () {
|
|
21
|
-
//
|
|
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> 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">
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div id="node-input-permissions-container" class="red-ui-treeList" tabindex="0" style="width: 100%; height: 100%;">
|
|
62
|
+
<div class="red-ui-treeList-container">
|
|
63
|
+
<div class="red-ui-editableList" style="inset: 0px; position: absolute;">
|
|
64
|
+
<div class="red-ui-editableList-border red-ui-editableList-container" style="inset: 0px; position: absolute; max-height: none; overflow-y: auto;">
|
|
65
|
+
<ol class="red-ui-treeList-list red-ui-editableList-list" style="position: static; inset: auto; height: auto;">
|
|
66
|
+
<li>
|
|
67
|
+
<div class="red-ui-editableList-item-content">
|
|
68
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
69
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
70
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-changeInfo">
|
|
71
|
+
<label for="node-input-changeInfo">Can change group info</label>
|
|
72
|
+
</span>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</li>
|
|
76
|
+
|
|
77
|
+
<li>
|
|
78
|
+
<div class="red-ui-editableList-item-content">
|
|
79
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
80
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
81
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-postMessages">
|
|
82
|
+
<label for="node-input-postMessages">Can post messages</label>
|
|
83
|
+
</span>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</li>
|
|
87
|
+
<li>
|
|
88
|
+
<div class="red-ui-editableList-item-content">
|
|
89
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
90
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
91
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-editMessages">
|
|
92
|
+
<label for="node-input-editMessages">Can edit messages</label>
|
|
93
|
+
</span>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</li>
|
|
97
|
+
|
|
98
|
+
<li>
|
|
99
|
+
<div class="red-ui-editableList-item-content">
|
|
100
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
101
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
102
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-deleteMessages">
|
|
103
|
+
<label for="node-input-deleteMessages">Can delete messages</label>
|
|
104
|
+
</span>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</li>
|
|
108
|
+
|
|
109
|
+
<li>
|
|
110
|
+
<div class="red-ui-editableList-item-content">
|
|
111
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
112
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
113
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-banUsers">
|
|
114
|
+
<label for="node-input-banUsers">Can ban users</label>
|
|
115
|
+
</span>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
</li>
|
|
119
|
+
|
|
120
|
+
<li>
|
|
121
|
+
<div class="red-ui-editableList-item-content">
|
|
122
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
123
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
124
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-inviteUsers">
|
|
125
|
+
<label for="node-input-inviteUsers">Can invite users</label>
|
|
126
|
+
</span>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</li>
|
|
130
|
+
|
|
131
|
+
<li>
|
|
132
|
+
<div class="red-ui-editableList-item-content">
|
|
133
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
134
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
135
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-pinMessages">
|
|
136
|
+
<label for="node-input-pinMessages">Can pin messages</label>
|
|
137
|
+
</span>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</li>
|
|
141
|
+
|
|
142
|
+
<li>
|
|
143
|
+
<div class="red-ui-editableList-item-content">
|
|
144
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
145
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
146
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-addAdmins">
|
|
147
|
+
<label for="node-input-addAdmins">Can add new admins</label>
|
|
148
|
+
</span>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</li>
|
|
152
|
+
|
|
153
|
+
<li>
|
|
154
|
+
<div class="red-ui-editableList-item-content">
|
|
155
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
156
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
157
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-manageCall">
|
|
158
|
+
<label for="node-input-manageCall">Can manage voice/video chats</label>
|
|
159
|
+
</span>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</li>
|
|
163
|
+
|
|
164
|
+
<li>
|
|
165
|
+
<div class="red-ui-editableList-item-content">
|
|
166
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
167
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
168
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-anonymous">
|
|
169
|
+
<label for="node-input-anonymous">Is anonymous (hidden from group)</label>
|
|
170
|
+
</span>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
</li>
|
|
174
|
+
|
|
175
|
+
<li>
|
|
176
|
+
<div class="red-ui-editableList-item-content">
|
|
177
|
+
<div class="red-ui-treeList-label" style="justify-content: flex-start;">
|
|
178
|
+
<span class="red-ui-treeList-icon" style="width: unset; text-align: left; display: inline-flex;">
|
|
179
|
+
<input class="red-ui-treeList-checkbox" style="margin: 5px 5px 10px 5px;" type="checkbox" id="node-input-manageTopics">
|
|
180
|
+
<label for="node-input-manageTopics">Can manage topics</label>
|
|
181
|
+
</span>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</li>
|
|
185
|
+
|
|
186
|
+
</ol>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
</div>
|
|
191
|
+
|
|
192
|
+
</script>
|
|
193
|
+
<script type="text/html" data-help-name="promote-admin">
|
|
194
|
+
<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>
|
|
195
|
+
|
|
196
|
+
<h3>Inputs</h3>
|
|
197
|
+
<dl class="message-properties">
|
|
198
|
+
<dt>payload.chatId <span class="property-type">string</span></dt>
|
|
199
|
+
<dd>The group/channel username (e.g., <code>@mygroup</code>) or internal Telegram ID.</dd>
|
|
200
|
+
|
|
201
|
+
<dt>payload.userId <span class="property-type">string</span></dt>
|
|
202
|
+
<dd>The user to promote — as a username (e.g., <code>@someuser</code>) or Telegram ID.</dd>
|
|
203
|
+
|
|
204
|
+
<dt>payload.rank <span class="property-type">string</span></dt>
|
|
205
|
+
<dd>The admin's visible title (e.g. "Moderator", "Editor").</dd>
|
|
206
|
+
|
|
207
|
+
<dt>payload.[rightName] <span class="property-type">boolean</span></dt>
|
|
208
|
+
<dd>Each right can be passed to override the checkbox values at runtime. For example, <code>payload.banUsers</code> = <code>true</code>.</dd>
|
|
209
|
+
</dl>
|
|
210
|
+
|
|
211
|
+
<h3>Admin Rights</h3>
|
|
212
|
+
<p>These rights are configured via checkboxes in the UI:</p>
|
|
213
|
+
<ul>
|
|
214
|
+
<li><code>changeInfo</code> – Can change group/channel info</li>
|
|
215
|
+
<li><code>postMessages</code> – Can post messages (channel only)</li>
|
|
216
|
+
<li><code>editMessages</code> – Can edit any message</li>
|
|
217
|
+
<li><code>deleteMessages</code> – Can delete messages</li>
|
|
218
|
+
<li><code>banUsers</code> – Can ban or remove users</li>
|
|
219
|
+
<li><code>inviteUsers</code> – Can invite users</li>
|
|
220
|
+
<li><code>pinMessages</code> – Can pin/unpin messages</li>
|
|
221
|
+
<li><code>addAdmins</code> – Can add new admins</li>
|
|
222
|
+
<li><code>manageCall</code> – Can manage voice/video chats</li>
|
|
223
|
+
<li><code>anonymous</code> – Acts anonymously (e.g., shows as "Group Admin")</li>
|
|
224
|
+
<li><code>manageTopics</code> – Can manage discussion topics (forum groups)</li>
|
|
225
|
+
</ul>
|
|
226
|
+
|
|
227
|
+
<h3>Outputs</h3>
|
|
228
|
+
<dl class="message-properties">
|
|
229
|
+
<dt>payload.response <span class="property-type">object</span></dt>
|
|
230
|
+
<dd>The Telegram API response from <code>channels.EditAdmin</code>.</dd>
|
|
231
|
+
</dl>
|
|
232
|
+
|
|
233
|
+
<h3>Example</h3>
|
|
234
|
+
<pre>
|
|
235
|
+
{
|
|
236
|
+
"payload": {
|
|
237
|
+
"chatId": "@mygroup",
|
|
238
|
+
"userId": "@targetuser",
|
|
239
|
+
"rank": "admin",
|
|
240
|
+
"banUsers": true,
|
|
241
|
+
"pinMessages": true
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
</pre>
|
|
24
245
|
</script>
|
package/nodes/promote-admin.js
CHANGED
|
@@ -9,47 +9,42 @@ module.exports = function (RED) {
|
|
|
9
9
|
var node = this;
|
|
10
10
|
|
|
11
11
|
this.on('input', async function (msg) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
/** @type {TelegramClient} */
|
|
18
|
-
const client = msg.payload?.client ? msg.payload.client : this.config.client;
|
|
19
|
-
let group, user;
|
|
12
|
+
const client = msg.payload?.client || this.config.client;
|
|
13
|
+
const chatId = msg.payload.chatId || config.chatId;
|
|
14
|
+
const userId = msg.payload.userId || config.userId;
|
|
15
|
+
const rank = msg.payload.rank || config.rank || "admin";
|
|
20
16
|
|
|
21
17
|
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 =
|
|
26
|
-
changeInfo:
|
|
27
|
-
postMessages:
|
|
28
|
-
editMessages:
|
|
29
|
-
deleteMessages:
|
|
30
|
-
banUsers:
|
|
31
|
-
inviteUsers:
|
|
32
|
-
pinMessages:
|
|
33
|
-
addAdmins:
|
|
34
|
-
manageCall:
|
|
35
|
-
anonymous:
|
|
36
|
-
manageTopics:
|
|
18
|
+
const group = chatId[0] === "@" ? await client.getEntity(chatId) : parseID(chatId);
|
|
19
|
+
const user = userId[0] === "@" ? await client.getEntity(userId) : parseID(userId);
|
|
20
|
+
|
|
21
|
+
const adminRights = new Api.ChatAdminRights({
|
|
22
|
+
changeInfo: msg.payload.changeInfo ?? config.changeInfo,
|
|
23
|
+
postMessages: msg.payload.postMessages ?? config.postMessages,
|
|
24
|
+
editMessages: msg.payload.editMessages ?? config.editMessages,
|
|
25
|
+
deleteMessages: msg.payload.deleteMessages ?? config.deleteMessages,
|
|
26
|
+
banUsers: msg.payload.banUsers ?? config.banUsers,
|
|
27
|
+
inviteUsers: msg.payload.inviteUsers ?? config.inviteUsers,
|
|
28
|
+
pinMessages: msg.payload.pinMessages ?? config.pinMessages,
|
|
29
|
+
addAdmins: msg.payload.addAdmins ?? config.addAdmins,
|
|
30
|
+
manageCall: msg.payload.manageCall ?? config.manageCall,
|
|
31
|
+
anonymous: msg.payload.anonymous ?? config.anonymous,
|
|
32
|
+
manageTopics: msg.payload.manageTopics ?? config.manageTopics,
|
|
37
33
|
});
|
|
38
34
|
|
|
39
35
|
const result = await client.invoke(new Api.channels.EditAdmin({
|
|
40
36
|
channel: group,
|
|
41
37
|
userId: user,
|
|
42
|
-
adminRights,
|
|
43
|
-
rank,
|
|
38
|
+
adminRights: adminRights,
|
|
39
|
+
rank: rank,
|
|
44
40
|
}));
|
|
45
41
|
|
|
46
|
-
node.send({ payload: result });
|
|
47
|
-
|
|
42
|
+
node.send({ payload: { response: result } });
|
|
48
43
|
} catch (err) {
|
|
49
|
-
node.error(
|
|
44
|
+
node.error("Error promoting admin: " + err.message);
|
|
50
45
|
}
|
|
51
46
|
});
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
RED.nodes.registerType(
|
|
49
|
+
RED.nodes.registerType("promote-admin", PromoteAdmin);
|
|
55
50
|
};
|