Documentation
¶
Index ¶
- Variables
- type AutoSubscribeOptions
- type Client
- func (c *Client) Close(code websocket.StatusCode, reason string) error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) ListSubscribedRoomIDs(ctx context.Context) ([]string, error)
- func (c *Client) OnMessage(handler func(context.Context, Message))
- func (c *Client) SendMessage(ctx context.Context, roomID, text string) error
- func (c *Client) StartAutoSubscribeRooms(ctx context.Context, opts AutoSubscribeOptions)
- func (c *Client) SubscribeRoomMessages(ctx context.Context, roomID string) error
- func (c *Client) ValidateAuth(ctx context.Context) error
- type Config
- type Message
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotConnected is returned when an operation requires an active connection. ErrNotConnected = errors.New("rocketbot: not connected") )
Functions ¶
This section is empty.
Types ¶
type AutoSubscribeOptions ¶ added in v0.2.0
type AutoSubscribeOptions struct {
// Optional static room IDs to subscribe once on startup.
StaticRoomIDs []string
// Poll interval for discovering new room subscriptions.
Interval time.Duration
// Optional callback called for each successfully subscribed room id.
OnSubscribed func(roomID string)
// Optional callback for auto-subscribe/discovery errors.
OnError func(error)
// Optional callback after each discovery pass.
OnDiscovered func(roomCount int)
}
AutoSubscribeOptions controls background room auto-subscription.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a DDP client for building Rocket.Chat bots.
func (*Client) Close ¶
func (c *Client) Close(code websocket.StatusCode, reason string) error
Close closes websocket connection.
func (*Client) Connect ¶
Connect opens websocket, performs DDP connect and bot login (resume token auth).
func (*Client) ListSubscribedRoomIDs ¶ added in v0.2.0
ListSubscribedRoomIDs returns current room ids from /api/v1/subscriptions.get.
func (*Client) SendMessage ¶
SendMessage sends a plain text message to room/channel.
func (*Client) StartAutoSubscribeRooms ¶ added in v0.2.0
func (c *Client) StartAutoSubscribeRooms(ctx context.Context, opts AutoSubscribeOptions)
StartAutoSubscribeRooms starts background room subscription management.
func (*Client) SubscribeRoomMessages ¶
SubscribeRoomMessages subscribes to message stream for a specific room/channel.
type Config ¶
type Config struct {
// ServerURL is your Rocket.Chat base URL, for example: https://chat.example.com
ServerURL string
// UserID is the user id of bot account (X-User-Id / userId).
UserID string
// AuthToken is auth token for bot account (X-Auth-Token / resume token).
AuthToken string
// Optional custom HTTP client used by websocket dialer.
HTTPClient *http.Client
}
Config contains parameters needed to connect to Rocket.Chat over WebSocket (DDP).
Click to show internal directories.
Click to hide internal directories.