Skip to main content

Message

Struct Message 

Source
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

Source

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.

Source

pub fn title<T>(self, title: T) -> Self
where T: Into<String>,

Sets the push title.

If omitted, Bark receives "Notification" as the title.

Source

pub fn subtitle<S>(self, subtitle: S) -> Self
where S: Into<String>,

Sets the push subtitle.

Bark maps this to the notification subtitle when the value is present. Empty or whitespace-only values are omitted.

Source

pub fn body<B>(self, body: B) -> Self
where B: Into<String>,

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.

Source

pub fn markdown<M>(self, markdown: M) -> Self
where M: Into<String>,

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.

Source

pub fn image<I>(self, image: I) -> Self
where I: Into<String>,

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn copy<C>(self, copy: C) -> Self
where C: Into<String>,

Sets the text Bark should copy when automatic copy runs.

If omitted, Bark copies the notification body. Empty or whitespace-only values are omitted.

Source

pub fn sound<S>(self, sound: S) -> Self
where S: Into<String>,

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.

Source

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.

Source

pub fn icon<I>(self, icon: I) -> Self
where I: Into<String>,

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.

Source

pub fn group<G>(self, group: G) -> Self
where G: Into<String>,

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.

Source

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.

Source

pub fn ttl(self, ttl: u64) -> Self

Sets the archive time-to-live in seconds.

Bark applies this only to messages saved to history.

Source

pub fn url<U>(self, url: U) -> Self
where U: Into<String>,

Sets the URL opened when the notification is tapped.

Bark supports URL schemes and universal links. Empty or whitespace-only values are omitted.

Source

pub fn action<A>(self, action: A) -> Self
where A: Into<String>,

Sets Bark’s action parameter.

Bark documents action=alert as showing an action popup when the user opens the app from the notification.

Source

pub fn id<I>(self, id: I) -> Self
where I: Into<String>,

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Message

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more