bot_context

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ElemsToString

func ElemsToString(elems []*MessageElement) string

Types

type BaseBuilder

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

func NewBuilder

func NewBuilder() *BaseBuilder

func (*BaseBuilder) Append

func (b *BaseBuilder) Append(elementType ElementType, content string, source string) *BaseBuilder

func (*BaseBuilder) Build

func (b *BaseBuilder) Build() []*MessageElement

func (*BaseBuilder) Mention

func (b *BaseBuilder) Mention(id string) *BaseBuilder

func (*BaseBuilder) Quote

func (b *BaseBuilder) Quote(msg *BaseMessage) *BaseBuilder

func (*BaseBuilder) Text

func (b *BaseBuilder) Text(text string) *BaseBuilder

type BaseMessage

type BaseMessage struct {
	MessageType MessageType
	ID          string
	Content     string
	Elements    []*MessageElement
	Sender      *entity.Sender
	Time        time.Time
}

func UnmarshallMessage

func UnmarshallMessage(str string) (*BaseMessage, error)

func (*BaseMessage) Marshall

func (m *BaseMessage) Marshall() string

type BotContext

type BotContext interface {
	FeatureProvider
	ID() string
	Name() string
	Protocol() string
	Status() LoginStatus
	NewMessageBuilder() MessageBuilder
	SendDirectMessage(target entity.User, elements []*MessageElement) (*BaseMessage, error)
	SendGroupMessage(target entity.Group, elements []*MessageElement) (*BaseMessage, error)
	Contacts() []entity.User
	Groups() []entity.Group
	DownloadResourceFromRefLink(refLink string) (string, error)
}

type ButtonActionType added in v0.2.0

type ButtonActionType int

ButtonActionType 定义按钮点击交互动作类型

const (
	// ActionURL 打开链接
	ActionURL ButtonActionType = 0
	// ActionCallback 回调交互型(向服务端发送回调事件,例如 Telegram callback_data / QQ INTERACTION_CREATE)
	ActionCallback ButtonActionType = 1
	// ActionCommand 指令发送型(自动发送指令或填入输入框)
	ActionCommand ButtonActionType = 2
)

type ElementType

type ElementType int
const (
	TextElement ElementType = iota
	QuoteElement
	MentionElement
	ImageElement
	VideoElement
	FileElement
	VoiceElement
	StickerElement
	LinkElement
	InlineKeyboardElement
	OtherElement
)

type Feature added in v0.2.0

type Feature string

Feature 定义适配器所支持的能力特性

const (
	FeatureText           Feature = "text"
	FeatureImage          Feature = "image"
	FeatureMarkdown       Feature = "markdown"
	FeatureInlineImage    Feature = "inline_image"
	FeatureVoice          Feature = "voice"
	FeatureFile           Feature = "file"
	FeatureInlineKeyboard Feature = "inline_keyboard"
)

type FeatureProvider added in v0.2.0

type FeatureProvider interface {
	// Features 返回当前适配器所支持的所有特性列表
	Features() []Feature
	// SupportsFeature 判断当前适配器是否支持某个特性
	SupportsFeature(feature Feature) bool
}

FeatureProvider 接口表示提供特性支持查询的对象

type InlineKeyboard added in v0.2.0

type InlineKeyboard struct {
	Rows [][]InlineKeyboardButton `json:"rows"`
}

InlineKeyboard 跨平台统一内嵌键盘(多行按钮)

func NewInlineKeyboard added in v0.2.0

func NewInlineKeyboard() *InlineKeyboard

NewInlineKeyboard 创建空内嵌键盘

func ParseInlineKeyboard added in v0.2.0

func ParseInlineKeyboard(data string) (*InlineKeyboard, error)

FromJSON 从 JSON 反序列化 InlineKeyboard

func (*InlineKeyboard) AddRow added in v0.2.0

func (kb *InlineKeyboard) AddRow(buttons ...InlineKeyboardButton) *InlineKeyboard

AddRow 添加一行按钮

func (*InlineKeyboard) ToJSON added in v0.2.0

func (kb *InlineKeyboard) ToJSON() (string, error)

ToJSON 将 InlineKeyboard 序列化为 JSON 字符串

type InlineKeyboardButton added in v0.2.0

type InlineKeyboardButton struct {
	// Text 按钮显示文本
	Text string `json:"text"`
	// Action 动作类型:ActionURL, ActionCallback, ActionCommand
	Action ButtonActionType `json:"action"`
	// Data 对应动作携带的数据:ActionURL为链接,ActionCallback为回调标识/数据,ActionCommand为待发送文本
	Data string `json:"data"`
	// DirectSend 指令型按钮是否直接发送(仅对支持的平台有效,如 QQ 机器人 enter=true)
	DirectSend bool `json:"direct_send,omitempty"`
	// ID 可选,指定按钮唯一ID(QQ等平台需要时使用,留空则自动生成)
	ID string `json:"id,omitempty"`
}

InlineKeyboardButton 跨平台统一内嵌按钮

func NewCallbackButton added in v0.2.0

func NewCallbackButton(text, callbackData string) InlineKeyboardButton

NewCallbackButton 创建回调型按钮

func NewCommandButton added in v0.2.0

func NewCommandButton(text, cmd string, directSend bool) InlineKeyboardButton

NewCommandButton 创建指令型按钮

func NewURLButton added in v0.2.0

func NewURLButton(text, url string) InlineKeyboardButton

NewURLButton 创建打开网址按钮

type LoginStatus

type LoginStatus int
const (
	Offline LoginStatus = iota
	Online
	Connect
	Disconnect
	Reconnect
)

type MessageBuilder

type MessageBuilder interface {
	Protocol() string
	Text(text string) MessageBuilder
	Quote(msg *BaseMessage) MessageBuilder
	Mention(id string) MessageBuilder
	ImageFromFile(path string) MessageBuilder
	ImageFromUrl(url string) MessageBuilder
	ImageFromData(data []byte) MessageBuilder
	InlineKeyboard(kb *InlineKeyboard) MessageBuilder
	ReplyTo(msg MessageContext) (*BaseMessage, error)
	Send(id string) (*BaseMessage, error)
}

type MessageContext

type MessageContext interface {
	FeatureProvider
	Protocol() string
	BotContext() BotContext
	String() string
	Message() *BaseMessage
	SenderID() string
	NewMessageBuilder() MessageBuilder
	Reply(elements []*MessageElement) (*BaseMessage, error)
	ReplyText(a ...any) (*BaseMessage, error)
}

type MessageElement

type MessageElement struct {
	Type    ElementType
	Content string
	Source  string
}

type MessageType

type MessageType int
const (
	DirectMessage MessageType = iota
	GroupMessage
)

Jump to

Keyboard shortcuts

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