Post

NtfyPwsh TMI Edition

NtfyPwsh TMI Edition

NtfyPwsh TMI edition!

ntfy icon

Full examples with explanations for the NtfyPwsh module.

๐Ÿ“ฌ Send-NtfyMessage Cmdlet Overview

The Send-NtfyMessage cmdlet is the primary way to send notifications using the NtfyPwsh module. It supports a wide range of parameters to customize your notifications, including scheduling, formatting, attachments, actions, and more.

Parameters:

  • -Topic (String, Required): The topic/channel to send the notification to.
  • -Body (String,): The main message body.
  • -Title (String): Optional notification title.
  • -Priority (String): Set notification priority. Valid: โ€˜Minโ€™, โ€˜Lowโ€™, โ€˜Defaultโ€™, โ€˜Highโ€™, โ€˜Maxโ€™.
  • -Tags (Array): Add tags or emojis to the notification.
  • -Delay (String): Schedule delivery (timestamp, duration, or natural language).
  • -Action (Object): Add action buttons (use with Build-NtfyAction).
  • -OnClick (String): URL to open when notification is clicked.
  • -AttachmentPath (String): Local file path to attach.
  • -AttachmentURL (String): URL of file to attach.
  • -AttachmentName (String): Custom filename for attachment.
  • -Markdown (Switch): Enable Markdown formatting in the body.
  • -Icon (String): URL or emoji for notification icon.
  • -Email (String): Send notification to an email address.
  • -Phone (String): Trigger a phone call.
  • -NoCache (Switch): Prevent message from being cached on the server.
  • -FirebaseNo (Switch): Prevent forwarding to Firebase (FCM).
  • -Credential (PSCredential): PowerShell credential for basic authentication.
  • -TokenCreds (PSCredential): PowerShell credential for API token authentication.
  • -URI (String): Custom ntfy server URL (defaults to https://ntfy.sh).

โ„น๏ธ For a full parameter mapping, see the Parameter Mapping Table.

๐Ÿ“จ Publish a Basic Notification.

The simplest way to send a notification is with a topic, title, and body. This will send a notification to the default public ntfy.sh server, and anyone subscribed to the topic will receive it. You can use this for quick alerts, reminders, or any message you want to broadcast.

1
2
3
4
5
6
$ntfy = @{
    Topic = 'ntfypwsh'
    Body  = 'This is a test message'
    Title = 'Test Title'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Publishing

This sends a notification to the public โ€œntfypwshโ€ on ntfy.sh. Anyone subscribed to this topic will receive the notification. You can customize the Topic, Body, and Title as needed for your use case.

๐Ÿ“ Note: The -URI parameter defaults to https://ntfy.sh if not specified. If youโ€™re using a self-hosted instance, be sure to provide your instance URL with the -URI parameter.

๐Ÿ“จ Sending Basic Notifications to custom URL

Add the URI parameter and your instance address.

1
2
3
4
5
6
7
$ntfy = @{
    Topic = 'ntfypwsh'
    Body  = 'This is a test message'
    Title = 'Test Title'
    URI   = 'https://myntfy.mydomain.com'
}
Send-NtfyMessage @ntfy

๐Ÿ“จ Sending with message priority

You can set the priority of your notification using the Priority parameter. This controls how the notification is displayed and alerted on the recipientโ€™s device.

You can set Priority to one of the following options:

  • โ€˜Minโ€™
  • โ€˜Lowโ€™
  • โ€˜Defaultโ€™
  • โ€˜Highโ€™
  • โ€˜Maxโ€™

Example of sending a high-priority notification:

1
2
3
4
5
6
7
$ntfy = @{
    Topic    = 'ntfypwsh'
    Body     = 'This is an urgent message!'
    Title    = 'Urgent Alert'
    Priority = 'Max'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Message Priority

๐Ÿท๏ธ Tags & Emojis

You can add tags (including emojis) to your notifications using the -Tags parameter. Tags can help categorize or visually enhance your messages. Some emojis are mapped to special tag names in ntfy.

Some available emoji options for -Tags parameter:

  • ๐Ÿ‘
  • ๐Ÿ‘Ž๏ธ
  • ๐Ÿคฆ
  • ๐Ÿฅณ
  • โš ๏ธ
  • โ›”
  • ๐ŸŽ‰
  • ๐Ÿšจ
  • ๐Ÿšซ
  • โœ”๏ธ
  • ๐Ÿšฉ
  • ๐Ÿ’ฟ
  • ๐Ÿ“ข
  • ๐Ÿ’€
  • ๐Ÿ’ป

๐Ÿ’ก You can use tab completion in PowerShell to pick an emoji icon, or use a text value from the emoji short code list (see the full emoji list link below).

๐Ÿ“– Further reading: ntfy documentation โ€“ Tags & Emojis
๐Ÿ”— Full emoji list: ntfy supported emojis

Example of sending a notification with tags and emojis:

1
2
3
4
5
6
7
$ntfy = @{
    Topic = 'ntfypwsh'
    Body  = 'Backup completed successfully!'
    Title = 'Backup Status'
    Tags  = @('โœ”๏ธ','๐Ÿ’ป','green_circle')
}
Send-NtfyMessage @ntfy

๐Ÿ“ Markdown Formatting Example

You can enable Markdown formatting in your notification body using the -Markdown parameter. For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic    = 'ntfypwsh'
    Body     = "Look ma, **bold text**, *italics*, ..."
    Title    = 'Markdown baby!'
    Markdown = $true
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Markdown Formatting

โฐ Scheduled Delivery

Example of sending a scheduled notification:

You can schedule delivery by specifying:

  • a Unix timestamp (e.g. 1639194738)
  • a duration (e.g. 30m, 3h, 2 days)
  • a natural language time string (e.g. 10am, tomorrow, Tuesday, 7am, etc.)
1
2
3
4
5
6
7
$ntfy = @{
    Topic = 'ntfypwsh'
    Title = "Sent $((get-date).ToString())"
    Body = 'This message will be delivered after 1 minute.'
    Delay = '1m'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Scheduled Delivery
๐Ÿ”— Natural language time parser: when on GitHub

๐Ÿ› ๏ธ Action Buttons

You can add action buttons to notifications to allow yourself to react to a notification directly. This is incredibly useful and has countless applications. For example, you can control home appliances, respond to monitoring alerts, or trigger custom automationsโ€”all from your notification.

As of today, the following actions are supported:

๐Ÿ“– Further reading: ntfy documentation โ€“ Action Buttons

๐Ÿงฉ Build-NtfyAction Cmdlet Overview

You can use the Build-NtfyAction cmdlet to construct action button definitions for your notifications. This cmdlet helps you create properly formatted action headers for ntfy messages that require user interaction or automation. You can include up to 3 actions per notification.

Parameters:

  • -ActionView (Switch): Specify to create a โ€˜viewโ€™ action (open website/app).
  • -ActionHttp (Switch): Specify to create an โ€˜httpโ€™ action (send HTTP request).
  • -ActionBroadcast (Switch): Specify to create a โ€˜broadcastโ€™ action (Android only).
  • -Label (String, Required): The label for the action button or link.
  • -URL (String, Required for view/http): The URL associated with the action.
  • -Clear (Switch): If specified, clears the notification after the action is triggered.
  • -Method (String, http only): HTTP method for http actions. Valid: โ€˜GETโ€™, โ€˜POSTโ€™, โ€˜PUTโ€™, โ€˜DELETEโ€™. Default: โ€˜POSTโ€™.
  • -Body (String, http only): Optional body content for http actions.
  • -Headers (Hashtable, http only): Optional headers for http actions.
  • -Intent (String, broadcast only): Optional intent for broadcast actions (Android only).
  • -Extras (Hashtable, broadcast only): Optional extras for broadcast actions (Android only).

View Action

1
2
3
4
5
6
7
8
$action = Build-NtfyAction -ActionView -Label 'Open Website' -URL 'https://ntfy.sh'
$ntfy = @{
    Topic  = 'ntfypwsh'
    Title = 'Ntfy link'
    Body   = 'Tap to open ntfy.'
    Action = $action
}
Send-NtfyMessage @ntfy

HTTP Action

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$http = @{
    ActionHttp = $true
    Label = 'Publish Ntfy.sh'
    URL = 'https://ntfy.sh/ntfypwsh'
    Body = 'Sent a post api to myself'
}

$action = Build-NtfyAction @http

$ntfy = @{
    Topic = 'ntfypwsh'
    Action = $action
    Title = 'Send a Post HTTP'
    Body = 'This will publish another message to this topic'
}

Send-NtfyMessage @ntfy

Broadcast Action (Android only)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$broadcast = @{
    ActionBroadcast = $true
    Label = 'Take Screenshot'
    Extras = @{
        cmd = 'screenshot'
    }
}

$action = Build-NtfyAction @broadcast

$SendBroadcast = @{
    Topic = 'ntfypwsh'
    Action = $action
    Title = 'screenshot'
    Body = 'Please take a screenshot.'
    TokenCreds = $creds
}

Send-NtfyMessage @SendBroadcast

๐Ÿ–ฑ๏ธ Click Action Example

You can use the -OnClick parameter to specify a URL to open when the notification is clicked. For example, to open Reddit messages when the notification is clicked:

1
2
3
4
5
6
$ntfy = @{
    Topic  = 'ntfypwsh'
    Body   = 'Check out Ntfy!'
    OnClick = 'https://ntfy.sh'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Click Action

๐Ÿ“Ž Local File Attachment Example

You can attach a local file to your notification using the -AttachmentPath parameter. For example:

1
2
3
4
5
6
7
8
$ntfy = @{
    Topic          = 'ntfypwsh'
    Body           = 'This is a test message with attachment'
    Title          = 'Test attachment'
    AttachmentPath = 'D:\Downloads\avatar.jpg'
    AttachmentName = 'My Avatar'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Attach Local File

๐ŸŒ Attachment from URL Example

You can attach a file from a URL to your notification using the -AttachmentURL parameter. For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic         = 'ntfypwsh'
    Body          = 'This message has an attachment from a URL.'
    Title         = 'Attachment from URL'
    AttachmentURL = 'https://github.com/loganmarchione/homelab-svg-assets/blob/main/assets/ntfy.svg'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Attach File from a URL

๐Ÿ–ผ๏ธ Icon Example (Android only)

You can specify an icon for your notification using the -Icon parameter. The icon can be a URL to a PNG/JPEG image or an emoji (Android only). For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic = 'ntfypwsh'
    Body  = 'This message has a custom icon.'
    Title = 'Icon Example'
    Icon  = 'https://styles.redditmedia.com/t5_32uhe/styles/communityIcon_xnt6chtnr2j21.png'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Icons

๐Ÿ“ง Email Notification Example

You can send a notification to an email address using the -Email parameter. For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic = 'ntfypwsh'
    Body  = 'This message will be sent to your email.'
    Title = 'Email Example'
    Email = 'email@email.com'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ E-mail Notifications

๐Ÿ“ž Phone Call Example

You can send a notification that triggers a phone call using the -Phone parameter. The phone number must be in international format (e.g. +12345678901). For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic = 'ntfypwsh'
    Body  = 'This message will trigger a phone call.'
    Title = 'Phone Call Example'
    Phone = '+12345678901'
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Phone Calls

๐Ÿšซ No-Cache Example

You can prevent a message from being cached on the server using the -NoCache parameter. For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic   = 'ntfypwsh'
    Body    = 'This message will not be cached on the server.'
    Title   = 'No-Cache Example'
    NoCache = $true
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Message Caching

๐Ÿ“ต Disable Firebase Forwarding Example

You can prevent a message from being forwarded (if configured) to Firebase (FCM) using the -FirebaseNo parameter. For example:

1
2
3
4
5
6
7
$ntfy = @{
    Topic      = 'ntfypwsh'
    Body       = "This message won't be forwarded to FCM."
    Title      = 'No Firebase Example'
    FirebaseNo = $true
}
Send-NtfyMessage @ntfy

๐Ÿ“– Further reading: ntfy documentation โ€“ Disable Firebase

๐Ÿ” Authentication Examples

You can authenticate with ntfy using either basic authentication (username and password) or an API token. For more details, see the ntfy documentation โ€“ Authentication.

Basic Authentication (Username & Password)

1
2
3
4
5
6
7
8
$creds = Get-Credential -UserName ntfy # change to username, run command and enter password.
$ntfy = @{
    Topic      = 'ntfypwsh'
    Body       = 'This message uses basic authentication.'
    Title      = 'Basic Auth Example'
    Credential = $creds
}
Send-NtfyMessage @ntfy

API Token Authentication

1
2
3
4
5
6
7
8
$token = Get-Credential -UserName ntfy # Enter your API token as the password, username can be anything
$ntfy = @{
    Topic      = 'ntfypwsh'
    Body       = 'This message uses API token authentication.'
    Title      = 'API Token Example'
    TokenCreds = $token
}
Send-NtfyMessage @ntfy

๐Ÿ“‘ Parameter Mapping Table

Below is a mapping of ntfy headers/parameters to the corresponding PowerShell parameters in Send-NtfyMessage:

ntfy HeaderAliasesPowerShell ParameterDescription
X-MessageMessage, mBodyMain body of the message as shown in the notification
X-TitleTitle, tTitleMessage title
X-PriorityPriority, prio, pPriorityMessage priority
X-TagsTags, Tag, taTagsTags and emojis
X-DelayDelay, X-At, At, X-In, InDelayTimestamp or duration for delayed delivery
X-ActionsActions, ActionActionJSON array or short format of user actions
X-ClickClickOnClickURL to open when notification is clicked
X-AttachAttach, aAttachmentURLURL to send as an attachment (alternative to file upload)
X-MarkdownMarkdown, mdMarkdownEnable Markdown formatting in the notification body
X-IconIconIconURL to use as notification icon
X-FilenameFilename, file, fAttachmentNameOptional attachment filename, as it appears in the client
X-EmailX-E-Mail, Email, E-Mail, mail, eEmailE-mail address for e-mail notifications
X-CallCallPhonePhone number for phone calls
X-CacheCacheNoCacheAllows disabling message caching
X-FirebaseFirebaseFirebaseNoAllows disabling sending to Firebase
X-UnifiedPushUnifiedPush, up(not exposed)UnifiedPush publish option, only to be used by UnifiedPush apps
X-Poll-IDPoll-ID(not exposed)Internal parameter, used for iOS push notifications
Authorization-Credential/TokenCredsFor authentication (username/password or API token)
Content-Type-Markdown (if set to markdown)If set to text/markdown, Markdown formatting is enabled
This post is licensed under CC BY 4.0 by the author.