Automatizza i messaggi del canale WhatsApp usando PHP

11 marzo 2025

I canali WhatsApp sono essenziali per le aziende che vogliono connettersi con i loro team, clienti o community. Tuttavia, gestirli manualmente può richiedere molto tempo. E se potessi automatizzare la creazione e l'invio di messaggi ai canali WhatsApp? Con Wassenger e PHP, è semplice 🤖

🤩 🤖 Wassenger è una soluzione API completa per WhatsApp. Iscriviti per una prova gratuita di 7 giorni e inizia in pochi minuti!

In questa guida ti mostreremo come:

✅ Creare un canale WhatsApp
✅ Inviare messaggi a un canale WhatsApp
✅ Automatizzare i messaggi del canale per aggiornamenti e annunci

Perché automatizzare i messaggi dei canali WhatsApp? 🤔

Gestire e inviare messaggi ai canali WhatsApp manualmente può essere complicato. Automatizzare il processo ti permette di:

Risparmiare tempo — Non dovrai più inviare messaggi individuali a più canali.

Aumentare l’engagement — Mantieni i tuoi team o clienti aggiornati in tempo reale.

Migliorare la coerenza — Assicurati che i messaggi vengano inviati al momento giusto senza perdere aggiornamenti.

Scalare la comunicazione — Raggiungi più persone senza sforzo con messaggi automatizzati.

📢 Vuoi iniziare? Iscriviti a Wassenger ora! 🚀

Requisiti

  • Avere un numero WhatsApp già collegato alla piattaforma e online.
  • ID del canale (WID) che può essere trovato in due modi:
  1. Nel pannello di gestione del tuo numero WhatsApp, vai su “channels”. Da lì vedrai i canali a cui il tuo numero ha accesso.
  2. Usando l’API, richiedi i canali disponibili nel tuo dispositivo con questo endpoint.

Preparare la richiesta

URL API di destinazione usando il metodo POST per creare un canale

http://api.wassenger.com/v1/devices/{deviceId}/channels

URL API di destinazione usando il metodo POST per inviare messaggi a un canale

https://api.wassenger.com/v1/messages

Intestazioni HTTPS richieste > Ottieni la tua chiave API qui

Content-Type: application/json
Token: $API_TOKEN

🤩 🤖 Wassenger è una soluzione API completa per WhatsApp. Iscriviti per una prova gratuita di 7 giorni e inizia in pochi minuti!

Sei uno sviluppatore?

Scopri come usare il codice nel tuo browser senza installare alcun software.

Inoltre, puoi trovare diversi linguaggi da testare su Replit.com:

1. Come creare un canale WhatsApp con PHP

Creare un canale WhatsApp tramite l’API di Wassenger è semplice. Ecco come farlo in PHP:

Crea un canale con PHP (Guzzle)

// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation

