channels

package
v0.0.0-...-7cf926f Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WeComDecryptMessage

func WeComDecryptMessage(encryptedMsg, encodingAESKey string) (string, error)

WeComDecryptMessage decrypts the encrypted message using AES This is a common function used by both WeCom Bot and WeCom App For AIBOT, receiveid should be the aibotid; for other apps, it should be corp_id

func WeComDecryptMessageWithVerify

func WeComDecryptMessageWithVerify(encryptedMsg, encodingAESKey, receiveid string) (string, error)

WeComDecryptMessageWithVerify decrypts the encrypted message and optionally verifies receiveid receiveid: for AIBOT use aibotid, for WeCom App use corp_id. If empty, skip verification.

func WeComVerifySignature

func WeComVerifySignature(token, msgSignature, timestamp, nonce, msgEncrypt string) bool

WeComVerifySignature verifies the message signature for WeCom This is a common function used by both WeCom Bot and WeCom App

Types

type BaseChannel

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

func NewBaseChannel

func NewBaseChannel(name string, config any, bus *bus.MessageBus, allowList []string) *BaseChannel

func (*BaseChannel) HandleMessage

func (c *BaseChannel) HandleMessage(senderID, chatID, content string, media []string, metadata map[string]string)

func (*BaseChannel) IsAllowed

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

func (*BaseChannel) IsRunning

func (c *BaseChannel) IsRunning() bool

func (*BaseChannel) Name

func (c *BaseChannel) Name() string

type BotStatus

type BotStatus struct {
	Online bool `json:"online"`
	Good   bool `json:"good"`
}

type Channel

type Channel interface {
	Name() string
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Send(ctx context.Context, msg bus.OutboundMessage) error
	IsRunning() bool
	IsAllowed(senderID string) bool
}

type DingTalkChannel

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

DingTalkChannel implements the Channel interface for DingTalk (钉钉) It uses WebSocket for receiving messages via stream mode and API for sending

func NewDingTalkChannel

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

NewDingTalkChannel creates a new DingTalk channel instance

func (*DingTalkChannel) Send

Send sends a message to DingTalk via the chatbot reply API

func (*DingTalkChannel) SendDirectReply

func (c *DingTalkChannel) SendDirectReply(ctx context.Context, sessionWebhook, content string) error

SendDirectReply sends a direct reply using the session webhook

func (*DingTalkChannel) Start

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

Start initializes the DingTalk channel with Stream Mode

func (*DingTalkChannel) Stop

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

Stop gracefully stops the DingTalk channel

type DiscordChannel

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

func NewDiscordChannel

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

func (*DiscordChannel) Send

func (*DiscordChannel) SetTranscriber

func (c *DiscordChannel) SetTranscriber(transcriber *voice.GroqTranscriber)

func (*DiscordChannel) Start

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

func (*DiscordChannel) Stop

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

type FeishuChannel

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

func NewFeishuChannel

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

func (*FeishuChannel) Send

func (*FeishuChannel) Start

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

func (*FeishuChannel) Stop

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

type LINEChannel

type LINEChannel struct {
	*BaseChannel
	// contains filtered or unexported fields
}

LINEChannel implements the Channel interface for LINE Official Account using the LINE Messaging API with HTTP webhook for receiving messages and REST API for sending messages.

func NewLINEChannel

func NewLINEChannel(cfg config.LINEConfig, messageBus *bus.MessageBus) (*LINEChannel, error)

NewLINEChannel creates a new LINE channel instance.

func (*LINEChannel) Send

func (c *LINEChannel) Send(ctx context.Context, msg bus.OutboundMessage) error

Send sends a message to LINE. It first tries the Reply API (free) using a cached reply token, then falls back to the Push API.

func (*LINEChannel) Start

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

Start launches the HTTP webhook server.

func (*LINEChannel) Stop

func (c *LINEChannel) Stop(ctx context.Context) error

Stop gracefully shuts down the HTTP server.

type MaixCamChannel

type MaixCamChannel struct {
	*BaseChannel
	// contains filtered or unexported fields
}

func NewMaixCamChannel

func NewMaixCamChannel(cfg config.MaixCamConfig, bus *bus.MessageBus) (*MaixCamChannel, error)

func (*MaixCamChannel) Send

func (*MaixCamChannel) Start

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

func (*MaixCamChannel) Stop

func (c *MaixCamChannel) Stop(ctx context.Context) error

type MaixCamMessage

type MaixCamMessage struct {
	Type      string         `json:"type"`
	Tips      string         `json:"tips"`
	Timestamp float64        `json:"timestamp"`
	Data      map[string]any `json:"data"`
}

type Manager

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

func NewManager

