Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

send excel file as base64 via using WhatsApp api with Ultramsg

I am trying to convert excel file to base64 to send WhatsApp API with Ultramsg :

<?php

require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to=""; 
$filename="test.xlsx"; 
$document = base64_encode(file_get_contents("test.xlsx"));
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);

But I see this error :

Array
(
    [error] => Array
        (
            [0] => Array
                (
                    [document] => file extension not supported
                )

        )

)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you need add MIME types for Microsoft Excel
.xls=application/vnd.ms-excel
or
.xlsx=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;

So , Try this code block and enjoy (: :

<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to=""; 
$filename="test.xlsx"; 
$document = base64_encode(file_get_contents("test.xlsx"));
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading