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 optional HMAC-SHA256 signing.
Features
- Multi-Platform Support: Built-in builders for:
- Slack: Blocks-based messages with mrkdwn.
- Discord: Content-based messages with markdown.
- Telegram: HTML-formatted messages with markdown support and chat ID.
- Generic: Custom JSON payloads with optional HMAC signing and idempotency keys.
- Middleware Support: Built on top of
reqwest-middlewarefor extensible HTTP client behavior. - Async/Await: Native async support for high-performance notification delivery.
- Ready-to-use Examples: Check the examples/ directory for platform-specific implementations.
Installation
Add this to your Cargo.toml:
[]
= "0.1.1"
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 (Generic Only)
omnihook supports automatic payload signing using HMAC-SHA256 for Generic webhooks. When a secret is provided in the configuration, every request will include x-signature and x-timestamp headers. Use this when sending notifications to a custom endpoint where you wish to verify the payload's integrity.
use ;
use Url;
async
Idempotency Keys (Optional)
You can pass an optional idempotency key using notify_with_key. This will add an Idempotency-Key header to the request, which is useful for preventing duplicate processing on custom generic endpoints.
client.notify_with_key.await?;
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 markdown-to-HTML conversion.
use ;
let builder = TelegramPayloadBuilder ;
let payload = builder.build_payload;
// Returns: { "chat_id": "123456789", "text": "Alert\n\nSomething happened", "parse_mode": "HTML", ... }
Generic
Producing a standard high-level JSON object.
use ;
let builder = default;
let payload = builder.build_payload;
// Returns: { "title": "Alert", "body": "Something happened" }
Running Examples
You can run the examples provided in the examples/ directory using cargo run --example <name>. Most examples look for environment variables for configuration:
Slack
Discord
Telegram
Generic webhook
License
- MIT license (http://opensource.org/licenses/MIT)