func NewManager(cfg *config.Config, messageBus *bus.MessageBus) (*Manager, error)

func (*Manager) GetChannel

func (m *Manager) GetChannel(name string) (Channel, bool)

func (*Manager) GetEnabledChannels

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

func (*Manager) GetStatus

func (m *Manager) GetStatus() map[string]any

func (*Manager) RegisterChannel

func (m *Manager) RegisterChannel(name string, channel Channel)

func (*Manager) SendToChannel

func (m *Manager) SendToChannel(ctx context.Context, channelName, chatID, content string) error

func (*Manager) StartAll

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

func (*Manager) StopAll

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

func (*Manager) UnregisterChannel

func (m *Manager) UnregisterChannel(name string)

type OneBotChannel

type OneBotChannel struct {
	*BaseChannel
	// contains filtered or unexported fields
}

func NewOneBotChannel

func NewOneBotChannel(cfg config.OneBotConfig, messageBus *bus.MessageBus) (*OneBotChannel, error)

func (*OneBotChannel) Send

func (*OneBotChannel) SetTranscriber

func (c *OneBotChannel) SetTranscriber(transcriber *voice.GroqTranscriber)

func (*OneBotChannel) Start

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

func (*OneBotChannel) Stop

func (c *OneBotChannel) Stop(ctx context.Context) error

type PKCS7Padding

type PKCS7Padding struct{}

PKCS7Padding adds PKCS7 padding

type QQChannel

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

func NewQQChannel

func NewQQChannel(cfg config.QQConfig, messageBus *bus.MessageBus) (*QQChannel, error)

func (*QQChannel) Send

func (c *QQChannel) Send(ctx context.Context, msg bus.OutboundMessage) error

func (*QQChannel) Start

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

func (*QQChannel) Stop

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

type SlackChannel

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

func NewSlackChannel

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

func (*SlackChannel) Send

func (*SlackChannel) SetTranscriber

func (c *SlackChannel) SetTranscriber(transcriber *voice.GroqTranscriber)

func (*SlackChannel) Start

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

func (*SlackChannel) Stop

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

type TelegramChannel

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

func NewTelegramChannel

func NewTelegramChannel(cfg *config.Config, bus *bus.MessageBus) (*TelegramChannel, error)

func (*TelegramChannel) Send

func (*TelegramChannel) SetTranscriber

func (c *TelegramChannel) SetTranscriber(transcriber *voice.GroqTranscriber)

func (*TelegramChannel) Start

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

func (*TelegramChannel) Stop

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

type TelegramCommander

type TelegramCommander interface {
	Help(ctx context.Context, message telego.Message) error
	Start(ctx context.Context, message telego.Message) error
	Show(ctx context.Context, message telego.Message) error
	List(ctx context.Context, message telego.Message) error
}

func NewTelegramCommands

func NewTelegramCommands(bot *telego.Bot, cfg *config.Config) TelegramCommander

type WeComAccessTokenResponse

