hookburn_discord/lib.rs
1// crates/hookburn-discord/src/lib.rs
2#![deny(missing_docs)]
3
4//! Discord webhook client for Hookburn.
5//!
6//! This crate provides a client for sending messages to Discord via incoming webhooks.
7//! It implements the `WebhookSender` trait and can be used directly or through
8//! the unified `hookburn` crate.
9//!
10//! # Examples
11//!
12//! ## Direct usage
13//!
14//! ```rust,no_run
15//! use hookburn_discord::{WebhookClient, WebhookMessage, Embed};
16//!
17//! #[tokio::main]
18//! async fn main() -> Result<(), hookburn_discord::WebhookError> {
19//! let client = WebhookClient::new("https://discord.com/api/webhooks/ID/TOKEN")?;
20//!
21//! let message = WebhookMessage::builder()
22//! .content("Hello from Discord!")
23//! .username("MyBot")
24//! .build()?;
25//!
26//! client.send(&message).await
27//! }
28//! ```
29//!
30//! ## With the unified Hookburn client
31//!
32//! ```rust,no_run
33//! use hookburn::Hookburn;
34//! use hookburn_core::{ServiceConfig, GenericMessage};
35//!
36//! #[tokio::main]
37//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
38//! let hookburn = Hookburn::new();
39//!
40//! let config = ServiceConfig::new("https://discord.com/api/webhooks/ID/TOKEN");
41//! let sender = hookburn.create_sender("discord", config)?;
42//!
43//! let msg = GenericMessage::new("Hello from Hookburn!");
44//! sender.send(&msg).await?;
45//!
46//! Ok(())
47//! }
48//! ```
49
50/// Discord webhook client implementation.
51///
52/// Contains the main `WebhookClient` type and builder for sending messages to Discord.
53pub mod client;
54
55/// Error types for Discord webhook operations.
56///
57/// Defines `WebhookError` and all possible failure cases when interacting with Discord.
58pub mod error;
59
60/// Convenience macros for building Discord messages and embeds.
61///
62/// Provides `discord_message!` and `embed!` macros for concise message construction.
63pub mod macros;
64
65/// Message types and builders for Discord webhook payloads.
66///
67/// Contains `WebhookMessage`, `Embed`, `AllowedMentions`, and related types.
68pub mod message;
69
70/// Service registration for the Hookburn ecosystem.
71///
72/// Implements `ServiceBuilder` for Discord to enable unified service discovery.
73pub mod service;
74
75pub use client::{WebhookClient, WebhookClientBuilder};
76pub use error::WebhookError;
77pub use hookburn_core::WebhookSender;
78pub use message::{
79 AllowedMentionType, AllowedMentions, Embed, EmbedAuthor, EmbedBuilder, EmbedField, EmbedFooter,
80 EmbedImage, EmbedThumbnail, WebhookMessage, WebhookMessageBuilder, flags, json_code_block,
81};
82
83/// Register the Discord service with the global registry.
84///
85/// This function is called by the `hookburn` crate when the `discord` feature is enabled.
86/// It returns a `DiscordService` that implements the `ServiceBuilder` trait.
87///
88/// # Example
89///
90/// ```rust,no_run
91/// use hookburn_discord::register_service;
92/// use hookburn_core::WebhookRegistry;
93///
94/// let mut registry = WebhookRegistry::new();
95/// registry.register(register_service());
96/// ```
97pub fn register_service() -> service::DiscordService {
98 service::DiscordService::new()
99}