xmpp

package
v0.0.0-...-0e5a2fc Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapter

func Adapter(conf Config) joe.Module

Adapter initializes an XMPP client connection according to configuration given, and returns a Joe module, usable in calls to joe.New(), or an error if any occurs.

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

func (c *Client) Close() error

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

func (c *Client) RegisterAt(brain *joe.Brain)

RegisterAt sets the Joe Brain instance for the XMPP client.

func (*Client) Send

func (c *Client) Send(msg, channel string) error

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).

type MessageStanza

type MessageStanza struct {
	// Base, common fields.
	stanza.Message
	Body string `xml:"body"`

	// Additional, optional fields.
	Group GroupInfo `xml:"x"`
}

MessageStanza represents an XMPP message stanza, commonly used for transferring chat messages among users or group-chats.

type PresenceStanza

type PresenceStanza struct {
	// Base, common fields.
	stanza.Presence
}

PresenceStanza represents an XMPP presence stanza, commonly used for communicating availability.

Jump to

Keyboard shortcuts

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