Flatten webhook payload for simpler template access
- Add uid, from, subject at top level of WebhookPayload
- Allows {{body.from}} instead of {{body.message.from}}
- Fixes empty fields in OpenClaw hook templates
- Full message object still available for detailed access
This commit is contained in:
parent
59ddae7540
commit
1dacfdbaf9
BIN
mail-bridge
BIN
mail-bridge
Binary file not shown.
11
main.go
11
main.go
|
|
@ -67,10 +67,16 @@ type Message struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebhookPayload for new mail events
|
// WebhookPayload for new mail events
|
||||||
|
// Fields are flattened for simpler template access ({{body.from}} vs {{body.message.from}})
|
||||||
type WebhookPayload struct {
|
type WebhookPayload struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
Account string `json:"account"`
|
Account string `json:"account"`
|
||||||
Folder string `json:"folder"`
|
Folder string `json:"folder"`
|
||||||
|
// Flattened message fields for easier template access
|
||||||
|
UID uint32 `json:"uid"`
|
||||||
|
From string `json:"from"`
|
||||||
|
Subject string `json:"subject"`
|
||||||
|
// Full message object still available for detailed access
|
||||||
Message *Message `json:"message,omitempty"`
|
Message *Message `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,11 +272,14 @@ func handleNewMail(accountName string, acc AccountConfig, folder string) {
|
||||||
msg := msgs[0]
|
msg := msgs[0]
|
||||||
log.Printf("[%s] Webhook: from=%q subject=%q", accountName, msg.From, msg.Subject)
|
log.Printf("[%s] Webhook: from=%q subject=%q", accountName, msg.From, msg.Subject)
|
||||||
|
|
||||||
// Send webhook
|
// Send webhook with flattened fields for easy template access
|
||||||
payload := WebhookPayload{
|
payload := WebhookPayload{
|
||||||
Event: "new_mail",
|
Event: "new_mail",
|
||||||
Account: accountName,
|
Account: accountName,
|
||||||
Folder: folder,
|
Folder: folder,
|
||||||
|
UID: msg.UID,
|
||||||
|
From: msg.From,
|
||||||
|
Subject: msg.Subject,
|
||||||
Message: msg,
|
Message: msg,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue