This method allows retrieving up to 100 recent messages for a specific phone number or chat ID. The function is useful for analyzing communication history with a particular client, tracking communication context, and synchronizing data between WAMM.chat and external systems.
If you need to retrieve messages from all chats, use a separate method - Get Messages. There is also a WebHook mechanism that allows your system to receive messages and their statuses online, without API requests.
Supported Messengers
The API method for retrieving messages by number is available for the following messengers: WhatsApp, MAX Personal, Telegram Personal, Telegram Bot.
Request Example:
GET https://wamm.chat/api2/msg_get/{token}/?phone={phone}&col={count} or
GET https://wamm.chat/api2/msg_get/{token}/{phone}/{count} Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| token | string | Yes | API token obtained from settings |
| phone | string | Yes | Phone number in international format (e.g., 79001234567). For Telegram, you can specify a chat ID or nickname instead of a number; for MAX - chat ID |
| col | integer | Yes | Number of messages to retrieve (from 1 to 100) |
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 |
| phone fail | Phone number error |
Usage Examples
curl -X GET "https://wamm.chat/api2/msg_get/YOUR_TOKEN/?phone=79001234567&col=20"
function getMessagesByPhone($token, $phone, $count) {
// Prepare the request URL
$url = "https://wamm.chat/api2/msg_get/$token/?phone=$phone&col=$count";
// 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;
}
}
// Retrieve the last 20 messages from a specific number
$token = "YOUR_TOKEN";
$phone = "79001234567";
$messages = getMessagesByPhone($token, $phone, 20);