mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-28 09:37:43 +02:00
🐛 fix(matrix-web): handle Matrix SSO loginToken callback
Add loginWithLoginToken function to exchange Matrix SSO loginToken for credentials. The app layout now detects the loginToken URL parameter and completes the SSO flow. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9e9db590dc
commit
dc0d425f61
53 changed files with 1550 additions and 230 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { MatrixService } from './matrix.service';
|
||||
import { ContactsModule } from '../contacts/contacts.module';
|
||||
import { SessionModule, TranscriptionModule } from '@manacore/bot-services';
|
||||
import { SessionModule, TranscriptionModule, CreditModule } from '@manacore/bot-services';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -10,6 +10,7 @@ import { SessionModule, TranscriptionModule } from '@manacore/bot-services';
|
|||
TranscriptionModule.register({
|
||||
sttUrl: process.env.STT_URL || 'http://localhost:3020',
|
||||
}),
|
||||
CreditModule.forRoot(),
|
||||
],
|
||||
providers: [MatrixService],
|
||||
exports: [MatrixService],
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ import {
|
|||
UserListMapper,
|
||||
} from '@manacore/matrix-bot-common';
|
||||
import { ContactsService, Contact } from '../contacts/contacts.service';
|
||||
import { SessionService, TranscriptionService } from '@manacore/bot-services';
|
||||
import { SessionService, TranscriptionService, CreditService } from '@manacore/bot-services';
|
||||
import { HELP_MESSAGE } from '../config/configuration';
|
||||
|
||||
const CONTACT_CREATE_CREDITS = 0.02;
|
||||
|
||||
// Natural language keyword detector
|
||||
const keywordDetector = new KeywordCommandDetector([
|
||||
...COMMON_KEYWORDS,
|
||||
|
|
@ -29,7 +31,8 @@ export class MatrixService extends BaseMatrixService {
|
|||
configService: ConfigService,
|
||||
private readonly transcriptionService: TranscriptionService,
|
||||
private contactsService: ContactsService,
|
||||
private sessionService: SessionService
|
||||
private sessionService: SessionService,
|
||||
private creditService: CreditService
|
||||
) {
|
||||
super(configService);
|
||||
}
|
||||
|
|
@ -414,6 +417,18 @@ Sag "hilfe" fur alle Befehle!`;
|
|||
return;
|
||||
}
|
||||
|
||||
// Validate credits
|
||||
const validation = await this.creditService.validateCredits(token, CONTACT_CREATE_CREDITS);
|
||||
if (!validation.hasCredits) {
|
||||
const errorMsg = this.creditService.formatInsufficientCreditsError(
|
||||
CONTACT_CREATE_CREDITS,
|
||||
validation.availableCredits,
|
||||
'Kontakt erstellen'
|
||||
);
|
||||
await this.sendReply(roomId, event, errorMsg.text);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
await this.sendReply(
|
||||
roomId,
|
||||
|
|
@ -433,10 +448,11 @@ Sag "hilfe" fur alle Befehle!`;
|
|||
});
|
||||
|
||||
const name = contact.displayName || `${firstName} ${lastName || ''}`.trim();
|
||||
const balance = await this.creditService.getBalance(token);
|
||||
await this.sendReply(
|
||||
roomId,
|
||||
event,
|
||||
`Kontakt **${name}** erstellt!\n\nNutze \`!kontakte\` um die Liste zu sehen oder \`!edit\` um weitere Daten hinzuzufugen.`
|
||||
`Kontakt **${name}** erstellt!\n⚡ -${CONTACT_CREATE_CREDITS} Credits (${balance.balance.toFixed(2)} verbleibend)\n\nNutze \`!kontakte\` um die Liste zu sehen oder \`!edit\` um weitere Daten hinzuzufugen.`
|
||||
);
|
||||
} catch (error) {
|
||||
const errorMsg = error instanceof Error ? error.message : 'Unbekannter Fehler';
|
||||
|
|
@ -693,13 +709,23 @@ Sag "hilfe" fur alle Befehle!`;
|
|||
const result = await this.sessionService.login(sender, email, password);
|
||||
|
||||
if (result.success) {
|
||||
await this.sendReply(
|
||||
roomId,
|
||||
event,
|
||||
`Erfolgreich angemeldet!\n\nNutze \`!kontakte\` um deine Kontakte zu sehen.`
|
||||
);
|
||||
const token = this.sessionService.getToken(sender);
|
||||
if (token) {
|
||||
const balance = await this.creditService.getBalance(token);
|
||||
await this.sendReply(
|
||||
roomId,
|
||||
event,
|
||||
`✅ Erfolgreich angemeldet als **${email}**\n⚡ Credits: ${balance.balance.toFixed(2)}\n\nNutze \`!kontakte\` um deine Kontakte zu sehen.`
|
||||
);
|
||||
} else {
|
||||
await this.sendReply(
|
||||
roomId,
|
||||
event,
|
||||
`✅ Erfolgreich angemeldet!\n\nNutze \`!kontakte\` um deine Kontakte zu sehen.`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await this.sendReply(roomId, event, `Anmeldung fehlgeschlagen: ${result.error}`);
|
||||
await this.sendReply(roomId, event, `❌ Anmeldung fehlgeschlagen: ${result.error}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -707,14 +733,21 @@ Sag "hilfe" fur alle Befehle!`;
|
|||
const backendHealthy = await this.contactsService.checkHealth();
|
||||
const isLoggedIn = this.sessionService.isLoggedIn(sender);
|
||||
const sessionCount = this.sessionService.getSessionCount();
|
||||
const session = this.sessionService.getSession(sender);
|
||||
const token = this.sessionService.getToken(sender);
|
||||
|
||||
const statusText = `**Contacts Bot Status**
|
||||
let statusText = `**Contacts Bot Status**\n\n`;
|
||||
statusText += `**Backend:** ${backendHealthy ? '✅ Online' : '❌ Offline'}\n`;
|
||||
statusText += `**Aktive Sessions:** ${sessionCount}\n\n`;
|
||||
|
||||
**Backend:** ${backendHealthy ? 'Online' : 'Offline'}
|
||||
**Dein Status:** ${isLoggedIn ? 'Angemeldet' : 'Nicht angemeldet'}
|
||||
**Aktive Sessions:** ${sessionCount}
|
||||
|
||||
${!isLoggedIn ? 'Nutze `!login email passwort` um dich anzumelden.' : ''}`;
|
||||
if (isLoggedIn && session && token) {
|
||||
const balance = await this.creditService.getBalance(token);
|
||||
statusText += `👤 Angemeldet als: ${session.email}\n`;
|
||||
statusText += `⚡ Credits: ${balance.balance.toFixed(2)}\n`;
|
||||
} else {
|
||||
statusText += `👤 Nicht angemeldet\n`;
|
||||
statusText += `💡 Login: \`!login email passwort\``;
|
||||
}
|
||||
|
||||
await this.sendReply(roomId, event, statusText);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue