pub struct Message { /* private fields */ }Expand description
Builder for a Bark-compatible push message.
Message serializes to the JSON payload sent to APNs. For normal pushes it
writes both APNs aps fields and Bark custom fields. For encrypted pushes it
encrypts Bark request fields into ciphertext and keeps only the APNs
placeholder alert plus ciphertext/iv in clear text.
Start with Message::new and chain the fields that should be present:
use bark_apns::{InterruptionLevel, Message};
let message = Message::new()
.title("Build")
.body("finished")
.group("ci")
.level(InterruptionLevel::TimeSensitive);Implementations§
Source§impl Message
impl Message
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty message builder.
The default title is "Notification", the default level is
InterruptionLevel::Active, and no sound is set. A normal notification
must eventually contain either Message::body or Message::markdown.
Delete messages created with Message::delete do not require content.
Sourcepub fn title<T>(self, title: T) -> Self
pub fn title<T>(self, title: T) -> Self
Sets the push title.
If omitted, Bark receives "Notification" as the title.
Sourcepub fn subtitle<S>(self, subtitle: S) -> Self
pub fn subtitle<S>(self, subtitle: S) -> Self
Sets the push subtitle.
Bark maps this to the notification subtitle when the value is present. Empty or whitespace-only values are omitted.
Sourcepub fn body<B>(self, body: B) -> Self
pub fn body<B>(self, body: B) -> Self
Sets the plain-text push body.
Bark uses this as the notification body unless markdown is also
provided. For encrypted pushes, this value is included inside the
encrypted Bark JSON.
Sourcepub fn markdown<M>(self, markdown: M) -> Self
pub fn markdown<M>(self, markdown: M) -> Self
Sets the Markdown body.
Bark’s notification service extension renders this value and treats it as
taking precedence over body for display. Empty or whitespace-only values
are omitted.
Bark parses Markdown with Apple’s Swift Markdown package and its own
MarkdownParser. The parser handles paragraphs, headings, block quotes,
strong emphasis, emphasis, strikethrough, inline code, fenced or indented
code blocks, links, images, ordered lists, unordered lists, nested list
indentation, task-list checkboxes, soft breaks, and hard line breaks.
For push notification display, Bark’s notification service extension uses
the parsed attributed string’s plain .string value as the notification
body and collapses repeated blank lines. That means visual styles such as
bold, italic, strikethrough, link color, code font, and quote color are
not preserved in the notification banner itself; the rendered text,
headings, list markers, checkbox symbols, code text, link text, and image
alt text remain.
Sourcepub fn image<I>(self, image: I) -> Self
pub fn image<I>(self, image: I) -> Self
Sets a push image URL.
Bark downloads this image in the notification service extension and attaches it to the notification when possible. Empty or whitespace-only values are omitted.
Sourcepub fn level(self, level: InterruptionLevel) -> Self
pub fn level(self, level: InterruptionLevel) -> Self
Sets the notification interruption level.
Defaults to InterruptionLevel::Active. Critical notifications may
require the Bark app and APNs topic to have the appropriate entitlement.
Sourcepub fn volume(self, volume: u8) -> Self
pub fn volume(self, volume: u8) -> Self
Sets the critical alert volume from 0 to 10.
Bark uses this value for level=critical. Values larger than 10 are
clamped to 10.
Sourcepub fn badge(self, badge: u64) -> Self
pub fn badge(self, badge: u64) -> Self
Sets the app badge number.
The value is serialized into APNs aps.badge and Bark’s badge
parameter.
Sourcepub fn auto_copy(self, auto_copy: bool) -> Self
pub fn auto_copy(self, auto_copy: bool) -> Self
Sets Bark’s automatic copy flag.
Bark interprets "1" as enabled. On newer iOS versions the user may
still need to long-press or expand the notification to copy.
Sourcepub fn copy<C>(self, copy: C) -> Self
pub fn copy<C>(self, copy: C) -> Self
Sets the text Bark should copy when automatic copy runs.
If omitted, Bark copies the notification body. Empty or whitespace-only values are omitted.
Sourcepub fn sound<S>(self, sound: S) -> Self
pub fn sound<S>(self, sound: S) -> Self
Sets the Bark sound name.
This crate does not set a default sound, matching Bark’s request
semantics. For normal pushes, APNs receives aps.sound; if the value does
not end in .caf, the APNs sound name is suffixed with .caf. For
encrypted pushes, the sound is kept inside the encrypted Bark JSON and is
not exposed in clear text.
Sourcepub fn call(self, call: bool) -> Self
pub fn call(self, call: bool) -> Self
Enables or disables Bark’s repeated call-style ringing.
Bark expects "1" to enable this behavior. Passing false omits the
field.
Sourcepub fn icon<I>(self, icon: I) -> Self
pub fn icon<I>(self, icon: I) -> Self
Sets a custom icon URL.
Bark’s notification service extension downloads and caches the icon, then uses it to replace the default Bark icon when iOS supports the feature. Empty or whitespace-only values are omitted.
Sourcepub fn group<G>(self, group: G) -> Self
pub fn group<G>(self, group: G) -> Self
Sets the Bark group name.
The group is used for Notification Center grouping and for Bark’s history
grouping. Normal pushes also set APNs aps.thread-id.
Sourcepub fn archive(self, archive: bool) -> Self
pub fn archive(self, archive: bool) -> Self
Sets Bark’s archive flag.
true serializes "1" and asks Bark to save the push to history.
false serializes "0" and asks Bark not to archive it. If omitted,
Bark uses the app’s own archive setting.
Sourcepub fn ttl(self, ttl: u64) -> Self
pub fn ttl(self, ttl: u64) -> Self
Sets the archive time-to-live in seconds.
Bark applies this only to messages saved to history.
Sourcepub fn url<U>(self, url: U) -> Self
pub fn url<U>(self, url: U) -> Self
Sets the URL opened when the notification is tapped.
Bark supports URL schemes and universal links. Empty or whitespace-only values are omitted.
Sourcepub fn action<A>(self, action: A) -> Self
pub fn action<A>(self, action: A) -> Self
Sets Bark’s action parameter.
Bark documents action=alert as showing an action popup when the user
opens the app from the notification.
Sourcepub fn id<I>(self, id: I) -> Self
pub fn id<I>(self, id: I) -> Self
Sets the Bark message id.
The same id can update a delivered notification. It is also required for delete messages. APNs collapse ids must be at most 64 bytes, so this crate validates the id before sending.
Sourcepub fn delete(self) -> Self
pub fn delete(self) -> Self
Marks this message as a Bark delete request.
Delete requests serialize as a background APNs payload with delete=1
and require Message::id. They do not require body or markdown
content.
Sourcepub fn encryption(self, encryption: Encryption) -> Self
pub fn encryption(self, encryption: Encryption) -> Self
Encrypts Bark request fields before sending.
The APNs payload will contain the placeholder alert plus top-level
ciphertext and, for CBC/GCM, iv. Fields such as title, body,
markdown, sound, group, and badge are placed in the encrypted JSON
rather than clear-text APNs custom fields.