types

package
v0.0.0-...-b6c8c77 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package types contains various structs and other types used by whatsmeow.

Index

Constants

View Source
const (
	DefaultUserServer = "s.whatsapp.net"
	GroupServer       = "g.us"
	LegacyUserServer  = "c.us"
	BroadcastServer   = "broadcast"
	HiddenUserServer  = "lid"
	MessengerServer   = "msgr"
	InteropServer     = "interop"
	NewsletterServer  = "newsletter"
	HostedServer      = "hosted"
)

Known JID servers on WhatsApp

Variables

View Source
var (
	EmptyJID            = JID{}
	GroupServerJID      = NewJID("", GroupServer)
	ServerJID           = NewJID("", DefaultUserServer)
	BroadcastServerJID  = NewJID("", BroadcastServer)
	StatusBroadcastJID  = NewJID("status", BroadcastServer)
	PSAJID              = NewJID("0", LegacyUserServer)
	OfficialBusinessJID = NewJID("16505361212", LegacyUserServer)
)

Some JIDs that are contacted often.

Functions

This section is empty.

Types

type BasicCallMeta

type BasicCallMeta struct {
	From        JID
	Timestamp   time.Time
	CallCreator JID
	CallID      string
}

type Blocklist

type Blocklist struct {
	DHash string // TODO is this just a timestamp?
	JIDs  []JID
}

Blocklist contains the user's current list of blocked users.

type BusinessMessageLinkTarget

type BusinessMessageLinkTarget struct {
	JID JID // The JID of the business.

	PushName      string // The notify / push name of the business.
	VerifiedName  string // The verified business name.
	IsSigned      bool   // Some boolean, seems to be true?
	VerifiedLevel string // I guess the level of verification, starting from "unknown".

	Message string // The message that WhatsApp clients will pre-fill in the input box when clicking the link.
}

BusinessMessageLinkTarget contains the info that is found using a business message link (see Client.ResolveBusinessMessageLink)

type CallRemoteMeta

type CallRemoteMeta struct {
	RemotePlatform string // The platform of the caller's WhatsApp client
	RemoteVersion  string // Version of the caller's WhatsApp client
}

type ChatPresence

type ChatPresence string
const (
	ChatPresenceComposing ChatPresence = "composing"
	ChatPresencePaused    ChatPresence = "paused"
)

type ChatPresenceMedia

type ChatPresenceMedia string
const (
	ChatPresenceMediaText  ChatPresenceMedia = ""
	ChatPresenceMediaAudio ChatPresenceMedia = "audio"
)

type ContactInfo

type ContactInfo struct {
	Found bool

	FirstName    string
	FullName     string
	PushName     string
	BusinessName string
}

ContactInfo contains the cached names of a WhatsApp user.

type ContactQRLinkTarget

type ContactQRLinkTarget struct {
	JID      JID    // The JID of the user.
	Type     string // Might always be "contact".
	PushName string // The notify / push name of the user.
}

ContactQRLinkTarget contains the info that is found using a contact QR link (see Client.ResolveContactQRLink)

type DeviceSentMeta

type DeviceSentMeta struct {
	DestinationJID string // The destination user. This should match the MessageInfo.Recipient field.
	Phash          string
}

DeviceSentMeta contains metadata from messages sent by another one of the user's own devices.

type EditAttribute

type EditAttribute string
const (
	EditAttributeEmpty        EditAttribute = ""
	EditAttributeMessageEdit  EditAttribute = "1"
	EditAttributePinInChat    EditAttribute = "2"
	EditAttributeAdminEdit    EditAttribute = "3" // only used in newsletters
	EditAttributeSenderRevoke EditAttribute = "7"
	EditAttributeAdminRevoke  EditAttribute = "8"
)

type GraphQLError

type GraphQLError struct {
	Extensions GraphQLErrorExtensions `json:"extensions"`
	Message    string                 `json:"message"`
	Path       []string               `json:"path"`
}

func (GraphQLError) Error

func (gqle GraphQLError) Error() string

type GraphQLErrorExtensions

type GraphQLErrorExtensions struct {
	ErrorCode   int    `json:"error_code"`
	IsRetryable bool   `json:"is_retryable"`
	Severity    string `json:"severity"`
}

type GraphQLErrors

type GraphQLErrors []GraphQLError

func (GraphQLErrors) Error

func (gqles GraphQLErrors) Error() string

func (GraphQLErrors) Unwrap

func (gqles GraphQLErrors) Unwrap() []error

