This method allows sending a file to a recipient via a specified communication channel without the need to provide a public link. The file is transmitted in the request in BASE64 format. This is particularly convenient when you cannot or do not want to make the file publicly accessible but need to send it via a messenger.


Supported Messengers

The API method for sending files in BASE64 is available for the following messengers: WhatsApp, MAX Personal, Telegram Personal, Telegram Bot.


Request Example:

POST https://wamm.chat/api2/file_from_base64/{token}/?phone={phone}

or

POST https://wamm.chat/api2/file_from_base64/{token}/{phone}

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 username instead of a number; for MAX - a chat ID
quote_msg_idintegerNoID of the message being replied to (GET)
file_namestringYesName of the file being transmitted (in the POST request body)
file_base64stringYesFile body in BASE64 encoding (in the POST request body)

Success Response
{"err":0,"msg_id":1234567}

Possible Errors
Error CodeDescription
token failToken error
acc not authorizedWhatsApp connection is not authorized
phone failPhone number error
no WhatsApp on the numberNo WhatsApp associated with this number
phone not checked for WhatsApp, please retryNumber not checked for WhatsApp presence
url failEmpty link or missing http/https in the link
quote_msg_id fail, not foundMessage for reply not found

Usage Examples
curl -X POST -d "file_name=example.pdf&file_base64=BASE64_ENCODED_FILE_CONTENT" "https://wamm.chat/api2/file_from_base64/YOUR_TOKEN/?phone=79001234567"

function sendFileBase64($token, $phone, $fileName, $filePath) {
    // Read the file and convert it to BASE64
    $fileContent = file_get_contents($filePath);
    $fileBase64 = base64_encode($fileContent);
    
    // Prepare the request URL
    $url = "https://wamm.chat/api2/file_from_base64/$token/?phone=$phone";
    
    // Prepare the request data
    $postData = [
        'file_name' => $fileName,
        'file_base64' => $fileBase64
    ];
    
    // Configure cURL
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    // Execute the request
    $response = curl_exec($ch);
    curl_close($ch);
    
    // 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_id'])) {
                echo "File sent successfully, message ID: " . $json_response['msg_id'];
            } else {
                echo "Error: " . $json_response['err'];
            }
        } else {
            echo "Failed to process server response";
        }
    } else {
        echo "Failed to execute request to server";
    }
}

// Use the function to send a file
$token = "YOUR_TOKEN";
$phone = "79001234567";
$fileName = "document.pdf";
$filePath = "/path/to/document.pdf";

sendFileBase64($token, $phone, $fileName, $filePath);