Come programmare i messaggi nei gruppi WhatsApp

24 gennaio 2025

In questo tutorial imparerai come programmare la consegna di messaggi ai gruppi utilizzando l'API

Ci sono due modi per programmare la consegna di un messaggio a un orario e/o giorno futuro: specificando il giorno e l'ora esatti in cui desideri venga inviato oppure indicando di quanti minuti, ore o giorni desideri ritardare la consegna differita.

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

Se desideri inviare messaggi da codice, puoi usare qualsiasi linguaggio di programmazione per effettuare richieste HTTPS all'API. Di seguito è disponibile il tester API live con esempi di codice pronti all'uso in vari linguaggi di programmazione.

Requisiti

  • Avere un numero WhatsApp già collegato alla piattaforma e online.
  • ID del canale WhatsApp (WID) che puoi trovare in due modi:
  1. Nel pannello di gestione del tuo numero WhatsApp, vai su “Groups”. Da lì vedrai i canali a cui il tuo numero ha accesso.
  2. Utilizzando l'API, interroga i gruppi disponibili sul tuo dispositivo per questo endpoint.

Preparare la richiesta

URL target dell'API usando il metodo POST

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

Header HTTPS richiesti > Ottieni la tua API key qui

Content-Type: application/json
Token: $API_TOKEN

Usa il body in formato JSON

{ "group": "${@g.us">group_id}@g.us", "message": "This is a scheduled message to be sent tomorrow to a group chat. Date format is based on ISO 8601 format with default UTC time zone", "deliverAt": "2025-01-24T21:18:31.271Z" }

Congratulazioni! Ora puoi inviare messaggi automatici ai gruppi WhatsApp tramite l'API.

🤩 🤖 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 che puoi testare su Replit.com:

# Gli esempi richiedono il pacchetto requests per Python. # Installalo eseguendo: pip install requests

import requests

url = "https://api.wassenger.com/v1/messages"

payload = { "group": "${@g.us">group_id}@g.us", "message": "This is a scheduled message to be sent tomorrow to a group chat. Date format is based on ISO 8601 format with default UTC time zone", "deliverAt": "2025-01-24T21:18:31.271Z" } headers = { "Content-Type": "application/json", "Token": "API TOKEN GOES HERE" }

response = requests.post(url, json=payload, headers=headers)

print(response.json())

<?php
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => '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([
    'group' => '${@g.us">group_id}@g.us',
    'message' =>
      'This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone',
    'deliverAt' => '2025-01-24T21:18:31.271Z',
  ]),
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Token: API TOKEN GOES HERE',
  ],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}
// 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
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
  json_encode([
    'group' => '${@g.us">group_id}@g.us',
    'message' =>
      'This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone',
    'deliverAt' => '2025-01-24T21:18:31.271Z',
  ])
);
$request->setRequestUrl('https://api.wassenger.com/v1/messages');
$request->setRequestMethod('POST');
$request->setBody($body);
$request->setHeaders([
  'Content-Type' => 'application/json',
  'Token' => 'API TOKEN GOES HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
// 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
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.wassenger.com/v1/messages', [
  'body' =>
    '{"group":"${@g.us">group_id}@g.us", "message":"This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone", "deliverAt":"2025-01-24T21:18:31.271Z"}',
  'headers' => [
    'Content-Type' => 'application/json',
    'Token' => 'API TOKEN GOES HERE',
  ],
]);
echo $response->getBody();

// This code requires you to have installed RestSharp package. // Documentation: https://restsharp.dev // Installation: https://www.nuget.org/packages/RestSharp

var client = new RestClient("https://api.wassenger.com/v1/messages"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Token", "API TOKEN GOES HERE"); request.AddParameter("application/json", "{\"group\":\"${@g.us">group_id}@g.us\",\"message\":\"This is a scheduled message to be sent tomorrow to a group chat. Date format is based on ISO 8601 format with default UTC time zone\",\"deliverAt\":\"2025-01-24T21:18:31.271Z\"}", ParameterType.RequestBody); IRestResponse response = client.Execute(request);

