This method allows you to retrieve up to 100 of the latest outgoing and incoming messages from your messenger. The function is useful for synchronizing data between WAMM.chat and your systems, as well as for creating reports and analytics on communications. You can filter messages by direction (incoming/outgoing). Execute the request regularly, for example every few minutes, to get the latest messages, and on your side, filter previously loaded messages by "Message ID".
If you need to get messages for a specific chat, use a separate method - Get messages by phone number. There is also a WebHook mechanism that allows you to receive messages and their statuses online in your system, without API requests.
Supported Messengers
The API method for getting messages is available for the following messengers: WhatsApp, MAX Personal, Telegram Personal, Telegram Bot.
Request Example:
GET https://wamm.chat/api2/msg_get_last/{token}/?col={count} or
GET https://wamm.chat/api2/msg_get_last/{token}/{count} Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | API token obtained in the settings |
| col | integer | Yes | Number of messages to retrieve (from 1 to 100) |
| from_me | integer | No | Direction filter: 1 - outgoing, 0 - incoming. If not specified, all messages are returned |
Success Response
{
"err": 0,
"msg_data": [
{
"msg_id": "1234567",
"from_me": "1",
"phone": "79001234567",
"chat_name": "Ivan Petrov",
"tip_msg": "textMessage",
"msg_text": "Good afternoon!",
"msg_link": null,
"date_ins": "2023-05-24 19:52:00",
"date_upd": "2023-05-24 19:52:22",
"state": "delivered"
},
{
"msg_id": "1234566",
"from_me": "0",
"phone": "79001234567",
"chat_name": "Ivan Petrov",
"tip_msg": "textMessage",
"msg_text": "Hello!",
"msg_link": null,
"date_ins": "2023-05-24 19:50:15",
"date_upd": "2023-05-24 19:50:15",
"state": "received"
}
]
} Response Field Description
| Field | Description |
|---|---|
| msg_id | Unique message identifier |
| from_me | Message direction: 0 - incoming, 1 - outgoing |
| phone | Contact's phone number. For Telegram, MAX - chat ID |
| phone_real | Phone/Nickname, if known, for Telegram, MAX, where phone is the chat ID |
| chat_name | Contact name or chat title |
| tip_msg | Message type: textMessage (text), documentMessage (file), imageMessage (image), audioMessage (voice/audio), videoMessage (video), location (location), file_link (file/image/voice) |
| msg_text | Message text |
| msg_link | Link to the file (if applicable) |
| date_ins | Date and time of sending/receiving |
| date_upd | Date and time of the last status update |
| state | Message status (sending, delivered, viewed, received, and others) |
Possible Errors
| Error Code | Description |
|---|---|
| token fail | Token error |
| acc not authorized | Connection not authorized |
| col fail or more 100 | Error in count or exceeds 100 |
| msgs not be | No messages found |
Usage Examples
curl -X GET "https://wamm.chat/api2/msg_get_last/YOUR_TOKEN/?col=20"
function getLastMessages($token, $count, $fromMe = null) {
// Prepare the request URL
$url = "https://wamm.chat/api2/msg_get_last/$token/?col=$count";
// Add the from_me parameter if specified
if ($fromMe !== null) {
$url .= "&from_me=$fromMe";
}
// Execute the request
$response = file_get_contents($url);
// Process the response
if ($response !== false) {
// Convert the response to an array
$json_response = json_decode($response, true);
// Check for errors
if (isset($json_response['err'])) {
if ($json_response['err'] == 0 && isset($json_response['msg_data'])) {
return $json_response['msg_data'];
} else {
echo "Error: " . $json_response['err'];
return false;
}
} else {
echo "Failed to process server response";
return false;
}
} else {
echo "Failed to execute request to server";
return false;
}
}
// Get 20 latest messages
$token = "YOUR_TOKEN";
$messages = getLastMessages($token, 20);
// Or only incoming messages
$incomingMessages = getLastMessages($token, 20, 0);