<?php
namespace App\Helpers;
use App\Models\Transaction; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Http; use Log; use stdClass;
class WhatsappHelper { private $client;
public function __construct()
{
$this->client = Http::withToken(env('WHATSAPP_API_TOKEN'));
}
public function message($template, $phone, $headerParameters, $bodyParameters)
{
$payload = [
"messaging_product" => "whatsapp",
"recipient_type" => "individual",
"to" => $phone,
"type" => "template",
"template" => [
"name" => $template,
"language" => [
"code" => "pt_BR",
],
"components" => [
[
"type" => "header",
"parameters" => $headerParameters
],
[
"type" => "body",
"parameters" => $bodyParameters
]
]
]
];
$this->client->post(env('WHATSAPP_API_URL') . 'messages', $payload);
}
}
dentro da cron rodo isso; (new WhatsappHelper)->message('agendamentos', $appointment->patient->PatientUser->prefix_code ? $appointment->patient->PatientUser->prefix_code : '55' . $appointment->patient->PatientUser->cell_phone, $headerParameters, $bodyParameters);
e no meu env tenho os tokens WHATSAPP_API_TOKEN= WHATSAPP_API_URL=