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
| 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 username instead of a number; for MAX - a chat ID |
| quote_msg_id | integer | No | ID of the message being replied to (GET) |
| file_name | string | Yes | Name of the file being transmitted (in the POST request body) |
| file_base64 | string | Yes | File body in BASE64 encoding (in the POST request body) |
Success Response
{"err":0,"msg_id":1234567} Possible Errors
| Error Code | Description |
|---|---|
| token fail | Token error |
| acc not authorized | WhatsApp connection is not authorized |
| phone fail | Phone number error |
| no WhatsApp on the number | No WhatsApp associated with this number |
| phone not checked for WhatsApp, please retry | Number not checked for WhatsApp presence |
| url fail | Empty link or missing http/https in the link |
| quote_msg_id fail, not found | Message 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);