iobroker.telegram 1.12.3 → 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 CHANGED
@@ -706,6 +706,15 @@ 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
+
712
+ ### 1.12.5 (2022-04-19)
713
+ * (Apollon77) Fix crash cases reported by Sentry
714
+
715
+ ### 1.12.4 (2022-04-19)
716
+ * (Apollon77) Fix crash cases reported by Sentry
717
+
709
718
  ### 1.12.3 (2022-04-19)
710
719
  * (Apollon77) Make sure also not set states can be queried - will return "State not set" in this case!
711
720
 
package/io-package.json CHANGED
@@ -1,8 +1,44 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "telegram",
4
- "version": "1.12.3",
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
+ },
18
+ "1.12.5": {
19
+ "en": "Fix crash cases reported by Sentry",
20
+ "de": "Von Sentry gemeldete Absturzfälle beheben",
21
+ "ru": "Исправить случаи сбоев, о которых сообщил Sentry",
22
+ "pt": "Corrigir casos de travamento relatados pelo Sentinela",
23
+ "nl": "Herstel crashgevallen gemeld door Sentry",
24
+ "fr": "Correction des cas de plantage signalés par Sentry",
25
+ "it": "Risolvi i casi di crash segnalati da Sentry",
26
+ "es": "Solucionar casos de fallas informados por Sentry",
27
+ "pl": "Napraw przypadki awarii zgłoszone przez Sentry",
28
+ "zh-cn": "修复 Sentry 报告的崩溃案例"
29
+ },
30
+ "1.12.4": {
31
+ "en": "Fix crash cases reported by Sentry",
32
+ "de": "Von Sentry gemeldete Absturzfälle beheben",
33
+ "ru": "Исправить случаи сбоев, о которых сообщил Sentry",
34
+ "pt": "Corrigir casos de travamento relatados pelo Sentinela",
35
+ "nl": "Herstel crashgevallen gemeld door Sentry",
36
+ "fr": "Correction des cas de plantage signalés par Sentry",
37
+ "it": "Risolvi i casi di crash segnalati da Sentry",
38
+ "es": "Solucionar casos de fallas informados por Sentry",
39
+ "pl": "Napraw przypadki awarii zgłoszone przez Sentry",
40
+ "zh-cn": "修复 Sentry 报告的崩溃案例"
41
+ },
6
42
  "1.12.3": {
7
43
  "en": "Make sure also not set states can be queried - will return \"State not set\" in this case!",
8
44
  "de": "Stellen Sie sicher, dass auch nicht gesetzte Zustände abgefragt werden können - in diesem Fall wird \"Zustand nicht gesetzt\" zurückgegeben!",
@@ -50,42 +86,6 @@
50
86
  "es": "arregló los archivos de recepción",
51
87
  "pl": "naprawiono odbieranie plików",
52
88
  "zh-cn": "修复了接收文件"
53
- },
54
- "1.11.0": {
55
- "en": "Added bruteforce protection\nExtended blockly with `disable_web_preview` option\nadded `communicate.responseSilent` state to answer silently",
56
- "de": "Bruteforce-Schutz hinzugefügt\nBlockweise erweitert mit der Option `disable_web_preview`\n`communicate.responseSilent`-Zustand hinzugefügt, um still zu antworten",
57
- "ru": "Добавлена защита от брутфорса\nРасширен блочно с опцией `disable_web_preview`\nдобавлено состояние `communicate.responseSilent` для молчаливого ответа",
58
- "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",
59
- "nl": "Bruteforce-bescherming toegevoegd\nBlockly uitgebreid met de optie 'disable_web_preview'\nstatus `communicate.responseSilent` toegevoegd om stil te antwoorden",
60
- "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",
61
- "it": "Aggiunta protezione dalla forza bruta\nEsteso in blocco con l'opzione `disable_web_preview`\naggiunto lo stato `communicate.responseSilent` per rispondere in silenzio",
62
- "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.",
63
- "pl": "Dodano ochronę przed bruteforce\nRozszerzony blokowo z opcją `disable_web_preview`\ndodano stan `communicate.responseSilent` do cichej odpowiedzi",
64
- "zh-cn": "添加了蛮力保护\n使用 `disable_web_preview` 选项扩展块\n添加了`communicate.responseSilent`状态以静默回答"
65
- },
66
- "1.10.1": {
67
- "en": "Updated telegram library",
68
- "de": "Aktualisierte Telegrammbibliothek",
69
- "ru": "Обновлена библиотека телеграмм.",
70
- "pt": "Biblioteca de telegramas atualizada",
71
- "nl": "Bijgewerkte telegrambibliotheek",
72
- "fr": "Bibliothèque de télégrammes mise à jour",
73
- "it": "Libreria di telegrammi aggiornata",
74
- "es": "Biblioteca de telegramas actualizada",
75
- "pl": "Zaktualizowana biblioteka telegramów",
76
- "zh-cn": "更新的电报库"
77
- },
78
- "1.10.0": {
79
- "en": "Add botSendRaw state to allow processing of the RAW data send by bot\nAdd tier for js-controller 3.3\nFixed the control of the states",
80
- "de": "Fügen Sie den botSendRaw-Status hinzu, um die Verarbeitung der vom Bot gesendeten RAW-Daten zu ermöglichen\nStufe für js-controller 3.3 . hinzufügen\nDie Kontrolle der Zustände wurde behoben",
81
- "ru": "Добавьте состояние botSendRaw, чтобы разрешить обработку RAW-данных, отправленных ботом\nДобавить уровень для js-controller 3.3\nИсправлен контроль состояний",
82
- "pt": "Adicione o estado botSendRaw para permitir o processamento dos dados RAW enviados por bot\nAdicionar camada para js-controller 3.3\nCorrigido o controle dos estados",
83
- "nl": "Voeg botSendRaw-status toe om verwerking van de RAW-gegevens die door bot zijn verzonden toe te staan\nLaag toevoegen voor js-controller 3.3\nDe controle over de staten opgelost Fixed",
84
- "fr": "Ajouter l'état botSendRaw pour permettre le traitement des données RAW envoyées par le bot\nAjouter un niveau pour js-controller 3.3\nCorrection du contrôle des états",
85
- "it": "Aggiungi lo stato botSendRaw per consentire l'elaborazione dei dati RAW inviati dal bot\nAggiungi livello per js-controller 3.3\nRisolto il controllo degli stati",
86
- "es": "Agregue el estado botSendRaw para permitir el procesamiento de los datos RAW enviados por bot\nAgregar nivel para js-controller 3.3\nArreglado el control de los estados.",
87
- "pl": "Dodaj stan botSendRaw, aby umożliwić przetwarzanie danych RAW wysyłanych przez bota\nDodaj warstwę dla kontrolera js 3.3\nPoprawiono kontrolę stanów",
88
- "zh-cn": "添加 botSendRaw 状态以允许处理 bot 发送的 RAW 数据\n为 js-controller 3.3 添加层\n修复了对状态的控制"
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();
@@ -224,7 +217,7 @@ function startAdapter(options) {
224
217
  `You can call in shell following scrip to allow it for node.js: "iobroker fix"`
225
218
  );
226
219
  } else {
227
- adapter.log.error(`Cannot start server on ${settings.bind || '0.0.0.0'}:${serverPort}: ${e}`);
220
+ adapter.log.error(`Cannot start server on ${adapter.config.bind || '0.0.0.0'}:${serverPort}: ${e}`);
228
221
  }
