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
ParameterTypeRequiredDescription
tokenstringYesAPI token obtained in the settings
colintegerYesNumber of messages to retrieve (from 1 to 100)
from_meintegerNoDirection 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
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

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);