PHP code example of silvanix / wablas

1. Go to this page and download the library: Download silvanix/wablas 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/ */

    

silvanix / wablas example snippets


        use Silvanix/Wablas/Device;

        $device = new Device();

        $info = $device->info();
        $restart = $device->restart();
        $disconnect = $device->disconnect();
        
        $url = 'https://www.mywebhook.com/webhook';
        $set = $device->set_webhook($url);
        
        $incoming = $device->incoming('active');
        //for now anything than 'active' = incoming message disable
  

        use Silvanix/Wablas/Check;

        $check = new Check();

        $phones ='08121211111,089888888,07812121212';
        $check_phone = $check->phone($phones);

  

        use Silvanix/Wablas/Message;

        $send = new Message();

        $phones ='08121211111,089888888,07812121212';
        $message = 'hello';
        $image = 'https://i.imgur.com/OB0y6MR.jpg';

        $send_text = $send->single_text($phones,$message);
        $send_image =  $send->single_image($phones,$image,$message);
        
        
        ///send OTP Message

        $code = '12213';
        $phone = '081212121221';
        
        $send_otp = $send->otp($phone,$code);
        
        $header = 'Verification Code';
        $content = "Your verifiction code : $code";
        $footer = "supported by Wablas"; // footer is optional
        
        $send_custom_otp = $send->custom_otp($phone,$code,$header,$content,$footer);

  

        use Silvanix/Wablas/Message;

        $send = new Message();

        $message_id ='sakdj798-lkasjndl-k8792173kjas';
        
        $resend = $send->again($message_id);
        $cancel = $send->cancel($message_id);
        $cancel_all = $send->cancel_all();
        $revoke = $send->revoke($message_id);
  
  

        use Silvanix/Wablas/Message;

        $send = new Message();

        $payload = [
          [
              'phone' => '6281229889541',
              'message' => 'Test Pesan 1',
          ],
          [
              'phone' => '6281229889541',
              'message' => 'Hello {name} Pesan with spintax',
              'spintax' => true,
              'source' => 'for personal'
          ],
          [
              'phone' => '6285867765107',
              'message' => 'Hello Pesan 3',
              'secret' => true,
          ],
          [
              'phone' => '6287817274185-1632192971',
              'message' => 'Test Group',
              'isGroup' => true,
              'source' => 'group personal'
          ],
       ];
      $send_text = $send->multiple_text($payload);
  
 

       $payload = [
            [
                'phone' => '6281229889541',
                'image' => 'https://cdn-asset.jawapos.com/wp-content/uploads/2019/01/keluarga-pawang-di-jepang-maafkan-macan-putih-yang-membunuhnya_m_.jpg',
                'caption' => 'caption here',
            ],
            [
                'phone' => '6287817274185-1632192971',
                'image' => 'https://farm4.staticflickr.com/3075/3168662394_7d7103de7d_z_d.jpg',
                'caption' => 'Image to group',
                'isGroup' => true,
            ],
        ];
 

          $payload = [
              [
                  'phone' => '6281229889541',
                  'audio' => 'https://prof3ssorst3v3.github.io/media-sample-files/jimmy-coffee.mp3',
                  'caption' => 'caption here',
              ],
              [
                  'phone' => '6287817274185-1632192971',
                  'audio' => 'https://prof3ssorst3v3.github.io/media-sample-files/jimmy-coffee.mp3',
                  'isGroup' => true,
              ],
          ];
 

        $payload = [
            [
                'phone' => '6281229889541',
                'video' => 'https://prof3ssorst3v3.github.io/media-sample-files/lion-sample.mp4',
                'caption' => 'this caption optional',
            ],
            [
                'phone' => '6287817274185-1632192971',
                'video' => 'https://prof3ssorst3v3.github.io/media-sample-files/lion-sample.mp4',
                 'caption' => 'Image to group',
                'isGroup' => true,
            ],
        ];
 

        $payload = [
            [
                'phone' => '6281229889541',
                'document' => 'https://africau.edu/images/default/sample.pdf',
            ],
            [
                'phone' => '6287817274185-1632192971',
                'document' => 'https://africau.edu/images/default/sample.pdf',
                'isGroup' => true,
            ],
      ];
      

         $payload = [
            [
               'phone' => '6285867765107',
                'message'=> [
                    'title' => [
                        'type' => 'text',
                        'content' => 'template text',
                    ],
                    'buttons' => [
                        'url' => [
                            'display' => 'wablas.com',
                            'link' => 'https://wablas.com',
                        ],
                        'call' => [
                            'display' => 'contact us',
                            'phone' => '081223644xxx',
                        ],
                        'quickReply' => ["reply 1","reply 2"],
                    ],
                    'content' => 'sending template message...',
                    'footer' => 'footer template here',
                ]
            ]
        ];  
      
   

         $payload = [
            [
                'phone' => '6285867765107',
                'message'=> [
                    'title' => 'Title Here',
                    'description' => 'This is template message',
                    'buttonText' => 'Opsi',
                    'lists' => [
                        [
                            'title' => 'List 1',
                            'description' => 'This is list 1',
                        ],
                        [
                            'title' => 'List 2',
                            'description' => 'This is list 2',
                        ],
                    ],
                    'footer' => 'Footer message here.',
                ],
            ]
        ];
      
    

        $payload = [
            [
                'phone' => '6285867765107',
                'message' => [
                    'name' => 'place name',
                    'address' => 'street name',
                    'latitude' => 24.121231,
                    'longitude' => 55.1121221,
                ],
            ]
        ];
      
  

      $payload = [
          [
              'phone' => '6285867765107',
              'message' => [
                  'buttons' => ["Reply 1","Reply 2","Reply 3"],
                  'content' => 'This is example button message',
                  'footer' => 'this is footer message',
              ],
          ]
      ];
      

        use Silvanix\Wablas\File;
        public function store(Request $request)
        {
            $file = $request->file('file');
            $upload = new File();
            $url = $upload->local_upload($file);
            echo $url;
        }
      

      ...
        Route::post('.../store', [App\Http\Controllers\SomeController::class, 'store'])->name('store');
      

      use Silvanix\Wablas\Schedule;
           
          $payload = [
              [
                  'category' => 'text',
                  'phone' => '6285867765107',
                  'scheduled_at' => '2022-09-22 09:46:30',
                  'text' => 'Hallo kakak',
              ]
          ];
          
          $shedule = new Schedule();
          $create = $schedule->new_message($payload);
  
        

        $payload = [
                [
                    'category' => 'image',
                    'phone' => '62812185122343',
                    'scheduled_at' => '2022-05-20 13:20:00',
                    'text' => 'Cover Novel',
                    'url' => ' https://solo.wablas.com/image/20220315081917.jpeg',
                ],
                [
                    'category' => 'template',
                    'phone' => '6281218567323',
                    'scheduled_at' => '2022-05-20 13:20:00',
                    'text' => [
                        'title' => [
                            'type' => 'image',
                            'content' => 'https://farm4.staticflickr.com/3075/3168662394_7d7103de7d_z_d.jpg',
                        ],
                        'buttons' => [
                            'url' => [
                                'display' => 'wablas.com',
                                'link' => 'https://wablas.com',
                            ],
                            'call' => [
                                'display' => 'contact us',
                                'link' => '081223644660',
                            ],
                            'quickReply' => ["reply 1","reply 2"],
                        ],
                        'content' => 'sending template message...',
                        'footer' => 'footer template here',
                    ],
                ],
                [
                    'category' => 'button',
                    'phone' => '62812112121212',
                    'scheduled_at' => '2022-05-20 13:20:00',
                    'text' => [
                        'buttons' => ["button 1","button 2","button 3"],
                        'content' => 'sending template message...',
                        'footer' => 'footer template here',
                    ],
                ],
            ];  
  
        

          use Silvanix\Wablas\Schedule;
          
          $shedule = new Schedule();
          
          $id = 'kajbdiuwe-8723yjhasbds-asdknasd8y';
          $cancel = $schedule->cancel($id);
          $delete = $schedule->delete($id);
  
        

        use Silvanix\Wablas\Message;

        public function store(Request $request)
        {
            $phones = $request->phones;
            $caption = $request->caption;
            $file = $request->file('file');
            $send = new Message();
            $test = $send->local_file($file,$phones,$caption);
            echo $test;
        }
  
        

      ...
      Route::post('.../store', [App\Http\Controllers\SomeController::class, 'store'])->name('store');
      
      

          use Silvanix\Wablas\Report;
          
          $report = new Report();
          $get_report = $report->real_time();
          echo $get_report;
          
          $data = [
            'message_id' => '71236812736812,8127368721', //Multiple Id separated by ID
            'page' => '2' // number page, data show per page is 10
          ];
          
          $get_report = $report->real_time($data);
          echo $get_report;
          

          use Silvanix\Wablas\Contact;
          
           $data =
            [
                [
                    'name' => 'Danu',
                    'phone' => '6285867765222'
                ],
                [
                    'name' => 'Karina Setya',
                    'phone' => '6285867765777',
                    'email' => '[email protected]',
                    'birth_day' => '1992-03-12',
                    'address' => 'Kedokan RT 02/ RW 04 Klego Boyolali',
                ],
                [
                    'name' => 'Danu',
                    'phone' => '6285867765222'
                ]
            ];
            
          $contact = new Contact();
          $response = $contact->create($data);
          
          echo $response;
       
          

          use Silvanix\Wablas\Contact;
          
          $phone ='081393971212';
          $contact = new Contact();
          $response = $contact->block($phone);
          
          echo $response;
       
          

          use Silvanix\Wablas\Contact;
          
          $phone ='081393971212';
          $contact = new Contact();
          $response = $contact->unblock($phone);
          
          echo $response;