type GraphQLResponse

type GraphQLResponse struct {
	Data   json.RawMessage `json:"data"`
	Errors GraphQLErrors   `json:"errors"`
}

type GroupAnnounce

type GroupAnnounce struct {
	IsAnnounce        bool
	AnnounceVersionID string
}

GroupAnnounce specifies whether only admins can send messages in the group.

type GroupDelete

type GroupDelete struct {
	Deleted      bool
	DeleteReason string
}

type GroupEphemeral

type GroupEphemeral struct {
	IsEphemeral       bool
	DisappearingTimer uint32
}

GroupEphemeral contains the group's disappearing messages settings.

type GroupIncognito

type GroupIncognito struct {
	IsIncognito bool
}

type GroupInfo

type GroupInfo struct {
	JID      JID
	OwnerJID JID

	GroupName
	GroupTopic
	GroupLocked
	GroupAnnounce
	GroupEphemeral
	GroupIncognito

	GroupParent
	GroupLinkedParent
	GroupIsDefaultSub

	GroupCreated time.Time

	ParticipantVersionID string
	Participants         []GroupParticipant

	MemberAddMode GroupMemberAddMode
}

GroupInfo contains basic information about a group chat on WhatsApp.

type GroupIsDefaultSub

type GroupIsDefaultSub struct {
	IsDefaultSubGroup bool
}

type GroupLinkChange

type GroupLinkChange struct {
	Type         GroupLinkChangeType
	UnlinkReason GroupUnlinkReason
	Group        GroupLinkTarget
}

type GroupLinkChangeType

type GroupLinkChangeType string
const (
	GroupLinkChangeTypeParent  GroupLinkChangeType = "parent_group"
	GroupLinkChangeTypeSub     GroupLinkChangeType = "sub_group"
	GroupLinkChangeTypeSibling GroupLinkChangeType = "sibling_group"
)

type GroupLinkTarget

type GroupLinkTarget struct {
	JID JID
	GroupName
	GroupIsDefaultSub
}

type GroupLinkedParent

type GroupLinkedParent struct {
	LinkedParentJID JID
}

type GroupLocked

type GroupLocked struct {
	IsLocked bool
}

GroupLocked specifies whether the group info can only be edited by admins.

type GroupMemberAddMode

type GroupMemberAddMode string
const (
	GroupMemberAddModeAdmin GroupMemberAddMode = "admin_add"
)

type GroupName

type GroupName struct {
	Name      string
	NameSetAt time.Time
	NameSetBy JID
}

GroupName contains the name of a group along with metadata of who set it and when.

type GroupParent

type GroupParent struct {
	IsParent                      bool
	DefaultMembershipApprovalMode string // request_required
}

type GroupParticipant

type GroupParticipant struct {
	JID          JID
	LID          JID
	IsAdmin      bool
	IsSuperAdmin bool

	// This is only present for anonymous users in announcement groups, it's an obfuscated phone number
	DisplayName string

	// When creating groups, adding some participants may fail.
	// In such cases, the error code will be here.
	Error      int
	AddRequest *GroupParticipantAddRequest
}

GroupParticipant contains info about a participant of a WhatsApp group chat.

type GroupParticipantAddRequest

type GroupParticipantAddRequest struct {
	Code       string
	Expiration time.Time
}

type GroupTopic

type GroupTopic struct {
	Topic        string
	TopicID      string
	TopicSetAt   time.Time
	TopicSetBy   JID
	TopicDeleted bool
}

GroupTopic contains the topic (description) of a group along with metadata of who set it and when.

type GroupUnlinkReason

type GroupUnlinkReason string
const (
	GroupUnlinkReasonDefault GroupUnlinkReason = "unlink_group"
	GroupUnlinkReasonDelete  GroupUnlinkReason = "delete_parent"
)

type IsOnWhatsAppResponse

type IsOnWhatsAppResponse struct {
	Query string // The query string used
	JID   JID    // The canonical user ID
	IsIn  bool   // Whether the phone is registered or not.

	VerifiedName *VerifiedName // If the phone is a business, the verified business details.
}

IsOnWhatsAppResponse contains information received in response to checking if a phone number is on WhatsApp.

type JID

type JID struct {
	User       string
	RawAgent   uint8
	Device     uint16
	Integrator uint16
	Server     string
}

JID represents a WhatsApp user ID.

