sendCallToActionButton method
Implementation
Future<Request> sendCallToActionButton(
String phoneNumber,
String? headerText,
String bodyText,
String? footerText,
String buttonText,
String buttonUrl) 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": "cta_url",
"body": {"text": bodyText},
"action": {
"name": "cta_url",
"parameters": {"display_text": buttonText, "url": buttonUrl}
}
}
};
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;
}