Dart
Dart
WhatsApp Cloud API Send Message
See more WhatsApp Examples
Demonstrates how to send a message using the WhatsApp Cloud API (Business App)Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
// The following JSON is sent in the request body.
// {
// "messaging_product": "whatsapp",
// "to": "16302581871",
// "type": "template",
// "template": {
// "name": "hello_world",
// "language": {
// "code": "en_US"
// }
// }
// }
final json = CkJsonObject();
json.updateString('messaging_product', 'whatsapp');
json.updateString('to', '15555555555');
json.updateString('type', 'template');
json.updateString('template.name', 'hello_world');
json.updateString('template.language.code', 'en_US');
http.authToken = 'EAANrS5....yFB9Ma';
http.setRequestHeader('Content-Type', 'application/json');
final resp = CkHttpResponse();
try {
http.httpJson('POST', 'https://graph.facebook.com/v18.0/111111111111111/messages', json, 'application/json', resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print(resp.statusCode);
print(resp.bodyStr);
// Here's a screenshot of our WhatsApp test app.
//
}