Documentation
¶
Overview ¶
Package bridgeclient provides a Go SDK for connecting external platform adapters to HotPlex via the BridgeServer WebSocket gateway.
Usage:
client := bridgeclient.New(
bridgeclient.URL("wss://hotplex.internal:8080/bridge"),
bridgeclient.Platform("dingtalk"),
bridgeclient.Capabilities(bridgeclient.CapText, bridgeclient.CapCard),
bridgeclient.AuthToken(os.Getenv("HOTPLEX_BRIDGE_TOKEN")),
)
client.OnMessage(func(msg *bridgeclient.Message) *bridgeclient.Reply {
// Process msg.Content, msg.SessionKey, msg.Metadata
return &bridgeclient.Reply{
Content: "Hello from DingTalk!",
SessionKey: msg.SessionKey,
}
})
ctx := context.Background()
if err := client.Connect(ctx); err != nil {
log.Fatal(err)
}
defer client.Close()
// Block until disconnected
<-ctx.Done()
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) OnEvent(h EventHandler)
- func (c *Client) OnMessage(h MessageHandler)
- func (c *Client) SendMessage(ctx context.Context, msg *Message) error
- func (c *Client) Typing(ctx context.Context, sessionKey string) error
- type Error
- type Event
- type EventHandler
- type Message
- type MessageHandler
- type Metadata
- type Option
- func AuthToken(v string) Option
- func Capabilities(caps ...string) Option
- func HTTPClient(hc *http.Client) Option
- func Logger(l *slog.Logger) Option
- func Platform(v string) Option
- func ProxyURL(raw string) Option
- func TLSConfig(cfg *tls.Config) Option
- func Timeout(d time.Duration) Option
- func URL(v string) Option
- type Reply
Constants ¶
const ( CapText = bridgewire.CapText CapImage = bridgewire.CapImage CapCard = bridgewire.CapCard CapButtons = bridgewire.CapButtons CapTyping = bridgewire.CapTyping CapEdit = bridgewire.CapEdit CapDelete = bridgewire.CapDelete CapReact = bridgewire.CapReact CapThread = bridgewire.CapThread )
Cap* aliases for the public API (mirrors bridgewire constants).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a BridgeClient that connects to HotPlex BridgeServer as a WebSocket client.
func (*Client) Connect ¶
Connect establishes a WebSocket connection to BridgeServer, performs the register handshake, and starts background goroutines to handle incoming messages and events. It blocks until the context is cancelled or a fatal error occurs.
func (*Client) OnEvent ¶
func (c *Client) OnEvent(h EventHandler)
OnEvent registers a handler for inbound events from HotPlex. Only one handler can be registered; subsequent calls replace the previous one.
func (*Client) OnMessage ¶
func (c *Client) OnMessage(h MessageHandler)
OnMessage registers a handler for inbound messages from HotPlex. Only one handler can be registered; subsequent calls replace the previous one.
func (*Client) SendMessage ¶
SendMessage sends a message from the external platform to HotPlex. This is used for inbound messages (e.g., a user sends a DM on DingTalk).
type Event ¶
type Event struct {
Event string
Data json.RawMessage
// contains filtered or unexported fields
}
Event represents an inbound event from HotPlex (server → client). Common events: "stream_start", "stream_chunk", "stream_end", "typing_start", "typing_end".
type EventHandler ¶
type EventHandler func(evt *Event)
EventHandler processes inbound events from HotPlex.
type Message ¶
type Message struct {
SessionKey string
Content string
Metadata Metadata
// contains filtered or unexported fields
}
Message represents an inbound message from HotPlex (server → client).
type MessageHandler ¶
MessageHandler processes inbound messages from HotPlex and optionally returns a reply.
type Option ¶
Option configures a BridgeClient.
func AuthToken ¶
AuthToken sets the token used to authenticate with BridgeServer. This must match the bridge_token configured in HotPlex.
func Capabilities ¶
Capabilities sets the capabilities this adapter supports. If not set, defaults to CapText.
func HTTPClient ¶
HTTPClient sets a custom HTTP client for WebSocket dialing. This overrides URL, Timeout, and TLSConfig options.
func Platform ¶
Platform sets the platform name this adapter represents. This is used as the platform identifier in the Bridge Wire Protocol. Example: "dingtalk", "wechat", "lark"