Rest API

Method POST & GET ( All support )
Type JSON
RESPONSE { status : boolean , msg : 'text' } (JSON)

Rest Api

<?php

                                                    $data = [
                                                        'api_key' => '{{Auth::user()->api_key}}',
                                                        'sender' => 'Sender',
                                                        'number' => 'receiver',
                                                        'message' => 'Your message'
                                                    ];
                                                    $curl = curl_init();
                                                    
                                                    curl_setopt_array($curl, array(
                                                      CURLOPT_URL => {{url('/')}}/send-message,
                                                      CURLOPT_RETURNTRANSFER => true,
                                                      CURLOPT_ENCODING => '',
                                                      CURLOPT_MAXREDIRS => 10,
                                                      CURLOPT_TIMEOUT => 0,
                                                      CURLOPT_FOLLOWLOCATION => true,
                                                      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                                      CURLOPT_CUSTOMREQUEST => 'POST',
                                                      CURLOPT_POSTFIELDS => json_encode($data),
                                                      CURLOPT_HTTPHEADER => array(
                                                        'Content-Type: application/json'
                                                      ),
                                                    ));
                                                    
                                                    $response = curl_exec($curl);
                                                    
                                                    curl_close($curl);
                                                    echo $response;
                                                    
                                                    ?>
<?php

                                                    $data = [
                                                        'api_key' => '{{Auth::user()->api_key}}',
                                                        'sender' => 'Sender',
                                                        'number' => 'receiver',
                                                        'message' => 'Your caption',
                                                        'url' => 'Url Media'
                                                        'type' => 'audio / video / image / pdf / xls /xlsx /doc /docx /zip'//Choose One
                                                    ];
                                                    $curl = curl_init();
                                                    
                                                    curl_setopt_array($curl, array(
                                                      CURLOPT_URL => {{url('/')}}/send-media,
                                                      CURLOPT_RETURNTRANSFER => true,
                                                      CURLOPT_ENCODING => '',
                                                      CURLOPT_MAXREDIRS => 10,
                                                      CURLOPT_TIMEOUT => 0,
                                                      CURLOPT_FOLLOWLOCATION => true,
                                                      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                                      CURLOPT_CUSTOMREQUEST => 'POST',
                                                      CURLOPT_POSTFIELDS => json_encode($data),
                                                      CURLOPT_HTTPHEADER => array(
                                                        'Content-Type: application/json'
                                                      ),
                                                    ));
                                                    
                                                    $response = curl_exec($curl);
                                                    
                                                    curl_close($curl);
                                                    echo $response;
                                                    
                                                    ?>
<?php

                                                    $data = [
                                                        'api_key' => '{{Auth::user()->api_key}}',
                                                        'sender' => 'Sender',
                                                        'number' => 'receiver',
                                                        'message' => 'Your message',
                                                        'footer' => 'Your footer message',
                                                        'image' => 'URL image ', //OPTIONAL
                                                        'button1' => 'Button 1 ', //REQUIRED ( Button minimal 1 )
                                                        'button2' => 'Button 2', //OPTIONAL
                                                        'button3' => 'Button 3',//OPTIONAL
                                                    ];
                                                    $curl = curl_init();
                                                    
                                                    curl_setopt_array($curl, array(
                                                      CURLOPT_URL => {{url('/')}}/send-button,
                                                      CURLOPT_RETURNTRANSFER => true,
                                                      CURLOPT_ENCODING => '',
                                                      CURLOPT_MAXREDIRS => 10,
                                                      CURLOPT_TIMEOUT => 0,
                                                      CURLOPT_FOLLOWLOCATION => true,
                                                      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                                      CURLOPT_CUSTOMREQUEST => 'POST',
                                                      CURLOPT_POSTFIELDS => json_encode($data),
                                                      CURLOPT_HTTPHEADER => array(
                                                        'Content-Type: application/json'
                                                      ),
                                                    ));
                                                    
                                                    $response = curl_exec($curl);
                                                    
                                                    curl_close($curl);
                                                    echo $response;
                                                    
                                                    ?>
