Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Whatsapp

Hierarchy

  • Whatsapp

Index

Constructors

constructor

Events

onAck

  • onAck(fn: (message: Message) => void): void

onAddedToGroup

  • onAddedToGroup(fn: (chat: Chat) => any): Promise<void>
  • Parameters

    • fn: (chat: Chat) => any
        • Parameters

          Returns any

    Returns Promise<void>

    Observable stream of Chats

onAnyMessage

  • onAnyMessage(fn: (message: Message) => void): Promise<void>

onBattery

  • onBattery(fn: (battery: number) => void): Promise<void>
  • fires

    number

    Parameters

    • fn: (battery: number) => void

      callback

        • (battery: number): void
        • Parameters

          • battery: number

          Returns void

    Returns Promise<void>

onIncomingCall

  • onIncomingCall(fn: (call: any) => void): void
  • Parameters

    • fn: (call: any) => void
        • (call: any): void
        • Parameters

          • call: any

          Returns void

    Returns void

    Observable stream of call request objects

onLiveLocation

  • emits

    LiveLocationChangedEvent

    Parameters

    Returns Promise<any>

    boolean, if returns false then there were no valid live locations in the chat of chatId

onMessage

  • onMessage(fn: (message: Message) => void): void

onParticipantsChanged

onStateChanged

  • onStateChanged(fn: (state: string) => void): void
  • Parameters

    • fn: (state: string) => void
        • (state: string): void
        • Parameters

          • state: string

          Returns void

    Returns void

    Observable stream of messages

Properties

page

page: Page

Puppeteer Page running web.whatsapp.com

Methods

addLabel

  • addLabel(label: string, id: string): Promise<void>
  • Adds label from chat, message or contact. Only for business accounts.

    Parameters

    • label: string
    • id: string

      The Chat, message or contact id to which you want to add a label

    Returns Promise<void>

addParticipant

  • addParticipant(idGroup: string, idParticipant: string): Promise<void>
  • Add participant to Group

    Parameters

    • idGroup: string

      '0000000000-00000000@g.us'

    • idParticipant: string

      '000000000000@c.us'

    Returns Promise<void>

asyncLoadAllEarlierMessages

  • asyncLoadAllEarlierMessages(contactId: string): Promise<void>
  • Load all messages in chat object from server.

    Parameters

    • contactId: string

    Returns Promise<void>

    contact detial as promise

checkNumberStatus

  • checkNumberStatus(contactId: string): Promise<any>
  • Checks if a number is a valid whatsapp number

    Parameters

    • contactId: string

    Returns Promise<any>

    contact detial as promise

clearChat

  • clearChat(chatId: string): Promise<void>
  • Delete all messages from the chat.

    Parameters

    • chatId: string

    Returns Promise<void>

    boolean

contactBlock

  • contactBlock(id: string): Promise<void>
  • Block contact

    Parameters

    • id: string

      '000000000000@c.us'

    Returns Promise<void>

contactUnblock

  • contactUnblock(id: string): Promise<void>
  • Unblock contact

    Parameters

    • id: string

      '000000000000@c.us'

    Returns Promise<void>

createGroup

  • createGroup(groupName: string, contacts: string | string[]): Promise<any>
  • Sends a text message to given chat

    Parameters

    • groupName: string
    • contacts: string | string[]

    Returns Promise<any>

    Promise :

    {
      status: 200,
      gid: {
        server: 'g.us',
        user: '447777777777-1583678870',
        _serialized: '447777777777-1583678870@g.us'
      },
      participants: [
        { '447777777777@c.us': [Object] },
        { '447444444444@c.us': [Object] }
      ]
    }

deleteChat

  • deleteChat(chatId: string): Promise<boolean>
  • Delete the conversation from your whatsapp

    Parameters

    • chatId: string

    Returns Promise<boolean>

    boolean

