sendDocumentByUrl method

Future<Request> sendDocumentByUrl(
  1. String phoneNumber,
  2. String url,
  3. String? caption,
  4. String? fileName,
)

Implementation

Future<Request> sendDocumentByUrl(
    String phoneNumber, String url, String? caption, String? fileName) async {
  final Map<String, String> headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer $accessToken',
  };

  final Map<String, dynamic> body = {
    "messaging_product": "whatsapp",
    "recipient_type": "individual",
    "to": phoneNumber,
    "type": "document",
    "document": {"link": url}
  };

  if (caption != null) {
    body['document']['caption'] = caption;
  }

  if (fileName != null) {
    body['document']['filename'] = fileName;
  }

  await request.post('$fromNumberId/messages', headers, body);
  return request;
}