Sexy.Bot.Notification (Sexy v0.9.13)

Copy Markdown View Source

Send notification messages with dismiss and navigate buttons.

Notifications are messages sent to a chat that are separate from the main screen flow. They support two modes:

Overlay mode (default)

Sends a message without replacing the current screen. Adds a dismiss button so the user can remove the notification:

Sexy.Bot.notify(chat_id, %{text: "Action completed!"})

Replace mode

Replaces the current active screen. The notification becomes the new screen (mid is updated via Session):

Sexy.Bot.notify(chat_id, %{text: "Payment received!"}, replace: true)

Navigation buttons

Add a button that deletes the notification and navigates to a command. Sexy wraps this into the built-in /_transit route:

Sexy.Bot.notify(chat_id, %{text: "New order #42"},
  navigate: {"View Order", "/order id=42"}
)

You can also pass a function for custom callback data:

Sexy.Bot.notify(chat_id, %{text: "Alert"},
  navigate: {"Details", fn mid -> "/show mid=#{mid}" end}
)

Options

  • :replacefalse (default) for overlay, true to replace screen
  • :navigate{button_text, path} or {button_text, fn mid -> callback end}
  • :dismiss_text — custom dismiss button text (default: "OK")
  • :extra_buttons — additional button rows as [[%{text: ..., callback_data: ...}]]
  • :after — auto-delete the notification after N seconds (integer or float)

Summary

Functions

Send a notification to a chat.

Types

navigate_opt()

@type navigate_opt() ::
  {String.t(), String.t()} | {String.t(), (integer() -> String.t())}

notify_opt()

@type notify_opt() ::
  {:replace, boolean()}
  | {:navigate, navigate_opt()}
  | {:dismiss_text, String.t()}
  | {:extra_buttons, [[map()]]}
  | {:after, number()}

Functions

notify(chat_id, message, opts \\ [])

@spec notify(integer(), map(), [notify_opt()]) :: map()

Send a notification to a chat.

message is a map like %{text: "..."} or %{upload_type: :document, file: "...", filename: "..."} (also supports :photo, :video, :animation).

Options:

  • navigate: {"Button Text", "/command query"} — transit button (auto-wraps to /_transit)
  • navigate: {"Button Text", fn mid -> "..." end} — custom callback with mid injection
  • replace: false (default) — overlay mode, dismissable
  • replace: true — replaces current screen, no dismiss
  • extra_buttons: [[%{text: ..., ...}]] — extra button rows appended after navigate/dismiss
  • dismiss_text: "text" — custom dismiss button text
  • after: seconds — auto-delete the notification after delay