iobroker.telegram 3.3.2 → 3.4.0
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 +5 -6
- package/admin/blockly.js +434 -119
- package/admin/custom/customComponents.js +3 -3
- package/admin/custom/customComponents.js.map +1 -1
- package/admin/custom/static/js/main.5b254c9b.js +5 -0
- package/admin/custom/static/js/main.5b254c9b.js.map +1 -0
- package/admin/custom/static/js/{node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694110.cecb317a.chunk.js → node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-de23730.8e97bb92.chunk.js} +2 -2
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-de23730.8e97bb92.chunk.js.map +1 -0
- package/admin/custom/static/js/{node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694111.31c3460d.chunk.js → node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-de23731.0f3598f3.chunk.js} +2 -2
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-de23731.0f3598f3.chunk.js.map +1 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_mui_styles_index_js-node_modules_babel_ru-9901bb.9afab946.chunk.js +35 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_mui_styles_index_js-node_modules_babel_ru-9901bb.9afab946.chunk.js.map +1 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_mui_styles_index_js.f4b9096f.chunk.js +9 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_mui_styles_index_js.f4b9096f.chunk.js.map +1 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d270.8a187a3c.chunk.js +10 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d270.8a187a3c.chunk.js.map +1 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d271.06075af5.chunk.js +14 -0
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d271.06075af5.chunk.js.map +1 -0
- package/admin/custom/static/js/src_Components_jsx.39bd6057.chunk.js.map +1 -1
- package/admin/custom/static/js/src_bootstrap_jsx.f7189f51.chunk.js +3 -0
- package/admin/custom/static/js/src_bootstrap_jsx.f7189f51.chunk.js.map +1 -0
- package/admin/jsonConfig.json +1 -1
- package/admin/rules/asset-manifest.json +13 -11
- package/admin/rules/customRuleBlocks.js +3 -3
- package/admin/rules/customRuleBlocks.js.map +1 -1
- package/admin/rules/static/js/main.44f1f861.js +5 -0
- package/admin/rules/static/js/main.44f1f861.js.map +1 -0
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-d234ae.c537ddf6.chunk.js +3 -0
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-d234ae.c537ddf6.chunk.js.map +1 -0
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d270.bc9865f0.chunk.js +10 -0
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d270.bc9865f0.chunk.js.map +1 -0
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d271.bbc6ce97.chunk.js +14 -0
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_node_modules_react_index_js-_9d271.bbc6ce97.chunk.js.map +1 -0
- package/admin/rules/static/js/src_ActionTelegram_jsx.606264b1.chunk.js.map +1 -1
- package/io-package.json +14 -14
- package/main.js +25 -3
- package/package.json +4 -4
- package/admin/custom/static/js/main.5b1fac6c.js +0 -5
- package/admin/custom/static/js/main.5b1fac6c.js.map +0 -1
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694110.cecb317a.chunk.js.map +0 -1
- package/admin/custom/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694111.31c3460d.chunk.js.map +0 -1
- package/admin/custom/static/js/src_bootstrap_jsx.14a0e1d0.chunk.js +0 -3
- package/admin/custom/static/js/src_bootstrap_jsx.14a0e1d0.chunk.js.map +0 -1
- package/admin/rules/static/js/main.a721e2f4.js +0 -5
- package/admin/rules/static/js/main.a721e2f4.js.map +0 -1
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694110.50566baf.chunk.js +0 -3
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694110.50566baf.chunk.js.map +0 -1
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694111.f34776f9.chunk.js +0 -3
- package/admin/rules/static/js/node_modules_iobroker_adapter-react-v5_assets_devices_sync_recursive_-node_modules_iobroker_a-b694111.f34776f9.chunk.js.map +0 -1
package/admin/blockly.js
CHANGED
|
@@ -22,49 +22,40 @@ Blockly.Words['telegram_help'] = {'en': 'https://github.com/ioBroker/io
|
|
|
22
22
|
Blockly.Words['telegram_silent'] = {'en': 'without notification', 'de': 'ohne Benachrichtigung', 'ru': 'без уведомления', 'pt': 'sem notificação', 'nl': 'zonder kennisgeving', 'fr': 'sans notification', 'it': 'senza notifica', 'es': 'sin notificación', 'pl': 'bez powiadomienia'};
|
|
23
23
|
Blockly.Words['telegram_escaping'] = {'en': 'Escape chars', 'de': 'Escapezeichen verwenden', 'ru': 'Escape', 'pt': 'escape chars', 'nl': 'escape chars', 'fr': 'escape chars', 'it': 'escape chars', 'es': 'escape chars', 'pl': 'escape chars', 'zh-cn': 'escape chars'};
|
|
24
24
|
Blockly.Words['telegram_disable_web_preview'] = {'en': 'disable web preview', 'de': 'Webvorschau deaktivieren', 'ru': 'отключить предварительный просмотр в Интернете', 'pt': 'desativar a visualização da web', 'nl': 'webvoorbeeld uitschakelen', 'fr': 'désactiver l\'aperçu Web','it': 'disabilitare l\'anteprima web', 'es': 'deshabilitar la vista previa web', 'pl': 'wyłącz podgląd internetowy', 'zh-cn': '禁用网页预览'};
|
|
25
|
+
|
|
25
26
|
Blockly.Sendto.blocks['telegram'] =
|
|
26
|
-
'<block type="telegram">'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
+ ' </value>'
|
|
40
|
-
+ ' <value name="SILENT">'
|
|
41
|
-
+ ' </value>'
|
|
42
|
-
+ ' <value name="PARSEMODE">'
|
|
43
|
-
+ ' </value>'
|
|
44
|
-
+ ' <value name="ESCAPING">'
|
|
45
|
-
+ ' </value>'
|
|
46
|
-
+ ' <value name="DISABLE_WEB_PAGE_PREVIEW">'
|
|
47
|
-
+ ' </value>'
|
|
48
|
-
+ '</block>';
|
|
27
|
+
'<block type="telegram">' +
|
|
28
|
+
' <field name="INSTANCE"></field>' +
|
|
29
|
+
' <field name="LOG"></field>' +
|
|
30
|
+
' <field name="SILENT">FALSE</field>' +
|
|
31
|
+
' <field name="PARSEMODE">default</field>' +
|
|
32
|
+
' <field name="ESCAPING">FALSE</field>' +
|
|
33
|
+
' <field name="DISABLE_WEB_PAGE_PREVIEW">FALSE</field>' +
|
|
34
|
+
' <value name="MESSAGE">' +
|
|
35
|
+
' <shadow type="text">' +
|
|
36
|
+
' <field name="TEXT">text</field>' +
|
|
37
|
+
' </shadow>' +
|
|
38
|
+
' </value>' +
|
|
39
|
+
'</block>';
|
|
49
40
|
|
|
50
41
|
Blockly.Blocks['telegram'] = {
|
|
51
42
|
init: function() {
|
|
52
|
-
|
|
43
|
+
const options = [[Blockly.Translate('telegram_anyInstance'), '']];
|
|
53
44
|
if (typeof main !== 'undefined' && main.instances) {
|
|
54
|
-
for (
|
|
55
|
-
|
|
45
|
+
for (let i = 0; i < main.instances.length; i++) {
|
|
46
|
+
const m = main.instances[i].match(/^system.adapter.telegram.(\d+)$/);
|
|
56
47
|
if (m) {
|
|
57
|
-
|
|
48
|
+
const k = parseInt(m[1], 10);
|
|
58
49
|
options.push(['telegram.' + k, '.' + k]);
|
|
59
50
|
}
|
|
60
51
|
}
|
|
61
52
|
if (options.length === 0) {
|
|
62
|
-
for (
|
|
53
|
+
for (let u = 0; u <= 4; u++) {
|
|
63
54
|
options.push(['telegram.' + u, '.' + u]);
|
|
64
55
|
}
|
|
65
56
|
}
|
|
66
57
|
} else {
|
|
67
|
-
for (
|
|
58
|
+
for (let n = 0; n <= 4; n++) {
|
|
68
59
|
options.push(['telegram.' + n, '.' + n]);
|
|
69
60
|
}
|
|
70
61
|
}
|
|
@@ -76,22 +67,28 @@ Blockly.Blocks['telegram'] = {
|
|
|
76
67
|
this.appendValueInput('MESSAGE')
|
|
77
68
|
.appendField(Blockly.Translate('telegram_message'));
|
|
78
69
|
|
|
79
|
-
|
|
70
|
+
const inputUser = this.appendValueInput('USERNAME')
|
|
80
71
|
.setCheck('String')
|
|
81
72
|
.appendField(Blockly.Translate('telegram_username'));
|
|
73
|
+
if (inputUser.connection) {
|
|
74
|
+
inputUser.connection._optional = true;
|
|
75
|
+
}
|
|
82
76
|
|
|
83
|
-
|
|
77
|
+
const inputChat = this.appendValueInput('CHATID')
|
|
84
78
|
.setCheck('String')
|
|
85
79
|
.appendField(Blockly.Translate('telegram_chatid'));
|
|
80
|
+
if (inputChat.connection) {
|
|
81
|
+
inputChat.connection._optional = true;
|
|
82
|
+
}
|
|
86
83
|
|
|
87
84
|
this.appendDummyInput('LOG')
|
|
88
85
|
.appendField(Blockly.Translate('telegram_log'))
|
|
89
86
|
.appendField(new Blockly.FieldDropdown([
|
|
90
87
|
[Blockly.Translate('telegram_log_none'), ''],
|
|
91
|
-
[Blockly.Translate('telegram_log_info'), 'log'],
|
|
92
88
|
[Blockly.Translate('telegram_log_debug'), 'debug'],
|
|
89
|
+
[Blockly.Translate('telegram_log_info'), 'log'],
|
|
93
90
|
[Blockly.Translate('telegram_log_warn'), 'warn'],
|
|
94
|
-
[Blockly.Translate('telegram_log_error'), 'error']
|
|
91
|
+
[Blockly.Translate('telegram_log_error'), 'error'],
|
|
95
92
|
]), 'LOG');
|
|
96
93
|
|
|
97
94
|
this.appendDummyInput('SILENT')
|
|
@@ -110,13 +107,6 @@ Blockly.Blocks['telegram'] = {
|
|
|
110
107
|
.appendField(Blockly.Translate('telegram_disable_web_preview'))
|
|
111
108
|
.appendField(new Blockly.FieldCheckbox('FALSE'), 'DISABLE_WEB_PAGE_PREVIEW');
|
|
112
109
|
|
|
113
|
-
if (input.connection) {
|
|
114
|
-
input.connection._optional = true;
|
|
115
|
-
}
|
|
116
|
-
if (input1.connection) {
|
|
117
|
-
input1.connection._optional = true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
110
|
this.setInputsInline(false);
|
|
121
111
|
this.setPreviousStatement(true, null);
|
|
122
112
|
this.setNextStatement(true, null);
|
|
@@ -124,40 +114,39 @@ Blockly.Blocks['telegram'] = {
|
|
|
124
114
|
this.setColour(Blockly.Sendto.HUE);
|
|
125
115
|
this.setTooltip(Blockly.Translate('telegram_tooltip'));
|
|
126
116
|
this.setHelpUrl(Blockly.Translate('telegram_help'));
|
|
127
|
-
}
|
|
117
|
+
},
|
|
128
118
|
};
|
|
129
119
|
|
|
130
120
|
Blockly.JavaScript['telegram'] = function(block) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
const dropdown_instance = block.getFieldValue('INSTANCE');
|
|
122
|
+
const logLevel = block.getFieldValue('LOG');
|
|
123
|
+
let value_message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
124
|
+
const value_username = Blockly.JavaScript.valueToCode(block, 'USERNAME', Blockly.JavaScript.ORDER_ATOMIC);
|
|
125
|
+
const value_chatid = Blockly.JavaScript.valueToCode(block, 'CHATID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
126
|
+
const silent = block.getFieldValue('SILENT');
|
|
127
|
+
const escaping = block.getFieldValue('ESCAPING');
|
|
128
|
+
const disable_web_page_preview = block.getFieldValue('DISABLE_WEB_PAGE_PREVIEW');
|
|
129
|
+
const parsemode = block.getFieldValue('PARSEMODE');
|
|
130
|
+
|
|
131
|
+
let logText = '';
|
|
142
132
|
if (logLevel) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
logText = '';
|
|
133
|
+
const logUsername = value_username ? `[' + ${value_username} + ']` : '';
|
|
134
|
+
logText = `console.${logLevel}('telegram${logUsername}: ' + ${value_message});\n`;
|
|
146
135
|
}
|
|
147
136
|
|
|
148
137
|
if (escaping === 'TRUE') {
|
|
149
138
|
// escape following characters: "_*[]()~`>#+-=|{}.!"
|
|
150
|
-
value_message +=
|
|
139
|
+
value_message += ".replace(/([-_*\\[\\]()~`>#+=|{}.!])/g, '\\\\$1')";
|
|
151
140
|
}
|
|
152
141
|
|
|
153
|
-
return
|
|
154
|
-
value_message
|
|
155
|
-
(
|
|
156
|
-
(
|
|
157
|
-
(
|
|
158
|
-
(
|
|
159
|
-
'
|
|
160
|
-
logText
|
|
142
|
+
return `sendTo('telegram${dropdown_instance}', 'send', {\n` +
|
|
143
|
+
` text: ${value_message},\n` +
|
|
144
|
+
(value_username ? ` user: ${value_username},\n` : '') +
|
|
145
|
+
(value_chatid ? ` chatId: ${value_chatid},\n` : '') +
|
|
146
|
+
(silent === 'TRUE' ? ' disable_notification: true,\n' : '') +
|
|
147
|
+
(disable_web_page_preview === 'TRUE' ? ' disable_web_page_preview: true,\n' : '') +
|
|
148
|
+
(parsemode !== 'default' ? ` parse_mode: '${parsemode}',\n` : '') +
|
|
149
|
+
`});\n${logText}`;
|
|
161
150
|
};
|
|
162
151
|
|
|
163
152
|
// --- SendTo call telegram --------------------------------------------------
|
|
@@ -168,45 +157,41 @@ Blockly.Words['telegram_call_help'] = {'en': 'https://github.com/ioBroker/io
|
|
|
168
157
|
Blockly.Words['telegram_call_repeats'] = {'en': 'Repeats', 'de': 'Wiederholungen', 'ru': 'Повторить', 'pt': 'Repete', 'nl': 'Herhaalt', 'fr': 'Répète', 'it': 'Si ripete', 'es': 'Repite', 'pl': 'Powtarza się', 'zh-cn': '重复'};
|
|
169
158
|
|
|
170
159
|
Blockly.Sendto.blocks['telegram_call'] =
|
|
171
|
-
'<block type="telegram_call">'
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
+ ' </value>'
|
|
188
|
-
+ ' <value name="LOG">'
|
|
189
|
-
+ ' </value>'
|
|
190
|
-
+ '</block>';
|
|
160
|
+
'<block type="telegram_call">' +
|
|
161
|
+
' <field name="INSTANCE"></field>' +
|
|
162
|
+
' <field name="LANGUAGE"></field>' +
|
|
163
|
+
' <field name="REPEATS">1</field>' +
|
|
164
|
+
' <field name="LOG"></field>' +
|
|
165
|
+
' <value name="MESSAGE">' +
|
|
166
|
+
' <shadow type="text">' +
|
|
167
|
+
' <field name="TEXT">text</field>' +
|
|
168
|
+
' </shadow>' +
|
|
169
|
+
' </value>' +
|
|
170
|
+
' <value name="USERNAME">' +
|
|
171
|
+
' <shadow type="text">' +
|
|
172
|
+
' <field name="TEXT"></field>' +
|
|
173
|
+
' </shadow>' +
|
|
174
|
+
' </value>' +
|
|
175
|
+
'</block>';
|
|
191
176
|
|
|
192
177
|
Blockly.Blocks['telegram_call'] = {
|
|
193
178
|
init: function() {
|
|
194
|
-
|
|
179
|
+
const options = [[Blockly.Translate('telegram_anyInstance'), '']];
|
|
195
180
|
if (typeof main !== 'undefined' && main.instances) {
|
|
196
|
-
for (
|
|
197
|
-
|
|
181
|
+
for (let i = 0; i < main.instances.length; i++) {
|
|
182
|
+
const m = main.instances[i].match(/^system.adapter.telegram.(\d+)$/);
|
|
198
183
|
if (m) {
|
|
199
|
-
|
|
184
|
+
const k = parseInt(m[1], 10);
|
|
200
185
|
options.push(['telegram.' + k, '.' + k]);
|
|
201
186
|
}
|
|
202
187
|
}
|
|
203
188
|
if (options.length === 0) {
|
|
204
|
-
for (
|
|
189
|
+
for (let u = 0; u <= 4; u++) {
|
|
205
190
|
options.push(['telegram.' + u, '.' + u]);
|
|
206
191
|
}
|
|
207
192
|
}
|
|
208
193
|
} else {
|
|
209
|
-
for (
|
|
194
|
+
for (let n = 0; n <= 4; n++) {
|
|
210
195
|
options.push(['telegram.' + n, '.' + n]);
|
|
211
196
|
}
|
|
212
197
|
}
|
|
@@ -218,11 +203,14 @@ Blockly.Blocks['telegram_call'] = {
|
|
|
218
203
|
this.appendValueInput('MESSAGE')
|
|
219
204
|
.appendField(Blockly.Translate('telegram_message'));
|
|
220
205
|
|
|
221
|
-
|
|
206
|
+
const inputUsername = this.appendValueInput('USERNAME')
|
|
222
207
|
.setCheck('String')
|
|
223
208
|
.appendField(Blockly.Translate('telegram_username'));
|
|
209
|
+
if (inputUsername.connection) {
|
|
210
|
+
inputUsername.connection._optional = true;
|
|
211
|
+
}
|
|
224
212
|
|
|
225
|
-
|
|
213
|
+
const languages = [
|
|
226
214
|
[Blockly.Translate('telegram_call_system'), ''],
|
|
227
215
|
['German (Germany) (Female)', 'de-DE-Standard-A'],
|
|
228
216
|
['German (Germany) (Male)', 'de-DE-Standard-B'],
|
|
@@ -329,23 +317,19 @@ Blockly.Blocks['telegram_call'] = {
|
|
|
329
317
|
['2', '2'],
|
|
330
318
|
['3', '3'],
|
|
331
319
|
['4', '4'],
|
|
332
|
-
['5', '5']
|
|
320
|
+
['5', '5'],
|
|
333
321
|
]), 'REPEATS');
|
|
334
322
|
|
|
335
323
|
this.appendDummyInput('LOG')
|
|
336
324
|
.appendField(Blockly.Translate('telegram_log'))
|
|
337
325
|
.appendField(new Blockly.FieldDropdown([
|
|
338
326
|
[Blockly.Translate('telegram_log_none'), ''],
|
|
339
|
-
[Blockly.Translate('telegram_log_info'), 'log'],
|
|
340
327
|
[Blockly.Translate('telegram_log_debug'), 'debug'],
|
|
328
|
+
[Blockly.Translate('telegram_log_info'), 'log'],
|
|
341
329
|
[Blockly.Translate('telegram_log_warn'), 'warn'],
|
|
342
|
-
[Blockly.Translate('telegram_log_error'), 'error']
|
|
330
|
+
[Blockly.Translate('telegram_log_error'), 'error'],
|
|
343
331
|
]), 'LOG');
|
|
344
332
|
|
|
345
|
-
if (input.connection) {
|
|
346
|
-
input.connection._optional = true;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
333
|
this.setInputsInline(false);
|
|
350
334
|
this.setPreviousStatement(true, null);
|
|
351
335
|
this.setNextStatement(true, null);
|
|
@@ -353,31 +337,362 @@ Blockly.Blocks['telegram_call'] = {
|
|
|
353
337
|
this.setColour(Blockly.Sendto.HUE);
|
|
354
338
|
this.setTooltip(Blockly.Translate('telegram_call_tooltip'));
|
|
355
339
|
this.setHelpUrl(Blockly.Translate('telegram_call_help'));
|
|
356
|
-
}
|
|
340
|
+
},
|
|
357
341
|
};
|
|
358
342
|
|
|
359
343
|
Blockly.JavaScript['telegram_call'] = function(block) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
var logText;
|
|
344
|
+
const dropdown_instance = block.getFieldValue('INSTANCE');
|
|
345
|
+
const dropdown_language = block.getFieldValue('LANGUAGE');
|
|
346
|
+
const repeats = block.getFieldValue('REPEATS');
|
|
347
|
+
const logLevel = block.getFieldValue('LOG');
|
|
348
|
+
const value_message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', Blockly.JavaScript.ORDER_ATOMIC);
|
|
349
|
+
const value_username = Blockly.JavaScript.valueToCode(block, 'USERNAME', Blockly.JavaScript.ORDER_ATOMIC);
|
|
350
|
+
|
|
351
|
+
let logText = '';
|
|
369
352
|
if (logLevel) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
logText = '';
|
|
353
|
+
const logUsername = value_username ? `[' + ${value_username} + ']` : '';
|
|
354
|
+
logText = `console.${logLevel}('telegramCall${logUsername}: ' + ${value_message});\n`;
|
|
373
355
|
}
|
|
374
356
|
|
|
375
|
-
return
|
|
376
|
-
|
|
377
|
-
(value_username ?
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
357
|
+
return `sendTo('telegram${dropdown_instance}', 'call', {\n` +
|
|
358
|
+
` text: ${value_message},\n` +
|
|
359
|
+
(value_username ? ` user: ${value_username},\n` : '') +
|
|
360
|
+
` lang: '${dropdown_language}',\n` +
|
|
361
|
+
` repeats: ${parseInt(repeats, 10) || 1},\n` +
|
|
362
|
+
`});\n${logText}`;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// --- SendTo ask telegram --------------------------------------------------
|
|
366
|
+
Blockly.Words['telegram_ask'] = { 'en': 'ask via Telegram', 'de': 'fragen per Telegramm', 'ru': 'спрос через Telegram', 'pt': 'perguntar via Telegram', 'nl': 'vragen via Telegram', 'fr': 'demander via Telegram', 'it': 'chiedere via Telegram', 'es': 'pregunte por Telegram', 'pl': 'pytaj przez Telegram', 'uk': 'подати заявку', 'zh-cn': '通过Telegram 查询' };
|
|
367
|
+
Blockly.Words['telegram_ask_question'] = { 'en': 'Question', 'de': 'Frage', 'ru': 'Вопрос', 'pt': 'Pergunta', 'nl': 'Vraag', 'fr': 'Question', 'it': 'Domanda', 'es': 'Pregunta', 'pl': 'Pytanie', 'uk': 'Питання', 'zh-cn': '问题' };
|
|
368
|
+
Blockly.Words['telegram_ask_answers'] = { 'en': 'Answers', 'de': 'Antworten', 'ru': 'Ответы', 'pt': 'Respostas', 'nl': 'Antwoorden', 'fr': 'Réponses', 'it': 'Risposte', 'es': 'Respuestas', 'pl': 'Odpowiedzi', 'uk': 'Відповідей', 'zh-cn': '答复' };
|
|
369
|
+
Blockly.Words['telegram_ask_answer'] = { 'en': 'Answer', 'de': 'Antwort', 'ru': 'Ответ', 'pt': 'Resposta', 'nl': 'Antwoord', 'fr': 'Réponse', 'it': 'Risposta', 'es': 'Respuesta', 'pl': 'Odpowiedź', 'uk': 'Відправити', 'zh-cn': '答复' };
|
|
370
|
+
|
|
371
|
+
Blockly.Sendto.blocks['telegram_ask'] =
|
|
372
|
+
'<block type="telegram_ask">' +
|
|
373
|
+
' <mutation>' +
|
|
374
|
+
' <answer id="ANSWER_0" name="yes"></answer>' +
|
|
375
|
+
' </mutation>' +
|
|
376
|
+
' <field name="INSTANCE"></field>' +
|
|
377
|
+
' <field name="LOG"></field>' +
|
|
378
|
+
' <value name="QUESTION">' +
|
|
379
|
+
' <shadow type="text">' +
|
|
380
|
+
' <field name="TEXT">text</field>' +
|
|
381
|
+
' </shadow>' +
|
|
382
|
+
' </value>' +
|
|
383
|
+
' <value name="USERNAME">' +
|
|
384
|
+
' <shadow type="text">' +
|
|
385
|
+
' <field name="TEXT"></field>' +
|
|
386
|
+
' </shadow>' +
|
|
387
|
+
' </value>' +
|
|
388
|
+
' <value name="ANSWER_0">' +
|
|
389
|
+
' <shadow type="text">' +
|
|
390
|
+
' <field name="TEXT">Yes, please</field>' +
|
|
391
|
+
' </shadow>' +
|
|
392
|
+
' </value>' +
|
|
393
|
+
'</block>';
|
|
394
|
+
|
|
395
|
+
Blockly.Blocks['telegram_ask_container'] = {
|
|
396
|
+
/**
|
|
397
|
+
* Mutator block for container.
|
|
398
|
+
* @this Blockly.Block
|
|
399
|
+
*/
|
|
400
|
+
init: function() {
|
|
401
|
+
this.setColour(Blockly.Object.HUE);
|
|
402
|
+
|
|
403
|
+
this.appendDummyInput()
|
|
404
|
+
.appendField(Blockly.Translate('telegram_ask_answers'));
|
|
405
|
+
|
|
406
|
+
this.appendStatementInput('STACK');
|
|
407
|
+
this.setTooltip(Blockly.Translate('object_new_tooltip'));
|
|
408
|
+
|
|
409
|
+
this.contextMenu = false;
|
|
410
|
+
},
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
Blockly.Blocks['telegram_ask_mutator'] = {
|
|
414
|
+
/**
|
|
415
|
+
* Mutator block for add items.
|
|
416
|
+
* @this Blockly.Block
|
|
417
|
+
*/
|
|
418
|
+
init: function() {
|
|
419
|
+
this.setColour(Blockly.Sendto.HUE);
|
|
420
|
+
|
|
421
|
+
this.appendDummyInput('ANSWER')
|
|
422
|
+
.appendField(Blockly.Translate('telegram_ask_answer'))
|
|
423
|
+
.appendField(new Blockly.FieldTextInput('okay'), 'ANSWER');
|
|
424
|
+
|
|
425
|
+
this.setPreviousStatement(true);
|
|
426
|
+
this.setNextStatement(true);
|
|
427
|
+
|
|
428
|
+
this.setTooltip(Blockly.Translate('telegram_ask_tooltip'));
|
|
429
|
+
|
|
430
|
+
this.contextMenu = false;
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
Blockly.Blocks['telegram_ask'] = {
|
|
435
|
+
init: function() {
|
|
436
|
+
this.answers_ = [];
|
|
437
|
+
this.itemCount_ = 0;
|
|
438
|
+
if (typeof Blockly.icons === 'object') {
|
|
439
|
+
this.setMutator(new Blockly.icons.MutatorIcon(['telegram_ask_mutator'], this));
|
|
440
|
+
} else {
|
|
441
|
+
// Blockly 9.x
|
|
442
|
+
this.setMutator(new Blockly.Mutator(['telegram_ask_mutator'], this));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const options = [[Blockly.Translate('telegram_anyInstance'), '']];
|
|
446
|
+
if (typeof main !== 'undefined' && main.instances) {
|
|
447
|
+
for (let i = 0; i < main.instances.length; i++) {
|
|
448
|
+
const m = main.instances[i].match(/^system.adapter.telegram.(\d+)$/);
|
|
449
|
+
if (m) {
|
|
450
|
+
const k = parseInt(m[1], 10);
|
|
451
|
+
options.push(['telegram.' + k, '.' + k]);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (options.length === 0) {
|
|
455
|
+
for (let u = 0; u <= 4; u++) {
|
|
456
|
+
options.push(['telegram.' + u, '.' + u]);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
for (let n = 0; n <= 4; n++) {
|
|
461
|
+
options.push(['telegram.' + n, '.' + n]);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
this.appendDummyInput('INSTANCE')
|
|
466
|
+
.appendField(Blockly.Translate('telegram_ask'))
|
|
467
|
+
.appendField(new Blockly.FieldDropdown(options), 'INSTANCE');
|
|
468
|
+
|
|
469
|
+
this.appendValueInput('QUESTION')
|
|
470
|
+
.appendField(Blockly.Translate('telegram_ask_question'));
|
|
471
|
+
|
|
472
|
+
const inputUser = this.appendValueInput('USERNAME')
|
|
473
|
+
.setCheck('String')
|
|
474
|
+
.appendField(Blockly.Translate('telegram_username'));
|
|
475
|
+
if (inputUser.connection) {
|
|
476
|
+
inputUser.connection._optional = true;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const inputChat = this.appendValueInput('CHATID')
|
|
480
|
+
.setCheck('String')
|
|
481
|
+
.appendField(Blockly.Translate('telegram_chatid'));
|
|
482
|
+
if (inputChat.connection) {
|
|
483
|
+
inputChat.connection._optional = true;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
this.appendDummyInput('LOG')
|
|
487
|
+
.appendField(Blockly.Translate('telegram_log'))
|
|
488
|
+
.appendField(new Blockly.FieldDropdown([
|
|
489
|
+
[Blockly.Translate('telegram_log_none'), ''],
|
|
490
|
+
[Blockly.Translate('telegram_log_debug'), 'debug'],
|
|
491
|
+
[Blockly.Translate('telegram_log_info'), 'log'],
|
|
492
|
+
[Blockly.Translate('telegram_log_warn'), 'warn'],
|
|
493
|
+
[Blockly.Translate('telegram_log_error'), 'error'],
|
|
494
|
+
]), 'LOG');
|
|
495
|
+
|
|
496
|
+
this.setInputsInline(false);
|
|
497
|
+
this.setPreviousStatement(true, null);
|
|
498
|
+
this.setNextStatement(true, null);
|
|
499
|
+
|
|
500
|
+
this.setColour(Blockly.Sendto.HUE);
|
|
501
|
+
this.setTooltip(Blockly.Translate('telegram_tooltip'));
|
|
502
|
+
this.setHelpUrl(Blockly.Translate('telegram_help'));
|
|
503
|
+
},
|
|
504
|
+
/**
|
|
505
|
+
* Create XML to represent number of text inputs.
|
|
506
|
+
* @return {!Element} XML storage element.
|
|
507
|
+
* @this Blockly.Block
|
|
508
|
+
*/
|
|
509
|
+
mutationToDom: function () {
|
|
510
|
+
const container = document.createElement('mutation');
|
|
511
|
+
|
|
512
|
+
for (let i = 0; i < this.answers_.length; i++) {
|
|
513
|
+
const parameter = document.createElement('answer');
|
|
514
|
+
parameter.setAttribute('id', 'ANSWER_' + i);
|
|
515
|
+
parameter.setAttribute('name', this.answers_[i]);
|
|
516
|
+
container.appendChild(parameter);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return container;
|
|
520
|
+
},
|
|
521
|
+
/**
|
|
522
|
+
* Parse XML to restore the text inputs.
|
|
523
|
+
* @param {!Element} xmlElement XML storage element.
|
|
524
|
+
* @this Blockly.Block
|
|
525
|
+
*/
|
|
526
|
+
domToMutation: function (xmlElement) {
|
|
527
|
+
this.answers_ = [];
|
|
528
|
+
|
|
529
|
+
for (let i = 0, childNode; (childNode = xmlElement.childNodes[i]); i++) {
|
|
530
|
+
if (childNode.nodeName.toLowerCase() === 'answer') {
|
|
531
|
+
this.answers_.push(childNode.getAttribute('name'));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
this.itemCount_ = this.answers_.length;
|
|
536
|
+
this.updateShape_();
|
|
537
|
+
},
|
|
538
|
+
/**
|
|
539
|
+
* Populate the mutator's dialog with this block's components.
|
|
540
|
+
* @param {!Blockly.Workspace} workspace Mutator's workspace.
|
|
541
|
+
* @return {!Blockly.Block} Root block in mutator.
|
|
542
|
+
* @this Blockly.Block
|
|
543
|
+
*/
|
|
544
|
+
decompose: function (workspace) {
|
|
545
|
+
const containerBlock = workspace.newBlock('telegram_ask_container');
|
|
546
|
+
containerBlock.initSvg();
|
|
547
|
+
|
|
548
|
+
let connection = containerBlock.getInput('STACK').connection;
|
|
549
|
+
for (let i = 0; i < this.itemCount_; i++) {
|
|
550
|
+
const itemBlock = workspace.newBlock('telegram_ask_mutator');
|
|
551
|
+
itemBlock.setFieldValue(this.answers_[i], 'ANSWER');
|
|
552
|
+
itemBlock.initSvg();
|
|
553
|
+
connection.connect(itemBlock.previousConnection);
|
|
554
|
+
connection = itemBlock.nextConnection;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return containerBlock;
|
|
558
|
+
},
|
|
559
|
+
/**
|
|
560
|
+
* Reconfigure this block based on the mutator dialog's components.
|
|
561
|
+
* @param {!Blockly.Block} containerBlock Root block in mutator.
|
|
562
|
+
* @this Blockly.Block
|
|
563
|
+
*/
|
|
564
|
+
compose: function (containerBlock) {
|
|
565
|
+
this.answers_ = [];
|
|
566
|
+
|
|
567
|
+
let itemBlock = containerBlock.getInputTargetBlock('STACK');
|
|
568
|
+
// Count number of inputs.
|
|
569
|
+
const connections = [];
|
|
570
|
+
while (itemBlock) {
|
|
571
|
+
const attrName = itemBlock.getFieldValue('ANSWER');
|
|
572
|
+
this.answers_.push(attrName);
|
|
573
|
+
|
|
574
|
+
connections.push(itemBlock.valueConnection_);
|
|
575
|
+
itemBlock = itemBlock.nextConnection &&
|
|
576
|
+
itemBlock.nextConnection.targetBlock();
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Disconnect any children that don't belong.
|
|
580
|
+
for (let k = 0; k < this.itemCount_; k++) {
|
|
581
|
+
const connection = this.getInput('ANSWER_' + k).connection.targetConnection;
|
|
582
|
+
if (connection && !connections.includes(connection)) {
|
|
583
|
+
connection.disconnect();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
this.itemCount_ = connections.length;
|
|
588
|
+
if (this.itemCount_ < 0) {
|
|
589
|
+
this.itemCount_ = 0;
|
|
590
|
+
}
|
|
591
|
+
this.updateShape_();
|
|
592
|
+
|
|
593
|
+
// Reconnect any child blocks.
|
|
594
|
+
for (let i = 0; i < this.itemCount_; i++) {
|
|
595
|
+
Blockly.icons.MutatorIcon.reconnect(connections[i], this, 'ANSWER_' + i);
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
/**
|
|
599
|
+
* Store pointers to any connected child blocks.
|
|
600
|
+
* @param {!Blockly.Block} containerBlock Root block in mutator.
|
|
601
|
+
* @this Blockly.Block
|
|
602
|
+
*/
|
|
603
|
+
saveConnections: function(containerBlock) {
|
|
604
|
+
let itemBlock = containerBlock.getInputTargetBlock('STACK');
|
|
605
|
+
let i = 0;
|
|
606
|
+
|
|
607
|
+
while (itemBlock) {
|
|
608
|
+
const input = this.getInput('ANSWER_' + i);
|
|
609
|
+
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
|
610
|
+
i++;
|
|
611
|
+
itemBlock = itemBlock.nextConnection &&
|
|
612
|
+
itemBlock.nextConnection.targetBlock();
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
/**
|
|
616
|
+
* Modify this block to have the correct number of inputs.
|
|
617
|
+
* @private
|
|
618
|
+
* @this Blockly.Block
|
|
619
|
+
*/
|
|
620
|
+
updateShape_: function() {
|
|
621
|
+
const workspace = this.workspace;
|
|
622
|
+
|
|
623
|
+
// Add new inputs.
|
|
624
|
+
for (let i = 0; i < this.itemCount_; i++) {
|
|
625
|
+
let input = this.getInput('ANSWER_' + i);
|
|
626
|
+
|
|
627
|
+
if (!input) {
|
|
628
|
+
input = this.appendValueInput('ANSWER_' + i).setAlign(Blockly.ALIGN_RIGHT);
|
|
629
|
+
input.appendField(this.answers_[i]);
|
|
630
|
+
} else {
|
|
631
|
+
input.fieldRow[0].setValue(this.answers_[i]);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
let statement = this.getInput('STATEMENT_' + i);
|
|
635
|
+
if (!statement) {
|
|
636
|
+
statement = this.appendStatementInput('STATEMENT_' + i);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
setTimeout(__input => {
|
|
640
|
+
if (!__input.connection.isConnected()) {
|
|
641
|
+
const _shadow = workspace.newBlock('text');
|
|
642
|
+
_shadow.setShadow(true);
|
|
643
|
+
_shadow.setFieldValue('text', 'TEXT');
|
|
644
|
+
_shadow.initSvg();
|
|
645
|
+
_shadow.render();
|
|
646
|
+
_shadow.outputConnection.connect(__input.connection);
|
|
647
|
+
}
|
|
648
|
+
}, 100, input);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Remove deleted inputs.
|
|
652
|
+
for (let i = this.itemCount_; this.getInput('ANSWER_' + i); i++) {
|
|
653
|
+
this.removeInput('ANSWER_' + i);
|
|
654
|
+
this.removeInput('STATEMENT_' + i);
|
|
655
|
+
}
|
|
656
|
+
},
|
|
382
657
|
};
|
|
383
658
|
|
|
659
|
+
Blockly.JavaScript.forBlock['telegram_ask'] = function(block) {
|
|
660
|
+
const answers = [];
|
|
661
|
+
for (let id = 0; id < block.itemCount_; id++) {
|
|
662
|
+
const answer = Blockly.JavaScript.valueToCode(block, 'ANSWER_' + id, Blockly.JavaScript.ORDER_ATOMIC);
|
|
663
|
+
const statement = Blockly.JavaScript.statementToCode(block, 'STATEMENT_' + id);
|
|
664
|
+
if (answer && statement) {
|
|
665
|
+
answers.push({ id, answer, statement });
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const dropdown_instance = block.getFieldValue('INSTANCE');
|
|
670
|
+
const logLevel = block.getFieldValue('LOG');
|
|
671
|
+
const value_question = Blockly.JavaScript.valueToCode(block, 'QUESTION', Blockly.JavaScript.ORDER_ATOMIC);
|
|
672
|
+
const value_username = Blockly.JavaScript.valueToCode(block, 'USERNAME', Blockly.JavaScript.ORDER_ATOMIC);
|
|
673
|
+
const value_chatid = Blockly.JavaScript.valueToCode(block, 'CHATID', Blockly.JavaScript.ORDER_ATOMIC);
|
|
674
|
+
|
|
675
|
+
let logText = '';
|
|
676
|
+
if (logLevel) {
|
|
677
|
+
const logUsername = value_username ? `[' + ${value_username} + ']` : '';
|
|
678
|
+
logText = `console.${logLevel}('telegramAsk${logUsername}: ' + ${value_question});\n`;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
let logAnswer = '';
|
|
682
|
+
if (logLevel) {
|
|
683
|
+
logAnswer = ` console.${logLevel}('telegramAsk answer: ' + (msg?.data ?? '[no answer]'));\n`;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
return `sendTo('telegram${dropdown_instance}', 'ask', {\n` +
|
|
687
|
+
` text: ${value_question},\n` +
|
|
688
|
+
(value_username ? ` user: ${value_username},\n` : '') +
|
|
689
|
+
(value_chatid ? ` chatId: ${value_chatid},\n` : '') +
|
|
690
|
+
` reply_markup: {\n` +
|
|
691
|
+
` inline_keyboard: [\n` +
|
|
692
|
+
answers.map(a => ` [ { text: ${a.answer}, callback_data: '${a.id}' } ],\n`).join('\n') +
|
|
693
|
+
` ],\n` +
|
|
694
|
+
` }\n` +
|
|
695
|
+
`}, msg => {\n${logAnswer}` +
|
|
696
|
+
answers.map(a => ` if (msg?.data && msg.data == '${a.id}') {\n${Blockly.JavaScript.prefixLines(a.statement, Blockly.JavaScript.INDENT)} }`).join('\n') +
|
|
697
|
+
`\n});\n${logText}`;
|
|
698
|
+
};
|