events

package
v0.0.0-...-cddafba Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package events contains all the events that whatsmeow.Client emits to functions registered with AddEventHandler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppState

type AppState struct {
	Index []string
	*waProto.SyncActionValue
}

AppState is emitted directly for new data received from app state syncing. You should generally use the higher-level events like events.Contact and events.Mute.

type AppStateSyncComplete

type AppStateSyncComplete struct {
	Name appstate.WAPatchName
}

AppStateSyncComplete is emitted when app state is resynced.

type Archive

type Archive struct {
	JID       types.JID // The chat which was archived or unarchived.
	Timestamp time.Time // The time when the (un)archiving happened.

	Action *waProto.ArchiveChatAction // The current archival status of the chat.
}

Archive is emitted when a chat is archived or unarchived from another device.

type BusinessName

type BusinessName struct {
	JID             types.JID
	Message         *types.MessageInfo // This is only present if the change was detected in a message.
	OldBusinessName string
	NewBusinessName string
}

BusinessName is emitted when a message is received with a different verified business name than the previous value cached for the same user.

type CallAccept

type CallAccept struct {
	types.BasicCallMeta
	types.CallRemoteMeta

	Data *waBinary.Node
}

CallAccept is emitted when a call is accepted on WhatsApp.

type CallOffer

type CallOffer struct {
	types.BasicCallMeta
	types.CallRemoteMeta

	Data *waBinary.Node // The call offer data
}

CallOffer is emitted when the user receives a call on WhatsApp.

type CallOfferNotice

type CallOfferNotice struct {
	types.BasicCallMeta

	Media string // "audio" or "video" depending on call type
	Type  string // "group" when it's a group call

	Data *waBinary.Node
}

CallOfferNotice is emitted when the user receives a notice of a call on WhatsApp. This seems to be primarily for group calls (whereas CallOffer is for 1:1 calls).

type CallRelayLatency

type CallRelayLatency struct {
	types.BasicCallMeta
	Data *waBinary.Node
}

CallRelayLatency is emitted slightly after the user receives a call on WhatsApp.

type CallTerminate

type CallTerminate struct {
	types.BasicCallMeta
	Reason string
	Data   *waBinary.Node
}

CallTerminate is emitted when the other party terminates a call on WhatsApp.

type ChatPresence

type ChatPresence struct {
	types.MessageSource
	State types.ChatPresence      // The current state, either composing or paused
	Media types.ChatPresenceMedia // When composing, the type of message
}

ChatPresence is emitted when a chat state update (also known as typing notification) is received.

Note that WhatsApp won't send you these updates unless you mark yourself as online:

client.SendPresence(types.PresenceAvailable)

type ClientOutdated

type ClientOutdated struct{}

ClientOutdated is emitted when the WhatsApp server rejects the connection with the ConnectFailureClientOutdated code.

type ConnectFailure

type ConnectFailure struct {
	Reason ConnectFailureReason
	Raw    *waBinary.Node
}

ConnectFailure is emitted when the WhatsApp server sends a <failure> node with an unknown reason.

Known reasons are handled internally and emitted as different events (e.g. LoggedOut and TemporaryBan).

type ConnectFailureReason

type ConnectFailureReason int

ConnectFailureReason is an error code included in connection failure events.

const (
	ConnectFailureLoggedOut      ConnectFailureReason = 401
	ConnectFailureTempBanned     ConnectFailureReason = 402
	ConnectFailureMainDeviceGone ConnectFailureReason = 403
	ConnectFailureUnknownLogout  ConnectFailureReason = 406

	ConnectFailureClientOutdated ConnectFailureReason = 405
	ConnectFailureBadUserAgent   ConnectFailureReason = 409
)

func (ConnectFailureReason) IsLoggedOut

func (cfr ConnectFailureReason) IsLoggedOut() bool

IsLoggedOut returns true if the client should delete session data due to this connect failure.

func (ConnectFailureReason) String

func (cfr ConnectFailureReason) String() string

String returns the reason code and a short human-readable description of the error.

type Connected

type Connected struct{}

Connected is emitted when the client has successfully connected to the WhatsApp servers and is authenticated. The user who the client is authenticated as will be in the device store at this point, which is why this event doesn't contain any data.

type Contact

type Contact struct {
	JID       types.JID // The contact who was modified.
	Timestamp time.Time // The time when the modification happened.'

	Action *waProto.ContactAction // The new contact info.
}

Contact is emitted when an entry in the user's contact list is modified from another device.

type DeleteForMe