There are two types of JIDs: regular JID pairs (user and server) and AD-JIDs (user, agent and device). AD JIDs are only used to refer to specific devices of users, so the server is always s.whatsapp.net (DefaultUserServer). Regular JIDs can be used for entities on any servers (users, groups, broadcasts).

func NewADJID

func NewADJID(user string, agent, device uint8) JID

NewADJID creates a new AD JID.

func NewJID

func NewJID(user, server string) JID

NewJID creates a new regular JID.

func ParseJID

func ParseJID(jid string) (JID, error)

ParseJID parses a JID out of the given string. It supports both regular and AD JIDs.

func (JID) ADString

func (jid JID) ADString() string

func (JID) ActualAgent

func (jid JID) ActualAgent() uint8

func (JID) IsBroadcastList

func (jid JID) IsBroadcastList() bool

IsBroadcastList returns true if the JID is a broadcast list, but not the status broadcast.

func (JID) IsEmpty

func (jid JID) IsEmpty() bool

IsEmpty returns true if the JID has no server (which is required for all JIDs).

func (JID) MarshalText

func (jid JID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler for JID

func (*JID) Scan

func (jid *JID) Scan(src interface{}) error

Scan scans the given SQL value into this JID.

func (JID) SignalAddress

func (jid JID) SignalAddress() *signalProtocol.SignalAddress

SignalAddress returns the Signal protocol address for the user.

func (JID) String

func (jid JID) String() string

String converts the JID to a string representation. The output string can be parsed with ParseJID.

func (JID) ToNonAD

func (jid JID) ToNonAD() JID

ToNonAD returns a version of the JID struct that doesn't have the agent and device set.

func (*JID) UnmarshalText

func (jid *JID) UnmarshalText(val []byte) error

UnmarshalText implements encoding.TextUnmarshaler for JID

func (JID) UserInt

func (jid JID) UserInt() uint64

UserInt returns the user as an integer. This is only safe to run on normal users, not on groups or broadcast lists.

func (JID) Value

func (jid JID) Value() (driver.Value, error)

Value returns the string representation of the JID as a value that the SQL package can use.

type LocalChatSettings

type LocalChatSettings struct {
	Found bool

	MutedUntil time.Time
	Pinned     bool
	Archived   bool
}

LocalChatSettings contains the cached local settings for a chat.

type MessageID

type MessageID = string

MessageID is the internal ID of a WhatsApp message.

type MessageInfo

type MessageInfo struct {
	MessageSource
	ID        MessageID
	ServerID  MessageServerID
	Type      string
	PushName  string
	Timestamp time.Time
	Category  string
	Multicast bool
	MediaType string
	Edit      EditAttribute

	VerifiedName   *VerifiedName
	DeviceSentMeta *DeviceSentMeta // Metadata for direct messages sent from another one of the user's own devices.
}

MessageInfo contains metadata about an incoming message.

type MessageServerID

type MessageServerID = int

MessageServerID is the server ID of a WhatsApp newsletter message.

type MessageSource

type MessageSource struct {
	Chat     JID  // The chat where the message was sent.
	Sender   JID  // The user who sent the message.
	IsFromMe bool // Whether the message was sent by the current user instead of someone else.
	IsGroup  bool // Whether the chat is a group chat or broadcast list.

	// When sending a read receipt to a broadcast list message, the Chat is the broadcast list
	// and Sender is you, so this field contains the recipient of the read receipt.
	BroadcastListOwner JID
}

MessageSource contains basic sender and chat information about a message.

func (*MessageSource) IsIncomingBroadcast

func (ms *MessageSource) IsIncomingBroadcast() bool

IsIncomingBroadcast returns true if the message was sent to a broadcast list instead of directly to the user.

If this is true, it means the message shows up in the direct chat with the Sender.

func (*MessageSource) SourceString

func (ms *MessageSource) SourceString() string

SourceString returns a log-friendly representation of who sent the message and where.

type NewsletterKeyType

type NewsletterKeyType string
const (
	NewsletterKeyTypeJID    NewsletterKeyType = "JID"
	NewsletterKeyTypeInvite NewsletterKeyType = "INVITE"
)

type NewsletterMessage

type NewsletterMessage struct {
	MessageServerID MessageServerID
	ViewsCount      int
	ReactionCounts  map[string]int

	// This is only present when fetching messages, not in live updates
	Message *waProto.Message
}

type NewsletterMetadata

type NewsletterMetadata struct {
	ID         JID                       `json:"id"`
	State      WrappedNewsletterState    `json:"state"`
	ThreadMeta NewsletterThreadMetadata  `json:"thread_metadata"`
	ViewerMeta *NewsletterViewerMetadata `json:"viewer_metadata"`
}

type NewsletterMuteState

type NewsletterMuteState string
const (
	NewsletterMuteOn  NewsletterMuteState = "on"
	NewsletterMuteOff NewsletterMuteState = "off"
)

func (*NewsletterMuteState) UnmarshalText

func (nms *NewsletterMuteState) UnmarshalText(text []byte) error

type NewsletterMuted

type NewsletterMuted struct {
	Muted bool
}

type NewsletterPrivacy

type NewsletterPrivacy string
const (
	NewsletterPrivacyPrivate NewsletterPrivacy = "private"
	NewsletterPrivacyPublic  NewsletterPrivacy = "public"
)

func (*NewsletterPrivacy) UnmarshalText

func (np *NewsletterPrivacy) UnmarshalText(text []byte) error

type NewsletterReactionSettings

type NewsletterReactionSettings struct {
	Value NewsletterReactionsMode `json:"value"`
}

type NewsletterReactionsMode

type NewsletterReactionsMode string
const (
	NewsletterReactionsModeAll       NewsletterReactionsMode = "all"
	NewsletterReactionsModeBasic     NewsletterReactionsMode = "basic"
	NewsletterReactionsModeNone      NewsletterReactionsMode = "none"
	NewsletterReactionsModeBlocklist NewsletterReactionsMode = "blocklist"
)

type NewsletterRole

type NewsletterRole string
const (
	NewsletterRoleSubscriber NewsletterRole = "subscriber"
	NewsletterRoleGuest      NewsletterRole = "guest"
	NewsletterRoleAdmin      NewsletterRole = "admin"
	NewsletterRoleOwner      NewsletterRole = "owner"
)

func (*NewsletterRole) UnmarshalText

func (nr *NewsletterRole) UnmarshalText(text []byte) error

type NewsletterSettings

type NewsletterSettings struct {
	ReactionCodes NewsletterReactionSettings `json:"reaction_codes"`
}

type NewsletterState

type NewsletterState string
const (
	NewsletterStateActive       NewsletterState = "active"
	NewsletterStateSuspended    NewsletterState = "suspended"
	NewsletterStateGeoSuspended NewsletterState = "geosuspended"
)

func (*NewsletterState) UnmarshalText

func (ns *NewsletterState) UnmarshalText(text []byte) error

type NewsletterText

type NewsletterText struct {
	Text       string                   `json:"text"`
	ID         string                   `json:"id"`
	UpdateTime jsontime.UnixMicroString `json:"update_time"`
}

type NewsletterThreadMetadata

type NewsletterThreadMetadata struct {
	CreationTime      jsontime.UnixString         `json:"creation_time"`
	InviteCode        string                      `json:"invite"`
	Name              NewsletterText              `json:"name"`
	Description       NewsletterText              `json:"description"`
	SubscriberCount   int                         `json:"subscribers_count,string"`
	VerificationState NewsletterVerificationState `json:"verification"`
	Picture           *ProfilePictureInfo         `json:"picture"`
	Preview           ProfilePictureInfo          `json:"preview"`
	Settings          NewsletterSettings          `json:"settings"`
}

type NewsletterVerificationState

type NewsletterVerificationState string
const (
	NewsletterVerificationStateVerified   NewsletterVerificationState = "verified"
	NewsletterVerificationStateUnverified NewsletterVerificationState = "unverified"
)

func (*NewsletterVerificationState) UnmarshalText

func (nvs *NewsletterVerificationState) UnmarshalText(text []byte) error

type NewsletterViewerMetadata

type NewsletterViewerMetadata struct {
	Mute NewsletterMuteState `json:"mute"`
	Role NewsletterRole      `json:"role"`
}

type Presence

type Presence string
const (
	PresenceAvailable   Presence = "available"
	PresenceUnavailable Presence = "unavailable"
)

type PrivacySetting

type PrivacySetting string

PrivacySetting is an individual setting value in the user's privacy settings.

const (
	PrivacySettingUndefined        PrivacySetting = ""
	PrivacySettingAll              PrivacySetting = "all"
	PrivacySettingContacts         PrivacySetting = "contacts"
	PrivacySettingContactBlacklist PrivacySetting = "contact_blacklist"
	PrivacySettingMatchLastSeen    PrivacySetting = "match_last_seen"
	PrivacySettingKnown            PrivacySetting = "known"
	PrivacySettingNone             PrivacySetting = "none"
)

Possible privacy setting values.

type PrivacySettingType

type PrivacySettingType string

PrivacySettingType is the type of privacy setting.

const (
	PrivacySettingTypeGroupAdd     PrivacySettingType = "groupadd"     // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	PrivacySettingTypeLastSeen     PrivacySettingType = "last"         // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	PrivacySettingTypeStatus       PrivacySettingType = "status"       // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	PrivacySettingTypeProfile      PrivacySettingType = "profile"      // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	PrivacySettingTypeReadReceipts PrivacySettingType = "readreceipts" // Valid values: PrivacySettingAll, PrivacySettingNone
	PrivacySettingTypeOnline       PrivacySettingType = "online"       // Valid values: PrivacySettingAll, PrivacySettingMatchLastSeen
	PrivacySettingTypeCallAdd      PrivacySettingType = "calladd"      // Valid values: PrivacySettingAll, PrivacySettingKnown
)

type PrivacySettings

type PrivacySettings struct {
	GroupAdd     PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	LastSeen     PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	Status       PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	Profile      PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingContacts, PrivacySettingContactBlacklist, PrivacySettingNone
	ReadReceipts PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingNone
	CallAdd      PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingKnown
	Online       PrivacySetting // Valid values: PrivacySettingAll, PrivacySettingMatchLastSeen
}

PrivacySettings contains the user's privacy settings.

type ProfilePictureInfo

type ProfilePictureInfo struct {
	URL  string `json:"url"`  // The full URL for the image, can be downloaded with a simple HTTP request.
	ID   string `json:"id"`   // The ID of the image. This is the same as UserInfo.PictureID.
	Type string `json:"type"` // The type of image. Known types include "image" (full res) and "preview" (thumbnail).

	DirectPath string `json:"direct_path"` // The path to the image, probably not very useful
}

ProfilePictureInfo contains the ID and URL for a WhatsApp user's profile picture or group's photo.

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 = ""
	// ReceiptTypeSender is sent by your other devices when a message you sent is delivered to them.
	ReceiptTypeSender ReceiptType = "sender"
	// 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"
	// ReceiptTypePlayed means the user opened a view-once media message.
	//
	// This is dispatched for both incoming and outgoing messages when played. If the current user opened the media,
	// it means the media should be removed from all devices. If a recipient opened the media, it's just a notification
	// for the sender that the media was viewed.
	ReceiptTypePlayed ReceiptType = "played"
	// ReceiptTypePlayedSelf probably means the current user opened a view-once media message from a different device,
	// and has read receipts disabled in privacy settings.
	ReceiptTypePlayedSelf ReceiptType = "played-self"

	ReceiptTypeServerError ReceiptType = "server-error"
	ReceiptTypeInactive    ReceiptType = "inactive"
	ReceiptTypePeerMsg     ReceiptType = "peer_msg"
	ReceiptTypeHistorySync ReceiptType = "hist_sync"
)

