Initialization
To use the package, create a WhatsApp instance with your access token and business
phone number ID.
const accessToken = 'YOUR_ACCESS_TOKEN';
const fromNumberId = 'YOUR_BUSINESS_PHONE_NUMBER_ID';
final whatsapp = WhatsApp(accessToken, fromNumberId);
| param | type | required | description |
|---|---|---|---|
accessToken | String | yes | Access token for your Meta app |
fromNumberId | String | yes | Phone number ID of the WhatsApp business number |
Both values are trimmed, so trailing whitespace in environment variables or secret
stores does not break the Authorization header.
API version customization
The default Graph API version is v27.0. You can target another supported version:
whatsapp.setVersion('v26.0');
setVersion validates the format and throws ArgumentError for values that are not
like v27.0.
If not set, the package uses v27.0.
Timeouts and a custom transport
The client uses a dependency-free transport: dart:io on native platforms and browser
XMLHttpRequest on the web. You can inject your own HttpTransport for logging,
proxying, retries or an unsupported platform.
final request = Request(
requestTimeout: const Duration(seconds: 30),
uploadTimeout: const Duration(minutes: 5),
// transport: MyHttpTransport(),
);
final whatsapp = WhatsApp(accessToken, fromNumberId, request);
| option | default | description |
|---|---|---|
requestTimeout | 60 seconds | JSON API requests |
uploadTimeout | 5 minutes | Media uploads and downloads |
apiVersion | v27.0 | Graph API version |
Webhooks
Webhook signature verification and payload parsing are built in. Configure the callback URL in the Meta App Dashboard and see Webhooks for a complete example.