Dart Requires Chilkat v11.0.0+
Dart
Clickatell One API: Schedule a time-limited SMS reminder
See more Clickatell Examples
Schedule a reminder 15 minutes from now in UTC. The scheduledDeliveryTime includes its time zone and validityPeriod is expressed in minutes. Set both from the appointment and the period for which the reminder will still be useful. Use the returned message ID for a later status lookup.
Supply an international number as digits. Set the sender to the provisioned number when the integration requires it.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Assumes Chilkat is unlocked. See Global Unlock Sample.
final http = CkHttp();
http.requireSslCertVerify = true;
// Load the key for this One API integration from your application configuration.
http.setRequestHeader('Authorization', 'ONE_API_KEY');
http.setRequestHeader('Accept', 'application/json');
final schedule = CkDateTime();
schedule.setFromCurrentSystemTime();
schedule.addSeconds(900);
final sendAt = schedule.getAsTimestamp(false);
final body = CkJsonObject();
body.updateString('messages[0].channel', 'sms');
body.updateString('messages[0].to', 'PHONE_NUMBER');
body.updateString('messages[0].content', 'Appointment reminder: please check in at reception.');
body.updateString('messages[0].scheduledDeliveryTime', sendAt);
body.updateInt('messages[0].validityPeriod', 60);
final sender = '';
if (sender != '') {
body.updateString('messages[0].from', sender);
}
print('Requested send time (UTC): $sendAt');
final resp = CkHttpResponse();
var sent = true;
try {
http.httpJson('POST', 'https://platform.clickatell.com/v1/message', body, 'application/json', resp);
} on ChilkatException {
sent = false;
}
if (resp.statusCode == 0) {
print('No HTTP response. Check the message report before resending.');
return;
}
final reply = CkJsonObject();
var parsed = true;
try {
reply.load(resp.bodyStr);
} on ChilkatException {
parsed = false;
}
if ((!sent) || (resp.statusCode != 202)) {
print('Send returned HTTP ${resp.statusCode}');
if (reply.hasMember('error.description')) {
print(reply.stringOf('error.description'));
}
return;
}
if (reply.hasMember('error.code')) {
if (!reply.isNullOf('error.code')) {
print('Submission error ${reply.stringOf('error.code')} ${reply.stringOf('error.description')}');
return;
}
}
// HTTP acceptance and the recipient result are separate checks.
if ((!parsed) || (reply.jsonTypeOf('messages[0].accepted') != 5)) {
print('Missing recipient result. Check the message report.');
return;
}
if (!reply.boolOf('messages[0].accepted')) {
print('Message rejected: ${reply.stringOf('messages[0].error.code')} ${reply.stringOf('messages[0].error.description')}');
return;
}
if (reply.jsonTypeOf('messages[0].apiMessageId') != 1) {
print('Accepted without a message ID. Check the message report.');
return;
}
print('Accepted. Message ID: ${reply.stringOf('messages[0].apiMessageId')}');
}