robot

package
v1.0.42 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 74 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AudioMsgLen = 600
)

Variables

View Source
var (
	BotName       string
	LarkBotClient *lark.Client
)
View Source
var (
	QQApi         openapi.OpenAPI
	QQTokenSource oauth2.TokenSource
	QQRobotInfo   *dto.User
)
View Source
var (
	RobotControl  = new(RobotController)
	TencentMsgMap sync.Map
)
View Source
var (
	ComWechatApp *work.Work
)
View Source
var (
	Cron *cron.Cron
)
View Source
var (
	DingBotClient *client.StreamClient
)
View Source
var (
	DiscordSession *discordgo.Session
)
View Source
var (
	OfficialAccountApp *officialAccount.OfficialAccount
)
View Source
var (
	SlackClient *slack.Client
)
View Source
var TelegramBot *tgbotapi.BotAPI

Functions

func AddCron added in v1.0.35

func AddCron(cronInfo *db.Cron) error

func C2CMessageEventHandler added in v1.0.19

func C2CMessageEventHandler(event *dto.WSPayload, message *dto.WSC2CMessageData) error

func CloseTalk added in v1.0.25

func CloseTalk(vc *discordgo.VoiceConnection)

func CreateBot

func CreateBot(ctx context.Context) *tgbotapi.BotAPI

func ExecComWechat added in v1.0.35

func ExecComWechat(c *db.Cron)

func ExecCron added in v1.0.35

func ExecCron(c *db.Cron)

func ExecDing added in v1.0.35

func ExecDing(c *db.Cron)

func ExecLark added in v1.0.35

func ExecLark(c *db.Cron)

func ExecPersonalQQ added in v1.0.35

func ExecPersonalQQ(c *db.Cron)

func ExecSlack added in v1.0.35

func ExecSlack(c *db.Cron)

func ExecTelegram added in v1.0.35

func ExecTelegram(c *db.Cron)

func ExecWechat added in v1.0.35

func ExecWechat(c *db.Cron)

func ForceReply added in v1.0.24

func ForceReply(chatId int64, msgId int, i18MsgId string, bot *tgbotapi.BotAPI) error

func GetMarkdownContent

func GetMarkdownContent(content string) string

func InitCron added in v1.0.35

func InitCron()

func LarkMessageHandler

func LarkMessageHandler(ctx context.Context, message *larkim.P2MessageReceiveV1) error

func OnChatReceive

func OnChatReceive(ctx context.Context, message *chatbot.BotCallbackDataModel) ([]byte, error)

func ParseCommand

func ParseCommand(prompt string) (command string, args string)

ParseCommand extracts command and arguments like /photo xxx

func QQATMessageEventHandler added in v1.0.19

func QQATMessageEventHandler(event *dto.WSPayload, atMessage *dto.WSATMessageData) error

func QQGroupATMessageEventHandler added in v1.0.19

func QQGroupATMessageEventHandler(event *dto.WSPayload, atMessage *dto.WSGroupATMessageData) error

func SlackButtonHandler

func SlackButtonHandler(callback *slack.InteractionCallback)

func SlackCmdHandler

func SlackCmdHandler(command *slack.SlashCommand)

func SlackMessageHandler

func SlackMessageHandler(message *slackevents.MessageEvent)

func StartComWechatRobot

func StartComWechatRobot(ctx context.Context)

func StartDingRobot

func StartDingRobot(ctx context.Context)

func StartDiscordRobot

func StartDiscordRobot(ctx context.Context)

func StartLarkRobot

func StartLarkRobot(ctx context.Context)

func StartQQRobot added in v1.0.19

func StartQQRobot(ctx context.Context)

func StartRobot

func StartRobot()

func StartSlackRobot

func StartSlackRobot(ctx context.Context)

func StartTelegramRobot

func StartTelegramRobot(ctx context.Context)

StartTelegramRobot start listen robot callback

func StartWechatRobot added in v1.0.19

func StartWechatRobot()

func WechatMsgSent added in v1.0.19

func WechatMsgSent(msgId string)

func WithContext added in v1.0.27

func WithContext(ctx context.Context) func(*RobotInfo)

func WithRobot

func WithRobot(robot Robot) func(*RobotInfo)

func WithSkipCheck added in v1.0.34

func WithSkipCheck(skipCheck bool) func(*RobotInfo)

func WithUseRecord added in v1.0.35

func WithUseRecord(userRecord bool) func(*RobotInfo)