// This code uses the built-in HttpClient package in the .NET framework. // Documentation: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

using System.Net.Http.Headers; var client = new HttpClient(); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri("https://api.wassenger.com/v1/messages"), Headers = { { "Token", "API TOKEN GOES HERE" }, }, Content = new StringContent("{\"group\":\"${@g.us">group_id}@g.us\",\"message\":\"This is a scheduled message to be sent tomorrow to a group chat. Date format is based on ISO 8601 format with default UTC time zone\",\"deliverAt\":\"2025-01-24T21:18:31.271Z\"}") { Headers = { ContentType = new MediaTypeHeaderValue("application/json") } } }; using (var response = await client.SendAsync(request)) { response.EnsureSuccessStatusCode(); var body = await response.Content.ReadAsStringAsync(); Console.WriteLine(body); }

// This code requires you to have installed Unirest package.
// Documentation: https://kong.github.io/unirest-java/#requests
// Installation: http://kong.github.io/unirest-java/
HttpResponse<String> response = Unirest.post("https://api.wassenger.com/v1/messages")
.header("Content-Type", "application/json")
.header("Token", "API TOKEN GOES HERE")
.body("{\"group\":\"${@g.us">group_id}@g.us\", \"message\":\"This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone\", \"deliverAt\":\"2025-01-24T21:18:31.271Z\"}")
.asString();
$headers=@{}
$headers.Add("Content-Type", "application/json")
$headers.Add("Token", "API TOKEN GOES HERE")
$response = Invoke-WebRequest -Uri 'https://api.wassenger.com/v1/messages' -Method POST -Headers $headers -ContentType 'application/json' -Body '{"group":"${@g.us">group_id}@g.us", "message":"This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone", "deliverAt":"2025-01-24T21:18:31.271Z"}'
require 'uri'
require 'net/http'
url = URI("https://api.wassenger.com/v1/messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["Token"] = 'API TOKEN GOES HERE'
request.body = "{\"group\":\"${@g.us">group_id}@g.us\", \"message\":\"This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone\", \"deliverAt\":\"2025-01-24T21:18:31.271Z\"}"
response = http.request(request)
puts response.read_body
package main
import(
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url:= "https://api.wassenger.com/v1/messages"
payload:= strings.NewReader("{\"group\":\"${@g.us">group_id}@g.us\", \"message\":\"This is a scheduled message to be sent tomorrow to a group chat.Date format is based on ISO 8601 format with default UTC time zone\", \"deliverAt\":\"2025-01-24T21:18:31.271Z\"}")
req, _:= http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Token", "API TOKEN GOES HERE")
res, _:= http.DefaultClient.Do(req)
defer res.Body.Close()
body, _:= io.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}

🤩 🤖 Wassenger è una piattaforma di comunicazione completa e una soluzione API per WhatsApp. Esplora oltre 100+ casi d'uso API e automatizza qualsiasi cosa su WhatsApp iscrivendoti a una prova gratuita e iniziando in pochi minuti!

Test in tempo reale per inviare un messaggio a un gruppo tramite API

Esplora il nostro tester API live

Domande frequenti

Come inviare messaggi a più gruppi

Devi semplicemente inviare più richieste API, una per ogni gruppo destinatario.

Ad esempio, se vuoi inviare un messaggio a 10 gruppi, dovresti inviare 10 richieste HTTPS indipendenti all'API.

Non esiste un'opzione per inviare più messaggi in una singola richiesta API.

Che tipi di messaggi possono essere inviati?

Puoi inviare diversi tipi di messaggi, inclusi testo, immagini, video, emoji, audio, gif, posizioni geografiche e documenti file tramite API.

Consulta altri tutorial per maggiori informazioni.

Ulteriori risorse utili

Documentazione API

Per maggiori dettagli sull'endpoint API, consulta la nostra documentazione. Troverai tutte le informazioni sui parametri di richiesta accettati, possibili risposte di successo o errore e esempi di codice pronti all'uso in più linguaggi di programmazione.

https://app.wassenger.com/docs/#tag/Messages

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free