Rank 1: Thread
// Prepare and send the WhatsApp message $headers = [ "Content-Type" => "application/json", "Accept" => "application/json", ];
$data = [ "from" => $_ENV["VONAGE_WHATSAPP_NUMBER"], "to" => $body["from"], "message_type" => "text", "text" => 'Hi there! You sent me: ' . $body["text"], "channel" => "whatsapp", ];
$client = new Client(); $url = "https://messages-sandbox.nexmo.com/v1/messages";
try { $response = $client->post($url, [ "headers" => $headers, "json" => $data, "auth" => [ $_ENV["VONAGE_API_KEY"], $_ENV["VONAGE_API_SECRET"] ], ]);
if ($response->getStatusCode() === 200) { $result = json_decode($response->getBody(), true); return $context->res->json(["ok" => true]); } else { return $context->error("Error " . $response->getBody()); } } catch (Exception $e) { return $context->res->json(["ok" => false], 500); }};?>