In questo tutorial imparerai come programmare la consegna dei messaggi usando l'API
Ci sono due modi per programmare la consegna di un messaggio a un momento e/o giorno successivo: specificando il giorno e l'ora esatti in cui desideri che venga inviato oppure indicando di quanti minuti, ore o giorni desideri ritardare la consegna differita.
Se vuoi inviare messaggi da codice, puoi usare qualsiasi linguaggio di programmazione per effettuare richieste HTTPS all'API. Di seguito trovi il tester API live con esempi di codice pronti all'uso in vari linguaggi di programmazione.
Requisiti
- Avere un WhatsApp number già collegato alla piattaforma e online.
- Numero di telefono del destinatario con prefisso internazionale in E164 format. Esempio:
+393517224449. Puoi validare il numero di telefono qui.
Endpoint API
In questo tutorial useremo il seguente endpoint API:
Preparare la richiesta
URL API di destinazione (POST)
https://api.wassenger.com/v1/messages
Intestazioni HTTPS richieste
Content-Type: application/json
Token: ENTER API KEY HERE
Invia un messaggio a una data specifica in formato ISO8601
Esempio di body della richiesta in formato JSON
{ "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-01-15T10:42:34.416Z" }
Congratulazioni! Ora puoi inviare messaggi automatici usando l'API ai canali su WhatsApp.
🤩 🤖 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:
# Examples requires to have installed requests Python package.
# Install it by running: pip install requests
import requests
url = "https://api.wassenger.com/v1/messages"
payload = {
"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-01-15T10:42:34.416Z"
}
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([
'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-01-15T10:42:34.416Z',
]),
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([
'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-01-15T10:42:34.416Z',
])
);
$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' =>
'{"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-01-15T10:42:34.416Z"}',
'headers' => [
'Content-Type' => 'application/json',
'Token' => 'API TOKEN GOES HERE',
],
]);
echo $response->getBody();
// 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([
'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-01-15T10:42:34.416Z',
])
);
$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();
- C# (RestClient)
// 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", "{\"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-01-15T10:42:34.416Z\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
- C# (HttpClient)
// 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("{\"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-01-15T10:42:34.416Z\"}")
{
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("{\"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-01-15T10:42:34.416Z\"}")
.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 '{"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-01-15T10:42:34.416Z"}'
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 = "{\"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-01-15T10:42:34.416Z\"}"
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("{\"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-01-15T10:42:34.416Z\"}")
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 per una prova gratuita e iniziando in pochi minuti!
Test live per inviare un messaggio a un gruppo via API
Domande frequenti
Qual è la differenza tra inviare messaggi individuali e inviare in broadcast a un canale WhatsApp?
Con Wassenger puoi inviare messaggi individuali per conversazioni personalizzate oppure messaggi broadcast tramite campagne per raggiungere più destinatari contemporaneamente. Il broadcast ti permette di indirizzare gruppi di clienti in modo efficiente rispettando le politiche di messaggistica di WhatsApp.
Wassenger supporta la programmazione dei messaggi per i canali WhatsApp?
Assolutamente sì. Wassenger permette di programmare messaggi per date e orari specifici, garantendo una comunicazione tempestiva con i tuoi clienti.
Ci sono limiti sul numero di messaggi che posso inviare in un giorno?
Il numero di messaggi dipende dal tipo di account WhatsApp Business e dal piano. Wassenger fornisce strumenti per aiutarti a rimanere entro le linee guida di WhatsApp ed evitare sanzioni.
Posso includere contenuti multimediali (immagini, video, file) nei messaggi inviati ai canali WhatsApp?
Sì, Wassenger supporta i messaggi multimediali, permettendoti di inviare immagini, video, documenti e persino note vocali ai contatti o ai canali WhatsApp.
Ulteriori risorse utili
Per maggiori dettagli sull'endpoint API, consulta la nostra documentazione. Troverai tutti i dettagli sui parametri di richiesta accettati, le possibili risposte di successo o errore e esempi di codice pronti all'uso in più linguaggi di programmazione.







