| 123456789101112131415161718192021222324252627282930313233 |
- [CmdletBinding()]
- param(
- [Parameter(Mandatory = $true)][ValidatePattern('^https://')][string]$Endpoint,
- [Parameter(Mandatory = $true)][ValidatePattern('^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$')][string]$ProjectId
- )
- $ErrorActionPreference = 'Stop'
- $fileBytes = $null
- try {
- $testText = "# Central feedback endpoint test`r`n`r`nThis file verifies the public endpoint and Feishu delivery path. It contains no project data.`r`n"
- $fileBytes = [Text.Encoding]::UTF8.GetBytes($testText)
- $payload = @{
- project_id = $ProjectId
- record_version = 'v1.0.0'
- trigger = 'OWNER-REQUEST'
- file_name = ($ProjectId + '-endpoint-test-v1.0.0.md')
- file_base64 = [Convert]::ToBase64String($fileBytes)
- } | ConvertTo-Json -Compress
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- $uri = $Endpoint.TrimEnd('/') + '/v1/feedback'
- $result = Invoke-RestMethod -Method Post -Uri $uri -ContentType 'application/json' -Body $payload -TimeoutSec 120
- $result
- }
- catch {
- $message = $_.Exception.Message
- if ($_.ErrorDetails -and $_.ErrorDetails.Message) { $message = $_.ErrorDetails.Message }
- [pscustomobject]@{ status = 'not_sent'; detail = $message }
- exit 1
- }
- finally {
- if ($fileBytes) { [Array]::Clear($fileBytes, 0, $fileBytes.Length) }
- }
|