see Permalinks category export interface PermalinkParts { /**
     * The room ID or alias the permalink references. May be null.
     */ roomIdOrAlias : string ; /**
     * The user ID the permalink references. May be null.
     */ userId : string ; /**
     * The event ID the permalink references. May be null.
     */ eventId : string ; /**
     * The servers the permalink is routed through. May be null or empty.
     */ viaServers : string [ ] ; } category export class Permalinks { private constructor ( ) { } private static encodeViaArgs ( servers ) { if ( ! servers || ! servers . length ) return "" ; return `?via=${ servers . join ( "via=" ) }` ; } param { string } roomIdOrAlias param { string [ ] } viaServers returns { string } public static forRoom ( roomIdOrAlias , viaServers = [ ] ) { return `https://matrix.to/#/${ roomIdOrAlias }${ Permalinks . encodeViaArgs ( viaServers ) }` ; } param { string } userId returns { string } public static forUser ( userId ) { return `https://matrix.to/#/${ userId }` ; } param { string } roomIdOrAlias param { string } eventId param { string [ ] } viaServers returns { string } public static forEvent ( roomIdOrAlias , eventId , viaServers = [ ] ) { return `https://matrix.to/#/${ roomIdOrAlias }/${ eventId }${ Permalinks . encodeViaArgs ( viaServers ) }` ; } param { string } matrixTo returns { PermalinkParts } public static parseUrl ( matrixTo ) { if ( ! matrixTo || ! matrixTo . startsWith ( "https://matrix.to/#/" ) ) { throw new Error ( "Not a valid matrix.to URL" ) ; } const parts = matrixTo . substring ( "https://matrix.to/#/" . length ) . split ( "/" ) ; const entity = decodeURIComponent ( parts [ 0 ] ) ; if ( entity [ 0 ] === '@' ) { return { userId : entity , roomIdOrAlias : undefined , eventId : undefined , viaServers : undefined } ; } else if ( entity [ 0 ] === '#' || entity [ 0 ] === '!' ) { if ( parts . length === 1 ) { return { roomIdOrAlias : entity , userId : undefined , eventId : undefined , viaServers : [ ] } ; } const eventIdAndQuery = decodeURIComponent ( parts . length > 1 ? parts . slice ( 1 ) . join ( '/' ) : "" ) ; const secondaryParts = eventIdAndQuery . split ( '?' ) ; const eventId = secondaryParts [ 0 ] ; const query = secondaryParts . length > 1 ? secondaryParts [ 1 ] : "" ; const via = query . split ( "via=" ) . filter ( p => ! ! p ) ; return { roomIdOrAlias : entity , eventId : eventId , viaServers : via , userId : undefined } ; } throw new Error ( "Unexpected entity" ) ; } }