Current File : /home/inlingua/www/crm.vprotectindia.com/whatts-app-api/details.php
<?php
$token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwaG9uZU51bWJlciI6Iis5MTg0NDcxMjQ5NjYiLCJwaG9uZU51bWJlcklkIjoiMTM3NjUzNDQ5NDI4NTg4IiwiaWF0IjoxNjk1NzI5ODkxfQ.zouNW93K9Je56uNrDoyHqLWwrApcZbyUtsl88rpd7wo';
$apiBase = 'https://wb.omni.tatatelebusiness.com/whatsapp-cloud/messages';


function sendTextMessage($phone, $name, $email) {
    global $token, $apiBase;
    $body =[
  "to"=> $phone,
  "type"=> "template",
  "source"=> "external",
  "template"=> [
    "name"=> "welcome_note",
    "language"=> [
      "code"=> "en"
    ],
    "components"=> [
      [
        "type"=> "body",
        "parameters"=> [
          [
            "type"=> "text",
            "text"=> $name
          ],
          [
            "type"=> "text",
            "text"=> $email
          ]
        ]
      ]
    ]
  ],
  "metaData"=> [
    "custom_callback_data"=> "<optional_value>"
  ]
];
//echo '<pre>'; echo json_encode($body); exit;
    $ch = curl_init("$apiBase");
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            "Authorization:$token",
            "accept: application/json",
            "content-type: application/json; charset=utf-8 "
        ],
        CURLOPT_POSTFIELDS => json_encode($body)
    ]);
    $resp = curl_exec($ch);
    curl_close($ch);
    return json_decode($resp, true);
}

// Example usage
if(isset($_GET['mob']) && $_GET['mob'] !=''){
  
 $mob='91'.$_GET['mob']; 
} else {
  $mob='919643656504';
}  
  


$response = sendTextMessage(
    $mob, 
    'abdul', 
    'ansari@gmail.com');

print_r($response);

?>