Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WAConnection

Hierarchy

  • Base
    • WAConnection

Index

Constructors

constructor

Properties

autoReconnect

autoReconnect: ReconnectMode = ...

When to auto-reconnect

blocklist

blocklist: string[] = ...

browserDescription

browserDescription: [string, string, string] = ...

The Browser we're telling the WhatsApp Web servers we are

chatOrderingKey

chatOrderingKey: { compare: (k1: string, k2: string) => number; key: (c: WAChat) => string } = ...

key to use to order chats

Type declaration

  • compare: (k1: string, k2: string) => number
      • (k1: string, k2: string): number
      • Parameters

        • k1: string
        • k2: string

        Returns number

  • key: (c: WAChat) => string

chats

chats: default<WAChat, string> = ...

connectOptions

connectOptions: WAConnectOptions = ...

contacts

contacts: {} = ...

Type declaration

lastChatsReceived

lastChatsReceived: Date

loadProfilePicturesForChatsAutomatically

loadProfilePicturesForChatsAutomatically: boolean = true

logger

logger: Logger = ...

maxCachedMessages

maxCachedMessages: number = 50

messageLog

messageLog: { binaryTags?: any[]; fromMe: boolean; json: string; tag: string }[] = ...

pendingRequestTimeoutMs

pendingRequestTimeoutMs: number = null

Should requests be queued when the connection breaks in between; if 0, then an error will be thrown

phoneConnected

phoneConnected: boolean = false

Whether the phone is connected

shouldLogMessages

shouldLogMessages: boolean = false

log messages

state

state: WAConnectionState = 'close'

The connection state

user

user: WAUser

Metadata like WhatsApp id, name set on WhatsApp etc.

version

version: [number, number, number] = ...

The version of WhatsApp Web we're telling the servers we are

Methods

base64EncodedAuthInfo

  • base64EncodedAuthInfo(): { clientID: string; clientToken: string; encKey: string; macKey: string; serverToken: string }
  • base 64 encode the authentication credentials and return them these can then be used to login again by passing the object to the connect () function.

    see

    connect () in WhatsAppWeb.Session

    Returns { clientID: string; clientToken: string; encKey: string; macKey: string; serverToken: string }

    • clientID: string
    • clientToken: string
    • encKey: string
    • macKey: string
    • serverToken: string

blockUser

  • blockUser(jid: string, type?: "add" | "remove"): Promise<{ status: number }>
  • Add or remove user from blocklist

    Parameters

    • jid: string

      the ID of the person who you are blocking/unblocking

    • type: "add" | "remove" = 'add'

      type of operation

    Returns Promise<{ status: number }>

canLogin

  • canLogin(): boolean

chatRead

  • chatRead(jid: string, type?: "read" | "unread"): Promise<void>
  • Marks a chat as read/unread; updates the chat object too

    Parameters

    • jid: string

      the ID of the person/group whose message you want to mark read

    • type: "read" | "unread" = 'read'

    Returns Promise<void>

clearAuthInfo

clearMessage

  • clearMessage(messageKey: IMessageKey): Promise<{ status: number }>

close

  • close(): void

connect

deleteChat

  • deleteChat(jid: string): Promise<{ status: number }>

deleteMessage

downloadAndSaveMediaMessage

  • downloadAndSaveMediaMessage(message: WebMessageInfo, filename: string, attachExtension?: boolean): Promise<string>
  • Securely downloads the media from the message and saves to a file. Renews the download url automatically, if necessary.

    Parameters

    • message: WebMessageInfo

      the media message you want to decode

    • filename: string

      the name of the file where the media will be saved

    • attachExtension: boolean = true

      should the parsed extension be applied automatically to the file

    Returns Promise<string>

downloadMediaMessage

emit

  • emit(event: string, ...args: any[]): boolean

fetchGroupMetadataFromWA

fetchMessagesFromWA

  • fetchMessagesFromWA(jid: string, count: number, indexMessage?: { fromMe?: boolean; id?: string }, mostRecentFirst?: boolean): Promise<WebMessageInfo[]>

findMessage

  • findMessage(jid: string, chunkSize: number, onMessage: (m: WebMessageInfo) => boolean): Promise<void>

forwardMessage

generateForwardMessageContent

generateLinkPreview

generateMessageTag

  • generateMessageTag(longTag?: boolean): string

getBroadcastListInfo

getChats

  • getChats(): Promise<any>

getContacts

  • getContacts(): Promise<any>

getProfilePicture

  • getProfilePicture(jid: string): Promise<string>

getStatus

  • getStatus(jid?: string): Promise<{ status: string }>
  • Query the status of the person (see groupMetadata() for groups)

    Parameters

    • Optional jid: string

    Returns Promise<{ status: string }>

