protocol

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetLatestEventsAction     = "get_latest_events"
	GetSupportedActionsAction = "get_supported_actions"
	GetStatusAction           = "get_status"
	GetVersionAction          = "get_version"

	SendMessageAction = "send_message"

	GetUserInfoAction = "get_user_info"

	CreateChannelAction  = "create_channel"
	GetChannelInfoAction = "get_channel_info"
	GetChannelListAction = "get_channel_list"
)
View Source
const (
	MetaConnectEvent      = "meta.connect"
	MetaHeartbeatEvent    = "meta.heartbeat"
	MetaStatusUpdateEvent = "meta.status_update"

	MessageDirectEvent  = "message.direct"
	MessageGroupEvent   = "message.group"
	MessageChannelEvent = "message.channel"
	MessageCommandEvent = "message.command"

	NoticeFriendIncreaseEvent      = "notice.friend_increase"
	NoticeFriendDecreaseEvent      = "notice.friend_decrease"
	NoticeGroupMemberIncreaseEvent = "notice.group_member_increase"
	NoticeGroupMemberDecreaseEvent = "notice.group_member_decrease"
	NoticeChannelCreateEvent       = "notice.channel_create"
	NoticeChannelDeleteEvent       = "notice.channel_delete"
)

Variables

View Source
var ErrAccessDenied = NewError(60007, "access denied")

ErrAccessDenied Access Denied

View Source
var ErrBadHandler = NewError(20001, "bad handler")

ErrBadHandler Response status not set correctly, etc.

View Source
var ErrBadParam = NewError(10003, "bad parameter")

ErrBadParam Missing parameter or wrong parameter type

View Source
var ErrBadRequest = NewError(10001, "bad request")

ErrBadRequest Formatting errors (including implementations that do not support MessagePack), missing required fields, or incorrect field types

View Source
var ErrBadSegmentData = NewError(10007, "bad segment data")

ErrBadSegmentData The Chatbot implementation does not implement the semantics of this parameter

View Source
var ErrBadSegmentType = NewError(10006, "bad segment type")

ErrBadSegmentType Missing parameter or wrong parameter type

View Source
var ErrDatabaseError = NewError(31001, "database error")

ErrDatabaseError Such as database query failure

View Source
var ErrDatabaseReadError = NewError(31002, "database read error")

ErrDatabaseReadError Such as database read failure

View Source
var ErrDatabaseWriteError = NewError(31003, "database write error")

ErrDatabaseWriteError Such as database write failure

View Source
var ErrEmitEventError = NewError(37001, "emit event error")

ErrEmitEventError Emit event error

View Source
var ErrFilesystemError = NewError(32001, "filesystem error")

ErrFilesystemError If reading or writing a file fails, etc.

View Source
var ErrFlagError = NewError(60003, "flag error")

ErrFlagError Flag error

View Source
var ErrFlagExpired = NewError(60004, "flag expired")

ErrFlagExpired Flag expired

View Source
var ErrIAmTired = NewError(36001, "i am tired")

ErrIAmTired A Chatbot realizes the decision to strike.

View Source
var ErrInternalHandler = NewError(20002, "internal handler")

ErrInternalHandler An uncaught and unexpected exception has occurred within the Chatbot implementation.

View Source
var ErrInternalServerError = NewError(10000, "internal server error")

ErrInternalServerError Internal server error

View Source
var ErrLoginError = NewError(35001, "login error")

ErrLoginError Such as trying to send a message to a non-existent user

View Source
var ErrMethodNotAllowed = NewError(10008, "invalid http method")

ErrMethodNotAllowed Invalid HTTP method

View Source
var ErrNetworkError = NewError(33001, "network error")

ErrNetworkError e.g. failed to download a file, etc.

View Source
var ErrNotAuthorized = NewError(60005, "not authorized")

ErrNotAuthorized Not authorized

View Source
var ErrNotFound = NewError(10009, "not found")

ErrNotFound not found

View Source
var ErrOAuthError = NewError(60006, "oauth error")

ErrOAuthError OAuth error

