KI-AGENT: Matrix-Einbettung stabilisieren
This commit is contained in:
@@ -35,6 +35,11 @@ type MatrixUserSession = {
|
||||
validUntilMs: number
|
||||
}
|
||||
|
||||
type MatrixLoginTokenResponse = {
|
||||
login_token: string
|
||||
expires_in_ms: number
|
||||
}
|
||||
|
||||
type MatrixTenantRoomOptions = {
|
||||
key?: string
|
||||
name?: string
|
||||
@@ -1146,6 +1151,40 @@ export function matrixService(server: FastifyInstance) {
|
||||
}
|
||||
}
|
||||
|
||||
const createElementRoomSession = async (
|
||||
userId: string,
|
||||
tenantId: number | null,
|
||||
options: MatrixTenantRoomOptions = {}
|
||||
) => {
|
||||
const room = await provisionTenantRoom(userId, tenantId, options)
|
||||
const session = await ensureCurrentUserJoinedRoom(userId, tenantId, {
|
||||
roomId: room.roomId,
|
||||
alias: room.alias,
|
||||
})
|
||||
|
||||
const token = await requestMatrixJson<MatrixLoginTokenResponse>(
|
||||
"/_matrix/client/v1/login/get_token",
|
||||
session.accessToken,
|
||||
{
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({}),
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
roomId: room.roomId,
|
||||
alias: room.alias,
|
||||
key: room.key,
|
||||
name: room.name,
|
||||
matrixUserId: session.matrixUserId,
|
||||
loginToken: token.login_token,
|
||||
expiresInMs: token.expires_in_ms,
|
||||
homeserverUrl: homeserverUrl(),
|
||||
serverName: serverName(),
|
||||
}
|
||||
}
|
||||
|
||||
const listTenantCommunicationUsers = async (tenantId: number | null) => {
|
||||
const tenant = await getCurrentTenant(tenantId)
|
||||
const rows = await server.db
|
||||
@@ -1302,6 +1341,7 @@ export function matrixService(server: FastifyInstance) {
|
||||
getTenantRoomMessages,
|
||||
getTenantRoomMembers,
|
||||
sendTenantRoomMessage,
|
||||
createElementRoomSession,
|
||||
syncTenantRoomMembers,
|
||||
getGeneralRoomMessages,
|
||||
getGeneralRoomMembers,
|
||||
|
||||
Reference in New Issue
Block a user