personal

package
v1.0.54 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventMention       = "user_im_message_receive_at"
	EventSingleChat    = "user_im_message_receive_o2o"
	EventInChat        = "user_im_message_receive_group"
	EventFromUser      = "user_im_message_receive_user"
	EventReadO2O       = "user_im_message_read_o2o"
	EventReadGroup     = "user_im_message_read_group"
	EventRecallO2O     = "user_im_message_recall_o2o"
	EventRecallGroup   = "user_im_message_recall_group"
	EventReactionO2O   = "user_im_message_reaction_o2o"
	EventReactionGroup = "user_im_message_reaction_group"
)
View Source
const (
	StatusEnabled = "enabled"
	StatusPending = "pending"
)
View Source
const (
	StateFileName     = "personal_subscriptions.json"
	StateLockFileName = "personal_subscriptions.lock"
)
View Source
const DefaultBasePath = "/dws"

Variables

This section is empty.

Functions

func BuildFilter

func BuildFilter(filterJSON string, queryCSV string) (any, string, error)

func BuildRuleParam

func BuildRuleParam(eventKey string, opts RuleOptions) (ruleType string, ruleParam map[string]any, err error)

func CanonicalJSON

func CanonicalJSON(v any) (string, error)

func IdempotencyKey

func IdempotencyKey(identity Identity, eventKey, ruleType string, ruleParam map[string]any, filterCanonical string) string

func IsPublic

func IsPublic(eventKey string) bool

func IsSchemaPending

func IsSchemaPending(err error) bool

func ProjectOutput added in v1.0.54

func ProjectOutput(ev transport.Event) (any, error)

ProjectOutput converts the transport envelope into the stable personal event output. On malformed Data it returns the original envelope together with an error; the formatter logs the warning and still emits that envelope.

func PublicAvailabilityError

func PublicAvailabilityError(eventKey string) error

func RemoveRunStates

func RemoveRunStates(workDir string, subscribeIDs []string) error

func UpsertRunState

func UpsertRunState(workDir string, st RunState) error

Types

type APIError

type APIError struct {
	Code      string         `json:"code"`
	Message   string         `json:"message"`
	Retryable bool           `json:"retryable,omitempty"`
	Details   map[string]any `json:"details,omitempty"`
}

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	BaseURL             string
	HTTPClient          *http.Client
	Identity            Identity
	AccessTokenProvider func(context.Context) (string, error)
}

func NewClient

func NewClient(baseURL string, identity Identity) *Client

func (*Client) CreateSubscription

func (c *Client) CreateSubscription(ctx context.Context, req CreateSubscriptionRequest) (*Subscription, error)

func (*Client) DeleteSubscription

func (c *Client) DeleteSubscription(ctx context.Context, subscribeID string) error

func (*Client) GetSubscription

func (c *Client) GetSubscription(ctx context.Context, subscribeID string) (*Subscription, error)

func (*Client) ListSubscriptions

func (c *Client) ListSubscriptions(ctx context.Context, opts ListOptions) ([]Subscription, error)

type CreateSubscriptionRequest

type CreateSubscriptionRequest struct {
	EventKey       string         `json:"event_key"`
	RuleType       string         `json:"rule_type"`
	Name           string         `json:"name,omitempty"`
	RuleParam      map[string]any `json:"rule_param"`
	Filter         any            `json:"filter,omitempty"`
	Delivery       map[string]any `json:"delivery"`
	TTLSeconds     int64          `json:"ttl_seconds,omitempty"`
	IdempotencyKey string         `json:"idempotency_key,omitempty"`
}

type Definition

type Definition struct {
	EventKey       string                `json:"event_key"`
	DisplayName    string                `json:"display_name"`
	Description    string                `json:"description"`
	Category       string                `json:"category"`
	RuleType       string                `json:"rule_type"`
	Status         string                `json:"status"`
	RequiredParams []string              `json:"required_params"`
	Constraints    *ParameterConstraints `json:"constraints,omitempty"`
	Auth           map[string]any        `json:"auth,omitempty"`
	Public         bool                  `json:"-"`
}

func Catalog

