Documentation
¶
Index ¶
- Constants
- Variables
- func NewEventJobStatusQueue(rdb jq.RedisClient) *jq.Queue
- func NewEventMessageQueue(rdb jq.RedisClient) *jq.Queue
- type Agent
- type AgentBasic
- type Channel
- type ChannelType
- type DelayedJob
- type DelayedJobInput
- type Job
- type JobBasic
- type JobInput
- type JobRaw
- type JobResult
- type Message
- type MessageInput
- type UserSetting
Constants ¶
const ( EventMessage = "message" EventJobStatus = "job:status" )
Event will publish to redis queue
const ( JobStatusQueuing = "queuing" JobStatusCanceled = "canceled" JobStatusSent = "sent" JobStatusRunning = "running" JobStatusExpired = "expired" JobStatusSucceeded = "succeeded" JobStatusFailed = "failed" )
const ( MessageTypeText = "text" // MessageTypeInfo Warning had been moved to MessageLevel MessageTypeInfo = "info" MessageTypeWarning = "warning" // MessageTypeAuto have been deprecated MessageTypeAuto = "auto" )
const ( MessageLevelInfo = "info" MessageLevelWarning = "warning" MessageLevelError = "error" )
Variables ¶
var RESERVED = xtype.Strings{"agent", "delay", "status", "help", "delay", "group", "plan", "poster",
"link", "unlink", "follow", "unfollow", "sub", "unsub"}
Functions ¶
func NewEventJobStatusQueue ¶ added in v0.9.0
func NewEventJobStatusQueue(rdb jq.RedisClient) *jq.Queue
NewEventJobStatusQueue is stateless in local, you can create it anywhere.
func NewEventMessageQueue ¶ added in v0.9.0
func NewEventMessageQueue(rdb jq.RedisClient) *jq.Queue
NewEventMessageQueue is stateless in local, you can create it anywhere.
Types ¶
type Agent ¶
type Agent struct {
ID string `json:"id" gorm:"type:varchar(20);primaryKey"`
Secret string `json:"-" gorm:"type:varchar(20);index"`
UserID string `json:"user_id" gorm:"type:varchar(20);index:idx_uid;uniqueIndex:idx_un1;index:idx_un2"`
Available bool `json:"available" gorm:"default:true"`
Name string `json:"name" gorm:"type:varchar(50);uniqueIndex:idx_un1"`
Alias string `json:"alias" gorm:"type:varchar(50);index:idx_un2"`
Remark string `json:"remark"`
// IP address last connected from
IP string `json:"ip" gorm:"type:varchar(50)"`
// Only update after offline, means last activated at that time.
ActivatedAt *time.Time `json:"activated_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Agent belongs to user, have id and secret, saved in db.
type AgentBasic ¶
type AgentBasic struct {
Name string `json:"name"`
Alias string `json:"alias"`
Remark string `json:"remark"`
}
AgentBasic used for agent creation ui
type Channel ¶ added in v1.2.4
type Channel struct {
ID string `json:"id" gorm:"type:varchar(20);primaryKey"`
UserID string `json:"user_id" gorm:"type:varchar(20);index:idx_uid"`
// Name can't contain space.
Name string `json:"name" gorm:"type:varchar(50)"`
Remark string `json:"remark"`
Type ChannelType `json:"type" gorm:"type:varchar(10)"`
Address string `json:"address" gorm:"type:varchar(50)"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Channel is the way of sending message to users.
type ChannelType ¶ added in v1.2.4
type ChannelType string
ChannelType is provider+way, some provider have more than one way to send message
const ( ChannelTypeWechat ChannelType = "mp" ChannelTypeTelegram ChannelType = "tg" ChannelTypeFeishu ChannelType = "feishu" )
All channel types
type DelayedJob ¶ added in v1.2.0
type DelayedJob struct {
ID string `json:"id" gorm:"type:varchar(20);primaryKey"`
JobInput
ActiveAt time.Time `json:"active_at"`
CreatedAt time.Time `json:"created_at"`
}
DelayedJob will be stored in db for future run.
type DelayedJobInput ¶ added in v1.2.0
type DelayedJobInput struct {
Message string `validate:"required,lte=255" json:"message"`
Duration string `json:"duration,omitempty"`
Minutes int `json:"minutes,omitempty"`
Hours int `json:"hours,omitempty"`
Days int `json:"days,omitempty"`
// an url, will be called after job status changed,
// left empty will notify in your default IM,
// set to "disable" will disable any notify or callback
Callback string `validate:"omitempty,lte=255" json:"callback,omitempty"`
}
DelayedJobInput just for api input
type Job ¶
type Job struct {
ID string `json:"id" gorm:"type:varchar(20);primaryKey"`
JobInput
// queuing/canceled/sent/expired/succeeded/failed
Status string `json:"status" gorm:"type:varchar(10)"`
// agent returned, job log or other message
Result string `json:"result" gorm:"type:varchar(1024)"`
CreatedAt time.Time `json:"created_at" gorm:"index:by_user;index:by_agent"`
SentAt *time.Time `json:"sent_at,omitempty"`
CanceledAt *time.Time `json:"canceled_at,omitempty"`
ExpiredAt *time.Time `json:"expired_at,omitempty"`
SucceededAt *time.Time `json:"succeeded_at,omitempty"`
FailedAt *time.Time `json:"failed_at,omitempty"`
}
Job will be saved in db, it's a gorm mysql model
type JobInput ¶
type JobInput struct {
UserID string `json:"user_id" gorm:"type:varchar(20);index:by_user"`
AgentID string `json:"agent_id" gorm:"type:varchar(20);index:by_agent"`
// job payload
Message string `json:"message" gorm:"type:varchar(255)" validate:"required,lte=255"`
// source context, any string defined by source
Source string `json:"source" gorm:"type:varchar(255)" validate:"omitempty,lte=255"`
// callback url, if exists, will be called after sent/expired/succeeded/failed
// left empty will notify in your default IM,
// set to "disable" will disable any notify or callback
Callback string `json:"callback" gorm:"type:varchar(255)" validate:"omitempty,lte=255"`
}
JobInput is input fields which upstream service passed
type JobRaw ¶ added in v1.2.4
type JobRaw struct {
Message string `json:"message"`
}
JobRaw is raw input of job, format: AgentName JobMessage
type JobResult ¶
type JobResult struct {
// agent returned, job log or other message
Result string `json:"result,omitempty"`
}
JobResult is reported by agent The length of result is not limited, if it is longer than 1024, will be cut.
type Message ¶ added in v0.9.0
type Message struct {
ID string `json:"id"`
// AgentID is optional, exists when message is sent from an agent.
AgentID string `json:"agent_id"`
UserID string `json:"user_id"`
MessageInput
CreatedAt time.Time `json:"created_at"`
}
Message will send to IM, gen by agent api, or system event. Not stored in the database.
type MessageInput ¶ added in v0.9.0
type MessageInput struct {
// Channel is optional channel name, if empty, send to default level channel
Channel string `json:"channel"`
Type string `json:"type"`
Level string `json:"level"`
// Message is required
Message string `json:"message"`
}
MessageInput from api TODO: check it
type UserSetting ¶ added in v1.2.4
type UserSetting struct {
UserID string `json:"user_id" gorm:"type:varchar(20);primaryKey"`
// The default channels
DefaultInfoChannel string `json:"default_info_channel" gorm:"type:varchar(20)"`
DefaultWarningChannel string `json:"default_warning_channel" gorm:"type:varchar(20)"`
DefaultErrorChannel string `json:"default_error_channel" gorm:"type:varchar(20)"`
}
UserSetting stores user's setting. This package does not manage user profile. The user can be a person, or a team, in your app.