Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

56 lines
1.9 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package schemas
import "encoding/json"
// v2Envelope is the Feishu V2 envelope JSON Schema; bump when upstream changes header shape.
var v2Envelope = map[string]interface{}{
"type": "object",
"description": "飞书事件",
"properties": map[string]interface{}{
"schema": map[string]interface{}{
"type": "string",
"enum": []string{"2.0"},
"description": "飞书事件协议版本",
},
"header": map[string]interface{}{
"type": "object",
"description": "事件头,所有事件结构一致",
"properties": map[string]interface{}{
"event_id": map[string]string{"type": "string", "description": "事件唯一 ID"},
"event_type": map[string]string{"type": "string", "description": "事件类型,用于路由"},
"create_time": map[string]string{"type": "string", "description": "事件创建时间,毫秒时间戳字符串"},
"token": map[string]string{"type": "string", "description": "回调校验 token"},
"tenant_key": map[string]string{"type": "string", "description": "租户唯一标识"},
"app_id": map[string]string{"type": "string", "description": "接收事件的应用 ID"},
},
},
},
}
// WrapV2Envelope splices body into the `event` property; passes body through unchanged on parse fail.
func WrapV2Envelope(body json.RawMessage) json.RawMessage {
var parsed interface{}
if err := json.Unmarshal(body, &parsed); err != nil {
return body
}
envelope := map[string]interface{}{}
for k, v := range v2Envelope {
envelope[k] = v
}
// Rebuild properties so we don't mutate the package-level template.
props := map[string]interface{}{}
for k, v := range v2Envelope["properties"].(map[string]interface{}) {
props[k] = v
}
props["event"] = parsed
envelope["properties"] = props
data, err := json.Marshal(envelope)
if err != nil {
return body
}
return data
}