iobroker.telegram 6.2.0 → 6.3.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 +6 -12
- package/admin/i18n/de.json +2 -0
- package/admin/i18n/en.json +2 -0
- package/admin/i18n/es.json +2 -0
- package/admin/i18n/fr.json +2 -0
- package/admin/i18n/it.json +2 -0
- package/admin/i18n/nl.json +2 -0
- package/admin/i18n/pl.json +2 -0
- package/admin/i18n/pt.json +2 -0
- package/admin/i18n/ru.json +2 -0
- package/admin/i18n/uk.json +2 -0
- package/admin/i18n/zh-cn.json +2 -0
- package/admin/jsonConfig.json +14 -0
- package/admin/rules/@mf-types.zip +0 -0
- package/build/main.js +169 -14
- package/build/main.js.map +1 -1
- package/build/types.d.ts +2 -0
- package/io-package.json +28 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,12 @@ Use telegram service to communicate with ioBroker
|
|
|
40
40
|
Placeholder for the next version (at the beginning of the line):
|
|
41
41
|
### **WORK IN PROGRESS**
|
|
42
42
|
-->
|
|
43
|
+
### 6.3.0 (2026-11-07)
|
|
44
|
+
- (@GermanBluefox) Added "Delete received files after (days)": saved voice messages, photos, videos, audio files and documents older than that are deleted, in the file system or in the file storage, checked every hour. 0 (default) keeps them as before
|
|
45
|
+
|
|
46
|
+
### 6.2.1 (2026-11-07)
|
|
47
|
+
- (@GermanBluefox) Videos for the `assistant` instance are stored in the data directory of the instance (`iobroker-data/telegram_0/assistant`, the newest 20) and go along as `iobdisk://` URL, which the assistant reads from any host (js-controller 8.0+). With an older js-controller they still go to the file storage
|
|
48
|
+
|
|
43
49
|
### 6.2.0 (2026-11-04)
|
|
44
50
|
- (@GermanBluefox) Questions to the `assistant` instance (text and voice) wait at most 2 minutes for the answer; after that the user gets "The assistant did not answer in time." instead of no reply at all (e.g. when the assistant restarted meanwhile)
|
|
45
51
|
- (@GermanBluefox) Photos and videos are forwarded to the `assistant` instance too: photos (an album as one question, at most 4) with their caption as the question, videos are stored in the file storage of the instance (folder `assistant`, the newest 20) and only their place goes along. Can be switched off with "Photos and videos to the assistant"
|
|
@@ -55,18 +61,6 @@ Use telegram service to communicate with ioBroker
|
|
|
55
61
|
- (@GermanBluefox) Updated packages and improved the rules block
|
|
56
62
|
- (@patricknitsch) Retried getUpdates 409 conflicts quickly before falling back to a slow restartart
|
|
57
63
|
|
|
58
|
-
### 6.0.0 (2026-09-02)
|
|
59
|
-
- (@GermanBluefox) Adapter requires Node.js >= 22.19 now (required by undici 8)
|
|
60
|
-
- (@GermanBluefox) The connection to the telegram servers can be routed through an HTTP(S) or SOCKS5 proxy (new "Use proxy" settings; the old proxy fields had been without function for years)
|
|
61
|
-
- (@GermanBluefox) Migrated to `node-telegram-bot-api` v2. Updates are now received via long polling, so the "Polling interval" setting became obsolete and was removed from the configuration dialog. Errors thrown while processing an update are logged by the adapter instead of ending up on the console
|
|
62
|
-
- (@GermanBluefox) An empty "API URL" field no longer breaks every API call with "EFATAL: Failed to parse URL" - the default `https://api.telegram.org` is used again (#1371)
|
|
63
|
-
- (@GermanBluefox) A `text2command`/`assistant` instance stored in the long form (`system.adapter.text2command.0`, written by the config UI before v1.12.6) is migrated to the short form on startup, so the config dialog shows the selected instance again (#1365)
|
|
64
|
-
- (@GermanBluefox) Added the states `communicate.requestLocationLive` (live location is still being shared), `communicate.requestLocationHeading` and `communicate.requestLocationAccuracy` for received (live) locations
|
|
65
|
-
|
|
66
|
-
### 5.0.4 (2026-09-01)
|
|
67
|
-
- (@GermanBluefox) Blockly migrated to TypeScript
|
|
68
|
-
- (@bjoernjaeschke87-beep) Live location updates (delivered by Telegram as `edited_message`) now update `communicate.requestLocation` while the location is being shared
|
|
69
|
-
|
|
70
64
|
[Older changelogs can be found there](CHANGELOG_OLD.md)
|
|
71
65
|
|
|
72
66
|
## License
|
package/admin/i18n/de.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = behalten. Wird stündlich geprüft",
|
|
2
3
|
"API URL": "API-URL",
|
|
3
4
|
"All received files": "Alle empfangenen Dateien",
|
|
4
5
|
"Allow state control": "Erlaube Zustandssteuerung",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Verkettetes Zertifikat",
|
|
12
13
|
"Changed_Password": "Sie haben das Passwort für Ihren Bot geändert. Möchten Sie alle gespeicherten Benutzer jetzt löschen? Jeder Benutzer muss sich dann mit dem neuen Passwort erneut authentifizieren, bevor er erneut mit dem Bot kommunizieren kann.",
|
|
13
14
|
"Command to show the keyboard": "Befehl zum Anzeigen der Tastatur",
|
|
15
|
+
"Delete received files after (days)": "Empfangene Dateien löschen nach (Tagen)",
|
|
14
16
|
"Do not accept new users": "Neue Benutzer nicht akzeptieren",
|
|
15
17
|
"Done": "Fertig",
|
|
16
18
|
"File system": "Dateisystem",
|
package/admin/i18n/en.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = keep them. Checked every hour",
|
|
2
3
|
"API URL": "API URL",
|
|
3
4
|
"All received files": "All received files",
|
|
4
5
|
"Allow state control": "Allow state control",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Chained certificate",
|
|
12
13
|
"Changed_Password": "You have changed the password for your Bot. Do you want to delete all saved users now? Every user would have to authenticate again with the new password before they can communicate with the bot again.",
|
|
13
14
|
"Command to show the keyboard": "Command to show the keyboard",
|
|
15
|
+
"Delete received files after (days)": "Delete received files after (days)",
|
|
14
16
|
"Do not accept new users": "Do not accept new users",
|
|
15
17
|
"Done": "Done",
|
|
16
18
|
"File system": "File system",
|
package/admin/i18n/es.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = conservarlos. Se comprueba cada hora",
|
|
2
3
|
"API URL": "URL de API",
|
|
3
4
|
"All received files": "Todos los archivos recibidos",
|
|
4
5
|
"Allow state control": "Permitir el control del estado",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Certificado encadenado",
|
|
12
13
|
"Changed_Password": "Has cambiado la contraseña de tu Bot. ¿Desea eliminar todos los usuarios guardados ahora? Luego, cada usuario debe volver a autenticarse con la nueva contraseña antes de poder comunicarse con el bot nuevamente.",
|
|
13
14
|
"Command to show the keyboard": "Comando para mostrar el teclado",
|
|
15
|
+
"Delete received files after (days)": "Eliminar los archivos recibidos después de (días)",
|
|
14
16
|
"Do not accept new users": "No acepte nuevos usuarios.",
|
|
15
17
|
"Done": "Hecho",
|
|
16
18
|
"File system": "Sistema de archivos",
|
package/admin/i18n/fr.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = les conserver. Vérifié toutes les heures",
|
|
2
3
|
"API URL": "URL de l'API",
|
|
3
4
|
"All received files": "Tous les fichiers reçus",
|
|
4
5
|
"Allow state control": "Autoriser le contrôle de l'Etat",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Certificat chaîné",
|
|
12
13
|
"Changed_Password": "Vous avez changé le mot de passe de votre bot. Voulez-vous supprimer tous les utilisateurs enregistrés maintenant? Chaque utilisateur doit alors s'authentifier de nouveau avec le nouveau mot de passe avant de pouvoir communiquer à nouveau avec le bot.",
|
|
13
14
|
"Command to show the keyboard": "Commande pour afficher le clavier",
|
|
15
|
+
"Delete received files after (days)": "Supprimer les fichiers reçus après (jours)",
|
|
14
16
|
"Do not accept new users": "N'acceptez pas de nouveaux utilisateurs",
|
|
15
17
|
"Done": "Terminé",
|
|
16
18
|
"File system": "Système de fichiers",
|
package/admin/i18n/it.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = conservarli. Controllato ogni ora",
|
|
2
3
|
"API URL": "URL API",
|
|
3
4
|
"All received files": "Tutti i file ricevuti",
|
|
4
5
|
"Allow state control": "Consenti il controllo dello stato",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Certificato incatenato",
|
|
12
13
|
"Changed_Password": "Hai cambiato la password per il tuo Bot. Vuoi cancellare tutti gli utenti salvati ora? Ogni utente deve quindi eseguire nuovamente l'autenticazione con la nuova password prima di poter comunicare nuovamente con il bot.",
|
|
13
14
|
"Command to show the keyboard": "Comando per mostrare la tastiera",
|
|
15
|
+
"Delete received files after (days)": "Elimina i file ricevuti dopo (giorni)",
|
|
14
16
|
"Do not accept new users": "Non accettare nuovi utenti",
|
|
15
17
|
"Done": "Fatto",
|
|
16
18
|
"File system": "File system",
|
package/admin/i18n/nl.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = bewaren. Elk uur gecontroleerd",
|
|
2
3
|
"API URL": "API-URL",
|
|
3
4
|
"All received files": "Alle ontvangen bestanden",
|
|
4
5
|
"Allow state control": "Staatscontrole toestaan",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Geketend certificaat",
|
|
12
13
|
"Changed_Password": "U hebt het wachtwoord voor uw Bot gewijzigd. Wilt u alle opgeslagen gebruikers nu verwijderen? Elke gebruiker moet vervolgens opnieuw verifiëren met het nieuwe wachtwoord voordat deze weer met de bot kan communiceren.",
|
|
13
14
|
"Command to show the keyboard": "Commando om het toetsenbord te tonen",
|
|
15
|
+
"Delete received files after (days)": "Ontvangen bestanden verwijderen na (dagen)",
|
|
14
16
|
"Do not accept new users": "Accepteer geen nieuwe gebruikers.",
|
|
15
17
|
"Done": "Gedaan",
|
|
16
18
|
"File system": "Bestandssysteem",
|
package/admin/i18n/pl.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = zachowaj je. Sprawdzane co godzinę",
|
|
2
3
|
"API URL": "Adres URL API",
|
|
3
4
|
"All received files": "Wszystkie odebrane pliki",
|
|
4
5
|
"Allow state control": "Zezwalaj na kontrolę stanu",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Przykuty certyfikat",
|
|
12
13
|
"Changed_Password": "Zmieniłeś hasło do swojego Bot. Czy chcesz teraz usunąć wszystkich zapisanych użytkowników? Każdy użytkownik musi ponownie uwierzytelnić się przy użyciu nowego hasła, zanim będzie mógł ponownie komunikować się z botem.",
|
|
13
14
|
"Command to show the keyboard": "Polecenie, aby wyświetlić klawiaturę",
|
|
15
|
+
"Delete received files after (days)": "Usuń odebrane pliki po (dniach)",
|
|
14
16
|
"Do not accept new users": "Nie akceptuj nowych użytkowników",
|
|
15
17
|
"Done": "Gotowe",
|
|
16
18
|
"File system": "System plików",
|
package/admin/i18n/pt.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = mantê-los. Verificado a cada hora",
|
|
2
3
|
"API URL": "URL da API",
|
|
3
4
|
"All received files": "Todos os arquivos recebidos",
|
|
4
5
|
"Allow state control": "Permitir controle de estado",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Certificado encadeado",
|
|
12
13
|
"Changed_Password": "Você alterou a senha do seu bot. Você deseja excluir todos os usuários salvos agora? Cada usuário terá então que se reautenticar com a nova senha antes de poder se comunicar com o bot novamente.",
|
|
13
14
|
"Command to show the keyboard": "Comando para mostrar o teclado",
|
|
15
|
+
"Delete received files after (days)": "Excluir arquivos recebidos após (dias)",
|
|
14
16
|
"Do not accept new users": "Não aceitar novos usuários",
|
|
15
17
|
"Done": "Pronto",
|
|
16
18
|
"File system": "Sistema de arquivos",
|
package/admin/i18n/ru.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = не удалять. Проверяется каждый час",
|
|
2
3
|
"API URL": "URL API",
|
|
3
4
|
"All received files": "Все полученные файлы",
|
|
4
5
|
"Allow state control": "Разрешить контроль состояния",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "'Chained' сертификат",
|
|
12
13
|
"Changed_Password": "Вы изменили пароль для своего Бота. Вы хотите удалить всех сохраненных пользователей сейчас? Затем каждый пользователь должен повторно аутентифицироваться с новым паролем, прежде чем они смогут снова связаться с ботом.",
|
|
13
14
|
"Command to show the keyboard": "Команда отображения клавиатуры",
|
|
15
|
+
"Delete received files after (days)": "Удалять полученные файлы через (дней)",
|
|
14
16
|
"Do not accept new users": "Не принимать новых пользователей",
|
|
15
17
|
"Done": "Готово",
|
|
16
18
|
"File system": "Файловая система",
|
package/admin/i18n/uk.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = не видаляти. Перевіряється щогодини",
|
|
2
3
|
"API URL": "URL API",
|
|
3
4
|
"All received files": "Всі отримані файли",
|
|
4
5
|
"Allow state control": "Дозволити державний контроль",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "Прикутий сертифікат",
|
|
12
13
|
"Changed_Password": "Ви змінили пароль для свого бота. Ви бажаєте зараз видалити всіх збережених користувачів? Кожному користувачеві доведеться знову пройти автентифікацію з новим паролем, перш ніж він зможе знову спілкуватися з ботом.",
|
|
13
14
|
"Command to show the keyboard": "Команда для показу клавіатури",
|
|
15
|
+
"Delete received files after (days)": "Видаляти отримані файли через (днів)",
|
|
14
16
|
"Do not accept new users": "Не приймати нових користувачів",
|
|
15
17
|
"Done": "Сонце",
|
|
16
18
|
"File system": "Файлова система",
|
package/admin/i18n/zh-cn.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"0 = keep them. Checked every hour": "0 = 保留。每小时检查一次",
|
|
2
3
|
"API URL": "API 地址",
|
|
3
4
|
"All received files": "所有收到的文件",
|
|
4
5
|
"Allow state control": "允许控制状态",
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
"Chained certificate": "链式证书",
|
|
12
13
|
"Changed_Password": "您已更改Bot的密码。要立即删除所有已保存的用户吗?然后,每个用户必须使用新密码重新进行身份验证,然后才能再次与bot进行通信。",
|
|
13
14
|
"Command to show the keyboard": "用于显示键盘的命令",
|
|
15
|
+
"Delete received files after (days)": "在指定天数后删除收到的文件",
|
|
14
16
|
"Do not accept new users": "不对新用户进行身份验证",
|
|
15
17
|
"Done": "完毕",
|
|
16
18
|
"File system": "文件系统",
|
package/admin/jsonConfig.json
CHANGED
|
@@ -235,6 +235,20 @@
|
|
|
235
235
|
}
|
|
236
236
|
]
|
|
237
237
|
},
|
|
238
|
+
"deleteFilesAfterDays": {
|
|
239
|
+
"newLine": true,
|
|
240
|
+
"type": "number",
|
|
241
|
+
"xs": 12,
|
|
242
|
+
"sm": 12,
|
|
243
|
+
"md": 4,
|
|
244
|
+
"lg": 4,
|
|
245
|
+
"xl": 4,
|
|
246
|
+
"min": 0,
|
|
247
|
+
"label": "Delete received files after (days)",
|
|
248
|
+
"help": "0 = keep them. Checked every hour",
|
|
249
|
+
"hidden": "!data.saveFiles",
|
|
250
|
+
"default": 0
|
|
251
|
+
},
|
|
238
252
|
"allowStates": {
|
|
239
253
|
"newLine": true,
|
|
240
254
|
"type": "checkbox",
|
|
Binary file
|
package/build/main.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.mergeMessageIds = mergeMessageIds;
|
|
7
7
|
const node_fs_1 = require("node:fs");
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
8
9
|
const node_path_1 = require("node:path");
|
|
9
10
|
const axios_1 = __importDefault(require("axios"));
|
|
10
11
|
const node_telegram_bot_api_1 = require("node-telegram-bot-api");
|
|
@@ -57,8 +58,15 @@ const ALBUM_WAIT_MS = 1500;
|
|
|
57
58
|
const ASSISTANT_MAX_IMAGES = 4;
|
|
58
59
|
/** The size of a photo for the assistant: the largest one up to this edge (Telegram has e.g. 320, 800, 1280, 2560). */
|
|
59
60
|
const ASSISTANT_IMAGE_EDGE = 1600;
|
|
60
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Videos for the assistant stay in the folder `assistant` - in the data directory of the instance with js-controller
|
|
63
|
+
* 8.0+, else in its file storage; older ones are deleted.
|
|
64
|
+
*/
|
|
61
65
|
const ASSISTANT_VIDEOS_KEPT = 20;
|
|
66
|
+
/** Folders of received files that `deleteFilesAfterDays` cleans up (`assistant/` keeps its newest videos itself). */
|
|
67
|
+
const RECEIVED_FILE_FOLDERS = ['voice', 'photo', 'video', 'audio', 'document'];
|
|
68
|
+
/** How often old received files are looked for. */
|
|
69
|
+
const DELETE_OLD_FILES_INTERVAL_MS = 60 * 60 * 1000;
|
|
62
70
|
/**
|
|
63
71
|
* The size of a photo that goes to the assistant: the largest one up to {@link ASSISTANT_IMAGE_EDGE}, else the
|
|
64
72
|
* smallest. Enough to see what is on it, and far below the limit of the models.
|
|
@@ -190,6 +198,7 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
190
198
|
tmpDirName = '';
|
|
191
199
|
questions = [];
|
|
192
200
|
garbageCollectorInterval;
|
|
201
|
+
deleteOldFilesInterval;
|
|
193
202
|
isServer = false;
|
|
194
203
|
/**
|
|
195
204
|
* In-memory queue of outgoing sends that failed because telegram was unreachable. They are resent (FIFO)
|
|
@@ -415,6 +424,10 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
415
424
|
this.log.error(`Cannot create tmp directory: ${this.tmpDirName}: ${err}`);
|
|
416
425
|
}
|
|
417
426
|
}
|
|
427
|
+
if (this.deleteFilesAfterDays() > 0) {
|
|
428
|
+
void this.deleteOldFiles();
|
|
429
|
+
this.deleteOldFilesInterval = this.setInterval(() => void this.deleteOldFiles(), DELETE_OLD_FILES_INTERVAL_MS);
|
|
430
|
+
}
|
|
418
431
|
if (this.isServer) {
|
|
419
432
|
this.config.port = parseInt(String(this.config.port), 10);
|
|
420
433
|
// Load certificates
|
|
@@ -492,6 +505,10 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
492
505
|
this.clearInterval(this.garbageCollectorInterval);
|
|
493
506
|
this.garbageCollectorInterval = undefined;
|
|
494
507
|
}
|
|
508
|
+
if (this.deleteOldFilesInterval) {
|
|
509
|
+
this.clearInterval(this.deleteOldFilesInterval);
|
|
510
|
+
this.deleteOldFilesInterval = undefined;
|
|
511
|
+
}
|
|
495
512
|
if (this.pollingRestartTimer) {
|
|
496
513
|
this.clearTimeout(this.pollingRestartTimer);
|
|
497
514
|
this.pollingRestartTimer = undefined;
|
|
@@ -1812,8 +1829,8 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
1812
1829
|
}
|
|
1813
1830
|
/**
|
|
1814
1831
|
* Forward photos and a video to the ioBroker.assistant instance. The photos go along as base64 (one size each, see
|
|
1815
|
-
* {@link assistantPhotoSize}); a video never does: it is stored
|
|
1816
|
-
*
|
|
1832
|
+
* {@link assistantPhotoSize}); a video never does: it is stored by
|
|
1833
|
+
* {@link storeVideoForAssistant} and only its place goes along.
|
|
1817
1834
|
* The caption is the question. The same user check as for text messages applies.
|
|
1818
1835
|
*
|
|
1819
1836
|
* @param msgs the message, or all messages of an album
|
|
@@ -1867,7 +1884,7 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
1867
1884
|
if (!images.length && !video) {
|
|
1868
1885
|
return;
|
|
1869
1886
|
}
|
|
1870
|
-
this.log.debug(`Forward ${images.length} photo(s)${video ? ` and a video (${video.path || video.error})` : ''} from ${user} to ${this.config.assistantInstance}`);
|
|
1887
|
+
this.log.debug(`Forward ${images.length} photo(s)${video ? ` and a video (${video.url || video.path || video.error})` : ''} from ${user} to ${this.config.assistantInstance}`);
|
|
1871
1888
|
let response;
|
|
1872
1889
|
try {
|
|
1873
1890
|
response = (await this.sendToIfAlive(this.config.assistantInstance, 'ask', {
|
|
@@ -1905,8 +1922,11 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
1905
1922
|
.catch(error => this.log.error(`send Message Error: ${error}`));
|
|
1906
1923
|
}
|
|
1907
1924
|
/**
|
|
1908
|
-
* Store a video for the assistant
|
|
1909
|
-
*
|
|
1925
|
+
* Store a video for the assistant - it may run on another host, and a video does not go through the message bus.
|
|
1926
|
+
* With js-controller 8.0+ the video is written to the folder `assistant` in the data directory of this instance and
|
|
1927
|
+
* goes along as `iobdisk://` URL, which the assistant reads from any host with `readDiskFile(url)`. With an older
|
|
1928
|
+
* js-controller it goes to the ioBroker file storage of this instance as `{ adapter, path }`. Keeps the newest
|
|
1929
|
+
* {@link ASSISTANT_VIDEOS_KEPT}.
|
|
1910
1930
|
*
|
|
1911
1931
|
* @param msg the message with the video or video note
|
|
1912
1932
|
* @returns where it is, or why it is not there
|
|
@@ -1925,7 +1945,13 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
1925
1945
|
const content = await this.downloadFileOnce(file.file_id);
|
|
1926
1946
|
const date = new Date().toISOString().replace(/T/, '_').replace(/\..+/, '').replace(/:/g, '-');
|
|
1927
1947
|
const ext = mimeType === 'video/quicktime' ? 'mov' : (mimeType.split('/')[1] || 'mp4').replace(/\W/g, '');
|
|
1928
|
-
const
|
|
1948
|
+
const name = `video_${date}_${msg.message_id}.${ext}`;
|
|
1949
|
+
const url = await this.storeAssistantVideoOnDisk(name, content);
|
|
1950
|
+
if (url) {
|
|
1951
|
+
void this.pruneAssistantVideos();
|
|
1952
|
+
return { ...info, url, size: content.length };
|
|
1953
|
+
}
|
|
1954
|
+
const path = `assistant/${name}`;
|
|
1929
1955
|
await this.writeFileAsync(this.namespace, path, content);
|
|
1930
1956
|
void this.pruneAssistantVideos();
|
|
1931
1957
|
return { ...info, adapter: this.namespace, path, size: content.length };
|
|
@@ -1935,16 +1961,61 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
1935
1961
|
return { ...info, error: `could not be stored: ${error instanceof Error ? error.message : String(error)}` };
|
|
1936
1962
|
}
|
|
1937
1963
|
}
|
|
1938
|
-
/**
|
|
1964
|
+
/**
|
|
1965
|
+
* Write a video for the assistant to the folder `assistant` in the data directory of this instance.
|
|
1966
|
+
*
|
|
1967
|
+
* @param name the file name
|
|
1968
|
+
* @param content the video
|
|
1969
|
+
* @returns its `iobdisk://` URL, or an empty string if js-controller is older than 8.0 or writing failed
|
|
1970
|
+
*/
|
|
1971
|
+
async storeAssistantVideoOnDisk(name, content) {
|
|
1972
|
+
// js-controller 8.0 and newer
|
|
1973
|
+
if (!this.tmpDirName ||
|
|
1974
|
+
typeof this.getDiskFileUrl !== 'function') {
|
|
1975
|
+
return '';
|
|
1976
|
+
}
|
|
1977
|
+
const fileLocation = (0, node_path_1.join)(this.tmpDirName, 'assistant', name);
|
|
1978
|
+
try {
|
|
1979
|
+
await (0, promises_1.mkdir)((0, node_path_1.join)(this.tmpDirName, 'assistant'), { recursive: true });
|
|
1980
|
+
await (0, promises_1.writeFile)(fileLocation, content);
|
|
1981
|
+
}
|
|
1982
|
+
catch (error) {
|
|
1983
|
+
this.log.debug(`Cannot write the video to ${fileLocation}, it goes to the file storage: ${error}`);
|
|
1984
|
+
return '';
|
|
1985
|
+
}
|
|
1986
|
+
const url = this.getReceivedFileUrl(fileLocation);
|
|
1987
|
+
if (!url) {
|
|
1988
|
+
await (0, promises_1.unlink)(fileLocation).catch(() => { });
|
|
1989
|
+
}
|
|
1990
|
+
return url;
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Delete all but the newest {@link ASSISTANT_VIDEOS_KEPT} videos for the assistant, in the data directory and in the
|
|
1994
|
+
* file storage (where they were before js-controller 8.0).
|
|
1995
|
+
*/
|
|
1939
1996
|
async pruneAssistantVideos() {
|
|
1997
|
+
// the names start with the date, so the order of the names is the order of time
|
|
1998
|
+
const tooOld = (names) => {
|
|
1999
|
+
const videos = names.filter(name => name.startsWith('video_')).sort();
|
|
2000
|
+
return videos.slice(0, Math.max(0, videos.length - ASSISTANT_VIDEOS_KEPT));
|
|
2001
|
+
};
|
|
2002
|
+
if (this.tmpDirName) {
|
|
2003
|
+
const dir = (0, node_path_1.join)(this.tmpDirName, 'assistant');
|
|
2004
|
+
try {
|
|
2005
|
+
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
2006
|
+
for (const name of tooOld(entries.filter(e => e.isFile()).map(e => e.name))) {
|
|
2007
|
+
await (0, promises_1.unlink)((0, node_path_1.join)(dir, name));
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
catch (error) {
|
|
2011
|
+
if (error.code !== 'ENOENT') {
|
|
2012
|
+
this.log.debug(`Cannot delete old videos of the assistant in ${dir}: ${error}`);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
1940
2016
|
try {
|
|
1941
2017
|
const files = await this.readDirAsync(this.namespace, 'assistant');
|
|
1942
|
-
|
|
1943
|
-
const videos = files
|
|
1944
|
-
.filter(f => !f.isDir && f.file.startsWith('video_'))
|
|
1945
|
-
.map(f => f.file)
|
|
1946
|
-
.sort();
|
|
1947
|
-
for (const file of videos.slice(0, Math.max(0, videos.length - ASSISTANT_VIDEOS_KEPT))) {
|
|
2018
|
+
for (const file of tooOld(files.filter(f => !f.isDir).map(f => f.file))) {
|
|
1948
2019
|
await this.delFileAsync(this.namespace, `assistant/${file}`);
|
|
1949
2020
|
}
|
|
1950
2021
|
}
|
|
@@ -1952,6 +2023,90 @@ class Telegram extends adapter_core_1.Adapter {
|
|
|
1952
2023
|
this.log.debug(`Cannot delete old videos of the assistant: ${error}`);
|
|
1953
2024
|
}
|
|
1954
2025
|
}
|
|
2026
|
+
/** After how many days received files are deleted; 0 = never */
|
|
2027
|
+
deleteFilesAfterDays() {
|
|
2028
|
+
const days = Number(this.config.deleteFilesAfterDays);
|
|
2029
|
+
return Number.isFinite(days) && days > 0 ? days : 0;
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* Delete received files (voice, photo, video, audio, document) that are older than `deleteFilesAfterDays`, where
|
|
2033
|
+
* `saveFilesTo` stores them: in the file system or in the file storage of the instance.
|
|
2034
|
+
*
|
|
2035
|
+
* @param now the current time in ms
|
|
2036
|
+
* @returns how many files were deleted
|
|
2037
|
+
*/
|
|
2038
|
+
async deleteOldFiles(now = Date.now()) {
|
|
2039
|
+
const days = this.deleteFilesAfterDays();
|
|
2040
|
+
if (!days) {
|
|
2041
|
+
return 0;
|
|
2042
|
+
}
|
|
2043
|
+
const limit = now - days * 24 * 60 * 60 * 1000;
|
|
2044
|
+
let deleted = 0;
|
|
2045
|
+
let failed = 0;
|
|
2046
|
+
let lastError;
|
|
2047
|
+
for (const folder of RECEIVED_FILE_FOLDERS) {
|
|
2048
|
+
for (const file of await this.receivedFiles(folder)) {
|
|
2049
|
+
// a file without a known time is kept
|
|
2050
|
+
if (file.mtime === undefined || file.mtime >= limit) {
|
|
2051
|
+
continue;
|
|
2052
|
+
}
|
|
2053
|
+
try {
|
|
2054
|
+
await file.delete();
|
|
2055
|
+
deleted++;
|
|
2056
|
+
}
|
|
2057
|
+
catch (error) {
|
|
2058
|
+
failed++;
|
|
2059
|
+
lastError = error;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
if (deleted) {
|
|
2064
|
+
this.log.info(`Deleted ${deleted} received file(s) older than ${days} day(s)`);
|
|
2065
|
+
}
|
|
2066
|
+
if (failed) {
|
|
2067
|
+
this.log.warn(`Cannot delete ${failed} received file(s) older than ${days} day(s): ${String(lastError)}`);
|
|
2068
|
+
}
|
|
2069
|
+
return deleted;
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* The files in one folder of received files, with their modification time
|
|
2073
|
+
*
|
|
2074
|
+
* @param folder e.g. `video`
|
|
2075
|
+
*/
|
|
2076
|
+
async receivedFiles(folder) {
|
|
2077
|
+
try {
|
|
2078
|
+
if (this.config.saveFilesTo === 'filesystem') {
|
|
2079
|
+
const dir = (0, node_path_1.join)(this.tmpDirName, folder);
|
|
2080
|
+
if (!(0, node_fs_1.existsSync)(dir)) {
|
|
2081
|
+
return [];
|
|
2082
|
+
}
|
|
2083
|
+
const files = [];
|
|
2084
|
+
for (const name of await (0, promises_1.readdir)(dir)) {
|
|
2085
|
+
const file = (0, node_path_1.join)(dir, name);
|
|
2086
|
+
const stat = await (0, promises_1.lstat)(file);
|
|
2087
|
+
// only files, no folders or links
|
|
2088
|
+
if (stat.isFile()) {
|
|
2089
|
+
files.push({ mtime: stat.mtimeMs, delete: () => (0, promises_1.unlink)(file) });
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
return files;
|
|
2093
|
+
}
|
|
2094
|
+
if (this.config.saveFilesTo === 'iobroker') {
|
|
2095
|
+
const entries = await this.readDirAsync(this.namespace, `/${folder}`);
|
|
2096
|
+
return entries
|
|
2097
|
+
.filter(entry => !entry.isDir)
|
|
2098
|
+
.map(entry => ({
|
|
2099
|
+
mtime: entry.modifiedAt ?? entry.createdAt,
|
|
2100
|
+
delete: () => this.delFileAsync(this.namespace, `/${folder}/${entry.file}`),
|
|
2101
|
+
}));
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
catch (error) {
|
|
2105
|
+
// e.g. the folder does not exist in the file storage
|
|
2106
|
+
this.log.debug(`Cannot list the received files in ${folder}: ${String(error)}`);
|
|
2107
|
+
}
|
|
2108
|
+
return [];
|
|
2109
|
+
}
|
|
1955
2110
|
/**
|
|
1956
2111
|
* Store a downloaded file where `saveFilesTo` says (file system or ioBroker file storage).
|
|
1957
2112
|
*
|