Platform-neutral successor to Discord Authenticator, forked from its v0.1.2
state with fresh history. Same vault, same UI, same live-message mechanism —
now behind one `Sink` that speaks three platforms.
Why each platform needs what it needs (this drove the whole settings model):
- Discord: an incoming-webhook URL. Webhooks can edit their own messages.
- Slack: a bot token (xoxb-, scope chat:write) + channel ID. Slack incoming
webhooks can post but never edit, and editing IS the live mechanism, so
chat.postMessage / chat.update via a bot is the only path.
- Telegram: a bot token + chat id. No webhook concept exists. The app detects
the chat id itself from the bot's pending updates ("send /start, then
Detect"), since users rarely know it.
- core: Provider enum; settings hold all three configs so switching back and
forth never re-asks for tokens; per-platform shape validation that names the
common mistakes (xoxp- user token, #name instead of channel ID); a
destination key that clears message ids on platform/channel change but not
on token rotation
- delivery: shared DeliveryError + pacing Governor; Discord client refactored
onto them; new Slack client (classifies Slack's ok:false-on-HTTP-200
errors) and Telegram client ("message is not modified" is success; chat
detection via getUpdates); provider-agnostic message builders — code in a
copyable span everywhere, rollover time as live as each platform allows
- http-api: setup accepts an optional provider; settings PUT/GET carry the
full model; /api/slack/whoami, /api/telegram/whoami, /api/telegram/chats
- webui: three-way optional picker on setup and in Settings → Delivery with
guided per-platform fields; "Check token" (Slack) and "Detect chat"
(Telegram); inline white mark via currentColor
- brand: white mark on the dark plate; blue stays with the Discord sibling
- docs/TEAMS.md: exploration for v0.2 — Teams connectors were disabled May
2026 and Workflows webhooks can't edit, so live tiles need a Bot Framework
bot; options for the inbound endpoint on a homelab and a recommended scope
Verified against mock Discord, Slack and Telegram servers speaking each
platform's real protocol shape: edits target the same message rather than
re-posting, deleted tiles are recovered, dead credentials are surfaced with a
next step, renames refresh without a rollover, and switching platform reposts
on the new one and leaves the old one alone. 138 tests.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
//! One error type for the whole domain core.
|
|
|
|
use std::fmt;
|
|
|
|
pub type Result<T> = std::result::Result<T, Error>;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum Error {
|
|
/// Caller supplied something we can't accept. Surfaces as HTTP 400 and
|
|
/// the message is written to be read by a human in a toast.
|
|
#[error("{0}")]
|
|
Invalid(String),
|
|
|
|
/// Asked for something that isn't there. Surfaces as HTTP 404.
|
|
#[error("{0} not found")]
|
|
NotFound(String),
|
|
|
|
/// Refused because it would clobber existing state. Surfaces as 409.
|
|
#[error("{0}")]
|
|
Conflict(String),
|
|
|
|
#[error("i/o error: {0}")]
|
|
Io(#[from] std::io::Error),
|
|
|
|
#[error("serialization error: {0}")]
|
|
Serde(#[from] serde_json::Error),
|
|
|
|
/// Vault could not be sealed or unsealed. Deliberately vague — the
|
|
/// detail goes to the log, not to the caller.
|
|
#[error("cryptography error: {0}")]
|
|
Crypto(String),
|
|
|
|
#[error(transparent)]
|
|
Other(#[from] anyhow_lite::Any),
|
|
}
|
|
|
|
impl Error {
|
|
pub fn invalid(msg: impl fmt::Display) -> Self {
|
|
Self::Invalid(msg.to_string())
|
|
}
|
|
pub fn not_found(what: impl fmt::Display) -> Self {
|
|
Self::NotFound(what.to_string())
|
|
}
|
|
pub fn conflict(msg: impl fmt::Display) -> Self {
|
|
Self::Conflict(msg.to_string())
|
|
}
|
|
pub fn crypto(msg: impl fmt::Display) -> Self {
|
|
Self::Crypto(msg.to_string())
|
|
}
|
|
}
|
|
|
|
/// A minimal boxed-error shim so `core` doesn't need the `anyhow` crate
|
|
/// just to carry the occasional opaque third-party error.
|
|
pub mod anyhow_lite {
|
|
#[derive(Debug, thiserror::Error)]
|
|
#[error("{0}")]
|
|
pub struct Any(pub String);
|
|
|
|
impl Any {
|
|
pub fn new(e: impl std::fmt::Display) -> Self {
|
|
Self(e.to_string())
|
|
}
|
|
}
|
|
}
|