Omnihook
omnihook is a flexible, type-safe Rust library for sending webhook notifications to various platforms. It provides platform-specific payload builders for Slack, Discord, Telegram, and generic endpoints, with built-in support for HMAC-SHA256 signing.
Features
- Multi-Platform Support: Built-in builders for:
- Slack: Blocks-based messages with mrkdwn.
- Discord: Content-based messages with markdown.
- Telegram: MarkdownV2 formatted messages with chat ID support.
- Generic: Custom JSON payloads with template variables.
- HMAC Signing: Secure your webhooks with HMAC-SHA256 signatures and timestamps.
- Middleware Support: Built on top of
reqwest-middlewarefor extensible HTTP client behavior. - Async/Await: Native async support for high-performance notification delivery.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Example
use ;
use Url;
async
Customizing HTTP Client (Middleware)
Since omnihook uses reqwest-middleware, you can add retries, logging, or caching. To do this, provide your own Arc<ClientWithMiddleware> to WebhookClient::new:
use Arc;
use ClientBuilder;
use ;
use ;
use Url;
async
HMAC Signing & Security
omnihook supports automatic payload signing using HMAC-SHA256. When a secret is provided in the configuration, every request will include x-signature and x-timestamp headers.
use ;
use Url;
async
Payload Builders
The library uses the WebhookPayloadBuilder trait to allow for easy extensibility:
Slack
Uses Slack's Block Kit for structured messages.
use ;
let builder = default;
let payload = builder.build_payload;
// Returns: { "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "*Alert*\n\nSomething happened" } } ] }
Discord
Simple markdown-enabled content messages.
use ;
let builder = default;
let payload = builder.build_payload;
// Returns: { "content": "*Alert*\n\nSomething happened" }
Telegram
Handles required chat_id and MarkdownV2 escaping.
use ;
let builder = TelegramPayloadBuilder ;
let payload = builder.build_payload;
// Returns: { "chat_id": "123456789", "text": "*Alert* \n\nSomething happened", "parse_mode": "MarkdownV2", ... }
Generic
Producing a standard high-level JSON object.
use ;
let builder = default;
let payload = builder.build_payload;
// Returns: { "title": "Alert", "body": "Something happened" }
License
- MIT license (http://opensource.org/licenses/MIT)