Dart
Dart
WaTrend Send WhatsApp Text
See more WaTrend Examples
Send a WhatsApp text.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
// Use your actual access token instead of 555555555555555555555555555555
final req = CkHttpRequest();
req.addParam('number', '84933313xxx');
req.addParam('type', 'text');
req.addParam('message', 'This is a test message');
req.addParam('instance_id', '609ACF283XXXX');
req.addParam('access_token', '555555555555555555555555555555');
// Note: The WaTrend online documentation indicate a POST should be used.
// However, it seems you might actually need to send a GET request.
// It is unclear.
// If a GET is neeed, you would just send to the URL w/ query params like this:
final sbUrl = CkStringBuilder();
sbUrl.append('https://app.watrend.com/api/send.php?');
sbUrl.append(req.getUrlEncodedParams());
final responseBodyStr = http.quickGetStr(sbUrl.getAsString());
// The responseBodyStr contains the JSON response from the server..
req.httpVerb = 'POST';
req.contentType = 'application/x-www-form-urlencoded';
final resp = CkHttpResponse();
try {
http.httpReq('https://app.watrend.com/api/send.php', req, resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final sbResponseBody = CkStringBuilder();
resp.getBodySb(sbResponseBody);
final respStatusCode = resp.statusCode;
print('Response Status Code = $respStatusCode');
if (respStatusCode >= 400) {
print('Response Header:');
print(resp.header);
print('Failed.');
return;
}
print(resp.bodyStr);
// Both success and failed responses use 200 status code.
// A success response contains this JSON in the response body:
// {"status":"success", ... }
// A failed response will contain something like this:
// {"status":"error","message":"License Invalidated"}
final jResp = CkJsonObject();
jResp.loadSb(sbResponseBody);
final status = jResp.stringOf('status');
print('status: $status');
}