mirror of
https://github.com/block/buzz.git
synced 2026-11-01 23:11:58 +00:00
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <wpfleger@block.xyz> Signed-off-by: Will Pfleger <wpfleger@squareup.com> Signed-off-by: Will Pfleger <wpfleger96@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1fgdl5qqnh3k3f2xkqrvt7cujalhm623x4s7fdjdj5yrtp5fzjl9qrjpucw <4a1bfa0013bc6d14a8d600d8bf6392efefbd2a26ac3c96c9b2a106b0d12297ca@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub16v54tttfqacx9ycvc3k0ut0npj564ahcuajzy6qjvh57ntmsf4uq4806j2 <d32955ad69077062930cc46cfe2df30ca9aaf6f8e76422681265e9e9af704d78@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Will Pfleger <wpfleger96@gmail.com>
62 lines
2.2 KiB
Rust
62 lines
2.2 KiB
Rust
//! Action sink trait — interface for workflow side-effects.
|
|
//!
|
|
//! The relay implements [`ActionSink`] to provide direct DB access to the
|
|
//! executor, replacing the HTTP loopback pattern.
|
|
|
|
use std::future::Future;
|
|
use std::pin::Pin;
|
|
|
|
/// Errors from action sink operations.
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum ActionSinkError {
|
|
/// An input parameter is malformed (e.g. invalid UUID).
|
|
#[error("invalid input: {0}")]
|
|
InvalidInput(String),
|
|
/// The target channel does not exist.
|
|
#[error("channel not found: {0}")]
|
|
ChannelNotFound(String),
|
|
/// The target channel is archived.
|
|
#[error("channel is archived: {0}")]
|
|
ChannelArchived(String),
|
|
/// Nostr event construction or signing failed.
|
|
#[error("event construction failed: {0}")]
|
|
EventBuild(String),
|
|
/// A database operation failed.
|
|
#[error("database error: {0}")]
|
|
Database(String),
|
|
/// Message content is empty or whitespace-only.
|
|
#[error("empty message content")]
|
|
EmptyContent,
|
|
}
|
|
|
|
impl From<ActionSinkError> for crate::WorkflowError {
|
|
fn from(e: ActionSinkError) -> Self {
|
|
crate::WorkflowError::WebhookError(e.to_string())
|
|
}
|
|
}
|
|
|
|
/// Interface for workflow actions that produce side effects.
|
|
///
|
|
/// Implemented by the relay to provide direct DB/event access to the executor.
|
|
/// This replaces the HTTP loopback where the executor POSTed to the relay's
|
|
/// REST API (which failed with 401 auth errors).
|
|
///
|
|
/// Returns `Pin<Box<dyn Future>>` for dyn-compatibility — required because
|
|
/// `WorkflowEngine` stores `Arc<dyn ActionSink>`.
|
|
pub trait ActionSink: Send + Sync {
|
|
/// Post a message to a channel on behalf of a workflow owner.
|
|
///
|
|
/// - `channel_id`: UUID string of the target channel
|
|
/// - `text`: message body (must not be empty/whitespace-only)
|
|
/// - `author_pubkey`: hex-encoded pubkey of the workflow owner (used for
|
|
/// the `p` attribution tag; the relay keypair signs the event)
|
|
///
|
|
/// Returns the event ID hex string on success.
|
|
fn send_message(
|
|
&self,
|
|
channel_id: &str,
|
|
text: &str,
|
|
author_pubkey: &str,
|
|
) -> Pin<Box<dyn Future<Output = Result<String, ActionSinkError>> + Send + '_>>;
|
|
}
|