func Catalog(category string, enabledOnly, includePending bool) []Definition

func Definitions

func Definitions() []Definition

func Lookup

func Lookup(eventKey string) (Definition, bool)

type Identity

type Identity struct {
	AccessToken  string `json:"-"`
	LocalSubject string `json:"-"`
	CorpID       string `json:"corp_id"`
	UserID       string `json:"user_id"`
	ClientID     string `json:"client_id"`
	SourceID     string `json:"source_id"`
}

func (Identity) Key

func (i Identity) Key() string

type ListOptions

type ListOptions struct {
	Status      string
	EventKey    string
	SubscribeID string
}

type MessageEventOutput added in v1.0.54

type MessageEventOutput struct {
	Type                 string `json:"type" description:"事件类型,固定为当前 event_key"`
	EventID              string `json:"event_id" description:"事件 ID,可用于去重"`
	Timestamp            int64  `json:"timestamp" description:"事件发生时间戳" format:"timestamp_ms"`
	SubscribeID          string `json:"subscribe_id" description:"订阅 ID"`
	MessageID            string `json:"message_id" description:"开放消息 ID" format:"open_message_id"`
	ConversationID       string `json:"conversation_id" description:"会话 ID" format:"open_conversation_id"`
	Sender               string `json:"sender" description:"发送人展示名"`
	SenderOpenDingTalkID string `json:"sender_open_dingtalk_id" description:"发送人开放 ID" format:"open_dingtalk_id"`
	Content              string `json:"content" description:"消息正文"`
	CreateTime           string `json:"create_time" description:"消息创建时间"`
	EventTime            int64  `json:"event_time" description:"消息事件时间戳" format:"timestamp_ms"`
}

MessageEventOutput is the stable business-facing output for personal message receive events. Schema output is generated from these tags so the documented fields cannot drift from the values written by consume.

type ParameterConstraints added in v1.0.54

type ParameterConstraints struct {
	RequireOneOf      [][]string `json:"require_one_of,omitempty"`
	MutuallyExclusive [][]string `json:"mutually_exclusive,omitempty"`
}

type ReactionEventOutput added in v1.0.54

type ReactionEventOutput struct {
	Type                   string `json:"type" description:"事件类型,固定为当前 event_key"`
	EventID                string `json:"event_id" description:"事件 ID,可用于去重"`
	Timestamp              int64  `json:"timestamp" description:"事件发生时间戳" format:"timestamp_ms"`
	SubscribeID            string `json:"subscribe_id" description:"订阅 ID"`
	MessageID              string `json:"message_id" description:"收到表情回应的开放消息 ID" format:"open_message_id"`
	ConversationID         string `json:"conversation_id" description:"会话 ID" format:"open_conversation_id"`
	Operator               string `json:"operator" description:"执行表情回应操作的用户展示名"`
	OperatorOpenDingTalkID string `json:"operator_open_dingtalk_id" description:"执行表情回应操作的用户开放 ID" format:"open_dingtalk_id"`
	ReactionName           string `json:"reaction_name" description:"表情回应名称"`
	ReactionText           string `json:"reaction_text" description:"表情回应文本"`
	OperationType          string `json:"operation_type" description:"表情回应操作类型"`
	OperationTime          string `json:"operation_time" description:"表情回应操作时间"`
	Sender                 string `json:"sender" description:"原消息发送人展示名"`
	SenderOpenDingTalkID   string `json:"sender_open_dingtalk_id" description:"原消息发送人开放 ID" format:"open_dingtalk_id"`
	EventTime              int64  `json:"event_time" description:"消息事件时间戳" format:"timestamp_ms"`
}

type ReadEventOutput added in v1.0.54

