broke apprise notification function into its own module to be used by multiple scripts
Security / security (push) Successful in 58s
Security / security (push) Successful in 58s
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
||||
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
||||
|
||||
function Send-AppriseNotification
|
||||
{
|
||||
param(
|
||||
# Title of the notification
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$title,
|
||||
|
||||
# Content of the notification
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$content
|
||||
)
|
||||
|
||||
$headers = @{
|
||||
"Content-Type"="application/json"
|
||||
}
|
||||
$body = @{
|
||||
title=$title
|
||||
body=$content
|
||||
tags="$appriseWebhookTag"
|
||||
}
|
||||
$json = $body | ConvertTo-Json
|
||||
try {
|
||||
Invoke-WebRequest -URI $appriseWebhookURL -Method post -Body $json -Headers $headers
|
||||
}
|
||||
catch {
|
||||
Write-Host "Notification Error Encountered: $($global:Error[0])"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ USER 1000:1000
|
||||
WORKDIR /data
|
||||
COPY ["crontab", "/data/"]
|
||||
COPY --chmod=755 ["main.sh", "/data/"]
|
||||
COPY ["Start-DoneTickNotifier.ps1", "Start-DoneTickConsumer.ps1", "/data/"]
|
||||
COPY ["Start-DoneTickNotifier.ps1", "Start-DoneTickConsumer.ps1", "AppriseNotification.psm1", "/data/"]
|
||||
|
||||
ENTRYPOINT ["/data/main.sh"]
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
[string] $ListenUrl = "http://+:8080/"
|
||||
|
||||
Import-Module ./AppriseNotification.psm1
|
||||
|
||||
function Write-JsonResponse
|
||||
{
|
||||
param(
|
||||
@@ -91,8 +93,7 @@ function Receive-Webhook
|
||||
Write-Host "Payload: <empty>"
|
||||
}
|
||||
|
||||
# Add your real webhook handling here.
|
||||
# Example: inspect $payload.event, save data, or call another API.
|
||||
Send-AppriseNotification -title "Donetick Webhook Received" -content ($payload | ConvertTo-Json -Depth 20)
|
||||
|
||||
Write-JsonResponse -Response $response -StatusCode 200 -Body @{
|
||||
ok = $true
|
||||
|
||||
@@ -1,40 +1,8 @@
|
||||
[string] $dtHost = $ENV:DONETICKHOST
|
||||
[string] $dtPort = $ENV:DONETICKPORT
|
||||
[string] $dtAPIKey = $ENV:DONETICKAPIKEY
|
||||
[string] $appriseWebhookURL = $ENV:APPRISEWEBHOOKURL
|
||||
[string] $appriseWebhookTag = $ENV:APPRISEWEBHOOKTAG
|
||||
|
||||
|
||||
function Send-Notification
|
||||
{
|
||||
param(
|
||||
# Title of the notification
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$title,
|
||||
|
||||
# Content of the notification
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$content
|
||||
)
|
||||
|
||||
$headers = @{
|
||||
"Content-Type"="application/json"
|
||||
}
|
||||
$body = @{
|
||||
title=$title
|
||||
body=$content
|
||||
tags="$appriseWebhookTag"
|
||||
}
|
||||
$json = $body | ConvertTo-Json
|
||||
try {
|
||||
Invoke-WebRequest -URI $appriseWebhookURL -Method post -Body $json -Headers $headers
|
||||
}
|
||||
catch {
|
||||
Write-Host "Notification Error Encountered: $($global:Error[0])"
|
||||
}
|
||||
}
|
||||
Import-Module ./AppriseNotification.psm1
|
||||
|
||||
function Get-Chores
|
||||
{
|
||||
@@ -70,7 +38,6 @@ foreach($chore in $chores)
|
||||
{
|
||||
write-host "$($chore.name) $dueDate is due today!"
|
||||
$todaysTasks += $chore
|
||||
# Send-Notification -title "TASK DUE TODAY" -content "$($chore.Name) is due today!"
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,7 +55,7 @@ if ($overdueTasks.Count -ne 0)
|
||||
{
|
||||
$content += "$($overdueTask.Name) was due $((Get-Date $overdueTask.nextDueDate).ToLocalTime())`n"
|
||||
}
|
||||
Send-Notification -title "OVERDUE TASKS" -content $content
|
||||
Send-AppriseNotification -title "OVERDUE TASKS" -content $content
|
||||
}
|
||||
|
||||
if ($todaysTasks.Count -ne 0)
|
||||
@@ -99,5 +66,5 @@ if ($todaysTasks.Count -ne 0)
|
||||
{
|
||||
$content += "$($task.Name) is due $((Get-Date $task.nextDueDate).ToLocalTime())`n"
|
||||
}
|
||||
Send-Notification -title "TODAY'S TASKS" -content $content
|
||||
Send-AppriseNotification -title "TODAY'S TASKS" -content $content
|
||||
}
|
||||
Reference in New Issue
Block a user