XMPP 软件包提供向 XMPP 兼容服务用户发送和接收即时消息的方法。
如需发送消息,请使用以下代码:
m := &xmpp.Message{ To: []string{"kaylee@example.com"}, Body: `Hi! How's the carrot?`, } err := m.Send(c)
如需接收消息,请使用以下代码:
func init() { xmpp.Handle(handleChat) } func handleChat(c context.Context, m *xmpp.Message) { // ... }
变量
ErrPresenceUnavailable、ErrInvalidJID
var (
ErrPresenceUnavailable = errors.New("xmpp: presence unavailable")
ErrInvalidJID = errors.New("xmpp: invalid JID")
)
函数
func GetPresence
GetPresence 会检索用户的在线状态。 如果发件人地址是空字符串,则将使用默认地址 (yourapp@appspot.com/bot)。可能的返回值为“”“away”“dnd”“chat”“xa”。 如果在线状态不可用,则返回 ErrPresenceUnavailable。
func GetPresenceMulti
GetPresenceMulti 会检索多个用户的在线状态。 如果发件人地址是空字符串,则将使用默认地址 (yourapp@appspot.com/bot)。可能的返回值为“”“away”“dnd”“chat”“xa”。 如果在线状态不可用,则返回 appengine.MultiError。
func Handle
处理传入 XMPP 消息的 f 安排。 仅处理“chat”或“normal”类型的消息。
func Invite
Invite 会发送邀请。如果发件人地址是空字符串,则将使用默认地址 (yourapp@appspot.com/bot)。
消息
type Message struct {
// Sender is the JID of the sender.
// Optional for outgoing messages.
Sender string
// To is the intended recipients of the message.
// Incoming messages will have exactly one element.
To []string
// Body is the body of the message.
Body string
// Type is the message type, per RFC 3921.
// It defaults to "chat".
Type string
// RawXML is whether the body contains raw XML.
RawXML bool
}
Message 表示传入的聊天消息。
func (*Message) Send
Send 会发送消息。如果特定收件人发生任何故障,则错误将为 appengine.MultiError。
状态
type Presence struct {
// Sender is the JID (optional).
Sender string
// The intended recipient of the presence update.
To string
// Type, per RFC 3921 (optional). Defaults to "available".
Type string
// State of presence (optional).
// Valid values: "away", "chat", "xa", "dnd" (RFC 3921).
State string
// Free text status message (optional).
Status string
}
Presence 表示传出在线状态更新。
func (*Presence) Send
Send 会发送在线状态更新。