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