sendInteractiveLists method

Future<Request> sendInteractiveLists(
  1. String phoneNumber,
  2. String? headerText,
  3. String bodyText,
  4. String? footerText,
  5. String buttonText,
  6. List<Map<String, dynamic>> sections,
)

Implementation

Future<Request> sendInteractiveLists(
    String phoneNumber,
    String? headerText,
    String bodyText,
    String? footerText,
    String buttonText,
    List<Map<String, dynamic>> sections) 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": "interactive",
    "interactive": {
      "type": "list",
      "body": {"text": bodyText},
      "action": {
        "sections": sections,
        "button": buttonText,
      }
    }
  };

  if (headerText != null) {
    body['interactive']['header'] = {"type": "text", "text": headerText};
  }

  if (footerText != null) {
    body['interactive']['footer'] = {"text": footerText};
  }

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