webhook

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PredefinedEvents = []string{
	"chat.message",
	"chat.session_start",
	"chat.session_end",
	"tool.executed",
	"skill.activated",
	"skill.deactivated",
	"error",
	"warning",
	"update.available",
	"budget.exceeded",
	"mcp.connected",
	"mcp.disconnected",
}

PredefinedEvents 预定义事件类型

Functions

This section is empty.

Types

type DeliveryResult

type DeliveryResult struct {
	WebhookID  string        `json:"webhook_id"`
	EventID    string        `json:"event_id"`
	Timestamp  time.Time     `json:"timestamp"`
	Success    bool          `json:"success"`
	StatusCode int           `json:"status_code,omitempty"`
	Response   string        `json:"response,omitempty"`
	Error      string        `json:"error,omitempty"`
	Duration   time.Duration `json:"duration"`
}

DeliveryResult 投递结果

type Event

type Event struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type"`
	Source    string                 `json:"source"`
	Timestamp time.Time              `json:"timestamp"`
	Data      map[string]interface{} `json:"data"`
	Retries   int                    `json:"retries"`
}

Event 事件

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager Webhook 管理器

func NewManager

func NewManager(dataDir string) (*Manager, error)

NewManager 创建新的 Webhook 管理器

func (*Manager) AddHeader

func (m *Manager) AddHeader(id, key, value string) error

AddHeader 添加自定义 header

func (*Manager) Create

func (m *Manager) Create(name, url, secret string, events []string) (*Webhook, error)

Create 创建 Webhook

func (*Manager) Delete

func (m *Manager) Delete(id string) error

Delete 删除 Webhook

func (*Manager) Disable

func (m *Manager) Disable(id string) error

Disable 禁用 Webhook

func (*Manager) Emit

func (m *Manager) Emit(eventType, source string, data map[string]interface{})

Emit 触发事件

func (*Manager) EmitSync

func (m *Manager) EmitSync(eventType, source string, data map[string]interface{}) []*DeliveryResult

EmitSync 同步触发事件(等待所有投递完成)

func (*Manager) Enable

func (m *Manager) Enable(id string) error

Enable 启用 Webhook

func (*Manager) Get

func (m *Manager) Get(id string) *Webhook

Get 获取 Webhook

func (*Manager) GetDeliveryHistory

func (m *Manager) GetDeliveryHistory(webhookID string, limit int) []*DeliveryResult

GetDeliveryHistory 获取投递历史

func (*Manager) List

func (m *Manager) List() []*Webhook

List 列出所有 Webhook

func (*Manager) RemoveHeader

func (m *Manager) RemoveHeader(id, key string) error

RemoveHeader 移除自定义 header

func (*Manager) SetRetryPolicy

func (m *Manager) SetRetryPolicy(id string, policy RetryPolicy) error

SetRetryPolicy 设置重试策略

func (*Manager) Test

func (m *Manager) Test(id string) (*DeliveryResult, error)

Test 测试 Webhook

func (*Manager) Update

func (m *Manager) Update(id string, updates map[string]interface{}) error

Update 更新 Webhook

type RetryPolicy

type RetryPolicy struct {
	MaxRetries        int     `json:"max_retries"`
	RetryDelay        int     `json:"retry_delay_seconds"`
	BackoffMultiplier float64 `json:"backoff_multiplier"`
}

RetryPolicy retry policy

type Webhook

type Webhook struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	URL           string            `json:"url"`
	Secret        string            `json:"secret,omitempty"`
	Events        []string          `json:"events"` // 监听的事件类型
	Active        bool              `json:"active"`
	Headers       map[string]string `json:"headers,omitempty"`
	Timeout       int               `json:"timeout"` // 秒
	RetryPolicy   RetryPolicy       `json:"retry_policy"`
	CreatedAt     time.Time         `json:"created_at"`
	LastTriggered time.Time         `json:"last_triggered,omitempty"`
}

Webhook Webhook 配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL