iobroker.telegram 1.12.5 → 1.12.6
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 +3 -0
- package/io-package.json +13 -13
- package/main.js +112 -88
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -706,6 +706,9 @@ Before sending it to `telegram.INSTANCE.communicate.responseJson you need to str
|
|
|
706
706
|
-->
|
|
707
707
|
|
|
708
708
|
## Changelog
|
|
709
|
+
### 1.12.6 (2022-04-23)
|
|
710
|
+
* (Apollon77) Fix crash cases reported by Sentry
|
|
711
|
+
|
|
709
712
|
### 1.12.5 (2022-04-19)
|
|
710
713
|
* (Apollon77) Fix crash cases reported by Sentry
|
|
711
714
|
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "telegram",
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.6",
|
|
5
5
|
"news": {
|
|
6
|
+
"1.12.6": {
|
|
7
|
+
"en": "Fix crash cases reported by Sentry",
|
|
8
|
+
"de": "Von Sentry gemeldete Absturzfälle beheben",
|
|
9
|
+
"ru": "Исправить случаи сбоев, о которых сообщил Sentry",
|
|
10
|
+
"pt": "Corrigir casos de travamento relatados pelo Sentinela",
|
|
11
|
+
"nl": "Herstel crashgevallen gemeld door Sentry",
|
|
12
|
+
"fr": "Correction des cas de plantage signalés par Sentry",
|
|
13
|
+
"it": "Risolvi i casi di crash segnalati da Sentry",
|
|
14
|
+
"es": "Solucionar casos de fallas informados por Sentry",
|
|
15
|
+
"pl": "Napraw przypadki awarii zgłoszone przez Sentry",
|
|
16
|
+
"zh-cn": "修复 Sentry 报告的崩溃案例"
|
|
17
|
+
},
|
|
6
18
|
"1.12.5": {
|
|
7
19
|
"en": "Fix crash cases reported by Sentry",
|
|
8
20
|
"de": "Von Sentry gemeldete Absturzfälle beheben",
|
|
@@ -74,18 +86,6 @@
|
|
|
74
86
|
"es": "arregló los archivos de recepción",
|
|
75
87
|
"pl": "naprawiono odbieranie plików",
|
|
76
88
|
"zh-cn": "修复了接收文件"
|
|
77
|
-
},
|
|
78
|
-
"1.11.0": {
|
|
79
|
-
"en": "Added bruteforce protection\nExtended blockly with `disable_web_preview` option\nadded `communicate.responseSilent` state to answer silently",
|
|
80
|
-
"de": "Bruteforce-Schutz hinzugefügt\nBlockweise erweitert mit der Option `disable_web_preview`\n`communicate.responseSilent`-Zustand hinzugefügt, um still zu antworten",
|
|
81
|
-
"ru": "Добавлена защита от брутфорса\nРасширен блочно с опцией `disable_web_preview`\nдобавлено состояние `communicate.responseSilent` для молчаливого ответа",
|
|
82
|
-
"pt": "Proteção de força bruta adicionada\nEstendido em bloco com a opção `disable_web_preview`\nadicionado o estado `communicate.responseSilent` para responder silenciosamente",
|
|
83
|
-
"nl": "Bruteforce-bescherming toegevoegd\nBlockly uitgebreid met de optie 'disable_web_preview'\nstatus `communicate.responseSilent` toegevoegd om stil te antwoorden",
|
|
84
|
-
"fr": "Protection contre la force brute ajoutée\nÉtendu en bloc avec l'option `disable_web_preview`\najout de l'état `communicate.responseSilent` pour répondre en silence",
|
|
85
|
-
"it": "Aggiunta protezione dalla forza bruta\nEsteso in blocco con l'opzione `disable_web_preview`\naggiunto lo stato `communicate.responseSilent` per rispondere in silenzio",
|
|
86
|
-
"es": "Protección de fuerza bruta agregada\nExtendido en bloques con la opción `disable_web_preview`\nSe agregó el estado `communicate.responseSilent` para responder en silencio.",
|
|
87
|
-
"pl": "Dodano ochronę przed bruteforce\nRozszerzony blokowo z opcją `disable_web_preview`\ndodano stan `communicate.responseSilent` do cichej odpowiedzi",
|
|
88
|
-
"zh-cn": "添加了蛮力保护\n使用 `disable_web_preview` 选项扩展块\n添加了`communicate.responseSilent`状态以静默回答"
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"title": "Telegram",
|
package/main.js
CHANGED
|
@@ -21,8 +21,8 @@ const utils = require('@iobroker/adapter-core'); // Get common adapter uti
|
|
|
21
21
|
const adapterName = require('./package.json').name.split('.').pop();
|
|
22
22
|
const _ = require('./lib/words.js');
|
|
23
23
|
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
24
25
|
const LE = require(utils.controllerDir + '/lib/letsencrypt.js');
|
|
25
|
-
const tools = require(utils.controllerDir + '/lib/tools');
|
|
26
26
|
const https = require('https');
|
|
27
27
|
const axios = require("axios");
|
|
28
28
|
|
|
@@ -44,11 +44,6 @@ let gcInterval = null;
|
|
|
44
44
|
|
|
45
45
|
const commands = {};
|
|
46
46
|
const callbackQueryId = {};
|
|
47
|
-
const configFile = tools.getConfigFileName();
|
|
48
|
-
const tmp = configFile.split(/[\\\/]+/);
|
|
49
|
-
tmp.pop();
|
|
50
|
-
tmp.pop();
|
|
51
|
-
const tmpDir = tmp.join('/') + '/iobroker-data/tmp';
|
|
52
47
|
const mediaGroupExport = {};
|
|
53
48
|
let tmpDirName;
|
|
54
49
|
|
|
@@ -180,8 +175,6 @@ function startAdapter(options) {
|
|
|
180
175
|
adapter.on('ready', () => {
|
|
181
176
|
adapter.config.server = adapter.config.server === 'true';
|
|
182
177
|
|
|
183
|
-
!fs.existsSync(tmpDir) && fs.mkdirSync(tmpDir);
|
|
184
|
-
|
|
185
178
|
adapter._questions = [];
|
|
186
179
|
adapter.garbageCollectorinterval = setInterval(() => {
|
|
187
180
|
const now = Date.now();
|
|
@@ -369,7 +362,12 @@ function startAdapter(options) {
|
|
|
369
362
|
|
|
370
363
|
server.settings = adapter.config;
|
|
371
364
|
|
|
372
|
-
tmpDirName =
|
|
365
|
+
tmpDirName = path.join(utils.getAbsoluteDefaultDataDir(), adapter.namespace.replace('.', '_'));
|
|
366
|
+
try {
|
|
367
|
+
!fs.existsSync(tmpDirName) && fs.mkdirSync(tmpDirName);
|
|
368
|
+
} catch (e) {
|
|
369
|
+
adapter.log.error('Cannot create tmp directory: ' + tmpDirName);
|
|
370
|
+
}
|
|
373
371
|
|
|
374
372
|
return adapter;
|
|
375
373
|
}
|
|
@@ -1094,15 +1092,16 @@ function saveFile(fileID, fileName, callback) {
|
|
|
1094
1092
|
const buf = [];
|
|
1095
1093
|
res.on('data', data => buf.push(data));
|
|
1096
1094
|
res.on('end', () => {
|
|
1095
|
+
const fileLocation = path.join(tmpDirName, fileName);
|
|
1097
1096
|
try {
|
|
1098
|
-
fs.writeFileSync(
|
|
1097
|
+
fs.writeFileSync(fileLocation, Buffer.concat(buf));
|
|
1099
1098
|
} catch (err) {
|
|
1100
1099
|
return callback({error: 'Error: ' + err});
|
|
1101
1100
|
}
|
|
1102
1101
|
|
|
1103
1102
|
callback({
|
|
1104
|
-
info: 'It\'s saved! : ' +
|
|
1105
|
-
path:
|
|
1103
|
+
info: 'It\'s saved! : ' + fileLocation,
|
|
1104
|
+
path: fileLocation
|
|
1106
1105
|
});
|
|
1107
1106
|
});
|
|
1108
1107
|
|
|
@@ -1120,57 +1119,78 @@ function getMessage(msg) {
|
|
|
1120
1119
|
const date = new Date().toISOString().replace(/T/, '_').replace(/\..+/, '').replace(/:/g, '-');
|
|
1121
1120
|
adapter.log.debug('Received message: ' + JSON.stringify(msg));
|
|
1122
1121
|
|
|
1123
|
-
!fs.existsSync(tmpDirName) && fs.mkdirSync(tmpDirName);
|
|
1124
|
-
|
|
1125
1122
|
if (msg.voice) {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
}
|
|
1134
|
-
})
|
|
1135
|
-
} else if (adapter.config.saveFiles && msg.photo) {
|
|
1136
|
-
!fs.existsSync(tmpDirName + '/photo') && fs.mkdirSync(tmpDirName + '/photo');
|
|
1137
|
-
|
|
1138
|
-
const qualityMap = {
|
|
1139
|
-
0: 'low',
|
|
1140
|
-
1: 'med',
|
|
1141
|
-
2: 'high',
|
|
1142
|
-
3: 'highdef'
|
|
1143
|
-
};
|
|
1144
|
-
|
|
1145
|
-
msg.photo.forEach((item, i) => {
|
|
1146
|
-
let quality = 'none';
|
|
1147
|
-
if (qualityMap.hasOwnProperty(i)) {
|
|
1148
|
-
quality = qualityMap[i];
|
|
1149
|
-
}
|
|
1150
|
-
let fileName = '';
|
|
1151
|
-
if (msg.media_group_id) {
|
|
1152
|
-
if (!mediaGroupExport.hasOwnProperty(msg.media_group_id)) {
|
|
1153
|
-
const id = Object.keys(mediaGroupExport).length;
|
|
1154
|
-
mediaGroupExport[msg.media_group_id] = {
|
|
1155
|
-
id,
|
|
1156
|
-
count: 0
|
|
1157
|
-
};
|
|
1123
|
+
try {
|
|
1124
|
+
const voiceFile = path.join(tmpDirName, 'voice');
|
|
1125
|
+
!fs.existsSync(voiceFile) && fs.mkdirSync(voiceFile);
|
|
1126
|
+
saveFile(msg.voice.file_id, adapter.config.saveFiles ? `/voice/${date}.ogg` : '/voice/temp.ogg', res => {
|
|
1127
|
+
if (!res.error) {
|
|
1128
|
+
adapter.log.info(res.info);
|
|
1129
|
+
adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
|
|
1158
1130
|
} else {
|
|
1159
|
-
|
|
1131
|
+
adapter.log.debug(res.error);
|
|
1160
1132
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1133
|
+
})
|
|
1134
|
+
} catch (err) {
|
|
1135
|
+
adapter.log.error('Error saving voice file: ' + err);
|
|
1136
|
+
}
|
|
1137
|
+
} else if (adapter.config.saveFiles && msg.photo) {
|
|
1138
|
+
try {
|
|
1139
|
+
const photoFile = path.join(tmpDirName, 'photo');
|
|
1140
|
+
!fs.existsSync(photoFile) && fs.mkdirSync(photoFile);
|
|
1141
|
+
|
|
1142
|
+
const qualityMap = {
|
|
1143
|
+
0: 'low',
|
|
1144
|
+
1: 'med',
|
|
1145
|
+
2: 'high',
|
|
1146
|
+
3: 'highdef'
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
msg.photo.forEach((item, i) => {
|
|
1150
|
+
let quality = 'none';
|
|
1151
|
+
if (qualityMap.hasOwnProperty(i)) {
|
|
1152
|
+
quality = qualityMap[i];
|
|
1153
|
+
}
|
|
1154
|
+
let fileName = '';
|
|
1155
|
+
if (msg.media_group_id) {
|
|
1156
|
+
if (!mediaGroupExport.hasOwnProperty(msg.media_group_id)) {
|
|
1157
|
+
const id = Object.keys(mediaGroupExport).length;
|
|
1158
|
+
mediaGroupExport[msg.media_group_id] = {
|
|
1159
|
+
id,
|
|
1160
|
+
count: 0
|
|
1161
|
+
};
|
|
1162
|
+
} else {
|
|
1163
|
+
mediaGroupExport[msg.media_group_id].count++;
|
|
1164
|
+
}
|
|
1165
|
+
fileName = `/photo/${date}_grpID_${mediaGroupExport[msg.media_group_id].id}_${mediaGroupExport[msg.media_group_id].count}_${quality}.jpg`;
|
|
1166
|
+
} else {
|
|
1167
|
+
fileName = `/photo/${date}_${quality}.jpg`;
|
|
1168
|
+
if (fs.existsSync(path.join(tmpDirName, fileName))) {
|
|
1169
|
+
let tIdx = 0;
|
|
1170
|
+
do {
|
|
1171
|
+
fileName = `/photo/${date}_${tIdx}_${quality}.jpg`;
|
|
1172
|
+
tIdx++;
|
|
1173
|
+
} while (fs.existsSync(path.join(tmpDirName, fileName)));
|
|
1174
|
+
}
|
|
1170
1175
|
}
|
|
1171
|
-
}
|
|
1172
1176
|
|
|
1173
|
-
|
|
1177
|
+
saveFile(item.file_id, fileName, res => {
|
|
1178
|
+
if (!res.error) {
|
|
1179
|
+
adapter.log.info(res.info);
|
|
1180
|
+
adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
|
|
1181
|
+
} else {
|
|
1182
|
+
adapter.log.debug(res.error);
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
});
|
|
1186
|
+
} catch (err) {
|
|
1187
|
+
adapter.log.error('Error saving photo file: ' + err);
|
|
1188
|
+
}
|
|
1189
|
+
} else if (adapter.config.saveFiles && msg.video) {
|
|
1190
|
+
try {
|
|
1191
|
+
const videoFile = path.join(tmpDirName, 'video');
|
|
1192
|
+
!fs.existsSync(videoFile) && fs.mkdirSync(videoFile);
|
|
1193
|
+
saveFile(msg.video.file_id, `/video/${date}.mp4`, res => {
|
|
1174
1194
|
if (!res.error) {
|
|
1175
1195
|
adapter.log.info(res.info);
|
|
1176
1196
|
adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
|
|
@@ -1178,37 +1198,39 @@ function getMessage(msg) {
|
|
|
1178
1198
|
adapter.log.debug(res.error);
|
|
1179
1199
|
}
|
|
1180
1200
|
});
|
|
1181
|
-
})
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
saveFile(msg.video.file_id, `/video/${date}.mp4`, res => {
|
|
1185
|
-
if (!res.error) {
|
|
1186
|
-
adapter.log.info(res.info);
|
|
1187
|
-
adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
|
|
1188
|
-
} else {
|
|
1189
|
-
adapter.log.debug(res.error);
|
|
1190
|
-
}
|
|
1191
|
-
});
|
|
1201
|
+
} catch (err) {
|
|
1202
|
+
adapter.log.error('Error saving video file: ' + err);
|
|
1203
|
+
}
|
|
1192
1204
|
} else if (adapter.config.saveFiles && msg.audio) {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1205
|
+
try {
|
|
1206
|
+
const audioFile = path.join(tmpDirName, 'audio');
|
|
1207
|
+
!fs.existsSync(audioFile) && fs.mkdirSync(audioFile);
|
|
1208
|
+
saveFile(msg.audio.file_id, `/audio/${date}.mp3`, res => {
|
|
1209
|
+
if (!res.error) {
|
|
1210
|
+
adapter.log.info(res.info);
|
|
1211
|
+
adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
|
|
1212
|
+
} else {
|
|
1213
|
+
adapter.log.debug(res.error);
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
} catch (err) {
|
|
1217
|
+
adapter.log.error('Error saving audio file: ' + err);
|
|
1218
|
+
}
|
|
1202
1219
|
} else if (adapter.config.saveFiles && msg.document) {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1220
|
+
try {
|
|
1221
|
+
const documentFile = path.join(tmpDirName, 'document');
|
|
1222
|
+
!fs.existsSync(documentFile) && fs.mkdirSync(documentFile);
|
|
1223
|
+
saveFile(msg.document.file_id, '/document/' + msg.document.file_name, res => {
|
|
1224
|
+
if (!res.error) {
|
|
1225
|
+
adapter.log.info(res.info);
|
|
1226
|
+
adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
|
|
1227
|
+
} else {
|
|
1228
|
+
adapter.log.debug(res.error);
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
} catch (err) {
|
|
1232
|
+
adapter.log.error('Error saving document file: ' + err);
|
|
1233
|
+
}
|
|
1212
1234
|
}
|
|
1213
1235
|
}
|
|
1214
1236
|
|
|
@@ -1931,7 +1953,9 @@ function connect() {
|
|
|
1931
1953
|
}
|
|
1932
1954
|
adapter.log.debug(`Start polling with: ${pollingOptions.polling.interval}(${typeof pollingOptions.polling.interval}) ms interval`);
|
|
1933
1955
|
bot = new TelegramBot(adapter.config.token, pollingOptions);
|
|
1934
|
-
bot.setWebHook('')
|
|
1956
|
+
bot.setWebHook('').catch(error => {
|
|
1957
|
+
adapter.log.error('setWebHook Error:' + error)
|
|
1958
|
+
});
|
|
1935
1959
|
}
|
|
1936
1960
|
|
|
1937
1961
|
// Check connection
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.telegram",
|
|
3
3
|
"description": "The adapter allows to send and receive telegram messages from ioBroker and to be a broker.",
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.6",
|
|
5
5
|
"author": "bluefox <dogafox@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/iobroker-community-adapters/ioBroker.telegram",
|
|
7
7
|
"repository": {
|