Skip to main content
Version: 4.2.0

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);
paramtyperequireddescription
accessTokenStringyesAccess token for your Meta app
fromNumberIdStringyesPhone 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.

Default version

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);
optiondefaultdescription
requestTimeout60 secondsJSON API requests
uploadTimeout5 minutesMedia uploads and downloads
apiVersionv27.0Graph 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.