※まだ処理途中でも通知来ることあるな・・・
C:\Users\<ユーザー名>\.codex\notify-slack.ps1を作成。UTF8のBOM付で保存
param(
[string]$payloadJson
)
$logFile = "C:\Users\<ユーザー名>\.codex\notify-slack.log"
$webhookUrl = "https://hooks.slack.com/services/XXXX/XXXX/XXXX"
Add-Content -Path $logFile -Value "---- $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ----"
Add-Content -Path $logFile -Value "RAW: $payloadJson"
try {
$payload = $payloadJson | ConvertFrom-Json
if ($payload.type -ne "agent-turn-complete") {
Add-Content -Path $logFile -Value "SKIP: not agent-turn-complete"
exit 0
}
$lastMessage = $payload.'last-assistant-message'
if ([string]::IsNullOrWhiteSpace($lastMessage)) {
$lastMessage = "Codex の処理が完了しました"
}
if ($lastMessage.Length -gt 200) {
$lastMessage = $lastMessage.Substring(0, 200) + "..."
}
$text = "Codex 完了`n$lastMessage"
$json = @{
text = $text
} | ConvertTo-Json -Compress -Depth 5
$bodyBytes = [System.Text.Encoding]::UTF8.GetBytes($json)
Invoke-RestMethod `
-Uri $webhookUrl `
-Method Post `
-ContentType "application/json; charset=utf-8" `
-Body $bodyBytes | Out-Null
Add-Content -Path $logFile -Value "POST OK"
}
catch {
Add-Content -Path $logFile -Value ("ERROR: " + $_.Exception.Message)
throw
}C:\Users\<ユーザー名>\.codex\config.tomlに以下を追加
上の方
... notify = [ "powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "C:\\Users\\<ユーザー名>\\.codex\\notify-slack.ps1" ] v
[tui]のところ
[tui] notifications = true notification_method = "auto" ...