Skip to content

Commit 995ca37

Browse files
committed
Add text replacement for alert HTML and webhook content
Introduces Get-CIPPTextReplacement to process $HTMLContent and $JSONContent with tenant-specific replacements before sending alerts. Ensures dynamic content personalization for both email and webhook notifications.
1 parent 72a6965 commit 995ca37

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Modules/CIPPCore/Public/Send-CIPPAlert.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ function Send-CIPPAlert {
1818
$Table = Get-CIPPTable -TableName SchedulerConfig
1919
$Filter = "RowKey eq 'CippNotifications' and PartitionKey eq 'CippNotifications'"
2020
$Config = [pscustomobject](Get-CIPPAzDataTableEntity @Table -Filter $Filter)
21+
22+
if ($HTMLContent) {
23+
$HTMLContent = Get-CIPPTextReplacement -TenantFilter $TenantFilter -Text $HTMLContent
24+
}
25+
2126
if ($Type -eq 'email') {
2227
Write-Information 'Trying to send email'
2328
try {
@@ -39,6 +44,7 @@ function Send-CIPPAlert {
3944
}
4045
}
4146
}
47+
4248
$PowerShellBody = [PSCustomObject]@{
4349
message = @{
4450
subject = $Title
@@ -52,6 +58,7 @@ function Send-CIPPAlert {
5258
}
5359

5460
$JSONBody = ConvertTo-Json -Compress -Depth 10 -InputObject $PowerShellBody
61+
5562
if ($PSCmdlet.ShouldProcess($($Recipients.EmailAddress.Address -join ', '), 'Sending email')) {
5663
$null = New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -NoAuthCheck $true -type POST -body ($JSONBody)
5764
}
@@ -93,7 +100,7 @@ function Send-CIPPAlert {
93100

94101
if ($Type -eq 'webhook') {
95102
Write-Information 'Trying to send webhook'
96-
103+
$JSONBody = Get-CIPPTextReplacement -TenantFilter $TenantFilter -Text $JSONContent -EscapeForJson
97104
try {
98105
if (![string]::IsNullOrWhiteSpace($Config.webhook) -or ![string]::IsNullOrWhiteSpace($AltWebhook)) {
99106
if ($PSCmdlet.ShouldProcess($Config.webhook, 'Sending webhook')) {

0 commit comments

Comments
 (0)