types

package
v0.0.0-...-681a319 Latest Latest
Warning

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

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

Documentation

Overview

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

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 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        string
	Type      string
	PushName  string
	Timestamp time.Time
	Category  string
	Multicast bool
	MediaType string

	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 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 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"
	PrivacySettingNone      PrivacySetting = "none"
)

Possible privacy setting values.

type PrivacySettings

type PrivacySettings struct {
	GroupAdd     PrivacySetting
	LastSeen     PrivacySetting
	Status       PrivacySetting
	Profile      PrivacySetting
	ReadReceipts PrivacySetting
}

PrivacySettings contains the user's privacy settings.

type ProfilePictureInfo

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

	DirectPath string // 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 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.

Directories

Path Synopsis
Package events contains all the events that whatsappprotocol.Client emits to functions registered with AddEventHandler.
Package events contains all the events that whatsappprotocol.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