Documentation
¶
Index ¶
- Constants
- Variables
- type Actor
- type Agent
- func (a *Agent) Messenger() *messenger.Messenger
- func (a *Agent) On(service, typ, action string, fn HandlerFunc)
- func (a *Agent) OnMessenger(fn HandlerFunc)
- func (a *Agent) OnTask(fn HandlerFunc)
- func (a *Agent) OnWiki(fn HandlerFunc)
- func (a *Agent) Run() error
- func (a *Agent) RunContext(ctx context.Context) error
- type DataWrapper
- type Entity
- type HandlerFunc
- type Option
- type SocketModeRequest
- func (r *SocketModeRequest) ChannelID() string
- func (r *SocketModeRequest) IsAction(a string) bool
- func (r *SocketModeRequest) IsBotMessage() bool
- func (r *SocketModeRequest) IsMessage() bool
- func (r *SocketModeRequest) IsService(s string) bool
- func (r *SocketModeRequest) IsType(t string) bool
- func (r *SocketModeRequest) Reply(text string) error
- func (r *SocketModeRequest) SenderID() string
- func (r *SocketModeRequest) Text() string
Constants ¶
const ( ServiceMessenger = "messenger" ServiceTask = "task" ServiceWiki = "wiki" )
Variables ¶
var ( ErrNoChannel = errors.New("socketmode: no channel ID available for reply") ErrNoWebClient = errors.New("socketmode: web client not initialized") ErrNoToken = errors.New("socketmode: agent token is required") ErrNoDomain = errors.New("socketmode: domain is required (e.g. WithDomain(\"company.dooray.com\"))") )
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent manages a WebSocket connection to Dooray and dispatches events to handlers.
func NewAgent ¶
NewAgent creates a new socket mode Agent. The agentToken is the DOORAY_AGENT_TOKEN used for authentication.
func (*Agent) Messenger ¶
Messenger returns the underlying Messenger client for making REST API calls.
func (*Agent) On ¶
func (a *Agent) On(service, typ, action string, fn HandlerFunc)
On registers a handler with optional filtering by service, type, and action. Empty strings match all values for that field.
func (*Agent) OnMessenger ¶
func (a *Agent) OnMessenger(fn HandlerFunc)
OnMessenger registers a handler for all messenger service events.
func (*Agent) OnTask ¶
func (a *Agent) OnTask(fn HandlerFunc)
OnTask registers a handler for all task service events.
func (*Agent) OnWiki ¶
func (a *Agent) OnWiki(fn HandlerFunc)
OnWiki registers a handler for all wiki service events.
type DataWrapper ¶
DataWrapper wraps additional action detail data.
type HandlerFunc ¶
type HandlerFunc func(req *SocketModeRequest)
HandlerFunc is the function signature for event handlers.
type Option ¶
type Option func(*Agent)
Option configures the Agent.
func WithDomain ¶
WithDomain sets the Dooray domain (e.g. "company").
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client for REST API calls.
func WithPingInterval ¶
WithPingInterval sets the WebSocket ping interval.
func WithReconnectBackoff ¶
WithReconnectBackoff sets the min and max reconnect backoff durations.
type SocketModeRequest ¶
type SocketModeRequest struct {
EnvelopeID string `json:"envelope_id"`
Type string `json:"type"`
Service string `json:"service"`
Action string `json:"action"`
Payload map[string]interface{} `json:"payload"`
Entity *Entity `json:"entity"`
Actor *Actor `json:"actor"`
ActionData *DataWrapper `json:"actionData"`
// contains filtered or unexported fields
}
SocketModeRequest represents an incoming event from the Dooray WebSocket connection.
func (*SocketModeRequest) ChannelID ¶
func (r *SocketModeRequest) ChannelID() string
ChannelID extracts the channel ID from the entity data.
func (*SocketModeRequest) IsAction ¶
func (r *SocketModeRequest) IsAction(a string) bool
IsAction checks if the event action matches.
func (*SocketModeRequest) IsBotMessage ¶
func (r *SocketModeRequest) IsBotMessage() bool
IsBotMessage returns true if the message was sent by this bot itself. It compares the sender ID with the bot's own organizationMemberId obtained during socket mode token exchange. Use this to avoid infinite loops when the bot replies to its own messages.
func (*SocketModeRequest) IsMessage ¶
func (r *SocketModeRequest) IsMessage() bool
IsMessage returns true if the event is a messenger message.
func (*SocketModeRequest) IsService ¶
func (r *SocketModeRequest) IsService(s string) bool
IsService checks if the event service matches.
func (*SocketModeRequest) IsType ¶
func (r *SocketModeRequest) IsType(t string) bool
IsType checks if the event type matches.
func (*SocketModeRequest) Reply ¶
func (r *SocketModeRequest) Reply(text string) error
Reply sends a text message back to the channel where the event originated. Only works for messenger events with a channel ID.
func (*SocketModeRequest) SenderID ¶
func (r *SocketModeRequest) SenderID() string
SenderID extracts the sender member ID from the entity data.
func (*SocketModeRequest) Text ¶
func (r *SocketModeRequest) Text() string
Text extracts the message text from the entity data.