type DeleteForMe struct {
	ChatJID   types.JID // The chat where the message was deleted.
	SenderJID types.JID // In group chats, the user who sent the message (except if the message was sent by the user).
	IsFromMe  bool      // Whether the message was sent by the user.
	MessageID string    // The message which was deleted.
	Timestamp time.Time // The time when the deletion happened.

	Action *waProto.DeleteMessageForMeAction // Additional information for the deletion.
}

DeleteForMe is emitted when a message is deleted (for the current user only) from another device.

type Disconnected

type Disconnected struct{}

Disconnected is emitted when the websocket is closed by the server.

type GroupInfo

type GroupInfo struct {
	JID       types.JID  // The group ID in question
	Notify    string     // Seems like a top-level type for the invite
	Sender    *types.JID // The user who made the change. Doesn't seem to be present when notify=invite
	Timestamp time.Time  // The time when the change occurred

	Name      *types.GroupName      // Group name change
	Topic     *types.GroupTopic     // Group topic (description) change
	Locked    *types.GroupLocked    // Group locked status change (can only admins edit group info?)
	Announce  *types.GroupAnnounce  // Group announce status change (can only admins send messages?)
	Ephemeral *types.GroupEphemeral // Disappearing messages change

	NewInviteLink *string // Group invite link change

	PrevParticipantVersionID string
	ParticipantVersionID     string

	JoinReason string // This will be "invite" if the user joined via invite link

	Join  []types.JID // Users who joined or were added the group
	Leave []types.JID // Users who left or were removed from the group

	Promote []types.JID // Users who were promoted to admins
	Demote  []types.JID // Users who were demoted to normal users

	UnknownChanges []*waBinary.Node
}

GroupInfo is emitted when the metadata of a group changes.

type HistorySync

type HistorySync struct {
	Data *waProto.HistorySync
}

HistorySync is emitted when the phone has sent a blob of historical messages.

type IdentityChange

type IdentityChange struct {
	JID       types.JID
	Timestamp time.Time

	// Implicit will be set to true if the event was triggered by an untrusted identity error,
	// rather than an identity change notification from the server.
	Implicit bool
}

IdentityChange is emitted when another user changes their primary device.

type JoinedGroup

type JoinedGroup struct {
	Reason    string          // If the event was triggered by you using an invite link, this will be "invite".
	Type      string          // "new" if it's a newly created group.
	CreateKey types.MessageID // If you created the group, this is the same message ID you passed to CreateGroup.
	types.GroupInfo
}

JoinedGroup is emitted when you join or are added to a group.

type KeepAliveRestored

type KeepAliveRestored struct{}

KeepAliveRestored is emitted if the keepalive pings start working again after some KeepAliveTimeout events. Note that if the websocket disconnects before the pings start working, this event will not be emitted.

type KeepAliveTimeout

type KeepAliveTimeout struct {
	ErrorCount  int
	LastSuccess time.Time
}

KeepAliveTimeout is emitted when the keepalive ping request to WhatsApp web servers times out.

Currently, there's no automatic handling for these, but it's expected that the TCP connection will either start working again or notice it's dead on its own eventually. Clients may use this event to decide to force a disconnect+reconnect faster.

type LoggedOut

type LoggedOut struct {
	// OnConnect is true if the event was triggered by a connect failure message.
	// If it's false, the event was triggered by a stream:error message.
	OnConnect bool
	// If OnConnect is true, then this field contains the reason code.
	Reason ConnectFailureReason
}

LoggedOut is emitted when the client has been unpaired from the phone.

This can happen while connected (stream:error messages) or right after connecting (connect failure messages).

This will not be emitted when the logout is initiated by this client (using Client.LogOut()).

type MarkChatAsRead

type MarkChatAsRead struct {
	JID       types.JID // The chat which was marked as read or unread.
	Timestamp time.Time // The time when the marking happened.

	Action *waProto.MarkChatAsReadAction // Whether the chat was marked as read or unread, and info about the most recent messages.
}

MarkChatAsRead is emitted when a whole chat is marked as read or unread from another device.

type MediaRetry

type MediaRetry struct {
	Ciphertext []byte
	IV         []byte

	// Sometimes there's an unencrypted media retry error. In these cases, Ciphertext and IV will be nil.
	Error *MediaRetryError

	Timestamp time.Time // The time of the response.

	MessageID types.MessageID // The ID of the message.
	ChatID    types.JID       // The chat ID where the message was sent.
	SenderID  types.JID       // The user who sent the message. Only present in groups.
	FromMe    bool            // Whether the message was sent by the current user or someone else.
}

