From 004fe85799b5ea3cf6f97000bd4510080eaa8fb6 Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Fri, 30 Jan 2026 17:32:09 +0100 Subject: [PATCH] fix(matrix-bots): resolve TypeScript strict null check errors - Fix parseInt undefined errors in configuration files - Add fallbacks for Matrix client constructor parameters - Fix possibly undefined data accesses with non-null assertions - Update setCurrentConversation to accept null Co-Authored-By: Claude Opus 4.5 --- .../matrix-chat-bot/src/bot/matrix.service.ts | 46 +++++++++---------- .../src/config/configuration.ts | 2 +- .../src/session/session.service.ts | 4 +- .../src/bot/matrix.service.ts | 4 +- .../src/config/configuration.ts | 2 +- .../src/bot/matrix.service.ts | 4 +- .../src/config/configuration.ts | 2 +- .../src/bot/matrix.service.ts | 4 +- .../src/config/configuration.ts | 2 +- .../src/bot/matrix.service.ts | 4 +- .../src/config/configuration.ts | 2 +- .../src/bot/matrix.service.ts | 4 +- .../src/config/configuration.ts | 2 +- .../src/bot/matrix.service.ts | 4 +- .../src/config/configuration.ts | 2 +- 15 files changed, 44 insertions(+), 44 deletions(-) diff --git a/services/matrix-chat-bot/src/bot/matrix.service.ts b/services/matrix-chat-bot/src/bot/matrix.service.ts index 5a1a7f90a..ed0232776 100644 --- a/services/matrix-chat-bot/src/bot/matrix.service.ts +++ b/services/matrix-chat-bot/src/bot/matrix.service.ts @@ -33,8 +33,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); this.client.on('room.message', this.handleMessage.bind(this)); @@ -245,9 +245,9 @@ export class MatrixService implements OnModuleInit { return `Fehler: ${result.error}`; } - let response = result.data.content; - if (result.data.usage) { - response += `\n\n_Tokens: ${result.data.usage.total_tokens}_`; + let response = result.data!.content; + if (result.data!.usage) { + response += `\n\n_Tokens: ${result.data!.usage.total_tokens}_`; } return response; } @@ -279,8 +279,8 @@ export class MatrixService implements OnModuleInit { return `Fehler: ${result.error}`; } - this.sessionService.setCurrentConversation(sender, result.data.id); - return `Neues Gespraech erstellt: **${result.data.title}**\nNutze \`!senden [nachricht]\` um zu chatten.`; + this.sessionService.setCurrentConversation(sender, result.data!.id); + return `Neues Gespraech erstellt: **${result.data!.title}**\nNutze \`!senden [nachricht]\` um zu chatten.`; } private async handleListConversations(sender: string): Promise { @@ -342,7 +342,7 @@ export class MatrixService implements OnModuleInit { return `Fehler: ${result.error}`; } - return this.formatConversationDetails(result.data); + return this.formatConversationDetails(result.data!); } const number = parseInt(numberStr, 10); @@ -361,7 +361,7 @@ export class MatrixService implements OnModuleInit { } this.sessionService.setCurrentConversation(sender, conversationId); - return `Gespraech ausgewaehlt: **${result.data.title}**\n\n${this.formatConversationDetails(result.data)}`; + return `Gespraech ausgewaehlt: **${result.data!.title}**\n\n${this.formatConversationDetails(result.data!)}`; } private formatConversationDetails(conv: Conversation): string { @@ -413,17 +413,17 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht })); // Get AI response - const completionResult = await this.chatService.createCompletion(token, messages, convResult.data.modelId); + const completionResult = await this.chatService.createCompletion(token, messages, convResult.data!.modelId); if (completionResult.error) { return `Fehler bei AI-Antwort: ${completionResult.error}`; } // Save assistant response - await this.chatService.addMessage(token, conversationId, completionResult.data.content, 'assistant'); + await this.chatService.addMessage(token, conversationId, completionResult.data!.content, 'assistant'); - let response = completionResult.data.content; - if (completionResult.data.usage) { - response += `\n\n_Tokens: ${completionResult.data.usage.total_tokens}_`; + let response = completionResult.data!.content; + if (completionResult.data!.usage) { + response += `\n\n_Tokens: ${completionResult.data!.usage.total_tokens}_`; } return response; } @@ -499,7 +499,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht return `Fehler: ${result.error}`; } - return `Titel geaendert zu: **${result.data.title}**`; + return `Titel geaendert zu: **${result.data!.title}**`; } private async handleArchive(sender: string, numberStr: string): Promise { @@ -527,7 +527,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht return `Fehler: ${result.error}`; } - return `Gespraech **${result.data.title}** archiviert.`; + return `Gespraech **${result.data!.title}** archiviert.`; } private async handleListArchived(sender: string): Promise { @@ -586,7 +586,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht return `Fehler: ${result.error}`; } - return `Gespraech **${result.data.title}** wiederhergestellt.`; + return `Gespraech **${result.data!.title}** wiederhergestellt.`; } private async handlePin(sender: string, numberStr: string): Promise { @@ -614,7 +614,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht return `Fehler: ${result.error}`; } - return `Gespraech **${result.data.title}** angepinnt. 📌`; + return `Gespraech **${result.data!.title}** angepinnt. 📌`; } private async handleUnpin(sender: string, numberStr: string): Promise { @@ -642,7 +642,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht return `Fehler: ${result.error}`; } - return `Pin fuer **${result.data.title}** entfernt.`; + return `Pin fuer **${result.data!.title}** entfernt.`; } private async handleDelete(sender: string, numberStr: string): Promise { @@ -728,8 +728,8 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht return 'Ausgewaehltes Modell nicht gefunden.'; } - const icon = BRANCH_ICONS[result.data.provider] || BRANCH_ICONS.default; - return `Aktuelles Modell: ${icon} **${result.data.name}**`; + const icon = BRANCH_ICONS[result.data!.provider] || BRANCH_ICONS.default; + return `Aktuelles Modell: ${icon} **${result.data!.name}**`; } const number = parseInt(numberStr, 10); @@ -748,7 +748,7 @@ Nutze \`!senden [nachricht]\` um zu chatten oder \`!verlauf\` fuer den Nachricht } this.sessionService.setSelectedModel(sender, modelId); - const icon = BRANCH_ICONS[result.data.provider] || BRANCH_ICONS.default; - return `Modell gewaehlt: ${icon} **${result.data.name}**\nWird fuer neue Gespraeche und Quick-Chat verwendet.`; + const icon = BRANCH_ICONS[result.data!.provider] || BRANCH_ICONS.default; + return `Modell gewaehlt: ${icon} **${result.data!.name}**\nWird fuer neue Gespraeche und Quick-Chat verwendet.`; } } diff --git a/services/matrix-chat-bot/src/config/configuration.ts b/services/matrix-chat-bot/src/config/configuration.ts index fcb89498a..9fb45d600 100644 --- a/services/matrix-chat-bot/src/config/configuration.ts +++ b/services/matrix-chat-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3327, + port: parseInt(process.env.PORT || '3327', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN, diff --git a/services/matrix-chat-bot/src/session/session.service.ts b/services/matrix-chat-bot/src/session/session.service.ts index 0ea5c854a..37871ea3a 100644 --- a/services/matrix-chat-bot/src/session/session.service.ts +++ b/services/matrix-chat-bot/src/session/session.service.ts @@ -93,10 +93,10 @@ export class SessionService { } // Current conversation management - setCurrentConversation(matrixUserId: string, conversationId: string): void { + setCurrentConversation(matrixUserId: string, conversationId: string | null): void { const session = this.sessions.get(matrixUserId); if (session) { - session.currentConversationId = conversationId; + session.currentConversationId = conversationId || undefined; } } diff --git a/services/matrix-manadeck-bot/src/bot/matrix.service.ts b/services/matrix-manadeck-bot/src/bot/matrix.service.ts index fd2d7c19c..2ec4aaa8e 100644 --- a/services/matrix-manadeck-bot/src/bot/matrix.service.ts +++ b/services/matrix-manadeck-bot/src/bot/matrix.service.ts @@ -36,8 +36,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); diff --git a/services/matrix-manadeck-bot/src/config/configuration.ts b/services/matrix-manadeck-bot/src/config/configuration.ts index c795dd039..b7f7a59a3 100644 --- a/services/matrix-manadeck-bot/src/config/configuration.ts +++ b/services/matrix-manadeck-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3321, + port: parseInt(process.env.PORT || '3321', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN, diff --git a/services/matrix-planta-bot/src/bot/matrix.service.ts b/services/matrix-planta-bot/src/bot/matrix.service.ts index b2d25fdd7..9ca6a7173 100644 --- a/services/matrix-planta-bot/src/bot/matrix.service.ts +++ b/services/matrix-planta-bot/src/bot/matrix.service.ts @@ -55,8 +55,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); diff --git a/services/matrix-planta-bot/src/config/configuration.ts b/services/matrix-planta-bot/src/config/configuration.ts index 881a7ccbf..0d1add6be 100644 --- a/services/matrix-planta-bot/src/config/configuration.ts +++ b/services/matrix-planta-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3322, + port: parseInt(process.env.PORT || '3322', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN, diff --git a/services/matrix-presi-bot/src/bot/matrix.service.ts b/services/matrix-presi-bot/src/bot/matrix.service.ts index 563e29e26..383d7422e 100644 --- a/services/matrix-presi-bot/src/bot/matrix.service.ts +++ b/services/matrix-presi-bot/src/bot/matrix.service.ts @@ -36,8 +36,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); diff --git a/services/matrix-presi-bot/src/config/configuration.ts b/services/matrix-presi-bot/src/config/configuration.ts index fec533243..4bf83c3b9 100644 --- a/services/matrix-presi-bot/src/config/configuration.ts +++ b/services/matrix-presi-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3325, + port: parseInt(process.env.PORT || '3325', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN, diff --git a/services/matrix-questions-bot/src/bot/matrix.service.ts b/services/matrix-questions-bot/src/bot/matrix.service.ts index f8d963390..8c38eb07c 100644 --- a/services/matrix-questions-bot/src/bot/matrix.service.ts +++ b/services/matrix-questions-bot/src/bot/matrix.service.ts @@ -37,8 +37,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); diff --git a/services/matrix-questions-bot/src/config/configuration.ts b/services/matrix-questions-bot/src/config/configuration.ts index 0b8418e4c..ed552305e 100644 --- a/services/matrix-questions-bot/src/config/configuration.ts +++ b/services/matrix-questions-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3324, + port: parseInt(process.env.PORT || '3324', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN, diff --git a/services/matrix-skilltree-bot/src/bot/matrix.service.ts b/services/matrix-skilltree-bot/src/bot/matrix.service.ts index 66123d2c4..0bcf669d5 100644 --- a/services/matrix-skilltree-bot/src/bot/matrix.service.ts +++ b/services/matrix-skilltree-bot/src/bot/matrix.service.ts @@ -60,8 +60,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); diff --git a/services/matrix-skilltree-bot/src/config/configuration.ts b/services/matrix-skilltree-bot/src/config/configuration.ts index 7919d07bf..2fa699563 100644 --- a/services/matrix-skilltree-bot/src/config/configuration.ts +++ b/services/matrix-skilltree-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3326, + port: parseInt(process.env.PORT || '3326', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN, diff --git a/services/matrix-storage-bot/src/bot/matrix.service.ts b/services/matrix-storage-bot/src/bot/matrix.service.ts index 026d2c806..30673b9e8 100644 --- a/services/matrix-storage-bot/src/bot/matrix.service.ts +++ b/services/matrix-storage-bot/src/bot/matrix.service.ts @@ -41,8 +41,8 @@ export class MatrixService implements OnModuleInit { return; } - const storage = new SimpleFsStorageProvider(storagePath); - this.client = new MatrixClient(homeserverUrl, accessToken, storage); + const storage = new SimpleFsStorageProvider(storagePath || './data/bot-storage.json'); + this.client = new MatrixClient(homeserverUrl || 'http://localhost:8008', accessToken, storage); AutojoinRoomsMixin.setupOnClient(this.client); diff --git a/services/matrix-storage-bot/src/config/configuration.ts b/services/matrix-storage-bot/src/config/configuration.ts index 9bb0c43cb..54c77870e 100644 --- a/services/matrix-storage-bot/src/config/configuration.ts +++ b/services/matrix-storage-bot/src/config/configuration.ts @@ -1,5 +1,5 @@ export default () => ({ - port: parseInt(process.env.PORT, 10) || 3323, + port: parseInt(process.env.PORT || '3323', 10), matrix: { homeserverUrl: process.env.MATRIX_HOMESERVER_URL || 'http://localhost:8008', accessToken: process.env.MATRIX_ACCESS_TOKEN,