PHP code example of beedelivery / client-php-api-wa-me

1. Go to this page and download the library: Download beedelivery/client-php-api-wa-me library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beedelivery / client-php-api-wa-me example snippets



use Api\Wame\WhatsApp;

tsApp(
    ["server" => "API server", 
    "key" => "Your Key Instance"]
    );

    $whatsapp->constructWebhook();
    $whatsapp->from->remoteJid; //  number that sent message
    $whatsapp->from->messageType; // video | text | audio| image | sticker | document| reaction | liveLocation | 
    $whatsapp->from->msgId;
    $whatsapp->from->pushName;
    $whatsapp->from->text; 

if ($whatsapp->from->messageType === "text" && $whatsapp->from->text === "Hi") {
  $whatsapp->sendText($whatsapp->from->remoteJid, "Hello!");
}

echo $whatsapp->getQrCodeHTML();

echo $whatsapp->getQrCodeBase64();

echo $whatsapp->inforInstance();

$body = [
        "allowWebhook" => false,
        "webhookMessage" => "",
        "webhookGroup" => "",
        "webhookConnection" => "",
        "webhookQrCode" => "", 
        "webhookMessageFromMe"=>"", 
        "webhookHistory"=>""
    ]; 
echo $whatsapp->updateWebhook($body);

echo $whatsapp->logout();

echo $whatsapp->listContacts();

echo $whatsapp->profilePic('556696852025');

echo $whatsapp->updateProfileName('Raphael Serafim');

$url =''; // url image 
$id  ='556696852025'; // if it's a group, use full id ex: [email protected] 
echo $whatsapp->updateProfilePicture($id, $url);

$MsgId ='';  
$to  ='556696852025'; // if it's a group, use full id ex: [email protected] 
echo $whatsapp->readReceipt($to, $MsgId);

  $body = [
    "messageKeys" => [
        "mediaKey" => "", 
        "directPath" => "", 
        "url" => "", 
        "messageType" => "" 
    ] 
  ];
echo $whatsapp->downloadMediaMessage($body);

 $to     = '556696852025'; // if it's a group, use full id ex: [email protected]  
 $status = 'composing';   // unavailable | available | composing | recording | paused
echo $whatsapp->sendPresence($to, $status);

 $to     = '556696852025'; // if it's a group, use full id ex: [email protected]  
 $text   = 'Hi';   
echo $whatsapp->sendText($to, $text);

 $to     = '556696852025'; // if it's a group, use full id ex: [email protected]  
 $url    = ''; // your MP3 or OGG audio URL    
 $ptt    = true;
echo $whatsapp->sendAudio($to, $url, $ptt  );
 
$to         = '556696852025'; // if it's a group, use full id ex: [email protected]  
$url        = '';
$type       = 'image'; //  image |  video | audio | document
$caption    = 'Hi';  
echo $whatsapp->sendMedia($to, $url, $type, $caption);

    $body = [
        "to" => "556696852025",
        "data" => [
            "text" => "Recebeu ?",
            "buttons" => [
                [
                    "title" => "Sim",
                    "id" => "1"
                ],
                [
                    "title" => "Não",
                    "id" => "2"
                ]
            ],
            "footerText" => "Escolha uma opção"
        ]
    ];
echo $whatsapp->sendButton($body);

    $body = [
        "to" => "556696852025",
        "data" => [
            "text" => "Finalizar a compra",
            "buttons" => [
                [
                    "type" => "urlButton", // replyButton | urlButton | callButton 
                    "title" => "Pagar",
                    "payload" => "https://api-wa.me"
                ]
            ],
            "footerText" => "Visite o site para finalizar"
        ]
    ];
echo $whatsapp->sendTemplateButtons($body);

    $body = [
        "messageData" => [
            "to" => "556696852025",
            "buttonText" => "Menu",
            "text" => "Esse nosso menu",
            "title" => "Menu",
            "description" => "veja nosso menu",
            "sections" => [
                [
                    "title" => "Menu 01",
                    "rows" => [
                        [
                            "title" => "Opção 01",
                            "description" => "essa é uma opção",
                            "rowId" => "1"
                        ],
                        [
                            "title" => "Opção 02",
                            "description" => "essa é outra opção",
                            "rowId" => "2"
                        ]
                    ]
                ]
            ],
            "listType" => 0
        ]
    ];
echo $whatsapp->sendList($body);

 $to     = '556696852025'; // if it's a group, use full id ex: [email protected]  
 $name   = 'CACHE SISTEMAS';   
 $number = '+556696883327';
echo $whatsapp->sendContact($to, $name, $number);

 $to     = '556696852025'; // if it's a group, use full id ex: [email protected]  
 $lat    = 35.000;   
 $lon    = 20.000;
 $address = 'Rua do fulando';
echo $whatsapp->sendLocation($to, $lat, $lon, $address);

 $to     = '556696852025'; // if it's a group, use full id ex: [email protected]  
 $text   =  '😘';   
 $msgId  =  '';
echo $whatsapp->sendReaction($to, $text, $msgId);
 
   echo $whatsapp->listGroup();
 
   $group_id = '[email protected]'; 
   echo $whatsapp->inforGroup($group_id);
 
   $group_id = '[email protected]'; 
   echo $whatsapp->groupInviteCode($group_id);
 
   $name = 'API PHP WhatsApp'; 
   $participants = ['556696852025'];
   echo $whatsapp->createGroup($name, $participants);
 
   $group_id     = '[email protected]'; 
   $participants = ['556696852025'];
   echo $whatsapp->addParticipantsGroup($group_id, $participants);
 
   $group_id     = '[email protected]'; 
   $participants = ['556696852025'];
   echo $whatsapp->promoteParticipantsGroup($group_id, $participants);
 
   $group_id     = '[email protected]'; 
   $participants = ['556696852025'];
   echo $whatsapp->demoteParticipantsGroup($group_id, $participants);
 
   $group_id     = '[email protected]'; 
   // true = Admin; false= All 
   echo $whatsapp->setWhoCanSendMessageGroup($group_id, true);
 
   $group_id     = '[email protected]'; 
   // true = Admin; false= All 
   echo $whatsapp->setWhoCanChangeSettingsGroup($group_id, true);
 
   $group_id     = '[email protected]'; 
   $participants = ['556696852025'];
   echo $whatsapp->removeParticipantsGroup($group_id, $participants);
 
   $group_id     = '[email protected]'; 
   echo $whatsapp->leaveGroup($group_id);