229
222
  if (!serverListening) {
230
223
  adapter.terminate ? adapter.terminate(utils.EXIT_CODES.ADAPTER_REQUESTED_TERMINATION) : process.exit(utils.EXIT_CODES.ADAPTER_REQUESTED_TERMINATION);
@@ -294,7 +287,7 @@ function startAdapter(options) {
294
287
  if (!state.ack) {
295
288
  if (id.endsWith('communicate.response')) {
296
289
  if (typeof state.val === 'object') {
297
- adapter.log.error(`communicate.response only supports passing a message to send as string. You provided ${JSON.stringofy(state.val)}. Please use "communicate.responseJson" instead with a stringified JSON object!`);
290
+ adapter.log.error(`communicate.response only supports passing a message to send as string. You provided ${JSON.stringify(state.val)}. Please use "communicate.responseJson" instead with a stringified JSON object!`);
298
291
  return;
299
292
  }
300
293
  // Send to someone this message
@@ -303,7 +296,7 @@ function startAdapter(options) {
303
296
  } else
304
297
  if (id.endsWith('communicate.responseSilent')) {
305
298
  if (typeof state.val === 'object') {
306
- adapter.log.error(`communicate.responseSilent only supports passing a message to send as string. You provided ${JSON.stringofy(state.val)}. Please use "communicate.responseSilentJson" instead with a stringified JSON object!`);
299
+ adapter.log.error(`communicate.responseSilent only supports passing a message to send as string. You provided ${JSON.stringify(state.val)}. Please use "communicate.responseSilentJson" instead with a stringified JSON object!`);
307
300
  return;
308
301
  }
309
302
  // Send to someone this message
@@ -369,7 +362,12 @@ function startAdapter(options) {
369
362
 
370
363
  server.settings = adapter.config;
371
364
 
372
- tmpDirName = tmpDir + '/' + adapter.namespace.replace('.', '_');
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(tmpDirName + fileName, Buffer.concat(buf));
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! : ' + tmpDirName + fileName,
1105
- path: tmpDirName + fileName
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
- !fs.existsSync(tmpDirName + '/voice') && fs.mkdirSync(tmpDirName + '/voice');
1127
- saveFile(msg.voice.file_id, adapter.config.saveFiles ? `/voice/${date}.ogg` : '/voice/temp.ogg', res => {
1128
- if (!res.error) {
1129
- adapter.log.info(res.info);
1130
- adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
1131
- } else {
1132
- adapter.log.debug(res.error);
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
- mediaGroupExport[msg.media_group_id].count++;
1131
+ adapter.log.debug(res.error);
1160
1132
  }
1161
- fileName = `/photo/${date}_grpID_${mediaGroupExport[msg.media_group_id].id}_${mediaGroupExport[msg.media_group_id].count}_${quality}.jpg`;
1162
- } else {
1163
- fileName = `/photo/${date}_${quality}.jpg`;
1164
- if (fs.existsSync(tmpDirName + fileName)) {
1165
- let tIdx = 0;
1166
- do {
1167
- fileName = `/photo/${date}_${tIdx}_${quality}.jpg`;
1168
- tIdx++;
1169
- } while (fs.existsSync(tmpDirName + fileName));
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
- saveFile(item.file_id, fileName, res => {
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
- } else if (adapter.config.saveFiles && msg.video) {
1183
- !fs.existsSync(tmpDirName + '/video') && fs.mkdirSync(tmpDirName + '/video');
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
- !fs.existsSync(tmpDirName + '/audio') && fs.mkdirSync(tmpDirName + '/audio');
1194
- saveFile(msg.audio.file_id, `/audio/${date}.mp3`, res => {
1195
- if (!res.error) {
1196
- adapter.log.info(res.info);
1197
- adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
1198
- } else {
1199
- adapter.log.debug(res.error);
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
- !fs.existsSync(tmpDirName + '/document') && fs.mkdirSync(tmpDirName + '/document');
1204
- saveFile(msg.document.file_id, '/document/' + msg.document.file_name, res => {
1205
- if (!res.error) {
1206
- adapter.log.info(res.info);
1207
- adapter.setState('communicate.pathFile', res.path, true, err => err && adapter.log.error(err));
1208
- } else {
1209
- adapter.log.debug(res.error);
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.3",
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": {