gleatfy

Types

Defintion for action buttons. If clear_after is set to True the message is marked as read after clicking on this button. See https://docs.ntfy.sh/publish/#action-buttons

pub type Action {
  View(label: String, url: String, clear_after: Bool)
  Http(
    label: String,
    request: Request(String),
    clear_after: Bool,
  )
  Broadcast(
    label: String,
    intent: String,
    extras: List(#(String, String)),
    clear_after: Bool,
  )
}

Constructors

  • View(label: String, url: String, clear_after: Bool)
  • Http(label: String, request: Request(String), clear_after: Bool)
  • Broadcast(
      label: String,
      intent: String,
      extras: List(#(String, String)),
      clear_after: Bool,
    )
pub opaque type Builder
pub type Error(a) {
  InvalidServerUrl(String)
  InvalidTopic(String)
  ClientError(a)
  InvalidServerResponse(String)
  ServerError(code: Int, http_status: Int, message: String)
}

Constructors

  • InvalidServerUrl(String)
  • InvalidTopic(String)
  • ClientError(a)
  • InvalidServerResponse(String)
  • ServerError(code: Int, http_status: Int, message: String)

Authentication method to use See https://docs.ntfy.sh/publish/#authentication

pub type Login {
  Basic(user: String, password: String)
  Token(token: String)
}

Constructors

  • Basic(user: String, password: String)
  • Token(token: String)

Notification message to send

pub type Message {
  Text(String)
  Markdown(String)
}

Constructors

  • Text(String)
  • Markdown(String)
pub type Priority {
  VeryHigh
  High
  Normal
  Low
  VeryLow
}

Constructors

  • VeryHigh
  • High
  • Normal
  • Low
  • VeryLow

Functions

pub fn actions(
  builder: Builder,
  are actions: List(Action),
) -> Builder

Add a list of action buttons for the notification See https://docs.ntfy.sh/publish/#action-buttons

Examples

new() |> actions(are: [View("Visit ntfy.sh", "https://ntfy.sh", True)])
  new()
|> actions(are: [
  Broadcast(
   "Take picture",
    "io.heckel.ntfy.USER_ACTION",
    [#("cmd", "pic"), #("camera", "front")],
   False,
 ),
])
  new()
  |> actions(are: [
    Http(
      "Close door",
      {
        let assert Ok(req) = request.to("https://api.mygarage.lan/")

        req
        |> request.set_method(http.Put)
        |> request.set_header("Authorization", "Bearer zAzsx1sk..")
        |> request.set_body("{\"action\": \"close\"}")
      },
      True,
    ),
  ])
}
pub fn attachment_filename(
  builder: Builder,
  is filename: String,
) -> Builder

Set a specific name for an attached file See https://docs.ntfy.sh/publish/#attach-file-from-a-url

pub fn attachment_url(
  builder: Builder,
  is attachment_url: String,
) -> Builder

Attach a file by a given URL See https://docs.ntfy.sh/publish/#attach-file-from-a-url

pub fn call(builder: Builder, to number: String) -> Builder

Set a phone number to be called to read the message out loud using text-to-speech See https://docs.ntfy.sh/publish/#phone-calls

pub fn click_url(
  builder: Builder,
  is click_url: String,
) -> Builder

Set an optional URL to open when the notification is clicked See https://docs.ntfy.sh/publish/#click-action

pub fn delay(builder: Builder, is delay: String) -> Builder

Set an optinal delay for notification delivery See https://docs.ntfy.sh/publish/#scheduled-delivery

pub fn email(builder: Builder, to email: String) -> Builder

Forward the notification to an email address See https://docs.ntfy.sh/publish/#e-mail-notifications

pub fn icon_url(builder: Builder, is icon_url: String) -> Builder

Set a notification icon by URL https://docs.ntfy.sh/publish/#icons

pub fn login(builder: Builder, with login: Login) -> Builder

Set the authentication method and data. Defaults to no authentication See https://docs.ntfy.sh/publish/#authentication

pub fn message(builder: Builder, is message: Message) -> Builder

Set the notification’s message body.

Examples

new() |> message(Text("Plain text"))
new() |> message(Markdown("**Markdown** text"))

For markdown messages see https://docs.ntfy.sh/publish/#markdown-formatting

pub fn new() -> Builder

Creates a fresh notification message builder

pub fn priority(
  builder: Builder,
  is priority: Priority,
) -> Builder

Set the notification’s priority See https://docs.ntfy.sh/publish/#message-priority

pub fn send(
  builder: Builder,
  using send_fn: fn(Request(String)) ->
    Result(Response(String), a),
) -> Result(String, Error(a))

Create the HTTP request, hands it over to send_fn and decodes its return value

Example

new() |> topic("alert") |> send(https.send)
/// -> Ok("message-id")
pub fn server(builder: Builder, is server: String) -> Builder

Set the ntfy instance to use. Defaults to https://ntfy.sh

pub fn tags(builder: Builder, are tags: List(String)) -> Builder

Set optional tags for the notification See https://docs.ntfy.sh/publish/#tags-emojis

pub fn title(builder: Builder, is title: String) -> Builder

Set the notification’s title. See https://docs.ntfy.sh/publish/#message-title

pub fn topic(builder: Builder, is topic: String) -> Builder

Set the mandatory topic to send the notification to.

pub fn without_firebase(builder: Builder) -> Builder

Tell the server not to send this notification to FCM See https://docs.ntfy.sh/publish/#disable-firebase

pub fn without_message_cache(builder: Builder) -> Builder

Tell the server not to cache this notification See https://docs.ntfy.sh/publish/#message-caching

Search Document