messaging

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESKeyToBase64

func AESKeyToBase64(hexKey string) string

AESKeyToBase64 converts a hex AES key to base64(hex_string) format for message items. Used for outbound messages (file/voice/video).

func DownloadFileFromCDN

func DownloadFileFromCDN(ctx context.Context, encryptQueryParam, aesKeyBase64 string) ([]byte, error)

DownloadFileFromCDN downloads and decrypts a file from the WeChat CDN.

func ExtractImageURLs

func ExtractImageURLs(text string) []string

ExtractImageURLs extracts image URLs from markdown text.

func ExtractURL

func ExtractURL(text string) string

ExtractURL extracts the first URL from text.

func HexKeyToBase64

func HexKeyToBase64(hexKey string) string

HexKeyToBase64 converts a hex AES key to base64(raw_bytes) format. Used for image_item.aeskey which is raw hex.

func IsURL

func IsURL(text string) bool

IsURL checks if the text is (or starts with) a URL.

func MarkdownToPlainText

func MarkdownToPlainText(text string) string

MarkdownToPlainText converts markdown to readable plain text for WeChat.

func NewClientID

func NewClientID() string

NewClientID generates a new unique client ID for message correlation.

func SaveLinkToLinkhoard

func SaveLinkToLinkhoard(ctx context.Context, saveDir, rawURL string) (string, error)

SaveLinkToLinkhoard fetches a URL and saves it as a Linkhoard-compatible markdown file. WeChat articles use direct fetch with browser headers; other sites use Jina Reader.

func SendMediaFromPath

func SendMediaFromPath(ctx context.Context, client *ilink.Client, toUserID, path, contextToken string) error

SendMediaFromPath reads a local file and sends it as a media message.

func SendMediaFromURL

func SendMediaFromURL(ctx context.Context, client *ilink.Client, toUserID, mediaURL, contextToken string) error

SendMediaFromURL downloads a file from a URL and sends it as a media message.

func SendTextReply

func SendTextReply(ctx context.Context, client *ilink.Client, toUserID, text, contextToken, clientID string) error

SendTextReply sends a text reply to a user through the iLink API. If clientID is empty, a new one is generated.

func SendTypingState

func SendTypingState(ctx context.Context, client *ilink.Client, userID, contextToken string) error

SendTypingState sends a typing indicator to a user via the iLink sendtyping API. It first fetches a typing_ticket via getconfig, then sends the typing status.

Types

type AgentFactory

type AgentFactory func(ctx context.Context, name string) agent.Agent

AgentFactory creates an agent by config name. Returns nil if the name is unknown.

type AgentMeta

type AgentMeta struct {
	Name    string
	Type    string // "acp", "cli", "http"
	Command string // binary path or endpoint
	Model   string
}

AgentMeta holds static config info about an agent (for /status display).

type Handler

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

Handler processes incoming WeChat messages and dispatches replies.

func NewHandler

func NewHandler(factory AgentFactory, saveDefault SaveDefaultFunc) *Handler

NewHandler creates a new message handler.

func (*Handler) HandleMessage

func (h *Handler) HandleMessage(ctx context.Context, client *ilink.Client, msg ilink.WeixinMessage)

HandleMessage processes a single incoming message.

func (*Handler) SetAgentMetas

func (h *Handler) SetAgentMetas(metas []AgentMeta)

SetAgentMetas sets the list of all configured agents (for /status).

func (*Handler) SetAgentWorkDirs

func (h *Handler) SetAgentWorkDirs(workDirs map[string]string)

SetAgentWorkDirs sets the configured working directory for each agent.

func (*Handler) SetCustomAliases

func (h *Handler) SetCustomAliases(aliases map[string]string)

SetCustomAliases sets custom alias mappings from config.

func (*Handler) SetDefaultAgent

func (h *Handler) SetDefaultAgent(name string, ag agent.Agent)

SetDefaultAgent sets the default agent (already started).

func (*Handler) SetSaveDir

func (h *Handler) SetSaveDir(dir string)

SetSaveDir sets the directory for saving images and files.

type LinkMetadata

type LinkMetadata struct {
	Title       string
	Description string
	Author      string
	OGImage     string
	Published   string
	Body        string
}

LinkMetadata holds extracted metadata from a web page.

func FetchLinkMetadata

func FetchLinkMetadata(ctx context.Context, rawURL string) (*LinkMetadata, error)

FetchLinkMetadata fetches a URL and extracts metadata from the HTML.

func FetchViaJina

func FetchViaJina(ctx context.Context, rawURL string) (*LinkMetadata, error)

FetchViaJina fetches a URL via Jina Reader API and returns metadata + markdown body.

type SaveDefaultFunc

type SaveDefaultFunc func(name string) error

SaveDefaultFunc persists the default agent name to config file.

type UploadedFile

type UploadedFile struct {
	DownloadParam string // encrypted query param for download
	AESKeyHex     string // hex-encoded AES key
	FileSize      int    // plaintext size
	CipherSize    int    // ciphertext size
}

UploadedFile holds the result of a CDN upload.

func UploadFileToCDN

func UploadFileToCDN(ctx context.Context, client *ilink.Client, data []byte, toUserID string, mediaType int) (*UploadedFile, error)

UploadFileToCDN encrypts and uploads a file to the WeChat CDN.

Jump to

Keyboard shortcuts

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