request('POST', 'https://api.wassenger.com/v1/devices/%7B%7Bdevice.id%7D%7D/channels', \[ 'body' => '{"name":"Channel name","description":"This is a channel sample description, up to 2048 characters allowed","image":{"url":"https://picsum.photos/600"}}', 'headers' => \[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', \], \]); echo $response\->getBody(); **Crea un canale con PHP (http2)** // This code example requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'name' => 'Channel name', 'description' => 'This is a channel sample description, up to 2048 characters allowed', 'image' => \[ 'url' => 'https://picsum.photos/600' \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/devices/%7B%7Bdevice.id%7D%7D/channels'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); **Crea un canale con PHP (curl)** ```php 'https://api.wassenger.com/v1/devices/{{device.id}}/channels', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode([ 'name' => 'Channel name', 'description' => 'This is a channel sample description, up to 2048 characters allowed', 'image' => [ 'url' => 'https://picsum.photos/600', ], ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` ✅ **Questo crea un nuovo canale WhatsApp** chiamato “Channel name”. > *🤩 🤖* [***Wassenger***](https://wassenger.com/) *è una piattaforma di comunicazione e una soluzione API completa per WhatsApp.* [***Esplora più di 100+ casi d'uso API e automatizza qualsiasi cosa su WhatsApp***](https://wassenger.com/) *iscrivendoti* [*per una prova gratuita e iniziando in pochi minuti****!***](https://wassenger.com/register) ### 2\. Come inviare messaggi a un canale WhatsApp con PHP Una volta creato il canale, puoi inviargli messaggi usando l’ID univoco del canale: **Invia un messaggio di testo con PHP (Guzzle)** ```php // This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation request('POST', 'https://api.wassenger.com/v1/messages', [ 'body' => '{"channel":"{{channel}}", "message":"This is a sample message sent to a channel"}', 'headers' => [ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ], ]); echo $response->getBody(); ``` **Invia un messaggio di testo con PHP (http2)** ```php // This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl_http // More information: https://mdref.m6w6.name/http append( json_encode([ 'channel' => '{{channel}}', 'message' => 'This is a sample message sent to a channel', ]) ); $request->setRequestUrl('https://api.wassenger.com/v1/messages'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders([ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` **Invia un messaggio di testo con PHP (curl)** ```php 'https://api.wassenger.com/v1/messages', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode([ 'channel' => '{{channel}}', 'message' => 'This is a sample message sent to a channel', ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` Puoi anche aggiungere media ai tuoi messaggi: **Invia messaggi multimediali con PHP (Guzzle)** ```php // This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation request('POST', 'https://api.wassenger.com/v1/messages', [ 'body' => '{"channel":"channel_id@newsletter", "message":"This is a caption for an image message", "media":{"url":"https://picsum.photos/seed/picsum/600/400", "viewOnce":false}}', 'headers' => [ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ], ]); echo $response->getBody(); ``` **Invia messaggi multimediali con PHP (http2)** ```php // This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl_http // More information: https://mdref.m6w6.name/http append( json_encode([ 'channel' => 'channel_id@newsletter', 'message' => 'This is a caption for an image message', 'media' => [ 'url' => 'https://picsum.photos/seed/picsum/600/400', 'viewOnce' => null, ], ]) ); $request->setRequestUrl('https://api.wassenger.com/v1/messages'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders([ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` **Invia messaggi multimediali con PHP (curl)** ```php 'https://api.wassenger.com/v1/messages', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode([ 'channel' => 'channel_id@newsletter', 'message' => 'This is a caption for an image message', 'media' => [ 'url' => 'https://picsum.photos/seed/picsum/600/400', 'viewOnce' => null, ], ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` ✅ **Questo invia automaticamente un messaggio al canale WhatsApp specificato.** > ***È stato utile****? Trova più esempi nel nostro* [***API Live Tester***](https://app.wassenger.com/help/api-tester) *🤖* ### 3\. Come programmare messaggi in un canale WhatsApp con PHP La programmazione dei messaggi ti permette di inviare aggiornamenti al momento perfetto: **Programma un messaggio con PHP (Guzzle)** ```php // This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP. // Install it first following these instructions: // https://docs.guzzlephp.org/en/stable/overview.html#installation request('POST', 'https://api.wassenger.com/v1/messages', [ 'body' => '{"channel":"channel_id@newsletter", "message":"This is a scheduled message to be sent tomorrow to a channel.Date format is based on ISO 8601 format with default UTC time zone", "deliverAt":"2025-03-07T10:23:53.810Z"}', 'headers' => [ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ], ]); echo $response->getBody(); ``` **Programma un messaggio con PHP (http2)** ```php // This code example requires to have installed pecl_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl_http // More information: https://mdref.m6w6.name/http append( json_encode([ 'channel' => 'channel_id@newsletter', 'message' => 'This is a scheduled message to be sent tomorrow to a channel.Date format is based on ISO 8601 format with default UTC time zone', 'deliverAt' => '2025-03-07T10:23:53.810Z', ]) ); $request->setRequestUrl('https://api.wassenger.com/v1/messages'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders([ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE', ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody(); ``` **Programma un messaggio con PHP (curl)** ```php 'https://api.wassenger.com/v1/messages', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode([ 'channel' => 'channel_id@newsletter', 'message' => 'This is a scheduled message to be sent tomorrow to a channel.Date format is based on ISO 8601 format with default UTC time zone', 'deliverAt' => '2025-03-07T10:23:53.810Z', ]), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Token: ENTER API KEY HERE', ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo 'cURL Error #:' . $err; } else { echo $response; } ``` ✅ **Questo programma automaticamente l'invio di un messaggio in un momento successivo.** > ***È stato utile****? Trova più esempi nel nostro* [***API Live Tester***](https://app.wassenger.com/help/api-tester) *🤖* ![](/images/blog/automate-whatsapp-channel-messages-using-ph-02.png) [Prova subito il nostro API-Live tester](https://app.wassenger.com/help/api-tester)! ### Domande Frequenti (FAQ) 🤔 #### 1\. Posso usare l’API di Wassenger per rimuovere utenti da un canale WhatsApp? Questa guida si concentra sull’invio di messaggi, ma l’API di Wassenger offre opzioni di gestione dei canali, inclusa l’aggiunta o la rimozione di utenti. 📢 **Hai bisogno di più aiuto?** Visita il [Wassenger Help Center](https://app.wassenger.com/help) per documentazione e supporto dettagliati! #### 2\. Posso inviare immagini, video o documenti ai canali WhatsApp usando l’API di Wassenger? Assolutamente! L’API di Wassenger ti permette di inviare contenuti multimediali come immagini, video, PDF e altro ai tuoi canali WhatsApp. #### 3\. Come posso verificare se il mio messaggio è stato consegnato correttamente a un canale WhatsApp? Puoi usare l’API di Wassenger per recuperare gli aggiornamenti di stato dei messaggi, assicurandoti che i tuoi messaggi siano consegnati e letti. #### 4\. Posso menzionare utenti specifici in un messaggio di un canale WhatsApp? Sì! Puoi menzionare partecipanti specifici includendo i loro numeri di telefono nel payload del messaggio. > *📌* ***Pronto ad automatizzare i tuoi messaggi su WhatsApp?*** [*Inizia la tua prova gratuita oggi!*](https://app.wassenger.com/register) *🚀* Con [**Wassenger**](https://wassenger.com) **e PHP**, puoi creare, inviare e programmare messaggi ai canali WhatsApp senza sforzo, rendendo la comunicazione più fluida ed efficiente.

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free