type ReadEventOutput struct {
	Type                 string `json:"type" description:"事件类型,固定为当前 event_key"`
	EventID              string `json:"event_id" description:"事件 ID,可用于去重"`
	Timestamp            int64  `json:"timestamp" description:"事件发生时间戳" format:"timestamp_ms"`
	SubscribeID          string `json:"subscribe_id" description:"订阅 ID"`
	MessageID            string `json:"message_id" description:"被读取消息的开放消息 ID" format:"open_message_id"`
	ConversationID       string `json:"conversation_id" description:"会话 ID" format:"open_conversation_id"`
	Reader               string `json:"reader" description:"读取消息的用户展示名"`
	ReaderOpenDingTalkID string `json:"reader_open_dingtalk_id" description:"读取消息的用户开放 ID" format:"open_dingtalk_id"`
	Sender               string `json:"sender" description:"原消息发送人展示名"`
	SenderOpenDingTalkID string `json:"sender_open_dingtalk_id" description:"原消息发送人开放 ID" format:"open_dingtalk_id"`
	ReadTime             string `json:"read_time" description:"消息读取时间"`
	EventTime            int64  `json:"event_time" description:"消息事件时间戳" format:"timestamp_ms"`
}

type RecallEventOutput added in v1.0.54

type RecallEventOutput struct {
	Type                   string `json:"type" description:"事件类型,固定为当前 event_key"`
	EventID                string `json:"event_id" description:"事件 ID,可用于去重"`
	Timestamp              int64  `json:"timestamp" description:"事件发生时间戳" format:"timestamp_ms"`
	SubscribeID            string `json:"subscribe_id" description:"订阅 ID"`
	MessageID              string `json:"message_id" description:"被撤回消息的开放消息 ID" format:"open_message_id"`
	ConversationID         string `json:"conversation_id" description:"会话 ID" format:"open_conversation_id"`
	Recaller               string `json:"recaller" description:"撤回消息的用户展示名"`
	RecallerOpenDingTalkID string `json:"recaller_open_dingtalk_id" description:"撤回消息的用户开放 ID" format:"open_dingtalk_id"`
	Sender                 string `json:"sender" description:"原消息发送人展示名"`
	SenderOpenDingTalkID   string `json:"sender_open_dingtalk_id" description:"原消息发送人开放 ID" format:"open_dingtalk_id"`
	RecallTime             string `json:"recall_time" description:"消息撤回时间"`
	EventTime              int64  `json:"event_time" description:"消息事件时间戳" format:"timestamp_ms"`
}

type RuleOptions

type RuleOptions struct {
	RuleType       string
	UserID         string
	OpenDingTalkID string
	GroupID        string
}

type RunState

type RunState struct {
	SubscribeID  string    `json:"subscribe_id"`
	EventKey     string    `json:"event_key,omitempty"`
	RuleType     string    `json:"rule_type,omitempty"`
	ClientID     string    `json:"client_id,omitempty"`
	SourceID     string    `json:"source_id,omitempty"`
	IdentityHash string    `json:"identity_hash,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
}

func LoadRunStates

func LoadRunStates(workDir string) ([]RunState, error)

type SchemaDocument

type SchemaDocument struct {
	EventKey       string                `json:"event_key"`
	DisplayName    string                `json:"display_name"`
	Description    string                `json:"description"`
	Category       string                `json:"category"`
	RuleType       string                `json:"rule_type"`
	RequiredParams []string              `json:"required_params"`
	Constraints    *ParameterConstraints `json:"constraints,omitempty"`
	JQRootPath     string                `json:"jq_root_path"`
	Schema         map[string]any        `json:"schema"`
}

func BuildSchemaDocument

func BuildSchemaDocument(def Definition) SchemaDocument

func BuildSchemaDocumentForMode added in v1.0.54

func BuildSchemaDocumentForMode(def Definition, flatten bool) SchemaDocument

type SchemaPendingError

type SchemaPendingError struct {
	EventKey string
}

func (*SchemaPendingError) Error

func (e *SchemaPendingError) Error() string

type Subscription

type Subscription struct {
	SubscribeID string     `json:"subscribe_id"`
	EventKey    string     `json:"event_key,omitempty"`
	RuleType    string     `json:"rule_type,omitempty"`
	Status      string     `json:"status,omitempty"`
	SourceID    string     `json:"source_id,omitempty"`
	CreatedAt   string     `json:"created_at,omitempty"`
	ExpiresAt   *time.Time `json:"expires_at,omitempty"`
}

Jump to

Keyboard shortcuts

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