From 9c7d12107b266ff2de7039287e90dcaeee2c5f4f Mon Sep 17 00:00:00 2001 From: Thumbscrew Date: Tue, 5 Apr 2022 17:07:46 +0100 Subject: [PATCH] add `Remove-MatrixRoomMessage` --- PSMatrix.psd1 | 3 ++- public/Remove-MatrixRoomMessage.ps1 | 39 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 public/Remove-MatrixRoomMessage.ps1 diff --git a/PSMatrix.psd1 b/PSMatrix.psd1 index 967e652..1e30cd9 100644 --- a/PSMatrix.psd1 +++ b/PSMatrix.psd1 @@ -77,7 +77,8 @@ FunctionsToExport = @( 'Get-MatrixJoinedRooms', 'Get-MatrixJoinedMembers', 'Get-MatrixRoomId', - 'Get-MatrixRoomMessages' + 'Get-MatrixRoomMessages', + 'Remove-MatrixRoomMessage' ) # 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/Remove-MatrixRoomMessage.ps1 b/public/Remove-MatrixRoomMessage.ps1 new file mode 100644 index 0000000..08c463f --- /dev/null +++ b/public/Remove-MatrixRoomMessage.ps1 @@ -0,0 +1,39 @@ +function Remove-MatrixRoomMessage { + param ( + [Parameter(Mandatory)] + [string] + $ServerUrl, + + [Parameter(Mandatory)] + [SecureString] + $AccessToken, + + [Parameter(Mandatory)] + [string] + $RoomId, + + [Parameter(Mandatory)] + [MatrixMessage] + $Message, + + [Parameter(Mandatory=$false)] + [string] + $Reason + ) + + $eventId = $Message.EventID + $txnId = New-Guid + $url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/rooms/$RoomId/redact/$eventId/$txnId" + Write-Debug "URL: $url" + $method = "Put" + $headers = Get-MatrixAuthHeaders -AccessToken $AccessToken + $body = @{ + reason = $Reason + } | ConvertTo-Json + + try { + return Invoke-RestMethod -Uri $url -Method $method -Headers $headers -Body $body + } catch { + Write-Error $_ + } +} \ No newline at end of file