getStories

  • getStories(): Promise<{ count: number; messages: WebMessageInfo[]; unread: number }[]>

groupAdd

groupCreate

groupDemoteAdmin

groupInviteCode

  • groupInviteCode(jid: string): Promise<string>

groupLeave

  • groupLeave(jid: string): Promise<{ status: number }>

groupMakeAdmin

groupMetadata

groupMetadataMinimal

groupQuery

  • groupQuery(type: string, jid?: string, subject?: string, participants?: string[], additionalNodes?: Node[]): Promise<{ status: number }>
  • Generic function for group queries

    Parameters

    • type: string
    • Optional jid: string
    • Optional subject: string
    • Optional participants: string[]
    • Optional additionalNodes: Node[]

    Returns Promise<{ status: number }>

groupRemove

groupSettingChange

  • groupSettingChange(jid: string, setting: GroupSettingChange, onlyAdmins: boolean): Promise<{ status: number }>

groupUpdateDescription

  • groupUpdateDescription(jid: string, description: string): Promise<{ status: number }>
  • Update the group description

    Parameters

    • jid: string

      the ID of the group

    • description: string

    Returns Promise<{ status: number }>

groupUpdateSubject

  • groupUpdateSubject(jid: string, title: string): Promise<{ status: number }>
  • Update the subject of the group

    Parameters

    • jid: string

      the ID of the group

    • title: string

      the new title of the group

    Returns Promise<{ status: number }>

isOnWhatsApp

  • isOnWhatsApp(str: string): Promise<{ exists: boolean; jid: string }>
  • Query whether a given number is registered on WhatsApp

    Parameters

    • str: string

      phone number/jid you want to check for

    Returns Promise<{ exists: boolean; jid: string }>

    undefined if the number doesn't exists, otherwise the correctly formatted jid

isOnWhatsAppNoConn

  • isOnWhatsAppNoConn(str: string): Promise<{ exists: boolean; jid: string }>
  • Query whether a given number is registered on WhatsApp, without needing to open a WS connection

    Parameters

    • str: string

      phone number/jid you want to check for

    Returns Promise<{ exists: boolean; jid: string }>

    undefined if the number doesn't exists, otherwise the correctly formatted jid

loadAllMessages

  • loadAllMessages(jid: string, onMessage: (m: WebMessageInfo) => void | Promise<void>, chunkSize?: number, mostRecentFirst?: boolean): Promise<void>
  • Load the entire friggin conversation with a group or person

    Parameters

    • jid: string
    • onMessage: (m: WebMessageInfo) => void | Promise<void>

      callback for every message retreived

    • chunkSize: number = 25

      the number of messages to load in a single request

    • mostRecentFirst: boolean = true

      retreive the most recent message first or retreive from the converation start

    Returns Promise<void>

loadAllUnreadMessages

loadAuthInfo

loadChats

  • loadChats(count: number, before: string, options?: WALoadChatOptions): Promise<{ chats: WAChat[]; cursor: string }>
  • Load chats in a paginated manner + gets the profile picture

    Parameters

    • count: number

      number of results to return

    • before: string

      chats before the given cursor

    • options: WALoadChatOptions = ...

    Returns Promise<{ chats: WAChat[]; cursor: string }>

    the chats & the cursor to fetch the next page

loadMessage

loadMessages

  • loadMessages(jid: string, count: number, cursor?: { fromMe?: boolean; id?: string }, mostRecentFirst?: boolean): Promise<{ cursor: { fromMe?: boolean; id?: string }; messages: WebMessageInfo[] }>
  • Load the conversation with a group or person

    Parameters

    • jid: string
    • count: number

      the number of messages to load

    • Optional cursor: { fromMe?: boolean; id?: string }

      the data for which message to offset the query by

      • Optional fromMe?: boolean
      • Optional id?: string
    • mostRecentFirst: boolean = true

      retreive the most recent message first or retreive from the converation start

    Returns Promise<{ cursor: { fromMe?: boolean; id?: string }; messages: WebMessageInfo[] }>

logout

  • logout(): Promise<void>
  • Disconnect from the phone. Your auth credentials become invalid after sending a disconnect request.

    see

    close() if you just want to close the connection

    Returns Promise<void>

messageInfo

  • messageInfo(jid: string, messageID: string): Promise<MessageInfo>

messagesReceivedAfter

  • messagesReceivedAfter(date: Date, onlyUnrespondedMessages?: boolean): Promise<WebMessageInfo[]>

