event

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleEncryptedEvent added in v1.2.6

func HandleEncryptedEvent(ctx context.Context, req *EncryptedRequest, secretKey string) (err error)

func HandleEncryptedEventWithChallenge added in v1.2.6

func HandleEncryptedEventWithChallenge(ctx context.Context, req *EncryptedRequest, secretKey, verificationToken string, callback func(challenge ChallengeResponse) (err error)) (err error)

func HandleEvent

func HandleEvent(ctx context.Context, req *CallbackRequest) (err error)

func NewTypeNotMatchError

func NewTypeNotMatchError(expectedType string, actualType string) error

func SetEventHandler

func SetEventHandler(handler Handler)

Types

type BaseEventHandler

type BaseEventHandler[realEvent any] struct {
	// contains filtered or unexported fields
}

func InitializeBaseEventHandler

func InitializeBaseEventHandler[realEvent any](fn func(ctx context.Context, event *FullCallbackRequest[realEvent]) (err error), eventType Enum) BaseEventHandler[realEvent]

func (BaseEventHandler[realEvent]) HandleEvent

func (b BaseEventHandler[realEvent]) HandleEvent(ctx context.Context, event *CallbackRequest) (err error)

func (BaseEventHandler[realEvent]) TriggerEventType

func (b BaseEventHandler[realEvent]) TriggerEventType() string

type CallbackRequest

type CallbackRequest struct {
	Schema string                `json:"schema,omitempty"` // 版本,只有2.0的版本有这个字段
	Header CallbackRequestHeader `json:"header"`           // 请求头
	Event  any                   `json:"event,omitempty"`  // 事件内容
}

func ParseEncryptedRequest added in v1.2.6

func ParseEncryptedRequest(requestBody []byte, secretKey string) (challengeBody CallbackRequest, err error)

ParseEncryptedRequest 解析飞书的回调请求,并进行解密 reference: https://open.feishu.cn/document/server-docs/event-subscription-guide/event-subscription-configure-/encrypt-key-encryption-configuration-case

func ParseEncryptedRequestString added in v1.2.6

func ParseEncryptedRequestString(encrypted string, secretKey string) (challengeBody CallbackRequest, err error)

ParseEncryptedRequestString 解析飞书的回调请求的encrypted字段,并进行解密 reference: https://open.feishu.cn/document/server-docs/event-subscription-guide/event-subscription-configure-/encrypt-key-encryption-configuration-case

type CallbackRequestHeader

type CallbackRequestHeader struct {
	EventID    string `json:"event_id"`    // 事件ID
	Token      string `json:"token"`       // 验证token
	CreateTime string `json:"create_time"` // 事件创建时间,毫秒级时间戳
	EventType  string `json:"event_type"`  // 事件类型
	TenantKey  string `json:"tenant_key"`  // 企业ID
	AppID      string `json:"app_id"`      // 应用ID
}

type ChallengeEmptyError added in v1.2.6

type ChallengeEmptyError struct{}

func NewChallengeEmptyError added in v1.2.6

func NewChallengeEmptyError() ChallengeEmptyError

func (ChallengeEmptyError) Error added in v1.2.6

func (c ChallengeEmptyError) Error() string

type ChallengeRequest

type ChallengeRequest struct {
	Challenge string `json:"challenge"`
	Token     string `json:"token"`
	Type      string `json:"type"`
}

type ChallengeResponse

type ChallengeResponse struct {
	Challenge string `json:"challenge"`
}

func ParseChallenge

func ParseChallenge(requestBody []byte, verificationToken string) (challengeBody ChallengeResponse, err error)

ParseChallenge 解析飞书的 challenge 请求,无需解密 reference: https://open.feishu.cn/document/server-docs/event-subscription-guide/event-subscription-configure-/request-url-configuration-case

func ParseChallengeWithEncryption

func ParseChallengeWithEncryption(requestBody []byte, verificationToken, secretKey string) (challengeBody ChallengeResponse, err error)

ParseChallengeWithEncryption 解析飞书的 challenge 请求,并进行解密 reference: https://open.feishu.cn/document/server-docs/event-subscription-guide/event-subscription-configure-/encrypt-key-encryption-configuration-case

type EncryptedRequest added in v1.2.6

type EncryptedRequest struct {
	Encrypt string `json:"encrypt"`
}

type Enum

type Enum string
const (
	EnumReceiveMessage Enum = "im.message.receive_v1"
	EnumBotEvent       Enum = "application.bot.menu_v6"
	EnumMemberAdd      Enum = "im.chat.member.user.added_v1"
	EnumMemberDelete   Enum = "im.chat.member.user.deleted_v1"
)

func (Enum) TriggerEventType

func (e Enum) TriggerEventType() string

type FullCallbackRequest

type FullCallbackRequest[eventData any] struct {
	Schema string                `json:"schema,omitempty"` // 版本,只有2.0的版本有这个字段
	Header CallbackRequestHeader `json:"header"`           // 请求头
	Event  eventData             `json:"event,omitempty"`  // 事件内容
}

func GetCallbackRequestEventData

func GetCallbackRequestEventData[data any](request *CallbackRequest, event Handler) (fullData FullCallbackRequest[data], err error)

type Handler

type Handler interface {
	TriggerEventType() string
	HandleEvent(ctx context.Context, event *CallbackRequest) (err error)
}

type HandlerNotFoundError added in v1.2.6

type HandlerNotFoundError struct {
	Event string `json:"event"`
}

func NewHandlerNotFoundError added in v1.2.6

func NewHandlerNotFoundError(event string) HandlerNotFoundError

func (HandlerNotFoundError) Error added in v1.2.6

func (h HandlerNotFoundError) Error() string

type HandlerTypeNotMatchError added in v1.2.6

type HandlerTypeNotMatchError struct {
	Event       string `json:"event"`
	HandlerType string `json:"handler_type"`
}

func NewHandlerTypeNotMatchError added in v1.2.6

func NewHandlerTypeNotMatchError(event, handlerType string) HandlerTypeNotMatchError

func (HandlerTypeNotMatchError) Error added in v1.2.6

func (h HandlerTypeNotMatchError) Error() string

type HandlerUnimplementedError added in v1.2.6

type HandlerUnimplementedError struct {
	Event string `json:"event"`
}

func NewHandlerUnimplementedError added in v1.2.6

func NewHandlerUnimplementedError(event string) HandlerUnimplementedError

func (HandlerUnimplementedError) Error added in v1.2.6

type SecretKeyUnsetError added in v1.2.6

type SecretKeyUnsetError struct{}

func NewSecretKeyUnsetError added in v1.2.6

func NewSecretKeyUnsetError() SecretKeyUnsetError

func (SecretKeyUnsetError) Error added in v1.2.6

func (s SecretKeyUnsetError) Error() string

type TypeNotMatchError

type TypeNotMatchError struct {
	ExpectedType string
	ActualType   string
}

func (TypeNotMatchError) Error

func (e TypeNotMatchError) Error() string

type VerificationTokenUnsetError added in v1.2.6

type VerificationTokenUnsetError struct{}

func NewVerificationTokenUnsetError added in v1.2.6

func NewVerificationTokenUnsetError() VerificationTokenUnsetError

func (VerificationTokenUnsetError) Error added in v1.2.6

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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