channel

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package channel 定义了 Golem 与不同聊天平台(如 Telegram、飞书等)交互的接口和基础实现。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseChannel

type BaseChannel struct {
	Bus       *bus.MessageBus // 关联的消息总线,用于转发入站消息
	AllowList map[string]bool // 允许访问此通道的用户 ID 列表(为空则不限制)
}

BaseChannel 提供跨不同通道共享的基础功能。

func (*BaseChannel) IsAllowed

func (b *BaseChannel) IsAllowed(senderID string) bool

IsAllowed 检查发送者 ID 是否在允许名单中。

func (*BaseChannel) PublishInbound

func (b *BaseChannel) PublishInbound(msg *bus.InboundMessage)

PublishInbound 将接收到的原始平台消息发布到消息总线中。

type Channel

type Channel interface {
	Name() string                                             // 返回通道名称(如 "telegram")
	Start(ctx context.Context) error                          // 启动通道连接或监听
	Stop(ctx context.Context) error                           // 停止通道连接
	Send(ctx context.Context, msg *bus.OutboundMessage) error // 发送出站消息到平台
	IsAllowed(senderID string) bool                           // 检查指定的发送者是否有权限使用此通道
}

Channel 定义了聊天平台对接需要实现的接口。

type DeliveryPolicy added in v0.5.1

type DeliveryPolicy struct {
	MaxConcurrentSends int           // 最大并发发送连接数
	RetryMaxAttempts   int           // 发送失败后的最大重试次数
	RetryBaseBackoff   time.Duration // 基础重试退避间隔
	RetryMaxBackoff    time.Duration // 最大重试退避间隔
	RateLimitPerSecond int           // 每秒允许发送的消息数上限
	DedupWindow        time.Duration // 消息去重的时间窗口大小
}

DeliveryPolicy 定义了出站消息的投递规则,包括重试次数、退避策略、速率限制和去重窗口。

type Manager

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

Manager 统一协调管理所有消息通道及其出站发送策略。

func NewManager

func NewManager(msgBus *bus.MessageBus) *Manager

NewManager 创建一个使用推荐默认策略的消息通道管理器。

func NewManagerWithLimit added in v0.1.4

func NewManagerWithLimit(msgBus *bus.MessageBus, maxConcurrentSends int) *Manager

NewManagerWithLimit 创建一个可控制最大并发发送数的管理器。

func NewManagerWithPolicy added in v0.5.1

func NewManagerWithPolicy(msgBus *bus.MessageBus, policy DeliveryPolicy) *Manager

NewManagerWithPolicy 使用自定义的出站消息投递策略创建一个管理器。

func (*Manager) Names

func (m *Manager) Names() []string

Names 返回所有已注册通道的名称列表。

func (*Manager) Register

func (m *Manager) Register(ch Channel)

Register 将一个通道实现注册到管理器中。

func (*Manager) RouteOutbound

func (m *Manager) RouteOutbound(ctx context.Context)

RouteOutbound 持续监控消息总线的出站队列,并将消息分发到对应的通道进行发送。

func (*Manager) SetRuntimeMetrics added in v0.4.2

func (m *Manager) SetRuntimeMetrics(recorder *metrics.RuntimeMetrics)

SetRuntimeMetrics 附加一个运行时指标收集器,用于跟踪出站消息的统计数据。

func (*Manager) StartAll

func (m *Manager) StartAll(ctx context.Context)

StartAll 启动管理器下属的所有消息通道,使其开始接收外部平台的入站消息。

func (*Manager) StopAll

func (m *Manager) StopAll(ctx context.Context)

StopAll 停止管理器下属的所有消息通道,关闭外部平台连接。

Directories

Path Synopsis
Package dingtalk 实现钉钉机器人的接入,采用钉钉侧流式 (Stream Mode) 协议进行消息推送。
Package dingtalk 实现钉钉机器人的接入,采用钉钉侧流式 (Stream Mode) 协议进行消息推送。
Package feishu 实现飞书机器人的接入,支持通过 WebSocket 模式接收和发送消息。
Package feishu 实现飞书机器人的接入,支持通过 WebSocket 模式接收和发送消息。
Package telegram 实现 Telegram 机器人的接入,支持文本消息及语音转录交互。
Package telegram 实现 Telegram 机器人的接入,支持文本消息及语音转录交互。

Jump to

Keyboard shortcuts

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