<?php

    $data = [
        'api_key' => '{{Auth::user()->api_key}}',
        'sender' => 'Sender',
        'number' => 'receiver',
        'message' => 'Your message',
        'footer' => 'Your footer message',
        'image' => 'URL image ', //OPTIONAL
        'template1' => 'template 1 ', //REQUIRED ( template minimal 1 )
        'template2' => 'template 2', //OPTIONAL
        'template3' => 'template 3',//OPTIONAL
    ];
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => {{url('/')}}/send-template,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS => json_encode($data),
      CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    ?>
{{-- List Message --}}
<?php

    $data = [
        'api_key' => '{{Auth::user()->api_key}}',
        'sender' => 'Sender',
        'number' => 'receiver',
        'message' => 'Your message',
        'footer' => 'Your footer message',
        'name' => 'Name List ',
        'title' => 'Title List ',
        'list1' => 'list 1 ', //REQUIRED ( list minimal 1 )
        'list2' => 'list 2', //OPTIONAL
        'list3' => 'list 3',//OPTIONAL
        'list4' => 'list 4',//OPTIONAL
        'list5' => 'list 5',//OPTIONAL
    ];
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => {{url('/')}}/send-list,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS => json_encode($data),
      CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    ?>
{{-- Generate qr --}} {{-- List Message --}}
<?php

    //Type respon (json)
    // { "status" : "processing", "message" : "processing"  }
    // { "status" : true, "message" : "Already Connected"  }
    // { "status" : false, "qrcode" : "qr url",  "message" : "Please Scan qrcode"  }

    $data = [
        'api_key' => '{{Auth::user()->api_key}}',
        'number' => 'Number',//the number you want to connect, will be added to the database if it is not registered.
       
        ];
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => {{url('/')}}/generate-qr,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS => json_encode($data),
      CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo $response;
    
    ?>
{{-- end generate qr --}}
                                              
<?php 
 
 
 header('content-type: application/json');
 $data = json_decode(file_get_contents('php://input'), true);
 file_put_contents('whatsapp.txt', '[' . date('Y-m-d H:i:s') . "]\n" . json_encode($data) . "\n\n", FILE_APPEND);                                               
 $message = strtolower($data['message']);
 $from = strtolower($data['from']);
 $respon = false;
 
 // auto respond text   
 function sayHello(){    
 return ["text" => 'Halloooo!'];
             }
 
 // auto respond gambaar            
function gambar(){
 return [
     'image' => ['url' => 'https://seeklogo.com/images/W/whatsapp-logo-A5A7F17DC1-seeklogo.com.png'],
     'caption' => 'Logo whatsapp!'
 ];   
}
 
//auto respond button
 function button(){
     $buttons = [
         ['buttonId' => 'id1', 'buttonText' => ['displayText' => 'BUTTON 1'], 'type' => 1], // button 1 // 
         ['buttonId' => 'id2', 'buttonText' => ['displayText' => 'BUTTON 2'], 'type' => 1], // button 2
         ['buttonId' => 'id3', 'buttonText' => ['displayText' => 'BUTTON 3'], 'type' => 1], // button 3
     ];
     $buttonMessage = [
         'text' => 'HOLA, INI ADALAH PESAN BUTTON', 
         'footer' => 'ini pesan footer', 
         'buttons' => $buttons,
         'headerType' => 1 
     ];
     return $buttonMessage;
 }
 
 // auto respon lists
function lists(){
 $sections = [
        [ 
        	"title" => "This is List menu",
        	"rows" => [
	        ["title" => "List 1", "description" => "this is list one"],
	        ["title" => "List 2", "description" => "this is list two"],
    	] 
    ]
];
 
 $listMessage = [
  "text" => "This is a list",
  "title" => "Title Chat",
  "buttonText" => "Select what will you do?",
  "sections" => $sections
 ];
 
 return $listMessage;  
 }
 
 
 if($message === 'hai'){
     $respon = sayHello();
 } else if($message === 'gambar'){
     $respon = gambar();
 } else if($message === 'tes button'){
     $respon = button();
 } else if($message === 'lists msg'){
     $respon = lists();
 }
 echo json_encode($respon);
?>