Types

type AccessToken

type AccessToken struct {
	AccessToken string `json:"access_token"`
	ExpiredTime int64  `json:"expired_time"`
}

type ComWechatRobot

type ComWechatRobot struct {
	Event contract.EventInterface
	Robot *RobotInfo
	App   *work.Work

	Command      string
	Prompt       string
	OriginPrompt string
	ImageContent []byte
	VoiceContent []byte
	TextMsg      *serverModel.MessageText
	VoiceMsg     *serverModel.MessageVoice
	ImageMsg     *serverModel.MessageImage
	UserName     string
}

func NewComWechatRobot

func NewComWechatRobot(event contract.EventInterface) *ComWechatRobot

type DingResp

type DingResp struct {
	ErrCode int32  `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type DingRobot

type DingRobot struct {
	Robot   *RobotInfo
	Client  *client.StreamClient
	Message *chatbot.BotCallbackDataModel

	Command      string
	Prompt       string
	BotName      string
	OriginPrompt string
	ImageContent []byte
	AudioContent []byte
	UserName     string
}

func NewDingRobot

func NewDingRobot(message *chatbot.BotCallbackDataModel) *DingRobot

func (*DingRobot) CreateDingAuthClient

func (d *DingRobot) CreateDingAuthClient() (_result *dingtalkoauth2.Client, _err error)

func (*DingRobot) CreateDingInteractClient

func (d *DingRobot) CreateDingInteractClient() (_result *dingtalkaiinteraction.Client, _err error)

func (*DingRobot) CreateDingRobotClient

func (d *DingRobot) CreateDingRobotClient() (result *dingtalkrobot.Client, err error)

func (*DingRobot) GetAccessToken

func (d *DingRobot) GetAccessToken() (string, error)

func (*DingRobot) GetImageContent

func (d *DingRobot) GetImageContent(accessToken string, c map[string]interface{}) ([]byte, error)

func (*DingRobot) GetMessageContent

func (d *DingRobot) GetMessageContent() (bool, error)

func (*DingRobot) ReplyMessage

func (d *DingRobot) ReplyMessage(ctx context.Context, requestBody map[string]interface{}) (*DingResp, error)

func (*DingRobot) SimpleReplyMarkdown

func (d *DingRobot) SimpleReplyMarkdown(ctx context.Context, content []byte) (*DingResp, error)

func (*DingRobot) UploadFileWithType

func (d *DingRobot) UploadFileWithType(accessToken, fileType, filePath string, fileContent []byte) (string, error)

func (*DingRobot) VideoReplyMarkdown

func (d *DingRobot) VideoReplyMarkdown(ctx context.Context, mediaId, format string) (*DingResp, error)

func (*DingRobot) VoiceReplyMarkdown added in v1.0.24

func (d *DingRobot) VoiceReplyMarkdown(ctx context.Context, mediaId string, duration int) (*DingResp, error)

type DiscordRobot

type DiscordRobot struct {
	Session *discordgo.Session
	Msg     *discordgo.MessageCreate
	Inter   *discordgo.InteractionCreate

	Robot        *RobotInfo
	Prompt       string
	Command      string
	ImageContent []byte
	AudioContent []byte
	UserName     string
}

func (*DiscordRobot) PlayAudioToDiscord added in v1.0.25

func (d *DiscordRobot) PlayAudioToDiscord(vc *discordgo.VoiceConnection)

func (*DiscordRobot) Talk added in v1.0.25

func (d *DiscordRobot) Talk()

type Element added in v1.0.31

type Element struct {
	ElementID   string       `json:"elementId"`
	ElementType int          `json:"elementType"`
	TextElement *TextElement `json:"textElement,omitempty"`
}

type FileData added in v1.0.19

type FileData struct {
	FileUUID string `json:"file_uuid"`
	FileInfo []byte `json:"file_info"`
	TTL      int    `json:"ttl"`
	ID       string `json:"id"`
}

type LarkRobot

type LarkRobot struct {
	Message *larkim.P2MessageReceiveV1
	Robot   *RobotInfo
	Client  *lark.Client

	Command      string
	Prompt       string
	BotName      string
	ImageContent []byte
	AudioContent []byte
	UserName     string
}

func NewLarkRobot

func NewLarkRobot(message *larkim.P2MessageReceiveV1) *LarkRobot

func (*LarkRobot) GetMessageContent

func (l *LarkRobot) GetMessageContent() (bool, error)

type MessageItem added in v1.0.31

type MessageItem struct {
	Data MessageItemData `json:"data"`
	Type string          `json:"type"`
}

type MessageItemData added in v1.0.34

type MessageItemData struct {
	Text string `json:"text"`
	Url  string `json:"url"`
	QQ   string `json:"qq"`
}

type MessagePostContent

type MessagePostContent struct {
	Title   string                 `json:"title"`
	Content [][]MessagePostElement `json:"content"`
}

type MessagePostElement

type MessagePostElement struct {
	Tag      string `json:"tag"`
	Text     string `json:"text"`
	ImageKey string `json:"image_key"`
	UserName string `json:"user_name"`
}

type MessagePostMarkdown

type MessagePostMarkdown struct {
	Text string `json:"text,omitempty"`
}

func (*MessagePostMarkdown) IsPost

func (m *MessagePostMarkdown) IsPost()

func (*MessagePostMarkdown) MarshalJSON

func (m *MessagePostMarkdown) MarshalJSON() ([]byte, error)

func (*MessagePostMarkdown) Tag

func (m *MessagePostMarkdown) Tag() string

type MessageText

type MessageText struct {
	Text string `json:"text"`
}

type MsgChan added in v1.0.19

type MsgChan struct {
	NormalMessageChan chan *param.MsgInfo
	StrMessageChan    chan string
}

type OneBotResult added in v1.0.32

type OneBotResult struct {
	MessageID string `json:"message_id"`
	Status    string `json:"status"`
}

type PersonalQQRobot added in v1.0.31

type PersonalQQRobot struct {
	Msg   *QQMessage
	Robot *RobotInfo
	Ctx   context.Context

	Command      string
	Prompt       string
	OriginPrompt string
	ImageContent []byte
	AudioContent []byte
	UserName     string
}

func NewPersonalQQRobot added in v1.0.31

func NewPersonalQQRobot(ctx context.Context, msgContent []byte) *PersonalQQRobot

func (*PersonalQQRobot) GetMessageContent added in v1.0.31

func (q *PersonalQQRobot) GetMessageContent() (bool, error)

func (*PersonalQQRobot) SendMsg added in v1.0.31

func (q *PersonalQQRobot) SendMsg(txt string, image []byte, video []byte, voice []byte) (string, error)

type QQMessage added in v1.0.31

type QQMessage struct {
	Font          int           `json:"font"`
	GroupId       string        `json:"group_id"`
	Message       []MessageItem `json:"message"`
	MessageFormat string        `json:"message_format"`
	MessageID     string        `json:"message_id"`
	MessageSeq    int64         `json:"message_seq"`
	MessageType   string        `json:"message_type"`
	PostType      string        `json:"post_type"`
	Raw           RawMessage    `json:"raw"`
	RawMessage    string        `json:"raw_message"`
	RealID        int64         `json:"real_id"`
	RealSeq       string        `json:"real_seq"`
	SelfID        string        `json:"self_id"`
	Sender        SenderInfo    `json:"sender"`
	SubType       string        `json:"sub_type"`
	TargetID      int64         `json:"target_id"`
	Time          int64         `json:"time"`
	UserID        string        `json:"user_id"`
}

type QQRobot added in v1.0.19

type QQRobot struct {
	Robot         *RobotInfo
	QQApi         openapi.OpenAPI
	QQTokenSource oauth2.TokenSource
	RobotInfo     *dto.User

	C2CMessage     *dto.WSC2CMessageData
	GroupAtMessage *dto.WSGroupATMessageData
	ATMessage      *dto.WSATMessageData

	Command      string
	Prompt       string
	BotName      string
	OriginPrompt string
	ImageContent []byte
	AudioContent []byte
	UserName     string
}

func NewQQRobot added in v1.0.19

func NewQQRobot(c2cMessage *dto.WSC2CMessageData,
	atGroupMessage *dto.WSGroupATMessageData, atMessage *dto.WSATMessageData) *QQRobot

func (*QQRobot) GetAttachment added in v1.0.19

func (q *QQRobot) GetAttachment() *dto.MessageAttachment

func (*QQRobot) PostRichMediaMessage added in v1.0.19

func (q *QQRobot) PostRichMediaMessage(data []byte, content string) error

func (*QQRobot) PostStreamMessage added in v1.0.19

func (q *QQRobot) PostStreamMessage(state, idx int32, id, content string) (string, error)

func (*QQRobot) UploadFile added in v1.0.19

func (q *QQRobot) UploadFile(imageContent string, fileType int) ([]byte, error)

type RawMessage added in v1.0.31

type RawMessage struct {
	ID             int64     `json:"id"`
	MsgID          string    `json:"msgId"`
	MsgSeq         string    `json:"msgSeq"`
	MsgTime        string    `json:"msgTime"`
	MsgType        int       `json:"msgType"`
	SubMsgType     int       `json:"subMsgType"`
	PeerUin        string    `json:"peerUin"`
	SenderUin      string    `json:"senderUin"`
	SenderUid      string    `json:"senderUid"`
	PeerUid        string    `json:"peerUid"`
	ClientSeq      string    `json:"clientSeq"`
	MsgRandom      string    `json:"msgRandom"`
	SendStatus     int       `json:"sendStatus"`
	SendType       int       `json:"sendType"`
	ChatType       int       `json:"chatType"`
	IsOnlineMsg    bool      `json:"isOnlineMsg"`
	IsImportMsg    bool      `json:"isImportMsg"`
	SourceType     int       `json:"sourceType"`
	FromAppID      string    `json:"fromAppid"`
	FromUid        string    `json:"fromUid"`
	PeerName       string    `json:"peerName"`
	SendNickName   string    `json:"sendNickName"`
	SendMemberName string    `json:"sendMemberName"`
	SendRemarkName string    `json:"sendRemarkName"`
	Elements       []Element `json:"elements"`
}

RawMessage 部分嵌套字段很多,以下是主要结构(可按需精简)

type Robot

type Robot interface {
	// contains filtered or unexported methods
}

type RobotController

type RobotController struct {
	Cancel context.CancelFunc
}

type RobotInfo

type RobotInfo struct {
	Ctx    context.Context
	Cancel context.CancelFunc
	Robot  Robot
	// contains filtered or unexported fields
}

func NewRobot

func NewRobot(options ...botOption) *RobotInfo

func (*RobotInfo) AddUserInfo added in v1.0.31

func (r *RobotInfo) AddUserInfo() bool

func (*RobotInfo) CreatePhoto added in v1.0.23

func (r *RobotInfo) CreatePhoto(prompt string, lastImageContent []byte) ([]byte, int, error)

func (*RobotInfo) CreateVideo added in v1.0.23

func (r *RobotInfo) CreateVideo(prompt string, lastImageContent []byte) ([]byte, int, error)

func (*RobotInfo) Exec

func (r *RobotInfo) Exec()

func (*RobotInfo) ExecChain

func (r *RobotInfo) ExecChain(msgContent string, msgChan *MsgChan)

func (*RobotInfo) ExecCmd

func (r *RobotInfo) ExecCmd(cmd string, defaultFunc func(), modeFunc func(string), typesFunc func(string))

func (*RobotInfo) ExecLLM

func (r *RobotInfo) ExecLLM(msgContent string, msgChan *MsgChan)

func (*RobotInfo) GetAudioContent

func (r *RobotInfo) GetAudioContent(audioContent []byte) (string, error)

func (*RobotInfo) GetChatIdAndMsgIdAndUserID

func (r *RobotInfo) GetChatIdAndMsgIdAndUserID() (string, string, string)

func (*RobotInfo) GetLastImageContent

func (r *RobotInfo) GetLastImageContent() ([]byte, error)

func (*RobotInfo) GetVoiceBaseTTS added in v1.0.24

func (r *RobotInfo) GetVoiceBaseTTS(content, encoding string) ([]byte, int, error)

func (*RobotInfo) HandleUpdate added in v1.0.25

func (r *RobotInfo) HandleUpdate(messageChan *MsgChan, encoding string)

func (*RobotInfo) InsertCron added in v1.0.35

func (r *RobotInfo) InsertCron(cron, prompt string) error

func (*RobotInfo) InsertRecord added in v1.0.24

func (r *RobotInfo) InsertRecord()

func (*RobotInfo) SendMarkdownMsg added in v1.0.37

func (r *RobotInfo) SendMarkdownMsg(msg *param.MsgInfo)

func (*RobotInfo) SendMsg

func (r *RobotInfo) SendMsg(chatId string, msgContent string, replyToMessageID string,
	mode string, inlineKeyboard *tgbotapi.InlineKeyboardMarkup) string

func (*RobotInfo) TalkingPreCheck

func (r *RobotInfo) TalkingPreCheck(f func())

type RobotModel added in v1.0.31

type RobotModel struct {
	TxtType    string
	ImgType    string
	VideoType  string
	TxtModel   string
	ImgModel   string
	VideoModel string
	RecType    string
	RecModel   string
	TTSType    string
	TTSModel   string
}

type SenderInfo added in v1.0.31

type SenderInfo struct {
	Card     string `json:"card"`
	Nickname string `json:"nickname"`
	UserID   string `json:"user_id"`
}

type SlackRobot

type SlackRobot struct {
	Event    *slackevents.MessageEvent
	CmdEvent *slack.SlashCommand
	Callback *slack.InteractionCallback

	Robot   *RobotInfo
	Client  *slack.Client
	Command string
	Prompt  string
	BotName string

	ImageContent []byte
	VoiceContent []byte
	UserName     string
}

func NewSlackRobot

func NewSlackRobot(message *slackevents.MessageEvent, command *slack.SlashCommand,
	callback *slack.InteractionCallback) *SlackRobot

type SmartModeResult added in v1.0.32

type SmartModeResult struct {
	Command string `json:"command"`
	Prompt  string `json:"prompt"`
	Cron    string `json:"cron"`
}

type StreamRobot added in v1.0.38

type StreamRobot interface {
	// contains filtered or unexported methods
}

type TelegramRobot

type TelegramRobot struct {
	Update tgbotapi.Update
	Bot    *tgbotapi.BotAPI

	Robot        *RobotInfo
	Prompt       string
	Command      string
	ImageContent []byte
	AudioContent []byte
	UserName     string
}

func NewTelegramRobot

func NewTelegramRobot(update tgbotapi.Update, bot *tgbotapi.BotAPI) *TelegramRobot

func (*TelegramRobot) ExecuteForceReply

func (t *TelegramRobot) ExecuteForceReply()

ExecuteForceReply use force reply interact with user

func (*TelegramRobot) GetAudioContent

func (t *TelegramRobot) GetAudioContent() []byte

func (*TelegramRobot) GetPhotoContent

func (t *TelegramRobot) GetPhotoContent() []byte

type TencentWechatMessage added in v1.0.22

type TencentWechatMessage struct {
	Msg       string
	Status    int
	StartTime time.Time
}

type TextElement added in v1.0.31

type TextElement struct {
	Content string `json:"content"`
}

type UploadFileRequest added in v1.0.19

type UploadFileRequest struct {
	FileType   int    `json:"file_type"`
	URL        string `json:"url"`
	SrvSendMsg bool   `json:"srv_send_msg"`
	FileData   string `json:"file_data"`
}

type VolDialog added in v1.0.25

type VolDialog struct {
	VolWsConn *websocket.Conn
	Audio     []byte

	CallUserId string
	Token      int
	Ctx        context.Context
	Cancel     context.CancelFunc
}

type Web

type Web struct {
	Command      string
	UserId       int64
	RealUserId   string
	Prompt       string
	ImageContent []byte
	AudioContent []byte

	OriginalPrompt string

	W       http.ResponseWriter
	Flusher http.Flusher

	Robot *RobotInfo
	// contains filtered or unexported fields
}

func NewWeb

func NewWeb(command string, userId int64, realUserId, prompt, originalPrompt string, bodyData []byte, w http.ResponseWriter, flusher http.Flusher) *Web

func (*Web) AddUserInfo added in v1.0.31

func (web *Web) AddUserInfo() bool

func (*Web) InsertRecord added in v1.0.24

func (web *Web) InsertRecord()

func (*Web) SendMsg

func (web *Web) SendMsg(msgContent string)

type WechatRobot added in v1.0.19

type WechatRobot struct {
	Event contract.EventInterface
	Robot *RobotInfo
	App   *officialAccount.OfficialAccount

	Command      string
	Prompt       string
	OriginPrompt string
	ImageContent []byte
	VoiceContent []byte

	TextMsg  *serverModel.MessageText
	VoiceMsg *serverModel.MessageVoice
	ImageMsg *serverModel.MessageImage
	UserName string
}

func NewWechatRobot added in v1.0.19

func NewWechatRobot(event contract.EventInterface) (*WechatRobot, bool)

func (*WechatRobot) GetLLMContent added in v1.0.19

func (w *WechatRobot) GetLLMContent() interface{}

Jump to

Keyboard shortcuts

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