channels

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ATMessageEventData

type ATMessageEventData struct {
	ID        string `json:"id"`
	Content   string `json:"content"`
	Timestamp string `json:"timestamp"`
	Author    struct {
		ID       string `json:"id"`
		Username string `json:"username"`
	} `json:"author"`
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id"`
}

ATMessageEventData 频道 @消息事件数据

type BaseChannel

type BaseChannel interface {
	// Name 返回通道名称
	Name() string

	// AccountID 返回通道账号ID
	AccountID() string

	// Start 启动通道
	Start(ctx context.Context) error

	// Stop 停止通道
	Stop() error

	// Send 发送消息
	Send(msg *bus.OutboundMessage) error

	// SendStream 发送流式消息
	SendStream(chatID string, stream <-chan *bus.StreamMessage) error

	// IsAllowed 检查发送者是否允许
	IsAllowed(senderID string) bool
}

BaseChannel 通道基础接口

type BaseChannelConfig

type BaseChannelConfig struct {
	Enabled    bool     `mapstructure:"enabled" json:"enabled"`
	AccountID  string   `mapstructure:"account_id" json:"account_id"` // 账号ID
	Name       string   `mapstructure:"name" json:"name"`             // 账号显示名称
	AllowedIDs []string `mapstructure:"allowed_ids" json:"allowed_ids"`
}

BaseChannelConfig 通道基础配置

type BaseChannelImpl

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

BaseChannelImpl 通道基础实现

func NewBaseChannelImpl

func NewBaseChannelImpl(name, accountID string, config BaseChannelConfig, bus *bus.MessageBus) *BaseChannelImpl

NewBaseChannelImpl 创建通道基础实现

func (*BaseChannelImpl) AccountID

func (c *BaseChannelImpl) AccountID() string

AccountID 返回通道账号ID

func (*BaseChannelImpl) IsAllowed

func (c *BaseChannelImpl) IsAllowed(senderID string) bool

IsAllowed 检查发送者是否允许

func (*BaseChannelImpl) IsRunning

func (c *BaseChannelImpl) IsRunning() bool

IsRunning 检查是否运行中

func (*BaseChannelImpl) Name

func (c *BaseChannelImpl) Name() string

Name 返回通道名称

func (*BaseChannelImpl) PublishInbound

func (c *BaseChannelImpl) PublishInbound(ctx context.Context, msg *bus.InboundMessage) error

PublishInbound 发布入站消息

func (*BaseChannelImpl) SendStream

func (c *BaseChannelImpl) SendStream(chatID string, stream <-chan *bus.StreamMessage) error

SendStream 发送流式消息 (默认实现,收集所有chunk后一次性发送)

func (*BaseChannelImpl) Start

func (c *BaseChannelImpl) Start(ctx context.Context) error

Start 启动通道

func (*BaseChannelImpl) Stop

func (c *BaseChannelImpl) Stop() error

Stop 停止通道

func (*BaseChannelImpl) WaitForStop

func (c *BaseChannelImpl) WaitForStop() <-chan struct{}

WaitForStop 等待停止信号

type C2CMessageEventData

type C2CMessageEventData struct {
	ID        string `json:"id"`
	Content   string `json:"content"`
	Timestamp string `json:"timestamp"`
	Author    struct {
		UserOpenID string `json:"user_openid"`
	} `json:"author"`
}

C2CMessageEventData C2C 消息事件数据

type DingTalkChannel

type DingTalkChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

DingTalkChannel DingTalk 通道实现

func NewDingTalkChannel

func NewDingTalkChannel(cfg config.DingTalkChannelConfig, bus *bus.MessageBus) (*DingTalkChannel, error)

NewDingTalkChannel 创建 DingTalk 通道实例

func (*DingTalkChannel) Send

