lark-webhook-notify
A Rust library for sending rich notification cards to Lark (Feishu) bots via webhooks.
Send structured cards for CI/CD pipelines, job status, alerts, and custom notifications — with built-in Chinese/English translations, HMAC-SHA256 request signing, and a fluent card builder API.
Install
[]
= "0.1"
Quick Start
use ;
Configuration
Credentials are loaded in priority order (highest wins):
| Source | Fields |
|---|---|
Direct params to LarkWebhookSettings::load |
webhook_url, webhook_secret |
| Environment variables | LARK_WEBHOOK_URL, LARK_WEBHOOK_SECRET |
TOML file (lark_webhook.toml or custom path) |
webhook_url, webhook_secret |
Example lark_webhook.toml:
= "https://open.feishu.cn/open-apis/bot/v2/hook/..."
= "your_signing_secret"
Or provide credentials directly:
let notifier = from_params?;
Pre-built Workflow Templates
For common pipeline and job notification patterns, use the module-level free functions.
All functions return a GenericCardTemplate that implements LarkTemplate.
Network submission
use ;
// Notify that submission started
let card = network_submission_start;
notifier.send_template?;
// Notify completion
let card = network_submission_complete;
notifier.send_template?;
// Notify failure
let card = network_submission_failure;
notifier.send_template?;
Job lifecycle
use ;
// Submission started
let card = job_submission_start;
notifier.send_template?;
// Job finished
let card = job_complete;
notifier.send_template?;
Task set progress
use ;
use HashMap;
let mut progress = new;
progress.insert;
progress.insert;
let card = task_set_progress;
notifier.send_template?;
Other workflow notifications
| Function | Header color | Use case |
|---|---|---|
config_upload_complete |
Green | Config/file upload finished |
result_collection_start |
Wathet | Result gathering started |
result_collection_complete |
Green | Result gathering finished |
comparison_complete |
Orange | Dataset comparison done |
High-Level Template Structs
For per-template customization, instantiate the structs directly:
use ;
let card = StartTaskTemplate ;
notifier.send_template?;
Available template structs: SimpleMessageTemplate, AlertTemplate, LegacyTaskTemplate,
StartTaskTemplate, ReportTaskResultTemplate, ReportFailureTaskTemplate, RawContentTemplate.
Custom Cards with CardBuilder
For full control, use the fluent CardBuilder:
use ;
let card = new
.header
.markdown
.columns
.column
.column
.end_columns
.collapsible
.build;
notifier.send_template?;
Builder methods
| Method | Description |
|---|---|
.header(title, status, color, subtitle) |
Card header. color = None auto-detects from status text |
.markdown(content, align, size) |
Markdown text block |
.metadata(label, value) |
Single **Label:** value line |
.metadata_block(&[("Label", "val")]) |
Multiple metadata lines in one block |
.columns() / .column(...) / .end_columns() |
Multi-column layout |
.collapsible(title, content, expanded) |
Collapsible panel |
.divider() |
Horizontal rule |
.add_block(block) |
Add any impl Into<serde_json::Value> block directly |
Auto color detection from status:
| Status text | Color |
|---|---|
"running", "submitted" |
Wathet (light blue) |
"success", "completed" |
Green |
"failed", "error" |
Red |
"warning" |
Orange |
| anything else | Blue |
Language Support
All workflow functions and template structs accept a LanguageCode parameter:
use LanguageCode;
Zh // Chinese (default for most workflow functions)
En // English
Field labels (job name, status, timestamps) are automatically translated. User-supplied strings (task names, descriptions, error messages) pass through unchanged.
Convenience Functions
One-call wrappers for sending without constructing templates manually:
use ;
send_alert?;
Block Types (low-level)
For assembling raw card JSON, the blocks module exports typed structs. All implement
From<T> for serde_json::Value:
use ;
let v: Value = Markdown .into;
Available: Markdown, TextTag, HeaderBlock, Column, ColumnSet,
CollapsiblePanel, TemplateReference, Card.
Layout enums (all re-exported from crate root): TextAlign, TextSize,
HAlign, VAlign, BgStyle, ColumnWidth.
Error Handling
use ;
match notifier.send_template
License
Apache-2.0. See LICENSE.