func (ReceiptType) GoString

func (rt ReceiptType) GoString() string

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

type StatusPrivacy

type StatusPrivacy struct {
	Type StatusPrivacyType
	List []JID

	IsDefault bool
}

StatusPrivacy contains the settings for who to send status messages to by default.

type StatusPrivacyType

type StatusPrivacyType string

StatusPrivacyType is the type of list in StatusPrivacy.

const (
	// StatusPrivacyTypeContacts means statuses are sent to all contacts.
	StatusPrivacyTypeContacts StatusPrivacyType = "contacts"
	// StatusPrivacyTypeBlacklist means statuses are sent to all contacts, except the ones on the list.
	StatusPrivacyTypeBlacklist StatusPrivacyType = "blacklist"
	// StatusPrivacyTypeWhitelist means statuses are only sent to users on the list.
	StatusPrivacyTypeWhitelist StatusPrivacyType = "whitelist"
)

type UserInfo

type UserInfo struct {
	VerifiedName *VerifiedName
	Status       string
	PictureID    string
	Devices      []JID
}

UserInfo contains info about a WhatsApp user.

type VerifiedName

type VerifiedName struct {
	Certificate *waProto.VerifiedNameCertificate
	Details     *waProto.VerifiedNameCertificate_Details
}

VerifiedName contains verified WhatsApp business details.

type WrappedNewsletterState

type WrappedNewsletterState struct {
	Type NewsletterState `json:"type"`
}

Directories

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

Jump to

Keyboard shortcuts

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