Documentation ¶
Index ¶
- func Adapter(conf Config) joe.Module
- type Client
- func (c *Client) Close() error
- func (c *Client) HandleInvite(w xmlstream.TokenWriter, info *GroupInfo) error
- func (c *Client) HandleMessage(w xmlstream.TokenWriter, msg *MessageStanza) error
- func (c *Client) HandlePresence(w xmlstream.TokenWriter, p *PresenceStanza) error
- func (c *Client) HandleXMPP(t xmlstream.TokenReadEncoder, start *xml.StartElement) error
- func (c *Client) RegisterAt(brain *joe.Brain)
- func (c *Client) Send(msg, channel string) error
- type Config
- type GroupInfo
- type MessageStanza
- type PresenceStanza
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an active XMPP session against a server, and configuration for handling messages against a Joe instance.
func (*Client) Close ¶
Close shuts down the active XMPP session and server connection, returning an error if the process fails at any point.
func (*Client) HandleInvite ¶
func (c *Client) HandleInvite(w xmlstream.TokenWriter, info *GroupInfo) error
HandleInvite responds to the given invite (direct or mediated) with an 'available' presence, which allows the client to participate in MUCs.
func (*Client) HandleMessage ¶
func (c *Client) HandleMessage(w xmlstream.TokenWriter, msg *MessageStanza) error
HandleMessage parses the given MessageStanza, validating its contents and responding either as a direct message, or as a group-chat mention, depending on the intent. HandleMessage will also handle invites to group-chats, joining these automatically and with no confirmation needed.
By default, only messages prepended with the local part of the client JID will be responded to in group-chats; this is to avoid handling messages where this is not wanted. Such mentions will be, in turn, responded to with a mention for the sending user.
Currently, only mediated invites (XEP-0045) are handled, and rooms are not re-joined if the client closes its connection to the server.
func (*Client) HandlePresence ¶
func (c *Client) HandlePresence(w xmlstream.TokenWriter, p *PresenceStanza) error
HandlePresence parses the given PresenceStanza and responds (usually to the affirmative), depending on the presence type, e.g. for subscription requests, HandlePresence will automatically subscribe and respond. Any errors returned in parsing on responding will be returned.
func (*Client) HandleXMPP ¶
func (c *Client) HandleXMPP(t xmlstream.TokenReadEncoder, start *xml.StartElement) error
HandleXMPP parses incoming XML tokens and calls a corresponding handler, e.g. HandleMessage, for the stanza type represented. Unhandled stanza types will be ignored with no error returned.
func (*Client) RegisterAt ¶
RegisterAt sets the Joe Brain instance for the XMPP client.
func (*Client) Send ¶
Send wraps the given text in a message stanza and sets the recipient to the given channel, which is expected to be a JID (bare for direct messages). A error is returned if the channel JID does not parse, or if the message fails to send for any reason.
type Config ¶
type Config struct { // Required configuration. JID string Password string // Optional configuration. NoTLS bool // Whether to disable TLS connection to the XMPP server. UseStartTLS bool // Whether or not connection will be allowed to be made over StartTLS. // Other fields. Logger *zap.Logger // The instance to use for emitting log messages. }
Config represents required and optional configuration values used in setting up the XMPP bot client.
type GroupInfo ¶
type GroupInfo struct { Channel jid.JID `xml:"-"` Password string `xml:"password` Invite struct { From jid.JID `xml:"from,attr"` } `xml:"invite"` }
GroupInfo represents information needed for joining a MUC, either automatically or as part of an invite (direct or mediated).