{"id":1165,"date":"2026-11-04T16:01:00","date_gmt":"2026-11-04T16:01:00","guid":{"rendered":"https:\/\/vectalk.com.br\/blog\/whatsapp-api-php-laravel\/"},"modified":"2026-11-04T16:01:07","modified_gmt":"2026-11-04T16:01:07","slug":"whatsapp-api-php-laravel","status":"publish","type":"post","link":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/","title":{"rendered":"WhatsApp API with PHP and Laravel: sending messages and webhooks from scratch"},"content":{"rendered":"\n<p><em>Updated on November 4, 2026<\/em><\/p>\n\n\n\n<p>To use the official WhatsApp Business API with PHP and Laravel you need two pieces: a service that <code>POST<\/code>s to the <code>\/&lt;PHONE_NUMBER_ID&gt;\/messages<\/code> endpoint using Laravel&#8217;s HTTP client and a Bearer token, and a webhook route that answers Meta&#8217;s <code>GET<\/code> verification, validates the <code>X-Hub-Signature-256<\/code> header and returns <code>200<\/code> fast, leaving the actual processing to a queue. This tutorial builds both from scratch, with complete code.<\/p>\n\n\n\n<p>The code targets Laravel 13 (the version of the official docs on November 4, 2026) and Meta&#8217;s Cloud API. At the end, we show what changes if you use Vectalk.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What you&#8217;ll build<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-text\">Customer on WhatsApp\n      \u2502 message\n      \u25bc\nMeta (Cloud API) \u2500\u2500POST + X-Hub-Signature-256\u2500\u2500\u25b6 \/api\/webhook\/whatsapp\n                                                     \u2502 validate signature\n                                                     \u2502 return 200\n                                                     \u25bc\n                                              queue (jobs)\n                                                     \u2502 dedupe by wamid\n                                                     \u25bc\n                                       ProcessWhatsAppWebhook\n                                                     \u2502 reply\n                                                     \u25bc\n                                  WhatsAppService \u2500\u2500POST \/messages\u2500\u2500\u25b6 Meta<\/code><\/pre>\n\n\n\n<p>Files we&#8217;ll create or edit:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>File<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>.env<\/code> and <code>config\/services.php<\/code><\/td><td>Credentials and base URL<\/td><\/tr><tr><td><code>app\/Services\/WhatsAppService.php<\/code><\/td><td>Sending messages with retries<\/td><\/tr><tr><td><code>routes\/api.php<\/code><\/td><td>Webhook <code>GET<\/code> and <code>POST<\/code> routes<\/td><\/tr><tr><td><code>app\/Http\/Middleware\/VerifyWhatsAppSignature.php<\/code><\/td><td>HMAC validation<\/td><\/tr><tr><td><code>app\/Http\/Controllers\/WhatsAppWebhookController.php<\/code><\/td><td>Verification and intake<\/td><\/tr><tr><td><code>app\/Jobs\/ProcessWhatsAppWebhook.php<\/code><\/td><td>Queued processing<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Meta app with the WhatsApp product, a phone number registered on the Cloud API, and an access token. For production, use a system user token (see <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-permanent-access-token\/\">permanent access token<\/a>).<\/li>\n\n\n<li>The app&#8217;s <strong>Phone Number ID<\/strong> and <strong>App Secret<\/strong>. Both are in your Meta app dashboard.<\/li>\n\n\n<li>A Laravel project with a database configured (the queue will use the <code>database<\/code> driver, the default for new apps).<\/li>\n\n\n<li>A public HTTPS URL for the webhook. In development, use a tunnel such as ngrok (<a href=\"https:\/\/vectalk.com.br\/blog\/en\/test-whatsapp-webhook-locally\/\">test the webhook locally<\/a>).<\/li>\n\n<\/ul>\n\n\n\n<p>If you&#8217;re still deciding between integrating directly with Meta or going through a provider, start with the <a href=\"https:\/\/vectalk.com.br\/blog\/en\/official-whatsapp-api\/\">official WhatsApp API guide<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Configuration<\/h2>\n\n\n\n<p>In <code>.env<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">WHATSAPP_BASE_URL=https:\/\/graph.facebook.com\/v26.0\nWHATSAPP_PHONE_NUMBER_ID=106540352242922\nWHATSAPP_TOKEN=EAAJB...\nWHATSAPP_APP_SECRET=your_app_secret\nWHATSAPP_VERIFY_TOKEN=a_long_random_string\nQUEUE_CONNECTION=database<\/code><\/pre>\n\n\n\n<p>In <code>config\/services.php<\/code>, add:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">'whatsapp' =&gt; [\n    'base_url' =&gt; env('WHATSAPP_BASE_URL', 'https:\/\/graph.facebook.com\/v26.0'),\n    'phone_number_id' =&gt; env('WHATSAPP_PHONE_NUMBER_ID'),\n    'token' =&gt; env('WHATSAPP_TOKEN'),\n    'app_secret' =&gt; env('WHATSAPP_APP_SECRET'),\n    'verify_token' =&gt; env('WHATSAPP_VERIFY_TOKEN'),\n],<\/code><\/pre>\n\n\n\n<p>Always read <code>config('services.whatsapp.*')<\/code> in your code, never <code>env()<\/code> directly. According to the <a href=\"https:\/\/laravel.com\/docs\/configuration\" target=\"_blank\" rel=\"noreferrer noopener\">configuration docs<\/a>, once the config is cached the <code>.env<\/code> file isn&#8217;t loaded, and <code>env()<\/code> only returns system-level variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. A sending service with retries<\/h2>\n\n\n\n<p>Laravel ships an HTTP client built on Guzzle. The methods used below (<code>withToken<\/code>, <code>acceptJson<\/code>, <code>timeout<\/code>, <code>retry<\/code>, <code>throw<\/code>) are in the <a href=\"https:\/\/laravel.com\/docs\/http-client\" target=\"_blank\" rel=\"noreferrer noopener\">HTTP Client docs<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">&lt;?php\n\nnamespace App\\Services;\n\nuse Illuminate\\Http\\Client\\ConnectionException;\nuse Illuminate\\Http\\Client\\PendingRequest;\nuse Illuminate\\Http\\Client\\RequestException;\nuse Illuminate\\Support\\Facades\\Http;\nuse Throwable;\n\nclass WhatsAppService\n{\n    private function client(): PendingRequest\n    {\n        $cfg = config('services.whatsapp');\n\n        return Http::baseUrl($cfg['base_url'])\n            -&gt;withToken($cfg['token'])\n            -&gt;acceptJson()\n            -&gt;timeout(15)\n            -&gt;retry(3, fn (int $attempt) =&gt; $attempt * 1000, function (Throwable $e, PendingRequest $request) {\n                \/\/ Retry only on network errors, 429 (rate limit) and 5xx.\n                if ($e instanceof ConnectionException) {\n                    return true;\n                }\n\n                return $e instanceof RequestException\n                    &amp;&amp; ($e-&gt;response-&gt;status() === 429 || $e-&gt;response-&gt;serverError());\n            });\n    }\n\n    public function send(array $payload): array\n    {\n        $phoneId = config('services.whatsapp.phone_number_id');\n\n        return $this-&gt;client()\n            -&gt;post(\"\/{$phoneId}\/messages\", ['messaging_product' =&gt; 'whatsapp'] + $payload)\n            -&gt;throw()\n            -&gt;json();\n    }\n\n    public function sendText(string $to, string $body, ?string $replyTo = null): array\n    {\n        $payload = ['to' =&gt; $to, 'type' =&gt; 'text', 'text' =&gt; ['body' =&gt; $body]];\n\n        if ($replyTo) {\n            $payload['context'] = ['message_id' =&gt; $replyTo];\n        }\n\n        return $this-&gt;send($payload);\n    }\n\n    public function sendTemplate(string $to, string $name, string $lang, array $bodyParams = []): array\n    {\n        $components = [];\n\n        if ($bodyParams) {\n            $components[] = [\n                'type' =&gt; 'body',\n                'parameters' =&gt; array_map(fn ($v) =&gt; ['type' =&gt; 'text', 'text' =&gt; (string) $v], $bodyParams),\n            ];\n        }\n\n        return $this-&gt;send([\n            'to' =&gt; $to,\n            'type' =&gt; 'template',\n            'template' =&gt; ['name' =&gt; $name, 'language' =&gt; ['code' =&gt; $lang], 'components' =&gt; $components],\n        ]);\n    }\n\n    public function markAsRead(string $messageId, bool $typing = false): array\n    {\n        $payload = ['status' =&gt; 'read', 'message_id' =&gt; $messageId];\n\n        if ($typing) {\n            $payload['typing_indicator'] = ['type' =&gt; 'text'];\n        }\n\n        return $this-&gt;send($payload);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Key points:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Retry only where it helps.<\/strong> 400-level errors (bad parameter, missing template) won&#8217;t improve on a second try. Retrying only 429 and 5xx avoids duplicate messages caused by logic errors.<\/li>\n\n\n<li><strong>Growing backoff.<\/strong> The second argument to <code>retry<\/code> is a closure returning the wait in milliseconds (1 s, 2 s&#8230;). At high volume, tune it to your number&#8217;s throughput (error 131056 signals a rate limit).<\/li>\n\n\n<li><strong><code>throw()<\/code><\/strong> turns 4xx\/5xx into a <code>RequestException<\/code>, with Meta&#8217;s response available in <code>$e-&gt;response-&gt;json()<\/code> for logging.<\/li>\n\n<\/ul>\n\n\n\n<p>To test sending from Tinker:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">app(\\App\\Services\\WhatsAppService::class)\n    -&gt;sendTemplate('16505551234', 'hello_world', 'en_US');<\/code><\/pre>\n\n\n\n<p>Outside the 24-hour window, only approved templates are delivered, and the first contact with a customer must always be a template. The JSON for templates with variables, media and buttons is in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/send-whatsapp-template-message-api\/\">how to send a template message via the API<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Webhook routes<\/h2>\n\n\n\n<p>Enable API routes (this command creates <code>routes\/api.php<\/code>):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">php artisan install:api<\/code><\/pre>\n\n\n\n<p>According to the <a href=\"https:\/\/laravel.com\/docs\/routing\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel routing docs<\/a>, routes in <code>routes\/api.php<\/code> are stateless, get the <code>\/api<\/code> prefix and belong to the <code>api<\/code> middleware group, without the CSRF protection of the <code>web<\/code> group. That&#8217;s exactly what a webhook needs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">&lt;?php\n\nuse App\\Http\\Controllers\\WhatsAppWebhookController;\nuse App\\Http\\Middleware\\VerifyWhatsAppSignature;\nuse Illuminate\\Support\\Facades\\Route;\n\nRoute::get('\/webhook\/whatsapp', [WhatsAppWebhookController::class, 'verify']);\n\nRoute::post('\/webhook\/whatsapp', [WhatsAppWebhookController::class, 'receive'])\n    -&gt;middleware(VerifyWhatsAppSignature::class);<\/code><\/pre>\n\n\n\n<p>The final URL is <code>https:\/\/your-domain.com\/api\/webhook\/whatsapp<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. GET verification (hub.challenge)<\/h2>\n\n\n\n<p>When you configure the webhook in the app dashboard, Meta sends a <code>GET<\/code> with <code>hub.mode=subscribe<\/code>, <code>hub.challenge<\/code> and <code>hub.verify_token<\/code>. If the token matches, you return <code>200<\/code> with the <code>hub.challenge<\/code> value; otherwise, anything other than <code>200<\/code> (<a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">Create a webhook endpoint<\/a>).<\/p>\n\n\n\n<p>Here&#8217;s the PHP gotcha: the <a href=\"https:\/\/www.php.net\/manual\/en\/language.variables.external.php\" target=\"_blank\" rel=\"noreferrer noopener\">PHP manual<\/a> states that dots in incoming variable names are converted to underscores. So <code>hub.mode<\/code> arrives as <code>hub_mode<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">&lt;?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Jobs\\ProcessWhatsAppWebhook;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Http\\Response;\n\nclass WhatsAppWebhookController extends Controller\n{\n    public function verify(Request $request): Response\n    {\n        \/\/ PHP turns \"hub.mode\" into \"hub_mode\"\n        $mode = $request-&gt;query('hub_mode');\n        $token = $request-&gt;query('hub_verify_token');\n        $challenge = $request-&gt;query('hub_challenge');\n\n        if ($mode === 'subscribe' &amp;&amp; hash_equals((string) config('services.whatsapp.verify_token'), (string) $token)) {\n            return response((string) $challenge, 200)-&gt;header('Content-Type', 'text\/plain');\n        }\n\n        return response('forbidden', 403);\n    }\n\n    public function receive(Request $request): Response\n    {\n        ProcessWhatsAppWebhook::dispatch($request-&gt;json()-&gt;all());\n\n        return response('', 200);\n    }\n}<\/code><\/pre>\n\n\n\n<p>The <code>receive<\/code> method doesn&#8217;t process anything: it queues the payload and responds. Responding quickly is what prevents retries and event backlogs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Validating X-Hub-Signature-256<\/h2>\n\n\n\n<p>Every <code>POST<\/code> from Meta carries an <code>X-Hub-Signature-256: sha256=&lt;hash&gt;<\/code> header. The hash is an HMAC-SHA256 of the <strong>raw request body<\/strong>, keyed with your App Secret. You recompute it and compare; if it doesn&#8217;t match, reject the request.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">php artisan make:middleware VerifyWhatsAppSignature<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">&lt;?php\n\nnamespace App\\Http\\Middleware;\n\nuse Closure;\nuse Illuminate\\Http\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass VerifyWhatsAppSignature\n{\n    public function handle(Request $request, Closure $next): Response\n    {\n        $secret = (string) config('services.whatsapp.app_secret');\n        $header = (string) $request-&gt;header('X-Hub-Signature-256', '');\n\n        \/\/ Use the raw body: re-serializing the JSON changes bytes and breaks the hash.\n        $expected = 'sha256=' . hash_hmac('sha256', $request-&gt;getContent(), $secret);\n\n        if ($secret === '' || ! hash_equals($expected, $header)) {\n            abort(401, 'invalid signature');\n        }\n\n        return $next($request);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Three common mistakes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Computing the HMAC over <code>json_encode($request-&gt;all())<\/code> instead of <code>getContent()<\/code>. Any difference in whitespace, key order or slash escaping changes the hash.<\/li>\n\n\n<li>Using <code>==<\/code> instead of <code>hash_equals<\/code>, which compares in constant time.<\/li>\n\n\n<li>Using the access token as the key. The key is the <strong>App Secret<\/strong> of the app that signs the webhooks.<\/li>\n\n<\/ul>\n\n\n\n<p>The same steps in other languages are in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-signature-validation\/\">how to validate the webhook signature<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Processing job with deduplication<\/h2>\n\n\n\n<p>Meta retries a failed <code>POST<\/code> immediately, then a few more times with decreasing frequency for up to 7 days, and asks your server to handle duplicates. Events may also arrive batched, with up to 1,000 updates per request. That&#8217;s why the job walks every entry and dedupes on the message <code>id<\/code> (the <code>wamid<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">php artisan make:job ProcessWhatsAppWebhook<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">&lt;?php\n\nnamespace App\\Jobs;\n\nuse App\\Services\\WhatsAppService;\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\nuse Illuminate\\Foundation\\Queue\\Queueable;\nuse Illuminate\\Queue\\Attributes\\Tries;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Illuminate\\Support\\Facades\\Log;\n\n#[Tries(5)]\nclass ProcessWhatsAppWebhook implements ShouldQueue\n{\n    use Queueable;\n\n    public function __construct(public array $payload) {}\n\n    public function handle(WhatsAppService $wa): void\n    {\n        foreach ($this-&gt;payload['entry'] ?? [] as $entry) {\n            foreach ($entry['changes'] ?? [] as $change) {\n                if (($change['field'] ?? null) !== 'messages') {\n                    continue;\n                }\n\n                $value = $change['value'] ?? [];\n\n                foreach ($value['messages'] ?? [] as $msg) {\n                    \/\/ Cache::add is atomic: only the first delivery gets through.\n                    if (! Cache::add('wa:msg:' . $msg['id'], 1, 60 * 60 * 24 * 7)) {\n                        continue;\n                    }\n                    $this-&gt;handleMessage($wa, $msg);\n                }\n\n                foreach ($value['statuses'] ?? [] as $status) {\n                    Log::info('whatsapp.status', [\n                        'id' =&gt; $status['id'],\n                        'status' =&gt; $status['status'],\n                        'errors' =&gt; $status['errors'] ?? null,\n                    ]);\n                }\n            }\n        }\n    }\n\n    private function handleMessage(WhatsAppService $wa, array $msg): void\n    {\n        $wa-&gt;markAsRead($msg['id'], typing: true);\n\n        $reply = match ($msg['type']) {\n            'text' =&gt; 'Got it: \"' . mb_substr($msg['text']['body'], 0, 200) . '\". We\\'ll help you shortly.',\n            'image', 'document' =&gt; 'File received, thanks!',\n            default =&gt; 'Message received.',\n        };\n\n        $wa-&gt;sendText($msg['from'], $reply, replyTo: $msg['id']);\n    }\n}<\/code><\/pre>\n\n\n\n<p>Details:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Cache::add<\/code> only writes if the key doesn&#8217;t exist and, per the <a href=\"https:\/\/laravel.com\/docs\/cache\" target=\"_blank\" rel=\"noreferrer noopener\">cache docs<\/a>, it&#8217;s atomic. We keep the key for 7 days, matching Meta&#8217;s retry window. In production, prefer storing the <code>wamid<\/code> in the database with a unique index, alongside the raw payload.<\/li>\n\n\n<li>Statuses (<code>sent<\/code>, <code>delivered<\/code>, <code>read<\/code>, <code>failed<\/code>) arrive in the same <code>messages<\/code> field, in the <code>statuses<\/code> array. They can arrive out of order; treat each as an independent event (<a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-message-status-webhook\/\">message status webhooks<\/a>).<\/li>\n\n\n<li>The <code>#[Tries(5)]<\/code> attribute sets how many times the job is attempted, per the <a href=\"https:\/\/laravel.com\/docs\/queues\" target=\"_blank\" rel=\"noreferrer noopener\">queues docs<\/a>. If a reply fails after the message was marked as processed, it won&#8217;t be retried; if that matters, move <code>Cache::add<\/code> after the send or use a table with state.<\/li>\n\n<\/ul>\n\n\n\n<p>Run the worker:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">php artisan queue:work --tries=3 --timeout=30<\/code><\/pre>\n\n\n\n<p>In production, keep the worker under a process supervisor.<\/p>\n\n\n\n<p>The full architecture (queues, retries, status ordering and raw payload storage) is covered in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-integration-architecture\/\">WhatsApp API integration architecture<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">7. Test locally<\/h2>\n\n\n\n<p>GET verification:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">curl \"http:\/\/localhost:8000\/api\/webhook\/whatsapp?hub.mode=subscribe&amp;hub.verify_token=a_long_random_string&amp;hub.challenge=12345\"<\/code><\/pre>\n\n\n\n<p>The response should be just <code>12345<\/code>.<\/p>\n\n\n\n<p>A signed POST, simulating Meta:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-bash\">BODY='{\"object\":\"whatsapp_business_account\",\"entry\":[{\"id\":\"0\",\"changes\":[{\"field\":\"messages\",\"value\":{\"messages\":[{\"from\":\"16505551234\",\"id\":\"wamid.TEST1\",\"timestamp\":\"1762250400\",\"type\":\"text\",\"text\":{\"body\":\"hi\"}}]}}]}]}'\nSIG=$(printf '%s' \"$BODY\" | openssl dgst -sha256 -hmac \"your_app_secret\" | sed 's\/^.* \/\/')\ncurl -X POST http:\/\/localhost:8000\/api\/webhook\/whatsapp \\\n  -H \"Content-Type: application\/json\" \\\n  -H \"X-Hub-Signature-256: sha256=$SIG\" \\\n  -d \"$BODY\"<\/code><\/pre>\n\n\n\n<p>With the tunnel running, set the public URL and verify token in <strong>App Dashboard &gt; WhatsApp &gt; Configuration<\/strong> and subscribe to the <code>messages<\/code> field. If nothing arrives, check the field subscription, the public URL and the worker logs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common problems<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>Meta says the callback URL couldn&#8217;t be verified<\/td><td>Reading <code>hub.challenge<\/code> instead of <code>hub_challenge<\/code>, or returning HTML<\/td><td>Use <code>hub_*<\/code> and return plain text with status 200<\/td><\/tr><tr><td>419 on POST<\/td><td>Route defined in <code>routes\/web.php<\/code> (CSRF)<\/td><td>Move it to <code>routes\/api.php<\/code><\/td><\/tr><tr><td>401 on every POST<\/td><td>HMAC computed over re-serialized JSON or with the wrong key<\/td><td>Use <code>getContent()<\/code> and the App Secret<\/td><\/tr><tr><td>Messages answered twice<\/td><td>No dedup by <code>wamid<\/code><\/td><td>Use <code>Cache::add<\/code> or a unique index<\/td><\/tr><tr><td>Slow webhook that gets retried<\/td><td>Processing inside the controller<\/td><td>Dispatch the job and return 200<\/td><\/tr><tr><td><code>env()<\/code> returns <code>null<\/code> in production<\/td><td>Cached config<\/td><td>Read from <code>config('services.whatsapp')<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to do this with Vectalk<\/h2>\n\n\n\n<p>Vectalk is a proxy for the official Cloud API: payloads are identical. To reuse the same <code>WhatsAppService<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set <code>WHATSAPP_BASE_URL<\/code> to <code>https:\/\/apis.vectalk.com.br\/api<\/code> and use the token generated under <strong>Settings \u2192 API Tokens<\/strong> in the dashboard (<a href=\"https:\/\/docs.vectalk.com.br\/authentication\">authentication<\/a>, in Portuguese).<\/li>\n\n\n<li>Sending goes to <code>POST \/messages<\/code> (no Phone Number ID in the URL). With an instance token the number is resolved automatically; with an organization token, include <code>phone_number_id<\/code> in the body. Adjust the <code>post()<\/code> line in the service.<\/li>\n\n\n<li>The webhook is registered via the API (<a href=\"https:\/\/docs.vectalk.com.br\/api-reference\/webhooks\/register\">register webhook<\/a>) with <code>instance_id<\/code>, <code>url<\/code> and <code>name<\/code>, and receives Meta&#8217;s own payload. The <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">webhooks docs<\/a> ask for a <code>200<\/code> within 20 seconds; otherwise the event is retried.<\/li>\n\n<\/ul>\n\n\n\n<p>Vectalk&#8217;s documentation doesn&#8217;t describe a <code>GET<\/code> verification with <code>hub.challenge<\/code> or a signature header on forwarded events. In that setup, protect the route with a hard-to-guess secret in the URL path and confirm the details with support. Deduplication by <code>wamid<\/code> is still required. <a href=\"https:\/\/apps.vectalk.com.br\/register\">Create your account<\/a> to try it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need a WhatsApp PHP package?<\/h3>\n\n\n\n<p>No. Laravel&#8217;s HTTP client handles sending, and the webhook is a regular route. Third-party packages can help, but they add a dependency that has to keep up with Graph API versions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does this work in plain PHP, without Laravel?<\/h3>\n\n\n\n<p>Yes. The logic is the same: <code>curl<\/code> or Guzzle for the <code>POST<\/code>, <code>hash_hmac('sha256', file_get_contents('php:\/\/input'), $secret)<\/code> for the signature, and <code>$_GET['hub_challenge']<\/code> for verification.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why use a queue if processing is fast?<\/h3>\n\n\n\n<p>Because webhook response time doesn&#8217;t depend only on your code: a slow call to the API, the database or an AI model can delay the response. With a queue, the <code>200<\/code> goes out immediately and processing can be retried without losing the event.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Which Graph API version should I use?<\/h3>\n\n\n\n<p>Use a supported version and pin it in your config. Meta&#8217;s documentation examples use <code>v26.0<\/code> as of this date. Upgrade deliberately, testing first.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can one webhook handle several phone numbers?<\/h3>\n\n\n\n<p>Yes. The payload includes <code>metadata.phone_number_id<\/code>, which identifies the number that received the message. Use it to route events and to pick the right token when replying.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Official sources consulted on November 4, 2026:<\/strong> <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">Create a webhook endpoint (Meta)<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/overview\" target=\"_blank\" rel=\"noreferrer noopener\">Webhooks overview (Meta)<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/typing-indicators\" target=\"_blank\" rel=\"noreferrer noopener\">Typing indicators (Meta)<\/a>, <a href=\"https:\/\/laravel.com\/docs\/configuration\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel: Configuration<\/a>, <a href=\"https:\/\/laravel.com\/docs\/routing\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel: Routing<\/a>, <a href=\"https:\/\/laravel.com\/docs\/http-client\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel: HTTP Client<\/a>, <a href=\"https:\/\/laravel.com\/docs\/queues\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel: Queues<\/a>, <a href=\"https:\/\/laravel.com\/docs\/cache\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel: Cache<\/a>, <a href=\"https:\/\/www.php.net\/manual\/en\/language.variables.external.php\" target=\"_blank\" rel=\"noreferrer noopener\">PHP: Variables From External Sources<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk: Webhooks<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/authentication\">Vectalk: Authentication<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Complete Laravel tutorial: send text and templates, build a webhook route with GET verification, validate the X-Hub-Signature-256 header, queue jobs and dedupe.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-1165","post","type-post","status-publish","format-standard","hentry","category-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WhatsApp API PHP &amp; Laravel: full tutorial | Vectalk<\/title>\n<meta name=\"description\" content=\"WhatsApp API PHP tutorial with Laravel: send messages with the HTTP client, verify the webhook, validate X-Hub-Signature-256 and process in a queue.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WhatsApp API PHP &amp; Laravel: full tutorial | Vectalk\" \/>\n<meta property=\"og:description\" content=\"WhatsApp API PHP tutorial with Laravel: send messages with the HTTP client, verify the webhook, validate X-Hub-Signature-256 and process in a queue.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Vectalk\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-04T16:01:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-04T16:01:07+00:00\" \/>\n<meta name=\"author\" content=\"wanderleyfcunha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"wanderleyfcunha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/\"},\"author\":{\"name\":\"wanderleyfcunha\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"headline\":\"WhatsApp API with PHP and Laravel: sending messages and webhooks from scratch\",\"datePublished\":\"2026-11-04T16:01:00+00:00\",\"dateModified\":\"2026-11-04T16:01:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/\"},\"wordCount\":1335,\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/\",\"name\":\"WhatsApp API PHP & Laravel: full tutorial | Vectalk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\"},\"datePublished\":\"2026-11-04T16:01:00+00:00\",\"dateModified\":\"2026-11-04T16:01:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"description\":\"WhatsApp API PHP tutorial with Laravel: send messages with the HTTP client, verify the webhook, validate X-Hub-Signature-256 and process in a queue.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-api-php-laravel\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WhatsApp API with PHP and Laravel: sending messages and webhooks from scratch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\",\"name\":\"Blog Vectalk\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\",\"name\":\"wanderleyfcunha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"caption\":\"wanderleyfcunha\"},\"sameAs\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WhatsApp API PHP & Laravel: full tutorial | Vectalk","description":"WhatsApp API PHP tutorial with Laravel: send messages with the HTTP client, verify the webhook, validate X-Hub-Signature-256 and process in a queue.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/","og_locale":"en_US","og_type":"article","og_title":"WhatsApp API PHP & Laravel: full tutorial | Vectalk","og_description":"WhatsApp API PHP tutorial with Laravel: send messages with the HTTP client, verify the webhook, validate X-Hub-Signature-256 and process in a queue.","og_url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/","og_site_name":"Blog Vectalk","article_published_time":"2026-11-04T16:01:00+00:00","article_modified_time":"2026-11-04T16:01:07+00:00","author":"wanderleyfcunha","twitter_card":"summary_large_image","twitter_misc":{"Written by":"wanderleyfcunha","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/#article","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/"},"author":{"name":"wanderleyfcunha","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"headline":"WhatsApp API with PHP and Laravel: sending messages and webhooks from scratch","datePublished":"2026-11-04T16:01:00+00:00","dateModified":"2026-11-04T16:01:07+00:00","mainEntityOfPage":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/"},"wordCount":1335,"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/","url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/","name":"WhatsApp API PHP & Laravel: full tutorial | Vectalk","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/#website"},"datePublished":"2026-11-04T16:01:00+00:00","dateModified":"2026-11-04T16:01:07+00:00","author":{"@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"description":"WhatsApp API PHP tutorial with Laravel: send messages with the HTTP client, verify the webhook, validate X-Hub-Signature-256 and process in a queue.","breadcrumb":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-php-laravel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vectalk.com.br\/blog\/"},{"@type":"ListItem","position":2,"name":"WhatsApp API with PHP and Laravel: sending messages and webhooks from scratch"}]},{"@type":"WebSite","@id":"https:\/\/vectalk.com.br\/blog\/#website","url":"https:\/\/vectalk.com.br\/blog\/","name":"Blog Vectalk","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vectalk.com.br\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b","name":"wanderleyfcunha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","caption":"wanderleyfcunha"},"sameAs":["https:\/\/vectalk.com.br\/blog"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/1165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/comments?post=1165"}],"version-history":[{"count":1,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/1165\/revisions"}],"predecessor-version":[{"id":1168,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/1165\/revisions\/1168"}],"wp:attachment":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/media?parent=1165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/categories?post=1165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/tags?post=1165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}