View Source
var ErrParamVerificationFailed = NewError(10031, "parameter verification failed")

ErrParamVerificationFailed Missing parameter or wrong parameter type

View Source
var ErrPlatformError = NewError(34001, "platform error")

ErrPlatformError e.g. failure to send messages due to bot platform limitations, etc.

View Source
var ErrSendMessageFailed = NewError(60002, "send message failed")

ErrSendMessageFailed Failed to send a message

View Source
var ErrShutdownError = NewError(38001, "shutdown error")

ErrShutdownError Shutdown error

View Source
var ErrTokenError = NewError(60001, "missing, invalid or expired access token")

ErrTokenError missing, invalid or expired access token

View Source
var ErrUnknownSelf = NewError(10102, "unknown self")

ErrUnknownSelf The bot account specified by the action request does not exist

View Source
var ErrUnsupported = NewError(10004, "unsupported")

ErrUnsupported The Chatbot implementation does not implement the semantics of this parameter

View Source
var ErrUnsupportedAction = NewError(10002, "unsupported action")

ErrUnsupportedAction The Chatbot implementation does not implement this action

View Source
var ErrUnsupportedSegment = NewError(10005, "unsupported segment")

ErrUnsupportedSegment The Chatbot implementation does not implement this segment type.

View Source
var ErrWhoAmI = NewError(10101, "who am i")

ErrWhoAmI Chatbot implements support for multiple bot accounts on a single Chatbot Connect connection, but the action request does not specify the account to be used

Functions

This section is empty.

Types

type Action

type Action interface {
	// GetLatestEvents get latest events, Only the HTTP communication method must be supported for polling for events.
	GetLatestEvents(req Request) Response
	// GetSupportedActions get supported actions
	GetSupportedActions(req Request) Response
	// GetStatus get status
	GetStatus(req Request) Response
	// GetVersion get version
	GetVersion(req Request) Response

	// SendMessage send message
	SendMessage(req Request) Response

	// GetUserInfo get user info
	GetUserInfo(req Request) Response

	// CreateChannel create channel
	CreateChannel(req Request) Response
	// GetChannelInfo get channel info
	GetChannelInfo(req Request) Response
	// GetChannelList get channel list
	GetChannelList(req Request) Response

	// RegisterChannels register channels
	RegisterChannels(req Request) Response
	// RegisterSlashCommands register slash commands
	RegisterSlashCommands(req Request) Response
}

Action An interface for the application to actively obtain information about the Chatbot implementation or robot platform and to control the behavior of the Chatbot implementation or robot.

type Adapter

type Adapter interface {
	MessageConvert(data any) Message
	EventConvert(data any) Event
}

Adapter Responsible for converting platform messages to chatbot event/message formats.

type Command

type Command struct {
	Token          string `json:"token"`
	TeamID         string `json:"team_id"`
	TeamDomain     string `json:"team_domain"`
	EnterpriseID   string `json:"enterprise_id,omitempty"`
	EnterpriseName string `json:"enterprise_name,omitempty"`
	ChannelID      string `json:"channel_id"`
	ChannelName    string `json:"channel_name"`
	UserID         string `json:"user_id"`
	UserName       string `json:"user_name"`
	Command        string `json:"command"`
	Text           string `json:"text"`
	ResponseURL    string `json:"response_url"`
	TriggerID      string `json:"trigger_id"`
	APIAppID       string `json:"api_app_id"`

	Prefix string `json:"prefix"`
}

type CommandEventData

type CommandEventData struct {
	Command string `json:"command,omitempty"`
}

type Driver

type Driver interface {
	// HttpServer The application can actively access the Chatbot implementation.
	HttpServer(ctx *fiber.Ctx) error
	// HttpWebhookClient Chatbot implements active access to applications
	HttpWebhookClient(message Message) error
	// WebSocketClient The application can actively access the Chatbot implementation.
	WebSocketClient(stop <-chan bool)
	// WebSocketServer Chatbot implements active access to applications
	WebSocketServer(stop <-chan bool)
}

Driver Functional implementation of the client/server responsible for receiving and sending messages (usually HTTP communication)

