FYI (FYI v1.0.2)
View SourceIn-app events & feedback with Slack/Telegram notifications.
FYI provides a simple way to:
- Emit events from your app (waitlist signups, purchases, etc.)
- Get notified in Slack and Telegram when things happen
- Optionally persist events to the database
Quick Start
# Emit an event
FYI.emit("purchase.created", %{amount: 4900, currency: "GBP"}, actor: user_id)
# Emit from Ecto.Multi (recommended)
Ecto.Multi.new()
|> Ecto.Multi.insert(:purchase, changeset)
|> FYI.Multi.emit("purchase.created", fn %{purchase: p} ->
%{payload: %{amount: p.amount}, actor: p.user_id}
end)
|> Repo.transaction()Configuration
config :fyi,
persist_events: true,
repo: MyApp.Repo,
sinks: [
{FYI.Sink.SlackWebhook, %{url: System.get_env("SLACK_WEBHOOK_URL")}},
{FYI.Sink.Telegram, %{
token: System.get_env("TELEGRAM_BOT_TOKEN"),
chat_id: System.get_env("TELEGRAM_CHAT_ID")
}}
],
routes: [
%{match: "waitlist.*", sinks: [:slack]},
%{match: "purchase.*", sinks: [:slack, :telegram]}
]
Summary
Functions
@spec emit(String.t(), map(), keyword()) :: {:ok, FYI.Event.t()} | {:error, term()}
Emits an event with the given name and payload.
The event is:
- Optionally persisted to the database (if
persist_events: true) - Asynchronously sent to configured sinks
Options
:actor- who triggered the event (user_id, email, etc.):tags- additional metadata map for filtering/routing:source- where the event originated
Examples
FYI.emit("user.signup", %{email: "user@example.com"})
FYI.emit("purchase.created", %{amount: 4900}, actor: user_id, tags: %{plan: "pro"})
@spec emit!(String.t(), map(), keyword()) :: FYI.Event.t()
Same as emit/3 but raises on error.
Subscribes to real-time FYI events. Used by the FYI inbox LiveView for live updates.