mirror of
https://github.com/Thumbscrew/PSMatrix.git
synced 2025-01-18 09:35:44 +00:00
add Get-MatrixRoomId
(#2)
This commit is contained in:
parent
a0d3272f2c
commit
1e765ccdd4
@ -73,7 +73,8 @@ FunctionsToExport = @(
|
||||
'New-MatrixAccessToken',
|
||||
'Remove-MatrixAccessToken',
|
||||
'Get-MatrixJoinedRooms',
|
||||
'Get-MatrixJoinedMembers'
|
||||
'Get-MatrixJoinedMembers',
|
||||
'Get-MatrixRoomId'
|
||||
)
|
||||
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
|
42
public/Get-MatrixRoomId.ps1
Normal file
42
public/Get-MatrixRoomId.ps1
Normal file
@ -0,0 +1,42 @@
|
||||
<#
|
||||
.Synopsis
|
||||
Get the Matrix Room ID for the given Room Alias.
|
||||
|
||||
.Description
|
||||
Get the Matrix Room ID for the given Room Alias from _matrix/client/v3/directory/room/{roomAlias}. See https://spec.matrix.org/v1.2/client-server-api/#get_matrixclientv3directoryroomroomalias.
|
||||
|
||||
.Parameter ServerUrl
|
||||
URL for the Matrix server to query, for example "https://matrix.example.com".
|
||||
|
||||
.Parameter RoomAlias
|
||||
The Matrix Room Alias to retrieve the Room ID for (e.g. '#matrix:matrix.org').
|
||||
|
||||
.Example
|
||||
Get-MatrixRoomId -ServerUrl $matrix -RoomAlias "#synapse:matrix.org"
|
||||
#>
|
||||
function Get-MatrixRoomId {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$ServerUrl,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$RoomAlias
|
||||
)
|
||||
|
||||
$encodedRoomAlias = $RoomAlias.Replace('#', '%23')
|
||||
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/directory/room/$encodedRoomAlias"
|
||||
Write-Debug "URL: $url"
|
||||
|
||||
try {
|
||||
$res = Invoke-RestMethod -Uri $url
|
||||
|
||||
$roomId = [PSCustomObject]@{
|
||||
RoomId = $res.room_id
|
||||
Servers = $res.servers
|
||||
}
|
||||
|
||||
return $roomId
|
||||
} catch {
|
||||
Write-Error $_
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user