type Error

type Error struct {
	Code    int64  `json:"code"`
	Message string `json:"message"`
}

func NewError

func NewError(code int64, message string) *Error

func (Error) Error

func (e Error) Error() string

func (Error) GetCode

func (e Error) GetCode() int64

func (Error) GetMessage

func (e Error) GetMessage() string

type Event

type Event struct {
	Id         string    `json:"id"`
	Time       int64     `json:"time"`
	Type       EventType `json:"type"`
	DetailType string    `json:"detail_type"`
	Data       any       `json:"data"`
}

type EventType

type EventType string
const (
	MetaEventType    EventType = "meta"
	MessageEventType EventType = "message"
	NoticeEventType  EventType = "notice"
	RequestEventType EventType = "request"
)

type Message

type Message []MessageSegment

func (Message) String

func (m Message) String() string

String impls the interface Stringer

type MessageEventData

type MessageEventData struct {
	Self       Self             `json:"self,omitempty"`
	MessageId  string           `json:"message_id,omitempty"`
	Message    []MessageSegment `json:"message,omitempty"`
	AltMessage string           `json:"alt_message,omitempty"`
	UserId     string           `json:"user_id,omitempty"`

	TopicId   string `json:"topic_id,omitempty"`
	TopicType string `json:"topic_type,omitempty"`

	Forwarded string `json:"forwarded,omitempty"`

	Seq    float64 `json:"seq,omitempty"`
	Option string  `json:"option,omitempty"`
}

type MessageSegment

type MessageSegment struct {
	Type string         `json:"type"`
	Data map[string]any `json:"data"`
}

func Audio

func Audio(fileId string) MessageSegment

func File

func File(fileId string) MessageSegment

func Image

func Image(fileId string) MessageSegment

func Location

func Location(latitude, longitude float64, title string, content string) MessageSegment

func Mention

func Mention(userId string) MessageSegment

func MentionAll

func MentionAll() MessageSegment

func Reply

func Reply(userId, messageId string) MessageSegment

func Text

func Text(text ...interface{}) MessageSegment

func Url

func Url(url string) MessageSegment

func Video

func Video(fileId string) MessageSegment

func Voice

func Voice(fileId string) MessageSegment

func (MessageSegment) String

func (s MessageSegment) String() string

String impls the interface Stringer

type Request

type Request struct {
	Action string         `json:"action"`
	Params map[string]any `json:"params"`
}

type Response

type Response struct {
	// Execution status (success or failure), must be one of ok and failed,
	// indicating successful and unsuccessful execution, respectively.
	Status ResponseStatus `json:"status"`
	// The return code, which must conform to the return code rules defined later on this page
	RetCode int64 `json:"retcode,omitempty"`
	// Response data
	Data any `json:"data,omitempty"`
	// Error message, it is recommended to fill in a human-readable error message when the action fails to execute,
	// or an empty string when it succeeds.
	Message string `json:"message,omitempty"`
}

func NewFailedResponse

func NewFailedResponse(e *Error) Response

func NewFailedResponseWithError

func NewFailedResponseWithError(e *Error, err error) Response

func NewSuccessResponse

func NewSuccessResponse(data any) Response

type ResponseStatus

type ResponseStatus string
const (
	Success ResponseStatus = "ok"
	Failed  ResponseStatus = "failed"

	SuccessCode = int64(0)
)

type Self

type Self struct {
	Platform string `json:"platform"`
	UserId   string `json:"user_id"`
}

type User

type User struct {
	RawData     types.KV `json:"raw_data"`
	Email       string   `json:"email"`
	Name        string   `json:"name"`
	FirstName   string   `json:"first_name"`
	LastName    string   `json:"last_name"`
	NickName    string   `json:"nick_name"`
	Description string   `json:"description"`
	UserID      string   `json:"user_id"`
	AvatarURL   string   `json:"avatar_url"`
	Location    string   `json:"location"`
	Platform    string   `json:"platform"`
	IsBot       bool     `json:"is_bot"`
}

Jump to

Keyboard shortcuts

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