sendContactDetails method

Future<Request> sendContactDetails(
  1. String phoneNumber,
  2. String? dateOfBirth,
  3. List<Map>? addresses,
  4. List<Map>? emails,
  5. Map person,
  6. Map? organization,
  7. List<Map> phones,
  8. List<Map>? urls,
)

Implementation

Future<Request> sendContactDetails(
  String phoneNumber,
  String? dateOfBirth,
  List<Map<dynamic, dynamic>>? addresses,
  List<Map<dynamic, dynamic>>? emails,
  Map<dynamic, dynamic> person,
  Map<dynamic, dynamic>? organization,
  List<Map<dynamic, dynamic>> phones,
  List<Map<dynamic, dynamic>>? urls,
) async {
  final Map<String, String> headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer $accessToken',
  };

  final Map<String, dynamic> body = {
    "messaging_product": "whatsapp",
    "to": phoneNumber,
    "type": "contacts",
    "contacts": [
      {
        "name": person,
        "phones": phones,
      }
    ]
  };

  if (addresses != null) {
    body['contacts'][0]['addresses'] = addresses;
  }

  if (dateOfBirth != null) {
    body['contacts'][0]['birthday'] = dateOfBirth;
  }

  if (emails != null) {
    body['contacts'][0]['emails'] = emails;
  }

  if (organization != null) {
    body['contacts'][0]['org'] = organization;
  }

  if (urls != null) {
    body['contacts'][0]['urls'] = urls;
  }

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