Allows to publish a ntfy notification using a fluent builder configuration.
Create valimport { ntfy } from "https://esm.town/v/xkonti/ntfy";
await ntfy()
.toServer(Deno.env.get("ntfyServer"))
.asUser(Deno.env.get("ntfyUser"), Deno.env.get("ntfyPassword"))
.toTopic("testing")
.withMessage("Hello there!")
.withTitle("First test")
.withViewAction("My website", "https://xkonti.tech")
.withTags("package", "val-town")
.withPriority("high")
.publish();
⚠️ For the notification to be sent it needs to be published (publish
function).
Executes specified functions that can modify the notification. Can be used to streamline authentication, apply common operations, etc.
Create valimport { ntfy } from "https://esm.town/v/xkonti/ntfy";
const toMyNtfyServer = (builder: ReturnType<typeof ntfy>) => {
builder
.toServer(Deno.env.get("ntfyServer"))
.asUser(Deno.env.get("ntfyUser"), Deno.env.get("ntfyPassword"));
};
await ntfy()
.use(toMyNtfyServer)
.toTopic('home-automation')
.withMessage('You left the front door open')
.publish();
You can pass it multiple functions.
Specifies a server that the notification will be sent do. By default it's https://ntfy.sh
.
Authenticates with the user and password. Please use ValTown's secrets for this.
Authenticates using the provided token. Please use ValTown's secrets for this.
Specifies which topic to publish the message to.
Specifies the main message of the notification. You can also flag it as markdown by passing true
as a second argument. By default markdown
is false
.
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('Your garage is **flooding**!', true)
...
Sets the title of the notification.
Create valawait ntfy()
.toTopic('home-automation')
.withTitle('Garage')
.withMessage('You left the front door open')
...
Sets the priority of the notification. Possible from lowest to highest priority: min
, low
, default
, high
, max
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withPriority('high')
...
Alternatively you can use dedicated functions: .withMinPriority()
, .withLowPriority()
, .withDefaultPriority()
, .withHighPriority()
, .withMaxPriority()
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withHighPriority()
...
Sets tags of the notification. This overrides any previously existing tags.
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withTags('door', 'safety')
...
Sets the delay for notification delivery. Read ntfy docs for more info.
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withDelay('tomorrow, 10am')
...
Adds an action button that opens a website or app when tapped.
label
- Label of the action button in the notificationurl
- URL to open when action is tappedclear
- Clear notification after action button is tapped (defaults tofalse
)
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withViewAction('View Val', 'https://www.val.town/v/xkonti/ntfy')
...
Adds an action button that sends an Android broadcast intent when tapped.
label
- Label of the action button in the notificationintent
- Android intent name, default isio.heckel.ntfy.USER_ACTION
extras
- Android intent extras.clear
- Clear notification after action button is tapped (defaults tofalse
)
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withBroadcastAction('Selfie', 'Take picture', { 'cmd': 'pic' })
...
Adds an action button that sends a HTTP request when tapped.
label
- Label of the action button in the notificationurl
- URL to which the HTTP request will be sentmethod
- HTTP method to use for request, default isPOST
headers
- HTTP headers to pass in request.body
- HTTP body as a stringclear
- Clear notification after action button is tapped (defaults tofalse
)
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withHtmlAction(
'Self-destruct',
'https://self.destruct/initiate',
'POST',
{ 'Authentication': 'Bearer 123' },
'{"countdown":60}'
)
...
Makes the notification open the specified URL when clicked (tapped).
Attached a file to the notification. Only one file can be attached.
Create valawait ntfy()
.toTopic('home-automation')
.withMessage('You left the front door open')
.withRawAttachment('todo.txt', 'Nothing!')
...
Attaches a file that is hosted elsewhere (URL).
Sets an icon for the notification.
Sends the notification via email instead.
Sends the notification via a phone call. The number defaults to yes
, which makes it use the first phone number defined on your ntfy account.
Disables the cache for the notification. Read the docs on caching for more info.
Disables Firebase forwarding for the notification. Read the docs on Firebase for more info.
Indicates intent of using the Unified Push for the notification. Read the docs on Unified Push for more info.