modifyChat

  • modifyChat(jid: string, type: clear, includeStarred?: boolean): Promise<{ status: number }>
  • modifyChat(jid: string, type: pin | mute, durationMs: number): Promise<{ status: number }>
  • modifyChat(jid: string, type: "archive" | "clear" | "delete" | "unarchive" | "mute" | archive | unarchive | pin | unpin | mute | unmute | delete | clear | "pin" | "unpin" | "unmute"): Promise<{ status: number }>
  • Clear the chat messages

    Parameters

    • jid: string

      the ID of the person/group you are modifiying

    • type: clear
    • Optional includeStarred: boolean

      delete starred messages, default false

    Returns Promise<{ status: number }>

  • Modify a given chat (archive, pin etc.)

    Parameters

    • jid: string

      the ID of the person/group you are modifiying

    • type: pin | mute
    • durationMs: number

      only for muting, how long to mute the chat for

    Returns Promise<{ status: number }>

  • Modify a given chat (archive, pin etc.)

    Parameters

    Returns Promise<{ status: number }>

on

prepareDisappearingMessageSettingContent

  • prepareDisappearingMessageSettingContent(ephemeralExpiration?: number): Message

prepareMessage

prepareMessageContent

prepareMessageFromContent

prepareMessageMedia

query

relayWAMessage

  • relayWAMessage(message: WebMessageInfo, __namedParameters?: { waitForAck: boolean }): Promise<void>
  • Relay (send) a WAMessage; more advanced functionality to send a built WA Message, you may want to stick with sendMessage()

    Parameters

    • message: WebMessageInfo
    • __namedParameters: { waitForAck: boolean } = ...
      • waitForAck: boolean

    Returns Promise<void>

requestNewQRCodeRef

requestPresenceUpdate

  • requestPresenceUpdate(jid: string): Promise<any>

searchMessages

  • searchMessages(txt: string, inJid: string, count: number, page: number): Promise<{ last: boolean; messages: WebMessageInfo[] }>
  • Search WhatsApp messages with a given text string

    Parameters

    • txt: string

      the search string

    • inJid: string

      the ID of the chat to search in, set to null to search all chats

    • count: number

      number of results to return

    • page: number

      page number of results (starts from 1)

    Returns Promise<{ last: boolean; messages: WebMessageInfo[] }>

sendMessage

sendPostConnectQueries

  • sendPostConnectQueries(): void

sendReadReceipt

  • sendReadReceipt(jid: string, messageKey: IMessageKey, count: number): Promise<{ status: number }>
  • Sends a read receipt for a given message; does not update the chat do @see chatRead

    deprecated

    just use chatRead()

    Parameters

    • jid: string

      the ID of the person/group whose message you want to mark read

    • messageKey: IMessageKey

      the key of the message

    • count: number

      number of messages to read, set to < 0 to unread a message

    Returns Promise<{ status: number }>

setQuery

  • setQuery(nodes: Node[], binaryTags?: WATag, tag?: string): Promise<{ status: number }>

setStatus

  • setStatus(status: string): Promise<{ status: number }>

starMessage

  • starMessage(messageKey: IMessageKey, type?: "star" | "unstar"): Promise<{ status: number }>

toggleDisappearingMessages

  • toggleDisappearingMessages(jid: string, ephemeralExpiration?: number, opts?: { waitForAck: boolean }): Promise<WebMessageInfo>
  • Toggles disappearing messages for the given chat

    Parameters

    • jid: string

      the chat to toggle

    • Optional ephemeralExpiration: number

      0 to disable, enter any positive number to enable disappearing messages for the specified duration; For the default see WA_DEFAULT_EPHEMERAL

    • opts: { waitForAck: boolean } = ...
      • waitForAck: boolean

    Returns Promise<WebMessageInfo>

unexpectedDisconnect

updateMediaMessage

  • Fetches the latest url & media key for the given message. You may need to call this when the message is old & the content is deleted off of the WA servers

    Parameters

    Returns Promise<void>

updatePresence

  • updatePresence(jid: string, type: Presence): Promise<string>
  • Tell someone about your presence -- online, typing, offline etc.

    Parameters

    • jid: string

      the ID of the person/group who you are updating

    • type: Presence

      your presence

    Returns Promise<string>

updateProfileName

  • updateProfileName(name: string): Promise<{ pushname: string; status: number }>

updateProfilePicture

waitForMessage

  • waitForMessage(tag: string, requiresPhoneConnection: boolean, timeoutMs?: number): Promise<any>
  • Wait for a message with a certain tag to be received

    Parameters

    • tag: string

      the message tag to await

    • requiresPhoneConnection: boolean
    • Optional timeoutMs: number

      timeout after which the promise will reject

    Returns Promise<any>

Generated using TypeDoc