mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 14:02:43 +08:00
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package event
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
// GenericProcessor is the fallback for unregistered event types.
|
|
// Compact mode parses the event payload as a map; Raw mode passes through raw.Event.
|
|
type GenericProcessor struct{}
|
|
|
|
func (p *GenericProcessor) EventType() string { return "" }
|
|
|
|
func (p *GenericProcessor) Transform(_ context.Context, raw *RawEvent, mode TransformMode) interface{} {
|
|
if mode == TransformRaw {
|
|
return raw
|
|
}
|
|
// Compact: parse event as flat map, inject envelope metadata so AI
|
|
// can always identify the event type regardless of which processor ran.
|
|
var eventMap map[string]interface{}
|
|
if err := json.Unmarshal(raw.Event, &eventMap); err != nil {
|
|
return raw
|
|
}
|
|
eventMap["type"] = raw.Header.EventType
|
|
if raw.Header.EventID != "" {
|
|
eventMap["event_id"] = raw.Header.EventID
|
|
}
|
|
if raw.Header.CreateTime != "" {
|
|
eventMap["timestamp"] = raw.Header.CreateTime
|
|
}
|
|
return eventMap
|
|
}
|
|
|
|
func (p *GenericProcessor) DeduplicateKey(raw *RawEvent) string { return raw.Header.EventID }
|
|
func (p *GenericProcessor) WindowStrategy() WindowConfig { return WindowConfig{} }
|