WhatsApp PHP

Chat
in package

WhatsApp PHP Chat entity.

Tags
author

Gabriel Silva

license

MIT

Table of Contents

Properties

$date  : DateTime|string
Last message date.
$id  : string
Chat ID / number.
$isArchived  : bool
Is chat archived?
$isGroup  : bool
Is chat a group?
$isMuted  : bool
Is chat muted?
$isPinned  : bool
Is chat pinned?
$isReadonly  : bool
Is chat read-only?
$name  : string
Contact name.
$unreadMessages  : int
Number of unread messages.

Methods

__construct()  : mixed
Create Chat entity.
getMessages()  : array<string|int, Message>
Gets the messages from this chat.
getProfile()  : Profile|null
Gets the profile associated with this chat.
searchMessages()  : array<string|int, Message>
Searches for a message in this chat.
sendLocation()  : bool
Sends a location pin to this chat.
sendMedia()  : bool
Sends a media message to this chat.
sendMessage()  : bool
Sends a text message to this chat.
sendSticker()  : bool
Sends a sticker to this chat.
sendVoice()  : bool
Sends a voice message to this chat.

Properties

$date

Last message date.

public DateTime|string $date

$id

Chat ID / number.

public string $id

$isArchived

Is chat archived?

public bool $isArchived

$isGroup

Is chat a group?

public bool $isGroup

$isMuted

Is chat muted?

public bool $isMuted

$isPinned

Is chat pinned?

public bool $isPinned

$isReadonly

Is chat read-only?

public bool $isReadonly

$name

Contact name.

public string $name

$unreadMessages

Number of unread messages.

public int $unreadMessages

Methods

__construct()

Create Chat entity.

public __construct([array<string|int, mixed> $data = [] ]) : mixed
Parameters
$data : array<string|int, mixed> = []

(Optional) Associative array of data to populate.

getMessages()

Gets the messages from this chat.

public getMessages([int|null $limit = null ]) : array<string|int, Message>
Parameters
$limit : int|null = null

(Optional) Maximum number of messages to fetch. Leave blank to get as many as possible.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
array<string|int, Message>

Returns a list of messages.

getProfile()

Gets the profile associated with this chat.

public getProfile() : Profile|null
Tags
throws
RequestException

Throws an exception if the request fails.

Return values
Profile|null

Returns the profile if found.

searchMessages()

Searches for a message in this chat.

public searchMessages(string $query[, int|null $limit = null ][, int|null $page = null ]) : array<string|int, Message>
Parameters
$query : string

Query string to search.

$limit : int|null = null

(Optional) Maximum number of messages to fetch.

$page : int|null = null

(Optional) Results page number.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
array<string|int, Message>

Returns a list of messages.

sendLocation()

Sends a location pin to this chat.

public sendLocation(int $latitude, int $longitude[, string|null $address = null ][, string|null $url = null ]) : bool
Parameters
$latitude : int

Latitude coordinates.

$longitude : int

Longitude coordinates.

$address : string|null = null

(Optional) Address name to include in the message.

$url : string|null = null

(Optional) URL to include in the message.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
bool

Returns true on success, false on failure.

sendMedia()

Sends a media message to this chat.

public sendMedia(string $file[, string|null $message = null ][, bool $viewOnce = false ][, bool $asDocument = false ][, bool $asVoice = false ][, bool $asGif = false ][, bool $asSticker = false ]) : bool
Parameters
$file : string

File location path or remote URL.

$message : string|null = null

(Optional) Caption to send with the media.

$viewOnce : bool = false

(Optional) Send the media as view once.

$asDocument : bool = false

(Optional) Send the media as a document.

$asVoice : bool = false

(Optional) Send audio media as a voice.

$asGif : bool = false

(Optional) Send video media as a GIF.

$asSticker : bool = false

(Optional) Send image media as a sticker.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
bool

Returns true on success, false on failure.

sendMessage()

Sends a text message to this chat.

public sendMessage(string $message) : bool
Parameters
$message : string

Message body.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
bool

Returns true on success, false on failure.

sendSticker()

Sends a sticker to this chat.

public sendSticker(string $file) : bool
Parameters
$file : string

Sticker image file location path or remote URL.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
bool

Returns true on success, false on failure.

sendVoice()

Sends a voice message to this chat.

public sendVoice(string $file[, bool $viewOnce = false ]) : bool
Parameters
$file : string

Audio file location path or remote URL.

$viewOnce : bool = false

(Optional) Send the audio as view once.

Tags
throws
RequestException

Throws an exception if the request fails.

Return values
bool

Returns true on success, false on failure.


        
On this page

Search results