type WeComAccessTokenResponse struct {
	ErrCode     int    `json:"errcode"`
	ErrMsg      string `json:"errmsg"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

WeComAccessTokenResponse represents the access token API response

type WeComAppChannel

type WeComAppChannel struct {
	*BaseChannel
	// contains filtered or unexported fields
}

WeComAppChannel implements the Channel interface for WeCom App (企业微信自建应用)

func NewWeComAppChannel

func NewWeComAppChannel(cfg config.WeComAppConfig, messageBus *bus.MessageBus) (*WeComAppChannel, error)

NewWeComAppChannel creates a new WeCom App channel instance

func (*WeComAppChannel) Name

func (c *WeComAppChannel) Name() string

Name returns the channel name

func (*WeComAppChannel) Send

Send sends a message to WeCom user proactively using access token

func (*WeComAppChannel) Start

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

Start initializes the WeCom App channel with HTTP webhook server

func (*WeComAppChannel) Stop

func (c *WeComAppChannel) Stop(ctx context.Context) error

Stop gracefully stops the WeCom App channel

type WeComBotChannel

type WeComBotChannel struct {
	*BaseChannel
	// contains filtered or unexported fields
}

WeComBotChannel implements the Channel interface for WeCom Bot (企业微信智能机器人) Uses webhook callback mode - simpler than WeCom App but only supports passive replies

func NewWeComBotChannel

func NewWeComBotChannel(cfg config.WeComConfig, messageBus *bus.MessageBus) (*WeComBotChannel, error)

NewWeComBotChannel creates a new WeCom Bot channel instance

func (*WeComBotChannel) Name

func (c *WeComBotChannel) Name() string

Name returns the channel name

func (*WeComBotChannel) Send

Send sends a message to WeCom user via webhook API Note: WeCom Bot can only reply within the configured timeout (default 5 seconds) of receiving a message For delayed responses, we use the webhook URL

func (*WeComBotChannel) Start

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

Start initializes the WeCom Bot channel with HTTP webhook server

func (*WeComBotChannel) Stop

func (c *WeComBotChannel) Stop(ctx context.Context) error

Stop gracefully stops the WeCom Bot channel

type WeComBotMessage

type WeComBotMessage struct {
	MsgID    string `json:"msgid"`
	AIBotID  string `json:"aibotid"`
	ChatID   string `json:"chatid"`   // Session ID, only present for group chats
	ChatType string `json:"chattype"` // "single" for DM, "group" for group chat
	From     struct {
		UserID string `json:"userid"`
	} `json:"from"`
	ResponseURL string `json:"response_url"`
	MsgType     string `json:"msgtype"` // text, image, voice, file, mixed
	Text        struct {
		Content string `json:"content"`
	} `json:"text"`
	Image struct {
		URL string `json:"url"`
	} `json:"image"`
	Voice struct {
		Content string `json:"content"` // Voice to text content
	} `json:"voice"`
	File struct {
		URL string `json:"url"`
	} `json:"file"`
	Mixed struct {
		MsgItem []struct {
			MsgType string `json:"msgtype"`
			Text    struct {
				Content string `json:"content"`
			} `json:"text"`
			Image struct {
				URL string `json:"url"`
			} `json:"image"`
		} `json:"msg_item"`
	} `json:"mixed"`
	Quote struct {
		MsgType string `json:"msgtype"`
		Text    struct {
			Content string `json:"content"`
		} `json:"text"`
	} `json:"quote"`
}

WeComBotMessage represents the JSON message structure from WeCom Bot (AIBOT)

type WeComBotReplyMessage

type WeComBotReplyMessage struct {
	MsgType string `json:"msgtype"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text,omitempty"`
}

WeComBotReplyMessage represents the reply message structure

type WeComImageMessage

type WeComImageMessage struct {
	ToUser  string `json:"touser"`
	MsgType string `json:"msgtype"`
	AgentID int64  `json:"agentid"`
	Image   struct {
		MediaID string `json:"media_id"`
	} `json:"image"`
}

WeComImageMessage represents image message for sending

type WeComMarkdownMessage

type WeComMarkdownMessage struct {
	ToUser   string `json:"touser"`
	MsgType  string `json:"msgtype"`
	AgentID  int64  `json:"agentid"`
	Markdown struct {
		Content string `json:"content"`
	} `json:"markdown"`
}

WeComMarkdownMessage represents markdown message for sending

type WeComSendMessageResponse

type WeComSendMessageResponse struct {
	ErrCode      int    `json:"errcode"`
	ErrMsg       string `json:"errmsg"`
	InvalidUser  string `json:"invaliduser"`
	InvalidParty string `json:"invalidparty"`
	InvalidTag   string `json:"invalidtag"`
}

WeComSendMessageResponse represents the send message API response

type WeComTextMessage

type WeComTextMessage struct {
	ToUser  string `json:"touser"`
	MsgType string `json:"msgtype"`
	AgentID int64  `json:"agentid"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text"`
	Safe int `json:"safe,omitempty"`
}

WeComTextMessage represents text message for sending

type WeComXMLMessage

type WeComXMLMessage struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   `xml:"ToUserName"`
	FromUserName string   `xml:"FromUserName"`
	CreateTime   int64    `xml:"CreateTime"`
	MsgType      string   `xml:"MsgType"`
	Content      string   `xml:"Content"`
	MsgId        int64    `xml:"MsgId"`
	AgentID      int64    `xml:"AgentID"`
	PicUrl       string   `xml:"PicUrl"`
	MediaId      string   `xml:"MediaId"`
	Format       string   `xml:"Format"`
	ThumbMediaId string   `xml:"ThumbMediaId"`
	LocationX    float64  `xml:"Location_X"`
	LocationY    float64  `xml:"Location_Y"`
	Scale        int      `xml:"Scale"`
	Label        string   `xml:"Label"`
	Title        string   `xml:"Title"`
	Description  string   `xml:"Description"`
	Url          string   `xml:"Url"`
	Event        string   `xml:"Event"`
	EventKey     string   `xml:"EventKey"`
}

WeComXMLMessage represents the XML message structure from WeCom

type WhatsAppChannel

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

func NewWhatsAppChannel

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

func (*WhatsAppChannel) Send

func (*WhatsAppChannel) Start

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

func (*WhatsAppChannel) Stop

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

Jump to

Keyboard shortcuts

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