Documentation ¶
Overview ¶
Package whatsapp provides a developer API to interact with the WhatsAppWeb-Servers.
Index ¶
- Constants
- func Download(url string, mediaKey []byte, appInfo MediaType, fileLength int) ([]byte, error)
- func GetLiveLocationProto(msg LiveLocationMessage) *proto.WebMessageInfo
- func GetLocationProto(msg LocationMessage) *proto.WebMessageInfo
- type AudioMessage
- type AudioMessageHandler
- type Conn
- func (wac *Conn) AddHandler(handler Handler)
- func (wac *Conn) AddMember(jid string, participants []string) (<-chan string, error)
- func (wac *Conn) Chats() (*binary.Node, error)
- func (wac *Conn) Contacts() (*binary.Node, error)
- func (wac *Conn) CreateGroup(subject string, participants []string) (<-chan string, error)
- func (wac *Conn) Disconnect()
- func (wac *Conn) Emoji() (*binary.Node, error)
- func (wac *Conn) Exist(jid string) (<-chan string, error)
- func (wac *Conn) GetGroupMetaData(jid string) (<-chan string, error)
- func (wac *Conn) GetProfilePicThumb(jid string) (<-chan string, error)
- func (wac *Conn) GetStatus(jid string) (<-chan string, error)
- func (wac *Conn) LeaveGroup(jid string) (<-chan string, error)
- func (wac *Conn) LoadChatHistoryBefore(jid string, count int, messageId string, owner bool, handlers []Handler)
- func (wac *Conn) LoadFullChatHistory(jid string, chunkSize int, handlers []Handler, ...)
- func (wac *Conn) LoadFullChatHistoryAfter(jid string, messageId string, chunkSize int, handlers []Handler, ...)
- func (wac *Conn) LoadMessages(jid, messageId string, count int) (*binary.Node, error)
- func (wac *Conn) LoadMessagesAfter(jid, messageId string, count int) (*binary.Node, error)
- func (wac *Conn) LoadMessagesBefore(jid, messageId string, count int) (*binary.Node, error)
- func (wac *Conn) Login(qrChan chan<- string) (Session, error)
- func (wac *Conn) Logout() error
- func (wac *Conn) Presence(jid string, presence Presence) (<-chan string, error)
- func (wac *Conn) Read(jid, id string) (<-chan string, error)
- func (wac *Conn) RemoveAdmin(jid string, participants []string) (<-chan string, error)
- func (wac *Conn) RemoveMember(jid string, participants []string) (<-chan string, error)
- func (wac *Conn) RestoreSession(session Session) (Session, error)
- func (wac *Conn) Search(search string, count, page int) (*binary.Node, error)
- func (wac *Conn) Send(msg interface{}) error
- func (wac *Conn) SetAdmin(jid string, participants []string) (<-chan string, error)
- func (wac *Conn) SetClientName(long, short string) error
- func (wac *Conn) SubscribePresence(jid string) (<-chan string, error)
- func (wac *Conn) UpdateGroupSubject(subject string, jid string) (<-chan string, error)
- func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (url string, mediaKey []byte, fileEncSha256 []byte, fileSha256 []byte, ...)
- type ConnectionStatus
- type Contact
- type DocumentMessage
- type DocumentMessageHandler
- type Handler
- type ImageMessage
- type ImageMessageHandler
- type Info
- type JsonMessageHandler
- type LiveLocationMessage
- type LiveLocationMessageHandler
- type LocationMessage
- type LocationMessageHandler
- type MediaType
- type MessageInfo
- type MessageOffsetInfo
- type MessageStatus
- type PhoneInfo
- type Presence
- type RawMessageHandler
- type Session
- type Store
- type TextMessage
- type TextMessageHandler
- type VideoMessage
- type VideoMessageHandler
Constants ¶
const ( PresenceAvailable = "available" PresenceComposing = "composing" )
const ( Error MessageStatus = 0 Pending = 1 ServerAck = 2 DeliveryAck = 3 Read = 4 Played = 5 )
Variables ¶
This section is empty.
Functions ¶
func GetLiveLocationProto ¶ added in v0.0.6
func GetLiveLocationProto(msg LiveLocationMessage) *proto.WebMessageInfo
func GetLocationProto ¶ added in v0.0.6
func GetLocationProto(msg LocationMessage) *proto.WebMessageInfo
Types ¶
type AudioMessage ¶
type AudioMessage struct { Info MessageInfo Length uint32 Type string Content io.Reader FileSha256 []byte FileLength uint64 // contains filtered or unexported fields }
AudioMessage represents a audio message. Unexported fields are needed for media up/downloading and media validation. Provide a io.Reader as Content for message sending.
func (*AudioMessage) Download ¶
func (m *AudioMessage) Download() ([]byte, error)
Download is the function to retrieve media data. The media gets downloaded, validated and returned.
type AudioMessageHandler ¶
type AudioMessageHandler interface { Handler HandleAudioMessage(message AudioMessage) }
The AudioMessageHandler interface needs to be implemented to receive audio messages dispatched by the dispatcher.
type Conn ¶
type Conn struct { Info *Info Store *Store ServerLastSeen time.Time // contains filtered or unexported fields }
Conn is created by NewConn. Interacting with the initialized Conn is the main way of interacting with our package. It holds all necessary information to make the package work internally.
func NewConn ¶
Creates a new connection with a given timeout. The websocket connection to the WhatsAppWeb servers get´s established. The goroutine for handling incoming messages is started
func NewConnWithClientName ¶ added in v0.0.5
func NewConnWithClientName(timeout time.Duration, clientName, shortClientName string, clientVersion string) (*Conn, error)
*
func (*Conn) AddHandler ¶
AddHandler adds an handler to the list of handler that receive dispatched messages. The provided handler must at least implement the Handler interface. Additionally implemented handlers(TextMessageHandler, ImageMessageHandler) are optional. At runtime it is checked if they are implemented and they are called if so and needed.
func (*Conn) CreateGroup ¶
func (*Conn) Disconnect ¶
func (wac *Conn) Disconnect()
async disconnection: sets disconnected flag so pumping goroutines will stop pumping
func (*Conn) GetGroupMetaData ¶
func (*Conn) GetProfilePicThumb ¶
TODO: filename? WhatsApp uses Store.Contacts for these functions TODO: functions probably shouldn't return a string, maybe build a struct / return json TODO: check for further queries
func (*Conn) LoadChatHistoryBefore ¶ added in v0.0.6
func (wac *Conn) LoadChatHistoryBefore(jid string, count int, messageId string, owner bool, handlers []Handler)
owner = search for owner's message; if handlers == nil the func will use default handlers
func (*Conn) LoadFullChatHistory ¶ added in v0.0.6
func (wac *Conn) LoadFullChatHistory(jid string, chunkSize int, handlers []Handler, pauseBetweenQueries time.Duration)
chunkSize = how many messages to load with one query; if handlers == nil the func will use default handlers; pauseBetweenQueries = how much time to sleep between queries
func (*Conn) LoadFullChatHistoryAfter ¶ added in v0.0.6
func (*Conn) LoadMessages ¶
func (*Conn) LoadMessagesAfter ¶
func (*Conn) LoadMessagesBefore ¶
func (*Conn) Login ¶
Login is the function that creates a new whatsapp session and logs you in. If you do not want to scan the qr code every time, you should save the returned session and use RestoreSession the next time. Login takes a writable channel as an parameter. This channel is used to push the data represented by the qr code back to the user. The received data should be displayed as an qr code in a way you prefer. To print a qr code to console you can use: github.com/Baozisoftware/qrcode-terminal-go Example login procedure:
wac, err := whatsapp.NewConn(5 * time.Second, "gleandroj/go-whatsapp", "go-whatsapp") if err != nil { panic(err) } qr := make(chan string) go func() { terminal := qrcodeTerminal.New() terminal.Get(<-qr).Print() }() session, err := wac.Login(qr) if err != nil { fmt.Fprintf(os.Stderr, "error during login: %v\n", err) } fmt.Printf("login successful, session: %v\n", session)
func (*Conn) Logout ¶
Logout is the function to logout from a WhatsApp session. Logging out means invalidating the current session. The session can not be resumed and will disappear on your phone in the WhatsAppWeb client list.
func (*Conn) RemoveAdmin ¶
func (*Conn) RemoveMember ¶
func (*Conn) RestoreSession ¶
RestoreSession is the function that restores a given session. It will try to reestablish the connection to the WhatsAppWeb servers with the provided session. If it succeeds it will return a new session. This new session has to be saved because the Client and Server-Token will change after every login. Logging in with old tokens is possible, but not suggested. If so, a challenge has to be resolved which is just another possible point of failure.
func (*Conn) SetClientName ¶
SetClientName sets the long and short client names that are sent to WhatsApp when logging in and displayed in the WhatsApp Web device list. As the values are only sent when logging in, changing them after logging in is not possible.
func (*Conn) SubscribePresence ¶
func (*Conn) UpdateGroupSubject ¶
type ConnectionStatus ¶ added in v0.0.5
connection status. TODO: wac has isConnected method, consider integration
func (*ConnectionStatus) Connected ¶ added in v0.0.5
func (s *ConnectionStatus) Connected() bool
func (*ConnectionStatus) SetConnected ¶ added in v0.0.5
func (s *ConnectionStatus) SetConnected(value bool)
type DocumentMessage ¶
type DocumentMessage struct { Info MessageInfo Title string PageCount uint32 Type string Thumbnail []byte Content io.Reader FileSha256 []byte FileLength uint64 // contains filtered or unexported fields }
DocumentMessage represents a document message. Unexported fields are needed for media up/downloading and media validation. Provide a io.Reader as Content for message sending.
func (*DocumentMessage) Download ¶
func (m *DocumentMessage) Download() ([]byte, error)
Download is the function to retrieve media data. The media gets downloaded, validated and returned.
type DocumentMessageHandler ¶
type DocumentMessageHandler interface { Handler HandleDocumentMessage(message DocumentMessage) }
The DocumentMessageHandler interface needs to be implemented to receive document messages dispatched by the dispatcher.
type Handler ¶
type Handler interface {
HandleError(err error)
}
The Handler interface is the minimal interface that needs to be implemented to be accepted as a valid handler for our dispatching system. The minimal handler is used to dispatch error messages. These errors occur on unexpected behavior by the websocket connection or if we are unable to handle or interpret an incoming message. Error produced by user actions are not dispatched through this handler. They are returned as an error on the specific function call.
type ImageMessage ¶
type ImageMessage struct { Info MessageInfo Caption string Thumbnail []byte Type string Content io.Reader FileSha256 []byte FileLength uint64 // contains filtered or unexported fields }
ImageMessage represents a image message. Unexported fields are needed for media up/downloading and media validation. Provide a io.Reader as Content for message sending.
func (*ImageMessage) Download ¶
func (m *ImageMessage) Download() ([]byte, error)
Download is the function to retrieve media data. The media gets downloaded, validated and returned.
type ImageMessageHandler ¶
type ImageMessageHandler interface { Handler HandleImageMessage(message ImageMessage) }
The ImageMessageHandler interface needs to be implemented to receive image messages dispatched by the dispatcher.
type JsonMessageHandler ¶
The JsonMessageHandler interface needs to be implemented to receive json messages dispatched by the dispatcher. These json messages contain status updates of every kind sent by WhatsAppWeb servers. WhatsAppWeb uses these messages to built a Store, which is used to save these "secondary" information. These messages may contain presence (available, last see) information, or just the battery status of your phone.
type LiveLocationMessage ¶ added in v0.0.6
type LiveLocationMessage struct { Info MessageInfo DegreesLatitude float64 DegreesLongitude float64 AccuracyInMeters uint32 SpeedInMps float32 DegreesClockwiseFromMagneticNorth uint32 Caption string SequenceNumber int64 JpegThumbnail []byte }
func GetLiveLocationMessage ¶ added in v0.0.6
func GetLiveLocationMessage(msg *proto.WebMessageInfo) LiveLocationMessage
type LiveLocationMessageHandler ¶ added in v0.0.6
type LiveLocationMessageHandler interface { Handler HandleLiveLocationMessage(message LiveLocationMessage) }
The LiveLocationMessageHandler interface needs to be implemented to receive live location messages dispatched by the dispatcher.
type LocationMessage ¶ added in v0.0.6
type LocationMessage struct { Info MessageInfo DegreesLatitude float64 DegreesLongitude float64 Name string Address string Url string JpegThumbnail []byte }
func GetLocationMessage ¶ added in v0.0.6
func GetLocationMessage(msg *proto.WebMessageInfo) LocationMessage
type LocationMessageHandler ¶ added in v0.0.6
type LocationMessageHandler interface { Handler HandleLocationMessage(message LocationMessage) }
The LocationMessageHandler interface needs to be implemented to receive location messages dispatched by the dispatcher.
type MessageInfo ¶
type MessageInfo struct { Id string RemoteJid string SenderJid string FromMe bool Timestamp uint64 PushName string Status MessageStatus QuotedMessageID string Source *proto.WebMessageInfo }
MessageInfo contains general message information. It is part of every of every message type.
type MessageOffsetInfo ¶ added in v0.0.6
type MessageStatus ¶
type MessageStatus int
type RawMessageHandler ¶
type RawMessageHandler interface { Handler HandleRawMessage(message *proto.WebMessageInfo) }
* The RawMessageHandler interface needs to be implemented to receive raw messages dispatched by the dispatcher. Raw messages are the raw protobuf structs instead of the easy-to-use structs in TextMessageHandler, ImageMessageHandler, etc..
type Session ¶
type Session struct { ClientId string ClientToken string ServerToken string EncKey []byte MacKey []byte Wid string }
Session contains session individual information. To be able to resume the connection without scanning the qr code every time you should save the Session returned by Login and use RestoreSession the next time you want to login. Every successful created connection returns a new Session. The Session(ClientToken, ServerToken) is altered after every re-login and should be saved every time.
type TextMessage ¶
type TextMessage struct { Info MessageInfo Text string }
TextMessage represents a text message.
type TextMessageHandler ¶
type TextMessageHandler interface { Handler HandleTextMessage(message TextMessage) }
The TextMessageHandler interface needs to be implemented to receive text messages dispatched by the dispatcher.
type VideoMessage ¶
type VideoMessage struct { Info MessageInfo Caption string Thumbnail []byte Length uint32 Type string Content io.Reader FileSha256 []byte FileLength uint64 // contains filtered or unexported fields }
VideoMessage represents a video message. Unexported fields are needed for media up/downloading and media validation. Provide a io.Reader as Content for message sending.
func (*VideoMessage) Download ¶
func (m *VideoMessage) Download() ([]byte, error)
Download is the function to retrieve media data. The media gets downloaded, validated and returned.
type VideoMessageHandler ¶
type VideoMessageHandler interface { Handler HandleVideoMessage(message VideoMessage) }
The VideoMessageHandler interface needs to be implemented to receive video messages dispatched by the dispatcher.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
crypto package contains cryptographic functions and servers as a support package for github.com/gleandroj/go-whatsapp.
|
crypto package contains cryptographic functions and servers as a support package for github.com/gleandroj/go-whatsapp. |
cbc
CBC describes a block cipher mode.
|
CBC describes a block cipher mode. |
curve25519
In cryptography, Curve25519 is an elliptic curve offering 128 bits of security and designed for use with the elliptic curve Diffie–Hellman (ECDH) key agreement scheme.
|
In cryptography, Curve25519 is an elliptic curve offering 128 bits of security and designed for use with the elliptic curve Diffie–Hellman (ECDH) key agreement scheme. |
hkdf
HKDF is a simple key derivation function (KDF) based on a hash-based message authentication code (HMAC).
|
HKDF is a simple key derivation function (KDF) based on a hash-based message authentication code (HMAC). |
examples
|
|
login
Module
|