sendLocation method

Future<Request> sendLocation(
  1. String phoneNumber,
  2. double latitude,
  3. double longitude,
  4. String? name,
  5. String? address,
)

Implementation

Future<Request> sendLocation(String phoneNumber, double latitude,
    double longitude, String? name, String? address) 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": "location",
    "location": {
      "latitude": latitude.toString(),
      "longitude": longitude.toString(),
    }
  };

  if (name != null) {
    body["location"]["name"] = name;
  }

  if (address != null) {
    body["location"]["address"] = address;
  }

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