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
ParameterTypeRequiredDescription
tokenstringYesAPI token obtained from settings
phonestringYesPhone 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
colintegerYesNumber 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
FieldDescription
msg_idUnique message identifier
from_meMessage direction: 0 - incoming, 1 - outgoing
phoneContact's phone number. For Telegram, MAX - chat ID
phone_realPhone/Nickname, if known, for Telegram, MAX, where phone is the chat ID
chat_nameContact name or chat title
tip_msgMessage type: textMessage (text), documentMessage (file), imageMessage (image), audioMessage (voice/audio), videoMessage (video), location (location), file_link (file/image/voice)
msg_textMessage text
msg_linkLink to the file (if applicable)
date_insDate and time of sending/receiving
date_updDate and time of the last status update
stateMessage status (sending, delivered, viewed, received, and others)

Possible Errors
Error CodeDescription
token failToken error
acc not authorizedConnection not authorized
col fail or more 100Error in count or exceeds 100
msgs not beNo messages found
phone failPhone 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);