deleteMessage

  • deleteMessage(contactId: string, messageId: string[] | string, onlyLocal?: boolean): Promise<any>
  • Deletes message of given message id

    Parameters

    • contactId: string

      The chat id from which to delete the message.

    • messageId: string[] | string

      The specific message id of the message to be deleted

    • Default value onlyLocal: boolean = false

      If it should only delete locally (message remains on the other recipienct's phone). Defaults to false.

    Returns Promise<any>

    nothing

demoteParticipant

  • demoteParticipant(idGroup: string, idParticipant: string): Promise<void>
  • Demote Admin of Group

    Parameters

    • idGroup: string

      '0000000000-00000000@g.us'

    • idParticipant: string

      '000000000000@c.us'

    Returns Promise<void>

forceRefocus

  • forceRefocus(): Promise<void>

forwardMessages

  • forwardMessages(to: string, messages: any, skipMyMessages: boolean): Promise<any>
  • Forward an array of messages to a specific chat using the message ids or Objects

    Parameters

    • to: string

      '000000000000@c.us'

    • messages: any

      this can be any mixture of message ids or message objects

    • skipMyMessages: boolean

      This indicates whether or not to skip your own messages from the array

    Returns Promise<any>

getAllChats

  • getAllChats(withNewMessageOnly?: boolean): Promise<any>
  • Retrieves all chats

    Parameters

    • Default value withNewMessageOnly: boolean = false

    Returns Promise<any>

    array of [Chat]

getAllChatsWithMessages

  • getAllChatsWithMessages(withNewMessageOnly?: boolean): Promise<any>
  • Retrieves all chats with messages

    Parameters

    • Default value withNewMessageOnly: boolean = false

    Returns Promise<any>

    array of [Chat]

getAllContacts

  • getAllContacts(): Promise<Contact[]>

getAllGroups

  • getAllGroups(withNewMessagesOnly?: boolean): Promise<any>
  • Retrieve all groups

    Parameters

    • Default value withNewMessagesOnly: boolean = false

    Returns Promise<any>

    array of groups

getAllMessagesInChat

  • getAllMessagesInChat(chatId: string, includeMe: boolean, includeNotifications: boolean): Promise<[Message]>
  • Retrieves all Messages in a chat

    Parameters

    • chatId: string
    • includeMe: boolean
    • includeNotifications: boolean

    Returns Promise<[Message]>

    any

getAllNewMessages

  • getAllNewMessages(): Promise<any>
  • Retrieves all new Messages. where isNewMsg==true

    Returns Promise<any>

    list of messages

getAllUnreadMessages

  • getAllUnreadMessages(): Promise<any>
  • Retrieves all unread Messages. where ack==-1

    Returns Promise<any>

    list of messages

getBatteryLevel

  • getBatteryLevel(): Promise<Number>

getBusinessProfilesProducts

  • getBusinessProfilesProducts(id: string): Promise<void>
  • Find any product listings of the given number. Use this to query a catalog

    Parameters

    • id: string

      id of buseinss profile (i.e the number with @c.us)

    Returns Promise<void>

    None

getChat

  • getChat(contactId: string): Promise<Chat>
  • Retrieves chat object of given contact id

    Parameters

    • contactId: string

    Returns Promise<Chat>

    contact detial as promise

getChatById

  • getChatById(contactId: string): Promise<Chat>
  • Retrieves chat object of given contact id

    Parameters

    • contactId: string

    Returns Promise<Chat>

    contact detial as promise

getConnectionState

  • getConnectionState(): Promise<any>
  • Returns the connecction state

    Returns Promise<any>

    Any of OPENING, PAIRING, UNPAIRED, UNPAIRED_IDLE, CONNECTED, TIMEOUT, CONFLICT, UNLAUNCHED, PROXYBLOCK, TOS_BLOCK, SMB_TOS_BLOCK, DEPRECATED_VERSION

getContact

  • getContact(contactId: string): Promise<Contact>
  • Retrieves contact detail object of given contact id

    Parameters

    • contactId: string

    Returns Promise<Contact>

    contact detial as promise

getGeneratedUserAgent

  • getGeneratedUserAgent(userA?: string): Promise<string>
  • Get the generated user agent, this is so you can send it to the decryption module.

    Parameters

    • Optional userA: string

    Returns Promise<string>

    String useragent of wa-web session

getGroupAdmins

  • getGroupAdmins(idGroup: string): Promise<Contact[]>
  • Get Admins of a Group

    Parameters

    • idGroup: string

      '0000000000-00000000@g.us'

    Returns Promise<Contact[]>

getGroupInviteLink

  • getGroupInviteLink(chatId: string): Promise<boolean>
  • Retreives an invite link for a group chat. returns false if chat is not a group.

    Parameters

    • chatId: string

    Returns Promise<boolean>

    Promise

getGroupMembers

  • getGroupMembers(groupId: string): Promise<Contact[]>

getGroupMembersId

  • getGroupMembersId(groupId: string): Promise<Id[]>
  • Retrieves group members as [Id] objects

    Parameters

    • groupId: string

      group id

    Returns Promise<Id[]>

getMe

  • getMe(): Promise<any>
  • Returns an object with all of your host device details

    Returns Promise<any>

getProfilePicFromServer

  • getProfilePicFromServer(chatId: string): Promise<any>
  • Retrieves chat picture

    Parameters

    • chatId: string

    Returns Promise<any>

    Url of the chat picture or undefined if there is no picture for the chat.

getStatus

  • getStatus(contactId: string): Promise<void>
  • Get the status of a contact

    Parameters

    • contactId: string

      to '000000000000@c.us' returns: {id: string,status: string}

    Returns Promise<void>

getUnreadMessages

  • getUnreadMessages(includeMe: boolean, includeNotifications: boolean, use_unread_count: boolean): Promise<any>
  • Retrieves all undread Messages

    Parameters

    • includeMe: boolean
    • includeNotifications: boolean
    • use_unread_count: boolean

    Returns Promise<any>

    any

getWAVersion

  • getWAVersion(): Promise<String>

isChatOnline

  • isChatOnline(chatId: string): Promise<boolean>
  • SChecks if a chat contact is online. Not entirely sure if this works with groups.

    Parameters

    Returns Promise<boolean>

isConnected

  • isConnected(): Promise<Boolean>
  • Retrieves if the phone is online. Please note that this may not be real time.

    Returns Promise<Boolean>

    Boolean

kill

  • kill(): Promise<boolean>

leaveGroup

  • leaveGroup(groupId: string): Promise<any>
  • Removes the host device from the group

    Parameters

    • groupId: string

      group id

    Returns Promise<any>

loadAllEarlierMessages

  • loadAllEarlierMessages(contactId: string): Promise<void>
  • Load all messages in chat object from server.

    Parameters

    • contactId: string

    Returns Promise<void>

    contact detial as promise

loadAndGetAllMessagesInChat

  • loadAndGetAllMessagesInChat(chatId: string, includeMe: boolean, includeNotifications: boolean): Promise<[Message]>
  • loads and Retrieves all Messages in a chat

    Parameters

    • chatId: string
    • includeMe: boolean
    • includeNotifications: boolean

    Returns Promise<[Message]>

    any

loadEarlierMessages

  • loadEarlierMessages(contactId: string): Promise<Message[]>
  • Load more messages in chat object from server. Use this in a while loop

    Parameters

    • contactId: string

    Returns Promise<Message[]>

    contact detial as promise

promoteParticipant

  • promoteParticipant(idGroup: string, idParticipant: string): Promise<void>
  • Promote Participant to Admin in Group

    Parameters

    • idGroup: string

      '0000000000-00000000@g.us'

    • idParticipant: string

      '000000000000@c.us'

    Returns Promise<void>

removeLabel

  • removeLabel(label: string, id: string): Promise<void>
  • Removes label from chat, message or contact. Only for business accounts.

    Parameters

    • label: string
    • id: string

      The Chat, message or contact id to which you want to add a label

    Returns Promise<void>

removeParticipant

  • removeParticipant(idGroup: string, idParticipant: string): Promise<void>
  • Remove participant of Group

    Parameters

    • idGroup: string

      '0000000000-00000000@g.us'

    • idParticipant: string

      '000000000000@c.us'

    Returns Promise<void>

reply

  • reply(to: string, content: string, quotedMsg: any): Promise<void>
  • Parameters

    • to: string

      string chatid

    • content: string

      string reply text

    • quotedMsg: any

      string | Message the msg object or id to reply to.

    Returns Promise<void>

revokeGroupInviteLink

  • revokeGroupInviteLink(chatId: string): Promise<string | false | true>
  • Revokes the current invite link for a group chat. Any previous links will stop working

    Parameters

    • chatId: string

    Returns Promise<string | false | true>

    Promise

sendContact

  • sendContact(to: string, contactId: string | string[]): Promise<any>
  • Sends contact card to given chat id

    Parameters

    • to: string

      'xxxx@c.us'

    • contactId: string | string[]

    Returns Promise<any>

sendFile

  • sendFile(to: string, base64: string, filename: string, caption: string): Promise<void>
  • Sends a file to given chat, with caption or not, using base64. This is exactly the same as sendImage

    Parameters

    • to: string

      chat id xxxxx@us.c

    • base64: string

      base64 data:image/xxx;base64,xxx

    • filename: string

      string xxxxx

    • caption: string

      string xxxxx

    Returns Promise<void>

sendGiphy

  • sendGiphy(to: string, giphyMediaUrl: string, caption: string): Promise<void>

sendImage

  • sendImage(to: string, base64: string, filename: string, caption: string): Promise<void>
  • Sends a image to given chat, with caption or not, using base64

    Parameters

    • to: string

      chat id xxxxx@us.c

    • base64: string

      base64 data:image/xxx;base64,xxx

    • filename: string

      string xxxxx

    • caption: string

      string xxxxx

    Returns Promise<void>

sendImageAsSticker

  • sendImageAsSticker(b64: string, to: string): Promise<false | void>
  • This function takes an image and sends it as a sticker to the recipient. This is helpful for sending semi-ephemeral things like QR codes. The advantage is that it will not show up in the recipients gallery. This function automatiicaly converts images to the required webp format.

    Parameters

    • b64: string
    • to: string

    Returns Promise<false | void>

sendImageWithProduct

  • sendImageWithProduct(to: string, base64: string, caption: string, bizNumber: string, productId: string): Promise<void>
  • Sends product with image to chat

    Parameters

    • to: string
    • base64: string
    • caption: string

      string the caption you want to add to this message

    • bizNumber: string

      string the @c.us number of the business account from which you want to grab the product

    • productId: string

      string the id of the product within the main catalog of the aforementioned business

    Returns Promise<void>

sendLocation

  • sendLocation(to: string, lat: any, lng: any, loc: string): Promise<void>
  • Sends a location message to given chat

    Parameters

    • to: string

      chat id: xxxxx@c.us

    • lat: any

      latitude: '51.5074'

    • lng: any

      longitude: '0.1278'

    • loc: string

      location text: 'LONDON!'

    Returns Promise<void>

sendMessageWithThumb

  • sendMessageWithThumb(thumb: string, url: string, title: string, description: string, chatId: string): Promise<void>
  • Parameters

    • thumb: string
    • url: string
    • title: string
    • description: string
    • chatId: string

    Returns Promise<void>

sendSeen

  • sendSeen(chatId: string): Promise<void>
  • Sets a chat status to seen. Marks all messages as ack: 3

    Parameters

    Returns Promise<void>

sendText

  • sendText(to: string, content: string): Promise<string>
  • Sends a text message to given chat

    Parameters

    • to: string

      chat id: xxxxx@us.c

    • content: string

      text message

    Returns Promise<string>

sendTextWithMentions

  • sendTextWithMentions(to: string, content: string): Promise<string>
  • Sends a text message to given chat that includes mentions. In order to use this method correctly you will need to send the text like this: "@4474747474747 how are you?" Basically, add a @ symbol before the number of the contact you want to mention.

    Parameters

    • to: string

      chat id: xxxxx@us.c

    • content: string

      text message

    Returns Promise<string>

sendVCard

  • sendVCard(chatId: string, vcard: string, contactName: string): Promise<void>
  • Send VCARD

    Parameters

    • chatId: string

      '000000000000@c.us'

    • vcard: string

      vcard as a string

    • contactName: string

      The display name for the contact. CANNOT BE NULL OTHERWISE IT WILL SEND SOME RANDOM CONTACT FROM YOUR ADDRESS BOOK.

    Returns Promise<void>

sendVideoAsGif

  • sendVideoAsGif(to: string, base64: string, filename: string, caption: string): Promise<void>
  • Sends a video to given chat as a gif, with caption or not, using base64

    Parameters

    • to: string

      chat id xxxxx@us.c

    • base64: string

      base64 data:video/xxx;base64,xxx

    • filename: string

      string xxxxx

    • caption: string

      string xxxxx

    Returns Promise<void>

setChatState

  • setChatState(chatState: ChatState, chatId: String): Promise<any>
  • Sets the chat state

    Parameters

    • chatState: ChatState

      The state you want to set for the chat. Can be TYPING (0), RECRDING (1) or PAUSED (2).

    • chatId: String

    Returns Promise<any>

setMyName

  • setMyName(newName: string): Promise<void>
  • Set your profile name

    Parameters

    • newName: string

      String new name to set for your profile

    Returns Promise<void>

setMyStatus

  • setMyStatus(newStatus: string): Promise<void>
  • set your about me

    Parameters

    • newStatus: string

      String new profile status

    Returns Promise<void>

setPresence

  • setPresence(available: boolean): Promise<void>
  • Set presence to available or unavailable.

    Parameters

    • available: boolean

      if true it will set your presence to 'online', false will set to unabailable (i.e no 'online' on recipients' phone);

    Returns Promise<void>

simulateTyping

  • simulateTyping(to: string, on: boolean): Promise<void>
  • Simulate '...typing' in chat

    Parameters

    • to: string

      'xxxx@c.us'

    • on: boolean

      turn on similated typing, false to turn it off you need to manually turn this off.

    Returns Promise<void>