sendImageById method

Future<Request> sendImageById(
  1. String phoneNumber,
  2. String mediaId,
  3. String? caption
)

Implementation

Future<Request> sendImageById(
    String phoneNumber, String mediaId, String? caption) 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": "image",
    "image": {"id": mediaId}
  };

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

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