From 35edf299571752a12a049de64f856c14933a1e6a Mon Sep 17 00:00:00 2001 From: Thumbscrew Date: Thu, 31 Mar 2022 21:30:43 +0100 Subject: [PATCH] add `Join-MatrixRoom` function --- PSMatrix.psd1 | 3 ++- public/Join-MatrixRoom.ps1 | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 public/Join-MatrixRoom.ps1 diff --git a/PSMatrix.psd1 b/PSMatrix.psd1 index 68b668a..6d742a0 100644 --- a/PSMatrix.psd1 +++ b/PSMatrix.psd1 @@ -72,7 +72,8 @@ PowerShellVersion = '7.0' FunctionsToExport = @( 'New-MatrixAccessToken', 'Remove-MatrixAccessToken', - 'Get-MatrixJoinedRooms' + 'Get-MatrixJoinedRooms', + 'Join-MatrixRoom' ) # 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. diff --git a/public/Join-MatrixRoom.ps1 b/public/Join-MatrixRoom.ps1 new file mode 100644 index 0000000..807b8f1 --- /dev/null +++ b/public/Join-MatrixRoom.ps1 @@ -0,0 +1,23 @@ +function Join-MatrixRoom { + param( + [Parameter(Mandatory)] + [string]$ServerUrl, + + [Parameter(Mandatory)] + [SecureString]$AccessToken, + + [Parameter(Mandatory)] + [string]$RoomAliasOrId + ) + + $url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/join/$RoomAliasOrId?server_name=techlore.net" + $headers = Get-MatrixAuthHeaders -AccessToken $AccessToken + $method = "POST" + + try { + $res = Invoke-RestMethod -Uri $url -Headers $headers -Method $method + return $res + } catch { + Write-Error $_ + } +} \ No newline at end of file