MediaRetry is emitted when the phone sends a response to a media retry request.

type MediaRetryError

type MediaRetryError struct {
	Code int
}

type Message

type Message struct {
	Info    types.MessageInfo // Information about the message like the chat and sender IDs
	Message *waProto.Message  // The actual message struct

	IsEphemeral bool // True if the message was unwrapped from an EphemeralMessage
	IsViewOnce  bool // True if the message was unwrapped from a ViewOnceMessage

	// The raw message struct. This is the raw unmodified data, which means the actual message might
	// be wrapped in DeviceSentMessage, EphemeralMessage or ViewOnceMessage.
	RawMessage *waProto.Message
}

Message is emitted when receiving a new message.

func (*Message) UnwrapRaw

func (evt *Message) UnwrapRaw() *Message

UnwrapRaw fills the Message, IsEphemeral and IsViewOnce fields based on the raw message in the RawMessage field.

type Mute

type Mute struct {
	JID       types.JID // The chat which was muted or unmuted.
	Timestamp time.Time // The time when the (un)muting happened.

	Action *waProto.MuteAction // The current mute status of the chat.
}

Mute is emitted when a chat is muted or unmuted from another device.

type OfflineSyncCompleted

type OfflineSyncCompleted struct {
	Count int
}

OfflineSyncCompleted is emitted after the server has finished sending missed events.

type OfflineSyncPreview

type OfflineSyncPreview struct {
	Total int

	AppDataChanges int
	Messages       int
	Notifications  int
	Receipts       int
}

OfflineSyncPreview is emitted right after connecting if the server is going to send events that the client missed during downtime.

type PairError

type PairError struct {
	ID           types.JID
	BusinessName string
	Platform     string
	Error        error
}

PairError is emitted when a pair-success event is received from the server, but finishing the pairing locally fails.

type PairSuccess

type PairSuccess struct {
	ID           types.JID
	BusinessName string
	Platform     string
}

PairSuccess is emitted after the QR code has been scanned with the phone and the handshake has been completed. Note that this is generally followed by a websocket reconnection, so you should wait for the Connected before trying to send anything.

type Picture

type Picture struct {
	JID       types.JID // The user or group ID where the picture was changed.
	Author    types.JID // The user who changed the picture.
	Timestamp time.Time // The timestamp when the picture was changed.
	Remove    bool      // True if the picture was removed.
	PictureID string    // The new picture ID if it was not removed.
}

Picture is emitted when a user's profile picture or group's photo is changed.

You can use Client.GetProfilePictureInfo to get the actual image URL after this event.

type Pin

type Pin struct {
	JID       types.JID // The chat which was pinned or unpinned.
	Timestamp time.Time // The time when the (un)pinning happened.

	Action *waProto.PinAction // Whether the chat is now pinned or not.
}

Pin is emitted when a chat is pinned or unpinned from another device.

type Presence

type Presence struct {
	// The user whose presence event this is
	From types.JID
	// True if the user is now offline
	Unavailable bool
	// The time when the user was last online. This may be the zero value if the user has hid their last seen time.
	LastSeen time.Time
}

Presence is emitted when a presence update is received.

Note that WhatsApp only sends you presence updates for individual users after you subscribe to them:

client.SubscribePresence(user JID)

type PrivacySettings

type PrivacySettings struct {
	NewSettings         types.PrivacySettings
	GroupAddChanged     bool
	LastSeenChanged     bool
	StatusChanged       bool
	ProfileChanged      bool
	ReadReceiptsChanged bool
}

PrivacySettings is emitted when the user changes their privacy settings.

type PushName

type PushName struct {
	JID         types.JID          // The user whose push name changed.
	Message     *types.MessageInfo // The message where this change was first noticed.
	OldPushName string             // The previous push name from the local cache.
	NewPushName string             // The new push name that was included in the message.
}

PushName is emitted when a message is received with a different push name than the previous value cached for the same user.

type PushNameSetting

type PushNameSetting struct {
	Timestamp time.Time // The time when the push name was changed.

	Action *waProto.PushNameSetting // The new push name for the user.
}

PushNameSetting is emitted when the user's push name is changed from another device.

type QR

type QR struct {
	Codes []string
}

QR is emitted after connecting when there's no session data in the device store.

The QR codes are available in the Codes slice. You should render the strings as QR codes one by one, switching to the next one whenever enough time has passed. WhatsApp web seems to show the first code for 60 seconds and all other codes for 20 seconds.

