PHP

Build Quickly with Sample Codes

Sample Code In PHP

Below codes are just for your reference and we dont give any official support or customisation

PHP Sample Code for Handling Webhook Request & Giving Instant Reply

This code extracts the information from a webhook URL and give a reply back, please replace the values accordingly

<?php

/*Mobile number with country code from the message came, 
if the sender mobile number is saved in the phone contacts then instead of number the contact name will come here as number. 
For Whatsapp Group the number will be Group Name @Sender Name / Number */
$mobile_number = isset($_REQUEST['number']) ? $_REQUEST['number'] : 0;

/*Text message received in the application - only first 1000 characters will be pushed to the server.*/
$msg = isset($_REQUEST['message-in']) ? $_REQUEST['message-in'] : 0;

/*On which messaging app the message has received 1=Whatsapp Personal | 2 = Whatsapp Business*/
$application = isset($_REQUEST['application']) ? $_REQUEST['application'] : 0;

/*What kind of message is received , text=1, photo=2, video=3, audio=4, location=5, document=6, contact=7*/
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 0;

/*Unique id assigned by the picky assist application*/
$uniqueid = isset($_REQUEST['unique-id']) ? $_REQUEST['unique-id'] : 0;

if (!empty($mobile_number)) {
/*Reply should be in JSON format. The response parameters are : 
1. 'message-out' - Message you need to give it as reply.
2. 'delay' - If you would like to give response by setting a delay then please pass the delay value 
in “delay” variable , delay need to be set in seconds and maximum allowed delay is 3600 seconds 
i.e delay=10 means message will send after 10 seconds
*/

/*Giving Reply should be in JSON*/
$data = array('message-out' => ' Hello Picky','delay' => 0);

echo json_encode($data);
}
?>

Sample Broadcast API Code in PHP

Below is the sample broadcast API code is PHP, please replace the JSON data with your own data and submit

<?php

    //--API PARAMETERS ENCODED AS JSON--
    $JSON_DATA = '{"token":"API_TOKEN_XXXXXXX","priority ":0,"application":"1","sleep":0,"globalmessage":"test","globalmedia":"","data":[{"number":"MOBILE_NUMBER_1_WITH_COUNTRY_CODE","message":""},{"number":"MOBILE_NUMBER_2_WITH_COUNTRY_CODE","message":""}]}';
  

    //--CURL FUNCTION TO CALL THE API--
    $url = 'https://pickyassist.com/app/api/v2/push';

    $ch = curl_init($url);                                                                      
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $JSON_DATA);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($JSON_DATA))                                                                       
    );                                                                                                                   
                                                                                                                            
    $result = curl_exec($ch);

    //--API RESPONSE--
    print_r( json_decode($result,true) );


?>

Last updated