Class: Chat

Chat()

Represents a Chat on WhatsApp

Constructor

new Chat()

Source:

Extends

Members

archived :boolean

Indicates if the Chat is archived

Type:
  • boolean
Source:

id :object

ID that represents the chat

Type:
  • object
Source:

isGroup :boolean

Indicates if the Chat is a Group Chat

Type:
  • boolean
Source:

isLocked :boolean

Indicates if the Chat is locked

Type:
  • boolean
Source:

isMuted :boolean

Indicates if the chat is muted or not

Type:
  • boolean
Source:

isReadOnly :boolean

Indicates if the Chat is readonly

Type:
  • boolean
Source:

lastMessage :Message

Last message fo chat

Type:
Source:

muteExpiration :number

Unix timestamp for when the mute expires

Type:
  • number
Source:

name :string

Title of the chat

Type:
  • string
Source:

pinned :boolean

Indicates if the Chat is pinned

Type:
  • boolean
Source:

timestamp :number

Unix timestamp for when the last activity occurred

Type:
  • number
Source:

unreadCount :number

Amount of messages unread

Type:
  • number
Source:

Methods

(async) addOrEditCustomerNote(note) → {Promise.<void>}

Add or edit a customer note

Parameters:
Name Type Description
note string

The note to add Customer notes are available only to eligible WhatsApp Business accounts.

Source:
See:
Returns:
Type
Promise.<void>

(async) archive()

Archives this chat

Source:

(async) changeLabels(labelIds) → {Promise.<void>}

Add or remove labels to this Chat

Parameters:
Name Type Description
labelIds Array.<(number|string)>
Source:
Returns:
Type
Promise.<void>

(async) clearMessages() → {Promise.<boolean>}

Clears all messages from the chat

Source:
Returns:

result

Type
Promise.<boolean>

(async) clearState()

Stops typing or recording in chat immediately.

Source:

(async) delete() → {Promise.<Boolean>}

Deletes the chat

Source:
Returns:

result

Type
Promise.<Boolean>

(async) fetchMessages(searchOptions) → {Promise.<Array.<Message>>}

Loads chat messages, sorted from earliest to latest.

Parameters:
Name Type Description
searchOptions Object

Options for searching messages. Right now only limit and fromMe is supported.

Properties
Name Type Attributes Description
limit Number <optional>

The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.

fromMe Boolean <optional>

Return only messages from the bot number or vise versa. To get all messages, leave the option undefined.

Source:
Returns:
Type
Promise.<Array.<Message>>

(async) getContact() → {Promise.<Contact>}

Returns the Contact that corresponds to this Chat.

Source:
Returns:
Type
Promise.<Contact>

(async) getCustomerNote() → {Promise.<({chatId: string, content: string, createdAt: number, id: string, modifiedAt: number, type: string}|null)>}

Get a customer note

Source:
See:
Returns:

Null when customer notes are unavailable for the account or this is a group/channel.

Type
Promise.<({chatId: string, content: string, createdAt: number, id: string, modifiedAt: number, type: string}|null)>

(async) getLabels() → {Promise.<Array.<Label>>}

Returns array of all Labels assigned to this Chat

Source:
Returns:
Type
Promise.<Array.<Label>>

(async) getPinnedMessages() → {Promise.<Array.<Message>>}

Gets instances of all pinned messages in a chat

Source:
Returns:
Type
Promise.<Array.<Message>>

(async) markUnread()

Mark this chat as unread

Source:

(async) mute(unmuteDatenullable) → {Promise.<{isMuted: boolean, muteExpiration: number}>}

Mutes this chat forever, unless a date is specified

Parameters:
Name Type Attributes Description
unmuteDate Date <nullable>

Date when the chat will be unmuted, don't provide a value to mute forever

Source:
Returns:
Type
Promise.<{isMuted: boolean, muteExpiration: number}>

(async) pin() → {Promise.<boolean>}

Pins this chat

Source:
Returns:

New pin state. Could be false if the max number of pinned chats was reached.

Type
Promise.<boolean>

(async) sendMessage(content, optionsopt) → {Promise.<(Message|null|undefined)>}

Send a message to this chat

Parameters:
Name Type Attributes Description
content string | MessageMedia | Location
options MessageSendOptions <optional>
Source:
Returns:

Message that was just sent

Type
Promise.<(Message|null|undefined)>

(async) sendSeen() → {Promise.<Boolean>}

Sets the chat as seen

Source:
Returns:

result

Type
Promise.<Boolean>

(async) sendStateRecording()

Simulate recording audio in chat. This will last for 25 seconds.

Source:

(async) sendStateTyping()

Simulate typing in chat. This will last for 25 seconds.

Source:

(async) syncHistory() → {Promise.<boolean>}

Sync chat history conversation

Source:
Returns:

True if operation completed successfully, false otherwise.

Type
Promise.<boolean>

(async) unarchive()

un-archives this chat

Source:

(async) unmute() → {Promise.<{isMuted: boolean, muteExpiration: number}>}

Unmutes this chat

Source:
Returns:
Type
Promise.<{isMuted: boolean, muteExpiration: number}>

(async) unpin() → {Promise.<boolean>}

Unpins this chat

Source:
Returns:

New pin state

Type
Promise.<boolean>