When the QR code has been scanned and pairing is complete, PairSuccess will be emitted. If you run out of codes before scanning, the server will close the websocket, and you will have to reconnect to get more codes.

type QRScannedWithoutMultidevice

type QRScannedWithoutMultidevice struct{}

QRScannedWithoutMultidevice is emitted when the pairing QR code is scanned, but the phone didn't have multidevice enabled. The same QR code can still be scanned after this event, which means the user can just be told to enable multidevice and re-scan the code.

type Receipt

type Receipt struct {
	types.MessageSource
	MessageIDs []types.MessageID
	Timestamp  time.Time
	Type       ReceiptType
}

Receipt is emitted when an outgoing message is delivered to or read by another user, or when another device reads an incoming message.

N.B. WhatsApp on Android sends message IDs from newest message to oldest, but WhatsApp on iOS sends them in the opposite order (oldest first).

type ReceiptType

type ReceiptType string

ReceiptType represents the type of a Receipt event.

const (
	// ReceiptTypeDelivered means the message was delivered to the device (but the user might not have noticed).
	ReceiptTypeDelivered ReceiptType = ""
	// ReceiptTypeRetry means the message was delivered to the device, but decrypting the message failed.
	ReceiptTypeRetry ReceiptType = "retry"
	// ReceiptTypeRead means the user opened the chat and saw the message.
	ReceiptTypeRead ReceiptType = "read"
	// ReceiptTypeReadSelf means the current user read a message from a different device, and has read receipts disabled in privacy settings.
	ReceiptTypeReadSelf ReceiptType = "read-self"
)

func (ReceiptType) GoString

func (rt ReceiptType) GoString() string

GoString returns the name of the Go constant for the ReceiptType value.

type Star

type Star struct {
	ChatJID   types.JID // The chat where the message was pinned.
	SenderJID types.JID // In group chats, the user who sent the message (except if the message was sent by the user).
	IsFromMe  bool      // Whether the message was sent by the user.
	MessageID string    // The message which was starred or unstarred.
	Timestamp time.Time // The time when the (un)starring happened.

	Action *waProto.StarAction // Whether the message is now starred or not.
}

Star is emitted when a message is starred or unstarred from another device.

type StreamError

type StreamError struct {
	Code string
	Raw  *waBinary.Node
}

StreamError is emitted when the WhatsApp server sends a <stream:error> node with an unknown code.

Known codes are handled internally and emitted as different events (e.g. LoggedOut).

type StreamReplaced

type StreamReplaced struct{}

StreamReplaced is emitted when the client is disconnected by another client connecting with the same keys.

This can happen if you accidentally start another process with the same session or otherwise try to connect twice with the same session.

type TempBanReason

type TempBanReason int

TempBanReason is an error code included in temp ban error events.

const (
	TempBanBlockedByUsers         TempBanReason = 101
	TempBanSentToTooManyPeople    TempBanReason = 102
	TempBanCreatedTooManyGroups   TempBanReason = 103
	TempBanSentTooManySameMessage TempBanReason = 104
	TempBanBroadcastList          TempBanReason = 106
)

func (TempBanReason) String

func (tbr TempBanReason) String() string

String returns the reason code and a human-readable description of the ban reason.

type TemporaryBan

type TemporaryBan struct {
	Code   TempBanReason
	Expire time.Time
}

TemporaryBan is emitted when there's a connection failure with the ConnectFailureTempBanned reason code.

func (*TemporaryBan) String

func (tb *TemporaryBan) String() string

type UnarchiveChatsSetting

type UnarchiveChatsSetting struct {
	Timestamp time.Time // The time when the setting was changed.

	Action *waProto.UnarchiveChatsSetting // The new settings.
}

UnarchiveChatsSetting is emitted when the user changes the "Keep chats archived" setting from another device.

type UndecryptableMessage

type UndecryptableMessage struct {
	Info types.MessageInfo

	// IsUnavailable is true if the recipient device didn't send a ciphertext to this device at all
	// (as opposed to sending a ciphertext, but the ciphertext not being decryptable).
	IsUnavailable bool
}

UndecryptableMessage is emitted when receiving a new message that failed to decrypt.

The library will automatically ask the sender to retry. If the sender resends the message, and it's decryptable, then it will be emitted as a normal Message event.

The UndecryptableMessage event may also be repeated if the resent message is also undecryptable.

type UnknownCallEvent

type UnknownCallEvent struct {
	Node *waBinary.Node
}

UnknownCallEvent is emitted when a call element with unknown content is received.

Jump to

Keyboard shortcuts

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