func (c *DingTalkChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息到 DingTalk

func (*DingTalkChannel) SendDirectReply

func (c *DingTalkChannel) SendDirectReply(sessionWebhook, content string) error

SendDirectReply 使用 session webhook 发送直接回复

func (*DingTalkChannel) SendStream

func (c *DingTalkChannel) SendStream(chatID string, stream <-chan *bus.StreamMessage) error

SendStream 发送流式消息 (DingTalk 不支持,收集后一次性发送)

func (*DingTalkChannel) Start

func (c *DingTalkChannel) Start(ctx context.Context) error

Start 启动 DingTalk 通道 (Stream Mode)

func (*DingTalkChannel) Stop

func (c *DingTalkChannel) Stop() error

Stop 停止 DingTalk 通道

type DiscordChannel

type DiscordChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

DiscordChannel Discord 通道

func NewDiscordChannel

func NewDiscordChannel(cfg DiscordConfig, bus *bus.MessageBus) (*DiscordChannel, error)

NewDiscordChannel 创建 Discord 通道

func (*DiscordChannel) Send

func (c *DiscordChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*DiscordChannel) Start

func (c *DiscordChannel) Start(ctx context.Context) error

Start 启动 Discord 通道

func (*DiscordChannel) Stop

func (c *DiscordChannel) Stop() error

Stop 停止 Discord 通道

type DiscordConfig

type DiscordConfig struct {
	BaseChannelConfig
	Token string `mapstructure:"token" json:"token"`
}

DiscordConfig Discord 配置

type FeishuChannel

type FeishuChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

FeishuChannel 飞书通道 - WebSocket 模式

func NewFeishuChannel

func NewFeishuChannel(cfg config.FeishuChannelConfig, bus *bus.MessageBus) (*FeishuChannel, error)

NewFeishuChannel 创建飞书通道

func (*FeishuChannel) Send

func (c *FeishuChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*FeishuChannel) Start

func (c *FeishuChannel) Start(ctx context.Context) error

Start 启动飞书通道

func (*FeishuChannel) Stop added in v0.2.1

func (c *FeishuChannel) Stop() error

Stop 停止飞书通道

type GoogleChatChannel

type GoogleChatChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

GoogleChatChannel Google Chat 通道

func NewGoogleChatChannel

func NewGoogleChatChannel(cfg GoogleChatConfig, bus *bus.MessageBus) (*GoogleChatChannel, error)

NewGoogleChatChannel 创建 Google Chat 通道

func (*GoogleChatChannel) HandleWebhook

func (c *GoogleChatChannel) HandleWebhook(ctx context.Context, event *chat.DeprecatedEvent) error

HandleWebhook 处理 Google Chat webhook (需要在外部 HTTP 端点调用)

func (*GoogleChatChannel) InitService

func (c *GoogleChatChannel) InitService(ctx context.Context) error

InitService 初始化 Google Chat 服务 (如果需要主动发送)

func (*GoogleChatChannel) Send

Send 发送消息

func (*GoogleChatChannel) SendWithWebhook

func (c *GoogleChatChannel) SendWithWebhook(webhookURL string, msg *bus.OutboundMessage) error

SendWithWebhook 使用 webhook 发送消息 (推荐方式)

func (*GoogleChatChannel) Start

func (c *GoogleChatChannel) Start(ctx context.Context) error

Start 启动 Google Chat 通道

func (*GoogleChatChannel) Stop

func (c *GoogleChatChannel) Stop() error

Stop 停止 Google Chat 通道

type GoogleChatConfig

type GoogleChatConfig struct {
	BaseChannelConfig
	ProjectID   string `mapstructure:"project_id" json:"project_id"`
	Credentials string `mapstructure:"credentials" json:"credentials"` // Service account credentials JSON
}

GoogleChatConfig Google Chat 配置

type GroupATMessageEventData

type GroupATMessageEventData struct {
	ID        string `json:"id"`
	Content   string `json:"content"`
	Timestamp string `json:"timestamp"`
	Author    struct {
		MemberOpenID string `json:"member_openid"`
	} `json:"author"`
	GroupOpenID string `json:"group_openid"`
}

GroupATMessageEventData 群 @消息事件数据

type HelloData

type HelloData struct {
	HeartbeatInterval int `json:"heartbeat_interval"`
}

HelloData Hello 事件数据

type InfoflowChannel

type InfoflowChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

InfoflowChannel 百度如流通道

func NewInfoflowChannel

func NewInfoflowChannel(accountID string, cfg InfoflowConfig, bus *bus.MessageBus) (*InfoflowChannel, error)

NewInfoflowChannel 创建如流通道

func (*InfoflowChannel) Send

func (c *InfoflowChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*InfoflowChannel) SendStream

func (c *InfoflowChannel) SendStream(chatID string, stream <-chan *bus.StreamMessage) error

SendStream 发送流式消息(如流不支持,使用普通发送)

func (*InfoflowChannel) Start

func (c *InfoflowChannel) Start(ctx context.Context) error

Start 启动如流通道

func (*InfoflowChannel) Stop

func (c *InfoflowChannel) Stop() error

Stop 停止通道

type InfoflowConfig

type InfoflowConfig struct {
	BaseChannelConfig
	WebhookURL  string `json:"webhook_url" mapstructure:"webhook_url"`
	Token       string `json:"token" mapstructure:"token"`
	AESKey      string `json:"aes_key" mapstructure:"aes_key"`
	WebhookPort int    `json:"webhook_port" mapstructure:"webhook_port"`
}

InfoflowConfig 如流通道配置

type Manager

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

Manager 通道管理器

func NewManager

func NewManager(bus *bus.MessageBus) *Manager

NewManager 创建通道管理器

func (*Manager) DispatchOutbound

func (m *Manager) DispatchOutbound(ctx context.Context) error

DispatchOutbound 分发出站消息

func (*Manager) Get

func (m *Manager) Get(name string) (BaseChannel, bool)

Get 获取通道

func (*Manager) List

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

List 列出所有通道名称

func (*Manager) Register

func (m *Manager) Register(channel BaseChannel) error

Register 注册通道

func (*Manager) RegisterWithName

func (m *Manager) RegisterWithName(channel BaseChannel, name string) error

RegisterWithName 使用指定名称注册通道

func (*Manager) SetupFromConfig

func (m *Manager) SetupFromConfig(cfg *config.Config) error

SetupFromConfig 从配置设置通道

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start 启动所有通道

func (*Manager) Status

func (m *Manager) Status(name string) (map[string]interface{}, error)

Status 获取通道状态

func (*Manager) Stop

func (m *Manager) Stop() error

Stop 停止所有通道

type QQChannel

type QQChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

QQChannel QQ 官方开放平台 Bot 通道 使用 botgo SDK 实现:https://github.com/tencent-connect/botgo

func NewQQChannel

func NewQQChannel(accountID string, cfg config.QQChannelConfig, bus *bus.MessageBus) (*QQChannel, error)

NewQQChannel 创建 QQ 官方 Bot 通道

func (*QQChannel) GetSession

func (c *QQChannel) GetSession() *dto.WebsocketAP

GetSession 获取当前会话信息(用于调试)

func (*QQChannel) HandleWebhook

func (c *QQChannel) HandleWebhook(ctx context.Context, event []byte) error

HandleWebhook 处理 QQ Webhook 回调(WebSocket 模式下不使用)

func (*QQChannel) Send

func (c *QQChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*QQChannel) Start

func (c *QQChannel) Start(ctx context.Context) error

Start 启动 QQ 官方 Bot 通道

func (*QQChannel) Stop

func (c *QQChannel) Stop() error

Stop 停止 QQ 官方 Bot 通道

type ReadyData

type ReadyData struct {
	SessionID string `json:"session_id"`
	Version   int    `json:"version"`
	User      struct {
		ID       string `json:"id"`
		Username string `json:"username"`
		Bot      bool   `json:"bot"`
	} `json:"user"`
}

ReadyData Ready 事件数据

type SlackChannel

type SlackChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

SlackChannel Slack 通道

func NewSlackChannel

func NewSlackChannel(cfg SlackConfig, bus *bus.MessageBus) (*SlackChannel, error)

NewSlackChannel 创建 Slack 通道

func (*SlackChannel) Send

func (c *SlackChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*SlackChannel) Start

func (c *SlackChannel) Start(ctx context.Context) error

Start 启动 Slack 通道

func (*SlackChannel) Stop

func (c *SlackChannel) Stop() error

Stop 停止 Slack 通道

type SlackConfig

type SlackConfig struct {
	BaseChannelConfig
	Token         string `mapstructure:"token" json:"token"`
	SigningSecret string `mapstructure:"signing_secret" json:"signing_secret"`
}

SlackConfig Slack 配置

type TeamsActor

type TeamsActor struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

TeamsActor Teams 参与者

type TeamsAttachment

type TeamsAttachment struct {
	ContentType string                 `json:"contentType"`
	Content     map[string]interface{} `json:"content"`
}

TeamsAttachment Teams 附件

type TeamsChannel

type TeamsChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

TeamsChannel Microsoft Teams 通道

func NewTeamsChannel

func NewTeamsChannel(cfg TeamsConfig, bus *bus.MessageBus) (*TeamsChannel, error)

NewTeamsChannel 创建 Teams 通道

func (*TeamsChannel) HandleWebhook

func (c *TeamsChannel) HandleWebhook(ctx context.Context, webhookMsg *TeamsWebhookMessage) error

HandleWebhook 处理 Teams webhook (需要在外部 HTTP 端点调用)

func (*TeamsChannel) Send

func (c *TeamsChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*TeamsChannel) SendAdaptiveCard

func (c *TeamsChannel) SendAdaptiveCard(msg *bus.OutboundMessage, card map[string]interface{}) error

SendAdaptiveCard 发送自适应卡片 (富格式消息)

func (*TeamsChannel) SendWithWebhook

func (c *TeamsChannel) SendWithWebhook(webhookURL string, msg *bus.OutboundMessage) error

SendWithWebhook 使用 webhook 发送消息 (用于 outgoing webhooks)

func (*TeamsChannel) Start

func (c *TeamsChannel) Start(ctx context.Context) error

Start 启动 Teams 通道

func (*TeamsChannel) Stop

func (c *TeamsChannel) Stop() error

Stop 停止 Teams 通道

type TeamsConfig

type TeamsConfig struct {
	BaseChannelConfig
	AppID       string `mapstructure:"app_id" json:"app_id"`
	AppPassword string `mapstructure:"app_password" json:"app_password"`
	TenantID    string `mapstructure:"tenant_id" json:"tenant_id"`
	WebhookURL  string `mapstructure:"webhook_url" json:"webhook_url"` // For outgoing webhooks
}

TeamsConfig Teams 配置

type TeamsConversation

type TeamsConversation struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

TeamsConversation Teams 会话

type TeamsEntity

type TeamsEntity struct {
	Type string                 `json:"type"`
	Data map[string]interface{} `json:"data,omitempty"`
}

TeamsEntity Teams 实体

type TeamsWebhookMessage

type TeamsWebhookMessage struct {
	Type         string            `json:"type"`
	ID           string            `json:"id"`
	Timestamp    string            `json:"timestamp"`
	ServiceURL   string            `json:"serviceUrl"`
	ChannelID    string            `json:"channelId"`
	From         TeamsActor        `json:"from"`
	Conversation TeamsConversation `json:"conversation"`
	Text         string            `json:"text"`
	Attachments  []TeamsAttachment `json:"attachments"`
	Entities     []TeamsEntity     `json:"entities"`
}

TeamsWebhookMessage Teams webhook 消息

type TelegramChannel

type TelegramChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

TelegramChannel Telegram 通道

func NewTelegramChannel

func NewTelegramChannel(accountID string, cfg TelegramConfig, bus *bus.MessageBus) (*TelegramChannel, error)

NewTelegramChannel 创建 Telegram 通道

func (*TelegramChannel) Send

func (c *TelegramChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*TelegramChannel) Start

func (c *TelegramChannel) Start(ctx context.Context) error

Start 启动 Telegram 通道

type TelegramConfig

type TelegramConfig struct {
	BaseChannelConfig
	Token string `mapstructure:"token" json:"token"`
}

TelegramConfig Telegram 配置

type WSPayload

type WSPayload struct {
	Op int             `json:"op"`
	D  json.RawMessage `json:"d"`
	S  uint32          `json:"s"`
	T  string          `json:"t"`
}

WSPayload WebSocket 消息负载

type WeWorkChannel

type WeWorkChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

WeWorkChannel 企业微信通道

func NewWeWorkChannel

func NewWeWorkChannel(cfg config.WeWorkChannelConfig, bus *bus.MessageBus) (*WeWorkChannel, error)

NewWeWorkChannel 创建企业微信通道

func (*WeWorkChannel) Send

func (c *WeWorkChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*WeWorkChannel) Start

func (c *WeWorkChannel) Start(ctx context.Context) error

Start 启动企业微信通道

type WhatsAppChannel

type WhatsAppChannel struct {
	*BaseChannelImpl
	// contains filtered or unexported fields
}

WhatsAppChannel WhatsApp 通道

func NewWhatsAppChannel

func NewWhatsAppChannel(cfg WhatsAppConfig, bus *bus.MessageBus) (*WhatsAppChannel, error)

NewWhatsAppChannel 创建 WhatsApp 通道

func (*WhatsAppChannel) Send

func (c *WhatsAppChannel) Send(msg *bus.OutboundMessage) error

Send 发送消息

func (*WhatsAppChannel) Start

func (c *WhatsAppChannel) Start(ctx context.Context) error

Start 启动 WhatsApp 通道

type WhatsAppConfig

type WhatsAppConfig struct {
	BaseChannelConfig
	BridgeURL string `mapstructure:"bridge_url" json:"bridge_url"`
}

WhatsAppConfig WhatsApp 配置

type WhatsAppMessage

type WhatsAppMessage struct {
	ID        string `json:"id"`
	From      string `json:"from"`
	ChatID    string `json:"chat_id"`
	Text      string `json:"text"`
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

WhatsAppMessage WhatsApp 消息

Jump to

Keyboard shortcuts

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