sendMessage method

Future<Request> sendMessage(
  1. String phoneNumber,
  2. String text,
  3. bool previewUrl
)

Implementation

Future<Request> sendMessage(
    String phoneNumber, String text, bool previewUrl) 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': 'text',
    'text': {
      'preview_url': previewUrl,
      'body': text,
    },
  };

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